Changeset 46c20c8 in mainline for uspace/app


Ignore:
Timestamp:
2010-11-26T20:08:10Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45df59a
Parents:
fb150d78 (diff), ffdd2b9 (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.

Location:
uspace/app
Files:
112 added
1 deleted
90 edited
7 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/Makefile

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

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

    rfb150d78 r46c20c8  
    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

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

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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    2929#include <stdio.h>
    3030#include <stdlib.h>
    31 #include <string.h>
     31#include <str.h>
     32#include <sys/typefmt.h>
    3233#include "config.h"
    3334#include "util.h"
     
    6869        unsigned int argc;
    6970        unsigned int i, j;
    70         dev_handle_t handle;
     71        devmap_handle_t handle;
    7172        uint8_t *blk;
    7273        size_t size, bytes, rows;
    7374        size_t block_size;
    7475        int rc;
    75         bn_t ba;
     76        aoff64_t ba;
    7677        uint8_t b;
    7778
     
    122123                rc = block_read_direct(handle, ba, 1, blk);
    123124                if (rc != EOK) {
    124                         printf("%s: Error reading block %llu\n", cmdname, ba);
     125                        printf("%s: Error reading block %" PRIuOFF64 "\n", cmdname, ba);
    125126                        free(blk);
    126127                        block_fini(handle);
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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;
     
    9595
    9696        if (vb)
    97                 printf("%d bytes to copy\n", total);
     97                printf("%" PRIu64 " bytes to copy\n", total);
    9898
    9999        lseek(fd1, 0, SEEK_SET);
     
    130130                 */
    131131                if (res != 0) {
    132                         printf("\n%d more bytes than actually exist were copied\n", res);
     132                        printf("\n%zd more bytes than actually exist were copied\n", res);
    133133                        goto err;
    134134                }
     
    187187                        return CMD_SUCCESS;
    188188                case 'v':
    189                         printf("%d\n", CP_VERSION);
     189                        printf("%s\n", CP_VERSION);
    190190                        return CMD_SUCCESS;
    191191                case 'V':
     
    223223
    224224        if (verbose)
    225                 printf("%d bytes copied\n", ret);
     225                printf("%" PRId64 " bytes copied\n", ret);
    226226
    227227        if (ret >= 0)
  • uspace/app/bdsh/cmds/modules/help/help.c

    rfb150d78 r46c20c8  
    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
    47 #define HELP_IS_MODULE   1
    48 #define HELP_IS_BUILTIN  0
    49 #define HELP_IS_RUBBISH  -1
     47#define HELP_IS_COMMANDS        2
     48#define HELP_IS_MODULE          1
     49#define HELP_IS_BUILTIN         0
     50#define HELP_IS_RUBBISH         -1
    5051
    5152volatile int mod_switch = -1;
     
    5556{
    5657        int rc = HELP_IS_RUBBISH;
     58
     59        if (str_cmp(cmd, "commands") == 0)
     60                return HELP_IS_COMMANDS;
    5761
    5862        rc = is_builtin(cmd);
     
    9094}
    9195
    92 int cmd_help(char *argv[])
     96static void help_commands(void)
    9397{
     98        builtin_t *cmd;
    9499        module_t *mod;
    95         builtin_t *cmd;
    96         unsigned int i = 0;
    97         int rc = 0;
    98         int argc;
    99         int level = HELP_SHORT;
     100        unsigned int i;
    100101
    101         argc = cli_count_args(argv);
    102 
    103         if (argc > 3) {
    104                 printf("\nToo many arguments to `%s', try:\n", cmdname);
    105                 help_cmd_help(HELP_SHORT);
    106                 return CMD_FAILURE;
    107         }
    108 
    109         if (argc == 3) {
    110                 if (!str_cmp("extended", argv[2]))
    111                         level = HELP_LONG;
    112                 else
    113                         level = HELP_SHORT;
    114         }
    115 
    116         if (argc > 1) {
    117                 rc = is_mod_or_builtin(argv[1]);
    118                 switch (rc) {
    119                 case HELP_IS_RUBBISH:
    120                         printf("Invalid command %s\n", argv[1]);
    121                         return CMD_FAILURE;
    122                 case HELP_IS_MODULE:
    123                         help_module(mod_switch, level);
    124                         return CMD_SUCCESS;
    125                 case HELP_IS_BUILTIN:
    126                         help_builtin(mod_switch, level);
    127                         return CMD_SUCCESS;
    128                 }
    129         }
    130 
    131         printf("\n  Available commands are:\n");
     102        printf("\n  Bdsh built-in commands:\n");
    132103        printf("  ------------------------------------------------------------\n");
    133104
     
    154125        printf("\n  Try %s %s for more information on how `%s' works.\n\n",
    155126                cmdname, cmdname, cmdname);
     127}
     128
     129/** Display survival tips. ('help' without arguments) */
     130static void help_survival(void)
     131{
     132        printf("Don't panic!\n\n");
     133
     134        printf("This is Bdsh, the Brain dead shell, currently "
     135            "the primary user interface to HelenOS. Bdsh allows you to enter "
     136            "commands and supports history (Up, Down arrow keys), "
     137            "line editing (Left Arrow, Right Arrow, Home, End, Backspace), "
     138            "selection (Shift + movement keys), copy and paste (Ctrl-C, "
     139            "Ctrl-V), similar to common desktop environments.\n\n");
     140
     141        printf("The most basic filesystem commands are Bdsh builtins. Type "
     142            "'help commands' [Enter] to see the list of Bdsh builtin commands. "
     143            "Other commands are external executables located in the /app and "
     144            "/srv directories. Type 'ls /app' [Enter] and 'ls /srv' [Enter] "
     145            "to see their list. You can execute an external command simply "
     146            "by entering its name (e.g. type 'tetris' [Enter]).\n\n");
     147
     148        printf("HelenOS has virtual consoles (VCs). You can switch between "
     149            "these using the F1-F11 keys.\n\n");
     150
     151        printf("This is but a small glimpse of what you can do with HelenOS. "
     152            "To learn more please point your browser to the HelenOS User's "
     153            "Guide: http://trac.helenos.org/trac.fcgi/wiki/UsersGuide\n\n");
     154}
     155
     156int cmd_help(char *argv[])
     157{
     158        int rc = 0;
     159        int argc;
     160        int level = HELP_SHORT;
     161
     162        argc = cli_count_args(argv);
     163
     164        if (argc > 3) {
     165                printf("\nToo many arguments to `%s', try:\n", cmdname);
     166                help_cmd_help(HELP_SHORT);
     167                return CMD_FAILURE;
     168        }
     169
     170        if (argc == 3) {
     171                if (!str_cmp("extended", argv[2]))
     172                        level = HELP_LONG;
     173                else
     174                        level = HELP_SHORT;
     175        }
     176
     177        if (argc > 1) {
     178                rc = is_mod_or_builtin(argv[1]);
     179                switch (rc) {
     180                case HELP_IS_RUBBISH:
     181                        printf("Invalid topic %s\n", argv[1]);
     182                        return CMD_FAILURE;
     183                case HELP_IS_COMMANDS:
     184                        help_commands();
     185                        return CMD_SUCCESS;
     186                case HELP_IS_MODULE:
     187                        help_module(mod_switch, level);
     188                        return CMD_SUCCESS;
     189                case HELP_IS_BUILTIN:
     190                        help_builtin(mod_switch, level);
     191                        return CMD_SUCCESS;
     192                }
     193        }
     194
     195        help_survival();
    156196
    157197        return CMD_SUCCESS;
  • uspace/app/bdsh/cmds/modules/kcon/kcon.c

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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[] = {
     
    168168                rc = write(fd, buffer, to_write);
    169169                if (rc <= 0) {
    170                         printf("%s: Error writing file (%d).\n", cmdname, rc);
     170                        printf("%s: Error writing file (%zd).\n", cmdname, rc);
    171171                        close(fd);
    172172                        return CMD_FAILURE;
     
    177177        rc = close(fd);
    178178        if (rc != 0) {
    179                 printf("%s: Error writing file (%d).\n", cmdname, rc);
     179                printf("%s: Error writing file (%zd).\n", cmdname, rc);
    180180                return CMD_FAILURE;
    181181        }
  • uspace/app/bdsh/cmds/modules/module_aliases.h

    rfb150d78 r46c20c8  
    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

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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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/cmds/modules/unmount/unmount.c

    rfb150d78 r46c20c8  
    4747        } else {
    4848                help_cmd_unmount(HELP_SHORT);
    49                 printf("Usage:  %s <mp>\n", cmdname);
     49                printf("Usage: %s <mp>\n", cmdname);
    5050        }
    5151        return;
     
    6868        rc = unmount(argv[1]);
    6969        if (rc != EOK) {
    70                 printf("Unable to unmount %s (rc=%d)\n", argv[1]);
     70                printf("Unable to unmount %s (rc=%d)\n", argv[1], rc);
    7171                return CMD_FAILURE;
    7272        }
  • uspace/app/bdsh/errors.c

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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>
     43#include <errno.h>
    4244
    4345#include "config.h"
     
    115117        task_exit_t texit;
    116118        char *tmp;
    117         int retval;
     119        int rc, retval;
    118120
    119121        tmp = str_dup(find_command(cmd));
    120122        free(found);
    121123
    122         tid = task_spawn((const char *)tmp, argv);
     124        rc = task_spawnv(&tid, tmp, (const char **) argv);
    123125        free(tmp);
    124126
    125         if (tid == 0) {
    126                 cli_error(CL_EEXEC, "Cannot spawn `%s'.", cmd);
     127        if (rc != 0) {
     128                cli_error(CL_EEXEC, "%s: Cannot spawn `%s' (%s)", progname, cmd,
     129                    str_error(rc));
    127130                return 1;
    128131        }
    129132       
    130         task_wait(tid, &texit, &retval);
    131         if (texit != TASK_EXIT_NORMAL) {
    132                 printf("Command failed (unexpectedly terminated).\n");
     133        rc = task_wait(tid, &texit, &retval);
     134        if (rc != EOK) {
     135                printf("%s: Failed waiting for command (%s)\n", progname,
     136                    str_error(rc));
     137        } else if (texit != TASK_EXIT_NORMAL) {
     138                printf("%s: Command failed (unexpectedly terminated)\n", progname);
    133139        } else if (retval != 0) {
    134                 printf("Command failed (return value %d).\n", retval);
     140                printf("%s: Command failed (exit code %d)\n",
     141                    progname, retval);
    135142        }
    136143
  • uspace/app/bdsh/exec.h

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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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);
     
    8889                exit(EXIT_FAILURE);
    8990
    90         printf("Welcome to %s - %s\nType `help' at any time for usage information.\n",
    91                 progname, PACKAGE_STRING);
    92 
    9391        while (!cli_quit) {
    9492                get_input(&usr);
     
    9997                }
    10098        }
    101         goto finit;
    10299
    103 finit:
     100        printf("Leaving %s.\n", progname);
     101
    104102        cli_finit(&usr);
    105103        return ret;
  • uspace/app/bdsh/scli.h

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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                        }
     
    780781                        c = str_decode(row_buf, &pos, size);
    781782                        if (c != '\t') {
    782                                 printf("%lc", c);
     783                                printf("%lc", (wint_t) c);
    783784                                s_column += 1;
    784785                        } else {
     
    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);
    833         printf("%*s", scr_columns - 1 - n, "");
     832       
     833        int pos = scr_columns - 1 - n;
     834        printf("%*s", pos, "");
    834835        fflush(stdout);
    835         console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     836        console_set_style(con, STYLE_NORMAL);
    836837
    837838        pane.rflags |= REDRAW_CARET;
     
    847848
    848849        spt_get_coord(&caret_pt, &coord);
    849         console_goto(con, coord.column - pane.sh_column,
     850        console_set_pos(con, coord.column - pane.sh_column,
    850851            coord.row - pane.sh_row);
    851852}
     
    11521153static void status_display(char const *str)
    11531154{
    1154         console_goto(con, 0, scr_rows - 1);
    1155         console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
    1156         printf(" %*s ", -(scr_columns - 3), str);
     1155        console_set_pos(con, 0, scr_rows - 1);
     1156        console_set_style(con, STYLE_INVERTED);
     1157       
     1158        int pos = -(scr_columns - 3);
     1159        printf(" %*s ", pos, str);
    11571160        fflush(stdout);
    1158         console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     1161        console_set_style(con, STYLE_NORMAL);
    11591162
    11601163        pane.rflags |= REDRAW_CARET;
  • uspace/app/edit/sheet.c

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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 = \
    3935        getterm.c \
    40         version.c
     36        version.c \
     37        welcome.c
    4138
    42 include ../Makefile.common
     39include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/getterm/getterm.c

    rfb150d78 r46c20c8  
    4040#include <stdio.h>
    4141#include <task.h>
     42#include <str_error.h>
     43#include <errno.h>
    4244#include "version.h"
     45#include "welcome.h"
     46
     47#define APP_NAME  "getterm"
    4348
    4449static void usage(void)
    4550{
    46         printf("Usage: getterm <terminal> <path>\n");
     51        printf("Usage: %s <terminal> [-w] <command> [<arguments...>]\n", APP_NAME);
    4752}
    4853
     
    6974}
    7075
    71 static task_id_t spawn(char *fname)
    72 {
    73         char *args[2];
    74        
    75         args[0] = fname;
    76         args[1] = NULL;
    77        
    78         task_id_t id = task_spawn(fname, args);
    79        
    80         if (id == 0)
    81                 printf("Error spawning %s\n", fname);
    82        
    83         return id;
    84 }
    85 
    8676int main(int argc, char *argv[])
    8777{
    88         if (argc < 3) {
     78        int rc;
     79        task_exit_t texit;
     80        int retval;
     81        task_id_t id;
     82        char *fname, *term;
     83        char **cmd_args;
     84        bool print_wmsg;
     85
     86        argv++;
     87        argc--;
     88        if (argc < 1) {
    8989                usage();
    9090                return -1;
    9191        }
     92
     93        if (str_cmp(*argv, "-w") == 0) {
     94                print_wmsg = true;
     95                argv++;
     96                argc--;
     97        } else {
     98                print_wmsg = false;
     99        }
     100
     101        if (argc < 2) {
     102                usage();
     103                return -1;
     104        }
     105
     106        term = *argv++;
     107        fname = *argv;
     108        cmd_args = argv;
    92109       
    93         reopen(&stdin, 0, argv[1], O_RDONLY, "r");
    94         reopen(&stdout, 1, argv[1], O_WRONLY, "w");
    95         reopen(&stderr, 2, argv[1], O_WRONLY, "w");
     110        reopen(&stdin, 0, term, O_RDONLY, "r");
     111        reopen(&stdout, 1, term, O_WRONLY, "w");
     112        reopen(&stderr, 2, term, O_WRONLY, "w");
    96113       
    97114        /*
     
    110127                return -4;
    111128       
    112         version_print(argv[1]);
    113         task_id_t id = spawn(argv[2]);
    114        
    115         if (id != 0) {
    116                 task_exit_t texit;
    117                 int retval;
    118                 task_wait(id, &texit, &retval);
    119                
    120                 return 0;
     129        version_print(term);
     130        if (print_wmsg)
     131                welcome_msg_print();
     132
     133        rc = task_spawnv(&id, fname, (const char * const *) cmd_args);
     134        if (rc != EOK) {
     135                printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,
     136                    str_error(rc));
     137                return -5;
    121138        }
    122        
    123         return -5;
     139
     140        rc = task_wait(id, &texit, &retval);
     141        if (rc != EOK) {
     142                printf("%s: Error waiting for %s (%s)\n", APP_NAME, fname,
     143                    str_error(rc));
     144                return -6;
     145        }
     146
     147        return 0;
    124148}
    125149
  • uspace/app/getterm/version.c

    rfb150d78 r46c20c8  
    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
     
    6161        printf("HelenOS release %s (%s)%s%s\n", release, name, revision, timestamp);
    6262        printf("Running on %s (%s)\n", arch, term);
    63         printf("Copyright (c) 2001-2009 HelenOS project\n\n");
     63        printf("Copyright (c) 2001-2010 HelenOS project\n\n");
    6464}
    6565
  • uspace/app/init/Makefile

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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                 return false;
    105         case ELIMIT:
    106                 printf(NAME ": Unable to mount device filesystem\n");
    107                 return false;
    108         case ENOENT:
    109                 printf(NAME ": Unknown filesystem type (devfs)\n");
    110                 return false;
    111         default:
    112                 printf(NAME ": Error mounting device filesystem (%d)\n", rc);
    113                 return false;
    114         }
    115        
    116         return true;
    117 }
    118 
    119 static void spawn(char *fname)
    120 {
    121         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        int rc;
    122127        struct stat s;
    123128       
     
    125130                return;
    126131       
    127         printf(NAME ": Spawning %s\n", fname);
    128        
    129         argv[0] = fname;
    130         argv[1] = NULL;
    131        
    132         if (!task_spawn(fname, argv))
    133                 printf(NAME ": Error spawning %s\n", fname);
    134 }
    135 
    136 static void srv_start(char *fname)
    137 {
    138         char *argv[2];
     132        printf("%s: Spawning %s\n", NAME, fname);
     133        rc = task_spawnl(NULL, fname, fname, NULL);
     134        if (rc != EOK) {
     135                printf("%s: Error spawning %s (%s)\n", NAME, fname,
     136                    str_error(rc));
     137        }
     138}
     139
     140static void srv_start(const char *fname)
     141{
    139142        task_id_t id;
    140143        task_exit_t texit;
     
    145148                return;
    146149       
    147         printf(NAME ": Starting %s\n", fname);
    148        
    149         argv[0] = fname;
    150         argv[1] = NULL;
    151        
    152         id = task_spawn(fname, argv);
     150        printf("%s: Starting %s\n", NAME, fname);
     151        rc = task_spawnl(&id, fname, fname, NULL);
    153152        if (!id) {
    154                 printf(NAME ": Error spawning %s\n", fname);
    155                 return;
    156         }
    157 
     153                printf("%s: Error spawning %s (%s)\n", NAME, fname,
     154                    str_error(rc));
     155                return;
     156        }
     157       
    158158        rc = task_wait(id, &texit, &retval);
    159159        if (rc != EOK) {
    160                 printf(NAME ": Error waiting for %s\n", fname);
    161                 return;
    162         }
    163 
    164         if ((texit != TASK_EXIT_NORMAL) || (retval != 0)) {
    165                 printf(NAME ": Server %s failed to start (returned %d)\n",
     160                printf("%s: Error waiting for %s (%s(\n", NAME, fname,
     161                    str_error(rc));
     162                return;
     163        }
     164       
     165        if (texit != TASK_EXIT_NORMAL) {
     166                printf("%s: Server %s failed to start (unexpectedly "
     167                    "terminated)\n", NAME, fname);
     168                return;
     169        }
     170
     171        if (retval != 0) {
     172                printf("%s: Server %s failed to start (exit code %d)\n", NAME,
    166173                        fname, retval);
    167174        }
    168175}
    169176
    170 static void console(char *dev)
    171 {
    172         char *argv[3];
     177static void console(const char *dev)
     178{
    173179        char hid_in[DEVMAP_NAME_MAXLEN];
    174180        int rc;
     
    176182        snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
    177183       
    178         printf(NAME ": Spawning %s with %s\n", SRV_CONSOLE, hid_in);
     184        printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in);
    179185       
    180186        /* Wait for the input device to be ready */
    181         dev_handle_t handle;
     187        devmap_handle_t handle;
    182188        rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
    183        
    184         if (rc == EOK) {
    185                 argv[0] = SRV_CONSOLE;
    186                 argv[1] = hid_in;
    187                 argv[2] = NULL;
    188                
    189                 if (!task_spawn(SRV_CONSOLE, argv))
    190                         printf(NAME ": Error spawning %s with %s\n", SRV_CONSOLE, hid_in);
    191         } else
    192                 printf(NAME ": Error waiting on %s\n", hid_in);
    193 }
    194 
    195 static void getterm(char *dev, char *app)
    196 {
    197         char *argv[4];
     189        if (rc != EOK) {
     190                printf("%s: Error waiting on %s (%s)\n", NAME, hid_in,
     191                    str_error(rc));
     192                return;
     193        }
     194       
     195        rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, hid_in, NULL);
     196        if (rc != EOK) {
     197                printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
     198                    hid_in, str_error(rc));
     199        }
     200}
     201
     202static void getterm(const char *dev, const char *app, bool wmsg)
     203{
    198204        char term[DEVMAP_NAME_MAXLEN];
    199205        int rc;
     
    201207        snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
    202208       
    203         printf(NAME ": Spawning %s with %s %s\n", APP_GETTERM, term, app);
     209        printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
    204210       
    205211        /* Wait for the terminal device to be ready */
    206         dev_handle_t handle;
     212        devmap_handle_t handle;
    207213        rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
    208        
    209         if (rc == EOK) {
    210                 argv[0] = APP_GETTERM;
    211                 argv[1] = term;
    212                 argv[2] = app;
    213                 argv[3] = NULL;
    214                
    215                 if (!task_spawn(APP_GETTERM, argv))
    216                         printf(NAME ": Error spawning %s with %s %s\n", APP_GETTERM,
    217                             term, app);
    218         } else
    219                 printf(NAME ": Error waiting on %s\n", term);
    220 }
    221 
    222 static void mount_scratch(void)
    223 {
    224         int rc;
    225 
    226         printf("Trying to mount null/0 on /scratch... ");
    227         fflush(stdout);
    228 
    229         rc = mount("tmpfs", "/scratch", "null/0", "", 0);
    230         if (rc == EOK)
    231                 printf("OK\n");
    232         else
    233                 printf("Failed\n");
    234 }
    235 
    236 static void mount_data(void)
    237 {
    238         int rc;
    239 
    240         printf("Trying to mount bd/disk0 on /data... ");
    241         fflush(stdout);
    242 
    243         rc = mount("fat", "/data", "bd/disk0", "wtcache", 0);
    244         if (rc == EOK)
    245                 printf("OK\n");
    246         else
    247                 printf("Failed\n");
     214        if (rc != EOK) {
     215                printf("%s: Error waiting on %s (%s)\n", NAME, term,
     216                    str_error(rc));
     217                return;
     218        }
     219       
     220        if (wmsg) {
     221                rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, "-w", term,
     222                    app, NULL);
     223                if (rc != EOK) {
     224                        printf("%s: Error spawning %s -w %s %s (%s)\n", NAME,
     225                            APP_GETTERM, term, app, str_error(rc));
     226                }
     227        } else {
     228                rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app,
     229                    NULL);
     230                if (rc != EOK) {
     231                        printf("%s: Error spawning %s %s %s (%s)\n", NAME,
     232                            APP_GETTERM, term, app, str_error(rc));
     233                }
     234        }
     235}
     236
     237static bool mount_scratch(void)
     238{
     239        int rc = mount(SCRATCH_FS_TYPE, SCRATCH_MOUNT_POINT, "", "", 0);
     240        return mount_report("Scratch filesystem", SCRATCH_MOUNT_POINT,
     241            SCRATCH_FS_TYPE, NULL, rc);
     242}
     243
     244static bool mount_data(void)
     245{
     246        int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0);
     247        return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
     248            DATA_DEVICE, rc);
    248249}
    249250
     
    253254       
    254255        if (!mount_root(STRING(RDFMT))) {
    255                 printf(NAME ": Exiting\n");
     256                printf("%s: Exiting\n", NAME);
    256257                return -1;
    257258        }
    258 
     259       
    259260        /* Make sure tmpfs is running. */
    260261        if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
     
    266267       
    267268        if (!mount_devfs()) {
    268                 printf(NAME ": Exiting\n");
     269                printf("%s: Exiting\n", NAME);
    269270                return -2;
    270271        }
    271 
     272       
    272273        mount_scratch();
    273274       
     
    276277        srv_start("/srv/cuda_adb");
    277278        srv_start("/srv/i8042");
     279        srv_start("/srv/s3c24ser");
    278280        srv_start("/srv/adb_ms");
    279281        srv_start("/srv/char_ms");
    280 
     282        srv_start("/srv/s3c24ts");
     283       
    281284        spawn("/srv/fb");
    282285        spawn("/srv/kbd");
     
    284287       
    285288        spawn("/srv/clip");
    286 
     289       
    287290        /*
    288291         * Start these synchronously so that mount_data() can be
     
    295298        (void) srv_start;
    296299#endif
    297 
     300       
    298301#ifdef CONFIG_MOUNT_DATA
    299302        mount_data();
     
    301304        (void) mount_data;
    302305#endif
    303 
    304         getterm("term/vc0", "/app/bdsh");
    305         getterm("term/vc1", "/app/bdsh");
    306         getterm("term/vc2", "/app/bdsh");
    307         getterm("term/vc3", "/app/bdsh");
    308         getterm("term/vc4", "/app/bdsh");
    309         getterm("term/vc5", "/app/bdsh");
    310         getterm("term/vc6", "/app/klog");
    311 
     306       
     307        getterm("term/vc0", "/app/bdsh", true);
     308        getterm("term/vc1", "/app/bdsh", false);
     309        getterm("term/vc2", "/app/bdsh", false);
     310        getterm("term/vc3", "/app/bdsh", false);
     311        getterm("term/vc4", "/app/bdsh", false);
     312        getterm("term/vc5", "/app/bdsh", false);
     313        getterm("term/vc6", "/app/klog", false);
     314       
    312315        return 0;
    313316}
  • uspace/app/klog/Makefile

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    4343#include <event.h>
    4444#include <errno.h>
     45#include <str_error.h>
    4546#include <io/klog.h>
    4647
    47 #define NAME  "klog"
     48#define NAME       "klog"
     49#define LOG_FNAME  "/log/klog"
    4850
    4951/* Pointer to klog area */
    5052static wchar_t *klog;
    5153static size_t klog_length;
     54
     55static FILE *log;
    5256
    5357static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
     
    5862        size_t i;
    5963       
    60         for (i = klog_len - klog_stored; i < klog_len; i++)
    61                 putchar(klog[(klog_start + i) % klog_length]);
     64        for (i = klog_len - klog_stored; i < klog_len; i++) {
     65                wchar_t ch = klog[(klog_start + i) % klog_length];
     66               
     67                putchar(ch);
     68               
     69                if (log != NULL)
     70                        fputc(ch, log);
     71        }
     72       
     73        if (log != NULL) {
     74                fflush(log);
     75                fsync(fileno(log));
     76        }
    6277}
    6378
    6479int main(int argc, char *argv[])
    6580{
    66         size_t klog_pages = sysinfo_value("klog.pages");
     81        size_t klog_pages;
     82        if (sysinfo_get_value("klog.pages", &klog_pages) != EOK) {
     83                printf("%s: Error getting klog address\n", NAME);
     84                return -1;
     85        }
     86       
    6787        size_t klog_size = klog_pages * PAGE_SIZE;
    6888        klog_length = klog_size / sizeof(wchar_t);
     
    7090        klog = (wchar_t *) as_get_mappable_page(klog_size);
    7191        if (klog == NULL) {
    72                 printf(NAME ": Error allocating memory area\n");
     92                printf("%s: Error allocating memory area\n", NAME);
    7393                return -1;
    7494        }
     
    7797            klog_size, SERVICE_MEM_KLOG);
    7898        if (res != EOK) {
    79                 printf(NAME ": Error initializing memory area\n");
     99                printf("%s: Error initializing memory area\n", NAME);
    80100                return -1;
    81101        }
    82102       
    83103        if (event_subscribe(EVENT_KLOG, 0) != EOK) {
    84                 printf(NAME ": Error registering klog notifications\n");
     104                printf("%s: Error registering klog notifications\n", NAME);
    85105                return -1;
    86106        }
     107       
     108        /*
     109         * Mode "a" would be definitively much better here, but it is
     110         * not well supported by the FAT driver.
     111         *
     112         */
     113        log = fopen(LOG_FNAME, "w");
     114        if (log == NULL)
     115                printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME,
     116                    str_error(errno));
    87117       
    88118        async_set_interrupt_received(interrupt_received);
  • uspace/app/mkfat/Makefile

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    8585    struct fat_params *par);
    8686static int fat_blocks_write(struct fat_params const *par,
    87     dev_handle_t handle);
     87    devmap_handle_t handle);
    8888static void fat_bootsec_create(struct fat_params const *par, struct fat_bs *bs);
    8989
     
    9595        int rc;
    9696        char *dev_path;
    97         dev_handle_t handle;
     97        devmap_handle_t handle;
    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;
     
    234234
    235235/** Create file system with the given parameters. */
    236 static int fat_blocks_write(struct fat_params const *par, dev_handle_t handle)
    237 {
    238         bn_t addr;
     236static int fat_blocks_write(struct fat_params const *par, devmap_handle_t handle)
     237{
     238        aoff64_t addr;
    239239        uint8_t *buffer;
    240240        int i;
  • uspace/app/netecho/Makefile

    rfb150d78 r46c20c8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBC_PREFIX)/libc.a
    32 
    33 OUTPUT = libpci.a
     31LIBS =
     32EXTRA_CFLAGS =
     33BINARY = netecho
    3434
    3535SOURCES = \
    36         access.c \
    37         generic.c \
    38         names.c \
    39         i386-ports.c
     36        netecho.c \
     37        print_error.c
    4038
    41 include ../Makefile.common
     39include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/redir/Makefile

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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#include <errno.h>
     46
     47#define NAME  "redir"
    4448
    4549static void usage(void)
    4650{
    47         printf("Usage: redir [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n");
     51        printf("Usage: %s [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n",
     52            NAME);
    4853}
    4954
     
    7277static task_id_t spawn(int argc, char *argv[])
    7378{
    74         char **args = (char *) calloc(argc + 1, sizeof(char *));
     79        const char **args;
     80        task_id_t id = 0;
     81        int rc;
     82
     83        args = (const char **) calloc(argc + 1, sizeof(char *));
    7584        if (!args) {
    7685                printf("No memory available\n");
     
    8493        args[argc] = NULL;
    8594       
    86         task_id_t id = task_spawn(argv[0], args);
     95        rc = task_spawnv(&id, argv[0], args);
    8796       
    8897        free(args);
    8998       
    90         if (id == 0)
    91                 printf("Error spawning %s\n", argv[0]);
     99        if (rc != EOK) {
     100                printf("%s: Error spawning %s (%s)\n", NAME, argv[0],
     101                    str_error(rc));
     102        }
    92103       
    93104        return id;
  • uspace/app/sbi/src/bigint_t.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup libcsparc64
    30  * @{
    31  */
    32 /** @file
    33  */
    34 
    35 #ifndef LIBC_ia64_ISTATE_H_
    36 #define LIBC_ia64_ISTATE_H_
     29#ifndef BIGINT_T_H_
     30#define BIGINT_T_H_
    3731
    3832#include <sys/types.h>
     33#include <stdint.h>
    3934
    40 /** Interrupt context.
     35typedef uint8_t bigint_word_t;
     36typedef uint16_t bigint_dword_t;
     37
     38#define BIGINT_BASE ((bigint_dword_t) 256UL)
     39
     40/** Big integer.
    4141 *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
     42 * Used to implement Sysel @c int type.
    4343 */
    44 typedef struct istate {
    45         /* TODO */
    46 } istate_t;
     44typedef struct bigint {
     45        /** Number of non-zero digits in the @c digit array. */
     46        size_t length;
    4747
    48 static inline uintptr_t istate_get_pc(istate_t *istate)
    49 {
    50         /* TODO */
    51         return 0;
    52 }
     48        /** Sign. */
     49        bool_t negative;
    5350
    54 static inline uintptr_t istate_get_fp(istate_t *istate)
    55 {
    56         /* TODO */
    57         return 0;
    58 }
     51        /** Digits starting from the least significant. */
     52        bigint_word_t *digit;
     53} bigint_t;
    5954
    6055#endif
    61 
    62 /** @}
    63  */
  • uspace/app/sbi/src/builtin.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup libcamd64
    30  * @{
    31  */
    32 /** @file Macros for format specifiers.
    33  *
    34  * Macros for formatting stdint types as specified in section
    35  * 7.8.1 Macros for format specifiers of the C99 draft specification
    36  * (ISO/IEC 9899:201x). Only some macros from the specification are
    37  * implemented.
    38  */
     29#ifndef BUILTIN_H_
     30#define BUILTIN_H_
    3931
    40 #ifndef LIBC_amd64_INTTYPES_H_
    41 #define LIBC_amd64_INTTYPES_H_
     32#include "mytypes.h"
    4233
    43 #define PRId8 "d"
    44 #define PRId16 "d"
    45 #define PRId32 "d"
    46 #define PRId64 "lld"
    47 #define PRIdPTR "lld"
     34void builtin_declare(stree_program_t *program);
     35void builtin_bind(builtin_t *bi);
     36void builtin_code_snippet(builtin_t *bi, const char *snippet);
    4837
    49 #define PRIo8 "o"
    50 #define PRIo16 "o"
    51 #define PRIo32 "o"
    52 #define PRIo64 "llo"
    53 #define PRIoPTR "llo"
     38stree_csi_t *builtin_get_gf_class(builtin_t *builtin);
     39void builtin_run_proc(run_t *run, stree_proc_t *proc);
    5440
    55 #define PRIu8 "u"
    56 #define PRIu16 "u"
    57 #define PRIu32 "u"
    58 #define PRIu64 "llu"
    59 #define PRIuPTR "llu"
     41rdata_var_t *builtin_get_self_mbr_var(run_t *run, const char *mbr_name);
     42void builtin_return_string(run_t *run, const char *str);
    6043
    61 #define PRIx8 "x"
    62 #define PRIx16 "x"
    63 #define PRIx32 "x"
    64 #define PRIx64 "llx"
    65 #define PRIxPTR "llx"
     44stree_symbol_t *builtin_declare_fun(stree_csi_t *csi, const char *name);
     45void builtin_fun_add_arg(stree_symbol_t *fun_sym, const char *name);
    6646
    67 #define PRIX8 "X"
    68 #define PRIX16 "X"
    69 #define PRIX32 "X"
    70 #define PRIX64 "llX"
    71 #define PRIXPTR "llX"
     47stree_symbol_t *builtin_find_lvl0(builtin_t *bi, const char *sym_name);
     48stree_symbol_t *builtin_find_lvl1(builtin_t *bi, const char *csi_name,
     49    const char *sym_name);
     50
     51void builtin_fun_bind(builtin_t *bi, const char *csi_name,
     52    const char *sym_name, builtin_proc_t bproc);
    7253
    7354#endif
    74 
    75 /** @}
    76  */
  • uspace/app/sbi/src/input.h

    rfb150d78 r46c20c8  
    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/tdata.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup libcarm32
    30  * @{
    31  */
    32 /** @file Macros for format specifiers.
    33  *
    34  * Macros for formatting stdint types as specified in section
    35  * 7.8.1 Macros for format specifiers of the C99 draft specification
    36  * (ISO/IEC 9899:201x). Only some macros from the specification are
    37  * implemented.
    38  */
     29#ifndef TDATA_H_
     30#define TDATA_H_
    3931
    40 #ifndef LIBC_arm32_INTTYPES_H_
    41 #define LIBC_arm32_INTTYPES_H_
     32#include "mytypes.h"
    4233
    43 #define PRId8 "d"
    44 #define PRId16 "d"
    45 #define PRId32 "d"
    46 #define PRId64 "lld"
    47 #define PRIdPTR "d"
     34tdata_item_t *tdata_item_new(titem_class_t tic);
     35tdata_array_t *tdata_array_new(void);
     36tdata_object_t *tdata_object_new(void);
     37tdata_primitive_t *tdata_primitive_new(tprimitive_class_t tpc);
     38tdata_deleg_t *tdata_deleg_new(void);
     39tdata_ebase_t *tdata_ebase_new(void);
     40tdata_enum_t *tdata_enum_new(void);
     41tdata_fun_t *tdata_fun_new(void);
     42tdata_vref_t *tdata_vref_new(void);
    4843
    49 #define PRIo8 "o"
    50 #define PRIo16 "o"
    51 #define PRIo32 "o"
    52 #define PRIo64 "llo"
    53 #define PRIoPTR "o"
     44tdata_fun_sig_t *tdata_fun_sig_new(void);
    5445
    55 #define PRIu8 "u"
    56 #define PRIu16 "u"
    57 #define PRIu32 "u"
    58 #define PRIu64 "llu"
    59 #define PRIuPTR "u"
     46tdata_tvv_t *tdata_tvv_new(void);
     47tdata_item_t *tdata_tvv_get_val(tdata_tvv_t *tvv, sid_t name);
     48void tdata_tvv_set_val(tdata_tvv_t *tvv, sid_t name, tdata_item_t *tvalue);
    6049
    61 #define PRIx8 "x"
    62 #define PRIx16 "x"
    63 #define PRIx32 "x"
    64 #define PRIx64 "llx"
    65 #define PRIxPTR "x"
     50bool_t tdata_is_csi_derived_from_ti(stree_csi_t *a, tdata_item_t *tb);
     51bool_t tdata_is_ti_derived_from_ti(tdata_item_t *ta, tdata_item_t *tb);
     52bool_t tdata_item_equal(tdata_item_t *a, tdata_item_t *b);
    6653
    67 #define PRIX8 "X"
    68 #define PRIX16 "X"
    69 #define PRIX32 "X"
    70 #define PRIX64 "llX"
    71 #define PRIXPTR "X"
     54void tdata_item_subst(tdata_item_t *ti, tdata_tvv_t *tvv, tdata_item_t **res);
     55void tdata_item_print(tdata_item_t *titem);
    7256
    7357#endif
    74 
    75 /** @}
    76  */
  • uspace/app/stats/stats.c

    rfb150d78 r46c20c8  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2010 Stanislav Kozina
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libc
     29/** @addtogroup stats
     30 * @brief Print system statistics.
    3031 * @{
    3132 */
    32 /** @file Formatting macros for types from sys/types.h and some other
    33  * system types.
     33/**
     34 * @file
    3435 */
    3536
    36 #ifndef LIBC_SYS_TYPEFMT_H_
    37 #define LIBC_SYS_TYPEFMT_H_
     37#include <stdio.h>
     38#include <stats.h>
     39#include <sys/time.h>
     40#include <inttypes.h>
     41#include <malloc.h>
    3842
    39 #include <inttypes.h>
     43#define NAME  "sysstat"
    4044
    41 /* off_t */
    42 #define PRIdOFF "ld"
    43 #define PRIuOFF "lu"
    44 #define PRIxOFF "lx"
    45 #define PRIXOFF "lX"
     45#define DAY     86400
     46#define HOUR    3600
     47#define MINUTE  60
    4648
    47 /* bn_t */
    48 #define PRIdBN PRId64
    49 #define PRIuBN PRIu64
    50 #define PRIxBN PRIx64
    51 #define PRIXBN PRIX64
    52 
    53 /* (s)size_t */
    54 #define PRIdSIZE PRIdPTR
    55 #define PRIuSIZE PRIuPTR
    56 #define PRIxSIZE PRIxPTR
    57 #define PRIXSIZE PRIXPTR
    58 
    59 /* sysarg_t */
    60 #define PRIdSYSARG PRIdPTR
    61 #define PRIuSYSARG PRIuPTR
    62 #define PRIxSYSARG PRIxPTR
    63 #define PRIXSYSARG PRIxPTR
    64 
    65 /* ipcarg_t */
    66 #define PRIdIPCARG PRIdPTR
    67 #define PRIuIPCARG PRIuPTR
    68 #define PRIxIPCARG PRIxPTR
    69 #define PRIXIPCARG PRIXPTR
    70 
    71 /* taskid_t */
    72 #define PRIdTASKID PRId64
    73 #define PRIuTASKID PRIu64
    74 #define PRIxTASKID PRIx64
    75 #define PRIXTASKID PRIx64
    76 
    77 #endif
     49int main(int argc, char *argv[])
     50{
     51        struct timeval time;
     52        if (gettimeofday(&time, NULL) != 0) {
     53                fprintf(stderr, "%s: Cannot get time of day\n", NAME);
     54                return -1;
     55        }
     56       
     57        uint64_t sec = time.tv_sec;
     58        printf("%02" PRIu64 ":%02" PRIu64 ":%02" PRIu64,
     59            (sec % DAY) / HOUR, (sec % HOUR) / MINUTE, sec % MINUTE);
     60       
     61        sysarg_t uptime = stats_get_uptime();
     62        printf(", up %" PRIun " days, %" PRIun " hours, "
     63            "%" PRIun " minutes, %" PRIun " seconds",
     64            uptime / DAY, (uptime % DAY) / HOUR,
     65            (uptime % HOUR) / MINUTE, uptime % MINUTE);
     66       
     67        size_t count;
     68        load_t *load = stats_get_load(&count);
     69        if (load != NULL) {
     70                printf(", load average: ");
     71               
     72                size_t i;
     73                for (i = 0; i < count; i++) {
     74                        if (i > 0)
     75                                printf(" ");
     76                       
     77                        stats_print_load_fragment(load[i], 2);
     78                }
     79               
     80                free(load);
     81        }
     82       
     83        printf("\n");
     84        return 0;
     85}
    7886
    7987/** @}
  • uspace/app/taskdump/Makefile

    rfb150d78 r46c20c8  
    2828
    2929USPACE_PREFIX = ../..
    30 LIBS = $(LIBC_PREFIX)/libc.a
    3130EXTRA_CFLAGS = -Iinclude
    32 
    33 OUTPUT = taskdump
     31BINARY = taskdump
    3432
    3533SOURCES = \
     
    3836        symtab.c
    3937
    40 include ../Makefile.common
     38include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/taskdump/elf_core.c

    rfb150d78 r46c20c8  
    6262#include "include/elf_core.h"
    6363
    64 static off_t align_foff_up(off_t foff, uintptr_t vaddr, size_t page_size);
     64static off64_t align_foff_up(off64_t foff, uintptr_t vaddr, size_t page_size);
    6565static int write_all(int fd, void *data, size_t len);
    6666static int write_mem_area(int fd, as_area_info_t *area, int phoneid);
     
    7979 *                      ENOMEM on out of memory, EIO on write error.
    8080 */
    81 int elf_core_save(const char *file_name, as_area_info_t *ainfo, int n, int phoneid)
     81int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid)
    8282{
    8383        elf_header_t elf_hdr;
    84         off_t foff;
     84        off64_t foff;
    8585        size_t n_ph;
    8686        elf_word flags;
     
    8989        int fd;
    9090        int rc;
    91         int i;
     91        unsigned int i;
    9292
    9393        n_ph = n;
     
    184184
    185185        for (i = 0; i < n_ph; ++i) {
    186                 if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off_t) -1) {
     186                if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) {
    187187                        printf("Failed writing memory data.\n");
    188188                        free(p_hdr);
     
    202202
    203203/** Align file offset up to be congruent with vaddr modulo page size. */
    204 static off_t align_foff_up(off_t foff, uintptr_t vaddr, size_t page_size)
    205 {
    206         off_t rfo, rva;
    207         off_t advance;
    208 
    209         rva = vaddr % page_size;
    210         rfo = foff % page_size;
    211 
    212         advance = (rva >= rfo) ? rva - rfo : (page_size + rva - rfo);
    213         return foff + advance;
     204static off64_t align_foff_up(off64_t foff, uintptr_t vaddr, size_t page_size)
     205{
     206        off64_t rva = vaddr % page_size;
     207        off64_t rfo = foff % page_size;
     208       
     209        if (rva >= rfo)
     210                return (foff + (rva - rfo));
     211       
     212        return (foff + (page_size + (rva - rfo)));
    214213}
    215214
  • uspace/app/taskdump/include/elf_core.h

    rfb150d78 r46c20c8  
    3636#define ELF_CORE_H_
    3737
    38 int elf_core_save(const char *file_name, as_area_info_t *ainfo, int n, int phoneid);
     38int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid);
    3939
    4040#endif
  • uspace/app/taskdump/symtab.c

    rfb150d78 r46c20c8  
    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;
     
    307308        rc = lseek(fd, elf_hdr->e_shoff + idx * sizeof(elf_section_header_t),
    308309            SEEK_SET);
    309         if (rc == (off_t) -1)
     310        if (rc == (off64_t) -1)
    310311                return EIO;
    311312
     
    328329 * @return              EOK on success or EIO on failure.
    329330 */
    330 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)
    331332{
    332333        int rc;
    333334
    334335        rc = lseek(fd, start, SEEK_SET);
    335         if (rc == (off_t) -1) {
     336        if (rc == (off64_t) -1) {
    336337                printf("failed seeking chunk\n");
    337338                *ptr = NULL;
  • uspace/app/taskdump/taskdump.c

    rfb150d78 r46c20c8  
    5454#define LINE_BYTES 16
    5555
    56 #define DBUF_SIZE 4096
    57 static uint8_t data_buf[DBUF_SIZE];
    58 
    5956static int phoneid;
    6057static task_id_t task_id;
     
    7067static int thread_dump(uintptr_t thash);
    7168static int areas_dump(void);
    72 static int area_dump(as_area_info_t *area);
    73 static void hex_dump(uintptr_t addr, void *buffer, size_t size);
    7469static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value);
    7570
     
    9085        rc = connect_task(task_id);
    9186        if (rc < 0) {
    92                 printf("Failed connecting to task %" PRIdTASKID ".\n", task_id);
     87                printf("Failed connecting to task %" PRIu64 ".\n", task_id);
    9388                return 1;
    9489        }
     
    9792        app_symtab = NULL;
    9893
    99         printf("Dumping task '%s' (task ID %" PRIdTASKID ").\n", app_name, task_id);
     94        printf("Dumping task '%s' (task ID %" PRIu64 ").\n", app_name, task_id);
    10095        autoload_syms();
    10196        putchar('\n');
     
    131126        if (rc < 0) {
    132127                printf("Error connecting\n");
    133                 printf("ipc_connect_task(%" PRIdTASKID ") -> %d ", task_id, rc);
     128                printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, rc);
    134129                return rc;
    135130        }
     
    173168                                core_file_name = *argv;
    174169                        } else {
    175                                 printf("Uknown option '%s'\n", arg[0]);
     170                                printf("Uknown option '%c'\n", arg[0]);
    176171                                print_syntax();
    177172                                return -1;
     
    245240        printf("Threads:\n");
    246241        for (i = 0; i < n_threads; i++) {
    247                 printf(" [%d] hash: %p\n", 1+i, thash_buf[i]);
     242                printf(" [%zu] hash: %p\n", 1 + i, (void *) thash_buf[i]);
    248243
    249244                thread_dump(thash_buf[i]);
     
    289284        printf("Address space areas:\n");
    290285        for (i = 0; i < n_areas; i++) {
    291                 printf(" [%d] flags: %c%c%c%c base: %p size: %p\n", 1+i,
     286                printf(" [%zu] flags: %c%c%c%c base: %p size: %zu\n", 1 + i,
    292287                    (ainfo_buf[i].flags & AS_AREA_READ) ? 'R' : '-',
    293288                    (ainfo_buf[i].flags & AS_AREA_WRITE) ? 'W' : '-',
    294289                    (ainfo_buf[i].flags & AS_AREA_EXEC) ? 'X' : '-',
    295290                    (ainfo_buf[i].flags & AS_AREA_CACHEABLE) ? 'C' : '-',
    296                     ainfo_buf[i].start_addr, ainfo_buf[i].size);
     291                    (void *) ainfo_buf[i].start_addr, ainfo_buf[i].size);
    297292        }
    298293
     
    331326
    332327        sym_pc = fmt_sym_address(pc);
    333         printf("Thread %p crashed at %s. FP = %p\n", thash, sym_pc, fp);
     328        printf("Thread %p crashed at %s. FP = %p\n", (void *) thash,
     329            sym_pc, (void *) fp);
    334330        free(sym_pc);
    335331
     
    339335        while (stacktrace_fp_valid(&st, fp)) {
    340336                sym_pc = fmt_sym_address(pc);
    341                 printf("  %p: %s\n", fp, sym_pc);
     337                printf("  %p: %s\n", (void *) fp, sym_pc);
    342338                free(sym_pc);
    343339
     
    354350
    355351        return EOK;
    356 }
    357 
    358 static int area_dump(as_area_info_t *area)
    359 {
    360         size_t to_copy;
    361         size_t total;
    362         uintptr_t addr;
    363         int rc;
    364 
    365         addr = area->start_addr;
    366         total = 0;
    367 
    368         while (total < area->size) {
    369                 to_copy = min(area->size - total, DBUF_SIZE);
    370                 rc = udebug_mem_read(phoneid, data_buf, addr, to_copy);
    371                 if (rc < 0) {
    372                         printf("udebug_mem_read() failed.\n");
    373                         return rc;
    374                 }
    375 
    376                 hex_dump(addr, data_buf, to_copy);
    377 
    378                 addr += to_copy;
    379                 total += to_copy;
    380         }
    381 
    382         return EOK;
    383 }
    384 
    385 static void hex_dump(uintptr_t addr, void *buffer, size_t size)
    386 {
    387         uint8_t *data = (uint8_t *) buffer;
    388         uint8_t b;
    389         size_t pos, i;
    390 
    391         assert(addr % LINE_BYTES == 0);
    392         assert(size % LINE_BYTES == 0);
    393 
    394         pos = 0;
    395 
    396         while (pos < size) {
    397                 printf("%08lx:", addr + pos);
    398                 for (i = 0; i < LINE_BYTES; ++i) {
    399                         if (i % 4 == 0) putchar(' ');
    400                         printf(" %02x", data[pos + i]);
    401                 }
    402                 putchar('\t');
    403 
    404                 for (i = 0; i < LINE_BYTES; ++i) {
    405                         b = data[pos + i];
    406                         if (b >= 32 && b < 127) {
    407                                 putchar(b);
    408                         } else {
    409                                 putchar(' ');
    410                         }
    411                 }
    412                 putchar('\n');
    413                 pos += LINE_BYTES;
    414         }
    415352}
    416353
     
    521458
    522459        if (rc == EOK) {
    523                 rc = asprintf(&str, "%p (%s+%p)", addr, name, offs);
     460                rc = asprintf(&str, "%p (%s+%zu)", (void *) addr, name, offs);
    524461        } else {
    525                 rc = asprintf(&str, "%p", addr);
     462                rc = asprintf(&str, "%p", (void *) addr);
    526463        }
    527464
  • uspace/app/tester/Makefile

    rfb150d78 r46c20c8  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBC_PREFIX)/libc.a
    32 
    33 OUTPUT = tester
     31BINARY = tester
    3432
    3533SOURCES = \
     
    4038        print/print3.c \
    4139        print/print4.c \
     40        print/print5.c \
    4241        console/console1.c \
    4342        stdio/stdio1.c \
     
    5150        ipc/connect.c \
    5251        loop/loop1.c \
    53         mm/malloc1.c
     52        mm/malloc1.c \
     53        hw/serial/serial1.c
    5454
    55 include ../Makefile.common
     55include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/tester/console/console1.c

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

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

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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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);
     
    7272        }
    7373       
    74         TPRINTF("OK\nCompleted %llu round trips in %u seconds, %llu rt/s.\n",
     74        TPRINTF("OK\nCompleted %" PRIu64 " round trips in %u seconds, %" PRIu64 " rt/s.\n",
    7575            count, DURATION_SECS, count / DURATION_SECS);
    7676       
  • uspace/app/tester/ipc/register.c

    rfb150d78 r46c20c8  
    2727 */
    2828
     29#include <inttypes.h>
    2930#include <stdio.h>
    3031#include <unistd.h>
     
    4142        unsigned int i;
    4243       
    43         TPRINTF("Connected phone %#x accepting\n", icall->in_phone_hash);
     44        TPRINTF("Connected phone %" PRIun " accepting\n", icall->in_phone_hash);
    4445        ipc_answer_0(iid, EOK);
    4546        for (i = 0; i < MAX_CONNECTIONS; i++) {
     
    5758                switch (IPC_GET_METHOD(call)) {
    5859                case IPC_M_PHONE_HUNGUP:
    59                         TPRINTF("Phone %#x hung up\n", icall->in_phone_hash);
     60                        TPRINTF("Phone %" PRIun " hung up\n", icall->in_phone_hash);
    6061                        retval = 0;
    6162                        break;
    6263                case IPC_TEST_METHOD:
    63                         TPRINTF("Received well known message from %#x: %#x\n",
     64                        TPRINTF("Received well known message from %" PRIun ": %" PRIun "\n",
    6465                            icall->in_phone_hash, callid);
    6566                        ipc_answer_0(callid, EOK);
    6667                        break;
    6768                default:
    68                         TPRINTF("Received unknown message from %#x: %#x\n",
     69                        TPRINTF("Received unknown message from %" PRIun ": %" PRIun "\n",
    6970                            icall->in_phone_hash, callid);
    7071                        ipc_answer_0(callid, ENOENT);
     
    7475}
    7576
    76 char *test_register(void)
     77const char *test_register(void)
    7778{
    7879        async_set_client_connection(client_connection);
  • uspace/app/tester/loop/loop1.c

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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");
     
    4949        TPRINTF("Real output:     \"%8.10s\"\n\n", "very long text");
    5050       
    51         TPRINTF("Testing printf(\"%%s\", NULL):\n");
    52         TPRINTF("Expected output: \"(NULL)\"\n");
    53         TPRINTF("Real output:     \"%s\"\n\n", NULL);
    54        
    5551        return NULL;
    5652}
  • uspace/app/tester/print/print2.c

    rfb150d78 r46c20c8  
    3131#include "../tester.h"
    3232
    33 char *test_print2(void)
     33const char *test_print2(void)
    3434{
    35         TPRINTF("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n");
    36         TPRINTF("Expected output: [a] [  b] [c  ] [ d] [e ]\n");
    37         TPRINTF("Real output:     [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e');
     35        TPRINTF("Testing printf(\"%%c\", 'a'):\n");
     36        TPRINTF("Expected output: [a]\n");
     37        TPRINTF("Real output:     [%c]\n\n", 'a');
    3838       
    3939        TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n");
  • uspace/app/tester/print/print3.c

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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");
     
    4545                TPRINTF("  ");
    4646                for (index = 0; index < 32; index++)
    47                         TPRINTF("%lc", (wchar_t) ((group << 5) + index));
     47                        TPRINTF("%lc", (wint_t) ((group << 5) + index));
    4848               
    4949                TPRINTF("\n");
     
    5757                uint8_t index;
    5858                for (index = 0; index < 32; index++)
    59                         TPRINTF("%lc", (wchar_t) ((group << 5) + index));
     59                        TPRINTF("%lc", (wint_t) ((group << 5) + index));
    6060               
    6161                TPRINTF("\n");
  • uspace/app/tester/stdio/stdio1.c

    rfb150d78 r46c20c8  
    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);
     
    6060       
    6161        buf[cnt] = '\0';
    62         TPRINTF("Read %u bytes, string \"%s\"\n", cnt, buf);
     62        TPRINTF("Read %zu bytes, string \"%s\"\n", cnt, buf);
    6363       
    6464        TPRINTF("Seek to beginning...");
  • uspace/app/tester/stdio/stdio2.c

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    3838#include <unistd.h>
    3939#include <stdio.h>
    40 #include <string.h>
     40#include <str.h>
    4141#include "tester.h"
    4242
     
    5151#include "print/print3.def"
    5252#include "print/print4.def"
     53#include "print/print5.def"
    5354#include "console/console1.def"
    5455#include "stdio/stdio1.def"
     
    6364#include "loop/loop1.def"
    6465#include "mm/malloc1.def"
     66#include "hw/serial/serial1.def"
    6567        {NULL, NULL, NULL, false}
    6668};
     
    6971{
    7072        /* Execute the test */
    71         char *ret = test->entry();
     73        const char *ret = test->entry();
    7274       
    7375        if (ret == NULL) {
     
    110112        }
    111113       
     114        unsigned int _len = (unsigned int) len;
     115        if ((_len != len) || (((int) _len) < 0)) {
     116                printf("Command length overflow\n");
     117                return;
     118        }
     119       
    112120        for (test = tests; test->name != NULL; test++)
    113                 printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
     121                printf("%-*s %s%s\n", _len, test->name, test->desc,
     122                    (test->safe ? "" : " (unsafe)"));
    114123       
    115         printf("%-*s Run all safe tests\n", len, "*");
     124        printf("%-*s Run all safe tests\n", _len, "*");
    116125}
    117126
  • uspace/app/tester/tester.h

    rfb150d78 r46c20c8  
    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_print5(void);
     71extern const char *test_console1(void);
     72extern const char *test_stdio1(void);
     73extern const char *test_stdio2(void);
     74extern const char *test_fault1(void);
     75extern const char *test_fault2(void);
     76extern const char *test_fault3(void);
     77extern const char *test_vfs1(void);
     78extern const char *test_ping_pong(void);
     79extern const char *test_register(void);
     80extern const char *test_connect(void);
     81extern const char *test_loop1(void);
     82extern const char *test_malloc1(void);
     83extern const char *test_serial1(void);
    8284
    8385extern test_t tests[];
  • uspace/app/tester/thread/thread1.c

    rfb150d78 r46c20c8  
    3535#include <stdio.h>
    3636#include <unistd.h>
     37#include <inttypes.h>
    3738#include "../tester.h"
    3839
     
    5051}
    5152
    52 char *test_thread1(void)
     53const char *test_thread1(void)
    5354{
    5455        unsigned int i;
    55         int total = 0;
     56        atomic_count_t total = 0;
    5657       
    5758        atomic_set(&finish, 1);
     
    7475        atomic_set(&finish, 0);
    7576        while (atomic_get(&threads_finished) < total) {
    76                 TPRINTF("Threads left: %u\n", total - atomic_get(&threads_finished));
     77                TPRINTF("Threads left: %" PRIua "\n",
     78                    total - atomic_get(&threads_finished));
    7779                sleep(1);
    7880        }
  • uspace/app/tester/vfs/vfs1.c

    rfb150d78 r46c20c8  
    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)
     
    105105        if (cnt < 0)
    106106                return "write() failed";
    107         TPRINTF("Written %d bytes\n", cnt);
     107        TPRINTF("Written %zd bytes\n", cnt);
    108108       
    109109        if (lseek(fd0, 0, SEEK_SET) != 0)
     
    116116                        return "read() failed";
    117117               
    118                 TPRINTF("Read %d bytes: \".*s\"\n", cnt, cnt, buf);
     118                int _cnt = (int) cnt;
     119                if (_cnt != cnt) {
     120                        /* Count overflow, just to be sure. */
     121                        TPRINTF("Read %zd bytes\n", cnt);
     122                } else {
     123                        TPRINTF("Read %zd bytes: \"%.*s\"\n", cnt, _cnt, buf);
     124                }
    119125        }
    120126       
    121127        close(fd0);
    122128       
    123         char *rv = read_root();
     129        const char *rv = read_root();
    124130        if (rv != NULL)
    125131                return rv;
  • uspace/app/tetris/Makefile

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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        do { \
     43                if ((b) != 0) { \
     44                        (float).upper = (a); \
     45                        (float).lower = (b); \
     46                } else { \
     47                        (float).upper = 0; \
     48                        (float).lower = 1; \
     49                } \
     50        } while (0)
    4051
    41 /** Size of buffer for storing task name in task_t. */
    42 #define BOOTINFO_TASK_NAME_BUFLEN  32
     52typedef enum {
     53        OP_TASKS,
     54        OP_IPC,
     55        OP_EXCS,
     56        OP_HELP
     57} op_mode_t;
    4358
    44 #define BSP_PROCESSOR  1
    45 #define AP_PROCESSOR   0
     59typedef enum {
     60        SORT_TASK_CYCLES
     61} sort_mode_t;
    4662
    47 #define SUBARCH_US   1
    48 #define SUBARCH_US3  3
     63extern op_mode_t op_mode;
     64extern sort_mode_t sort_mode;
     65extern bool excs_all;
    4966
    5067typedef struct {
    51         void *addr;
    52         uint32_t size;
    53         char name[BOOTINFO_TASK_NAME_BUFLEN];
    54 } task_t;
     68        uint64_t upper;
     69        uint64_t lower;
     70} fixed_float;
    5571
    5672typedef struct {
    57         uint32_t count;
    58         task_t tasks[TASKMAP_MAX_RECORDS];
    59 } taskmap_t;
     73        fixed_float idle;
     74        fixed_float busy;
     75} perc_cpu_t;
    6076
    6177typedef 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;
     78        fixed_float virtmem;
     79        fixed_float ucycles;
     80        fixed_float kcycles;
     81} perc_task_t;
    6882
    69 extern uint32_t silo_ramdisk_image;
    70 extern uint32_t silo_ramdisk_size;
     83typedef struct {
     84        fixed_float cycles;
     85        fixed_float count;
     86} perc_exc_t;
    7187
    72 extern void start(void);
    73 extern void bootstrap(void);
     88typedef struct {
     89        time_t hours;
     90        time_t minutes;
     91        time_t seconds;
     92       
     93        sysarg_t udays;
     94        sysarg_t uhours;
     95        sysarg_t uminutes;
     96        sysarg_t useconds;
     97       
     98        size_t load_count;
     99        load_t *load;
     100       
     101        size_t cpus_count;
     102        stats_cpu_t *cpus;
     103        perc_cpu_t *cpus_perc;
     104       
     105        size_t tasks_count;
     106        stats_task_t *tasks;
     107        perc_task_t *tasks_perc;
     108        size_t *tasks_map;
     109       
     110        size_t threads_count;
     111        stats_thread_t *threads;
     112       
     113        size_t exceptions_count;
     114        stats_exc_t *exceptions;
     115        perc_exc_t *exceptions_perc;
     116       
     117        stats_physmem_t *physmem;
     118       
     119        uint64_t *ucycles_diff;
     120        uint64_t *kcycles_diff;
     121        uint64_t *ecycles_diff;
     122        uint64_t *ecount_diff;
     123} data_t;
    74124
    75125#endif
     126
     127/**
     128 * @}
     129 */
  • uspace/app/trace/Makefile

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

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

    rfb150d78 r46c20c8  
    137137
    138138        if (oper != NULL) {
    139                 printf("%s (%ld)", oper->name, method);
     139                printf("%s (%" PRIun ")", oper->name, method);
    140140                return;
    141141        }
    142142
    143         printf("%ld", method);
     143        printf("%" PRIun, method);
    144144}
    145145
     
    201201
    202202        if ((display_mask & DM_IPC) != 0) {
    203                 printf("Call ID: %p, phone: %d, proto: %s, method: ", hash,
    204                         phone, (proto ? proto->name : "n/a"));
     203                printf("Call ID: %p, phone: %d, proto: %s, method: ",
     204                    (void *) hash, phone,
     205                    (proto ? proto->name : "n/a"));
    205206                ipc_m_print(proto, IPC_GET_METHOD(*call));
    206                 printf(" args: (%" PRIuIPCARG ", %" PRIuIPCARG ", %" PRIuIPCARG
    207                     ", %" PRIuIPCARG ", %" PRIuIPCARG ")\n", args[1], args[2],
    208                     args[3], args[4], args[5]);
     207                printf(" args: (%" PRIun ", %" PRIun ", %" PRIun ", "
     208                    "%" PRIun ", %" PRIun ")\n",
     209                    args[1], args[2], args[3], args[4], args[5]);
    209210        }
    210211
     
    281282
    282283        if ((display_mask & DM_IPC) != 0) {
    283                 printf("Response to %p: retval=%ld, args = (%" PRIuIPCARG
    284                     ", %" PRIuIPCARG ", %" PRIuIPCARG ", %" PRIuIPCARG
    285                     ", %" PRIuIPCARG ")\n",
    286                     hash, retval, IPC_GET_ARG1(*answer),
     284                printf("Response to %p: retval=%" PRIdn ", args = (%" PRIun ", "
     285                    "%" PRIun ", %" PRIun ", %" PRIun ", %" PRIun ")\n",
     286                    (void *) hash, retval, IPC_GET_ARG1(*answer),
    287287                    IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer),
    288288                    IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer));
     
    340340                /* Not a response */
    341341                if ((display_mask & DM_IPC) != 0) {
    342                         printf("Not a response (hash %p)\n", hash);
     342                        printf("Not a response (hash %p)\n", (void *) hash);
    343343                }
    344344                return;
  • uspace/app/trace/proto.c

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    7373    [SYS_PHYSMEM_MAP] = { "physmem_map",                4,      V_ERRNO },
    7474    [SYS_IOSPACE_ENABLE] = { "iospace_enable",          1,      V_ERRNO },
    75     [SYS_PREEMPT_CONTROL] = { "preempt_control",        1,      V_ERRNO },
     75    [SYS_INTERRUPT_ENABLE] = { "interrupt_enable",      2,      V_ERRNO },
    7676
    77     [SYS_SYSINFO_VALID] = { "sysinfo_valid",            2,      V_HASH },
    78     [SYS_SYSINFO_VALUE] = { "sysinfo_value",            2,      V_HASH },
     77    [SYS_SYSINFO_GET_TAG] = { "sysinfo_get_tag",                2,      V_INTEGER },
     78    [SYS_SYSINFO_GET_VALUE] = { "sysinfo_get_value",            3,      V_ERRNO },
     79    [SYS_SYSINFO_GET_DATA_SIZE] = { "sysinfo_get_data_size",    3,      V_ERRNO },
     80    [SYS_SYSINFO_GET_DATA] = { "sysinfo_get_data",              4,      V_ERRNO },
     81
    7982    [SYS_DEBUG_ENABLE_CONSOLE] = { "debug_enable_console", 0,   V_ERRNO },
    8083    [SYS_IPC_CONNECT_KBOX] = { "ipc_connect_kbox",      1,      V_ERRNO }
  • uspace/app/trace/syscalls.h

    rfb150d78 r46c20c8  
    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

    rfb150d78 r46c20c8  
    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>
     
    161161        if (rc < 0) {
    162162                printf("Error connecting\n");
    163                 printf("ipc_connect_task(%" PRIdTASKID ") -> %d ", task_id, rc);
     163                printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, rc);
    164164                return rc;
    165165        }
     
    200200        printf("Threads:");
    201201        for (i = 0; i < n_threads; i++) {
    202                 printf(" [%d] (hash %p)", 1+i, thread_hash_buf[i]);
    203         }
    204         printf("\ntotal of %u threads\n", tb_needed / sizeof(uintptr_t));
     202                printf(" [%d] (hash %p)", 1 + i, (void *) thread_hash_buf[i]);
     203        }
     204        printf("\ntotal of %zu threads\n", tb_needed / sizeof(uintptr_t));
    205205
    206206        return 0;
     
    224224        case V_HASH:
    225225        case V_PTR:
    226                 printf("%p", val);
     226                printf("%p", (void *) val);
    227227                break;
    228228
     
    248248        case V_CHAR:
    249249                if (sval >= 0x20 && sval < 0x7f) {
    250                         printf("'%c'", sval);
     250                        printf("'%c'", (char) sval);
    251251                } else {
    252252                        switch (sval) {
     
    257257                        case '\t': printf("'\\t'"); break;
    258258                        case '\\': printf("'\\\\'"); break;
    259                         default: printf("'\\x%02lX'", val); break;
     259                        default: printf("'\\x%02" PRIxn "'", val); break;
    260260                        }
    261261                }
     
    277277
    278278        putchar('(');
    279         if (n > 0) printf("%" PRIdSYSARG, sc_args[0]);
     279        if (n > 0) printf("%" PRIun, sc_args[0]);
    280280        for (i = 1; i < n; i++) {
    281                 printf(", %" PRIdSYSARG, sc_args[i]);
     281                printf(", %" PRIun, sc_args[i]);
    282282        }
    283283        putchar(')');
     
    489489{
    490490        async_serialize_start();
    491         printf("New thread, hash 0x%lx\n", hash);
     491        printf("New thread, hash %p\n", (void *) hash);
    492492        async_serialize_end();
    493493
     
    510510        }
    511511
    512         printf("Start tracing thread [%d] (hash %p).\n", thread_id, thread_hash);
     512        printf("Start tracing thread [%u] (hash %p).\n",
     513            thread_id, (void *) thread_hash);
    513514
    514515        while (!abort_trace) {
     
    516517                fibril_mutex_lock(&state_lock);
    517518                if (paused) {
    518                         printf("Thread [%d] paused. Press R to resume.\n",
     519                        printf("Thread [%u] paused. Press R to resume.\n",
    519520                            thread_id);
    520521
     
    522523                                fibril_condvar_wait(&state_cv, &state_lock);
    523524
    524                         printf("Thread [%d] resumed.\n", thread_id);
     525                        printf("Thread [%u] resumed.\n", thread_id);
    525526                }
    526527                fibril_mutex_unlock(&state_lock);
     
    554555                                break;
    555556                        case UDEBUG_EVENT_THREAD_E:
    556                                 printf("Thread %p exited.\n", val0);
     557                                printf("Thread %" PRIun " exited.\n", val0);
    557558                                fibril_mutex_lock(&state_lock);
    558559                                abort_trace = true;
     
    585586}
    586587
    587 static loader_t *preload_task(const char *path, char *const argv[],
     588static loader_t *preload_task(const char *path, char **argv,
    588589    task_id_t *task_id)
    589590{
     
    591592        int rc;
    592593
    593         /* Spawn a program loader */   
     594        /* Spawn a program loader */
    594595        ldr = loader_connect();
    595596        if (ldr == NULL)
     
    607608
    608609        /* Send arguments */
    609         rc = loader_set_args(ldr, argv);
     610        rc = loader_set_args(ldr, (const char **) argv);
    610611        if (rc != EOK)
    611612                goto error;
     
    870871}
    871872
    872 static display_mask_t parse_display_mask(char *text)
     873static display_mask_t parse_display_mask(const char *text)
    873874{
    874875        display_mask_t dm;
    875         char *c;
    876 
    877         c = text;
    878 
     876        const char *c = text;
     877       
    879878        while (*c) {
    880879                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;
     880                case 't':
     881                        dm = dm | DM_THREAD;
     882                        break;
     883                case 's':
     884                        dm = dm | DM_SYSCALL;
     885                        break;
     886                case 'i':
     887                        dm = dm | DM_IPC;
     888                        break;
     889                case 'p':
     890                        dm = dm | DM_SYSTEM | DM_USER;
     891                        break;
    885892                default:
    886893                        printf("Unexpected event type '%c'.\n", *c);
    887894                        exit(1);
    888895                }
    889 
     896               
    890897                ++c;
    891898        }
    892 
     899       
    893900        return dm;
    894901}
     
    896903static int parse_args(int argc, char *argv[])
    897904{
    898         char *arg;
    899905        char *err_p;
    900906
    901907        task_id = 0;
    902908
    903         --argc; ++argv;
     909        --argc;
     910        ++argv;
    904911
    905912        while (argc > 0) {
    906                 arg = *argv;
     913                char *arg = *argv;
    907914                if (arg[0] == '+') {
    908915                        display_mask = parse_display_mask(&arg[1]);
     
    910917                        if (arg[1] == 't') {
    911918                                /* Trace an already running task */
    912                                 --argc; ++argv;
     919                                --argc;
     920                                ++argv;
    913921                                task_id = strtol(*argv, &err_p, 10);
    914922                                task_ldr = NULL;
     
    920928                                }
    921929                        } else {
    922                                 printf("Uknown option '%s'\n", arg[0]);
     930                                printf("Uknown option '%c'\n", arg[0]);
    923931                                print_syntax();
    924932                                return -1;
     
    927935                        break;
    928936                }
    929 
    930                 --argc; ++argv;
     937               
     938                --argc;
     939                ++argv;
    931940        }
    932941
    933942        if (task_id != 0) {
    934                 if (argc == 0) return 0;
     943                if (argc == 0)
     944                        return 0;
    935945                printf("Extra arguments\n");
    936946                print_syntax();
     
    946956        /* Preload the specified program file. */
    947957        printf("Spawning '%s' with arguments:\n", *argv);
    948         {
    949                 char **cp = argv;
    950                 while (*cp) printf("'%s'\n", *cp++);
    951         }
     958       
     959        char **cp = argv;
     960        while (*cp)
     961                printf("'%s'\n", *cp++);
     962       
    952963        task_ldr = preload_task(*argv, argv, &task_id);
    953964        task_wait_for = true;
     
    974985        rc = connect_task(task_id);
    975986        if (rc < 0) {
    976                 printf("Failed connecting to task %" PRIdTASKID ".\n", task_id);
     987                printf("Failed connecting to task %" PRIu64 ".\n", task_id);
    977988                return 1;
    978989        }
    979990
    980         printf("Connected to task %" PRIdTASKID ".\n", task_id);
     991        printf("Connected to task %" PRIu64 ".\n", task_id);
    981992
    982993        if (task_ldr != NULL)
Note: See TracChangeset for help on using the changeset viewer.