Changeset 46c20c8 in mainline for uspace/app
- Timestamp:
- 2010-11-26T20:08:10Z (15 years ago)
- 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. - Location:
- uspace/app
- Files:
-
- 112 added
- 1 deleted
- 90 edited
- 7 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/Makefile
rfb150d78 r46c20c8 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBC _PREFIX)/libc.a32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I . -Icmds/ -Icmds/builtins -Icmds/modules33 34 OUTPUT= bdsh31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a 32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) -I. -Icmds/ \ 33 -Icmds/builtins -Icmds/modules 34 BINARY = bdsh 35 35 36 36 SOURCES = \ … … 60 60 scli.c 61 61 62 include ../Makefile.common62 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/bdsh/cmds/builtin_cmds.c
rfb150d78 r46c20c8 34 34 #include <stdio.h> 35 35 #include <stdlib.h> 36 #include <str ing.h>36 #include <str.h> 37 37 #include "errors.h" 38 38 #include "cmds.h" -
uspace/app/bdsh/cmds/builtins/builtins.h
rfb150d78 r46c20c8 10 10 #include "cd/cd_def.h" 11 11 #include "exit/exit_def.h" 12 {NULL, NULL, NULL, NULL }12 {NULL, NULL, NULL, NULL, 0} 13 13 }; 14 14 -
uspace/app/bdsh/cmds/builtins/cd/cd.c
rfb150d78 r46c20c8 32 32 #include <stdlib.h> 33 33 #include <unistd.h> 34 #include <str ing.h>34 #include <str.h> 35 35 #include <errno.h> 36 36 … … 41 41 #include "cd.h" 42 42 43 static c har *cmdname = "cd";43 static const char *cmdname = "cd"; 44 44 45 45 void help_cmd_cd(unsigned int level) -
uspace/app/bdsh/cmds/builtins/cd/cd_def.h
rfb150d78 r46c20c8 4 4 &cmd_cd, 5 5 &help_cmd_cd, 6 0 6 7 }, -
uspace/app/bdsh/cmds/builtins/exit/exit_def.h
rfb150d78 r46c20c8 4 4 &cmd_exit, 5 5 &help_cmd_exit, 6 0 6 7 }, -
uspace/app/bdsh/cmds/cmds.h
rfb150d78 r46c20c8 33 33 /* Module structure */ 34 34 typedef struct { 35 c har *name;/* Name of the command */36 c har *desc;/* Description of the command */35 const char *name; /* Name of the command */ 36 const char *desc; /* Description of the command */ 37 37 mod_entry_t entry; /* Command (exec) entry function */ 38 38 mod_help_t help; /* Command (help) entry function */ … … 41 41 /* Builtin structure, same as modules except different types of entry points */ 42 42 typedef struct { 43 c har *name;44 c har *desc;43 const char *name; 44 const char *desc; 45 45 builtin_entry_t entry; 46 46 builtin_help_t help; … … 57 57 extern int is_module(const char *); 58 58 extern int is_module_alias(const char *); 59 extern char * 59 extern char *alias_for_module(const char *); 60 60 extern int help_module(int, unsigned int); 61 61 extern int run_module(int, char *[]); … … 65 65 extern int is_builtin(const char *); 66 66 extern int is_builtin_alias(const char *); 67 extern char * 67 extern char *alias_for_builtin(const char *); 68 68 extern int help_builtin(int, unsigned int); 69 69 extern int run_builtin(int, char *[], cliuser_t *); -
uspace/app/bdsh/cmds/mod_cmds.c
rfb150d78 r46c20c8 47 47 #include <stdio.h> 48 48 #include <stdlib.h> 49 #include <str ing.h>49 #include <str.h> 50 50 #include "errors.h" 51 51 #include "cmds.h" -
uspace/app/bdsh/cmds/modules/bdd/bdd.c
rfb150d78 r46c20c8 29 29 #include <stdio.h> 30 30 #include <stdlib.h> 31 #include <string.h> 31 #include <str.h> 32 #include <sys/typefmt.h> 32 33 #include "config.h" 33 34 #include "util.h" … … 68 69 unsigned int argc; 69 70 unsigned int i, j; 70 dev _handle_t handle;71 devmap_handle_t handle; 71 72 uint8_t *blk; 72 73 size_t size, bytes, rows; 73 74 size_t block_size; 74 75 int rc; 75 bn_t ba;76 aoff64_t ba; 76 77 uint8_t b; 77 78 … … 122 123 rc = block_read_direct(handle, ba, 1, blk); 123 124 if (rc != EOK) { 124 printf("%s: Error reading block % llu\n", cmdname, ba);125 printf("%s: Error reading block %" PRIuOFF64 "\n", cmdname, ba); 125 126 free(blk); 126 127 block_fini(handle); -
uspace/app/bdsh/cmds/modules/cat/cat.c
rfb150d78 r46c20c8 33 33 #include <unistd.h> 34 34 #include <getopt.h> 35 #include <str ing.h>35 #include <str.h> 36 36 #include <fcntl.h> 37 37 … … 43 43 #include "cmds.h" 44 44 45 static c har *cmdname = "cat";45 static const char *cmdname = "cat"; 46 46 #define CAT_VERSION "0.0.1" 47 47 #define CAT_DEFAULT_BUFLEN 1024 48 48 49 static c har *cat_oops = "That option is not yet supported\n";49 static const char *cat_oops = "That option is not yet supported\n"; 50 50 51 51 static struct option const long_options[] = { … … 85 85 { 86 86 int fd, bytes = 0, count = 0, reads = 0; 87 off _t total = 0;87 off64_t total = 0; 88 88 char *buff = NULL; 89 89 -
uspace/app/bdsh/cmds/modules/cp/cp.c
rfb150d78 r46c20c8 33 33 #include <unistd.h> 34 34 #include <getopt.h> 35 #include <str ing.h>35 #include <str.h> 36 36 #include <fcntl.h> 37 37 #include "config.h" … … 74 74 { 75 75 int fd1, fd2, bytes = 0; 76 off _t total = 0;76 off64_t total = 0; 77 77 int64_t copied = 0; 78 78 char *buff = NULL; … … 95 95 96 96 if (vb) 97 printf("% dbytes to copy\n", total);97 printf("%" PRIu64 " bytes to copy\n", total); 98 98 99 99 lseek(fd1, 0, SEEK_SET); … … 130 130 */ 131 131 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); 133 133 goto err; 134 134 } … … 187 187 return CMD_SUCCESS; 188 188 case 'v': 189 printf("% d\n", CP_VERSION);189 printf("%s\n", CP_VERSION); 190 190 return CMD_SUCCESS; 191 191 case 'V': … … 223 223 224 224 if (verbose) 225 printf("% dbytes copied\n", ret);225 printf("%" PRId64 " bytes copied\n", ret); 226 226 227 227 if (ret >= 0) -
uspace/app/bdsh/cmds/modules/help/help.c
rfb150d78 r46c20c8 31 31 #include <stdio.h> 32 32 #include <stdlib.h> 33 #include <str ing.h>33 #include <str.h> 34 34 35 35 #include "config.h" … … 42 42 #include "util.h" 43 43 44 static c har *cmdname = "help";44 static const char *cmdname = "help"; 45 45 extern const char *progname; 46 46 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 50 51 51 52 volatile int mod_switch = -1; … … 55 56 { 56 57 int rc = HELP_IS_RUBBISH; 58 59 if (str_cmp(cmd, "commands") == 0) 60 return HELP_IS_COMMANDS; 57 61 58 62 rc = is_builtin(cmd); … … 90 94 } 91 95 92 int cmd_help(char *argv[])96 static void help_commands(void) 93 97 { 98 builtin_t *cmd; 94 99 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; 100 101 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"); 132 103 printf(" ------------------------------------------------------------\n"); 133 104 … … 154 125 printf("\n Try %s %s for more information on how `%s' works.\n\n", 155 126 cmdname, cmdname, cmdname); 127 } 128 129 /** Display survival tips. ('help' without arguments) */ 130 static 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 156 int 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(); 156 196 157 197 return CMD_SUCCESS; -
uspace/app/bdsh/cmds/modules/kcon/kcon.c
rfb150d78 r46c20c8 40 40 #include "cmds.h" 41 41 42 static c har *cmdname = "kcon";42 static const char *cmdname = "kcon"; 43 43 44 44 /* Dispays help for kcon in various levels */ -
uspace/app/bdsh/cmds/modules/ls/ls.c
rfb150d78 r46c20c8 40 40 #include <sys/types.h> 41 41 #include <sys/stat.h> 42 #include <str ing.h>42 #include <str.h> 43 43 44 44 #include "errors.h" … … 49 49 #include "cmds.h" 50 50 51 static c har *cmdname = "ls";51 static const char *cmdname = "ls"; 52 52 53 53 static void ls_scan_dir(const char *d, DIR *dirp) -
uspace/app/bdsh/cmds/modules/mkdir/mkdir.c
rfb150d78 r46c20c8 38 38 #include <getopt.h> 39 39 #include <stdarg.h> 40 #include <str ing.h>40 #include <str.h> 41 41 42 42 #include "config.h" … … 49 49 #define MKDIR_VERSION "0.0.1" 50 50 51 static c har *cmdname = "mkdir";51 static const char *cmdname = "mkdir"; 52 52 53 53 static struct option const long_options[] = { -
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
rfb150d78 r46c20c8 38 38 #include <getopt.h> 39 39 #include <stdarg.h> 40 #include <str ing.h>40 #include <str.h> 41 41 #include <ctype.h> 42 42 … … 51 51 #define BUFFER_SIZE 16384 52 52 53 static c har *cmdname = "mkfile";53 static const char *cmdname = "mkfile"; 54 54 55 55 static struct option const long_options[] = { … … 168 168 rc = write(fd, buffer, to_write); 169 169 if (rc <= 0) { 170 printf("%s: Error writing file (% d).\n", cmdname, rc);170 printf("%s: Error writing file (%zd).\n", cmdname, rc); 171 171 close(fd); 172 172 return CMD_FAILURE; … … 177 177 rc = close(fd); 178 178 if (rc != 0) { 179 printf("%s: Error writing file (% d).\n", cmdname, rc);179 printf("%s: Error writing file (%zd).\n", cmdname, rc); 180 180 return CMD_FAILURE; 181 181 } -
uspace/app/bdsh/cmds/modules/module_aliases.h
rfb150d78 r46c20c8 12 12 * the entry point being reached. */ 13 13 14 c har *mod_aliases[] = {14 const char *mod_aliases[] = { 15 15 "ren", "mv", 16 16 "umount", "unmount", -
uspace/app/bdsh/cmds/modules/mount/mount.c
rfb150d78 r46c20c8 58 58 { 59 59 unsigned int argc; 60 c har *mopts = "";60 const char *mopts = ""; 61 61 int rc; 62 62 -
uspace/app/bdsh/cmds/modules/pwd/pwd.c
rfb150d78 r46c20c8 39 39 #include "pwd.h" 40 40 41 static c har *cmdname = "pwd";41 static const char *cmdname = "pwd"; 42 42 43 43 void help_cmd_pwd(unsigned int level) -
uspace/app/bdsh/cmds/modules/rm/rm.c
rfb150d78 r46c20c8 36 36 #include <getopt.h> 37 37 #include <mem.h> 38 #include <str ing.h>38 #include <str.h> 39 39 40 40 #include "config.h" … … 45 45 #include "cmds.h" 46 46 47 static c har *cmdname = "rm";47 static const char *cmdname = "rm"; 48 48 #define RM_VERSION "0.0.1" 49 49 -
uspace/app/bdsh/cmds/modules/sleep/sleep.c
rfb150d78 r46c20c8 38 38 #include "cmds.h" 39 39 40 static c har *cmdname = "sleep";40 static const char *cmdname = "sleep"; 41 41 42 42 /* Dispays help for sleep in various levels */ -
uspace/app/bdsh/cmds/modules/touch/touch.c
rfb150d78 r46c20c8 38 38 #include <dirent.h> 39 39 #include <sys/types.h> 40 #include <str ing.h>40 #include <str.h> 41 41 42 42 #include "config.h" … … 47 47 #include "cmds.h" 48 48 49 static c har *cmdname = "touch";49 static const char *cmdname = "touch"; 50 50 51 51 /* Dispays help for touch in various levels */ -
uspace/app/bdsh/cmds/modules/unmount/unmount.c
rfb150d78 r46c20c8 47 47 } else { 48 48 help_cmd_unmount(HELP_SHORT); 49 printf("Usage: 49 printf("Usage: %s <mp>\n", cmdname); 50 50 } 51 51 return; … … 68 68 rc = unmount(argv[1]); 69 69 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); 71 71 return CMD_FAILURE; 72 72 } -
uspace/app/bdsh/errors.c
rfb150d78 r46c20c8 30 30 31 31 #include <stdio.h> 32 #include <str ing.h>32 #include <str.h> 33 33 #include <stdlib.h> 34 34 #include <unistd.h> … … 47 47 /* Look up errno in cl_errors and return the corresponding string. 48 48 * Return NULL if not found */ 49 static c har *err2str(int err)49 static const char *err2str(int err) 50 50 { 51 51 -
uspace/app/bdsh/errstr.h
rfb150d78 r46c20c8 4 4 /* Simple array to translate error codes to meaningful strings */ 5 5 6 static c har *cl_errors[] = {6 static const char *cl_errors[] = { 7 7 "Success", 8 8 "Failure", … … 18 18 }; 19 19 20 static c har *err2str(int);20 static const char *err2str(int); 21 21 22 22 #endif -
uspace/app/bdsh/exec.c
rfb150d78 r46c20c8 38 38 #include <stdlib.h> 39 39 #include <unistd.h> 40 #include <str ing.h>40 #include <str.h> 41 41 #include <fcntl.h> 42 #include <str_error.h> 43 #include <errno.h> 42 44 43 45 #include "config.h" … … 115 117 task_exit_t texit; 116 118 char *tmp; 117 int r etval;119 int rc, retval; 118 120 119 121 tmp = str_dup(find_command(cmd)); 120 122 free(found); 121 123 122 tid = task_spawn((const char *)tmp,argv);124 rc = task_spawnv(&tid, tmp, (const char **) argv); 123 125 free(tmp); 124 126 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)); 127 130 return 1; 128 131 } 129 132 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); 133 139 } 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); 135 142 } 136 143 -
uspace/app/bdsh/exec.h
rfb150d78 r46c20c8 5 5 6 6 extern unsigned int try_exec(char *, char **); 7 7 8 #endif -
uspace/app/bdsh/input.c
rfb150d78 r46c20c8 1 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 2 2 * All rights reserved. 3 * Copyright (c) 2008, Jiri Svoboda - All Rights Reserved4 3 * 5 4 * Redistribution and use in source and binary forms, with or without … … 32 31 #include <stdio.h> 33 32 #include <stdlib.h> 34 #include <str ing.h>33 #include <str.h> 35 34 #include <io/console.h> 36 35 #include <io/keycode.h> … … 43 42 #include <assert.h> 44 43 #include <bool.h> 44 #include <tinput.h> 45 45 46 46 #include "config.h" … … 51 51 #include "exec.h" 52 52 53 #define HISTORY_LEN 10 53 extern volatile unsigned int cli_quit; 54 54 55 55 /** 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); 56 static tinput_t *tinput; 100 57 101 58 /* Tokenizes input from console, sees if the first word is a built-in, if so … … 149 106 } 150 107 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) 108 void get_input(cliuser_t *usr) 539 109 { 540 110 char *str; 541 111 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;770 112 771 113 fflush(stdout); … … 775 117 console_set_style(fphone(stdout), STYLE_NORMAL); 776 118 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 } 778 131 779 132 /* Check for empty input. */ … … 787 140 } 788 141 789 voidinput_init(void)142 int input_init(void) 790 143 { 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; 792 151 } -
uspace/app/bdsh/input.h
rfb150d78 r46c20c8 8 8 extern void get_input(cliuser_t *); 9 9 extern int tok_input(cliuser_t *); 10 extern voidinput_init(void);10 extern int input_init(void); 11 11 12 12 #endif -
uspace/app/bdsh/scli.c
rfb150d78 r46c20c8 31 31 #include <stdio.h> 32 32 #include <stdlib.h> 33 #include <str ing.h>33 #include <str.h> 34 34 #include <unistd.h> 35 35 #include "config.h" … … 65 65 usr->lasterr = 0; 66 66 67 input_init(); 67 if (input_init() != 0) 68 return 1; 68 69 69 70 return (int) cli_set_prompt(usr); … … 88 89 exit(EXIT_FAILURE); 89 90 90 printf("Welcome to %s - %s\nType `help' at any time for usage information.\n",91 progname, PACKAGE_STRING);92 93 91 while (!cli_quit) { 94 92 get_input(&usr); … … 99 97 } 100 98 } 101 goto finit;102 99 103 finit: 100 printf("Leaving %s.\n", progname); 101 104 102 cli_finit(&usr); 105 103 return ret; -
uspace/app/bdsh/scli.h
rfb150d78 r46c20c8 6 6 7 7 typedef struct { 8 c har *name;8 const char *name; 9 9 char *line; 10 10 char *cwd; … … 13 13 } cliuser_t; 14 14 15 extern const char *progname; 16 15 17 #endif -
uspace/app/bdsh/util.c
rfb150d78 r46c20c8 29 29 30 30 #include <stdio.h> 31 #include <str ing.h>31 #include <str.h> 32 32 #include <stdarg.h> 33 33 #include <stdlib.h> -
uspace/app/edit/Makefile
rfb150d78 r46c20c8 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBC_PREFIX)/libc.a 32 33 OUTPUT = edit 31 BINARY = edit 34 32 35 33 SOURCES = \ … … 37 35 sheet.c 38 36 39 include ../Makefile.common37 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/edit/edit.c
rfb150d78 r46c20c8 40 40 #include <vfs/vfs.h> 41 41 #include <io/console.h> 42 #include <io/ color.h>42 #include <io/style.h> 43 43 #include <io/keycode.h> 44 44 #include <errno.h> … … 100 100 static bool cursor_visible; 101 101 102 static int scr_rows, scr_columns; 102 static ipcarg_t scr_rows; 103 static ipcarg_t scr_columns; 103 104 104 105 #define ROW_BUF_SIZE 4096 … … 475 476 static void file_save_as(void) 476 477 { 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 481 481 fname = filename_prompt("Save As", old_fname); 482 482 if (fname == NULL) { … … 485 485 } 486 486 487 rc = file_save(fname);487 int rc = file_save(fname); 488 488 if (rc != EOK) 489 489 return; … … 506 506 asprintf(&str, "%s: %s", prompt, init_value); 507 507 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); 509 509 free(str); 510 510 511 console_set_ color(con, COLOR_WHITE, COLOR_BLACK, 0);511 console_set_style(con, STYLE_INVERTED); 512 512 513 513 max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt)); … … 553 553 str = wstr_to_astr(buffer); 554 554 555 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);555 console_set_style(con, STYLE_NORMAL); 556 556 557 557 return str; … … 672 672 { 673 673 int sh_rows, rows; 674 int i, j;675 674 676 675 sheet_get_num_rows(&doc.sh, &sh_rows); … … 679 678 /* Draw rows from the sheet. */ 680 679 681 console_ goto(con, 0, 0);680 console_set_pos(con, 0, 0); 682 681 pane_row_range_display(0, rows); 683 682 684 683 /* Clear the remaining rows if file is short. */ 685 684 685 int i; 686 ipcarg_t j; 686 687 for (i = rows; i < pane.rows; ++i) { 687 console_ goto(con, 0, i);688 console_set_pos(con, 0, i); 688 689 for (j = 0; j < scr_columns; ++j) 689 690 putchar(' '); … … 718 719 wchar_t c; 719 720 size_t pos, size; 720 unsigneds_column;721 int s_column; 721 722 coord_t csel_start, csel_end, ctmp; 722 723 … … 737 738 /* Draw rows from the sheet. */ 738 739 739 console_ goto(con, 0, 0);740 console_set_pos(con, 0, 0); 740 741 for (i = r0; i < r1; ++i) { 741 742 /* Starting point for row display */ … … 757 758 coord_cmp(&rbc, &csel_end) < 0) { 758 759 fflush(stdout); 759 console_set_ color(con, COLOR_BLACK, COLOR_RED, 0);760 console_set_style(con, STYLE_SELECTED); 760 761 fflush(stdout); 761 762 } 762 763 763 console_ goto(con, 0, i);764 console_set_pos(con, 0, i); 764 765 size = str_size(row_buf); 765 766 pos = 0; 766 767 s_column = pane.sh_column; 767 768 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)) { 769 770 fflush(stdout); 770 console_set_ color(con, COLOR_BLACK, COLOR_RED, 0);771 console_set_style(con, STYLE_SELECTED); 771 772 fflush(stdout); 772 773 } 773 774 774 if ( csel_end.row == rbc.row && csel_end.column == s_column) {775 if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) { 775 776 fflush(stdout); 776 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);777 console_set_style(con, STYLE_NORMAL); 777 778 fflush(stdout); 778 779 } … … 780 781 c = str_decode(row_buf, &pos, size); 781 782 if (c != '\t') { 782 printf("%lc", c);783 printf("%lc", (wint_t) c); 783 784 s_column += 1; 784 785 } else { … … 792 793 } 793 794 794 if ( csel_end.row == rbc.row && csel_end.column == s_column) {795 if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) { 795 796 fflush(stdout); 796 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);797 console_set_style(con, STYLE_NORMAL); 797 798 fflush(stdout); 798 799 } … … 808 809 putchar(' '); 809 810 fflush(stdout); 810 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);811 console_set_style(con, STYLE_NORMAL); 811 812 } 812 813 … … 819 820 spt_t caret_pt; 820 821 coord_t coord; 821 char *fname;822 int n;823 822 824 823 tag_get_pt(&pane.caret_pos, &caret_pt); 825 824 spt_get_coord(&caret_pt, &coord); 826 825 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 " 832 831 "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, ""); 834 835 fflush(stdout); 835 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);836 console_set_style(con, STYLE_NORMAL); 836 837 837 838 pane.rflags |= REDRAW_CARET; … … 847 848 848 849 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, 850 851 coord.row - pane.sh_row); 851 852 } … … 1152 1153 static void status_display(char const *str) 1153 1154 { 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); 1157 1160 fflush(stdout); 1158 console_set_ color(con, COLOR_BLACK, COLOR_WHITE, 0);1161 console_set_style(con, STYLE_NORMAL); 1159 1162 1160 1163 pane.rflags |= REDRAW_CARET; -
uspace/app/edit/sheet.c
rfb150d78 r46c20c8 50 50 51 51 #include <stdlib.h> 52 #include <str ing.h>52 #include <str.h> 53 53 #include <errno.h> 54 54 #include <adt/list.h> -
uspace/app/getterm/Makefile
rfb150d78 r46c20c8 28 28 # 29 29 30 include ../../../version31 DEFS += -DRELEASE=$(RELEASE) "-DNAME=$(NAME)"32 33 30 USPACE_PREFIX = ../.. 34 LIBS = $(LIBC_PREFIX)/libc.a 35 36 OUTPUT = getterm 31 DEFS = -DRELEASE=$(RELEASE) "-DNAME=$(NAME)" 32 BINARY = getterm 37 33 38 34 SOURCES = \ 39 35 getterm.c \ 40 version.c 36 version.c \ 37 welcome.c 41 38 42 include ../Makefile.common39 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/getterm/getterm.c
rfb150d78 r46c20c8 40 40 #include <stdio.h> 41 41 #include <task.h> 42 #include <str_error.h> 43 #include <errno.h> 42 44 #include "version.h" 45 #include "welcome.h" 46 47 #define APP_NAME "getterm" 43 48 44 49 static void usage(void) 45 50 { 46 printf("Usage: getterm <terminal> <path>\n");51 printf("Usage: %s <terminal> [-w] <command> [<arguments...>]\n", APP_NAME); 47 52 } 48 53 … … 69 74 } 70 75 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 86 76 int main(int argc, char *argv[]) 87 77 { 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) { 89 89 usage(); 90 90 return -1; 91 91 } 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; 92 109 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"); 96 113 97 114 /* … … 110 127 return -4; 111 128 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; 121 138 } 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; 124 148 } 125 149 -
uspace/app/getterm/version.c
rfb150d78 r46c20c8 40 40 #include "version.h" 41 41 42 static c har *release = STRING(RELEASE);43 static c har *name = STRING(NAME);44 static c har *arch = STRING(UARCH);42 static const char *release = STRING(RELEASE); 43 static const char *name = STRING(NAME); 44 static const char *arch = STRING(UARCH); 45 45 46 46 #ifdef REVISION 47 static c har *revision = ", revision " STRING(REVISION);47 static const char *revision = ", revision " STRING(REVISION); 48 48 #else 49 static c har *revision = "";49 static const char *revision = ""; 50 50 #endif 51 51 52 52 #ifdef TIMESTAMP 53 static c har *timestamp = "\nBuilt on " STRING(TIMESTAMP);53 static const char *timestamp = "\nBuilt on " STRING(TIMESTAMP); 54 54 #else 55 static c har *timestamp = "";55 static const char *timestamp = ""; 56 56 #endif 57 57 … … 61 61 printf("HelenOS release %s (%s)%s%s\n", release, name, revision, timestamp); 62 62 printf("Running on %s (%s)\n", arch, term); 63 printf("Copyright (c) 2001-20 09HelenOS project\n\n");63 printf("Copyright (c) 2001-2010 HelenOS project\n\n"); 64 64 } 65 65 -
uspace/app/init/Makefile
rfb150d78 r46c20c8 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBC_PREFIX)/libc.a 32 33 OUTPUT = init 31 BINARY = init 34 32 35 33 SOURCES = \ 36 34 init.c 37 35 38 include ../Makefile.common36 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/init/init.c
rfb150d78 r46c20c8 46 46 #include <malloc.h> 47 47 #include <macros.h> 48 #include <str ing.h>48 #include <str.h> 49 49 #include <devmap.h> 50 #include <str_error.h> 50 51 #include "init.h" 51 52 53 #define ROOT_DEVICE "bd/initrd" 54 #define ROOT_MOUNT_POINT "/" 55 56 #define DEVFS_FS_TYPE "devfs" 52 57 #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" 53 65 54 66 #define SRV_CONSOLE "/srv/console" … … 57 69 static void info_print(void) 58 70 { 59 printf(NAME ": HelenOS init\n"); 71 printf("%s: HelenOS init\n", NAME); 72 } 73 74 static 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; 60 101 } 61 102 62 103 static bool mount_root(const char *fstype) 63 104 { 64 char *opts = ""; 65 const char *root_dev = "bd/initrd"; 105 const char *opts = ""; 66 106 67 107 if (str_cmp(fstype, "tmpfs") == 0) 68 108 opts = "restore"; 69 109 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); 92 114 } 93 115 94 116 static bool mount_devfs(void) 95 117 { 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 124 static void spawn(const char *fname) 125 { 126 int rc; 122 127 struct stat s; 123 128 … … 125 130 return; 126 131 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 140 static void srv_start(const char *fname) 141 { 139 142 task_id_t id; 140 143 task_exit_t texit; … … 145 148 return; 146 149 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); 153 152 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 158 158 rc = task_wait(id, &texit, &retval); 159 159 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, 166 173 fname, retval); 167 174 } 168 175 } 169 176 170 static void console(char *dev) 171 { 172 char *argv[3]; 177 static void console(const char *dev) 178 { 173 179 char hid_in[DEVMAP_NAME_MAXLEN]; 174 180 int rc; … … 176 182 snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev); 177 183 178 printf( NAME ": Spawning %s with %s\n", SRV_CONSOLE, hid_in);184 printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in); 179 185 180 186 /* Wait for the input device to be ready */ 181 dev _handle_t handle;187 devmap_handle_t handle; 182 188 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 } else192 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 202 static void getterm(const char *dev, const char *app, bool wmsg) 203 { 198 204 char term[DEVMAP_NAME_MAXLEN]; 199 205 int rc; … … 201 207 snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev); 202 208 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); 204 210 205 211 /* Wait for the terminal device to be ready */ 206 dev _handle_t handle;212 devmap_handle_t handle; 207 213 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 237 static 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 244 static 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); 248 249 } 249 250 … … 253 254 254 255 if (!mount_root(STRING(RDFMT))) { 255 printf( NAME ": Exiting\n");256 printf("%s: Exiting\n", NAME); 256 257 return -1; 257 258 } 258 259 259 260 /* Make sure tmpfs is running. */ 260 261 if (str_cmp(STRING(RDFMT), "tmpfs") != 0) { … … 266 267 267 268 if (!mount_devfs()) { 268 printf( NAME ": Exiting\n");269 printf("%s: Exiting\n", NAME); 269 270 return -2; 270 271 } 271 272 272 273 mount_scratch(); 273 274 … … 276 277 srv_start("/srv/cuda_adb"); 277 278 srv_start("/srv/i8042"); 279 srv_start("/srv/s3c24ser"); 278 280 srv_start("/srv/adb_ms"); 279 281 srv_start("/srv/char_ms"); 280 282 srv_start("/srv/s3c24ts"); 283 281 284 spawn("/srv/fb"); 282 285 spawn("/srv/kbd"); … … 284 287 285 288 spawn("/srv/clip"); 286 289 287 290 /* 288 291 * Start these synchronously so that mount_data() can be … … 295 298 (void) srv_start; 296 299 #endif 297 300 298 301 #ifdef CONFIG_MOUNT_DATA 299 302 mount_data(); … … 301 304 (void) mount_data; 302 305 #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 312 315 return 0; 313 316 } -
uspace/app/klog/Makefile
rfb150d78 r46c20c8 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBC_PREFIX)/libc.a 32 33 OUTPUT = klog 31 BINARY = klog 34 32 35 33 SOURCES = \ 36 34 klog.c 37 35 38 include ../Makefile.common36 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/klog/klog.c
rfb150d78 r46c20c8 43 43 #include <event.h> 44 44 #include <errno.h> 45 #include <str_error.h> 45 46 #include <io/klog.h> 46 47 47 #define NAME "klog" 48 #define NAME "klog" 49 #define LOG_FNAME "/log/klog" 48 50 49 51 /* Pointer to klog area */ 50 52 static wchar_t *klog; 51 53 static size_t klog_length; 54 55 static FILE *log; 52 56 53 57 static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) … … 58 62 size_t i; 59 63 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 } 62 77 } 63 78 64 79 int main(int argc, char *argv[]) 65 80 { 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 67 87 size_t klog_size = klog_pages * PAGE_SIZE; 68 88 klog_length = klog_size / sizeof(wchar_t); … … 70 90 klog = (wchar_t *) as_get_mappable_page(klog_size); 71 91 if (klog == NULL) { 72 printf( NAME ": Error allocating memory area\n");92 printf("%s: Error allocating memory area\n", NAME); 73 93 return -1; 74 94 } … … 77 97 klog_size, SERVICE_MEM_KLOG); 78 98 if (res != EOK) { 79 printf( NAME ": Error initializing memory area\n");99 printf("%s: Error initializing memory area\n", NAME); 80 100 return -1; 81 101 } 82 102 83 103 if (event_subscribe(EVENT_KLOG, 0) != EOK) { 84 printf( NAME ": Error registering klog notifications\n");104 printf("%s: Error registering klog notifications\n", NAME); 85 105 return -1; 86 106 } 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)); 87 117 88 118 async_set_interrupt_received(interrupt_received); -
uspace/app/mkfat/Makefile
rfb150d78 r46c20c8 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBC_PREFIX)/libc.a31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a 32 32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) 33 34 OUTPUT = mkfat 33 BINARY = mkfat 35 34 36 35 SOURCES = \ 37 36 mkfat.c 38 37 39 include ../Makefile.common38 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/mkfat/fat.h
rfb150d78 r46c20c8 78 78 uint16_t signature; 79 79 } __attribute__ ((packed)); 80 struct fat32{80 struct { 81 81 /* FAT32 only */ 82 82 /** Sectors per FAT. */ … … 108 108 /** Signature. */ 109 109 uint16_t signature; 110 } __attribute__ ((packed));110 } fat32 __attribute__ ((packed)); 111 111 }; 112 112 } __attribute__ ((packed)) fat_bs_t; -
uspace/app/mkfat/mkfat.c
rfb150d78 r46c20c8 85 85 struct fat_params *par); 86 86 static int fat_blocks_write(struct fat_params const *par, 87 dev _handle_t handle);87 devmap_handle_t handle); 88 88 static void fat_bootsec_create(struct fat_params const *par, struct fat_bs *bs); 89 89 … … 95 95 int rc; 96 96 char *dev_path; 97 dev _handle_t handle;97 devmap_handle_t handle; 98 98 size_t block_size; 99 99 char *endptr; 100 bn_t dev_nblocks;100 aoff64_t dev_nblocks; 101 101 102 102 cfg.total_sectors = 0; … … 160 160 printf(NAME ": Warning, failed to obtain block device size.\n"); 161 161 } else { 162 printf(NAME ": Block device has %" PRIu BN" blocks.\n",162 printf(NAME ": Block device has %" PRIuOFF64 " blocks.\n", 163 163 dev_nblocks); 164 164 cfg.total_sectors = dev_nblocks; … … 234 234 235 235 /** 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;236 static int fat_blocks_write(struct fat_params const *par, devmap_handle_t handle) 237 { 238 aoff64_t addr; 239 239 uint8_t *buffer; 240 240 int i; -
uspace/app/netecho/Makefile
rfb150d78 r46c20c8 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBC_PREFIX)/libc.a32 33 OUTPUT = libpci.a 31 LIBS = 32 EXTRA_CFLAGS = 33 BINARY = netecho 34 34 35 35 SOURCES = \ 36 access.c \ 37 generic.c \ 38 names.c \ 39 i386-ports.c 36 netecho.c \ 37 print_error.c 40 38 41 include ../Makefile.common39 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/redir/Makefile
rfb150d78 r46c20c8 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBC_PREFIX)/libc.a 32 33 OUTPUT = redir 31 BINARY = redir 34 32 35 33 SOURCES = \ 36 34 redir.c 37 35 38 include ../Makefile.common36 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/redir/redir.c
rfb150d78 r46c20c8 39 39 #include <fcntl.h> 40 40 #include <unistd.h> 41 #include <str ing.h>41 #include <str.h> 42 42 #include <stdio.h> 43 43 #include <task.h> 44 #include <str_error.h> 45 #include <errno.h> 46 47 #define NAME "redir" 44 48 45 49 static void usage(void) 46 50 { 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); 48 53 } 49 54 … … 72 77 static task_id_t spawn(int argc, char *argv[]) 73 78 { 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 *)); 75 84 if (!args) { 76 85 printf("No memory available\n"); … … 84 93 args[argc] = NULL; 85 94 86 task_id_t id = task_spawn(argv[0], args);95 rc = task_spawnv(&id, argv[0], args); 87 96 88 97 free(args); 89 98 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 } 92 103 93 104 return id; -
uspace/app/sbi/src/bigint_t.h
rfb150d78 r46c20c8 27 27 */ 28 28 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_ 37 31 38 32 #include <sys/types.h> 33 #include <stdint.h> 39 34 40 /** Interrupt context. 35 typedef uint8_t bigint_word_t; 36 typedef uint16_t bigint_dword_t; 37 38 #define BIGINT_BASE ((bigint_dword_t) 256UL) 39 40 /** Big integer. 41 41 * 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. 43 43 */ 44 typedef struct istate{45 /* TODO*/46 } istate_t;44 typedef struct bigint { 45 /** Number of non-zero digits in the @c digit array. */ 46 size_t length; 47 47 48 static inline uintptr_t istate_get_pc(istate_t *istate) 49 { 50 /* TODO */ 51 return 0; 52 } 48 /** Sign. */ 49 bool_t negative; 53 50 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; 59 54 60 55 #endif 61 62 /** @}63 */ -
uspace/app/sbi/src/builtin.h
rfb150d78 r46c20c8 27 27 */ 28 28 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_ 39 31 40 #ifndef LIBC_amd64_INTTYPES_H_ 41 #define LIBC_amd64_INTTYPES_H_ 32 #include "mytypes.h" 42 33 43 #define PRId8 "d" 44 #define PRId16 "d" 45 #define PRId32 "d" 46 #define PRId64 "lld" 47 #define PRIdPTR "lld" 34 void builtin_declare(stree_program_t *program); 35 void builtin_bind(builtin_t *bi); 36 void builtin_code_snippet(builtin_t *bi, const char *snippet); 48 37 49 #define PRIo8 "o" 50 #define PRIo16 "o" 51 #define PRIo32 "o" 52 #define PRIo64 "llo" 53 #define PRIoPTR "llo" 38 stree_csi_t *builtin_get_gf_class(builtin_t *builtin); 39 void builtin_run_proc(run_t *run, stree_proc_t *proc); 54 40 55 #define PRIu8 "u" 56 #define PRIu16 "u" 57 #define PRIu32 "u" 58 #define PRIu64 "llu" 59 #define PRIuPTR "llu" 41 rdata_var_t *builtin_get_self_mbr_var(run_t *run, const char *mbr_name); 42 void builtin_return_string(run_t *run, const char *str); 60 43 61 #define PRIx8 "x" 62 #define PRIx16 "x" 63 #define PRIx32 "x" 64 #define PRIx64 "llx" 65 #define PRIxPTR "llx" 44 stree_symbol_t *builtin_declare_fun(stree_csi_t *csi, const char *name); 45 void builtin_fun_add_arg(stree_symbol_t *fun_sym, const char *name); 66 46 67 #define PRIX8 "X" 68 #define PRIX16 "X" 69 #define PRIX32 "X" 70 #define PRIX64 "llX" 71 #define PRIXPTR "llX" 47 stree_symbol_t *builtin_find_lvl0(builtin_t *bi, const char *sym_name); 48 stree_symbol_t *builtin_find_lvl1(builtin_t *bi, const char *csi_name, 49 const char *sym_name); 50 51 void builtin_fun_bind(builtin_t *bi, const char *csi_name, 52 const char *sym_name, builtin_proc_t bproc); 72 53 73 54 #endif 74 75 /** @}76 */ -
uspace/app/sbi/src/input.h
rfb150d78 r46c20c8 1 1 /* 2 * Copyright (c) 20 06 Martin Decky2 * Copyright (c) 2010 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 #ifndef BOOT_mips32_TYPES_H_30 #define BOOT_mips32_TYPES_H_29 #ifndef INPUT_H_ 30 #define INPUT_H_ 31 31 32 #include <gentypes.h>32 #include "mytypes.h" 33 33 34 typedef signed char int8_t; 34 int input_new_file(input_t **input, const char *fname); 35 int input_new_interactive(input_t **input); 36 int input_new_string(input_t **input, const char *str); 35 37 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; 38 int input_get_line(input_t *input, char **line); 39 int input_get_line_no(input_t *input); 43 40 44 41 #endif -
uspace/app/sbi/src/tdata.h
rfb150d78 r46c20c8 27 27 */ 28 28 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_ 39 31 40 #ifndef LIBC_arm32_INTTYPES_H_ 41 #define LIBC_arm32_INTTYPES_H_ 32 #include "mytypes.h" 42 33 43 #define PRId8 "d" 44 #define PRId16 "d" 45 #define PRId32 "d" 46 #define PRId64 "lld" 47 #define PRIdPTR "d" 34 tdata_item_t *tdata_item_new(titem_class_t tic); 35 tdata_array_t *tdata_array_new(void); 36 tdata_object_t *tdata_object_new(void); 37 tdata_primitive_t *tdata_primitive_new(tprimitive_class_t tpc); 38 tdata_deleg_t *tdata_deleg_new(void); 39 tdata_ebase_t *tdata_ebase_new(void); 40 tdata_enum_t *tdata_enum_new(void); 41 tdata_fun_t *tdata_fun_new(void); 42 tdata_vref_t *tdata_vref_new(void); 48 43 49 #define PRIo8 "o" 50 #define PRIo16 "o" 51 #define PRIo32 "o" 52 #define PRIo64 "llo" 53 #define PRIoPTR "o" 44 tdata_fun_sig_t *tdata_fun_sig_new(void); 54 45 55 #define PRIu8 "u" 56 #define PRIu16 "u" 57 #define PRIu32 "u" 58 #define PRIu64 "llu" 59 #define PRIuPTR "u" 46 tdata_tvv_t *tdata_tvv_new(void); 47 tdata_item_t *tdata_tvv_get_val(tdata_tvv_t *tvv, sid_t name); 48 void tdata_tvv_set_val(tdata_tvv_t *tvv, sid_t name, tdata_item_t *tvalue); 60 49 61 #define PRIx8 "x" 62 #define PRIx16 "x" 63 #define PRIx32 "x" 64 #define PRIx64 "llx" 65 #define PRIxPTR "x" 50 bool_t tdata_is_csi_derived_from_ti(stree_csi_t *a, tdata_item_t *tb); 51 bool_t tdata_is_ti_derived_from_ti(tdata_item_t *ta, tdata_item_t *tb); 52 bool_t tdata_item_equal(tdata_item_t *a, tdata_item_t *b); 66 53 67 #define PRIX8 "X" 68 #define PRIX16 "X" 69 #define PRIX32 "X" 70 #define PRIX64 "llX" 71 #define PRIXPTR "X" 54 void tdata_item_subst(tdata_item_t *ti, tdata_tvv_t *tvv, tdata_item_t **res); 55 void tdata_item_print(tdata_item_t *titem); 72 56 73 57 #endif 74 75 /** @}76 */ -
uspace/app/stats/stats.c
rfb150d78 r46c20c8 1 1 /* 2 * Copyright (c) 2010 Jiri Svoboda2 * Copyright (c) 2010 Stanislav Kozina 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libc 29 /** @addtogroup stats 30 * @brief Print system statistics. 30 31 * @{ 31 32 */ 32 /** @file Formatting macros for types from sys/types.h and some other33 * system types.33 /** 34 * @file 34 35 */ 35 36 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> 38 42 39 # include <inttypes.h>43 #define NAME "sysstat" 40 44 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 46 48 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 49 int 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 } 78 86 79 87 /** @} -
uspace/app/taskdump/Makefile
rfb150d78 r46c20c8 28 28 29 29 USPACE_PREFIX = ../.. 30 LIBS = $(LIBC_PREFIX)/libc.a31 30 EXTRA_CFLAGS = -Iinclude 32 33 OUTPUT = taskdump 31 BINARY = taskdump 34 32 35 33 SOURCES = \ … … 38 36 symtab.c 39 37 40 include ../Makefile.common38 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/taskdump/elf_core.c
rfb150d78 r46c20c8 62 62 #include "include/elf_core.h" 63 63 64 static off _t align_foff_up(off_t foff, uintptr_t vaddr, size_t page_size);64 static off64_t align_foff_up(off64_t foff, uintptr_t vaddr, size_t page_size); 65 65 static int write_all(int fd, void *data, size_t len); 66 66 static int write_mem_area(int fd, as_area_info_t *area, int phoneid); … … 79 79 * ENOMEM on out of memory, EIO on write error. 80 80 */ 81 int elf_core_save(const char *file_name, as_area_info_t *ainfo, int n, int phoneid)81 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid) 82 82 { 83 83 elf_header_t elf_hdr; 84 off _t foff;84 off64_t foff; 85 85 size_t n_ph; 86 86 elf_word flags; … … 89 89 int fd; 90 90 int rc; 91 int i;91 unsigned int i; 92 92 93 93 n_ph = n; … … 184 184 185 185 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) { 187 187 printf("Failed writing memory data.\n"); 188 188 free(p_hdr); … … 202 202 203 203 /** 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; 204 static 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))); 214 213 } 215 214 -
uspace/app/taskdump/include/elf_core.h
rfb150d78 r46c20c8 36 36 #define ELF_CORE_H_ 37 37 38 int elf_core_save(const char *file_name, as_area_info_t *ainfo, int n, int phoneid);38 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid); 39 39 40 40 #endif -
uspace/app/taskdump/symtab.c
rfb150d78 r46c20c8 49 49 static int section_hdr_load(int fd, const elf_header_t *ehdr, int idx, 50 50 elf_section_header_t *shdr); 51 static int chunk_load(int fd, off _t start, off_t size, void **ptr);51 static int chunk_load(int fd, off64_t start, size_t size, void **ptr); 52 52 static int read_all(int fd, void *buf, size_t len); 53 53 … … 65 65 elf_header_t elf_hdr; 66 66 elf_section_header_t sec_hdr; 67 off_t shstrt_start, shstrt_size; 67 off64_t shstrt_start; 68 size_t shstrt_size; 68 69 char *shstrt, *sec_name; 69 70 void *data; … … 307 308 rc = lseek(fd, elf_hdr->e_shoff + idx * sizeof(elf_section_header_t), 308 309 SEEK_SET); 309 if (rc == (off _t) -1)310 if (rc == (off64_t) -1) 310 311 return EIO; 311 312 … … 328 329 * @return EOK on success or EIO on failure. 329 330 */ 330 static int chunk_load(int fd, off _t start, off_t size, void **ptr)331 static int chunk_load(int fd, off64_t start, size_t size, void **ptr) 331 332 { 332 333 int rc; 333 334 334 335 rc = lseek(fd, start, SEEK_SET); 335 if (rc == (off _t) -1) {336 if (rc == (off64_t) -1) { 336 337 printf("failed seeking chunk\n"); 337 338 *ptr = NULL; -
uspace/app/taskdump/taskdump.c
rfb150d78 r46c20c8 54 54 #define LINE_BYTES 16 55 55 56 #define DBUF_SIZE 409657 static uint8_t data_buf[DBUF_SIZE];58 59 56 static int phoneid; 60 57 static task_id_t task_id; … … 70 67 static int thread_dump(uintptr_t thash); 71 68 static 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);74 69 static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value); 75 70 … … 90 85 rc = connect_task(task_id); 91 86 if (rc < 0) { 92 printf("Failed connecting to task %" PRI dTASKID".\n", task_id);87 printf("Failed connecting to task %" PRIu64 ".\n", task_id); 93 88 return 1; 94 89 } … … 97 92 app_symtab = NULL; 98 93 99 printf("Dumping task '%s' (task ID %" PRI dTASKID").\n", app_name, task_id);94 printf("Dumping task '%s' (task ID %" PRIu64 ").\n", app_name, task_id); 100 95 autoload_syms(); 101 96 putchar('\n'); … … 131 126 if (rc < 0) { 132 127 printf("Error connecting\n"); 133 printf("ipc_connect_task(%" PRI dTASKID") -> %d ", task_id, rc);128 printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, rc); 134 129 return rc; 135 130 } … … 173 168 core_file_name = *argv; 174 169 } else { 175 printf("Uknown option '% s'\n", arg[0]);170 printf("Uknown option '%c'\n", arg[0]); 176 171 print_syntax(); 177 172 return -1; … … 245 240 printf("Threads:\n"); 246 241 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]); 248 243 249 244 thread_dump(thash_buf[i]); … … 289 284 printf("Address space areas:\n"); 290 285 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, 292 287 (ainfo_buf[i].flags & AS_AREA_READ) ? 'R' : '-', 293 288 (ainfo_buf[i].flags & AS_AREA_WRITE) ? 'W' : '-', 294 289 (ainfo_buf[i].flags & AS_AREA_EXEC) ? 'X' : '-', 295 290 (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); 297 292 } 298 293 … … 331 326 332 327 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); 334 330 free(sym_pc); 335 331 … … 339 335 while (stacktrace_fp_valid(&st, fp)) { 340 336 sym_pc = fmt_sym_address(pc); 341 printf(" %p: %s\n", fp, sym_pc);337 printf(" %p: %s\n", (void *) fp, sym_pc); 342 338 free(sym_pc); 343 339 … … 354 350 355 351 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 }415 352 } 416 353 … … 521 458 522 459 if (rc == EOK) { 523 rc = asprintf(&str, "%p (%s+% p)",addr, name, offs);460 rc = asprintf(&str, "%p (%s+%zu)", (void *) addr, name, offs); 524 461 } else { 525 rc = asprintf(&str, "%p", addr);462 rc = asprintf(&str, "%p", (void *) addr); 526 463 } 527 464 -
uspace/app/tester/Makefile
rfb150d78 r46c20c8 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBC_PREFIX)/libc.a 32 33 OUTPUT = tester 31 BINARY = tester 34 32 35 33 SOURCES = \ … … 40 38 print/print3.c \ 41 39 print/print4.c \ 40 print/print5.c \ 42 41 console/console1.c \ 43 42 stdio/stdio1.c \ … … 51 50 ipc/connect.c \ 52 51 loop/loop1.c \ 53 mm/malloc1.c 52 mm/malloc1.c \ 53 hw/serial/serial1.c 54 54 55 include ../Makefile.common55 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/tester/console/console1.c
rfb150d78 r46c20c8 36 36 #include "../tester.h" 37 37 38 const char *color_name[] = {38 static const char *color_name[] = { 39 39 [COLOR_BLACK] = "black", 40 40 [COLOR_BLUE] = "blue", … … 47 47 }; 48 48 49 c har *test_console1(void)49 const char *test_console1(void) 50 50 { 51 51 if (!test_quiet) { … … 53 53 fflush(stdout); 54 54 console_set_style(fphone(stdout), STYLE_NORMAL); 55 printf(" normal ");55 printf(" normal "); 56 56 fflush(stdout); 57 57 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 "); 59 65 fflush(stdout); 60 66 console_set_style(fphone(stdout), STYLE_NORMAL); 61 printf(" .\n");67 printf("\n"); 62 68 63 69 unsigned int i; … … 73 79 } 74 80 fflush(stdout); 75 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);81 console_set_style(fphone(stdout), STYLE_NORMAL); 76 82 putchar('\n'); 77 83 } … … 86 92 } 87 93 fflush(stdout); 88 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);94 console_set_style(fphone(stdout), STYLE_NORMAL); 89 95 putchar('\n'); 90 96 } … … 94 100 for (i = 0; i < 255; i += 16) { 95 101 fflush(stdout); 96 console_set_rgb_color(fphone(stdout), 0xffffff, i << 16);102 console_set_rgb_color(fphone(stdout), (255 - i) << 16, i << 16); 97 103 putchar('X'); 98 104 } … … 103 109 for (i = 0; i < 255; i += 16) { 104 110 fflush(stdout); 105 console_set_rgb_color(fphone(stdout), 0xffffff, i << 8);111 console_set_rgb_color(fphone(stdout), (255 - i) << 8, i << 8); 106 112 putchar('X'); 107 113 } … … 112 118 for (i = 0; i < 255; i += 16) { 113 119 fflush(stdout); 114 console_set_rgb_color(fphone(stdout), 0xffffff, i);120 console_set_rgb_color(fphone(stdout), 255 - i, i); 115 121 putchar('X'); 116 122 } 117 123 fflush(stdout); 118 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);124 console_set_style(fphone(stdout), STYLE_NORMAL); 119 125 putchar('\n'); 120 126 } -
uspace/app/tester/fault/fault1.c
rfb150d78 r46c20c8 30 30 #include "../tester.h" 31 31 32 c har *test_fault1(void)32 const char *test_fault1(void) 33 33 { 34 34 ((int *)(0))[1] = 0; -
uspace/app/tester/fault/fault2.c
rfb150d78 r46c20c8 30 30 #include "../tester.h" 31 31 32 char *test_fault2(void) 32 typedef int __attribute__((may_alias)) aliasing_int; 33 34 const char *test_fault2(void) 33 35 { 34 36 volatile long long var; 35 37 volatile int var1; 36 38 37 var1 = *(( int *) (((char *) (&var)) + 1));39 var1 = *((aliasing_int *) (((char *) (&var)) + 1)); 38 40 39 41 return "Survived unaligned read"; -
uspace/app/tester/fault/fault3.c
rfb150d78 r46c20c8 30 30 #include <stdlib.h> 31 31 32 c har *test_fault3(void)32 const char *test_fault3(void) 33 33 { 34 34 abort(); -
uspace/app/tester/fault/fault3.def
rfb150d78 r46c20c8 3 3 "Abort", 4 4 &test_fault3, 5 true5 false 6 6 }, -
uspace/app/tester/ipc/connect.c
rfb150d78 r46c20c8 39 39 } 40 40 41 c har *test_connect(void)41 const char *test_connect(void) 42 42 { 43 43 TPRINTF("Connecting to %u...", IPC_TEST_SERVICE); -
uspace/app/tester/ipc/ping_pong.c
rfb150d78 r46c20c8 38 38 #define COUNT_GRANULARITY 100 39 39 40 c har *test_ping_pong(void)40 const char *test_ping_pong(void) 41 41 { 42 42 TPRINTF("Pinging ns server for %d seconds...", DURATION_SECS); … … 72 72 } 73 73 74 TPRINTF("OK\nCompleted % llu round trips in %u seconds, %llurt/s.\n",74 TPRINTF("OK\nCompleted %" PRIu64 " round trips in %u seconds, %" PRIu64 " rt/s.\n", 75 75 count, DURATION_SECS, count / DURATION_SECS); 76 76 -
uspace/app/tester/ipc/register.c
rfb150d78 r46c20c8 27 27 */ 28 28 29 #include <inttypes.h> 29 30 #include <stdio.h> 30 31 #include <unistd.h> … … 41 42 unsigned int i; 42 43 43 TPRINTF("Connected phone % #xaccepting\n", icall->in_phone_hash);44 TPRINTF("Connected phone %" PRIun " accepting\n", icall->in_phone_hash); 44 45 ipc_answer_0(iid, EOK); 45 46 for (i = 0; i < MAX_CONNECTIONS; i++) { … … 57 58 switch (IPC_GET_METHOD(call)) { 58 59 case IPC_M_PHONE_HUNGUP: 59 TPRINTF("Phone % #xhung up\n", icall->in_phone_hash);60 TPRINTF("Phone %" PRIun " hung up\n", icall->in_phone_hash); 60 61 retval = 0; 61 62 break; 62 63 case IPC_TEST_METHOD: 63 TPRINTF("Received well known message from % #x: %#x\n",64 TPRINTF("Received well known message from %" PRIun ": %" PRIun "\n", 64 65 icall->in_phone_hash, callid); 65 66 ipc_answer_0(callid, EOK); 66 67 break; 67 68 default: 68 TPRINTF("Received unknown message from % #x: %#x\n",69 TPRINTF("Received unknown message from %" PRIun ": %" PRIun "\n", 69 70 icall->in_phone_hash, callid); 70 71 ipc_answer_0(callid, ENOENT); … … 74 75 } 75 76 76 c har *test_register(void)77 const char *test_register(void) 77 78 { 78 79 async_set_client_connection(client_connection); -
uspace/app/tester/loop/loop1.c
rfb150d78 r46c20c8 31 31 #include "../tester.h" 32 32 33 c har *test_loop1(void)33 const char *test_loop1(void) 34 34 { 35 35 TPRINTF("Looping..."); -
uspace/app/tester/mm/malloc1.c
rfb150d78 r46c20c8 73 73 74 74 typedef struct { 75 c har *name;75 const char *name; 76 76 sp_term_cond_s cond; 77 77 sp_action_prob_s prob; … … 90 90 91 91 typedef struct { 92 c har *name;92 const char *name; 93 93 ph_alloc_size_s alloc; 94 94 subphase_s *subphases; … … 628 628 } 629 629 630 c har *test_malloc1(void)630 const char *test_malloc1(void) 631 631 { 632 632 init_mem(); -
uspace/app/tester/print/print1.c
rfb150d78 r46c20c8 31 31 #include "../tester.h" 32 32 33 c har *test_print1(void)33 const char *test_print1(void) 34 34 { 35 35 TPRINTF("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n"); … … 49 49 TPRINTF("Real output: \"%8.10s\"\n\n", "very long text"); 50 50 51 TPRINTF("Testing printf(\"%%s\", NULL):\n");52 TPRINTF("Expected output: \"(NULL)\"\n");53 TPRINTF("Real output: \"%s\"\n\n", NULL);54 55 51 return NULL; 56 52 } -
uspace/app/tester/print/print2.c
rfb150d78 r46c20c8 31 31 #include "../tester.h" 32 32 33 c har *test_print2(void)33 const char *test_print2(void) 34 34 { 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'); 38 38 39 39 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 34 34 #define BUFFER_SIZE 32 35 35 36 c har *test_print3(void)36 const char *test_print3(void) 37 37 { 38 38 char buffer[BUFFER_SIZE]; -
uspace/app/tester/print/print4.c
rfb150d78 r46c20c8 31 31 #include "../tester.h" 32 32 33 c har *test_print4(void)33 const char *test_print4(void) 34 34 { 35 35 TPRINTF("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n"); … … 45 45 TPRINTF(" "); 46 46 for (index = 0; index < 32; index++) 47 TPRINTF("%lc", (w char_t) ((group << 5) + index));47 TPRINTF("%lc", (wint_t) ((group << 5) + index)); 48 48 49 49 TPRINTF("\n"); … … 57 57 uint8_t index; 58 58 for (index = 0; index < 32; index++) 59 TPRINTF("%lc", (w char_t) ((group << 5) + index));59 TPRINTF("%lc", (wint_t) ((group << 5) + index)); 60 60 61 61 TPRINTF("\n"); -
uspace/app/tester/stdio/stdio1.c
rfb150d78 r46c20c8 36 36 static char buf[BUF_SIZE + 1]; 37 37 38 c har *test_stdio1(void)38 const char *test_stdio1(void) 39 39 { 40 40 FILE *file; 41 c har *file_name = "/readme";41 const char *file_name = "/readme"; 42 42 43 43 TPRINTF("Open file \"%s\"...", file_name); … … 60 60 61 61 buf[cnt] = '\0'; 62 TPRINTF("Read % u bytes, string \"%s\"\n", cnt, buf);62 TPRINTF("Read %zu bytes, string \"%s\"\n", cnt, buf); 63 63 64 64 TPRINTF("Seek to beginning..."); -
uspace/app/tester/stdio/stdio2.c
rfb150d78 r46c20c8 32 32 #include "../tester.h" 33 33 34 c har *test_stdio2(void)34 const char *test_stdio2(void) 35 35 { 36 36 FILE *file; 37 c har *file_name = "/test";37 const char *file_name = "/test"; 38 38 39 39 TPRINTF("Open file \"%s\" for writing...", file_name); -
uspace/app/tester/tester.c
rfb150d78 r46c20c8 38 38 #include <unistd.h> 39 39 #include <stdio.h> 40 #include <str ing.h>40 #include <str.h> 41 41 #include "tester.h" 42 42 … … 51 51 #include "print/print3.def" 52 52 #include "print/print4.def" 53 #include "print/print5.def" 53 54 #include "console/console1.def" 54 55 #include "stdio/stdio1.def" … … 63 64 #include "loop/loop1.def" 64 65 #include "mm/malloc1.def" 66 #include "hw/serial/serial1.def" 65 67 {NULL, NULL, NULL, false} 66 68 }; … … 69 71 { 70 72 /* Execute the test */ 71 c har *ret = test->entry();73 const char *ret = test->entry(); 72 74 73 75 if (ret == NULL) { … … 110 112 } 111 113 114 unsigned int _len = (unsigned int) len; 115 if ((_len != len) || (((int) _len) < 0)) { 116 printf("Command length overflow\n"); 117 return; 118 } 119 112 120 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)")); 114 123 115 printf("%-*s Run all safe tests\n", len, "*");124 printf("%-*s Run all safe tests\n", _len, "*"); 116 125 } 117 126 -
uspace/app/tester/tester.h
rfb150d78 r46c20c8 54 54 } 55 55 56 typedef c har *(*test_entry_t)(void);56 typedef const char *(*test_entry_t)(void); 57 57 58 58 typedef struct { 59 c har *name;60 c har *desc;59 const char *name; 60 const char *desc; 61 61 test_entry_t entry; 62 62 bool safe; 63 63 } test_t; 64 64 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); 65 extern const char *test_thread1(void); 66 extern const char *test_print1(void); 67 extern const char *test_print2(void); 68 extern const char *test_print3(void); 69 extern const char *test_print4(void); 70 extern const char *test_print5(void); 71 extern const char *test_console1(void); 72 extern const char *test_stdio1(void); 73 extern const char *test_stdio2(void); 74 extern const char *test_fault1(void); 75 extern const char *test_fault2(void); 76 extern const char *test_fault3(void); 77 extern const char *test_vfs1(void); 78 extern const char *test_ping_pong(void); 79 extern const char *test_register(void); 80 extern const char *test_connect(void); 81 extern const char *test_loop1(void); 82 extern const char *test_malloc1(void); 83 extern const char *test_serial1(void); 82 84 83 85 extern test_t tests[]; -
uspace/app/tester/thread/thread1.c
rfb150d78 r46c20c8 35 35 #include <stdio.h> 36 36 #include <unistd.h> 37 #include <inttypes.h> 37 38 #include "../tester.h" 38 39 … … 50 51 } 51 52 52 c har *test_thread1(void)53 const char *test_thread1(void) 53 54 { 54 55 unsigned int i; 55 int total = 0;56 atomic_count_t total = 0; 56 57 57 58 atomic_set(&finish, 1); … … 74 75 atomic_set(&finish, 0); 75 76 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)); 77 79 sleep(1); 78 80 } -
uspace/app/tester/vfs/vfs1.c
rfb150d78 r46c20c8 30 30 #include <stdio.h> 31 31 #include <stdlib.h> 32 #include <str ing.h>32 #include <str.h> 33 33 #include <vfs/vfs.h> 34 34 #include <unistd.h> … … 54 54 static char text[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"; 55 55 56 static c har *read_root(void)56 static const char *read_root(void) 57 57 { 58 58 TPRINTF("Opening the root directory..."); … … 73 73 } 74 74 75 c har *test_vfs1(void)75 const char *test_vfs1(void) 76 76 { 77 77 if (mkdir(MOUNT_POINT, 0) != 0) … … 105 105 if (cnt < 0) 106 106 return "write() failed"; 107 TPRINTF("Written % d bytes\n", cnt);107 TPRINTF("Written %zd bytes\n", cnt); 108 108 109 109 if (lseek(fd0, 0, SEEK_SET) != 0) … … 116 116 return "read() failed"; 117 117 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 } 119 125 } 120 126 121 127 close(fd0); 122 128 123 c har *rv = read_root();129 const char *rv = read_root(); 124 130 if (rv != NULL) 125 131 return rv; -
uspace/app/tetris/Makefile
rfb150d78 r46c20c8 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBC_PREFIX)/libc.a 32 33 OUTPUT = tetris 31 BINARY = tetris 34 32 35 33 SOURCES = \ … … 40 38 screen.c 41 39 42 include ../Makefile.common40 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/tetris/input.c
rfb150d78 r46c20c8 52 52 #include <errno.h> 53 53 #include <unistd.h> 54 #include <str ing.h>54 #include <str.h> 55 55 56 56 #include "input.h" -
uspace/app/tetris/scores.c
rfb150d78 r46c20c8 52 52 #include <errno.h> 53 53 #include <stdio.h> 54 #include <str ing.h>54 #include <str.h> 55 55 #include <io/console.h> 56 56 #include <io/keycode.h> -
uspace/app/tetris/scores.h
rfb150d78 r46c20c8 48 48 49 49 #include <sys/time.h> 50 #include <str ing.h>50 #include <str.h> 51 51 52 52 #define MAXLOGNAME 16 -
uspace/app/tetris/screen.c
rfb150d78 r46c20c8 49 49 #include <stdio.h> 50 50 #include <stdlib.h> 51 #include <str ing.h>51 #include <str.h> 52 52 #include <unistd.h> 53 53 #include <vfs/vfs.h> 54 54 #include <async.h> 55 #include <bool.h> 56 #include <io/console.h> 57 #include <io/style.h> 55 58 #include "screen.h" 56 59 #include "tetris.h" 57 #include <io/console.h>58 60 59 61 #define STOP (B_COLS - 3) … … 63 65 static int isset; /* true => terminal is in game mode */ 64 66 65 static int use_color;/* true => use colors */67 static bool use_color; /* true => use colors */ 66 68 67 69 static const struct shape *lastshape; … … 72 74 * simply literal strings); 73 75 */ 74 static inline void putstr(c har *s)76 static inline void putstr(const char *s) 75 77 { 76 78 while (*s) … … 81 83 { 82 84 fflush(stdout); 83 console_set_rgb_color(fphone(stdout), 0xf 0f0f0,85 console_set_rgb_color(fphone(stdout), 0xffffff, 84 86 use_color ? color : 0x000000); 85 87 } … … 88 90 { 89 91 fflush(stdout); 90 console_set_ rgb_color(fphone(stdout), 0, 0xf0f0f0);92 console_set_style(fphone(stdout), STYLE_NORMAL); 91 93 } 92 94 … … 118 120 } 119 121 120 void moveto(i nt r, int c)122 void moveto(ipcarg_t r, ipcarg_t c) 121 123 { 122 124 fflush(stdout); 123 console_ goto(fphone(stdout), c, r);125 console_set_pos(fphone(stdout), c, r); 124 126 } 125 127 … … 131 133 } 132 134 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); 135 static bool get_display_color_sup(void) 136 { 137 ipcarg_t ccap; 138 int rc = console_get_color_cap(fphone(stdout), &ccap); 139 139 140 if (rc != 0) 140 return 0;141 141 return false; 142 142 143 return (ccap >= CONSOLE_CCAP_RGB); 143 144 } … … 181 182 } 182 183 183 void stop(c har *why)184 void stop(const char *why) 184 185 { 185 186 if (isset) … … 308 309 * (We need its length in case we have to overwrite with blanks.) 309 310 */ 310 void scr_msg(char *s, intset)311 void scr_msg(char *s, bool set) 311 312 { 312 313 int l = str_size(s); -
uspace/app/tetris/screen.h
rfb150d78 r46c20c8 48 48 49 49 #include <sys/types.h> 50 #include <ipc/ipc.h> 50 51 #include <async.h> 52 #include <bool.h> 51 53 52 54 typedef struct { 53 i nt ws_row;54 i nt ws_col;55 ipcarg_t ws_row; 56 ipcarg_t ws_col; 55 57 } winsize_t; 56 58 57 59 extern winsize_t winsize; 58 60 59 extern void moveto(i nt r, int c);61 extern void moveto(ipcarg_t r, ipcarg_t c); 60 62 extern void clear_screen(void); 61 63 … … 65 67 extern void scr_end(void); 66 68 extern void scr_init(void); 67 extern void scr_msg(char *, int);69 extern void scr_msg(char *, bool); 68 70 extern void scr_set(void); 69 71 extern void scr_update(void); -
uspace/app/tetris/tetris.c
rfb150d78 r46c20c8 53 53 #include <stdio.h> 54 54 #include <stdlib.h> 55 #include <str ing.h>55 #include <str.h> 56 56 #include <unistd.h> 57 57 #include <getopt.h> -
uspace/app/tetris/tetris.h
rfb150d78 r46c20c8 186 186 extern int fits_in(const struct shape *, int); 187 187 extern void place(const struct shape *, int, int); 188 extern void stop(c har *);188 extern void stop(const char *); 189 189 190 190 /** @} -
uspace/app/top/top.h
rfb150d78 r46c20c8 1 1 /* 2 * Copyright (c) 2005 Martin Decky 2 * Copyright (c) 2010 Stanislav Kozina 3 * Copyright (c) 2010 Martin Decky 3 4 * All rights reserved. 4 5 * … … 27 28 */ 28 29 29 #ifndef BOOT_sparc64_MAIN_H_ 30 #define BOOT_sparc64_MAIN_H_ 30 /** @addtogroup top 31 * @{ 32 */ 31 33 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_ 36 36 37 #define KERNEL_VIRTUAL_ADDRESS 0x400000 37 #include <task.h> 38 #include <stats.h> 39 #include <time.h> 38 40 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) 40 51 41 /** Size of buffer for storing task name in task_t. */ 42 #define BOOTINFO_TASK_NAME_BUFLEN 32 52 typedef enum { 53 OP_TASKS, 54 OP_IPC, 55 OP_EXCS, 56 OP_HELP 57 } op_mode_t; 43 58 44 #define BSP_PROCESSOR 1 45 #define AP_PROCESSOR 0 59 typedef enum { 60 SORT_TASK_CYCLES 61 } sort_mode_t; 46 62 47 #define SUBARCH_US 1 48 #define SUBARCH_US3 3 63 extern op_mode_t op_mode; 64 extern sort_mode_t sort_mode; 65 extern bool excs_all; 49 66 50 67 typedef 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; 55 71 56 72 typedef 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; 60 76 61 77 typedef 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; 68 82 69 extern uint32_t silo_ramdisk_image; 70 extern uint32_t silo_ramdisk_size; 83 typedef struct { 84 fixed_float cycles; 85 fixed_float count; 86 } perc_exc_t; 71 87 72 extern void start(void); 73 extern void bootstrap(void); 88 typedef 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; 74 124 75 125 #endif 126 127 /** 128 * @} 129 */ -
uspace/app/trace/Makefile
rfb150d78 r46c20c8 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBC_PREFIX)/libc.a 32 33 OUTPUT = trace 31 BINARY = trace 34 32 35 33 SOURCES = \ … … 41 39 errors.c 42 40 43 include ../Makefile.common41 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/trace/errors.h
rfb150d78 r46c20c8 37 37 38 38 typedef struct { 39 c har *name;/**< Error value name (Exx) */40 c har *desc;/**< Error description */39 const char *name; /**< Error value name (Exx) */ 40 const char *desc; /**< Error description */ 41 41 } err_desc_t; 42 42 -
uspace/app/trace/ipc_desc.h
rfb150d78 r46c20c8 38 38 typedef struct { 39 39 int number; 40 c har *name;40 const char *name; 41 41 } ipc_m_desc_t; 42 42 -
uspace/app/trace/ipcp.c
rfb150d78 r46c20c8 137 137 138 138 if (oper != NULL) { 139 printf("%s (% ld)", oper->name, method);139 printf("%s (%" PRIun ")", oper->name, method); 140 140 return; 141 141 } 142 142 143 printf("% ld", method);143 printf("%" PRIun, method); 144 144 } 145 145 … … 201 201 202 202 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")); 205 206 ipc_m_print(proto, IPC_GET_METHOD(*call)); 206 printf(" args: (%" PRIu IPCARG ", %" PRIuIPCARG ", %" PRIuIPCARG207 " , %" 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]); 209 210 } 210 211 … … 281 282 282 283 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), 287 287 IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer), 288 288 IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer)); … … 340 340 /* Not a response */ 341 341 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); 343 343 } 344 344 return; -
uspace/app/trace/proto.c
rfb150d78 r46c20c8 157 157 } 158 158 159 static void proto_struct_init(proto_t *proto, c har *name)159 static void proto_struct_init(proto_t *proto, const char *name) 160 160 { 161 161 proto->name = name; … … 164 164 } 165 165 166 proto_t *proto_new(c har *name)166 proto_t *proto_new(const char *name) 167 167 { 168 168 proto_t *p; … … 206 206 } 207 207 208 static void oper_struct_init(oper_t *oper, c har *name)208 static void oper_struct_init(oper_t *oper, const char *name) 209 209 { 210 210 oper->name = name; 211 211 } 212 212 213 oper_t *oper_new(c har *name, int argc, val_type_t *arg_types,213 oper_t *oper_new(const char *name, int argc, val_type_t *arg_types, 214 214 val_type_t rv_type, int respc, val_type_t *resp_types) 215 215 { -
uspace/app/trace/proto.h
rfb150d78 r46c20c8 43 43 44 44 typedef struct { 45 c har *name;45 const char *name; 46 46 47 47 int argc; … … 56 56 typedef struct { 57 57 /** Protocol name */ 58 c har *name;58 const char *name; 59 59 60 60 /** Maps method number to operation */ … … 70 70 void proto_register(int srv, proto_t *proto); 71 71 proto_t *proto_get_by_srv(int srv); 72 proto_t *proto_new(c har *name);72 proto_t *proto_new(const char *name); 73 73 void proto_delete(proto_t *proto); 74 74 void proto_add_oper(proto_t *proto, int method, oper_t *oper); 75 75 oper_t *proto_get_oper(proto_t *proto, int method); 76 76 77 oper_t *oper_new(c har *name, int argc, val_type_t *arg_types,77 oper_t *oper_new(const char *name, int argc, val_type_t *arg_types, 78 78 val_type_t rv_type, int respc, val_type_t *resp_types); 79 79 -
uspace/app/trace/syscalls.c
rfb150d78 r46c20c8 73 73 [SYS_PHYSMEM_MAP] = { "physmem_map", 4, V_ERRNO }, 74 74 [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 }, 76 76 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 79 82 [SYS_DEBUG_ENABLE_CONSOLE] = { "debug_enable_console", 0, V_ERRNO }, 80 83 [SYS_IPC_CONNECT_KBOX] = { "ipc_connect_kbox", 1, V_ERRNO } -
uspace/app/trace/syscalls.h
rfb150d78 r46c20c8 39 39 40 40 typedef struct { 41 c har *name;41 const char *name; 42 42 int n_args; 43 43 val_type_t rv_type; -
uspace/app/trace/trace.c
rfb150d78 r46c20c8 43 43 #include <task.h> 44 44 #include <mem.h> 45 #include <str ing.h>45 #include <str.h> 46 46 #include <bool.h> 47 47 #include <loader/loader.h> … … 161 161 if (rc < 0) { 162 162 printf("Error connecting\n"); 163 printf("ipc_connect_task(%" PRI dTASKID") -> %d ", task_id, rc);163 printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, rc); 164 164 return rc; 165 165 } … … 200 200 printf("Threads:"); 201 201 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)); 205 205 206 206 return 0; … … 224 224 case V_HASH: 225 225 case V_PTR: 226 printf("%p", val);226 printf("%p", (void *) val); 227 227 break; 228 228 … … 248 248 case V_CHAR: 249 249 if (sval >= 0x20 && sval < 0x7f) { 250 printf("'%c'", sval);250 printf("'%c'", (char) sval); 251 251 } else { 252 252 switch (sval) { … … 257 257 case '\t': printf("'\\t'"); break; 258 258 case '\\': printf("'\\\\'"); break; 259 default: printf("'\\x%02 lX'", val); break;259 default: printf("'\\x%02" PRIxn "'", val); break; 260 260 } 261 261 } … … 277 277 278 278 putchar('('); 279 if (n > 0) printf("%" PRI dSYSARG, sc_args[0]);279 if (n > 0) printf("%" PRIun, sc_args[0]); 280 280 for (i = 1; i < n; i++) { 281 printf(", %" PRI dSYSARG, sc_args[i]);281 printf(", %" PRIun, sc_args[i]); 282 282 } 283 283 putchar(')'); … … 489 489 { 490 490 async_serialize_start(); 491 printf("New thread, hash 0x%lx\n",hash);491 printf("New thread, hash %p\n", (void *) hash); 492 492 async_serialize_end(); 493 493 … … 510 510 } 511 511 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); 513 514 514 515 while (!abort_trace) { … … 516 517 fibril_mutex_lock(&state_lock); 517 518 if (paused) { 518 printf("Thread [% d] paused. Press R to resume.\n",519 printf("Thread [%u] paused. Press R to resume.\n", 519 520 thread_id); 520 521 … … 522 523 fibril_condvar_wait(&state_cv, &state_lock); 523 524 524 printf("Thread [% d] resumed.\n", thread_id);525 printf("Thread [%u] resumed.\n", thread_id); 525 526 } 526 527 fibril_mutex_unlock(&state_lock); … … 554 555 break; 555 556 case UDEBUG_EVENT_THREAD_E: 556 printf("Thread % pexited.\n", val0);557 printf("Thread %" PRIun " exited.\n", val0); 557 558 fibril_mutex_lock(&state_lock); 558 559 abort_trace = true; … … 585 586 } 586 587 587 static loader_t *preload_task(const char *path, char * const argv[],588 static loader_t *preload_task(const char *path, char **argv, 588 589 task_id_t *task_id) 589 590 { … … 591 592 int rc; 592 593 593 /* Spawn a program loader */ 594 /* Spawn a program loader */ 594 595 ldr = loader_connect(); 595 596 if (ldr == NULL) … … 607 608 608 609 /* Send arguments */ 609 rc = loader_set_args(ldr, argv);610 rc = loader_set_args(ldr, (const char **) argv); 610 611 if (rc != EOK) 611 612 goto error; … … 870 871 } 871 872 872 static display_mask_t parse_display_mask(c har *text)873 static display_mask_t parse_display_mask(const char *text) 873 874 { 874 875 display_mask_t dm; 875 char *c; 876 877 c = text; 878 876 const char *c = text; 877 879 878 while (*c) { 880 879 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; 885 892 default: 886 893 printf("Unexpected event type '%c'.\n", *c); 887 894 exit(1); 888 895 } 889 896 890 897 ++c; 891 898 } 892 899 893 900 return dm; 894 901 } … … 896 903 static int parse_args(int argc, char *argv[]) 897 904 { 898 char *arg;899 905 char *err_p; 900 906 901 907 task_id = 0; 902 908 903 --argc; ++argv; 909 --argc; 910 ++argv; 904 911 905 912 while (argc > 0) { 906 arg = *argv;913 char *arg = *argv; 907 914 if (arg[0] == '+') { 908 915 display_mask = parse_display_mask(&arg[1]); … … 910 917 if (arg[1] == 't') { 911 918 /* Trace an already running task */ 912 --argc; ++argv; 919 --argc; 920 ++argv; 913 921 task_id = strtol(*argv, &err_p, 10); 914 922 task_ldr = NULL; … … 920 928 } 921 929 } else { 922 printf("Uknown option '% s'\n", arg[0]);930 printf("Uknown option '%c'\n", arg[0]); 923 931 print_syntax(); 924 932 return -1; … … 927 935 break; 928 936 } 929 930 --argc; ++argv; 937 938 --argc; 939 ++argv; 931 940 } 932 941 933 942 if (task_id != 0) { 934 if (argc == 0) return 0; 943 if (argc == 0) 944 return 0; 935 945 printf("Extra arguments\n"); 936 946 print_syntax(); … … 946 956 /* Preload the specified program file. */ 947 957 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 952 963 task_ldr = preload_task(*argv, argv, &task_id); 953 964 task_wait_for = true; … … 974 985 rc = connect_task(task_id); 975 986 if (rc < 0) { 976 printf("Failed connecting to task %" PRI dTASKID".\n", task_id);987 printf("Failed connecting to task %" PRIu64 ".\n", task_id); 977 988 return 1; 978 989 } 979 990 980 printf("Connected to task %" PRI dTASKID".\n", task_id);991 printf("Connected to task %" PRIu64 ".\n", task_id); 981 992 982 993 if (task_ldr != NULL)
Note:
See TracChangeset
for help on using the changeset viewer.