Changeset 03362fbd in mainline for uspace/app


Ignore:
Timestamp:
2013-02-09T23:14:45Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
22dfd38
Parents:
b5d2e57 (diff), 005b765 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Conflict resulting from bool.h → stdbool.h move and ddf structs turning opaque.
Fails to boot to shell console.

Location:
uspace/app
Files:
30 added
3 deleted
52 edited
4 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/Makefile

    rb5d2e57 r03362fbd  
    5353        cmds/modules/unmount/unmount.c \
    5454        cmds/modules/kcon/kcon.c \
     55        cmds/modules/cmp/cmp.c \
    5556        cmds/builtins/batch/batch.c \
    5657        cmds/builtins/exit/exit.c \
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    rb5d2e57 r03362fbd  
    3838#include "cmds.h"
    3939
    40 #include <libblock.h>
     40#include <block.h>
    4141#include <loc.h>
    4242#include <errno.h>
  • uspace/app/bdsh/cmds/modules/modules.h

    rb5d2e57 r03362fbd  
    6363#include "printf/entry.h"
    6464#include "echo/entry.h"
     65#include "cmp/entry.h"
    6566
    6667/* Each .def function fills the module_t struct with the individual name, entry
     
    8687#include "printf/printf_def.h"
    8788#include "echo/echo_def.h"
     89#include "cmp/cmp_def.h"
    8890
    8991        {NULL, NULL, NULL, NULL}
  • uspace/app/bdsh/compl.c

    rb5d2e57 r03362fbd  
    2828 */
    2929
    30 #include <bool.h>
     30#include <stdbool.h>
    3131#include <dirent.h>
    3232#include <errno.h>
  • uspace/app/bdsh/config.h

    rb5d2e57 r03362fbd  
    5555#define PACKAGE_STRING "The brain dead shell"
    5656#define PACKAGE_TARNAME "bdsh"
    57 #define PACKAGE_VERSION "0.0.1"
    58 
    59 
    60 
     57#define PACKAGE_VERSION "0.1.0"
  • uspace/app/bdsh/errors.h

    rb5d2e57 r03362fbd  
    3030#define ERRORS_H
    3131
     32#include <io/verify.h>
     33
    3234/* Various error levels */
    3335#define CL_EFATAL  -1
     
    4648extern volatile int cli_errno;
    4749
    48 extern void cli_error(int, const char *, ...);
     50extern void cli_error(int, const char *, ...)
     51    PRINTF_ATTRIBUTE(2, 3);
    4952
    5053#endif
  • uspace/app/bdsh/input.c

    rb5d2e57 r03362fbd  
    4141#include <errno.h>
    4242#include <assert.h>
    43 #include <bool.h>
     43#include <stdbool.h>
    4444#include <tinput.h>
    4545
     
    6767int process_input(cliuser_t *usr)
    6868{
    69         token_t *tokens = calloc(WORD_MAX, sizeof(token_t));
    70         if (tokens == NULL)
     69        token_t *tokens_buf = calloc(WORD_MAX, sizeof(token_t));
     70        if (tokens_buf == NULL)
    7171                return ENOMEM;
     72        token_t *tokens = tokens_buf;
    7273       
    7374        char *cmd[WORD_MAX];
     
    8081
    8182        if (usr->line == NULL) {
    82                 free(tokens);
     83                free(tokens_buf);
    8384                return CL_EFAIL;
    8485        }
     
    213214        }
    214215        tok_fini(&tok);
    215         free(tokens);
     216        free(tokens_buf);
    216217
    217218        return rc;
     
    268269        if (rc != EOK) {
    269270                /* Error in communication with console */
     271                cli_quit = 1;
    270272                return;
    271273        }
  • uspace/app/bithenge/Makefile

    rb5d2e57 r03362fbd  
    11#
    2 # Copyright (c) 2005 Martin Decky
    3 # Copyright (c) 2007 Jakub Jermar
     2# Copyright (c) 2012 Sean Bartell
    43# All rights reserved.
    54#
     
    2928
    3029USPACE_PREFIX = ../..
    31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBEXT2_PREFIX)/libext2.a
    32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBEXT2_PREFIX)
    33 BINARY = ext2info
     30LIBS = $(LIBBITHENGE_PREFIX)/libbithenge.a $(LIBBLOCK_PREFIX)/libblock.a
     31EXTRA_CFLAGS = -I$(LIBBITHENGE_PREFIX)/include -D__HELENOS__
     32BINARY = bithenge
    3433
    3534SOURCES = \
    36         ext2info.c
     35        test.c
    3736
    3837include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/blkdump/blkdump.c

    rb5d2e57 r03362fbd  
    4040#include <stdio.h>
    4141#include <stdlib.h>
    42 #include <libblock.h>
     42#include <block.h>
    4343#include <mem.h>
    4444#include <loc.h>
  • uspace/app/date/Makefile

    rb5d2e57 r03362fbd  
    11#
    2 # Copyright (c) 2011 Martin Decky
     2# Copyright (c) 2012 Maurizio Lombardi
    33# All rights reserved.
    44#
     
    2828
    2929USPACE_PREFIX = ../..
    30 LIBRARY = libfb
     30BINARY = date
    3131
    3232SOURCES = \
    33         fb.c \
    34         imgmap.c \
    35         screenbuffer.c
     33        date.c
    3634
    3735include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/devctl/devctl.c

    rb5d2e57 r03362fbd  
    151151        rc = devman_fun_offline(funh);
    152152        if (rc != EOK) {
    153                 printf(NAME ": Failed to offline function '%s'.\n", path);
     153                printf(NAME ": Failed to offline function '%s' (%s)\n", path,
     154                    str_error(rc));
    154155                return rc;
    155156        }
  • uspace/app/edit/Makefile

    rb5d2e57 r03362fbd  
    3333SOURCES = \
    3434        edit.c \
    35         sheet.c
     35        sheet.c \
     36        search.c
    3637
    3738include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/edit/edit.c

    rb5d2e57 r03362fbd  
    11/*
    22 * Copyright (c) 2009 Jiri Svoboda
     3 * Copyright (c) 2012 Martin Sucha
    34 * All rights reserved.
    45 *
     
    4647#include <macros.h>
    4748#include <clipboard.h>
    48 #include <bool.h>
     49#include <stdbool.h>
    4950
    5051#include "sheet.h"
     52#include "search.h"
    5153
    5254enum redraw_flags {
     
    8385         */
    8486        int ideal_column;
     87       
     88        char *previous_search;
     89        bool previous_search_reverse;
    8590} pane_t;
    8691
     
    9196typedef struct {
    9297        char *file_name;
    93         sheet_t sh;
     98        sheet_t *sh;
    9499} doc_t;
    95100
     
    106111#define BUF_SIZE 64
    107112#define TAB_WIDTH 8
    108 #define ED_INFTY 65536
    109113
    110114/** Maximum filename length that can be entered. */
     
    126130static int file_save_range(char const *fname, spt_t const *spos,
    127131    spt_t const *epos);
    128 static char *filename_prompt(char const *prompt, char const *init_value);
    129132static char *range_get_str(spt_t const *spos, spt_t const *epos);
     133
     134static char *prompt(char const *prompt, char const *init_value);
    130135
    131136static void pane_text_display(void);
     
    139144static void delete_char_after(void);
    140145static void caret_update(void);
    141 static void caret_move(int drow, int dcolumn, enum dir_spec align_dir);
    142 static void caret_move_word_left(void);
    143 static void caret_move_word_right(void);
     146static void caret_move_relative(int drow, int dcolumn, enum dir_spec align_dir, bool select);
     147static void caret_move_absolute(int row, int column, enum dir_spec align_dir, bool select);
     148static void caret_move(spt_t spt, bool select, bool update_ideal_column);
     149static void caret_move_word_left(bool select);
     150static void caret_move_word_right(bool select);
     151static void caret_go_to_line_ask(void);
    144152
    145153static bool selection_active(void);
    146154static void selection_sel_all(void);
    147155static void selection_sel_range(spt_t pa, spt_t pb);
    148 static void selection_sel_prev_word(void);
    149 static void selection_sel_next_word(void);
    150156static void selection_get_points(spt_t *pa, spt_t *pb);
    151157static void selection_delete(void);
    152158static void selection_copy(void);
    153159static void insert_clipboard_data(void);
     160
     161static void search(char *pattern, bool reverse);
     162static void search_prompt(bool reverse);
     163static void search_repeat(void);
    154164
    155165static void pt_get_sof(spt_t *pt);
     
    160170static bool pt_is_delimiter(spt_t *pt);
    161171static bool pt_is_punctuation(spt_t *pt);
     172static spt_t pt_find_word_left(spt_t spt);
     173static spt_t pt_find_word_left(spt_t spt);
     174
    162175static int tag_cmp(tag_t const *a, tag_t const *b);
    163176static int spt_cmp(spt_t const *a, spt_t const *b);
     
    170183{
    171184        kbd_event_t ev;
    172         coord_t coord;
    173185        bool new_file;
    174 
    175         spt_t pt;
     186        int rc;
    176187
    177188        con = console_init(stdin, stdout);
     
    186197
    187198        /* Start with an empty sheet. */
    188         sheet_init(&doc.sh);
     199        rc = sheet_create(&doc.sh);
     200        if (rc != EOK) {
     201                printf("Out of memory.\n");
     202                return -1;
     203        }
    189204
    190205        /* Place caret at the beginning of file. */
    191         coord.row = coord.column = 1;
    192         sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt);
    193         sheet_place_tag(&doc.sh, &pt, &pane.caret_pos);
    194         pane.ideal_column = coord.column;
     206        spt_t sof;
     207        pt_get_sof(&sof);
     208        sheet_place_tag(doc.sh, &sof, &pane.caret_pos);
     209        pane.ideal_column = 1;
    195210
    196211        if (argc == 2) {
     
    208223                new_file = true;
    209224
     225        /* Place selection start tag. */
     226        sheet_place_tag(doc.sh, &sof, &pane.sel_start);
     227
    210228        /* Move to beginning of file. */
    211         caret_move(-ED_INFTY, -ED_INFTY, dir_before);
    212 
    213         /* Place selection start tag. */
    214         tag_get_pt(&pane.caret_pos, &pt);
    215         sheet_place_tag(&doc.sh, &pt, &pane.sel_start);
     229        pt_get_sof(&sof);
     230        caret_move(sof, true, true);
    216231
    217232        /* Initial display */
     
    361376static void key_handle_ctrl(kbd_event_t const *ev)
    362377{
     378        spt_t pt;
    363379        switch (ev->key) {
    364380        case KC_Q:
     
    392408                selection_sel_all();
    393409                break;
    394         case KC_W:
    395                 if (selection_active())
    396                         break;
    397                 selection_sel_prev_word();
    398                 selection_delete();
    399                 break;
    400410        case KC_RIGHT:
    401                 caret_move_word_right();
     411                caret_move_word_right(false);
    402412                break;
    403413        case KC_LEFT:
    404                 caret_move_word_left();
     414                caret_move_word_left(false);
     415                break;
     416        case KC_L:
     417                caret_go_to_line_ask();
     418                break;
     419        case KC_F:
     420                search_prompt(false);
     421                break;
     422        case KC_N:
     423                search_repeat();
     424                break;
     425        case KC_HOME:
     426                pt_get_sof(&pt);
     427                caret_move(pt, false, true);
     428                break;
     429        case KC_END:
     430                pt_get_eof(&pt);
     431                caret_move(pt, false, true);
    405432                break;
    406433        default:
     
    411438static void key_handle_shift_ctrl(kbd_event_t const *ev)
    412439{
     440        spt_t pt;
    413441        switch(ev->key) {
    414442        case KC_LEFT:
    415                 selection_sel_prev_word();
     443                caret_move_word_left(true);
    416444                break;
    417445        case KC_RIGHT:
    418                 selection_sel_next_word();
     446                caret_move_word_right(true);
     447                break;
     448        case KC_F:
     449                search_prompt(true);
     450                break;
     451        case KC_HOME:
     452                pt_get_sof(&pt);
     453                caret_move(pt, true, true);
     454                break;
     455        case KC_END:
     456                pt_get_eof(&pt);
     457                caret_move(pt, true, true);
    419458                break;
    420459        default:
     
    423462}
    424463
    425 static void key_handle_movement(unsigned int key, bool select)
    426 {
    427         spt_t pt;
    428         spt_t caret_pt;
     464/** Move caret while preserving or resetting selection. */
     465static void caret_move(spt_t new_caret_pt, bool select, bool update_ideal_column)
     466{
     467        spt_t old_caret_pt, old_sel_pt;
    429468        coord_t c_old, c_new;
    430469        bool had_sel;
    431470
    432471        /* Check if we had selection before. */
    433         tag_get_pt(&pane.caret_pos, &caret_pt);
    434         tag_get_pt(&pane.sel_start, &pt);
    435         had_sel = !spt_equal(&caret_pt, &pt);
    436 
    437         switch (key) {
    438         case KC_LEFT:
    439                 caret_move(0, -1, dir_before);
    440                 break;
    441         case KC_RIGHT:
    442                 caret_move(0, 0, dir_after);
    443                 break;
    444         case KC_UP:
    445                 caret_move(-1, 0, dir_before);
    446                 break;
    447         case KC_DOWN:
    448                 caret_move(+1, 0, dir_before);
    449                 break;
    450         case KC_HOME:
    451                 caret_move(0, -ED_INFTY, dir_before);
    452                 break;
    453         case KC_END:
    454                 caret_move(0, +ED_INFTY, dir_before);
    455                 break;
    456         case KC_PAGE_UP:
    457                 caret_move(-pane.rows, 0, dir_before);
    458                 break;
    459         case KC_PAGE_DOWN:
    460                 caret_move(+pane.rows, 0, dir_before);
    461                 break;
    462         default:
    463                 break;
    464         }
     472        tag_get_pt(&pane.caret_pos, &old_caret_pt);
     473        tag_get_pt(&pane.sel_start, &old_sel_pt);
     474        had_sel = !spt_equal(&old_caret_pt, &old_sel_pt);
     475
     476        /* Place tag of the caret */
     477        sheet_remove_tag(doc.sh, &pane.caret_pos);
     478        sheet_place_tag(doc.sh, &new_caret_pt, &pane.caret_pos);
    465479
    466480        if (select == false) {
    467481                /* Move sel_start to the same point as caret. */
    468                 sheet_remove_tag(&doc.sh, &pane.sel_start);
    469                 tag_get_pt(&pane.caret_pos, &pt);
    470                 sheet_place_tag(&doc.sh, &pt, &pane.sel_start);
    471         }
    472 
     482                sheet_remove_tag(doc.sh, &pane.sel_start);
     483                sheet_place_tag(doc.sh, &new_caret_pt, &pane.sel_start);
     484        }
     485
     486        spt_get_coord(&new_caret_pt, &c_new);
    473487        if (select) {
    474                 tag_get_pt(&pane.caret_pos, &pt);
    475                 spt_get_coord(&caret_pt, &c_old);
    476                 spt_get_coord(&pt, &c_new);
     488                spt_get_coord(&old_caret_pt, &c_old);
    477489
    478490                if (c_old.row == c_new.row)
     
    485497                pane.rflags |= REDRAW_TEXT;
    486498        }
     499       
     500        if (update_ideal_column)
     501                pane.ideal_column = c_new.column;
     502       
     503        caret_update();
     504}
     505
     506static void key_handle_movement(unsigned int key, bool select)
     507{
     508        spt_t pt;
     509        switch (key) {
     510        case KC_LEFT:
     511                caret_move_relative(0, -1, dir_before, select);
     512                break;
     513        case KC_RIGHT:
     514                caret_move_relative(0, 0, dir_after, select);
     515                break;
     516        case KC_UP:
     517                caret_move_relative(-1, 0, dir_before, select);
     518                break;
     519        case KC_DOWN:
     520                caret_move_relative(+1, 0, dir_before, select);
     521                break;
     522        case KC_HOME:
     523                tag_get_pt(&pane.caret_pos, &pt);
     524                pt_get_sol(&pt, &pt);
     525                caret_move(pt, select, true);
     526                break;
     527        case KC_END:
     528                tag_get_pt(&pane.caret_pos, &pt);
     529                pt_get_eol(&pt, &pt);
     530                caret_move(pt, select, true);
     531                break;
     532        case KC_PAGE_UP:
     533                caret_move_relative(-pane.rows, 0, dir_before, select);
     534                break;
     535        case KC_PAGE_DOWN:
     536                caret_move_relative(+pane.rows, 0, dir_before, select);
     537                break;
     538        default:
     539                break;
     540        }
    487541}
    488542
     
    520574        char *fname;
    521575       
    522         fname = filename_prompt("Save As", old_fname);
     576        fname = prompt("Save As", old_fname);
    523577        if (fname == NULL) {
    524578                status_display("Save cancelled.");
     
    535589}
    536590
    537 /** Ask for a file name. */
    538 static char *filename_prompt(char const *prompt, char const *init_value)
     591/** Ask for a string. */
     592static char *prompt(char const *prompt, char const *init_value)
    539593{
    540594        kbd_event_t ev;
     
    657711
    658712        do {
    659                 sheet_copy_out(&doc.sh, &sp, epos, buf, BUF_SIZE, &bep);
     713                sheet_copy_out(doc.sh, &sp, epos, buf, BUF_SIZE, &bep);
    660714                bytes = str_size(buf);
    661715
     
    692746
    693747        while (true) {
    694                 sheet_copy_out(&doc.sh, &sp, epos, &buf[bpos], buf_size - bpos,
     748                sheet_copy_out(doc.sh, &sp, epos, &buf[bpos], buf_size - bpos,
    695749                    &bep);
    696750                bytes = str_size(&buf[bpos]);
     
    714768        int sh_rows, rows;
    715769
    716         sheet_get_num_rows(&doc.sh, &sh_rows);
     770        sheet_get_num_rows(doc.sh, &sh_rows);
    717771        rows = min(sh_rows - pane.sh_row + 1, pane.rows);
    718772
     
    784838                rbc.row = pane.sh_row + i;
    785839                rbc.column = pane.sh_column;
    786                 sheet_get_cell_pt(&doc.sh, &rbc, dir_before, &rb);
     840                sheet_get_cell_pt(doc.sh, &rbc, dir_before, &rb);
    787841
    788842                /* Ending point for row display */
    789843                rec.row = pane.sh_row + i;
    790844                rec.column = pane.sh_column + pane.columns;
    791                 sheet_get_cell_pt(&doc.sh, &rec, dir_before, &re);
     845                sheet_get_cell_pt(doc.sh, &rec, dir_before, &re);
    792846
    793847                /* Copy the text of the row to the buffer. */
    794                 sheet_copy_out(&doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep);
     848                sheet_copy_out(doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep);
    795849
    796850                /* Display text from the buffer. */
     
    842896                /* Fill until the end of display area. */
    843897
    844                 if (str_length(row_buf) < (unsigned) scr_columns)
    845                         fill = scr_columns - str_length(row_buf);
     898                if ((unsigned)s_column - 1 < scr_columns)
     899                        fill = scr_columns - (s_column - 1);
    846900                else
    847901                        fill = 0;
     
    861915        spt_t caret_pt;
    862916        coord_t coord;
     917        int last_row;
    863918
    864919        tag_get_pt(&pane.caret_pos, &caret_pt);
    865920        spt_get_coord(&caret_pt, &coord);
    866921
     922        sheet_get_num_rows(doc.sh, &last_row);
     923
    867924        const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>";
    868925
    869926        console_set_pos(con, 0, scr_rows - 1);
    870927        console_set_style(con, STYLE_INVERTED);
    871         int n = printf(" %d, %d: File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
    872             "Ctrl-E Save As", coord.row, coord.column, fname);
     928        int n = printf(" %d, %d (%d): File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
     929            "Ctrl-E Save As", coord.row, coord.column, last_row, fname);
    873930       
    874931        int pos = scr_columns - 1 - n;
     
    906963        cbuf[offs] = '\0';
    907964
    908         (void) sheet_insert(&doc.sh, &pt, dir_before, cbuf);
     965        (void) sheet_insert(doc.sh, &pt, dir_before, cbuf);
    909966
    910967        pane.rflags |= REDRAW_ROW;
     
    923980
    924981        coord.column -= 1;
    925         sheet_get_cell_pt(&doc.sh, &coord, dir_before, &sp);
    926 
    927         (void) sheet_delete(&doc.sh, &sp, &ep);
     982        sheet_get_cell_pt(doc.sh, &coord, dir_before, &sp);
     983
     984        (void) sheet_delete(doc.sh, &sp, &ep);
    928985
    929986        pane.rflags |= REDRAW_ROW;
     
    941998        spt_get_coord(&sp, &sc);
    942999
    943         sheet_get_cell_pt(&doc.sh, &sc, dir_after, &ep);
     1000        sheet_get_cell_pt(doc.sh, &sc, dir_after, &ep);
    9441001        spt_get_coord(&ep, &ec);
    9451002
    946         (void) sheet_delete(&doc.sh, &sp, &ep);
     1003        (void) sheet_delete(doc.sh, &sp, &ep);
    9471004
    9481005        pane.rflags |= REDRAW_ROW;
     
    9911048}
    9921049
    993 /** Change the caret position.
     1050/** Relatively move caret position.
    9941051 *
    9951052 * Moves caret relatively to the current position. Looking at the first
     
    9971054 * to a new character cell, and thus a new character. Then we either go to the
    9981055 * point before the the character or after it, depending on @a align_dir.
     1056 *
     1057 * @param select true if the selection tag should stay where it is
    9991058 */
    1000 static void caret_move(int drow, int dcolumn, enum dir_spec align_dir)
     1059static void caret_move_relative(int drow, int dcolumn, enum dir_spec align_dir,
     1060    bool select)
    10011061{
    10021062        spt_t pt;
     
    10161076                else {
    10171077                        coord.row--;
    1018                         sheet_get_row_width(&doc.sh, coord.row, &coord.column);
     1078                        sheet_get_row_width(doc.sh, coord.row, &coord.column);
    10191079                }
    10201080        }
    10211081        if (drow > 0) {
    1022                 sheet_get_num_rows(&doc.sh, &num_rows);
     1082                sheet_get_num_rows(doc.sh, &num_rows);
    10231083                if (coord.row > num_rows) coord.row = num_rows;
    10241084        }
     
    10331093         * coordinates. The character can be wider than one cell (e.g. tab).
    10341094         */
    1035         sheet_get_cell_pt(&doc.sh, &coord, align_dir, &pt);
    1036         sheet_remove_tag(&doc.sh, &pane.caret_pos);
    1037         sheet_place_tag(&doc.sh, &pt, &pane.caret_pos);
     1095        sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt);
    10381096
    10391097        /* For non-vertical movement set the new value for @c ideal_column. */
    1040         if (!pure_vertical) {
    1041                 spt_get_coord(&pt, &coord);
    1042                 pane.ideal_column = coord.column;
    1043         }
    1044 
    1045         caret_update();
    1046 }
    1047 
    1048 static void caret_move_word_left(void)
    1049 {
     1098        caret_move(pt, select, !pure_vertical);
     1099}
     1100
     1101/** Absolutely move caret position.
     1102 *
     1103 * Moves caret to a specified position. We get to a new character cell, and
     1104 * thus a new character. Then we either go to the point before the the character
     1105 * or after it, depending on @a align_dir.
     1106 *
     1107 * @param select true if the selection tag should stay where it is
     1108 */
     1109static void caret_move_absolute(int row, int column, enum dir_spec align_dir,
     1110    bool select)
     1111{
     1112        coord_t coord;
     1113        coord.row = row;
     1114        coord.column = column;
     1115       
    10501116        spt_t pt;
    1051 
     1117        sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt);
     1118       
     1119        caret_move(pt, select, true);
     1120}
     1121
     1122/** Find beginning of a word to the left of spt */
     1123static spt_t pt_find_word_left(spt_t spt)
     1124{
    10521125        do {
    1053                 caret_move(0, -1, dir_before);
    1054 
    1055                 tag_get_pt(&pane.caret_pos, &pt);
    1056 
    1057                 sheet_remove_tag(&doc.sh, &pane.sel_start);
    1058                 sheet_place_tag(&doc.sh, &pt, &pane.sel_start);
    1059         } while (!pt_is_word_beginning(&pt));
    1060 
    1061         pane.rflags |= REDRAW_TEXT;
    1062 }
    1063 
    1064 static void caret_move_word_right(void)
     1126                spt_prev_char(spt, &spt);
     1127        } while (!pt_is_word_beginning(&spt));
     1128        return spt;
     1129}
     1130
     1131/** Find beginning of a word to the right of spt */
     1132static spt_t pt_find_word_right(spt_t spt)
     1133{
     1134        do {
     1135                spt_next_char(spt, &spt);
     1136        } while (!pt_is_word_beginning(&spt));
     1137        return spt;
     1138}
     1139
     1140static void caret_move_word_left(bool select)
    10651141{
    10661142        spt_t pt;
    1067 
    1068         do {
    1069                 caret_move(0, 0, dir_after);
    1070 
    1071                 tag_get_pt(&pane.caret_pos, &pt);
    1072 
    1073                 sheet_remove_tag(&doc.sh, &pane.sel_start);
    1074                 sheet_place_tag(&doc.sh, &pt, &pane.sel_start);
    1075         } while (!pt_is_word_beginning(&pt));
    1076 
    1077         pane.rflags |= REDRAW_TEXT;
     1143        tag_get_pt(&pane.caret_pos, &pt);
     1144        spt_t word_left = pt_find_word_left(pt);
     1145        caret_move(word_left, select, true);
     1146}
     1147
     1148static void caret_move_word_right(bool select)
     1149{
     1150        spt_t pt;
     1151        tag_get_pt(&pane.caret_pos, &pt);
     1152        spt_t word_right = pt_find_word_right(pt);
     1153        caret_move(word_right, select, true);
     1154}
     1155
     1156/** Ask for line and go to it. */
     1157static void caret_go_to_line_ask(void)
     1158{
     1159        char *sline;
     1160       
     1161        sline = prompt("Go to line", "");
     1162        if (sline == NULL) {
     1163                status_display("Go to line cancelled.");
     1164                return;
     1165        }
     1166       
     1167        char *endptr;
     1168        int line = strtol(sline, &endptr, 10);
     1169        if (*endptr != '\0') {
     1170                free(sline);
     1171                status_display("Invalid number entered.");
     1172                return;
     1173        }
     1174        free(sline);
     1175       
     1176        caret_move_absolute(line, pane.ideal_column, dir_before, false);
     1177}
     1178
     1179/* Search operations */
     1180static int search_spt_producer(void *data, wchar_t *ret)
     1181{
     1182        assert(data != NULL);
     1183        assert(ret != NULL);
     1184        spt_t *spt = data;
     1185        *ret = spt_next_char(*spt, spt);
     1186        return EOK;
     1187}
     1188
     1189static int search_spt_reverse_producer(void *data, wchar_t *ret)
     1190{
     1191        assert(data != NULL);
     1192        assert(ret != NULL);
     1193        spt_t *spt = data;
     1194        *ret = spt_prev_char(*spt, spt);
     1195        return EOK;
     1196}
     1197
     1198static int search_spt_mark(void *data, void **mark)
     1199{
     1200        assert(data != NULL);
     1201        assert(mark != NULL);
     1202        spt_t *spt = data;
     1203        spt_t *new = calloc(1, sizeof(spt_t));
     1204        *mark = new;
     1205        if (new == NULL)
     1206                return ENOMEM;
     1207        *new = *spt;
     1208        return EOK;
     1209}
     1210
     1211static void search_spt_mark_free(void *data)
     1212{
     1213        free(data);
     1214}
     1215
     1216static search_ops_t search_spt_ops = {
     1217        .equals = char_exact_equals,
     1218        .producer = search_spt_producer,
     1219        .mark = search_spt_mark,
     1220        .mark_free = search_spt_mark_free,
     1221};
     1222
     1223static search_ops_t search_spt_reverse_ops = {
     1224        .equals = char_exact_equals,
     1225        .producer = search_spt_reverse_producer,
     1226        .mark = search_spt_mark,
     1227        .mark_free = search_spt_mark_free,
     1228};
     1229
     1230/** Ask for line and go to it. */
     1231static void search_prompt(bool reverse)
     1232{
     1233        char *pattern;
     1234       
     1235        const char *prompt_text = "Find next";
     1236        if (reverse)
     1237                prompt_text = "Find previous";
     1238       
     1239        const char *default_value = "";
     1240        if (pane.previous_search)
     1241                default_value = pane.previous_search;
     1242       
     1243        pattern = prompt(prompt_text, default_value);
     1244        if (pattern == NULL) {
     1245                status_display("Search cancelled.");
     1246                return;
     1247        }
     1248       
     1249        if (pane.previous_search)
     1250                free(pane.previous_search);
     1251        pane.previous_search = pattern;
     1252        pane.previous_search_reverse = reverse;
     1253       
     1254        search(pattern, reverse);
     1255}
     1256
     1257static void search_repeat(void)
     1258{
     1259        if (pane.previous_search == NULL) {
     1260                status_display("No previous search to repeat.");
     1261                return;
     1262        }
     1263       
     1264        search(pane.previous_search, pane.previous_search_reverse);
     1265}
     1266
     1267static void search(char *pattern, bool reverse)
     1268{
     1269        status_display("Searching...");
     1270       
     1271        spt_t sp, producer_pos;
     1272        tag_get_pt(&pane.caret_pos, &sp);
     1273       
     1274        /* Start searching on the position before/after caret */
     1275        if (!reverse) {
     1276                spt_next_char(sp, &sp);
     1277        }
     1278        else {
     1279                spt_prev_char(sp, &sp);
     1280        }
     1281        producer_pos = sp;
     1282       
     1283        search_ops_t ops = search_spt_ops;
     1284        if (reverse)
     1285                ops = search_spt_reverse_ops;
     1286       
     1287        search_t *search = search_init(pattern, &producer_pos, ops, reverse);
     1288        if (search == NULL) {
     1289                status_display("Failed initializing search.");
     1290                return;
     1291        }
     1292       
     1293        match_t match;
     1294        int rc = search_next_match(search, &match);
     1295        if (rc != EOK) {
     1296                status_display("Failed searching.");
     1297                search_fini(search);
     1298        }
     1299       
     1300        if (match.end) {
     1301                status_display("Match found.");
     1302                assert(match.end != NULL);
     1303                spt_t *end = match.end;
     1304                caret_move(*end, false, true);
     1305                while (match.length > 0) {
     1306                        match.length--;
     1307                        if (reverse) {
     1308                                spt_next_char(*end, end);
     1309                        }
     1310                        else {
     1311                                spt_prev_char(*end, end);
     1312                        }
     1313                }
     1314                caret_move(*end, true, true);
     1315                free(end);
     1316        }
     1317        else {
     1318                status_display("Not found.");
     1319        }
     1320       
     1321        search_fini(search);
    10781322}
    10791323
     
    11151359
    11161360        if (rel < 0)
    1117                 sheet_delete(&doc.sh, &pa, &pb);
     1361                sheet_delete(doc.sh, &pa, &pb);
    11181362        else
    1119                 sheet_delete(&doc.sh, &pb, &pa);
     1363                sheet_delete(doc.sh, &pb, &pa);
    11201364
    11211365        if (ca.row == cb.row)
     
    11391383static void selection_sel_range(spt_t pa, spt_t pb)
    11401384{
    1141         sheet_remove_tag(&doc.sh, &pane.sel_start);
    1142         sheet_place_tag(&doc.sh, &pa, &pane.sel_start);
    1143         sheet_remove_tag(&doc.sh, &pane.caret_pos);
    1144         sheet_place_tag(&doc.sh, &pb, &pane.caret_pos);
     1385        sheet_remove_tag(doc.sh, &pane.sel_start);
     1386        sheet_place_tag(doc.sh, &pa, &pane.sel_start);
     1387        sheet_remove_tag(doc.sh, &pane.caret_pos);
     1388        sheet_place_tag(doc.sh, &pb, &pane.caret_pos);
    11451389
    11461390        pane.rflags |= REDRAW_TEXT;
    11471391        caret_update();
    1148 }
    1149 
    1150 /** Add the previous word to the selection */
    1151 static void selection_sel_prev_word(void)
    1152 {
    1153         spt_t cpt, wpt, spt, ept;
    1154 
    1155         selection_get_points(&spt, &ept);
    1156 
    1157         tag_get_pt(&pane.caret_pos, &cpt);
    1158         caret_move_word_left();
    1159         tag_get_pt(&pane.caret_pos, &wpt);
    1160 
    1161         if (spt_cmp(&spt, &cpt) == 0)
    1162                 selection_sel_range(ept, wpt);
    1163         else
    1164                 selection_sel_range(spt, wpt);
    1165 }
    1166 
    1167 /** Add the next word to the selection */
    1168 static void selection_sel_next_word(void)
    1169 {
    1170         spt_t cpt, wpt, spt, ept;
    1171 
    1172         selection_get_points(&spt, &ept);
    1173 
    1174         tag_get_pt(&pane.caret_pos, &cpt);
    1175         caret_move_word_right();
    1176         tag_get_pt(&pane.caret_pos, &wpt);
    1177 
    1178         if (spt_cmp(&ept, &cpt) == 0)
    1179                 selection_sel_range(spt, wpt);
    1180         else
    1181                 selection_sel_range(ept, wpt);
    11821392}
    11831393
     
    12251435
    12261436        coord.row = coord.column = 1;
    1227         sheet_get_cell_pt(&doc.sh, &coord, dir_before, pt);
     1437        sheet_get_cell_pt(doc.sh, &coord, dir_before, pt);
    12281438}
    12291439
     
    12341444        int num_rows;
    12351445
    1236         sheet_get_num_rows(&doc.sh, &num_rows);
     1446        sheet_get_num_rows(doc.sh, &num_rows);
    12371447        coord.row = num_rows + 1;
    12381448        coord.column = 1;
    12391449
    1240         sheet_get_cell_pt(&doc.sh, &coord, dir_after, pt);
     1450        sheet_get_cell_pt(doc.sh, &coord, dir_after, pt);
    12411451}
    12421452
     
    12491459        coord.column = 1;
    12501460
    1251         sheet_get_cell_pt(&doc.sh, &coord, dir_before, spt);
     1461        sheet_get_cell_pt(doc.sh, &coord, dir_before, spt);
    12521462}
    12531463
     
    12591469
    12601470        spt_get_coord(cpt, &coord);
    1261         sheet_get_row_width(&doc.sh, coord.row, &row_width);
     1471        sheet_get_row_width(doc.sh, coord.row, &row_width);
    12621472        coord.column = row_width - 1;
    12631473
    1264         sheet_get_cell_pt(&doc.sh, &coord, dir_after, ept);
     1474        sheet_get_cell_pt(doc.sh, &coord, dir_after, ept);
    12651475}
    12661476
     
    12881498
    12891499        coord.column -= 1;
    1290         sheet_get_cell_pt(&doc.sh, &coord, dir_before, &lp);
     1500        sheet_get_cell_pt(doc.sh, &coord, dir_before, &lp);
    12911501
    12921502        return pt_is_delimiter(&lp)
     
    13101520
    13111521        coord.column += 1;
    1312         sheet_get_cell_pt(&doc.sh, &coord, dir_after, &rp);
     1522        sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp);
    13131523
    13141524        ch = range_get_str(pt, &rp);
     
    13361546
    13371547        coord.column += 1;
    1338         sheet_get_cell_pt(&doc.sh, &coord, dir_after, &rp);
     1548        sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp);
    13391549
    13401550        ch = range_get_str(pt, &rp);
  • uspace/app/edit/sheet.c

    rb5d2e57 r03362fbd  
    5757
    5858#include "sheet.h"
     59#include "sheet_impl.h"
    5960
    6061enum {
     
    6667
    6768/** Initialize an empty sheet. */
    68 int sheet_init(sheet_t *sh)
    69 {
     69int sheet_create(sheet_t **rsh)
     70{
     71        sheet_t *sh;
     72
     73        sh = calloc(1, sizeof(sheet_t));
     74        if (sh == NULL)
     75                return ENOMEM;
     76
    7077        sh->dbuf_size = INITIAL_SIZE;
    7178        sh->text_size = 0;
     
    7784        list_initialize(&sh->tags);
    7885
     86        *rsh = sh;
    7987        return EOK;
    8088}
     
    315323}
    316324
     325/** Get a character at spt and return next spt */
     326wchar_t spt_next_char(spt_t spt, spt_t *next)
     327{
     328        wchar_t ch = str_decode(spt.sh->data, &spt.b_off, spt.sh->text_size);
     329        if (next)
     330                *next = spt;
     331        return ch;
     332}
     333
     334wchar_t spt_prev_char(spt_t spt, spt_t *prev)
     335{
     336        wchar_t ch = str_decode_reverse(spt.sh->data, &spt.b_off, spt.sh->text_size);
     337        if (prev)
     338                *prev = spt;
     339        return ch;
     340}
     341
    317342/** Place a tag on the specified s-point. */
    318343void sheet_place_tag(sheet_t *sh, spt_t const *pt, tag_t *tag)
  • uspace/app/edit/sheet.h

    rb5d2e57 r03362fbd  
    3939#include <adt/list.h>
    4040#include <sys/types.h>
    41 #include <bool.h>
     41#include <stdbool.h>
    4242
    4343/** Direction (in linear space) */
     
    5050
    5151/** Sheet */
    52 typedef struct {
    53         /* Note: This structure is opaque for the user. */
    54 
    55         size_t text_size;
    56         size_t dbuf_size;
    57         char *data;
    58 
    59         list_t tags;
    60 } sheet_t;
     52struct sheet;
     53typedef struct sheet sheet_t;
    6154
    6255/** Character cell coordinates
     
    9790} tag_t;
    9891
    99 extern int sheet_init(sheet_t *);
     92extern int sheet_create(sheet_t **);
    10093extern int sheet_insert(sheet_t *, spt_t *, enum dir_spec, char *);
    10194extern int sheet_delete(sheet_t *, spt_t *, spt_t *);
     
    108101extern void spt_get_coord(spt_t const *, coord_t *);
    109102extern bool spt_equal(spt_t const *, spt_t const *);
     103extern wchar_t spt_next_char(spt_t, spt_t *);
     104extern wchar_t spt_prev_char(spt_t, spt_t *);
    110105
    111106extern void sheet_place_tag(sheet_t *, spt_t const *, tag_t *);
  • uspace/app/init/init.c

    rb5d2e57 r03362fbd  
    3737#include <stdio.h>
    3838#include <unistd.h>
     39#include <stdarg.h>
    3940#include <vfs/vfs.h>
    40 #include <bool.h>
     41#include <stdbool.h>
    4142#include <errno.h>
    4243#include <fcntl.h>
     
    6566#define SRV_CONSOLE  "/srv/console"
    6667#define APP_GETTERM  "/app/getterm"
     68
     69#define SRV_COMPOSITOR  "/srv/compositor"
     70
     71#define HID_INPUT              "hid/input"
     72#define HID_OUTPUT             "hid/output"
     73#define HID_COMPOSITOR_SERVER  ":0"
     74
     75#define srv_start(path, ...) \
     76        srv_startl(path, path, ##__VA_ARGS__, NULL)
    6777
    6878/** Print banner */
     
    143153}
    144154
    145 static void spawn(const char *fname)
    146 {
    147         int rc;
     155static int srv_startl(const char *path, ...)
     156{
    148157        struct stat s;
    149        
    150         if (stat(fname, &s) == ENOENT)
    151                 return;
    152        
    153         printf("%s: Spawning %s\n", NAME, fname);
    154         rc = task_spawnl(NULL, fname, fname, NULL);
    155         if (rc != EOK) {
    156                 printf("%s: Error spawning %s (%s)\n", NAME, fname,
    157                     str_error(rc));
    158         }
    159 }
    160 
    161 static void srv_start(const char *fname)
    162 {
     158        if (stat(path, &s) == ENOENT) {
     159                printf("%s: Unable to stat %s\n", NAME, path);
     160                return ENOENT;
     161        }
     162       
     163        printf("%s: Starting %s\n", NAME, path);
     164       
     165        va_list ap;
     166        const char *arg;
     167        int cnt = 0;
     168       
     169        va_start(ap, path);
     170        do {
     171                arg = va_arg(ap, const char *);
     172                cnt++;
     173        } while (arg != NULL);
     174        va_end(ap);
     175       
     176        va_start(ap, path);
    163177        task_id_t id;
     178        int rc = task_spawn(&id, path, cnt, ap);
     179        va_end(ap);
     180       
     181        if (rc != EOK) {
     182                printf("%s: Error spawning %s (%s)\n", NAME, path,
     183                    str_error(rc));
     184                return rc;
     185        }
     186       
     187        if (!id) {
     188                printf("%s: Error spawning %s (invalid task id)\n", NAME,
     189                    path);
     190                return EINVAL;
     191        }
     192       
    164193        task_exit_t texit;
    165         int rc, retval;
    166         struct stat s;
    167        
    168         if (stat(fname, &s) == ENOENT)
    169                 return;
    170        
    171         printf("%s: Starting %s\n", NAME, fname);
    172         rc = task_spawnl(&id, fname, fname, NULL);
    173         if (!id) {
    174                 printf("%s: Error spawning %s (%s)\n", NAME, fname,
    175                     str_error(rc));
    176                 return;
    177         }
    178        
     194        int retval;
    179195        rc = task_wait(id, &texit, &retval);
    180196        if (rc != EOK) {
    181                 printf("%s: Error waiting for %s (%s)\n", NAME, fname,
    182                     str_error(rc));
    183                 return;
     197                printf("%s: Error waiting for %s (%s)\n", NAME, path,
     198                    str_error(rc));
     199                return rc;
    184200        }
    185201       
    186202        if (texit != TASK_EXIT_NORMAL) {
    187203                printf("%s: Server %s failed to start (unexpectedly "
    188                     "terminated)\n", NAME, fname);
    189                 return;
    190         }
    191 
    192         if (retval != 0) {
     204                    "terminated)\n", NAME, path);
     205                return EINVAL;
     206        }
     207       
     208        if (retval != 0)
    193209                printf("%s: Server %s failed to start (exit code %d)\n", NAME,
    194                         fname, retval);
    195         }
    196 }
    197 
    198 static void console(const char *isvc, const char *fbsvc)
    199 {
    200         printf("%s: Spawning %s %s %s\n", NAME, SRV_CONSOLE, isvc, fbsvc);
    201        
     210                    path, retval);
     211       
     212        return retval;
     213}
     214
     215static int console(const char *isvc, const char *osvc)
     216{
    202217        /* Wait for the input service to be ready */
    203218        service_id_t service_id;
     
    206221                printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
    207222                    str_error(rc));
    208                 return;
    209         }
    210        
    211         /* Wait for the framebuffer service to be ready */
    212         rc = loc_service_get_id(fbsvc, &service_id, IPC_FLAG_BLOCKING);
    213         if (rc != EOK) {
    214                 printf("%s: Error waiting on %s (%s)\n", NAME, fbsvc,
    215                     str_error(rc));
    216                 return;
    217         }
    218        
    219         rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, isvc, fbsvc, NULL);
    220         if (rc != EOK) {
    221                 printf("%s: Error spawning %s %s %s (%s)\n", NAME, SRV_CONSOLE,
    222                     isvc, fbsvc, str_error(rc));
    223         }
     223                return rc;
     224        }
     225       
     226        /* Wait for the output service to be ready */
     227        rc = loc_service_get_id(osvc, &service_id, IPC_FLAG_BLOCKING);
     228        if (rc != EOK) {
     229                printf("%s: Error waiting on %s (%s)\n", NAME, osvc,
     230                    str_error(rc));
     231                return rc;
     232        }
     233       
     234        return srv_start(SRV_CONSOLE, isvc, osvc);
     235}
     236
     237static int compositor(const char *isvc, const char *name)
     238{
     239        /* Wait for the input service to be ready */
     240        service_id_t service_id;
     241        int rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING);
     242        if (rc != EOK) {
     243                printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
     244                    str_error(rc));
     245                return rc;
     246        }
     247       
     248        return srv_start(SRV_COMPOSITOR, isvc, name);
     249}
     250
     251static int gui_start(const char *app, const char *srv_name)
     252{
     253        char winreg[50];
     254        snprintf(winreg, sizeof(winreg), "%s%s%s", "comp", srv_name, "/winreg");
     255       
     256        printf("%s: Spawning %s %s\n", NAME, app, winreg);
     257       
     258        task_id_t id;
     259        int rc = task_spawnl(&id, app, app, winreg, NULL);
     260        if (rc != EOK) {
     261                printf("%s: Error spawning %s %s (%s)\n", NAME, app,
     262                    winreg, str_error(rc));
     263                return -1;
     264        }
     265       
     266        task_exit_t texit;
     267        int retval;
     268        rc = task_wait(id, &texit, &retval);
     269        if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
     270                printf("%s: Error retrieving retval from %s (%s)\n", NAME,
     271                    app, str_error(rc));
     272                return -1;
     273        }
     274       
     275        return retval;
    224276}
    225277
     
    227279{
    228280        char term[LOC_NAME_MAXLEN];
    229         int rc;
    230        
    231281        snprintf(term, LOC_NAME_MAXLEN, "%s/%s", LOCFS_MOUNT_POINT, svc);
    232282       
     
    235285        /* Wait for the terminal service to be ready */
    236286        service_id_t service_id;
    237         rc = loc_service_get_id(svc, &service_id, IPC_FLAG_BLOCKING);
     287        int rc = loc_service_get_id(svc, &service_id, IPC_FLAG_BLOCKING);
    238288        if (rc != EOK) {
    239289                printf("%s: Error waiting on %s (%s)\n", NAME, term,
     
    279329        if (!mount_root(STRING(RDFMT))) {
    280330                printf("%s: Exiting\n", NAME);
    281                 return -1;
     331                return 1;
    282332        }
    283333       
    284334        /* Make sure tmpfs is running. */
    285         if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
    286                 spawn("/srv/tmpfs");
    287         }
    288        
    289         spawn("/srv/locfs");
    290         spawn("/srv/taskmon");
     335        if (str_cmp(STRING(RDFMT), "tmpfs") != 0)
     336                srv_start("/srv/tmpfs");
     337       
     338        srv_start("/srv/locfs");
     339        srv_start("/srv/taskmon");
    291340       
    292341        if (!mount_locfs()) {
    293342                printf("%s: Exiting\n", NAME);
    294                 return -2;
     343                return 2;
    295344        }
    296345       
    297346        mount_tmpfs();
    298347       
    299         spawn("/srv/devman");
    300         spawn("/srv/apic");
    301         spawn("/srv/i8259");
    302         spawn("/srv/obio");
     348        srv_start("/srv/devman");
     349        srv_start("/srv/apic");
     350        srv_start("/srv/i8259");
     351        srv_start("/srv/obio");
    303352        srv_start("/srv/cuda_adb");
    304353        srv_start("/srv/s3c24xx_uart");
    305354        srv_start("/srv/s3c24xx_ts");
    306355       
    307         spawn("/srv/loopip");
    308         spawn("/srv/ethip");
    309         spawn("/srv/inetsrv");
    310         spawn("/srv/tcp");
    311         spawn("/srv/udp");
    312        
    313         spawn("/srv/fb");
    314         spawn("/srv/input");
    315         console("hid/input", "hid/fb0");
    316        
    317         spawn("/srv/clipboard");
    318         spawn("/srv/remcons");
     356        srv_start("/srv/loopip");
     357        srv_start("/srv/ethip");
     358        srv_start("/srv/inetsrv");
     359        srv_start("/srv/tcp");
     360        srv_start("/srv/udp");
     361       
     362        srv_start("/srv/clipboard");
     363        srv_start("/srv/remcons");
    319364       
    320365        /*
     
    325370        srv_start("/srv/ata_bd");
    326371        srv_start("/srv/gxe_bd");
    327 #else
    328         (void) srv_start;
    329372#endif
    330373       
    331374#ifdef CONFIG_MOUNT_DATA
    332375        /* Make sure fat is running. */
    333         if (str_cmp(STRING(RDFMT), "fat") != 0) {
     376        if (str_cmp(STRING(RDFMT), "fat") != 0)
    334377                srv_start("/srv/fat");
    335         }
     378       
    336379        mount_data();
    337380#else
     
    339382#endif
    340383       
    341         spawn("/srv/hound");
    342         switch((unsigned)CONFIG_VC_COUNT) {
    343         default:
    344         case 6: getterm("term/vc5", "/app/bdsh", false);
    345         case 5: getterm("term/vc4", "/app/bdsh", false);
    346         case 4: getterm("term/vc3", "/app/bdsh", false);
    347         case 3: getterm("term/vc2", "/app/bdsh", false);
    348         case 2: getterm("term/vc1", "/app/bdsh", false);
    349         case 1: getterm("term/vc0", "/app/bdsh", true);
    350         }
     384        srv_start("/srv/hound");
     385        srv_start("/srv/input", HID_INPUT);
     386        srv_start("/srv/output", HID_OUTPUT);
     387       
     388        int rc = compositor(HID_INPUT, HID_COMPOSITOR_SERVER);
     389        if (rc == EOK) {
     390                gui_start("/app/vlaunch", HID_COMPOSITOR_SERVER);
     391                gui_start("/app/vterm", HID_COMPOSITOR_SERVER);
     392        } else {
     393                rc = console(HID_INPUT, HID_OUTPUT);
     394                if (rc == EOK) {
     395                        switch((unsigned)CONFIG_VC_COUNT) {
     396                        default:
     397                        case 6: getterm("term/vc5", "/app/bdsh", false);
     398                        case 5: getterm("term/vc4", "/app/bdsh", false);
     399                        case 4: getterm("term/vc3", "/app/bdsh", false);
     400                        case 3: getterm("term/vc2", "/app/bdsh", false);
     401                        case 2: getterm("term/vc1", "/app/bdsh", false);
     402                        case 1: getterm("term/vc0", "/app/bdsh", true);
     403                        }
    351404#ifdef CONFIG_KERNEL_LOG_VC_6
    352         getterm("term/vc6", "/app/klog", false);
     405                        getterm("term/vc6", "/app/klog", false);
    353406#endif
     407                }
     408        }
    354409       
    355410        return 0;
  • uspace/app/klog/Makefile

    rb5d2e57 r03362fbd  
    2929
    3030USPACE_PREFIX = ../..
     31LIBS = $(LIBCLUI_PREFIX)/libclui.a
     32EXTRA_CFLAGS = -I$(LIBCLUI_PREFIX)
    3133BINARY = klog
    3234
  • uspace/app/klog/klog.c

    rb5d2e57 r03362fbd  
    4848#include <adt/list.h>
    4949#include <adt/prodcons.h>
     50#include <tinput.h>
    5051
    5152#define NAME       "klog"
     
    228229        }
    229230       
     231        tinput_t *input = tinput_new();
     232        if (!input) {
     233                fprintf(stderr, "%s: Could not create input\n", NAME);
     234                return ENOMEM;
     235        }       
     236
    230237        fibril_add_ready(fid);
    231238        event_unmask(EVENT_KLOG);
    232239        klog_update();
    233240       
    234         task_retval(0);
    235         async_manager();
    236        
    237         return 0;
     241        tinput_set_prompt(input, "klog> ");
     242
     243        char *str;
     244        while ((rc = tinput_read(input, &str)) == EOK) {
     245                if (str_cmp(str, "") == 0) {
     246                        free(str);
     247                        continue;
     248                }
     249
     250                klog_command(str, str_size(str));
     251                free(str);
     252        }
     253 
     254        if (rc == ENOENT)
     255                rc = EOK;       
     256
     257        return EOK;
    238258}
    239259
  • uspace/app/logset/Makefile

    rb5d2e57 r03362fbd  
    11#
    2 # Copyright (c) 2011 Vojtech Horky
     2# Copyright (c) 2012 Vojtech Horky
    33# All rights reserved.
    44#
     
    2828
    2929USPACE_PREFIX = ../..
    30 BINARY = lsusb
    31 
    32 LIBS = \
    33         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    34         $(LIBUSB_PREFIX)/libusb.a \
    35         $(LIBDRV_PREFIX)/libdrv.a
    36 EXTRA_CFLAGS = \
    37         -I$(LIBUSB_PREFIX)/include \
    38         -I$(LIBUSBDEV_PREFIX)/include \
    39         -I$(LIBDRV_PREFIX)/include
     30BINARY = logset
    4031
    4132SOURCES = \
  • uspace/app/mkbd/main.c

    rb5d2e57 r03362fbd  
    4040#include <errno.h>
    4141#include <str_error.h>
    42 #include <bool.h>
     42#include <stdbool.h>
    4343#include <getopt.h>
    4444#include <devman.h>
  • uspace/app/mkexfat/exfat.h

    rb5d2e57 r03362fbd  
    3434#include <sys/types.h>
    3535#include <stdint.h>
    36 #include <bool.h>
     36#include <stdbool.h>
    3737
    3838#define EXFAT_FILENAME_LEN      255
  • uspace/app/mkexfat/mkexfat.c

    rb5d2e57 r03362fbd  
    3838
    3939#include <stdio.h>
    40 #include <libblock.h>
     40#include <block.h>
    4141#include <assert.h>
    4242#include <errno.h>
     
    4646#include <sys/types.h>
    4747#include <sys/typefmt.h>
    48 #include <bool.h>
     48#include <stdbool.h>
    4949#include <str.h>
    5050#include <getopt.h>
     51#include <macros.h>
    5152#include "exfat.h"
    5253#include "upcase.h"
     
    8788#define FIRST_FREE_CLUSTER   2
    8889
    89 #define min(x, y) ((x) < (y) ? (x) : (y))
    9090
    9191typedef struct exfat_cfg {
  • uspace/app/mkfat/mkfat.c

    rb5d2e57 r03362fbd  
    4040#include <stdio.h>
    4141#include <stdlib.h>
    42 #include <libblock.h>
     42#include <block.h>
    4343#include <mem.h>
    4444#include <loc.h>
  • uspace/app/mkmfs/mkmfs.c

    rb5d2e57 r03362fbd  
    3939#include <stdio.h>
    4040#include <stdlib.h>
    41 #include <libblock.h>
     41#include <block.h>
    4242#include <unistd.h>
    4343#include <errno.h>
  • uspace/app/msim/arch_helenos/input.c

    rb5d2e57 r03362fbd  
    3232/** @file HelenOS specific functions for MSIM simulator.
    3333 */
     34
     35/* Because of asprintf. */
     36#define _GNU_SOURCE
    3437#include "../../io/input.h"
    3538#include "../../io/output.h"
     
    3841#include <tinput.h>
    3942#include <errno.h>
     43#include <stdlib.h>
    4044
    4145static tinput_t *input_prompt;
  • uspace/app/msim/arch_helenos/misc.c

    rb5d2e57 r03362fbd  
    4444#include <ctype.h>
    4545#include <stdio.h>
     46#include <stdlib.h>
    4647
    4748/* Define when the dprinter device shall try to filter
  • uspace/app/nettest2/nettest2.c

    rb5d2e57 r03362fbd  
    4545#include <time.h>
    4646#include <arg_parse.h>
    47 #include <bool.h>
     47#include <stdbool.h>
    4848
    4949#include <net/in.h>
  • uspace/app/nterm/conn.c

    rb5d2e57 r03362fbd  
    3333 */
    3434
    35 #include <bool.h>
     35#include <stdbool.h>
    3636#include <errno.h>
    3737#include <fibril.h>
  • uspace/app/nterm/nterm.c

    rb5d2e57 r03362fbd  
    3333 */
    3434
    35 #include <bool.h>
     35#include <stdbool.h>
    3636#include <errno.h>
    3737#include <io/console.h>
  • uspace/app/ping/ping.c

    rb5d2e57 r03362fbd  
    3434
    3535#include <async.h>
    36 #include <bool.h>
     36#include <stdbool.h>
    3737#include <errno.h>
    3838#include <fibril_synch.h>
  • uspace/app/sportdmp/sportdmp.c

    rb5d2e57 r03362fbd  
    3737static void syntax_print(void)
    3838{
    39         fprintf(stderr, "Usage: sportdmp <baud> <device_service>\n");
     39        fprintf(stderr, "Usage: sportdmp [--baud=<baud>] [device_service]\n");
    4040}
    4141
    4242int main(int argc, char **argv)
    4343{
    44         const char* svc_path = "devices/\\hw\\pci0\\00:01.0\\com1\\a";
    4544        sysarg_t baud = 9600;
     45        service_id_t svc_id;
    4646       
    47         if (argc > 1) {
     47        int arg = 1;
     48        int rc;
     49               
     50        if (argc > arg && str_test_prefix(argv[arg], "--baud=")) {
     51                size_t arg_offset = str_lsize(argv[arg], 7);
     52                char* arg_str = argv[arg] + arg_offset;
     53                if (str_length(arg_str) == 0) {
     54                        fprintf(stderr, "--baud requires an argument\n");
     55                        syntax_print();
     56                        return 1;
     57                }
    4858                char *endptr;
    49                 baud = strtol(argv[1], &endptr, 10);
     59                baud = strtol(arg_str, &endptr, 10);
    5060                if (*endptr != '\0') {
    5161                        fprintf(stderr, "Invalid value for baud\n");
     
    5363                        return 1;
    5464                }
     65                arg++;
    5566        }
    5667       
    57         if (argc > 2) {
    58                 svc_path = argv[2];
     68        if (argc > arg) {
     69                rc = loc_service_get_id(argv[arg], &svc_id, 0);
     70                if (rc != EOK) {
     71                        fprintf(stderr, "Cannot find device service %s\n",
     72                            argv[arg]);
     73                        return 1;
     74                }
     75                arg++;
     76        }
     77        else {
     78                category_id_t serial_cat_id;
     79               
     80                rc = loc_category_get_id("serial", &serial_cat_id, 0);
     81                if (rc != EOK) {
     82                        fprintf(stderr, "Failed getting id of category "
     83                            "'serial'\n");
     84                        return 1;
     85                }
     86               
     87                service_id_t *svc_ids;
     88                size_t svc_count;
     89               
     90                rc = loc_category_get_svcs(serial_cat_id, &svc_ids, &svc_count);                if (rc != EOK) {
     91                        fprintf(stderr, "Failed getting list of services\n");
     92                        return 1;
     93                }
     94               
     95                if (svc_count == 0) {
     96                        fprintf(stderr, "No service in category 'serial'\n");
     97                        free(svc_ids);
     98                        return 1;
     99                }
     100               
     101                svc_id = svc_ids[0];
     102                free(svc_ids);
    59103        }
    60104       
    61         if (argc > 3) {
     105        if (argc > arg) {
     106                fprintf(stderr, "Too many arguments\n");
    62107                syntax_print();
    63108                return 1;
    64109        }
    65110       
    66         service_id_t svc_id;
    67         int rc = loc_service_get_id(svc_path, &svc_id, IPC_FLAG_BLOCKING);
    68         if (rc != EOK) {
    69                 fprintf(stderr, "Cannot find device service %s\n", svc_path);
    70                 return 1;
    71         }
    72111       
    73112        async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE, svc_id,
    74113            IPC_FLAG_BLOCKING);
    75114        if (!sess) {
    76                 fprintf(stderr, "Failed connecting to service %s\n", svc_path);
     115                fprintf(stderr, "Failed connecting to service\n");
    77116        }
    78117       
     
    101140                ssize_t i;
    102141                for (i = 0; i < read; i++) {
    103                         if ((buf[i] >= 32) && (buf[i] < 128))
    104                                 putchar((wchar_t) buf[i]);
    105                         else
    106                                 putchar('.');
    107                         fflush(stdout);
     142                        printf("%02hhx ", buf[i]);
    108143                }
     144                fflush(stdout);
    109145        }
    110146       
  • uspace/app/stats/stats.c

    rb5d2e57 r03362fbd  
    4444#include <malloc.h>
    4545#include <inttypes.h>
    46 #include <bool.h>
     46#include <stdbool.h>
    4747#include <str.h>
    4848#include <arg_parse.h>
  • uspace/app/taskdump/taskdump.c

    rb5d2e57 r03362fbd  
    4747#include <macros.h>
    4848#include <assert.h>
    49 #include <bool.h>
     49#include <stdbool.h>
    5050
    5151#include <symtab.h>
  • uspace/app/tester/Makefile

    rb5d2e57 r03362fbd  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBEXT2_PREFIX)/libext2.a $(LIBBLOCK_PREFIX)/libblock.a
    32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBEXT2_PREFIX)
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
     32EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBSOFTFLOAT_PREFIX)
    3333BINARY = tester
    3434
     
    4242        print/print4.c \
    4343        print/print5.c \
     44        print/print6.c \
    4445        console/console1.c \
    4546        stdio/stdio1.c \
    4647        stdio/stdio2.c \
     48        stdio/logger1.c \
     49        stdio/logger2.c \
    4750        fault/fault1.c \
    4851        fault/fault2.c \
    4952        fault/fault3.c \
     53        float/float1.c \
     54        float/softfloat1.c \
    5055        vfs/vfs1.c \
    5156        ipc/ping_pong.c \
     
    5863        mm/mapping1.c \
    5964        hw/misc/virtchar1.c \
    60         hw/serial/serial1.c \
    61         libext2/libext2_1.c
     65        hw/serial/serial1.c
    6266
    6367include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/tester/mm/common.c

    rb5d2e57 r03362fbd  
    343343       
    344344        area->addr = as_area_create(AS_AREA_ANY, size,
    345             AS_AREA_WRITE | AS_AREA_READ);
     345            AS_AREA_WRITE | AS_AREA_READ | AS_AREA_CACHEABLE);
    346346        if (area->addr == AS_MAP_FAILED) {
    347347                free(area);
  • uspace/app/tester/mm/common.h

    rb5d2e57 r03362fbd  
    3737
    3838#include <sys/types.h>
    39 #include <bool.h>
     39#include <stdbool.h>
    4040#include <adt/list.h>
    4141
  • uspace/app/tester/mm/mapping1.c

    rb5d2e57 r03362fbd  
    4343       
    4444        void *result = as_area_create(AS_AREA_ANY, size,
    45             AS_AREA_READ | AS_AREA_WRITE);
     45            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
    4646        if (result == AS_MAP_FAILED)
    4747                return NULL;
  • uspace/app/tester/print/print5.def

    rb5d2e57 r03362fbd  
    11{
    2         "print1",
    3         "String printf test",
    4         &test_print1,
     2        "print5",
     3        "Char printf test",
     4        &test_print5,
    55        true
    66},
  • uspace/app/tester/tester.c

    rb5d2e57 r03362fbd  
    3939#include <stdio.h>
    4040#include <str.h>
     41#include <io/log.h>
    4142#include "tester.h"
    4243
     
    5253#include "print/print4.def"
    5354#include "print/print5.def"
     55#include "print/print6.def"
    5456#include "console/console1.def"
    5557#include "stdio/stdio1.def"
    5658#include "stdio/stdio2.def"
     59#include "stdio/logger1.def"
     60#include "stdio/logger2.def"
    5761#include "fault/fault1.def"
    5862#include "fault/fault2.def"
    5963#include "fault/fault3.def"
     64#include "float/float1.def"
     65#include "float/softfloat1.def"
    6066#include "vfs/vfs1.def"
    6167#include "ipc/ping_pong.def"
     
    6874#include "hw/serial/serial1.def"
    6975#include "hw/misc/virtchar1.def"
    70 #include "libext2/libext2_1.def"
    7176        {NULL, NULL, NULL, false}
    7277};
     
    138143        }
    139144       
     145        log_init("tester");
     146
    140147        test_quiet = false;
    141148        test_argc = argc - 2;
  • uspace/app/tester/tester.h

    rb5d2e57 r03362fbd  
    3737
    3838#include <sys/types.h>
    39 #include <bool.h>
     39#include <stdbool.h>
    4040#include <stacktrace.h>
    4141
     
    8585extern const char *test_print4(void);
    8686extern const char *test_print5(void);
     87extern const char *test_print6(void);
    8788extern const char *test_console1(void);
    8889extern const char *test_stdio1(void);
    8990extern const char *test_stdio2(void);
     91extern const char *test_logger1(void);
     92extern const char *test_logger2(void);
    9093extern const char *test_fault1(void);
    9194extern const char *test_fault2(void);
    9295extern const char *test_fault3(void);
     96extern const char *test_float1(void);
     97extern const char *test_softfloat1(void);
    9398extern const char *test_vfs1(void);
    9499extern const char *test_ping_pong(void);
     
    101106extern const char *test_serial1(void);
    102107extern const char *test_virtchar1(void);
    103 extern const char *test_libext2_1(void);
    104108extern const char *test_devman1(void);
    105109extern const char *test_devman2(void);
  • uspace/app/tetris/screen.c

    rb5d2e57 r03362fbd  
    6161#include <vfs/vfs.h>
    6262#include <async.h>
    63 #include <bool.h>
     63#include <stdbool.h>
    6464#include <io/console.h>
    6565#include <io/style.h>
  • uspace/app/tetris/screen.h

    rb5d2e57 r03362fbd  
    5858#include <io/console.h>
    5959#include <async.h>
    60 #include <bool.h>
     60#include <stdbool.h>
    6161
    6262typedef struct {
  • uspace/app/top/screen.h

    rb5d2e57 r03362fbd  
    3636
    3737#include <io/console.h>
     38#include <io/verify.h>
    3839#include "top.h"
    3940
     
    4344extern void screen_done(void);
    4445extern void print_data(data_t *);
    45 extern void show_warning(const char *, ...);
     46extern void show_warning(const char *, ...)
     47    PRINTF_ATTRIBUTE(1, 2);
    4648
    4749extern int tgetchar(unsigned int);
  • uspace/app/trace/ipcp.c

    rb5d2e57 r03362fbd  
    3838#include <sys/typefmt.h>
    3939#include <abi/ipc/methods.h>
     40#include <macros.h>
    4041#include "ipc_desc.h"
    4142#include "proto.h"
     
    5253        ipc_callid_t call_hash;
    5354
    54         link_t link;
     55        ht_link_t link;
    5556} pending_call_t;
    5657
     
    6465int have_conn[MAX_PHONE];
    6566
    66 #define PCALL_TABLE_CHAINS 32
    67 hash_table_t pending_calls;
     67static hash_table_t pending_calls;
    6868
    6969/*
     
    7373proto_t *proto_unknown;         /**< Protocol with no known methods. */
    7474
    75 static hash_index_t pending_call_hash(unsigned long key[]);
    76 static int pending_call_compare(unsigned long key[], hash_count_t keys,
    77     link_t *item);
    78 static void pending_call_remove_callback(link_t *item);
    79 
    80 hash_table_operations_t pending_call_ops = {
     75
     76static size_t pending_call_key_hash(void *key)
     77{
     78        ipc_callid_t *call_id = (ipc_callid_t *)key;
     79        return *call_id;
     80}
     81
     82static size_t pending_call_hash(const ht_link_t *item)
     83{
     84        pending_call_t *hs = hash_table_get_inst(item, pending_call_t, link);
     85        return hs->call_hash;
     86}
     87
     88static bool pending_call_key_equal(void *key, const ht_link_t *item)
     89{
     90        ipc_callid_t *call_id = (ipc_callid_t *)key;
     91        pending_call_t *hs = hash_table_get_inst(item, pending_call_t, link);
     92
     93        return *call_id == hs->call_hash;
     94}
     95
     96static hash_table_ops_t pending_call_ops = {
    8197        .hash = pending_call_hash,
    82         .compare = pending_call_compare,
    83         .remove_callback = pending_call_remove_callback
     98        .key_hash = pending_call_key_hash,
     99        .key_equal = pending_call_key_equal,
     100        .equal = NULL,
     101        .remove_callback = NULL
    84102};
    85 
    86 
    87 static hash_index_t pending_call_hash(unsigned long key[])
    88 {
    89 //      printf("pending_call_hash\n");
    90         return key[0] % PCALL_TABLE_CHAINS;
    91 }
    92 
    93 static int pending_call_compare(unsigned long key[], hash_count_t keys,
    94     link_t *item)
    95 {
    96         pending_call_t *hs;
    97 
    98 //      printf("pending_call_compare\n");
    99         hs = hash_table_get_instance(item, pending_call_t, link);
    100 
    101         // FIXME: this will fail if sizeof(long) < sizeof(void *).
    102         return key[0] == hs->call_hash;
    103 }
    104 
    105 static void pending_call_remove_callback(link_t *item)
    106 {
    107 //      printf("pending_call_remove_callback\n");
    108 }
    109103
    110104
     
    177171        }
    178172
    179         hash_table_create(&pending_calls, PCALL_TABLE_CHAINS, 1, &pending_call_ops);
     173        bool ok = hash_table_create(&pending_calls, 0, 0, &pending_call_ops);
     174        assert(ok);
    180175}
    181176
     
    190185        pending_call_t *pcall;
    191186        proto_t *proto;
    192         unsigned long key[1];
    193187        oper_t *oper;
    194188        sysarg_t *args;
     
    254248        pcall->oper = oper;
    255249
    256         key[0] = hash;
    257 
    258         hash_table_insert(&pending_calls, key, &pcall->link);
     250        hash_table_insert(&pending_calls, &pcall->link);
    259251}
    260252
     
    334326void ipcp_call_in(ipc_call_t *call, ipc_callid_t hash)
    335327{
    336         link_t *item;
     328        ht_link_t *item;
    337329        pending_call_t *pcall;
    338         unsigned long key[1];
    339330       
    340331        if ((hash & IPC_CALLID_ANSWERED) == 0 && hash != IPCP_CALLID_SYNC) {
     
    347338       
    348339        hash = hash & ~IPC_CALLID_ANSWERED;
    349         key[0] = hash;
    350        
    351         item = hash_table_find(&pending_calls, key);
     340       
     341        item = hash_table_find(&pending_calls, &hash);
    352342        if (item == NULL)
    353343                return; /* No matching question found */
     
    357347         */
    358348       
    359         pcall = hash_table_get_instance(item, pending_call_t, link);
    360         hash_table_remove(&pending_calls, key, 1);
     349        pcall = hash_table_get_inst(item, pending_call_t, link);
     350        hash_table_remove(&pending_calls, &hash);
    361351       
    362352        parse_answer(hash, pcall, call);
  • uspace/app/trace/proto.c

    rb5d2e57 r03362fbd  
    4040#include "proto.h"
    4141
    42 #define SRV_PROTO_TABLE_CHAINS 32
    43 #define METHOD_OPER_TABLE_CHAINS 32
    44 
    45 hash_table_t srv_proto;
     42
     43/* Maps service number to protocol */
     44static hash_table_t srv_proto;
    4645
    4746typedef struct {
    48         unsigned srv;
     47        int srv;
    4948        proto_t *proto;
    50         link_t link;
     49        ht_link_t link;
    5150} srv_proto_t;
    5251
    5352typedef struct {
    54         sysarg_t method;
     53        int method;
    5554        oper_t *oper;
    56         link_t link;
     55        ht_link_t link;
    5756} method_oper_t;
    5857
    59 static hash_index_t srv_proto_hash(unsigned long key[]);
    60 static int srv_proto_compare(unsigned long key[], hash_count_t keys,
    61     link_t *item);
    62 static void srv_proto_remove_callback(link_t *item);
    63 
    64 hash_table_operations_t srv_proto_ops = {
     58/* Hash table operations. */
     59
     60static size_t srv_proto_key_hash(void *key)
     61{
     62        return *(int *)key;
     63}
     64
     65static size_t srv_proto_hash(const ht_link_t *item)
     66{
     67        srv_proto_t *sp = hash_table_get_inst(item, srv_proto_t, link);
     68        return sp->srv;
     69}
     70
     71static bool srv_proto_key_equal(void *key, const ht_link_t *item)
     72{
     73        srv_proto_t *sp = hash_table_get_inst(item, srv_proto_t, link);
     74        return sp->srv == *(int *)key;
     75}
     76
     77static hash_table_ops_t srv_proto_ops = {
    6578        .hash = srv_proto_hash,
    66         .compare = srv_proto_compare,
    67         .remove_callback = srv_proto_remove_callback
     79        .key_hash = srv_proto_key_hash,
     80        .key_equal = srv_proto_key_equal,
     81        .equal = NULL,
     82        .remove_callback = NULL
    6883};
    6984
    70 static hash_index_t method_oper_hash(unsigned long key[]);
    71 static int method_oper_compare(unsigned long key[], hash_count_t keys,
    72     link_t *item);
    73 static void method_oper_remove_callback(link_t *item);
    74 
    75 hash_table_operations_t method_oper_ops = {
     85
     86static size_t method_oper_key_hash(void *key)
     87{
     88        return *(int *)key;
     89}
     90
     91static size_t method_oper_hash(const ht_link_t *item)
     92{
     93        method_oper_t *mo = hash_table_get_inst(item, method_oper_t, link);
     94        return mo->method;
     95}
     96
     97static bool method_oper_key_equal(void *key, const ht_link_t *item)
     98{
     99        method_oper_t *mo = hash_table_get_inst(item, method_oper_t, link);
     100        return mo->method == *(int *)key;
     101}
     102
     103static hash_table_ops_t method_oper_ops = {
    76104        .hash = method_oper_hash,
    77         .compare = method_oper_compare,
    78         .remove_callback = method_oper_remove_callback
     105        .key_hash = method_oper_key_hash,
     106        .key_equal = method_oper_key_equal,
     107        .equal = NULL,
     108        .remove_callback = NULL
    79109};
    80110
    81 static hash_index_t srv_proto_hash(unsigned long key[])
    82 {
    83         return key[0] % SRV_PROTO_TABLE_CHAINS;
    84 }
    85 
    86 static int srv_proto_compare(unsigned long key[], hash_count_t keys,
    87     link_t *item)
     111
     112void proto_init(void)
     113{
     114        /* todo: check return value. */
     115        bool ok = hash_table_create(&srv_proto, 0, 0, &srv_proto_ops);
     116        assert(ok);
     117}
     118
     119void proto_cleanup(void)
     120{
     121        hash_table_destroy(&srv_proto);
     122}
     123
     124void proto_register(int srv, proto_t *proto)
    88125{
    89126        srv_proto_t *sp;
    90 
    91         sp = hash_table_get_instance(item, srv_proto_t, link);
    92 
    93         return key[0] == sp->srv;
    94 }
    95 
    96 static void srv_proto_remove_callback(link_t *item)
    97 {
    98 }
    99 
    100 static hash_index_t method_oper_hash(unsigned long key[])
    101 {
    102         return key[0] % METHOD_OPER_TABLE_CHAINS;
    103 }
    104 
    105 static int method_oper_compare(unsigned long key[], hash_count_t keys,
    106     link_t *item)
    107 {
    108         method_oper_t *mo;
    109 
    110         mo = hash_table_get_instance(item, method_oper_t, link);
    111 
    112         return key[0] == mo->method;
    113 }
    114 
    115 static void method_oper_remove_callback(link_t *item)
    116 {
    117 }
    118 
    119 
    120 void proto_init(void)
    121 {
    122         hash_table_create(&srv_proto, SRV_PROTO_TABLE_CHAINS, 1,
    123             &srv_proto_ops);
    124 }
    125 
    126 void proto_cleanup(void)
    127 {
    128         hash_table_destroy(&srv_proto);
    129 }
    130 
    131 void proto_register(int srv, proto_t *proto)
    132 {
    133         srv_proto_t *sp;
    134         unsigned long key;
    135127
    136128        sp = malloc(sizeof(srv_proto_t));
    137129        sp->srv = srv;
    138130        sp->proto = proto;
    139         key = srv;
    140 
    141         hash_table_insert(&srv_proto, &key, &sp->link);
     131
     132        hash_table_insert(&srv_proto, &sp->link);
    142133}
    143134
    144135proto_t *proto_get_by_srv(int srv)
    145136{
    146         unsigned long key;
    147         link_t *item;
    148         srv_proto_t *sp;
    149 
    150         key = srv;
    151         item = hash_table_find(&srv_proto, &key);
     137        ht_link_t *item = hash_table_find(&srv_proto, &srv);
    152138        if (item == NULL) return NULL;
    153139
    154         sp = hash_table_get_instance(item, srv_proto_t, link);
     140        srv_proto_t *sp = hash_table_get_inst(item, srv_proto_t, link);
    155141        return sp->proto;
    156142}
     
    159145{
    160146        proto->name = name;
    161         hash_table_create(&proto->method_oper, SRV_PROTO_TABLE_CHAINS, 1,
    162             &method_oper_ops);
     147        /* todo: check return value. */
     148        bool ok = hash_table_create(&proto->method_oper, 0, 0, &method_oper_ops);
     149        assert(ok);
    163150}
    164151
     
    181168{
    182169        method_oper_t *mo;
    183         unsigned long key;
    184170
    185171        mo = malloc(sizeof(method_oper_t));
    186172        mo->method = method;
    187173        mo->oper = oper;
    188         key = method;
    189 
    190         hash_table_insert(&proto->method_oper, &key, &mo->link);       
     174
     175        hash_table_insert(&proto->method_oper, &mo->link);     
    191176}
    192177
    193178oper_t *proto_get_oper(proto_t *proto, int method)
    194179{
    195         unsigned long key;
    196         link_t *item;
    197         method_oper_t *mo;
    198 
    199         key = method;
    200         item = hash_table_find(&proto->method_oper, &key);
     180        ht_link_t *item = hash_table_find(&proto->method_oper, &method);
    201181        if (item == NULL) return NULL;
    202182
    203         mo = hash_table_get_instance(item, method_oper_t, link);
     183        method_oper_t *mo = hash_table_get_inst(item, method_oper_t, link);
    204184        return mo->oper;
    205185}
  • uspace/app/trace/proto.h

    rb5d2e57 r03362fbd  
    6262} proto_t;
    6363
    64 /* Maps service number to protocol */
    65 extern hash_table_t srv_proto;
    6664
    6765extern void proto_init(void);
  • uspace/app/trace/syscalls.c

    rb5d2e57 r03362fbd  
    5353    [SYS_AS_AREA_DESTROY] = { "as_area_destroy",        1,      V_ERRNO },
    5454
    55     [SYS_IPC_CALL_SYNC_FAST] = { "ipc_call_sync_fast",  6,      V_ERRNO },
    56     [SYS_IPC_CALL_SYNC_SLOW] = { "ipc_call_sync_slow",  3,      V_ERRNO },
    5755    [SYS_IPC_CALL_ASYNC_FAST] = { "ipc_call_async_fast", 6,     V_HASH },
    5856    [SYS_IPC_CALL_ASYNC_SLOW] = { "ipc_call_async_slow", 2,     V_HASH },
  • uspace/app/trace/trace.c

    rb5d2e57 r03362fbd  
    4343#include <mem.h>
    4444#include <str.h>
    45 #include <bool.h>
     45#include <stdbool.h>
    4646#include <loader/loader.h>
    4747#include <io/console.h>
     
    318318}
    319319
    320 static void sc_ipc_call_sync_fast(sysarg_t *sc_args)
    321 {
    322         ipc_call_t question, reply;
    323         int rc;
    324         int phoneid;
    325 
    326         phoneid = sc_args[0];
    327 
    328         IPC_SET_IMETHOD(question, sc_args[1]);
    329         IPC_SET_ARG1(question, sc_args[2]);
    330         IPC_SET_ARG2(question, sc_args[3]);
    331         IPC_SET_ARG3(question, sc_args[4]);
    332         IPC_SET_ARG4(question, 0);
    333         IPC_SET_ARG5(question, 0);
    334 
    335         memset(&reply, 0, sizeof(reply));
    336         rc = udebug_mem_read(sess, &reply.args, sc_args[5], sizeof(reply.args));
    337         if (rc < 0)
    338                 return;
    339        
    340         ipcp_call_sync(phoneid, &question, &reply);
    341 }
    342 
    343 static void sc_ipc_call_sync_slow_b(unsigned thread_id, sysarg_t *sc_args)
    344 {
    345         ipc_call_t question;
    346         int rc;
    347 
    348         memset(&question, 0, sizeof(question));
    349         rc = udebug_mem_read(sess, &question.args, sc_args[1],
    350             sizeof(question.args));
    351 
    352         if (rc < 0) {
    353                 printf("Error: mem_read->%d\n", rc);
    354                 return;
    355         }
    356 
    357         thread_ipc_req[thread_id] = question;
    358 }
    359 
    360 static void sc_ipc_call_sync_slow_e(unsigned thread_id, sysarg_t *sc_args)
    361 {
    362         ipc_call_t reply;
    363         int rc;
    364 
    365         memset(&reply, 0, sizeof(reply));
    366         rc = udebug_mem_read(sess, &reply.args, sc_args[2],
    367             sizeof(reply.args));
    368 
    369         if (rc < 0) {
    370                 printf("Error: mem_read->%d\n", rc);
    371                 return;
    372         }
    373 
    374         ipcp_call_sync(sc_args[0], &thread_ipc_req[thread_id], &reply);
    375 }
    376 
    377320static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc)
    378321{
     
    408351                print_sc_args(sc_args, syscall_desc[sc_id].n_args);
    409352        }
    410 
    411         switch (sc_id) {
    412         case SYS_IPC_CALL_SYNC_SLOW:
    413                 sc_ipc_call_sync_slow_b(thread_id, sc_args);
    414                 break;
    415         default:
    416                 break;
    417         }
    418353}
    419354
     
    447382        case SYS_IPC_CALL_ASYNC_SLOW:
    448383                sc_ipc_call_async_slow(sc_args, sc_rc);
    449                 break;
    450         case SYS_IPC_CALL_SYNC_FAST:
    451                 sc_ipc_call_sync_fast(sc_args);
    452                 break;
    453         case SYS_IPC_CALL_SYNC_SLOW:
    454                 sc_ipc_call_sync_slow_e(thread_id, sc_args);
    455384                break;
    456385        case SYS_IPC_WAIT:
  • uspace/app/usbinfo/Makefile

    rb5d2e57 r03362fbd  
    4747        hid.c \
    4848        info.c \
     49        list.c \
    4950        main.c
    5051
  • uspace/app/usbinfo/desctree.c

    rb5d2e57 r03362fbd  
    3939#include <errno.h>
    4040#include <str_error.h>
    41 #include <bool.h>
     41#include <stdbool.h>
    4242
    4343#include <usb/usb.h>
  • uspace/app/usbinfo/dump.c

    rb5d2e57 r03362fbd  
    3939#include <errno.h>
    4040#include <str_error.h>
    41 #include <bool.h>
     41#include <stdbool.h>
    4242
    4343#include <usb/usb.h>
  • uspace/app/usbinfo/list.c

    rb5d2e57 r03362fbd  
    4040#include <errno.h>
    4141#include <str_error.h>
    42 #include <bool.h>
     42#include <stdbool.h>
    4343#include <getopt.h>
    4444#include <devman.h>
     
    4747#include <usb/hc.h>
    4848
    49 #define NAME "lsusb"
     49#include "usbinfo.h"
    5050
    5151#define MAX_USB_ADDRESS USB11_ADDRESS_MAX
     
    9090}
    9191
    92 int main(int argc, char *argv[])
     92void list(void)
    9393{
    9494        category_id_t usbhc_cat;
     
    102102                printf(NAME ": Error resolving category '%s'",
    103103                    USB_HC_CATEGORY);
    104                 return 1;
     104                return;
    105105        }
    106106
     
    108108        if (rc != EOK) {
    109109                printf(NAME ": Error getting list of host controllers.\n");
    110                 return 1;
     110                return;
    111111        }
    112112
     
    131131
    132132        free(svcs);
    133 
    134         return 0;
    135133}
    136134
  • uspace/app/usbinfo/main.c

    rb5d2e57 r03362fbd  
    3939#include <errno.h>
    4040#include <str_error.h>
    41 #include <bool.h>
     41#include <stdbool.h>
    4242#include <getopt.h>
    4343#include <devman.h>
     
    6262
    6363        _OPTION("-h --help", "Print this help and exit.");
     64        _OPTION("-l --list", "Print a list of host controllers and devices.");
    6465        _OPTION("-i --identification", "Brief device identification.");
    6566        _OPTION("-m --match-ids", "Print match ids generated for the device.");
     
    8283        {"help", no_argument, NULL, 'h'},
    8384        {"identification", no_argument, NULL, 'i'},
     85        {"list", no_argument, NULL, 'l'},
    8486        {"match-ids", no_argument, NULL, 'm'},
    8587        {"descriptor-tree", no_argument, NULL, 't'},
     
    9193        {0, 0, NULL, 0}
    9294};
    93 static const char *short_options = "himtTsSrR";
     95static const char *short_options = "hilmtTsSrR";
    9496
    9597static usbinfo_action_t actions[] = {
     
    146148        }
    147149
     150        bool something_active = false;
    148151        /*
    149152         * Process command-line options. They determine what shall be
     
    156159                switch (opt) {
    157160                        case -1:
     161                                break;
     162                        case 'l':
     163                                list();
    158164                                break;
    159165                        case '?':
     
    168174                                        if (actions[idx].opt == opt) {
    169175                                                actions[idx].active = true;
     176                                                something_active = true;
    170177                                                break;
    171178                                        }
     
    178185
    179186        /* Set the default action. */
    180         int idx = 0;
    181         bool something_active = false;
    182         while (actions[idx].opt != 0) {
    183                 if (actions[idx].active) {
    184                         something_active = true;
    185                         break;
    186                 }
    187                 idx++;
    188         }
    189187        if (!something_active) {
    190188                actions[0].active = true;
  • uspace/app/usbinfo/usbinfo.h

    rb5d2e57 r03362fbd  
    7979    dump_descriptor_in_tree_t, size_t, void *);
    8080
     81void list(void);
    8182
    8283void dump_short_device_identification(usbinfo_device_t *);
  • uspace/app/vuhid/main.c

    rb5d2e57 r03362fbd  
    155155        int rc;
    156156
    157         usb_log_enable(USB_LOG_LEVEL_DEBUG2, "vusbhid");
     157        log_init("vuhid");
    158158
    159159        fibril_mutex_initialize(&vuhid_data.iface_count_mutex);
  • uspace/app/websrv/websrv.c

    rb5d2e57 r03362fbd  
    3434 */
    3535
    36 #include <bool.h>
     36#include <stdbool.h>
    3737#include <errno.h>
    3838#include <assert.h>
Note: See TracChangeset for help on using the changeset viewer.