Changeset d011038 in mainline for uspace/app/sbi/src/builtin/bi_console.c
- Timestamp:
- 2011-03-29T20:12:44Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8f17503
- Parents:
- c4fb95d3 (diff), 93ebe4e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/builtin/bi_console.c
rc4fb95d3 rd011038 27 27 */ 28 28 29 /** @file Builtin functions. */29 /** @file Console builtin binding. */ 30 30 31 31 #include <stdio.h> … … 36 36 #include "../list.h" 37 37 #include "../mytypes.h" 38 #include "../os/os.h"39 38 #include "../run.h" 40 39 #include "../stree.h" … … 42 41 #include "../symbol.h" 43 42 44 #include "bi_ fun.h"43 #include "bi_console.h" 45 44 46 static void bi_fun_builtin_write(run_t *run); 47 static void bi_fun_builtin_writeline(run_t *run); 48 static void bi_fun_task_exec(run_t *run); 45 static void bi_console_write(run_t *run); 46 static void bi_console_writeline(run_t *run); 49 47 50 /** Declare builtin functions.48 /** Declare Console builtin. 51 49 * 52 50 * @param bi Builtin object 53 51 */ 54 void bi_ fun_declare(builtin_t *bi)52 void bi_console_declare(builtin_t *bi) 55 53 { 56 54 stree_modm_t *modm; … … 63 61 64 62 ident = stree_ident_new(); 65 ident->sid = strtab_get_sid(" Builtin");63 ident->sid = strtab_get_sid("Console"); 66 64 67 65 csi = stree_csi_new(csi_class); … … 89 87 fun_sym = builtin_declare_fun(csi, "WriteLine"); 90 88 builtin_fun_add_arg(fun_sym, "arg"); 91 92 /* Declare class Task. */93 94 builtin_code_snippet(bi,95 "class Task is\n"96 "fun Exec(args : string[], packed), static, builtin;\n"97 "end\n");98 89 } 99 90 … … 102 93 * @param bi Builtin object 103 94 */ 104 void bi_ fun_bind(builtin_t *bi)95 void bi_console_bind(builtin_t *bi) 105 96 { 106 builtin_fun_bind(bi, "Builtin", "Write", bi_fun_builtin_write); 107 builtin_fun_bind(bi, "Builtin", "WriteLine", bi_fun_builtin_writeline); 108 builtin_fun_bind(bi, "Task", "Exec", bi_fun_task_exec); 97 builtin_fun_bind(bi, "Console", "Write", bi_console_write); 98 builtin_fun_bind(bi, "Console", "WriteLine", bi_console_writeline); 109 99 } 110 100 … … 113 103 * @param run Runner object 114 104 */ 115 static void bi_ fun_builtin_write(run_t *run)105 static void bi_console_write(run_t *run) 116 106 { 117 107 rdata_var_t *var; … … 120 110 121 111 #ifdef DEBUG_RUN_TRACE 122 printf("Called Builtin.Write()\n");112 printf("Called Console.Write()\n"); 123 113 #endif 124 114 var = run_local_vars_lookup(run, strtab_get_sid("arg")); … … 152 142 * @param run Runner object 153 143 */ 154 static void bi_ fun_builtin_writeline(run_t *run)144 static void bi_console_writeline(run_t *run) 155 145 { 156 146 #ifdef DEBUG_RUN_TRACE 157 printf("Called Builtin.WriteLine()\n");147 printf("Called Console.WriteLine()\n"); 158 148 #endif 159 bi_ fun_builtin_write(run);149 bi_console_write(run); 160 150 putchar('\n'); 161 151 } 162 163 /** Start an executable and wait for it to finish.164 *165 * @param run Runner object166 */167 static void bi_fun_task_exec(run_t *run)168 {169 rdata_var_t *args;170 rdata_var_t *var;171 rdata_array_t *array;172 rdata_var_t *arg;173 int idx, dim;174 const char **cmd;175 176 #ifdef DEBUG_RUN_TRACE177 printf("Called Task.Exec()\n");178 #endif179 args = run_local_vars_lookup(run, strtab_get_sid("args"));180 181 assert(args);182 assert(args->vc == vc_ref);183 184 var = args->u.ref_v->vref;185 assert(var->vc == vc_array);186 187 array = var->u.array_v;188 assert(array->rank == 1);189 dim = array->extent[0];190 191 if (dim == 0) {192 printf("Error: Builtin.Exec() expects at least one argument.\n");193 exit(1);194 }195 196 cmd = calloc(dim + 1, sizeof(char *));197 if (cmd == NULL) {198 printf("Memory allocation failed.\n");199 exit(1);200 }201 202 for (idx = 0; idx < dim; ++idx) {203 arg = array->element[idx];204 if (arg->vc != vc_string) {205 printf("Error: Argument to Builtin.Exec() must be "206 "string (found %d).\n", arg->vc);207 exit(1);208 }209 210 cmd[idx] = arg->u.string_v->value;211 }212 213 cmd[dim] = '\0';214 215 if (os_exec((char * const *)cmd) != EOK) {216 printf("Error: Exec failed.\n");217 exit(1);218 }219 }
Note:
See TracChangeset
for help on using the changeset viewer.