Ignore:
Timestamp:
2011-03-29T20:12:44Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
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.
Message:

Merge mainline changes.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/builtin/bi_console.c

    rc4fb95d3 rd011038  
    2727 */
    2828
    29 /** @file Builtin functions. */
     29/** @file Console builtin binding. */
    3030
    3131#include <stdio.h>
     
    3636#include "../list.h"
    3737#include "../mytypes.h"
    38 #include "../os/os.h"
    3938#include "../run.h"
    4039#include "../stree.h"
     
    4241#include "../symbol.h"
    4342
    44 #include "bi_fun.h"
     43#include "bi_console.h"
    4544
    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);
     45static void bi_console_write(run_t *run);
     46static void bi_console_writeline(run_t *run);
    4947
    50 /** Declare builtin functions.
     48/** Declare Console builtin.
    5149 *
    5250 * @param bi    Builtin object
    5351 */
    54 void bi_fun_declare(builtin_t *bi)
     52void bi_console_declare(builtin_t *bi)
    5553{
    5654        stree_modm_t *modm;
     
    6361
    6462        ident = stree_ident_new();
    65         ident->sid = strtab_get_sid("Builtin");
     63        ident->sid = strtab_get_sid("Console");
    6664
    6765        csi = stree_csi_new(csi_class);
     
    8987        fun_sym = builtin_declare_fun(csi, "WriteLine");
    9088        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");
    9889}
    9990
     
    10293 * @param bi    Builtin object
    10394 */
    104 void bi_fun_bind(builtin_t *bi)
     95void bi_console_bind(builtin_t *bi)
    10596{
    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);
    10999}
    110100
     
    113103 * @param run   Runner object
    114104 */
    115 static void bi_fun_builtin_write(run_t *run)
     105static void bi_console_write(run_t *run)
    116106{
    117107        rdata_var_t *var;
     
    120110
    121111#ifdef DEBUG_RUN_TRACE
    122         printf("Called Builtin.Write()\n");
     112        printf("Called Console.Write()\n");
    123113#endif
    124114        var = run_local_vars_lookup(run, strtab_get_sid("arg"));
     
    152142 * @param run   Runner object
    153143 */
    154 static void bi_fun_builtin_writeline(run_t *run)
     144static void bi_console_writeline(run_t *run)
    155145{
    156146#ifdef DEBUG_RUN_TRACE
    157         printf("Called Builtin.WriteLine()\n");
     147        printf("Called Console.WriteLine()\n");
    158148#endif
    159         bi_fun_builtin_write(run);
     149        bi_console_write(run);
    160150        putchar('\n');
    161151}
    162 
    163 /** Start an executable and wait for it to finish.
    164  *
    165  * @param run   Runner object
    166  */
    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_TRACE
    177         printf("Called Task.Exec()\n");
    178 #endif
    179         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.