Changeset 52c4264 in mainline for uspace/app


Ignore:
Timestamp:
2012-08-17T12:23:52Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
267f235
Parents:
ae2c925 (diff), ad78054 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

Location:
uspace/app
Files:
9 added
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    rae2c925 r52c4264  
    3838#include "cmds.h"
    3939
    40 #include <libblock.h>
     40#include <block.h>
    4141#include <loc.h>
    4242#include <errno.h>
  • uspace/app/bdsh/input.c

    rae2c925 r52c4264  
    268268        if (rc != EOK) {
    269269                /* Error in communication with console */
     270                cli_quit = 1;
    270271                return;
    271272        }
  • uspace/app/blkdump/blkdump.c

    rae2c925 r52c4264  
    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/edit/Makefile

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

    rae2c925 r52c4264  
    11/*
    22 * Copyright (c) 2009 Jiri Svoboda
     3 * Copyright (c) 2012 Martin Sucha
    34 * All rights reserved.
    45 *
     
    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
     
    140145static void delete_char_after(void);
    141146static void caret_update(void);
    142 static void caret_move(int drow, int dcolumn, enum dir_spec align_dir);
    143 static void caret_move_word_left(void);
    144 static void caret_move_word_right(void);
    145 static void caret_move_to_line(int row);
     147static void caret_move_relative(int drow, int dcolumn, enum dir_spec align_dir, bool select);
     148static void caret_move_absolute(int row, int column, enum dir_spec align_dir, bool select);
     149static void caret_move(spt_t spt, bool select, bool update_ideal_column);
     150static void caret_move_word_left(bool select);
     151static void caret_move_word_right(bool select);
    146152static void caret_go_to_line_ask(void);
    147153
     
    149155static void selection_sel_all(void);
    150156static void selection_sel_range(spt_t pa, spt_t pb);
    151 static void selection_sel_prev_word(void);
    152 static void selection_sel_next_word(void);
    153157static void selection_get_points(spt_t *pa, spt_t *pb);
    154158static void selection_delete(void);
    155159static void selection_copy(void);
    156160static void insert_clipboard_data(void);
     161
     162static void search(char *pattern, bool reverse);
     163static void search_prompt(bool reverse);
     164static void search_repeat(void);
    157165
    158166static void pt_get_sof(spt_t *pt);
     
    163171static bool pt_is_delimiter(spt_t *pt);
    164172static bool pt_is_punctuation(spt_t *pt);
     173static spt_t pt_find_word_left(spt_t spt);
     174static spt_t pt_find_word_left(spt_t spt);
     175
    165176static int tag_cmp(tag_t const *a, tag_t const *b);
    166177static int spt_cmp(spt_t const *a, spt_t const *b);
     
    173184{
    174185        kbd_event_t ev;
    175         coord_t coord;
    176186        bool new_file;
    177187        int rc;
    178 
    179         spt_t pt;
    180188
    181189        con = console_init(stdin, stdout);
     
    197205
    198206        /* Place caret at the beginning of file. */
    199         coord.row = coord.column = 1;
    200         sheet_get_cell_pt(doc.sh, &coord, dir_before, &pt);
    201         sheet_place_tag(doc.sh, &pt, &pane.caret_pos);
    202         pane.ideal_column = coord.column;
     207        spt_t sof;
     208        pt_get_sof(&sof);
     209        sheet_place_tag(doc.sh, &sof, &pane.caret_pos);
     210        pane.ideal_column = 1;
    203211
    204212        if (argc == 2) {
     
    216224                new_file = true;
    217225
     226        /* Place selection start tag. */
     227        sheet_place_tag(doc.sh, &sof, &pane.sel_start);
     228
    218229        /* Move to beginning of file. */
    219         caret_move(-ED_INFTY, -ED_INFTY, dir_before);
    220 
    221         /* Place selection start tag. */
    222         tag_get_pt(&pane.caret_pos, &pt);
    223         sheet_place_tag(doc.sh, &pt, &pane.sel_start);
     230        pt_get_sof(&sof);
     231        caret_move(sof, true, true);
    224232
    225233        /* Initial display */
     
    369377static void key_handle_ctrl(kbd_event_t const *ev)
    370378{
     379        spt_t pt;
    371380        switch (ev->key) {
    372381        case KC_Q:
     
    400409                selection_sel_all();
    401410                break;
    402         case KC_W:
    403                 if (selection_active())
    404                         break;
    405                 selection_sel_prev_word();
    406                 selection_delete();
    407                 break;
    408411        case KC_RIGHT:
    409                 caret_move_word_right();
     412                caret_move_word_right(false);
    410413                break;
    411414        case KC_LEFT:
    412                 caret_move_word_left();
     415                caret_move_word_left(false);
    413416                break;
    414417        case KC_L:
    415418                caret_go_to_line_ask();
    416419                break;
     420        case KC_F:
     421                search_prompt(false);
     422                break;
     423        case KC_N:
     424                search_repeat();
     425                break;
     426        case KC_HOME:
     427                pt_get_sof(&pt);
     428                caret_move(pt, false, true);
     429                break;
     430        case KC_END:
     431                pt_get_eof(&pt);
     432                caret_move(pt, false, true);
     433                break;
    417434        default:
    418435                break;
     
    422439static void key_handle_shift_ctrl(kbd_event_t const *ev)
    423440{
     441        spt_t pt;
    424442        switch(ev->key) {
    425443        case KC_LEFT:
    426                 selection_sel_prev_word();
     444                caret_move_word_left(true);
    427445                break;
    428446        case KC_RIGHT:
    429                 selection_sel_next_word();
     447                caret_move_word_right(true);
     448                break;
     449        case KC_F:
     450                search_prompt(true);
     451                break;
     452        case KC_HOME:
     453                pt_get_sof(&pt);
     454                caret_move(pt, true, true);
     455                break;
     456        case KC_END:
     457                pt_get_eof(&pt);
     458                caret_move(pt, true, true);
    430459                break;
    431460        default:
     
    435464
    436465/** Move caret while preserving or resetting selection. */
    437 static void caret_movement(int drow, int dcolumn, enum dir_spec align_dir,
    438     bool select)
    439 {
    440         spt_t pt;
    441         spt_t caret_pt;
     466static void caret_move(spt_t new_caret_pt, bool select, bool update_ideal_column)
     467{
     468        spt_t old_caret_pt, old_sel_pt;
    442469        coord_t c_old, c_new;
    443470        bool had_sel;
    444471
    445472        /* Check if we had selection before. */
    446         tag_get_pt(&pane.caret_pos, &caret_pt);
    447         tag_get_pt(&pane.sel_start, &pt);
    448         had_sel = !spt_equal(&caret_pt, &pt);
    449 
    450         caret_move(drow, dcolumn, align_dir);
     473        tag_get_pt(&pane.caret_pos, &old_caret_pt);
     474        tag_get_pt(&pane.sel_start, &old_sel_pt);
     475        had_sel = !spt_equal(&old_caret_pt, &old_sel_pt);
     476
     477        /* Place tag of the caret */
     478        sheet_remove_tag(doc.sh, &pane.caret_pos);
     479        sheet_place_tag(doc.sh, &new_caret_pt, &pane.caret_pos);
    451480
    452481        if (select == false) {
    453482                /* Move sel_start to the same point as caret. */
    454483                sheet_remove_tag(doc.sh, &pane.sel_start);
    455                 tag_get_pt(&pane.caret_pos, &pt);
    456                 sheet_place_tag(doc.sh, &pt, &pane.sel_start);
    457         }
    458 
     484                sheet_place_tag(doc.sh, &new_caret_pt, &pane.sel_start);
     485        }
     486
     487        spt_get_coord(&new_caret_pt, &c_new);
    459488        if (select) {
    460                 tag_get_pt(&pane.caret_pos, &pt);
    461                 spt_get_coord(&caret_pt, &c_old);
    462                 spt_get_coord(&pt, &c_new);
     489                spt_get_coord(&old_caret_pt, &c_old);
    463490
    464491                if (c_old.row == c_new.row)
     
    471498                pane.rflags |= REDRAW_TEXT;
    472499        }
     500       
     501        if (update_ideal_column)
     502                pane.ideal_column = c_new.column;
     503       
     504        caret_update();
    473505}
    474506
     
    477509        switch (key) {
    478510        case KC_LEFT:
    479                 caret_movement(0, -1, dir_before, select);
     511                caret_move_relative(0, -1, dir_before, select);
    480512                break;
    481513        case KC_RIGHT:
    482                 caret_movement(0, 0, dir_after, select);
     514                caret_move_relative(0, 0, dir_after, select);
    483515                break;
    484516        case KC_UP:
    485                 caret_movement(-1, 0, dir_before, select);
     517                caret_move_relative(-1, 0, dir_before, select);
    486518                break;
    487519        case KC_DOWN:
    488                 caret_movement(+1, 0, dir_before, select);
     520                caret_move_relative(+1, 0, dir_before, select);
    489521                break;
    490522        case KC_HOME:
    491                 caret_movement(0, -ED_INFTY, dir_before, select);
     523                caret_move_relative(0, -ED_INFTY, dir_after, select);
    492524                break;
    493525        case KC_END:
    494                 caret_movement(0, +ED_INFTY, dir_before, select);
     526                caret_move_relative(0, +ED_INFTY, dir_before, select);
    495527                break;
    496528        case KC_PAGE_UP:
    497                 caret_movement(-pane.rows, 0, dir_before, select);
     529                caret_move_relative(-pane.rows, 0, dir_before, select);
    498530                break;
    499531        case KC_PAGE_DOWN:
    500                 caret_movement(+pane.rows, 0, dir_before, select);
     532                caret_move_relative(+pane.rows, 0, dir_before, select);
    501533                break;
    502534        default:
     
    10121044}
    10131045
    1014 /** Change the caret position.
     1046/** Relatively move caret position.
    10151047 *
    10161048 * Moves caret relatively to the current position. Looking at the first
     
    10181050 * to a new character cell, and thus a new character. Then we either go to the
    10191051 * point before the the character or after it, depending on @a align_dir.
     1052 *
     1053 * @param select true if the selection tag should stay where it is
    10201054 */
    1021 static void caret_move(int drow, int dcolumn, enum dir_spec align_dir)
     1055static void caret_move_relative(int drow, int dcolumn, enum dir_spec align_dir,
     1056    bool select)
    10221057{
    10231058        spt_t pt;
     
    10551090         */
    10561091        sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt);
    1057         sheet_remove_tag(doc.sh, &pane.caret_pos);
    1058         sheet_place_tag(doc.sh, &pt, &pane.caret_pos);
    10591092
    10601093        /* For non-vertical movement set the new value for @c ideal_column. */
    1061         if (!pure_vertical) {
    1062                 spt_get_coord(&pt, &coord);
    1063                 pane.ideal_column = coord.column;
    1064         }
    1065 
    1066         caret_update();
    1067 }
    1068 
    1069 static void caret_move_word_left(void)
    1070 {
     1094        caret_move(pt, select, !pure_vertical);
     1095}
     1096
     1097/** Absolutely move caret position.
     1098 *
     1099 * Moves caret to a specified position. We get to a new character cell, and
     1100 * thus a new character. Then we either go to the point before the the character
     1101 * or after it, depending on @a align_dir.
     1102 *
     1103 * @param select true if the selection tag should stay where it is
     1104 */
     1105static void caret_move_absolute(int row, int column, enum dir_spec align_dir,
     1106    bool select)
     1107{
     1108        coord_t coord;
     1109        coord.row = row;
     1110        coord.column = column;
     1111       
    10711112        spt_t pt;
    1072 
     1113        sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt);
     1114       
     1115        caret_move(pt, select, true);
     1116}
     1117
     1118/** Find beginning of a word to the left of spt */
     1119static spt_t pt_find_word_left(spt_t spt)
     1120{
    10731121        do {
    1074                 caret_move(0, -1, dir_before);
    1075 
    1076                 tag_get_pt(&pane.caret_pos, &pt);
    1077 
    1078                 sheet_remove_tag(doc.sh, &pane.sel_start);
    1079                 sheet_place_tag(doc.sh, &pt, &pane.sel_start);
    1080         } while (!pt_is_word_beginning(&pt));
    1081 
    1082         pane.rflags |= REDRAW_TEXT;
    1083 }
    1084 
    1085 static void caret_move_word_right(void)
     1122                spt_prev_char(spt, &spt);
     1123        } while (!pt_is_word_beginning(&spt));
     1124        return spt;
     1125}
     1126
     1127/** Find beginning of a word to the right of spt */
     1128static spt_t pt_find_word_right(spt_t spt)
     1129{
     1130        do {
     1131                spt_next_char(spt, &spt);
     1132        } while (!pt_is_word_beginning(&spt));
     1133        return spt;
     1134}
     1135
     1136static void caret_move_word_left(bool select)
    10861137{
    10871138        spt_t pt;
    1088 
    1089         do {
    1090                 caret_move(0, 0, dir_after);
    1091 
    1092                 tag_get_pt(&pane.caret_pos, &pt);
    1093 
    1094                 sheet_remove_tag(doc.sh, &pane.sel_start);
    1095                 sheet_place_tag(doc.sh, &pt, &pane.sel_start);
    1096         } while (!pt_is_word_beginning(&pt));
    1097 
    1098         pane.rflags |= REDRAW_TEXT;
    1099 }
    1100 
    1101 /** Change the caret position to a beginning of a given line
    1102  */
    1103 static void caret_move_to_line(int row)
     1139        tag_get_pt(&pane.caret_pos, &pt);
     1140        spt_t word_left = pt_find_word_left(pt);
     1141        caret_move(word_left, select, true);
     1142}
     1143
     1144static void caret_move_word_right(bool select)
    11041145{
    11051146        spt_t pt;
    1106         coord_t coord;
    1107 
    11081147        tag_get_pt(&pane.caret_pos, &pt);
    1109         spt_get_coord(&pt, &coord);
    1110 
    1111         caret_movement(row - coord.row, 0, dir_before, false);
     1148        spt_t word_right = pt_find_word_right(pt);
     1149        caret_move(word_right, select, true);
    11121150}
    11131151
     
    11261164        int line = strtol(sline, &endptr, 10);
    11271165        if (*endptr != '\0') {
     1166                free(sline);
    11281167                status_display("Invalid number entered.");
    11291168                return;
    11301169        }
    1131        
    1132         caret_move_to_line(line);
    1133 }
    1134 
     1170        free(sline);
     1171       
     1172        caret_move_absolute(line, pane.ideal_column, dir_before, false);
     1173}
     1174
     1175/* Search operations */
     1176static int search_spt_producer(void *data, wchar_t *ret)
     1177{
     1178        assert(data != NULL);
     1179        assert(ret != NULL);
     1180        spt_t *spt = data;
     1181        *ret = spt_next_char(*spt, spt);
     1182        return EOK;
     1183}
     1184
     1185static int search_spt_reverse_producer(void *data, wchar_t *ret)
     1186{
     1187        assert(data != NULL);
     1188        assert(ret != NULL);
     1189        spt_t *spt = data;
     1190        *ret = spt_prev_char(*spt, spt);
     1191        return EOK;
     1192}
     1193
     1194static int search_spt_mark(void *data, void **mark)
     1195{
     1196        assert(data != NULL);
     1197        assert(mark != NULL);
     1198        spt_t *spt = data;
     1199        spt_t *new = calloc(1, sizeof(spt_t));
     1200        *mark = new;
     1201        if (new == NULL)
     1202                return ENOMEM;
     1203        *new = *spt;
     1204        return EOK;
     1205}
     1206
     1207static void search_spt_mark_free(void *data)
     1208{
     1209        free(data);
     1210}
     1211
     1212static search_ops_t search_spt_ops = {
     1213        .equals = char_exact_equals,
     1214        .producer = search_spt_producer,
     1215        .mark = search_spt_mark,
     1216        .mark_free = search_spt_mark_free,
     1217};
     1218
     1219static search_ops_t search_spt_reverse_ops = {
     1220        .equals = char_exact_equals,
     1221        .producer = search_spt_reverse_producer,
     1222        .mark = search_spt_mark,
     1223        .mark_free = search_spt_mark_free,
     1224};
     1225
     1226/** Ask for line and go to it. */
     1227static void search_prompt(bool reverse)
     1228{
     1229        char *pattern;
     1230       
     1231        const char *prompt_text = "Find next";
     1232        if (reverse)
     1233                prompt_text = "Find previous";
     1234       
     1235        const char *default_value = "";
     1236        if (pane.previous_search)
     1237                default_value = pane.previous_search;
     1238       
     1239        pattern = prompt(prompt_text, default_value);
     1240        if (pattern == NULL) {
     1241                status_display("Search cancelled.");
     1242                return;
     1243        }
     1244       
     1245        if (pane.previous_search)
     1246                free(pane.previous_search);
     1247        pane.previous_search = pattern;
     1248        pane.previous_search_reverse = reverse;
     1249       
     1250        search(pattern, reverse);
     1251}
     1252
     1253static void search_repeat(void)
     1254{
     1255        if (pane.previous_search == NULL) {
     1256                status_display("No previous search to repeat.");
     1257                return;
     1258        }
     1259       
     1260        search(pane.previous_search, pane.previous_search_reverse);
     1261}
     1262
     1263static void search(char *pattern, bool reverse)
     1264{
     1265        status_display("Searching...");
     1266       
     1267        spt_t sp, producer_pos;
     1268        tag_get_pt(&pane.caret_pos, &sp);
     1269       
     1270        /* Start searching on the position before/after caret */
     1271        if (!reverse) {
     1272                spt_next_char(sp, &sp);
     1273        }
     1274        else {
     1275                spt_prev_char(sp, &sp);
     1276        }
     1277        producer_pos = sp;
     1278       
     1279        search_ops_t ops = search_spt_ops;
     1280        if (reverse)
     1281                ops = search_spt_reverse_ops;
     1282       
     1283        search_t *search = search_init(pattern, &producer_pos, ops, reverse);
     1284        if (search == NULL) {
     1285                status_display("Failed initializing search.");
     1286                return;
     1287        }
     1288       
     1289        match_t match;
     1290        int rc = search_next_match(search, &match);
     1291        if (rc != EOK) {
     1292                status_display("Failed searching.");
     1293                search_fini(search);
     1294        }
     1295       
     1296        if (match.end) {
     1297                status_display("Match found.");
     1298                assert(match.end != NULL);
     1299                spt_t *end = match.end;
     1300                caret_move(*end, false, true);
     1301                while (match.length > 0) {
     1302                        match.length--;
     1303                        if (reverse) {
     1304                                spt_next_char(*end, end);
     1305                        }
     1306                        else {
     1307                                spt_prev_char(*end, end);
     1308                        }
     1309                }
     1310                caret_move(*end, true, true);
     1311                free(end);
     1312        }
     1313        else {
     1314                status_display("Not found.");
     1315        }
     1316       
     1317        search_fini(search);
     1318}
    11351319
    11361320/** Check for non-empty selection. */
     
    12021386        pane.rflags |= REDRAW_TEXT;
    12031387        caret_update();
    1204 }
    1205 
    1206 /** Add the previous word to the selection */
    1207 static void selection_sel_prev_word(void)
    1208 {
    1209         spt_t cpt, wpt, spt, ept;
    1210 
    1211         selection_get_points(&spt, &ept);
    1212 
    1213         tag_get_pt(&pane.caret_pos, &cpt);
    1214         caret_move_word_left();
    1215         tag_get_pt(&pane.caret_pos, &wpt);
    1216 
    1217         if (spt_cmp(&spt, &cpt) == 0)
    1218                 selection_sel_range(ept, wpt);
    1219         else
    1220                 selection_sel_range(spt, wpt);
    1221 }
    1222 
    1223 /** Add the next word to the selection */
    1224 static void selection_sel_next_word(void)
    1225 {
    1226         spt_t cpt, wpt, spt, ept;
    1227 
    1228         selection_get_points(&spt, &ept);
    1229 
    1230         tag_get_pt(&pane.caret_pos, &cpt);
    1231         caret_move_word_right();
    1232         tag_get_pt(&pane.caret_pos, &wpt);
    1233 
    1234         if (spt_cmp(&ept, &cpt) == 0)
    1235                 selection_sel_range(spt, wpt);
    1236         else
    1237                 selection_sel_range(ept, wpt);
    12381388}
    12391389
  • uspace/app/edit/sheet.c

    rae2c925 r52c4264  
    323323}
    324324
     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
    325342/** Place a tag on the specified s-point. */
    326343void sheet_place_tag(sheet_t *sh, spt_t const *pt, tag_t *tag)
  • uspace/app/edit/sheet.h

    rae2c925 r52c4264  
    101101extern void spt_get_coord(spt_t const *, coord_t *);
    102102extern 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 *);
    103105
    104106extern void sheet_place_tag(sheet_t *, spt_t const *, tag_t *);
  • uspace/app/ext2info/ext2info.c

    rae2c925 r52c4264  
    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/init/init.c

    rae2c925 r52c4264  
    3737#include <stdio.h>
    3838#include <unistd.h>
     39#include <stdarg.h>
    3940#include <vfs/vfs.h>
    4041#include <bool.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         getterm("term/vc0", "/app/bdsh", true);
    342         getterm("term/vc1", "/app/bdsh", false);
    343         getterm("term/vc2", "/app/bdsh", false);
    344         getterm("term/vc3", "/app/bdsh", false);
    345         getterm("term/vc4", "/app/bdsh", false);
    346         getterm("term/vc5", "/app/bdsh", false);
    347         getterm("term/vc6", "/app/klog", false);
     384        srv_start("/srv/input", HID_INPUT);
     385        srv_start("/srv/output", HID_OUTPUT);
     386       
     387        int rc = compositor(HID_INPUT, HID_COMPOSITOR_SERVER);
     388        if (rc == EOK) {
     389                gui_start("/app/vlaunch", HID_COMPOSITOR_SERVER);
     390                gui_start("/app/vterm", HID_COMPOSITOR_SERVER);
     391        } else {
     392                rc = console(HID_INPUT, HID_OUTPUT);
     393                if (rc == EOK) {
     394                        getterm("term/vc0", "/app/bdsh", true);
     395                        getterm("term/vc1", "/app/bdsh", false);
     396                        getterm("term/vc2", "/app/bdsh", false);
     397                        getterm("term/vc3", "/app/bdsh", false);
     398                        getterm("term/vc4", "/app/bdsh", false);
     399                        getterm("term/vc5", "/app/bdsh", false);
     400                        getterm("term/vc6", "/app/klog", false);
     401                }
     402        }
    348403       
    349404        return 0;
  • uspace/app/mkexfat/mkexfat.c

    rae2c925 r52c4264  
    3838
    3939#include <stdio.h>
    40 #include <libblock.h>
     40#include <block.h>
    4141#include <assert.h>
    4242#include <errno.h>
  • uspace/app/mkfat/mkfat.c

    rae2c925 r52c4264  
    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

    rae2c925 r52c4264  
    3939#include <stdio.h>
    4040#include <stdlib.h>
    41 #include <libblock.h>
     41#include <block.h>
    4242#include <unistd.h>
    4343#include <errno.h>
Note: See TracChangeset for help on using the changeset viewer.