Changeset c47e1a8 in mainline for uspace/app


Ignore:
Timestamp:
2010-05-21T07:50:04Z (16 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d51ee2b
Parents:
cf8cc36 (diff), 15b592b (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 (rev. 451)

Location:
uspace/app
Files:
105 added
1 deleted
91 edited
6 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/Makefile

    rcf8cc36 rc47e1a8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBC_PREFIX)/libc.a
    32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I. -Icmds/ -Icmds/builtins -Icmds/modules
    33 
    34 OUTPUT = bdsh
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a
     32EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) -I. -Icmds/ \
     33        -Icmds/builtins -Icmds/modules
     34BINARY = bdsh
    3535
    3636SOURCES = \
     
    6060        scli.c
    6161
    62 include ../Makefile.common
     62include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/bdsh/cmds/builtin_cmds.c

    rcf8cc36 rc47e1a8  
    3434#include <stdio.h>
    3535#include <stdlib.h>
    36 #include <string.h>
     36#include <str.h>
    3737#include "errors.h"
    3838#include "cmds.h"
  • uspace/app/bdsh/cmds/builtins/builtins.h

    rcf8cc36 rc47e1a8  
    1010#include "cd/cd_def.h"
    1111#include "exit/exit_def.h"
    12         {NULL, NULL, NULL, NULL}
     12        {NULL, NULL, NULL, NULL, NULL}
    1313};
    1414
  • uspace/app/bdsh/cmds/builtins/cd/cd.c

    rcf8cc36 rc47e1a8  
    3232#include <stdlib.h>
    3333#include <unistd.h>
    34 #include <string.h>
     34#include <str.h>
    3535#include <errno.h>
    3636
     
    4141#include "cd.h"
    4242
    43 static char * cmdname = "cd";
     43static const char *cmdname = "cd";
    4444
    4545void help_cmd_cd(unsigned int level)
  • uspace/app/bdsh/cmds/builtins/cd/cd_def.h

    rcf8cc36 rc47e1a8  
    44        &cmd_cd,
    55        &help_cmd_cd,
     6        0
    67},
  • uspace/app/bdsh/cmds/builtins/exit/exit_def.h

    rcf8cc36 rc47e1a8  
    44        &cmd_exit,
    55        &help_cmd_exit,
     6        0
    67},
  • uspace/app/bdsh/cmds/cmds.h

    rcf8cc36 rc47e1a8  
    3333/* Module structure */
    3434typedef struct {
    35         char *name;         /* Name of the command */
    36         char *desc;         /* Description of the command */
     35        const char *name;   /* Name of the command */
     36        const char *desc;   /* Description of the command */
    3737        mod_entry_t entry;  /* Command (exec) entry function */
    3838        mod_help_t help;    /* Command (help) entry function */
     
    4141/* Builtin structure, same as modules except different types of entry points */
    4242typedef struct {
    43         char *name;
    44         char *desc;
     43        const char *name;
     44        const char *desc;
    4545        builtin_entry_t entry;
    4646        builtin_help_t help;
     
    5757extern int is_module(const char *);
    5858extern int is_module_alias(const char *);
    59 extern char * alias_for_module(const char *);
     59extern char *alias_for_module(const char *);
    6060extern int help_module(int, unsigned int);
    6161extern int run_module(int, char *[]);
     
    6565extern int is_builtin(const char *);
    6666extern int is_builtin_alias(const char *);
    67 extern char * alias_for_builtin(const char *);
     67extern char *alias_for_builtin(const char *);
    6868extern int help_builtin(int, unsigned int);
    6969extern int run_builtin(int, char *[], cliuser_t *);
  • uspace/app/bdsh/cmds/mod_cmds.c

    rcf8cc36 rc47e1a8  
    4747#include <stdio.h>
    4848#include <stdlib.h>
    49 #include <string.h>
     49#include <str.h>
    5050#include "errors.h"
    5151#include "cmds.h"
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    rcf8cc36 rc47e1a8  
    2929#include <stdio.h>
    3030#include <stdlib.h>
    31 #include <string.h>
     31#include <str.h>
    3232#include "config.h"
    3333#include "util.h"
     
    7373        size_t block_size;
    7474        int rc;
    75         bn_t ba;
     75        aoff64_t ba;
    7676        uint8_t b;
    7777
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    rcf8cc36 rc47e1a8  
    3333#include <unistd.h>
    3434#include <getopt.h>
    35 #include <string.h>
     35#include <str.h>
    3636#include <fcntl.h>
    3737
     
    4343#include "cmds.h"
    4444
    45 static char *cmdname = "cat";
     45static const char *cmdname = "cat";
    4646#define CAT_VERSION "0.0.1"
    4747#define CAT_DEFAULT_BUFLEN 1024
    4848
    49 static char *cat_oops = "That option is not yet supported\n";
     49static const char *cat_oops = "That option is not yet supported\n";
    5050
    5151static struct option const long_options[] = {
     
    8585{
    8686        int fd, bytes = 0, count = 0, reads = 0;
    87         off_t total = 0;
     87        off64_t total = 0;
    8888        char *buff = NULL;
    8989
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    rcf8cc36 rc47e1a8  
    3333#include <unistd.h>
    3434#include <getopt.h>
    35 #include <string.h>
     35#include <str.h>
    3636#include <fcntl.h>
    3737#include "config.h"
     
    7474{
    7575        int fd1, fd2, bytes = 0;
    76         off_t total = 0;
     76        off64_t total = 0;
    7777        int64_t copied = 0;
    7878        char *buff = NULL;
  • uspace/app/bdsh/cmds/modules/help/help.c

    rcf8cc36 rc47e1a8  
    3131#include <stdio.h>
    3232#include <stdlib.h>
    33 #include <string.h>
     33#include <str.h>
    3434
    3535#include "config.h"
     
    4242#include "util.h"
    4343
    44 static char *cmdname = "help";
     44static const char *cmdname = "help";
    4545extern const char *progname;
    4646
  • uspace/app/bdsh/cmds/modules/kcon/kcon.c

    rcf8cc36 rc47e1a8  
    4040#include "cmds.h"
    4141
    42 static char *cmdname = "kcon";
     42static const char *cmdname = "kcon";
    4343
    4444/* Dispays help for kcon in various levels */
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    rcf8cc36 rc47e1a8  
    4040#include <sys/types.h>
    4141#include <sys/stat.h>
    42 #include <string.h>
     42#include <str.h>
    4343
    4444#include "errors.h"
     
    4949#include "cmds.h"
    5050
    51 static char *cmdname = "ls";
     51static const char *cmdname = "ls";
    5252
    5353static void ls_scan_dir(const char *d, DIR *dirp)
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    rcf8cc36 rc47e1a8  
    3838#include <getopt.h>
    3939#include <stdarg.h>
    40 #include <string.h>
     40#include <str.h>
    4141
    4242#include "config.h"
     
    4949#define MKDIR_VERSION "0.0.1"
    5050
    51 static char *cmdname = "mkdir";
     51static const char *cmdname = "mkdir";
    5252
    5353static struct option const long_options[] = {
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    rcf8cc36 rc47e1a8  
    3838#include <getopt.h>
    3939#include <stdarg.h>
    40 #include <string.h>
     40#include <str.h>
    4141#include <ctype.h>
    4242
     
    5151#define BUFFER_SIZE 16384
    5252
    53 static char *cmdname = "mkfile";
     53static const char *cmdname = "mkfile";
    5454
    5555static struct option const long_options[] = {
  • uspace/app/bdsh/cmds/modules/module_aliases.h

    rcf8cc36 rc47e1a8  
    1212 * the entry point being reached. */
    1313
    14 char *mod_aliases[] = {
     14const char *mod_aliases[] = {
    1515        "ren", "mv",
    1616        "umount", "unmount",
  • uspace/app/bdsh/cmds/modules/mount/mount.c

    rcf8cc36 rc47e1a8  
    5858{
    5959        unsigned int argc;
    60         char *mopts = "";
     60        const char *mopts = "";
    6161        int rc;
    6262
  • uspace/app/bdsh/cmds/modules/pwd/pwd.c

    rcf8cc36 rc47e1a8  
    3939#include "pwd.h"
    4040
    41 static char * cmdname = "pwd";
     41static const char *cmdname = "pwd";
    4242
    4343void help_cmd_pwd(unsigned int level)
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    rcf8cc36 rc47e1a8  
    3636#include <getopt.h>
    3737#include <mem.h>
    38 #include <string.h>
     38#include <str.h>
    3939
    4040#include "config.h"
     
    4545#include "cmds.h"
    4646
    47 static char *cmdname = "rm";
     47static const char *cmdname = "rm";
    4848#define RM_VERSION "0.0.1"
    4949
  • uspace/app/bdsh/cmds/modules/sleep/sleep.c

    rcf8cc36 rc47e1a8  
    3838#include "cmds.h"
    3939
    40 static char *cmdname = "sleep";
     40static const char *cmdname = "sleep";
    4141
    4242/* Dispays help for sleep in various levels */
  • uspace/app/bdsh/cmds/modules/touch/touch.c

    rcf8cc36 rc47e1a8  
    3838#include <dirent.h>
    3939#include <sys/types.h>
    40 #include <string.h>
     40#include <str.h>
    4141
    4242#include "config.h"
     
    4747#include "cmds.h"
    4848
    49 static char *cmdname = "touch";
     49static const char *cmdname = "touch";
    5050
    5151/* Dispays help for touch in various levels */
  • uspace/app/bdsh/errors.c

    rcf8cc36 rc47e1a8  
    3030
    3131#include <stdio.h>
    32 #include <string.h>
     32#include <str.h>
    3333#include <stdlib.h>
    3434#include <unistd.h>
     
    4747/* Look up errno in cl_errors and return the corresponding string.
    4848 * Return NULL if not found */
    49 static char *err2str(int err)
     49static const char *err2str(int err)
    5050{
    5151
  • uspace/app/bdsh/errstr.h

    rcf8cc36 rc47e1a8  
    44/* Simple array to translate error codes to meaningful strings */
    55
    6 static char *cl_errors[] = {
     6static const char *cl_errors[] = {
    77        "Success",
    88        "Failure",
     
    1818};
    1919
    20 static char *err2str(int);
     20static const char *err2str(int);
    2121
    2222#endif
  • uspace/app/bdsh/exec.c

    rcf8cc36 rc47e1a8  
    3838#include <stdlib.h>
    3939#include <unistd.h>
    40 #include <string.h>
     40#include <str.h>
    4141#include <fcntl.h>
     42#include <str_error.h>
    4243
    4344#include "config.h"
     
    120121        free(found);
    121122
    122         tid = task_spawn((const char *)tmp, argv);
     123        tid = task_spawn(tmp, (const char **) argv, &retval);
    123124        free(tmp);
    124125
    125126        if (tid == 0) {
    126                 cli_error(CL_EEXEC, "Cannot spawn `%s'.", cmd);
     127                cli_error(CL_EEXEC, "%s: Cannot spawn `%s' (%s)", progname, cmd,
     128                    str_error(retval));
    127129                return 1;
    128130        }
     
    130132        task_wait(tid, &texit, &retval);
    131133        if (texit != TASK_EXIT_NORMAL) {
    132                 printf("Command failed (unexpectedly terminated).\n");
     134                printf("%s: Command failed (unexpectedly terminated)\n", progname);
    133135        } else if (retval != 0) {
    134                 printf("Command failed (return value %d).\n", retval);
     136                printf("%s: Command failed (%s)\n",
     137                    progname, str_error(retval));
    135138        }
    136139
  • uspace/app/bdsh/exec.h

    rcf8cc36 rc47e1a8  
    55
    66extern unsigned int try_exec(char *, char **);
     7
    78#endif
  • uspace/app/bdsh/input.c

    rcf8cc36 rc47e1a8  
    11/* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
    22 * All rights reserved.
    3  * Copyright (c) 2008, Jiri Svoboda - All Rights Reserved
    43 *
    54 * Redistribution and use in source and binary forms, with or without
     
    3231#include <stdio.h>
    3332#include <stdlib.h>
    34 #include <string.h>
     33#include <str.h>
    3534#include <io/console.h>
    3635#include <io/keycode.h>
     
    4342#include <assert.h>
    4443#include <bool.h>
     44#include <tinput.h>
    4545
    4646#include "config.h"
     
    5151#include "exec.h"
    5252
    53 #define HISTORY_LEN 10
     53extern volatile unsigned int cli_quit;
    5454
    5555/** Text input field. */
    56 typedef struct {
    57         /** Buffer holding text currently being edited */
    58         wchar_t buffer[INPUT_MAX + 1];
    59         /** Screen coordinates of the top-left corner of the text field */
    60         int col0, row0;
    61         /** Screen dimensions */
    62         int con_cols, con_rows;
    63         /** Number of characters in @c buffer */
    64         int nc;
    65         /** Caret position within buffer */
    66         int pos;
    67         /** Selection mark position within buffer */
    68         int sel_start;
    69 
    70         /** History (dynamically allocated strings) */
    71         char *history[1 + HISTORY_LEN];
    72         /** Number of entries in @c history, not counting [0] */
    73         int hnum;
    74         /** Current position in history */
    75         int hpos;
    76         /** Exit flag */
    77         bool done;
    78 } tinput_t;
    79 
    80 /** Seek direction */
    81 typedef enum {
    82         seek_backward = -1,
    83         seek_forward = 1
    84 } seek_dir_t;
    85 
    86 static tinput_t tinput;
    87 
    88 static char *tinput_read(tinput_t *ti);
    89 static void tinput_insert_string(tinput_t *ti, const char *str);
    90 static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb);
    91 static bool tinput_sel_active(tinput_t *ti);
    92 static void tinput_sel_all(tinput_t *ti);
    93 static void tinput_sel_delete(tinput_t *ti);
    94 static void tinput_key_ctrl(tinput_t *ti, console_event_t *ev);
    95 static void tinput_key_shift(tinput_t *ti, console_event_t *ev);
    96 static void tinput_key_ctrl_shift(tinput_t *ti, console_event_t *ev);
    97 static void tinput_key_unmod(tinput_t *ti, console_event_t *ev);
    98 static void tinput_pre_seek(tinput_t *ti, bool shift_held);
    99 static void tinput_post_seek(tinput_t *ti, bool shift_held);
     56static tinput_t *tinput;
    10057
    10158/* Tokenizes input from console, sees if the first word is a built-in, if so
     
    149106}
    150107
    151 static void tinput_display_tail(tinput_t *ti, int start, int pad)
    152 {
    153         static wchar_t dbuf[INPUT_MAX + 1];
    154         int sa, sb;
    155         int i, p;
    156 
    157         tinput_sel_get_bounds(ti, &sa, &sb);
    158 
    159         console_goto(fphone(stdout), (ti->col0 + start) % ti->con_cols,
    160             ti->row0 + (ti->col0 + start) / ti->con_cols);
    161         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
    162 
    163         p = start;
    164         if (p < sa) {
    165                 memcpy(dbuf, ti->buffer + p, (sa - p) * sizeof(wchar_t));
    166                 dbuf[sa - p] = '\0';
    167                 printf("%ls", dbuf);
    168                 p = sa;
    169         }
    170 
    171         if (p < sb) {
    172                 fflush(stdout);
    173                 console_set_color(fphone(stdout), COLOR_BLACK, COLOR_RED, 0);
    174                 memcpy(dbuf, ti->buffer + p,
    175                     (sb - p) * sizeof(wchar_t));
    176                 dbuf[sb - p] = '\0';
    177                 printf("%ls", dbuf);
    178                 p = sb;
    179         }
    180 
    181         fflush(stdout);
    182         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
    183 
    184         if (p < ti->nc) {
    185                 memcpy(dbuf, ti->buffer + p,
    186                     (ti->nc - p) * sizeof(wchar_t));
    187                 dbuf[ti->nc - p] = '\0';
    188                 printf("%ls", dbuf);
    189         }
    190 
    191         for (i = 0; i < pad; ++i)
    192                 putchar(' ');
    193         fflush(stdout);
    194 }
    195 
    196 static char *tinput_get_str(tinput_t *ti)
    197 {
    198         return wstr_to_astr(ti->buffer);
    199 }
    200 
    201 static void tinput_position_caret(tinput_t *ti)
    202 {
    203         console_goto(fphone(stdout), (ti->col0 + ti->pos) % ti->con_cols,
    204             ti->row0 + (ti->col0 + ti->pos) / ti->con_cols);
    205 }
    206 
    207 /** Update row0 in case the screen could have scrolled. */
    208 static void tinput_update_origin(tinput_t *ti)
    209 {
    210         int width, rows;
    211 
    212         width = ti->col0 + ti->nc;
    213         rows = (width / ti->con_cols) + 1;
    214 
    215         /* Update row0 if the screen scrolled. */
    216         if (ti->row0 + rows > ti->con_rows)
    217                 ti->row0 = ti->con_rows - rows;
    218 }
    219 
    220 static void tinput_insert_char(tinput_t *ti, wchar_t c)
    221 {
    222         int i;
    223         int new_width, new_height;
    224 
    225         if (ti->nc == INPUT_MAX)
    226                 return;
    227 
    228         new_width = ti->col0 + ti->nc + 1;
    229         if (new_width % ti->con_cols == 0) {
    230                 /* Advancing to new line. */
    231                 new_height = (new_width / ti->con_cols) + 1;
    232                 if (new_height >= ti->con_rows)
    233                         return; /* Disallow text longer than 1 page for now. */
    234         }
    235 
    236         for (i = ti->nc; i > ti->pos; --i)
    237                 ti->buffer[i] = ti->buffer[i - 1];
    238 
    239         ti->buffer[ti->pos] = c;
    240         ti->pos += 1;
    241         ti->nc += 1;
    242         ti->buffer[ti->nc] = '\0';
    243         ti->sel_start = ti->pos;
    244 
    245         tinput_display_tail(ti, ti->pos - 1, 0);
    246         tinput_update_origin(ti);
    247         tinput_position_caret(ti);
    248 }
    249 
    250 static void tinput_insert_string(tinput_t *ti, const char *str)
    251 {
    252         int i;
    253         int new_width, new_height;
    254         int ilen;
    255         wchar_t c;
    256         size_t off;
    257 
    258         ilen = min((ssize_t) str_length(str), INPUT_MAX - ti->nc);
    259         if (ilen == 0)
    260                 return;
    261 
    262         new_width = ti->col0 + ti->nc + ilen;
    263         new_height = (new_width / ti->con_cols) + 1;
    264         if (new_height >= ti->con_rows)
    265                 return; /* Disallow text longer than 1 page for now. */
    266 
    267         for (i = ti->nc - 1; i >= ti->pos; --i)
    268                 ti->buffer[i + ilen] = ti->buffer[i];
    269 
    270         off = 0; i = 0;
    271         while (i < ilen) {
    272                 c = str_decode(str, &off, STR_NO_LIMIT);
    273                 if (c == '\0')
    274                         break;
    275 
    276                 /* Filter out non-printable chars. */
    277                 if (c < 32)
    278                         c = 32;
    279 
    280                 ti->buffer[ti->pos + i] = c;
    281                 ++i;
    282         }
    283 
    284         ti->pos += ilen;
    285         ti->nc += ilen;
    286         ti->buffer[ti->nc] = '\0';
    287         ti->sel_start = ti->pos;
    288 
    289         tinput_display_tail(ti, ti->pos - ilen, 0);
    290         tinput_update_origin(ti);
    291         tinput_position_caret(ti);
    292 }
    293 
    294 static void tinput_backspace(tinput_t *ti)
    295 {
    296         int i;
    297 
    298         if (tinput_sel_active(ti)) {
    299                 tinput_sel_delete(ti);
    300                 return;
    301         }
    302 
    303         if (ti->pos == 0)
    304                 return;
    305 
    306         for (i = ti->pos; i < ti->nc; ++i)
    307                 ti->buffer[i - 1] = ti->buffer[i];
    308         ti->pos -= 1;
    309         ti->nc -= 1;
    310         ti->buffer[ti->nc] = '\0';
    311         ti->sel_start = ti->pos;
    312 
    313         tinput_display_tail(ti, ti->pos, 1);
    314         tinput_position_caret(ti);
    315 }
    316 
    317 static void tinput_delete(tinput_t *ti)
    318 {
    319         if (tinput_sel_active(ti)) {
    320                 tinput_sel_delete(ti);
    321                 return;
    322         }
    323 
    324         if (ti->pos == ti->nc)
    325                 return;
    326 
    327         ti->pos += 1;
    328         ti->sel_start = ti->pos;
    329 
    330         tinput_backspace(ti);
    331 }
    332 
    333 static void tinput_seek_cell(tinput_t *ti, seek_dir_t dir, bool shift_held)
    334 {
    335         tinput_pre_seek(ti, shift_held);
    336 
    337         if (dir == seek_forward) {
    338                 if (ti->pos < ti->nc)
    339                         ti->pos += 1;
    340         } else {
    341                 if (ti->pos > 0)
    342                         ti->pos -= 1;
    343         }
    344 
    345         tinput_post_seek(ti, shift_held);
    346 }
    347 
    348 static void tinput_seek_word(tinput_t *ti, seek_dir_t dir, bool shift_held)
    349 {
    350         tinput_pre_seek(ti, shift_held);
    351 
    352         if (dir == seek_forward) {
    353                 if (ti->pos == ti->nc)
    354                         return;
    355 
    356                 while (1) {
    357                         ti->pos += 1;
    358 
    359                         if (ti->pos == ti->nc)
    360                                 break;
    361 
    362                         if (ti->buffer[ti->pos - 1] == ' ' &&
    363                             ti->buffer[ti->pos] != ' ')
    364                                 break;
    365                 }
    366         } else {
    367                 if (ti->pos == 0)
    368                         return;
    369 
    370                 while (1) {
    371                         ti->pos -= 1;
    372 
    373                         if (ti->pos == 0)
    374                                 break;
    375 
    376                         if (ti->buffer[ti->pos - 1] == ' ' &&
    377                             ti->buffer[ti->pos] != ' ')
    378                                 break;
    379                 }
    380 
    381         }
    382 
    383         tinput_post_seek(ti, shift_held);
    384 }
    385 
    386 static void tinput_seek_vertical(tinput_t *ti, seek_dir_t dir, bool shift_held)
    387 {
    388         tinput_pre_seek(ti, shift_held);
    389 
    390         if (dir == seek_forward) {
    391                 if (ti->pos + ti->con_cols <= ti->nc)
    392                         ti->pos = ti->pos + ti->con_cols;
    393         } else {
    394                 if (ti->pos - ti->con_cols >= 0)
    395                         ti->pos = ti->pos - ti->con_cols;
    396         }
    397 
    398         tinput_post_seek(ti, shift_held);
    399 }
    400 
    401 static void tinput_seek_max(tinput_t *ti, seek_dir_t dir, bool shift_held)
    402 {
    403         tinput_pre_seek(ti, shift_held);
    404 
    405         if (dir == seek_backward)
    406                 ti->pos = 0;
    407         else
    408                 ti->pos = ti->nc;
    409 
    410         tinput_post_seek(ti, shift_held);
    411 }
    412 
    413 static void tinput_pre_seek(tinput_t *ti, bool shift_held)
    414 {
    415         if (tinput_sel_active(ti) && !shift_held) {
    416                 /* Unselect and redraw. */
    417                 ti->sel_start = ti->pos;
    418                 tinput_display_tail(ti, 0, 0);
    419                 tinput_position_caret(ti);
    420         }
    421 }
    422 
    423 static void tinput_post_seek(tinput_t *ti, bool shift_held)
    424 {
    425         if (shift_held) {
    426                 /* Selecting text. Need redraw. */
    427                 tinput_display_tail(ti, 0, 0);
    428         } else {
    429                 /* Shift not held. Keep selection empty. */
    430                 ti->sel_start = ti->pos;
    431         }
    432         tinput_position_caret(ti);
    433 }
    434 
    435 static void tinput_history_insert(tinput_t *ti, char *str)
    436 {
    437         int i;
    438 
    439         if (ti->hnum < HISTORY_LEN) {
    440                 ti->hnum += 1;
    441         } else {
    442                 if (ti->history[HISTORY_LEN] != NULL)
    443                         free(ti->history[HISTORY_LEN]);
    444         }
    445 
    446         for (i = ti->hnum; i > 1; --i)
    447                 ti->history[i] = ti->history[i - 1];
    448 
    449         ti->history[1] = str_dup(str);
    450 
    451         if (ti->history[0] != NULL) {
    452                 free(ti->history[0]);
    453                 ti->history[0] = NULL;
    454         }
    455 }
    456 
    457 static void tinput_set_str(tinput_t *ti, char *str)
    458 {
    459         str_to_wstr(ti->buffer, INPUT_MAX, str);
    460         ti->nc = wstr_length(ti->buffer);
    461         ti->pos = ti->nc;
    462         ti->sel_start = ti->pos;
    463 }
    464 
    465 static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb)
    466 {
    467         if (ti->sel_start < ti->pos) {
    468                 *sa = ti->sel_start;
    469                 *sb = ti->pos;
    470         } else {
    471                 *sa = ti->pos;
    472                 *sb = ti->sel_start;
    473         }
    474 }
    475 
    476 static bool tinput_sel_active(tinput_t *ti)
    477 {
    478         return ti->sel_start != ti->pos;
    479 }
    480 
    481 static void tinput_sel_all(tinput_t *ti)
    482 {
    483         ti->sel_start = 0;
    484         ti->pos = ti->nc;
    485         tinput_display_tail(ti, 0, 0);
    486         tinput_position_caret(ti);
    487 }
    488 
    489 static void tinput_sel_delete(tinput_t *ti)
    490 {
    491         int sa, sb;
    492 
    493         tinput_sel_get_bounds(ti, &sa, &sb);
    494         if (sa == sb)
    495                 return;
    496 
    497         memmove(ti->buffer + sa, ti->buffer + sb,
    498             (ti->nc - sb) * sizeof(wchar_t));
    499         ti->pos = ti->sel_start = sa;
    500         ti->nc -= (sb - sa);
    501         ti->buffer[ti->nc] = '\0';
    502 
    503         tinput_display_tail(ti, sa, sb - sa);
    504         tinput_position_caret(ti);
    505 }
    506 
    507 static void tinput_sel_copy_to_cb(tinput_t *ti)
    508 {
    509         int sa, sb;
    510         wchar_t tmp_c;
    511         char *str;
    512 
    513         tinput_sel_get_bounds(ti, &sa, &sb);
    514 
    515         if (sb < ti->nc) {
    516                 tmp_c = ti->buffer[sb];
    517                 ti->buffer[sb] = '\0';
    518         }
    519 
    520         str = wstr_to_astr(ti->buffer + sa);
    521 
    522         if (sb < ti->nc)
    523                 ti->buffer[sb] = tmp_c;
    524 
    525         if (str == NULL)
    526                 goto error;
    527 
    528         if (clipboard_put_str(str) != EOK)
    529                 goto error;
    530 
    531         free(str);
    532         return;
    533 error:
    534         return;
    535         /* TODO: Give the user some warning. */
    536 }
    537 
    538 static void tinput_paste_from_cb(tinput_t *ti)
     108void get_input(cliuser_t *usr)
    539109{
    540110        char *str;
    541111        int rc;
    542 
    543         rc = clipboard_get_str(&str);
    544         if (rc != EOK || str == NULL)
    545                 return; /* TODO: Give the user some warning. */
    546 
    547         tinput_insert_string(ti, str);
    548         free(str);
    549 }
    550 
    551 static void tinput_history_seek(tinput_t *ti, int offs)
    552 {
    553         int pad;
    554 
    555         if (ti->hpos + offs < 0 || ti->hpos + offs > ti->hnum)
    556                 return;
    557 
    558         if (ti->history[ti->hpos] != NULL) {
    559                 free(ti->history[ti->hpos]);
    560                 ti->history[ti->hpos] = NULL;
    561         }
    562 
    563         ti->history[ti->hpos] = tinput_get_str(ti);
    564         ti->hpos += offs;
    565 
    566         pad = ti->nc - str_length(ti->history[ti->hpos]);
    567         if (pad < 0) pad = 0;
    568 
    569         tinput_set_str(ti, ti->history[ti->hpos]);
    570         tinput_display_tail(ti, 0, pad);
    571         tinput_update_origin(ti);
    572         tinput_position_caret(ti);
    573 }
    574 
    575 /** Initialize text input field.
    576  *
    577  * Must be called before using the field. It clears the history.
    578  */
    579 static void tinput_init(tinput_t *ti)
    580 {
    581         ti->hnum = 0;
    582         ti->hpos = 0;
    583         ti->history[0] = NULL;
    584 }
    585 
    586 /** Read in one line of input. */
    587 static char *tinput_read(tinput_t *ti)
    588 {
    589         console_event_t ev;
    590         char *str;
    591 
    592         fflush(stdout);
    593 
    594         if (console_get_size(fphone(stdin), &ti->con_cols, &ti->con_rows) != EOK)
    595                 return NULL;
    596         if (console_get_pos(fphone(stdin), &ti->col0, &ti->row0) != EOK)
    597                 return NULL;
    598 
    599         ti->pos = ti->sel_start = 0;
    600         ti->nc = 0;
    601         ti->buffer[0] = '\0';
    602         ti->done = false;
    603 
    604         while (!ti->done) {
    605                 fflush(stdout);
    606                 if (!console_get_event(fphone(stdin), &ev))
    607                         return NULL;
    608 
    609                 if (ev.type != KEY_PRESS)
    610                         continue;
    611 
    612                 if ((ev.mods & KM_CTRL) != 0 &&
    613                     (ev.mods & (KM_ALT | KM_SHIFT)) == 0) {
    614                         tinput_key_ctrl(ti, &ev);
    615                 }
    616 
    617                 if ((ev.mods & KM_SHIFT) != 0 &&
    618                     (ev.mods & (KM_CTRL | KM_ALT)) == 0) {
    619                         tinput_key_shift(ti, &ev);
    620                 }
    621 
    622                 if ((ev.mods & KM_CTRL) != 0 &&
    623                     (ev.mods & KM_SHIFT) != 0 &&
    624                     (ev.mods & KM_ALT) == 0) {
    625                         tinput_key_ctrl_shift(ti, &ev);
    626                 }
    627 
    628                 if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
    629                         tinput_key_unmod(ti, &ev);
    630                 }
    631 
    632                 if (ev.c >= ' ') {
    633                         tinput_sel_delete(ti);
    634                         tinput_insert_char(ti, ev.c);
    635                 }
    636         }
    637 
    638         ti->pos = ti->nc;
    639         tinput_position_caret(ti);
    640         putchar('\n');
    641 
    642         str = tinput_get_str(ti);
    643         if (str_cmp(str, "") != 0)
    644                 tinput_history_insert(ti, str);
    645 
    646         ti->hpos = 0;
    647 
    648         return str;
    649 }
    650 
    651 static void tinput_key_ctrl(tinput_t *ti, console_event_t *ev)
    652 {
    653         switch (ev->key) {
    654         case KC_LEFT:
    655                 tinput_seek_word(ti, seek_backward, false);
    656                 break;
    657         case KC_RIGHT:
    658                 tinput_seek_word(ti, seek_forward, false);
    659                 break;
    660         case KC_UP:
    661                 tinput_seek_vertical(ti, seek_backward, false);
    662                 break;
    663         case KC_DOWN:
    664                 tinput_seek_vertical(ti, seek_forward, false);
    665                 break;
    666         case KC_X:
    667                 tinput_sel_copy_to_cb(ti);
    668                 tinput_sel_delete(ti);
    669                 break;
    670         case KC_C:
    671                 tinput_sel_copy_to_cb(ti);
    672                 break;
    673         case KC_V:
    674                 tinput_sel_delete(ti);
    675                 tinput_paste_from_cb(ti);
    676                 break;
    677         case KC_A:
    678                 tinput_sel_all(ti);
    679                 break;
    680         default:
    681                 break;
    682         }
    683 }
    684 
    685 static void tinput_key_ctrl_shift(tinput_t *ti, console_event_t *ev)
    686 {
    687         switch (ev->key) {
    688         case KC_LEFT:
    689                 tinput_seek_word(ti, seek_backward, true);
    690                 break;
    691         case KC_RIGHT:
    692                 tinput_seek_word(ti, seek_forward, true);
    693                 break;
    694         case KC_UP:
    695                 tinput_seek_vertical(ti, seek_backward, true);
    696                 break;
    697         case KC_DOWN:
    698                 tinput_seek_vertical(ti, seek_forward, true);
    699                 break;
    700         default:
    701                 break;
    702         }
    703 }
    704 
    705 static void tinput_key_shift(tinput_t *ti, console_event_t *ev)
    706 {
    707         switch (ev->key) {
    708         case KC_LEFT:
    709                 tinput_seek_cell(ti, seek_backward, true);
    710                 break;
    711         case KC_RIGHT:
    712                 tinput_seek_cell(ti, seek_forward, true);
    713                 break;
    714         case KC_UP:
    715                 tinput_seek_vertical(ti, seek_backward, true);
    716                 break;
    717         case KC_DOWN:
    718                 tinput_seek_vertical(ti, seek_forward, true);
    719                 break;
    720         case KC_HOME:
    721                 tinput_seek_max(ti, seek_backward, true);
    722                 break;
    723         case KC_END:
    724                 tinput_seek_max(ti, seek_forward, true);
    725                 break;
    726         default:
    727                 break;
    728         }
    729 }
    730 
    731 static void tinput_key_unmod(tinput_t *ti, console_event_t *ev)
    732 {
    733         switch (ev->key) {
    734         case KC_ENTER:
    735         case KC_NENTER:
    736                 ti->done = true;
    737                 break;
    738         case KC_BACKSPACE:
    739                 tinput_backspace(ti);
    740                 break;
    741         case KC_DELETE:
    742                 tinput_delete(ti);
    743                 break;
    744         case KC_LEFT:
    745                 tinput_seek_cell(ti, seek_backward, false);
    746                 break;
    747         case KC_RIGHT:
    748                 tinput_seek_cell(ti, seek_forward, false);
    749                 break;
    750         case KC_HOME:
    751                 tinput_seek_max(ti, seek_backward, false);
    752                 break;
    753         case KC_END:
    754                 tinput_seek_max(ti, seek_forward, false);
    755                 break;
    756         case KC_UP:
    757                 tinput_history_seek(ti, +1);
    758                 break;
    759         case KC_DOWN:
    760                 tinput_history_seek(ti, -1);
    761                 break;
    762         default:
    763                 break;
    764         }
    765 }
    766 
    767 void get_input(cliuser_t *usr)
    768 {
    769         char *str;
    770112
    771113        fflush(stdout);
     
    775117        console_set_style(fphone(stdout), STYLE_NORMAL);
    776118
    777         str = tinput_read(&tinput);
     119        rc = tinput_read(tinput, &str);
     120        if (rc == ENOENT) {
     121                /* User requested exit */
     122                cli_quit = 1;
     123                putchar('\n');
     124                return;
     125        }
     126
     127        if (rc != EOK) {
     128                /* Error in communication with console */
     129                return;
     130        }
    778131
    779132        /* Check for empty input. */
     
    787140}
    788141
    789 void input_init(void)
     142int input_init(void)
    790143{
    791         tinput_init(&tinput);
     144        tinput = tinput_new();
     145        if (tinput == NULL) {
     146                printf("Failed to initialize input.\n");
     147                return 1;
     148        }
     149
     150        return 0;
    792151}
  • uspace/app/bdsh/input.h

    rcf8cc36 rc47e1a8  
    88extern void get_input(cliuser_t *);
    99extern int tok_input(cliuser_t *);
    10 extern void input_init(void);
     10extern int input_init(void);
    1111
    1212#endif
  • uspace/app/bdsh/scli.c

    rcf8cc36 rc47e1a8  
    3131#include <stdio.h>
    3232#include <stdlib.h>
    33 #include <string.h>
     33#include <str.h>
    3434#include <unistd.h>
    3535#include "config.h"
     
    6565        usr->lasterr = 0;
    6666
    67         input_init();
     67        if (input_init() != 0)
     68                return 1;
    6869
    6970        return (int) cli_set_prompt(usr);
     
    99100                }
    100101        }
    101         goto finit;
    102102
    103 finit:
     103        printf("Leaving %s.\n", progname);
     104
    104105        cli_finit(&usr);
    105106        return ret;
  • uspace/app/bdsh/scli.h

    rcf8cc36 rc47e1a8  
    66
    77typedef struct {
    8         char *name;
     8        const char *name;
    99        char *line;
    1010        char *cwd;
     
    1313} cliuser_t;
    1414
     15extern const char *progname;
     16
    1517#endif
  • uspace/app/bdsh/util.c

    rcf8cc36 rc47e1a8  
    2929
    3030#include <stdio.h>
    31 #include <string.h>
     31#include <str.h>
    3232#include <stdarg.h>
    3333#include <stdlib.h>
  • uspace/app/edit/Makefile

    rcf8cc36 rc47e1a8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBC_PREFIX)/libc.a
    32 
    33 OUTPUT = edit
     31BINARY = edit
    3432
    3533SOURCES = \
     
    3735        sheet.c
    3836
    39 include ../Makefile.common
     37include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/edit/edit.c

    rcf8cc36 rc47e1a8  
    4040#include <vfs/vfs.h>
    4141#include <io/console.h>
    42 #include <io/color.h>
     42#include <io/style.h>
    4343#include <io/keycode.h>
    4444#include <errno.h>
     
    100100static bool cursor_visible;
    101101
    102 static int scr_rows, scr_columns;
     102static ipcarg_t scr_rows;
     103static ipcarg_t scr_columns;
    103104
    104105#define ROW_BUF_SIZE 4096
     
    475476static void file_save_as(void)
    476477{
    477         char *old_fname, *fname;
    478         int rc;
    479 
    480         old_fname = (doc.file_name != NULL) ? doc.file_name : "";
     478        const char *old_fname = (doc.file_name != NULL) ? doc.file_name : "";
     479        char *fname;
     480       
    481481        fname = filename_prompt("Save As", old_fname);
    482482        if (fname == NULL) {
     
    485485        }
    486486
    487         rc = file_save(fname);
     487        int rc = file_save(fname);
    488488        if (rc != EOK)
    489489                return;
     
    506506        asprintf(&str, "%s: %s", prompt, init_value);
    507507        status_display(str);
    508         console_goto(con, 1 + str_length(str), scr_rows - 1);
     508        console_set_pos(con, 1 + str_length(str), scr_rows - 1);
    509509        free(str);
    510510
    511         console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
     511        console_set_style(con, STYLE_INVERTED);
    512512
    513513        max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt));
     
    553553        str = wstr_to_astr(buffer);
    554554
    555         console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     555        console_set_style(con, STYLE_NORMAL);
    556556
    557557        return str;
     
    672672{
    673673        int sh_rows, rows;
    674         int i, j;
    675674
    676675        sheet_get_num_rows(&doc.sh, &sh_rows);
     
    679678        /* Draw rows from the sheet. */
    680679
    681         console_goto(con, 0, 0);
     680        console_set_pos(con, 0, 0);
    682681        pane_row_range_display(0, rows);
    683682
    684683        /* Clear the remaining rows if file is short. */
    685 
     684       
     685        int i;
     686        ipcarg_t j;
    686687        for (i = rows; i < pane.rows; ++i) {
    687                 console_goto(con, 0, i);
     688                console_set_pos(con, 0, i);
    688689                for (j = 0; j < scr_columns; ++j)
    689690                        putchar(' ');
     
    718719        wchar_t c;
    719720        size_t pos, size;
    720         unsigned s_column;
     721        int s_column;
    721722        coord_t csel_start, csel_end, ctmp;
    722723
     
    737738        /* Draw rows from the sheet. */
    738739
    739         console_goto(con, 0, 0);
     740        console_set_pos(con, 0, 0);
    740741        for (i = r0; i < r1; ++i) {
    741742                /* Starting point for row display */
     
    757758                    coord_cmp(&rbc, &csel_end) < 0) {
    758759                        fflush(stdout);
    759                         console_set_color(con, COLOR_BLACK, COLOR_RED, 0);
     760                        console_set_style(con, STYLE_SELECTED);
    760761                        fflush(stdout);
    761762                }
    762763
    763                 console_goto(con, 0, i);
     764                console_set_pos(con, 0, i);
    764765                size = str_size(row_buf);
    765766                pos = 0;
    766767                s_column = pane.sh_column;
    767768                while (pos < size) {
    768                         if (csel_start.row == rbc.row && csel_start.column == s_column) {
     769                        if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) {
    769770                                fflush(stdout);
    770                                 console_set_color(con, COLOR_BLACK, COLOR_RED, 0);
     771                                console_set_style(con, STYLE_SELECTED);
    771772                                fflush(stdout);
    772773                        }
    773774       
    774                         if (csel_end.row == rbc.row && csel_end.column == s_column) {
     775                        if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
    775776                                fflush(stdout);
    776                                 console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     777                                console_set_style(con, STYLE_NORMAL);
    777778                                fflush(stdout);
    778779                        }
     
    792793                }
    793794
    794                 if (csel_end.row == rbc.row && csel_end.column == s_column) {
     795                if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
    795796                        fflush(stdout);
    796                         console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     797                        console_set_style(con, STYLE_NORMAL);
    797798                        fflush(stdout);
    798799                }
     
    808809                        putchar(' ');
    809810                fflush(stdout);
    810                 console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     811                console_set_style(con, STYLE_NORMAL);
    811812        }
    812813
     
    819820        spt_t caret_pt;
    820821        coord_t coord;
    821         char *fname;
    822         int n;
    823822
    824823        tag_get_pt(&pane.caret_pos, &caret_pt);
    825824        spt_get_coord(&caret_pt, &coord);
    826825
    827         fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>";
    828 
    829         console_goto(con, 0, scr_rows - 1);
    830         console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
    831         n = printf(" %d, %d: File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
     826        const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>";
     827
     828        console_set_pos(con, 0, scr_rows - 1);
     829        console_set_style(con, STYLE_INVERTED);
     830        int n = printf(" %d, %d: File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
    832831            "Ctrl-E Save As", coord.row, coord.column, fname);
    833832        printf("%*s", scr_columns - 1 - n, "");
    834833        fflush(stdout);
    835         console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     834        console_set_style(con, STYLE_NORMAL);
    836835
    837836        pane.rflags |= REDRAW_CARET;
     
    847846
    848847        spt_get_coord(&caret_pt, &coord);
    849         console_goto(con, coord.column - pane.sh_column,
     848        console_set_pos(con, coord.column - pane.sh_column,
    850849            coord.row - pane.sh_row);
    851850}
     
    11521151static void status_display(char const *str)
    11531152{
    1154         console_goto(con, 0, scr_rows - 1);
    1155         console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
     1153        console_set_pos(con, 0, scr_rows - 1);
     1154        console_set_style(con, STYLE_INVERTED);
    11561155        printf(" %*s ", -(scr_columns - 3), str);
    11571156        fflush(stdout);
    1158         console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     1157        console_set_style(con, STYLE_NORMAL);
    11591158
    11601159        pane.rflags |= REDRAW_CARET;
  • uspace/app/edit/sheet.c

    rcf8cc36 rc47e1a8  
    5050
    5151#include <stdlib.h>
    52 #include <string.h>
     52#include <str.h>
    5353#include <errno.h>
    5454#include <adt/list.h>
  • uspace/app/getterm/Makefile

    rcf8cc36 rc47e1a8  
    2828#
    2929
    30 include ../../../version
    31 DEFS += -DRELEASE=$(RELEASE) "-DNAME=$(NAME)"
    32 
    3330USPACE_PREFIX = ../..
    34 LIBS = $(LIBC_PREFIX)/libc.a
    35 
    36 OUTPUT = getterm
     31DEFS = -DRELEASE=$(RELEASE) "-DNAME=$(NAME)"
     32BINARY = getterm
    3733
    3834SOURCES = \
     
    4036        version.c
    4137
    42 include ../Makefile.common
     38include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/getterm/getterm.c

    rcf8cc36 rc47e1a8  
    4040#include <stdio.h>
    4141#include <task.h>
     42#include <str_error.h>
    4243#include "version.h"
     44
     45#define APP_NAME  "getterm"
    4346
    4447static void usage(void)
    4548{
    46         printf("Usage: getterm <terminal> <path>\n");
     49        printf("Usage: %s <terminal> <path>\n", APP_NAME);
    4750}
    4851
     
    6972}
    7073
    71 static task_id_t spawn(char *fname)
     74static task_id_t spawn(const char *fname)
    7275{
    73         char *args[2];
     76        const char *args[2];
    7477       
    7578        args[0] = fname;
    7679        args[1] = NULL;
    7780       
    78         task_id_t id = task_spawn(fname, args);
     81        int err;
     82        task_id_t id = task_spawn(fname, args, &err);
    7983       
    8084        if (id == 0)
    81                 printf("Error spawning %s\n", fname);
     85                printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,
     86                    str_error(err));
    8287       
    8388        return id;
  • uspace/app/getterm/version.c

    rcf8cc36 rc47e1a8  
    4040#include "version.h"
    4141
    42 static char *release = STRING(RELEASE);
    43 static char *name = STRING(NAME);
    44 static char *arch = STRING(UARCH);
     42static const char *release = STRING(RELEASE);
     43static const char *name = STRING(NAME);
     44static const char *arch = STRING(UARCH);
    4545
    4646#ifdef REVISION
    47         static char *revision = ", revision " STRING(REVISION);
     47        static const char *revision = ", revision " STRING(REVISION);
    4848#else
    49         static char *revision = "";
     49        static const char *revision = "";
    5050#endif
    5151
    5252#ifdef TIMESTAMP
    53         static char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
     53        static const char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
    5454#else
    55         static char *timestamp = "";
     55        static const char *timestamp = "";
    5656#endif
    5757
  • uspace/app/init/Makefile

    rcf8cc36 rc47e1a8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBC_PREFIX)/libc.a
    32 
    33 OUTPUT = init
     31BINARY = init
    3432
    3533SOURCES = \
    3634        init.c
    3735
    38 include ../Makefile.common
     36include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/init/init.c

    rcf8cc36 rc47e1a8  
    4646#include <malloc.h>
    4747#include <macros.h>
    48 #include <string.h>
     48#include <str.h>
    4949#include <devmap.h>
     50#include <str_error.h>
    5051#include "init.h"
    5152
     53#define ROOT_DEVICE       "bd/initrd"
     54#define ROOT_MOUNT_POINT  "/"
     55
     56#define DEVFS_FS_TYPE      "devfs"
    5257#define DEVFS_MOUNT_POINT  "/dev"
     58
     59#define SCRATCH_FS_TYPE      "tmpfs"
     60#define SCRATCH_MOUNT_POINT  "/scratch"
     61
     62#define DATA_FS_TYPE      "fat"
     63#define DATA_DEVICE       "bd/disk0"
     64#define DATA_MOUNT_POINT  "/data"
    5365
    5466#define SRV_CONSOLE  "/srv/console"
     
    5769static void info_print(void)
    5870{
    59         printf(NAME ": HelenOS init\n");
     71        printf("%s: HelenOS init\n", NAME);
     72}
     73
     74static bool mount_report(const char *desc, const char *mntpt,
     75    const char *fstype, const char *dev, int rc)
     76{
     77        switch (rc) {
     78        case EOK:
     79                if (dev != NULL)
     80                        printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt,
     81                            fstype, dev);
     82                else
     83                        printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype);
     84                break;
     85        case EBUSY:
     86                printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
     87                return false;
     88        case ELIMIT:
     89                printf("%s: %s limit exceeded\n", NAME, desc);
     90                return false;
     91        case ENOENT:
     92                printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
     93                return false;
     94        default:
     95                printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
     96                    str_error(rc));
     97                return false;
     98        }
     99       
     100        return true;
    60101}
    61102
    62103static bool mount_root(const char *fstype)
    63104{
    64         char *opts = "";
    65         const char *root_dev = "bd/initrd";
     105        const char *opts = "";
    66106       
    67107        if (str_cmp(fstype, "tmpfs") == 0)
    68108                opts = "restore";
    69109       
    70         int rc = mount(fstype, "/", root_dev, opts, IPC_FLAG_BLOCKING);
    71        
    72         switch (rc) {
    73         case EOK:
    74                 printf(NAME ": Root filesystem mounted, %s at %s\n",
    75                     fstype, root_dev);
    76                 break;
    77         case EBUSY:
    78                 printf(NAME ": Root filesystem already mounted\n");
    79                 return false;
    80         case ELIMIT:
    81                 printf(NAME ": Unable to mount root filesystem\n");
    82                 return false;
    83         case ENOENT:
    84                 printf(NAME ": Unknown filesystem type (%s)\n", fstype);
    85                 return false;
    86         default:
    87                 printf(NAME ": Error mounting root filesystem (%d)\n", rc);
    88                 return false;
    89         }
    90        
    91         return true;
     110        int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
     111            IPC_FLAG_BLOCKING);
     112        return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
     113            ROOT_DEVICE, rc);
    92114}
    93115
    94116static bool mount_devfs(void)
    95117{
    96         int rc = mount("devfs", DEVFS_MOUNT_POINT, "", "", IPC_FLAG_BLOCKING);
    97        
    98         switch (rc) {
    99         case EOK:
    100                 printf(NAME ": Device filesystem mounted\n");
    101                 break;
    102         case EBUSY:
    103                 printf(NAME ": Device filesystem already mounted\n");
    104 
    105                 return false;
    106         case ELIMIT:
    107                 printf(NAME ": Unable to mount device filesystem\n");
    108 
    109                 return false;
    110         case ENOENT:
    111                 printf(NAME ": Unknown filesystem type (devfs)\n");
    112 
    113                 return false;
    114         default:
    115                 printf(NAME ": Error mounting device filesystem (%d)\n", rc);
    116 
    117                 return false;
    118         }
    119        
    120         return true;
    121 }
    122 
    123 static void spawn(char *fname)
    124 {
    125         char *argv[2];
     118        int rc = mount(DEVFS_FS_TYPE, DEVFS_MOUNT_POINT, "", "",
     119            IPC_FLAG_BLOCKING);
     120        return mount_report("Device filesystem", DEVFS_MOUNT_POINT, DEVFS_FS_TYPE,
     121            NULL, rc);
     122}
     123
     124static void spawn(const char *fname)
     125{
     126        const char *argv[2];
    126127        struct stat s;
    127128       
     
    129130                return;
    130131       
    131         printf(NAME ": Spawning %s\n", fname);
     132        printf("%s: Spawning %s\n", NAME, fname);
    132133       
    133134        argv[0] = fname;
    134135        argv[1] = NULL;
    135136       
    136         if (!task_spawn(fname, argv))
    137                 printf(NAME ": Error spawning %s\n", fname);
    138 }
    139 
    140 static void srv_start(char *fname)
    141 {
    142         char *argv[2];
     137        int err;
     138        if (!task_spawn(fname, argv, &err))
     139                printf("%s: Error spawning %s (%s)\n", NAME, fname,
     140                    str_error(err));
     141}
     142
     143static void srv_start(const char *fname)
     144{
     145        const char *argv[2];
    143146        task_id_t id;
    144147        task_exit_t texit;
     
    149152                return;
    150153       
    151         printf(NAME ": Starting %s\n", fname);
     154        printf("%s: Starting %s\n", NAME, fname);
    152155       
    153156        argv[0] = fname;
    154157        argv[1] = NULL;
    155158       
    156         id = task_spawn(fname, argv);
     159        id = task_spawn(fname, argv, &retval);
    157160        if (!id) {
    158                 printf(NAME ": Error spawning %s\n", fname);
     161                printf("%s: Error spawning %s (%s)\n", NAME, fname,
     162                    str_error(retval));
    159163                return;
    160164        }
    161 
     165       
    162166        rc = task_wait(id, &texit, &retval);
    163167        if (rc != EOK) {
    164                 printf(NAME ": Error waiting for %s\n", fname);
     168                printf("%s: Error waiting for %s (%s(\n", NAME, fname,
     169                    str_error(retval));
    165170                return;
    166171        }
    167 
     172       
    168173        if ((texit != TASK_EXIT_NORMAL) || (retval != 0)) {
    169                 printf(NAME ": Server %s failed to start (returned %d)\n",
    170                         fname, retval);
    171         }
    172 }
    173 
    174 static void console(char *dev)
    175 {
    176         char *argv[3];
     174                printf("%s: Server %s failed to start (%s)\n", NAME,
     175                        fname, str_error(retval));
     176        }
     177}
     178
     179static void console(const char *dev)
     180{
     181        const char *argv[3];
    177182        char hid_in[DEVMAP_NAME_MAXLEN];
    178183        int rc;
     
    180185        snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
    181186       
    182         printf(NAME ": Spawning %s with %s\n", SRV_CONSOLE, hid_in);
     187        printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in);
    183188       
    184189        /* Wait for the input device to be ready */
     
    191196                argv[2] = NULL;
    192197               
    193                 if (!task_spawn(SRV_CONSOLE, argv))
    194                         printf(NAME ": Error spawning %s with %s\n", SRV_CONSOLE, hid_in);
     198                if (!task_spawn(SRV_CONSOLE, argv, &rc))
     199                        printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
     200                            hid_in, str_error(rc));
    195201        } else
    196                 printf(NAME ": Error waiting on %s\n", hid_in);
    197 }
    198 
    199 static void getterm(char *dev, char *app)
    200 {
    201         char *argv[4];
     202                printf("%s: Error waiting on %s (%s)\n", NAME, hid_in,
     203                    str_error(rc));
     204}
     205
     206static void getterm(const char *dev, const char *app)
     207{
     208        const char *argv[4];
    202209        char term[DEVMAP_NAME_MAXLEN];
    203210        int rc;
     
    205212        snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
    206213       
    207         printf(NAME ": Spawning %s with %s %s\n", APP_GETTERM, term, app);
     214        printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
    208215       
    209216        /* Wait for the terminal device to be ready */
     
    217224                argv[3] = NULL;
    218225               
    219                 if (!task_spawn(APP_GETTERM, argv))
    220                         printf(NAME ": Error spawning %s with %s %s\n", APP_GETTERM,
    221                             term, app);
     226                if (!task_spawn(APP_GETTERM, argv, &rc))
     227                        printf("%s: Error spawning %s %s %s (%s)\n", NAME, APP_GETTERM,
     228                            term, app, str_error(rc));
    222229        } else
    223                 printf(NAME ": Error waiting on %s\n", term);
    224 }
    225 
    226 static void mount_scratch(void)
    227 {
    228         int rc;
    229 
    230         printf("Trying to mount null/0 on /scratch... ");
    231         fflush(stdout);
    232 
    233         rc = mount("tmpfs", "/scratch", "null/0", "", 0);
    234         if (rc == EOK)
    235                 printf("OK\n");
    236         else
    237                 printf("Failed\n");
    238 }
    239 
    240 static void mount_data(void)
    241 {
    242         int rc;
    243 
    244         printf("Trying to mount bd/disk0 on /data... ");
    245         fflush(stdout);
    246 
    247         rc = mount("fat", "/data", "bd/disk0", "wtcache", 0);
    248         if (rc == EOK)
    249                 printf("OK\n");
    250         else
    251                 printf("Failed\n");
     230                printf("%s: Error waiting on %s (%s)\n", NAME, term,
     231                    str_error(rc));
     232}
     233
     234static bool mount_scratch(void)
     235{
     236        int rc = mount(SCRATCH_FS_TYPE, SCRATCH_MOUNT_POINT, "", "", 0);
     237        return mount_report("Scratch filesystem", SCRATCH_MOUNT_POINT,
     238            SCRATCH_FS_TYPE, NULL, rc);
     239}
     240
     241static bool mount_data(void)
     242{
     243        int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0);
     244        return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
     245            DATA_DEVICE, rc);
    252246}
    253247
     
    257251       
    258252        if (!mount_root(STRING(RDFMT))) {
    259                 printf(NAME ": Exiting\n");
     253                printf("%s: Exiting\n", NAME);
    260254                return -1;
    261255        }
    262 
     256       
    263257        /* Make sure tmpfs is running. */
    264258        if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
     
    270264       
    271265        if (!mount_devfs()) {
    272                 printf(NAME ": Exiting\n");
     266                printf("%s: Exiting\n", NAME);
    273267                return -2;
    274268        }
    275 
     269       
    276270        mount_scratch();
    277271       
     
    282276        srv_start("/srv/adb_ms");
    283277        srv_start("/srv/char_ms");
    284 
     278       
    285279        spawn("/srv/fb");
    286280        spawn("/srv/kbd");
     
    288282       
    289283        spawn("/srv/clip");
    290 
     284       
    291285        /*
    292286         * Start these synchronously so that mount_data() can be
     
    299293        (void) srv_start;
    300294#endif
    301 
     295       
    302296#ifdef CONFIG_MOUNT_DATA
    303297        mount_data();
     
    305299        (void) mount_data;
    306300#endif
    307 
     301       
    308302        getterm("term/vc0", "/app/bdsh");
    309303        getterm("term/vc1", "/app/bdsh");
     
    314308        getterm("term/vc6", "/app/klog");
    315309        getterm("term/vc7", "/srv/devman");
    316 
    317         //usleep(1000000);
    318         //spawn("/srv/dd");
    319                
    320310       
    321311        return 0;
  • uspace/app/klog/Makefile

    rcf8cc36 rc47e1a8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBC_PREFIX)/libc.a
    32 
    33 OUTPUT = klog
     31BINARY = klog
    3432
    3533SOURCES = \
    3634        klog.c
    3735
    38 include ../Makefile.common
     36include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/klog/klog.c

    rcf8cc36 rc47e1a8  
    6464int main(int argc, char *argv[])
    6565{
    66         size_t klog_pages = sysinfo_value("klog.pages");
     66        size_t klog_pages;
     67        if (sysinfo_get_value("klog.pages", &klog_pages) != EOK) {
     68                printf("%s: Error getting klog address\n", NAME);
     69                return -1;
     70        }
     71       
    6772        size_t klog_size = klog_pages * PAGE_SIZE;
    6873        klog_length = klog_size / sizeof(wchar_t);
     
    7075        klog = (wchar_t *) as_get_mappable_page(klog_size);
    7176        if (klog == NULL) {
    72                 printf(NAME ": Error allocating memory area\n");
     77                printf("%s: Error allocating memory area\n", NAME);
    7378                return -1;
    7479        }
     
    7782            klog_size, SERVICE_MEM_KLOG);
    7883        if (res != EOK) {
    79                 printf(NAME ": Error initializing memory area\n");
     84                printf("%s: Error initializing memory area\n", NAME);
    8085                return -1;
    8186        }
    8287       
    8388        if (event_subscribe(EVENT_KLOG, 0) != EOK) {
    84                 printf(NAME ": Error registering klog notifications\n");
     89                printf("%s: Error registering klog notifications\n", NAME);
    8590                return -1;
    8691        }
  • uspace/app/mkfat/Makefile

    rcf8cc36 rc47e1a8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBC_PREFIX)/libc.a
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a
    3232EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
    33 
    34 OUTPUT = mkfat
     33BINARY = mkfat
    3534
    3635SOURCES = \
    3736        mkfat.c
    3837
    39 include ../Makefile.common
     38include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/mkfat/fat.h

    rcf8cc36 rc47e1a8  
    7878                        uint16_t        signature;
    7979                } __attribute__ ((packed));
    80                 struct fat32 {
     80                struct {
    8181                        /* FAT32 only */
    8282                        /** Sectors per FAT. */
     
    108108                        /** Signature. */
    109109                        uint16_t        signature;
    110                 } __attribute__ ((packed));
     110                } fat32 __attribute__ ((packed));
    111111        };
    112112} __attribute__ ((packed)) fat_bs_t;
  • uspace/app/mkfat/mkfat.c

    rcf8cc36 rc47e1a8  
    9898        size_t block_size;
    9999        char *endptr;
    100         bn_t dev_nblocks;
     100        aoff64_t dev_nblocks;
    101101
    102102        cfg.total_sectors = 0;
     
    160160                printf(NAME ": Warning, failed to obtain block device size.\n");
    161161        } else {
    162                 printf(NAME ": Block device has %" PRIuBN " blocks.\n",
     162                printf(NAME ": Block device has %" PRIuOFF64 " blocks.\n",
    163163                    dev_nblocks);
    164164                cfg.total_sectors = dev_nblocks;
     
    236236static int fat_blocks_write(struct fat_params const *par, dev_handle_t handle)
    237237{
    238         bn_t addr;
     238        aoff64_t addr;
    239239        uint8_t *buffer;
    240240        int i;
  • uspace/app/redir/Makefile

    rcf8cc36 rc47e1a8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBC_PREFIX)/libc.a
    32 
    33 OUTPUT = redir
     31BINARY = redir
    3432
    3533SOURCES = \
    3634        redir.c
    3735
    38 include ../Makefile.common
     36include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/redir/redir.c

    rcf8cc36 rc47e1a8  
    3939#include <fcntl.h>
    4040#include <unistd.h>
    41 #include <string.h>
     41#include <str.h>
    4242#include <stdio.h>
    4343#include <task.h>
     44#include <str_error.h>
     45
     46#define NAME  "redir"
    4447
    4548static void usage(void)
    4649{
    47         printf("Usage: redir [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n");
     50        printf("Usage: %s [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n",
     51            NAME);
    4852}
    4953
     
    7276static task_id_t spawn(int argc, char *argv[])
    7377{
    74         char **args = (char *) calloc(argc + 1, sizeof(char *));
     78        const char **args = (const char **) calloc(argc + 1, sizeof(char *));
    7579        if (!args) {
    7680                printf("No memory available\n");
     
    8488        args[argc] = NULL;
    8589       
    86         task_id_t id = task_spawn(argv[0], args);
     90        int err;
     91        task_id_t id = task_spawn(argv[0], args, &err);
    8792       
    8893        free(args);
    8994       
    9095        if (id == 0)
    91                 printf("Error spawning %s\n", argv[0]);
     96                printf("%s: Error spawning %s (%s)\n", NAME, argv[0],
     97                    str_error(err));
    9298       
    9399        return id;
  • uspace/app/sbi/src/bigint.h

    rcf8cc36 rc47e1a8  
    11/*
    2  * Copyright (c) 2006 Martin Decky
     2 * Copyright (c) 2010 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #ifndef BOOT_ppc32_ASM_H_
    30 #define BOOT_ppc32_ASM_H_
     29#ifndef BIGINT_H_
     30#define BIGINT_H_
    3131
    32 #define PAGE_WIDTH  12
    33 #define PAGE_SIZE   (1 << PAGE_WIDTH)
     32#include "mytypes.h"
    3433
    35 #define TRANS_SIZE   1024
    36 #define BOOT_OFFSET  0x8000
     34void bigint_init(bigint_t *bigint, int value);
     35void bigint_shallow_copy(bigint_t *src, bigint_t *dest);
     36void bigint_clone(bigint_t *src, bigint_t *dest);
     37void bigint_reverse_sign(bigint_t *src, bigint_t *dest);
     38void bigint_destroy(bigint_t *bigint);
    3739
    38 #define BALLOC_MAX_SIZE  (128 * 1024)
     40int bigint_get_value_int(bigint_t *bigint, int *dval);
     41bool_t bigint_is_zero(bigint_t *bigint);
     42bool_t bigint_is_negative(bigint_t *bigint);
    3943
    40 #ifndef __ASM__
     44void bigint_div_digit(bigint_t *a, bigint_word_t b, bigint_t *quot,
     45    bigint_word_t *rem);
    4146
    42 #include "types.h"
    43 #include "main.h"
    44 #include "ofwarch.h"
    45 
    46 #define PA2KA(x)  (((uintptr_t) (x)) + 0x80000000)
    47 
    48 extern uint8_t balloc_base[BALLOC_MAX_SIZE];
    49 extern uintptr_t trans[TRANS_SIZE];
    50 
    51 extern void halt();
    52 extern void jump_to_kernel(void *bootinfo, unsigned int bootinfo_size,
    53     uintptr_t trans[], unsigned int kernel_size, void *real_mode) __attribute__((noreturn));
    54 extern void real_mode();
    55 
    56 #else
    57 
    58 #define PA2KA(x)  ((x) + 0x80000000)
     47void bigint_add(bigint_t *a, bigint_t *b, bigint_t *dest);
     48void bigint_sub(bigint_t *a, bigint_t *b, bigint_t *dest);
     49void bigint_mul(bigint_t *a, bigint_t *b, bigint_t *dest);
     50void bigint_print(bigint_t *bigint);
    5951
    6052#endif
    61 
    62 #endif
  • uspace/app/sbi/src/builtin.h

    rcf8cc36 rc47e1a8  
    11/*
    2  * Copyright (c) 2007 Michal Kebrt
    3  * Copyright (c) 2009 Vineeth Pillai
     2 * Copyright (c) 2010 Jiri Svoboda
    43 * All rights reserved.
    54 *
     
    2827 */
    2928
     29#ifndef BUILTIN_H_
     30#define BUILTIN_H_
    3031
    31 /** @addtogroup arm32boot
    32  * @{
    33  */
    34 /** @file
    35  *  @brief bootloader output logic
    36  */
     32#include "mytypes.h"
    3733
     34void builtin_declare(stree_program_t *program);
     35void builtin_bind(builtin_t *bi);
     36void builtin_code_snippet(builtin_t *bi, const char *snippet);
    3837
    39 #include <printf.h>
     38stree_csi_t *builtin_get_gf_class(builtin_t *builtin);
     39void builtin_run_proc(run_t *run, stree_proc_t *proc);
    4040
     41rdata_var_t *builtin_get_self_mbr_var(run_t *run, const char *mbr_name);
    4142
    42 /** Address where characters to be printed are expected. */
    43 #ifdef MACHINE_testarm
    44         #define PUTC_ADDRESS  0x10000000
     43stree_symbol_t *builtin_declare_fun(stree_csi_t *csi, const char *name);
     44void builtin_fun_add_arg(stree_symbol_t *fun_sym, const char *name);
     45
     46stree_symbol_t *builtin_find_lvl0(builtin_t *bi, const char *sym_name);
     47stree_symbol_t *builtin_find_lvl1(builtin_t *bi, const char *csi_name,
     48    const char *sym_name);
     49
     50void builtin_fun_bind(builtin_t *bi, const char *csi_name,
     51    const char *sym_name, builtin_proc_t bproc);
     52
    4553#endif
    46 
    47 #ifdef MACHINE_integratorcp
    48         #define PUTC_ADDRESS  0x16000000
    49 #endif
    50 
    51 
    52 
    53 /** Prints a character to the console.
    54  *
    55  * @param ch Character to be printed.
    56  */
    57 static void putc(char ch)
    58 {
    59         if (ch == '\n')
    60                 *((volatile char *) PUTC_ADDRESS) = '\r';
    61         *((volatile char *) PUTC_ADDRESS) = ch;
    62 }
    63 
    64 
    65 /** Prints a string to the console.
    66  *
    67  * @param str String to be printed.
    68  * @param len Number of characters to be printed.
    69  */
    70 void write(const char *str, const int len)
    71 {
    72         int i;
    73         for (i = 0; i < len; ++i) {
    74                 putc(str[i]);
    75         }
    76 }
    77 
    78 /** @}
    79  */
    80 
  • uspace/app/sbi/src/input.h

    rcf8cc36 rc47e1a8  
    11/*
    2  * Copyright (c) 2006 Martin Decky
     2 * Copyright (c) 2010 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #ifndef BOOT_mips32_TYPES_H_
    30 #define BOOT_mips32_TYPES_H_
     29#ifndef INPUT_H_
     30#define INPUT_H_
    3131
    32 #include <gentypes.h>
     32#include "mytypes.h"
    3333
    34 typedef signed char int8_t;
     34int input_new_file(input_t **input, const char *fname);
     35int input_new_interactive(input_t **input);
     36int input_new_string(input_t **input, const char *str);
    3537
    36 typedef unsigned char uint8_t;
    37 typedef unsigned short uint16_t;
    38 typedef unsigned int uint32_t;
    39 typedef unsigned long long uint64_t;
    40 
    41 typedef uint32_t uintptr_t;
    42 typedef uint32_t unative_t;
     38int input_get_line(input_t *input, char **line);
     39int input_get_line_no(input_t *input);
    4340
    4441#endif
  • uspace/app/sbi/src/lex.h

    rcf8cc36 rc47e1a8  
    11/*
    2  * Copyright (c) 2006 Martin Decky
     2 * Copyright (c) 2010 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #ifndef BOOT_ia64_TYPES_H_
    30 #define BOOT_ia64_TYPES_H_
     29#ifndef LEX_H_
     30#define LEX_H_
    3131
    32 #include <gentypes.h>
     32#include "mytypes.h"
    3333
    34 typedef signed char int8_t;
     34void lclass_print(lclass_t lclass);
     35void lem_print(lem_t *lem);
     36void lem_print_coords(lem_t *lem);
    3537
    36 typedef unsigned char uint8_t;
    37 typedef unsigned short uint16_t;
    38 typedef unsigned int uint32_t;
    39 typedef unsigned long uint64_t;
    40 
    41 typedef uint64_t uintptr_t;
    42 typedef uint64_t unative_t;
     38void lex_init(lex_t *lex, struct input *input);
     39void lex_next(lex_t *lex);
     40lem_t *lex_get_current(lex_t *lex);
     41lem_t *lex_peek_prev(lex_t *lex);
    4342
    4443#endif
  • uspace/app/sbi/src/symbol.h

    rcf8cc36 rc47e1a8  
    11/*
    2  * Copyright (c) 2005 Martin Decky
     2 * Copyright (c) 2010 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #ifndef BOOT_mips32_MAIN_H_
    30 #define BOOT_mips32_MAIN_H_
     29#ifndef SYMBOL_H_
     30#define SYMBOL_H_
    3131
    32 #define CPUMAP               0x80001000
    33 #define INITIAL_STACK        0x80002000
    34 #define MSIM_DORDER_ADDRESS  0xb0000004
     32#include "mytypes.h"
    3533
    36 #define TASKMAP_MAX_RECORDS  32
    37 #define CPUMAP_MAX_RECORDS   32
     34stree_symbol_t *symbol_xlookup_in_csi(stree_program_t *prog,
     35    stree_csi_t *scope, stree_texpr_t *texpr);
     36stree_symbol_t *symbol_lookup_in_csi(stree_program_t *prog, stree_csi_t *scope,
     37    stree_ident_t *name);
     38stree_symbol_t *symbol_search_csi(stree_program_t *prog, stree_csi_t *scope,
     39    stree_ident_t *name);
     40stree_symbol_t *symbol_search_csi_no_base(stree_program_t *prog,
     41    stree_csi_t *scope, stree_ident_t *name);
     42stree_symbol_t *symbol_find_epoint(stree_program_t *prog, stree_ident_t *name);
    3843
    39 #ifndef __ASM__
     44stree_deleg_t *symbol_to_deleg(stree_symbol_t *symbol);
     45stree_symbol_t *deleg_to_symbol(stree_deleg_t *deleg);
     46stree_csi_t *symbol_to_csi(stree_symbol_t *symbol);
     47stree_symbol_t *csi_to_symbol(stree_csi_t *csi);
     48stree_ctor_t *symbol_to_ctor(stree_symbol_t *symbol);
     49stree_symbol_t *ctor_to_symbol(stree_ctor_t *ctor);
     50stree_enum_t *symbol_to_enum(stree_symbol_t *symbol);
     51stree_symbol_t *enum_to_symbol(stree_enum_t *enum_d);
     52stree_fun_t *symbol_to_fun(stree_symbol_t *symbol);
     53stree_symbol_t *fun_to_symbol(stree_fun_t *fun);
     54stree_var_t *symbol_to_var(stree_symbol_t *symbol);
     55stree_symbol_t *var_to_symbol(stree_var_t *var);
     56stree_prop_t *symbol_to_prop(stree_symbol_t *symbol);
     57stree_symbol_t *prop_to_symbol(stree_prop_t *prop);
    4058
    41 /** Size of buffer for storing task name in task_t. */
    42 #define BOOTINFO_TASK_NAME_BUFLEN 32
    43 
    44 /** Struct holding information about single loaded task. */
    45 typedef struct {
    46         /** Address where the task was placed. */
    47         void *addr;
    48         /** Size of the task's binary. */
    49         unsigned int size;
    50         /** Task name. */
    51         char name[BOOTINFO_TASK_NAME_BUFLEN];
    52 } task_t;
    53 
    54 typedef struct {
    55         unsigned int cpumap;
    56         unsigned int cnt;
    57         task_t tasks[TASKMAP_MAX_RECORDS];
    58 } bootinfo_t;
    59 
    60 extern void start(void);
    61 extern void bootstrap(void);
     59void symbol_print_fqn(stree_symbol_t *symbol);
    6260
    6361#endif
    64 
    65 #endif
  • uspace/app/shutters/Makefile

    rcf8cc36 rc47e1a8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBC_PREFIX)/libc.a
    32 
    33 OUTPUT = shutters
     31BINARY = shutters
    3432
    3533SOURCES = \
    3634        shutters.c
    3735
    38 include ../Makefile.common
     36include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/shutters/shutters.c

    rcf8cc36 rc47e1a8  
    5353#include <sys/stat.h>
    5454
    55 #include <string.h>
     55#include <str.h>
    5656
    5757#define NAME            "shutters"
  • uspace/app/taskdump/Makefile

    rcf8cc36 rc47e1a8  
    2828
    2929USPACE_PREFIX = ../..
    30 LIBS = $(LIBC_PREFIX)/libc.a
    3130EXTRA_CFLAGS = -Iinclude
    32 
    33 OUTPUT = taskdump
     31BINARY = taskdump
    3432
    3533SOURCES = \
     34        elf_core.c \
    3635        taskdump.c \
    3736        symtab.c
    3837
    39 include ../Makefile.common
     38include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/taskdump/include/elf.h

    rcf8cc36 rc47e1a8  
    148148#define SHF_MASKPROC            0xf0000000
    149149
     150/** Macros for decomposing elf_symbol.st_info into binging and type */
     151#define ELF_ST_BIND(i)          ((i) >> 4)
     152#define ELF_ST_TYPE(i)          ((i) & 0x0f)
     153#define ELF_ST_INFO(b, t)       (((b) << 4) + ((t) & 0x0f))
     154
    150155/**
    151156 * Symbol binding
  • uspace/app/taskdump/symtab.c

    rcf8cc36 rc47e1a8  
    4949static int section_hdr_load(int fd, const elf_header_t *ehdr, int idx,
    5050    elf_section_header_t *shdr);
    51 static int chunk_load(int fd, off_t start, off_t size, void **ptr);
     51static int chunk_load(int fd, off64_t start, size_t size, void **ptr);
    5252static int read_all(int fd, void *buf, size_t len);
    5353
     
    6565        elf_header_t elf_hdr;
    6666        elf_section_header_t sec_hdr;
    67         off_t shstrt_start, shstrt_size;
     67        off64_t shstrt_start;
     68        size_t shstrt_size;
    6869        char *shstrt, *sec_name;
    6970        void *data;
     
    206207        size_t i;
    207208        char *sname;
     209        unsigned stype;
    208210
    209211        for (i = 0; i < st->sym_size / sizeof(elf_symbol_t); ++i) {
    210212                if (st->sym[i].st_name == 0)
     213                        continue;
     214
     215                stype = ELF_ST_TYPE(st->sym[i].st_info);
     216                if (stype != STT_OBJECT && stype != STT_FUNC)
    211217                        continue;
    212218
     
    240246        uintptr_t saddr, best_addr;
    241247        char *sname, *best_name;
     248        unsigned stype;
    242249
    243250        best_name = NULL;
     
    248255                        continue;
    249256
     257                stype = ELF_ST_TYPE(st->sym[i].st_info);
     258                if (stype != STT_OBJECT && stype != STT_FUNC &&
     259                    stype != STT_NOTYPE) {
     260                        continue;
     261                }
     262
    250263                saddr = st->sym[i].st_value;
    251264                sname = st->strtab + st->sym[i].st_name;
     265
     266                /* An ugly hack to filter out some special ARM symbols. */
     267                if (sname[0] == '$')
     268                        continue;
    252269
    253270                if (best_name == NULL || (saddr <= addr && saddr > best_addr)) {
     
    291308        rc = lseek(fd, elf_hdr->e_shoff + idx * sizeof(elf_section_header_t),
    292309            SEEK_SET);
    293         if (rc == (off_t) -1)
     310        if (rc == (off64_t) -1)
    294311                return EIO;
    295312
     
    312329 * @return              EOK on success or EIO on failure.
    313330 */
    314 static int chunk_load(int fd, off_t start, off_t size, void **ptr)
     331static int chunk_load(int fd, off64_t start, size_t size, void **ptr)
    315332{
    316333        int rc;
    317334
    318335        rc = lseek(fd, start, SEEK_SET);
    319         if (rc == (off_t) -1) {
     336        if (rc == (off64_t) -1) {
    320337                printf("failed seeking chunk\n");
    321338                *ptr = NULL;
  • uspace/app/taskdump/taskdump.c

    rcf8cc36 rc47e1a8  
    4040#include <udebug.h>
    4141#include <task.h>
    42 #include <kernel/mm/as.h>
     42#include <as.h>
    4343#include <sys/types.h>
    4444#include <sys/typefmt.h>
     
    4949
    5050#include <symtab.h>
     51#include <elf_core.h>
    5152#include <stacktrace.h>
    5253
    5354#define LINE_BYTES 16
    54 
    55 #define DBUF_SIZE 4096
    56 static uint8_t data_buf[DBUF_SIZE];
    5755
    5856static int phoneid;
    5957static task_id_t task_id;
    60 static bool dump_memory;
     58static bool write_core_file;
     59static char *core_file_name;
    6160static char *app_name;
    6261static symtab_t *app_symtab;
     
    6867static int thread_dump(uintptr_t thash);
    6968static int areas_dump(void);
    70 static int area_dump(as_area_info_t *area);
    71 static void hex_dump(uintptr_t addr, void *buffer, size_t size);
    7269static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value);
    7370
     
    8077        int rc;
    8178
    82         /*
    83          * FIXME: The stdio module cannot currently detect whether we are
    84          * writing to a console or file. This workaround make file output
    85          * faster.
    86          */
    87         setvbuf(stdout, NULL, _IOFBF, 32768);
    88 
    8979        printf("Task Dump Utility\n");
    90         dump_memory = false;
     80        write_core_file = false;
    9181
    9282        if (parse_args(argc, argv) < 0)
     
    172162                                        return -1;
    173163                                }
    174                         } else if (arg[1] == 'm' && arg[2] == '\0') {
    175                                 dump_memory = true;
     164                        } else if (arg[1] == 'c' && arg[2] == '\0') {
     165                                write_core_file = true;
     166
     167                                --argc; ++argv;
     168                                core_file_name = *argv;
    176169                        } else {
    177170                                printf("Uknown option '%s'\n", arg[0]);
     
    203196static void print_syntax(void)
    204197{
    205         printf("Syntax: taskdump [-m] -t <task_id>\n");
    206         printf("\t-m\tDump memory area contents.\n");
     198        printf("Syntax: taskdump [-c <core_file>] -t <task_id>\n");
     199        printf("\t-c <core_file_id>\tName of core file to write.\n");
    207200        printf("\t-t <task_id>\tWhich task to dump.\n");
    208201}
     
    297290                    (ainfo_buf[i].flags & AS_AREA_CACHEABLE) ? 'C' : '-',
    298291                    ainfo_buf[i].start_addr, ainfo_buf[i].size);
    299 
    300                 if (dump_memory) {
    301                         putchar('\n');
    302                         area_dump(&ainfo_buf[i]);
    303                         putchar('\n');
     292        }
     293
     294        putchar('\n');
     295
     296        if (write_core_file) {
     297                printf("Writing core file '%s'\n", core_file_name);
     298                rc = elf_core_save(core_file_name, ainfo_buf, n_areas, phoneid);
     299                if (rc != EOK) {
     300                        printf("Failed writing core file.\n");
     301                        return EIO;
    304302                }
    305303        }
    306 
    307         putchar('\n');
    308304
    309305        free(ainfo_buf);
     
    353349
    354350        return EOK;
    355 }
    356 
    357 static int area_dump(as_area_info_t *area)
    358 {
    359         size_t to_copy;
    360         size_t total;
    361         uintptr_t addr;
    362         int rc;
    363 
    364         addr = area->start_addr;
    365         total = 0;
    366 
    367         while (total < area->size) {
    368                 to_copy = min(area->size - total, DBUF_SIZE);
    369                 rc = udebug_mem_read(phoneid, data_buf, addr, to_copy);
    370                 if (rc < 0) {
    371                         printf("udebug_mem_read() failed.\n");
    372                         return rc;
    373                 }
    374 
    375                 hex_dump(addr, data_buf, to_copy);
    376 
    377                 addr += to_copy;
    378                 total += to_copy;
    379         }
    380 
    381         return EOK;
    382 }
    383 
    384 static void hex_dump(uintptr_t addr, void *buffer, size_t size)
    385 {
    386         uint8_t *data = (uint8_t *) buffer;
    387         uint8_t b;
    388         size_t pos, i;
    389 
    390         assert(addr % LINE_BYTES == 0);
    391         assert(size % LINE_BYTES == 0);
    392 
    393         pos = 0;
    394 
    395         while (pos < size) {
    396                 printf("%08lx:", addr + pos);
    397                 for (i = 0; i < LINE_BYTES; ++i) {
    398                         if (i % 4 == 0) putchar(' ');
    399                         printf(" %02x", data[pos + i]);
    400                 }
    401                 putchar('\t');
    402 
    403                 for (i = 0; i < LINE_BYTES; ++i) {
    404                         b = data[pos + i];
    405                         if (b >= 32 && b < 127) {
    406                                 putchar(b);
    407                         } else {
    408                                 putchar(' ');
    409                         }
    410                 }
    411                 putchar('\n');
    412                 pos += LINE_BYTES;
    413         }
    414351}
    415352
  • uspace/app/test_serial/Makefile

    rcf8cc36 rc47e1a8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBC_PREFIX)/libc.a
    32 
    33 OUTPUT = test_serial
     31BINARY = test_serial
    3432
    3533SOURCES = \
    3634        test_serial.c
    3735
    38 include ../Makefile.common
     36include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/test_serial/test_serial.c

    rcf8cc36 rc47e1a8  
    4545#include <devman.h>
    4646#include <device/char.h>
    47 #include <string.h>
     47#include <str.h>
    4848#include <ipc/serial_ctl.h>
    4949
     
    136136        }
    137137       
    138         char *the_end = "\n---------\nTHE END\n---------\n";
    139         write_dev(phone, the_end, str_size(the_end));
     138        const char *the_end = "\n---------\nTHE END\n---------\n";
     139        write_dev(phone, (void *)the_end, str_size(the_end));
    140140       
    141141        // restore original communication settings
  • uspace/app/tester/Makefile

    rcf8cc36 rc47e1a8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBC_PREFIX)/libc.a
    32 
    33 OUTPUT = tester
     31BINARY = tester
    3432
    3533SOURCES = \
     
    5351        mm/malloc1.c
    5452
    55 include ../Makefile.common
     53include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/tester/console/console1.c

    rcf8cc36 rc47e1a8  
    3636#include "../tester.h"
    3737
    38 const char *color_name[] = {
     38static const char *color_name[] = {
    3939        [COLOR_BLACK] = "black",
    4040        [COLOR_BLUE] = "blue",
     
    4747};
    4848
    49 char *test_console1(void)
     49const char *test_console1(void)
    5050{
    5151        if (!test_quiet) {
     
    5353                fflush(stdout);
    5454                console_set_style(fphone(stdout), STYLE_NORMAL);
    55                 printf("normal ");
     55                printf(" normal ");
    5656                fflush(stdout);
    5757                console_set_style(fphone(stdout), STYLE_EMPHASIS);
    58                 printf("emphasized");
     58                printf(" emphasized ");
     59                fflush(stdout);
     60                console_set_style(fphone(stdout), STYLE_INVERTED);
     61                printf(" inverted ");
     62                fflush(stdout);
     63                console_set_style(fphone(stdout), STYLE_SELECTED);
     64                printf(" selected ");
    5965                fflush(stdout);
    6066                console_set_style(fphone(stdout), STYLE_NORMAL);
    61                 printf(".\n");
     67                printf("\n");
    6268               
    6369                unsigned int i;
     
    7379                        }
    7480                        fflush(stdout);
    75                         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     81                        console_set_style(fphone(stdout), STYLE_NORMAL);
    7682                        putchar('\n');
    7783                }
     
    8692                        }
    8793                        fflush(stdout);
    88                         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     94                        console_set_style(fphone(stdout), STYLE_NORMAL);
    8995                        putchar('\n');
    9096                }
     
    94100                for (i = 0; i < 255; i += 16) {
    95101                        fflush(stdout);
    96                         console_set_rgb_color(fphone(stdout), 0xffffff, i << 16);
     102                        console_set_rgb_color(fphone(stdout), (255 - i) << 16, i << 16);
    97103                        putchar('X');
    98104                }
     
    103109                for (i = 0; i < 255; i += 16) {
    104110                        fflush(stdout);
    105                         console_set_rgb_color(fphone(stdout), 0xffffff, i << 8);
     111                        console_set_rgb_color(fphone(stdout), (255 - i) << 8, i << 8);
    106112                        putchar('X');
    107113                }
     
    112118                for (i = 0; i < 255; i += 16) {
    113119                        fflush(stdout);
    114                         console_set_rgb_color(fphone(stdout), 0xffffff, i);
     120                        console_set_rgb_color(fphone(stdout), 255 - i, i);
    115121                        putchar('X');
    116122                }
    117123                fflush(stdout);
    118                 console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     124                console_set_style(fphone(stdout), STYLE_NORMAL);
    119125                putchar('\n');
    120126        }
  • uspace/app/tester/fault/fault1.c

    rcf8cc36 rc47e1a8  
    3030#include "../tester.h"
    3131
    32 char *test_fault1(void)
     32const char *test_fault1(void)
    3333{
    3434        ((int *)(0))[1] = 0;
  • uspace/app/tester/fault/fault2.c

    rcf8cc36 rc47e1a8  
    3030#include "../tester.h"
    3131
    32 char *test_fault2(void)
     32typedef int __attribute__((may_alias)) aliasing_int;
     33
     34const char *test_fault2(void)
    3335{
    3436        volatile long long var;
    3537        volatile int var1;
    3638       
    37         var1 = *((int *) (((char *) (&var)) + 1));
     39        var1 = *((aliasing_int *) (((char *) (&var)) + 1));
    3840       
    3941        return "Survived unaligned read";
  • uspace/app/tester/fault/fault3.c

    rcf8cc36 rc47e1a8  
    3030#include <stdlib.h>
    3131
    32 char *test_fault3(void)
     32const char *test_fault3(void)
    3333{
    3434        abort();
  • uspace/app/tester/fault/fault3.def

    rcf8cc36 rc47e1a8  
    33        "Abort",
    44        &test_fault3,
    5         true
     5        false
    66},
  • uspace/app/tester/ipc/connect.c

    rcf8cc36 rc47e1a8  
    3939}
    4040
    41 char *test_connect(void)
     41const char *test_connect(void)
    4242{
    4343        TPRINTF("Connecting to %u...", IPC_TEST_SERVICE);
  • uspace/app/tester/ipc/ping_pong.c

    rcf8cc36 rc47e1a8  
    3838#define COUNT_GRANULARITY  100
    3939
    40 char *test_ping_pong(void)
     40const char *test_ping_pong(void)
    4141{
    4242        TPRINTF("Pinging ns server for %d seconds...", DURATION_SECS);
  • uspace/app/tester/ipc/register.c

    rcf8cc36 rc47e1a8  
    7474}
    7575
    76 char *test_register(void)
     76const char *test_register(void)
    7777{
    7878        async_set_client_connection(client_connection);
  • uspace/app/tester/loop/loop1.c

    rcf8cc36 rc47e1a8  
    3131#include "../tester.h"
    3232
    33 char *test_loop1(void)
     33const char *test_loop1(void)
    3434{
    3535        TPRINTF("Looping...");
  • uspace/app/tester/mm/malloc1.c

    rcf8cc36 rc47e1a8  
    7373
    7474typedef struct {
    75         char *name;
     75        const char *name;
    7676        sp_term_cond_s cond;
    7777        sp_action_prob_s prob;
     
    9090
    9191typedef struct {
    92         char *name;
     92        const char *name;
    9393        ph_alloc_size_s alloc;
    9494        subphase_s *subphases;
     
    628628}
    629629
    630 char *test_malloc1(void)
     630const char *test_malloc1(void)
    631631{
    632632        init_mem();
  • uspace/app/tester/print/print1.c

    rcf8cc36 rc47e1a8  
    3131#include "../tester.h"
    3232
    33 char *test_print1(void)
     33const char *test_print1(void)
    3434{
    3535        TPRINTF("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n");
  • uspace/app/tester/print/print2.c

    rcf8cc36 rc47e1a8  
    3131#include "../tester.h"
    3232
    33 char *test_print2(void)
     33const char *test_print2(void)
    3434{
    3535        TPRINTF("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n");
  • uspace/app/tester/print/print3.c

    rcf8cc36 rc47e1a8  
    3434#define BUFFER_SIZE  32
    3535
    36 char *test_print3(void)
     36const char *test_print3(void)
    3737{
    3838        char buffer[BUFFER_SIZE];
  • uspace/app/tester/print/print4.c

    rcf8cc36 rc47e1a8  
    3131#include "../tester.h"
    3232
    33 char *test_print4(void)
     33const char *test_print4(void)
    3434{
    3535        TPRINTF("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n");
  • uspace/app/tester/stdio/stdio1.c

    rcf8cc36 rc47e1a8  
    3636static char buf[BUF_SIZE + 1];
    3737
    38 char *test_stdio1(void)
     38const char *test_stdio1(void)
    3939{
    4040        FILE *file;
    41         char *file_name = "/readme";
     41        const char *file_name = "/readme";
    4242       
    4343        TPRINTF("Open file \"%s\"...", file_name);
  • uspace/app/tester/stdio/stdio2.c

    rcf8cc36 rc47e1a8  
    3232#include "../tester.h"
    3333
    34 char *test_stdio2(void)
     34const char *test_stdio2(void)
    3535{
    3636        FILE *file;
    37         char *file_name = "/test";
     37        const char *file_name = "/test";
    3838       
    3939        TPRINTF("Open file \"%s\" for writing...", file_name);
  • uspace/app/tester/tester.c

    rcf8cc36 rc47e1a8  
    3838#include <unistd.h>
    3939#include <stdio.h>
    40 #include <string.h>
     40#include <str.h>
    4141#include "tester.h"
    4242
     
    6969{
    7070        /* Execute the test */
    71         char *ret = test->entry();
     71        const char *ret = test->entry();
    7272       
    7373        if (ret == NULL) {
  • uspace/app/tester/tester.h

    rcf8cc36 rc47e1a8  
    5454        }
    5555
    56 typedef char *(*test_entry_t)(void);
     56typedef const char *(*test_entry_t)(void);
    5757
    5858typedef struct {
    59         char *name;
    60         char *desc;
     59        const char *name;
     60        const char *desc;
    6161        test_entry_t entry;
    6262        bool safe;
    6363} test_t;
    6464
    65 extern char *test_thread1(void);
    66 extern char *test_print1(void);
    67 extern char *test_print2(void);
    68 extern char *test_print3(void);
    69 extern char *test_print4(void);
    70 extern char *test_console1(void);
    71 extern char *test_stdio1(void);
    72 extern char *test_stdio2(void);
    73 extern char *test_fault1(void);
    74 extern char *test_fault2(void);
    75 extern char *test_fault3(void);
    76 extern char *test_vfs1(void);
    77 extern char *test_ping_pong(void);
    78 extern char *test_register(void);
    79 extern char *test_connect(void);
    80 extern char *test_loop1(void);
    81 extern char *test_malloc1(void);
     65extern const char *test_thread1(void);
     66extern const char *test_print1(void);
     67extern const char *test_print2(void);
     68extern const char *test_print3(void);
     69extern const char *test_print4(void);
     70extern const char *test_console1(void);
     71extern const char *test_stdio1(void);
     72extern const char *test_stdio2(void);
     73extern const char *test_fault1(void);
     74extern const char *test_fault2(void);
     75extern const char *test_fault3(void);
     76extern const char *test_vfs1(void);
     77extern const char *test_ping_pong(void);
     78extern const char *test_register(void);
     79extern const char *test_connect(void);
     80extern const char *test_loop1(void);
     81extern const char *test_malloc1(void);
    8282
    8383extern test_t tests[];
  • uspace/app/tester/thread/thread1.c

    rcf8cc36 rc47e1a8  
    5050}
    5151
    52 char *test_thread1(void)
     52const char *test_thread1(void)
    5353{
    5454        unsigned int i;
    55         int total = 0;
     55        atomic_count_t total = 0;
    5656       
    5757        atomic_set(&finish, 1);
  • uspace/app/tester/vfs/vfs1.c

    rcf8cc36 rc47e1a8  
    3030#include <stdio.h>
    3131#include <stdlib.h>
    32 #include <string.h>
     32#include <str.h>
    3333#include <vfs/vfs.h>
    3434#include <unistd.h>
     
    5454static char text[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit";
    5555
    56 static char *read_root(void)
     56static const char *read_root(void)
    5757{
    5858        TPRINTF("Opening the root directory...");
     
    7373}
    7474
    75 char *test_vfs1(void)
     75const char *test_vfs1(void)
    7676{
    7777        if (mkdir(MOUNT_POINT, 0) != 0)
     
    121121        close(fd0);
    122122       
    123         char *rv = read_root();
     123        const char *rv = read_root();
    124124        if (rv != NULL)
    125125                return rv;
  • uspace/app/tetris/Makefile

    rcf8cc36 rc47e1a8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBC_PREFIX)/libc.a
    32 
    33 OUTPUT = tetris
     31BINARY = tetris
    3432
    3533SOURCES = \
     
    4038        screen.c
    4139
    42 include ../Makefile.common
     40include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/tetris/input.c

    rcf8cc36 rc47e1a8  
    5252#include <errno.h>
    5353#include <unistd.h>
    54 #include <string.h>
     54#include <str.h>
    5555
    5656#include "input.h"
  • uspace/app/tetris/scores.c

    rcf8cc36 rc47e1a8  
    5252#include <errno.h>
    5353#include <stdio.h>
    54 #include <string.h>
     54#include <str.h>
    5555#include <io/console.h>
    5656#include <io/keycode.h>
  • uspace/app/tetris/scores.h

    rcf8cc36 rc47e1a8  
    4848
    4949#include <sys/time.h>
    50 #include <string.h>
     50#include <str.h>
    5151
    5252#define MAXLOGNAME   16
  • uspace/app/tetris/screen.c

    rcf8cc36 rc47e1a8  
    4949#include <stdio.h>
    5050#include <stdlib.h>
    51 #include <string.h>
     51#include <str.h>
    5252#include <unistd.h>
    5353#include <vfs/vfs.h>
    5454#include <async.h>
     55#include <bool.h>
     56#include <io/console.h>
     57#include <io/style.h>
    5558#include "screen.h"
    5659#include "tetris.h"
    57 #include <io/console.h>
    5860
    5961#define STOP  (B_COLS - 3)
     
    6365static int isset;               /* true => terminal is in game mode */
    6466
    65 static int use_color;           /* true => use colors */
     67static bool use_color;          /* true => use colors */
    6668
    6769static const struct shape *lastshape;
     
    7274 * simply literal strings);
    7375 */
    74 static inline void putstr(char *s)
     76static inline void putstr(const char *s)
    7577{
    7678        while (*s)
     
    8183{
    8284        fflush(stdout);
    83         console_set_rgb_color(fphone(stdout), 0xf0f0f0,
     85        console_set_rgb_color(fphone(stdout), 0xffffff,
    8486            use_color ? color : 0x000000);
    8587}
     
    8890{
    8991        fflush(stdout);
    90         console_set_rgb_color(fphone(stdout), 0, 0xf0f0f0);
     92        console_set_style(fphone(stdout), STYLE_NORMAL);
    9193}
    9294
     
    118120}
    119121
    120 void moveto(int r, int c)
     122void moveto(ipcarg_t r, ipcarg_t c)
    121123{
    122124        fflush(stdout);
    123         console_goto(fphone(stdout), c, r);
     125        console_set_pos(fphone(stdout), c, r);
    124126}
    125127
     
    131133}
    132134
    133 static int get_display_color_sup(void)
    134 {
    135         int rc;
    136         int ccap;
    137 
    138         rc = console_get_color_cap(fphone(stdout), &ccap);
     135static bool get_display_color_sup(void)
     136{
     137        ipcarg_t ccap;
     138        int rc = console_get_color_cap(fphone(stdout), &ccap);
     139       
    139140        if (rc != 0)
    140                 return 0;
    141 
     141                return false;
     142       
    142143        return (ccap >= CONSOLE_CCAP_RGB);
    143144}
     
    181182}
    182183
    183 void stop(char *why)
     184void stop(const char *why)
    184185{
    185186        if (isset)
     
    308309 * (We need its length in case we have to overwrite with blanks.)
    309310 */
    310 void scr_msg(char *s, int set)
     311void scr_msg(char *s, bool set)
    311312{
    312313        int l = str_size(s);
  • uspace/app/tetris/screen.h

    rcf8cc36 rc47e1a8  
    4848
    4949#include <sys/types.h>
     50#include <ipc/ipc.h>
    5051#include <async.h>
     52#include <bool.h>
    5153
    5254typedef struct {
    53         int ws_row;
    54         int ws_col;
     55        ipcarg_t ws_row;
     56        ipcarg_t ws_col;
    5557} winsize_t;
    5658
    5759extern winsize_t winsize;
    5860
    59 extern void moveto(int r, int c);
     61extern void moveto(ipcarg_t r, ipcarg_t c);
    6062extern void clear_screen(void);
    6163
     
    6567extern void scr_end(void);
    6668extern void scr_init(void);
    67 extern void scr_msg(char *, int);
     69extern void scr_msg(char *, bool);
    6870extern void scr_set(void);
    6971extern void scr_update(void);
  • uspace/app/tetris/tetris.c

    rcf8cc36 rc47e1a8  
    5353#include <stdio.h>
    5454#include <stdlib.h>
    55 #include <string.h>
     55#include <str.h>
    5656#include <unistd.h>
    5757#include <getopt.h>
  • uspace/app/tetris/tetris.h

    rcf8cc36 rc47e1a8  
    186186extern int fits_in(const struct shape *, int);
    187187extern void place(const struct shape *, int, int);
    188 extern void stop(char *);
     188extern void stop(const char *);
    189189
    190190/** @}
  • uspace/app/top/top.h

    rcf8cc36 rc47e1a8  
    11/*
    2  * Copyright (c) 2005 Martin Decky
     2 * Copyright (c) 2010 Stanislav Kozina
     3 * Copyright (c) 2010 Martin Decky
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
    29 #ifndef BOOT_sparc64_MAIN_H_
    30 #define BOOT_sparc64_MAIN_H_
     30/** @addtogroup top
     31 * @{
     32 */
    3133
    32 #include <ofw.h>
    33 #include <ofw_tree.h>
    34 #include <balloc.h>
    35 #include <types.h>
     34#ifndef TOP_TOP_H_
     35#define TOP_TOP_H_
    3636
    37 #define KERNEL_VIRTUAL_ADDRESS  0x400000
     37#include <task.h>
     38#include <stats.h>
     39#include <time.h>
    3840
    39 #define TASKMAP_MAX_RECORDS  32
     41#define FRACTION_TO_FLOAT(float, a, b) { \
     42        (float).upper = (a); \
     43        (float).lower = (b); \
     44}
    4045
    41 /** Size of buffer for storing task name in task_t. */
    42 #define BOOTINFO_TASK_NAME_BUFLEN  32
     46#define OP_TASKS  1
     47#define OP_IPC    2
    4348
    44 #define BSP_PROCESSOR  1
    45 #define AP_PROCESSOR   0
    46 
    47 #define SUBARCH_US   1
    48 #define SUBARCH_US3  3
     49extern int operation_type;
    4950
    5051typedef struct {
    51         void *addr;
    52         uint32_t size;
    53         char name[BOOTINFO_TASK_NAME_BUFLEN];
    54 } task_t;
     52        uint64_t upper;
     53        uint64_t lower;
     54} fixed_float;
    5555
    5656typedef struct {
    57         uint32_t count;
    58         task_t tasks[TASKMAP_MAX_RECORDS];
    59 } taskmap_t;
     57        fixed_float idle;
     58        fixed_float busy;
     59} perc_cpu_t;
    6060
    6161typedef struct {
    62         uintptr_t physmem_start;
    63         taskmap_t taskmap;
    64         memmap_t memmap;
    65         ballocs_t ballocs;
    66         ofw_tree_node_t *ofw_root;
    67 } bootinfo_t;
     62        fixed_float ucycles;
     63        fixed_float kcycles;
     64        fixed_float virtmem;
     65} perc_task_t;
    6866
    69 extern uint32_t silo_ramdisk_image;
    70 extern uint32_t silo_ramdisk_size;
    71 
    72 extern void start(void);
    73 extern void bootstrap(void);
     67typedef struct {
     68        time_t hours;
     69        time_t minutes;
     70        time_t seconds;
     71       
     72        sysarg_t udays;
     73        sysarg_t uhours;
     74        sysarg_t uminutes;
     75        sysarg_t useconds;
     76       
     77        size_t load_count;
     78        load_t *load;
     79       
     80        size_t cpus_count;
     81        stats_cpu_t *cpus;
     82        perc_cpu_t *cpus_perc;
     83       
     84        size_t tasks_count;
     85        stats_task_t *tasks;
     86        perc_task_t *tasks_perc;
     87       
     88        size_t threads_count;
     89        stats_thread_t *threads;
     90       
     91        stats_physmem_t *physmem;
     92} data_t;
    7493
    7594#endif
     95
     96/**
     97 * @}
     98 */
  • uspace/app/trace/Makefile

    rcf8cc36 rc47e1a8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBC_PREFIX)/libc.a
    32 
    33 OUTPUT = trace
     31BINARY = trace
    3432
    3533SOURCES = \
     
    4139        errors.c
    4240
    43 include ../Makefile.common
     41include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/trace/errors.h

    rcf8cc36 rc47e1a8  
    3737
    3838typedef struct {
    39         char *name;     /**< Error value name (Exx) */
    40         char *desc;     /**< Error description */
     39        const char *name;  /**< Error value name (Exx) */
     40        const char *desc;  /**< Error description */
    4141} err_desc_t;
    4242
  • uspace/app/trace/ipc_desc.h

    rcf8cc36 rc47e1a8  
    3838typedef struct {
    3939        int number;
    40         char *name;
     40        const char *name;
    4141} ipc_m_desc_t;
    4242
  • uspace/app/trace/proto.c

    rcf8cc36 rc47e1a8  
    157157}
    158158
    159 static void proto_struct_init(proto_t *proto, char *name)
     159static void proto_struct_init(proto_t *proto, const char *name)
    160160{
    161161        proto->name = name;
     
    164164}
    165165
    166 proto_t *proto_new(char *name)
     166proto_t *proto_new(const char *name)
    167167{
    168168        proto_t *p;
     
    206206}
    207207
    208 static void oper_struct_init(oper_t *oper, char *name)
     208static void oper_struct_init(oper_t *oper, const char *name)
    209209{
    210210        oper->name = name;
    211211}
    212212
    213 oper_t *oper_new(char *name, int argc, val_type_t *arg_types,
     213oper_t *oper_new(const char *name, int argc, val_type_t *arg_types,
    214214    val_type_t rv_type, int respc, val_type_t *resp_types)
    215215{
  • uspace/app/trace/proto.h

    rcf8cc36 rc47e1a8  
    4343
    4444typedef struct {
    45         char *name;
     45        const char *name;
    4646
    4747        int argc;
     
    5656typedef struct {
    5757        /** Protocol name */
    58         char *name;
     58        const char *name;
    5959
    6060        /** Maps method number to operation */
     
    7070void proto_register(int srv, proto_t *proto);
    7171proto_t *proto_get_by_srv(int srv);
    72 proto_t *proto_new(char *name);
     72proto_t *proto_new(const char *name);
    7373void proto_delete(proto_t *proto);
    7474void proto_add_oper(proto_t *proto, int method, oper_t *oper);
    7575oper_t *proto_get_oper(proto_t *proto, int method);
    7676
    77 oper_t *oper_new(char *name, int argc, val_type_t *arg_types,
     77oper_t *oper_new(const char *name, int argc, val_type_t *arg_types,
    7878    val_type_t rv_type, int respc, val_type_t *resp_types);
    7979
  • uspace/app/trace/syscalls.c

    rcf8cc36 rc47e1a8  
    7676        [SYS_INTERRUPT_ENABLE] = { "interrupt_enable",  2,      V_ERRNO },
    7777
    78     [SYS_SYSINFO_VALID] = { "sysinfo_valid",            2,      V_HASH },
    79     [SYS_SYSINFO_VALUE] = { "sysinfo_value",            2,      V_HASH },
     78    [SYS_SYSINFO_GET_TAG] = { "sysinfo_get_tag",                2,      V_INTEGER },
     79    [SYS_SYSINFO_GET_VALUE] = { "sysinfo_get_value",            3,      V_ERRNO },
     80    [SYS_SYSINFO_GET_DATA_SIZE] = { "sysinfo_get_data_size",    3,      V_ERRNO },
     81    [SYS_SYSINFO_GET_DATA] = { "sysinfo_get_data",              4,      V_ERRNO },
     82
    8083    [SYS_DEBUG_ENABLE_CONSOLE] = { "debug_enable_console", 0,   V_ERRNO },
    8184    [SYS_IPC_CONNECT_KBOX] = { "ipc_connect_kbox",      1,      V_ERRNO }
  • uspace/app/trace/syscalls.h

    rcf8cc36 rc47e1a8  
    3939
    4040typedef struct {
    41         char *name;
     41        const char *name;
    4242        int n_args;
    4343        val_type_t rv_type;
  • uspace/app/trace/trace.c

    rcf8cc36 rc47e1a8  
    4343#include <task.h>
    4444#include <mem.h>
    45 #include <string.h>
     45#include <str.h>
    4646#include <bool.h>
    4747#include <loader/loader.h>
     
    585585}
    586586
    587 static loader_t *preload_task(const char *path, char *const argv[],
     587static loader_t *preload_task(const char *path, char **argv,
    588588    task_id_t *task_id)
    589589{
     
    591591        int rc;
    592592
    593         /* Spawn a program loader */   
     593        /* Spawn a program loader */
    594594        ldr = loader_connect();
    595595        if (ldr == NULL)
     
    607607
    608608        /* Send arguments */
    609         rc = loader_set_args(ldr, argv);
     609        rc = loader_set_args(ldr, (const char **) argv);
    610610        if (rc != EOK)
    611611                goto error;
     
    870870}
    871871
    872 static display_mask_t parse_display_mask(char *text)
     872static display_mask_t parse_display_mask(const char *text)
    873873{
    874874        display_mask_t dm;
    875         char *c;
    876 
    877         c = text;
    878 
     875        const char *c = text;
     876       
    879877        while (*c) {
    880878                switch (*c) {
    881                 case 't': dm = dm | DM_THREAD; break;
    882                 case 's': dm = dm | DM_SYSCALL; break;
    883                 case 'i': dm = dm | DM_IPC; break;
    884                 case 'p': dm = dm | DM_SYSTEM | DM_USER; break;
     879                case 't':
     880                        dm = dm | DM_THREAD;
     881                        break;
     882                case 's':
     883                        dm = dm | DM_SYSCALL;
     884                        break;
     885                case 'i':
     886                        dm = dm | DM_IPC;
     887                        break;
     888                case 'p':
     889                        dm = dm | DM_SYSTEM | DM_USER;
     890                        break;
    885891                default:
    886892                        printf("Unexpected event type '%c'.\n", *c);
    887893                        exit(1);
    888894                }
    889 
     895               
    890896                ++c;
    891897        }
    892 
     898       
    893899        return dm;
    894900}
     
    896902static int parse_args(int argc, char *argv[])
    897903{
    898         char *arg;
    899904        char *err_p;
    900905
    901906        task_id = 0;
    902907
    903         --argc; ++argv;
     908        --argc;
     909        ++argv;
    904910
    905911        while (argc > 0) {
    906                 arg = *argv;
     912                char *arg = *argv;
    907913                if (arg[0] == '+') {
    908914                        display_mask = parse_display_mask(&arg[1]);
     
    910916                        if (arg[1] == 't') {
    911917                                /* Trace an already running task */
    912                                 --argc; ++argv;
     918                                --argc;
     919                                ++argv;
    913920                                task_id = strtol(*argv, &err_p, 10);
    914921                                task_ldr = NULL;
     
    927934                        break;
    928935                }
    929 
    930                 --argc; ++argv;
     936               
     937                --argc;
     938                ++argv;
    931939        }
    932940
    933941        if (task_id != 0) {
    934                 if (argc == 0) return 0;
     942                if (argc == 0)
     943                        return 0;
    935944                printf("Extra arguments\n");
    936945                print_syntax();
     
    946955        /* Preload the specified program file. */
    947956        printf("Spawning '%s' with arguments:\n", *argv);
    948         {
    949                 char **cp = argv;
    950                 while (*cp) printf("'%s'\n", *cp++);
    951         }
     957       
     958        char **cp = argv;
     959        while (*cp)
     960                printf("'%s'\n", *cp++);
     961       
    952962        task_ldr = preload_task(*argv, argv, &task_id);
    953963        task_wait_for = true;
Note: See TracChangeset for help on using the changeset viewer.