Changeset 7eaeec1 in mainline for uspace/app
- Timestamp:
- 2012-08-20T21:27:38Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6a97f2e
- Parents:
- f3a37e28 (diff), dd13349 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/app
- Files:
-
- 10 added
- 12 edited
-
bdsh/cmds/modules/bdd/bdd.c (modified) (1 diff)
-
bdsh/input.c (modified) (4 diffs)
-
blkdump/blkdump.c (modified) (1 diff)
-
edit/Makefile (modified) (1 diff)
-
edit/edit.c (modified) (38 diffs)
-
edit/search.c (added)
-
edit/search.h (added)
-
edit/search_impl.h (added)
-
edit/sheet.c (modified) (4 diffs)
-
edit/sheet.h (modified) (3 diffs)
-
edit/sheet_impl.h (added)
-
ext2info/ext2info.c (modified) (1 diff)
-
init/init.c (modified) (9 diffs)
-
mkexfat/mkexfat.c (modified) (1 diff)
-
mkfat/mkfat.c (modified) (1 diff)
-
mkmfs/mkmfs.c (modified) (1 diff)
-
vdemo/Makefile (added)
-
vdemo/vdemo.c (added)
-
vlaunch/Makefile (added)
-
vlaunch/vlaunch.c (added)
-
vterm/Makefile (added)
-
vterm/vterm.c (added)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/bdd/bdd.c
rf3a37e28 r7eaeec1 38 38 #include "cmds.h" 39 39 40 #include < libblock.h>40 #include <block.h> 41 41 #include <loc.h> 42 42 #include <errno.h> -
uspace/app/bdsh/input.c
rf3a37e28 r7eaeec1 67 67 int process_input(cliuser_t *usr) 68 68 { 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) 71 71 return ENOMEM; 72 token_t *tokens = tokens_buf; 72 73 73 74 char *cmd[WORD_MAX]; … … 80 81 81 82 if (usr->line == NULL) { 82 free(tokens );83 free(tokens_buf); 83 84 return CL_EFAIL; 84 85 } … … 213 214 } 214 215 tok_fini(&tok); 215 free(tokens );216 free(tokens_buf); 216 217 217 218 return rc; … … 268 269 if (rc != EOK) { 269 270 /* Error in communication with console */ 271 cli_quit = 1; 270 272 return; 271 273 } -
uspace/app/blkdump/blkdump.c
rf3a37e28 r7eaeec1 40 40 #include <stdio.h> 41 41 #include <stdlib.h> 42 #include < libblock.h>42 #include <block.h> 43 43 #include <mem.h> 44 44 #include <loc.h> -
uspace/app/edit/Makefile
rf3a37e28 r7eaeec1 33 33 SOURCES = \ 34 34 edit.c \ 35 sheet.c 35 sheet.c \ 36 search.c 36 37 37 38 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/edit/edit.c
rf3a37e28 r7eaeec1 1 1 /* 2 2 * Copyright (c) 2009 Jiri Svoboda 3 * Copyright (c) 2012 Martin Sucha 3 4 * All rights reserved. 4 5 * … … 49 50 50 51 #include "sheet.h" 52 #include "search.h" 51 53 52 54 enum redraw_flags { … … 83 85 */ 84 86 int ideal_column; 87 88 char *previous_search; 89 bool previous_search_reverse; 85 90 } pane_t; 86 91 … … 91 96 typedef struct { 92 97 char *file_name; 93 sheet_t sh;98 sheet_t *sh; 94 99 } doc_t; 95 100 … … 106 111 #define BUF_SIZE 64 107 112 #define TAB_WIDTH 8 108 #define ED_INFTY 65536109 113 110 114 /** Maximum filename length that can be entered. */ … … 140 144 static void delete_char_after(void); 141 145 static 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); 146 static void caret_move_relative(int drow, int dcolumn, enum dir_spec align_dir, bool select); 147 static void caret_move_absolute(int row, int column, enum dir_spec align_dir, bool select); 148 static void caret_move(spt_t spt, bool select, bool update_ideal_column); 149 static void caret_move_word_left(bool select); 150 static void caret_move_word_right(bool select); 146 151 static void caret_go_to_line_ask(void); 147 152 … … 149 154 static void selection_sel_all(void); 150 155 static 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);153 156 static void selection_get_points(spt_t *pa, spt_t *pb); 154 157 static void selection_delete(void); 155 158 static void selection_copy(void); 156 159 static void insert_clipboard_data(void); 160 161 static void search(char *pattern, bool reverse); 162 static void search_prompt(bool reverse); 163 static void search_repeat(void); 157 164 158 165 static void pt_get_sof(spt_t *pt); … … 163 170 static bool pt_is_delimiter(spt_t *pt); 164 171 static bool pt_is_punctuation(spt_t *pt); 172 static spt_t pt_find_word_left(spt_t spt); 173 static spt_t pt_find_word_left(spt_t spt); 174 165 175 static int tag_cmp(tag_t const *a, tag_t const *b); 166 176 static int spt_cmp(spt_t const *a, spt_t const *b); … … 173 183 { 174 184 kbd_event_t ev; 175 coord_t coord;176 185 bool new_file; 177 178 spt_t pt; 186 int rc; 179 187 180 188 con = console_init(stdin, stdout); … … 189 197 190 198 /* Start with an empty sheet. */ 191 sheet_init(&doc.sh); 199 rc = sheet_create(&doc.sh); 200 if (rc != EOK) { 201 printf("Out of memory.\n"); 202 return -1; 203 } 192 204 193 205 /* Place caret at the beginning of file. */ 194 coord.row = coord.column = 1;195 sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt);196 sheet_place_tag( &doc.sh, &pt, &pane.caret_pos);197 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; 198 210 199 211 if (argc == 2) { … … 211 223 new_file = true; 212 224 225 /* Place selection start tag. */ 226 sheet_place_tag(doc.sh, &sof, &pane.sel_start); 227 213 228 /* Move to beginning of file. */ 214 caret_move(-ED_INFTY, -ED_INFTY, dir_before); 215 216 /* Place selection start tag. */ 217 tag_get_pt(&pane.caret_pos, &pt); 218 sheet_place_tag(&doc.sh, &pt, &pane.sel_start); 229 pt_get_sof(&sof); 230 caret_move(sof, true, true); 219 231 220 232 /* Initial display */ … … 364 376 static void key_handle_ctrl(kbd_event_t const *ev) 365 377 { 378 spt_t pt; 366 379 switch (ev->key) { 367 380 case KC_Q: … … 395 408 selection_sel_all(); 396 409 break; 397 case KC_W:398 if (selection_active())399 break;400 selection_sel_prev_word();401 selection_delete();402 break;403 410 case KC_RIGHT: 404 caret_move_word_right( );411 caret_move_word_right(false); 405 412 break; 406 413 case KC_LEFT: 407 caret_move_word_left( );414 caret_move_word_left(false); 408 415 break; 409 416 case KC_L: 410 417 caret_go_to_line_ask(); 411 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); 432 break; 412 433 default: 413 434 break; … … 417 438 static void key_handle_shift_ctrl(kbd_event_t const *ev) 418 439 { 440 spt_t pt; 419 441 switch(ev->key) { 420 442 case KC_LEFT: 421 selection_sel_prev_word();443 caret_move_word_left(true); 422 444 break; 423 445 case KC_RIGHT: 424 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); 425 458 break; 426 459 default: … … 429 462 } 430 463 431 static void key_handle_movement(unsigned int key, bool select) 432 { 433 spt_t pt; 434 spt_t caret_pt;464 /** Move caret while preserving or resetting selection. */ 465 static void caret_move(spt_t new_caret_pt, bool select, bool update_ideal_column) 466 { 467 spt_t old_caret_pt, old_sel_pt; 435 468 coord_t c_old, c_new; 436 469 bool had_sel; 437 470 438 471 /* Check if we had selection before. */ 439 tag_get_pt(&pane.caret_pos, &caret_pt); 440 tag_get_pt(&pane.sel_start, &pt); 441 had_sel = !spt_equal(&caret_pt, &pt); 442 443 switch (key) { 444 case KC_LEFT: 445 caret_move(0, -1, dir_before); 446 break; 447 case KC_RIGHT: 448 caret_move(0, 0, dir_after); 449 break; 450 case KC_UP: 451 caret_move(-1, 0, dir_before); 452 break; 453 case KC_DOWN: 454 caret_move(+1, 0, dir_before); 455 break; 456 case KC_HOME: 457 caret_move(0, -ED_INFTY, dir_before); 458 break; 459 case KC_END: 460 caret_move(0, +ED_INFTY, dir_before); 461 break; 462 case KC_PAGE_UP: 463 caret_move(-pane.rows, 0, dir_before); 464 break; 465 case KC_PAGE_DOWN: 466 caret_move(+pane.rows, 0, dir_before); 467 break; 468 default: 469 break; 470 } 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); 471 479 472 480 if (select == false) { 473 481 /* Move sel_start to the same point as caret. */ 474 sheet_remove_tag( &doc.sh, &pane.sel_start);475 tag_get_pt(&pane.caret_pos, &pt);476 sheet_place_tag(&doc.sh, &pt, &pane.sel_start);477 } 478 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); 479 487 if (select) { 480 tag_get_pt(&pane.caret_pos, &pt); 481 spt_get_coord(&caret_pt, &c_old); 482 spt_get_coord(&pt, &c_new); 488 spt_get_coord(&old_caret_pt, &c_old); 483 489 484 490 if (c_old.row == c_new.row) … … 490 496 /* Redraw because text was unselected. */ 491 497 pane.rflags |= REDRAW_TEXT; 498 } 499 500 if (update_ideal_column) 501 pane.ideal_column = c_new.column; 502 503 caret_update(); 504 } 505 506 static 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; 492 540 } 493 541 } … … 663 711 664 712 do { 665 sheet_copy_out( &doc.sh, &sp, epos, buf, BUF_SIZE, &bep);713 sheet_copy_out(doc.sh, &sp, epos, buf, BUF_SIZE, &bep); 666 714 bytes = str_size(buf); 667 715 … … 698 746 699 747 while (true) { 700 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, 701 749 &bep); 702 750 bytes = str_size(&buf[bpos]); … … 720 768 int sh_rows, rows; 721 769 722 sheet_get_num_rows( &doc.sh, &sh_rows);770 sheet_get_num_rows(doc.sh, &sh_rows); 723 771 rows = min(sh_rows - pane.sh_row + 1, pane.rows); 724 772 … … 790 838 rbc.row = pane.sh_row + i; 791 839 rbc.column = pane.sh_column; 792 sheet_get_cell_pt( &doc.sh, &rbc, dir_before, &rb);840 sheet_get_cell_pt(doc.sh, &rbc, dir_before, &rb); 793 841 794 842 /* Ending point for row display */ 795 843 rec.row = pane.sh_row + i; 796 844 rec.column = pane.sh_column + pane.columns; 797 sheet_get_cell_pt( &doc.sh, &rec, dir_before, &re);845 sheet_get_cell_pt(doc.sh, &rec, dir_before, &re); 798 846 799 847 /* Copy the text of the row to the buffer. */ 800 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); 801 849 802 850 /* Display text from the buffer. */ … … 867 915 spt_t caret_pt; 868 916 coord_t coord; 917 int last_row; 869 918 870 919 tag_get_pt(&pane.caret_pos, &caret_pt); 871 920 spt_get_coord(&caret_pt, &coord); 872 921 922 sheet_get_num_rows(doc.sh, &last_row); 923 873 924 const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>"; 874 925 875 926 console_set_pos(con, 0, scr_rows - 1); 876 927 console_set_style(con, STYLE_INVERTED); 877 int n = printf(" %d, %d : File '%s'. Ctrl-Q Quit Ctrl-S Save "878 "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); 879 930 880 931 int pos = scr_columns - 1 - n; … … 912 963 cbuf[offs] = '\0'; 913 964 914 (void) sheet_insert( &doc.sh, &pt, dir_before, cbuf);965 (void) sheet_insert(doc.sh, &pt, dir_before, cbuf); 915 966 916 967 pane.rflags |= REDRAW_ROW; … … 929 980 930 981 coord.column -= 1; 931 sheet_get_cell_pt( &doc.sh, &coord, dir_before, &sp);932 933 (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); 934 985 935 986 pane.rflags |= REDRAW_ROW; … … 947 998 spt_get_coord(&sp, &sc); 948 999 949 sheet_get_cell_pt( &doc.sh, &sc, dir_after, &ep);1000 sheet_get_cell_pt(doc.sh, &sc, dir_after, &ep); 950 1001 spt_get_coord(&ep, &ec); 951 1002 952 (void) sheet_delete( &doc.sh, &sp, &ep);1003 (void) sheet_delete(doc.sh, &sp, &ep); 953 1004 954 1005 pane.rflags |= REDRAW_ROW; … … 997 1048 } 998 1049 999 /** Change the caret position.1050 /** Relatively move caret position. 1000 1051 * 1001 1052 * Moves caret relatively to the current position. Looking at the first … … 1003 1054 * to a new character cell, and thus a new character. Then we either go to the 1004 1055 * 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 1005 1058 */ 1006 static void caret_move(int drow, int dcolumn, enum dir_spec align_dir) 1059 static void caret_move_relative(int drow, int dcolumn, enum dir_spec align_dir, 1060 bool select) 1007 1061 { 1008 1062 spt_t pt; … … 1022 1076 else { 1023 1077 coord.row--; 1024 sheet_get_row_width( &doc.sh, coord.row, &coord.column);1078 sheet_get_row_width(doc.sh, coord.row, &coord.column); 1025 1079 } 1026 1080 } 1027 1081 if (drow > 0) { 1028 sheet_get_num_rows( &doc.sh, &num_rows);1082 sheet_get_num_rows(doc.sh, &num_rows); 1029 1083 if (coord.row > num_rows) coord.row = num_rows; 1030 1084 } … … 1039 1093 * coordinates. The character can be wider than one cell (e.g. tab). 1040 1094 */ 1041 sheet_get_cell_pt(&doc.sh, &coord, align_dir, &pt); 1042 sheet_remove_tag(&doc.sh, &pane.caret_pos); 1043 sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); 1095 sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt); 1044 1096 1045 1097 /* For non-vertical movement set the new value for @c ideal_column. */ 1046 if (!pure_vertical) { 1047 spt_get_coord(&pt, &coord); 1048 pane.ideal_column = coord.column; 1049 } 1050 1051 caret_update(); 1052 } 1053 1054 static void caret_move_word_left(void) 1055 { 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 */ 1109 static 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 1056 1116 spt_t pt; 1057 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 */ 1123 static spt_t pt_find_word_left(spt_t spt) 1124 { 1058 1125 do { 1059 caret_move(0, -1, dir_before); 1060 1061 tag_get_pt(&pane.caret_pos, &pt); 1062 1063 sheet_remove_tag(&doc.sh, &pane.sel_start); 1064 sheet_place_tag(&doc.sh, &pt, &pane.sel_start); 1065 } while (!pt_is_word_beginning(&pt)); 1066 1067 pane.rflags |= REDRAW_TEXT; 1068 } 1069 1070 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 */ 1132 static 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 1140 static void caret_move_word_left(bool select) 1071 1141 { 1072 1142 spt_t pt; 1073 1074 do { 1075 caret_move(0, 0, dir_after); 1076 1077 tag_get_pt(&pane.caret_pos, &pt); 1078 1079 sheet_remove_tag(&doc.sh, &pane.sel_start); 1080 sheet_place_tag(&doc.sh, &pt, &pane.sel_start); 1081 } while (!pt_is_word_beginning(&pt)); 1082 1083 pane.rflags |= REDRAW_TEXT; 1084 } 1085 1086 /** Change the caret position to a beginning of a given line 1087 */ 1088 static void caret_move_to_line(int row) 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 1148 static void caret_move_word_right(bool select) 1089 1149 { 1090 1150 spt_t pt; 1091 coord_t coord;1092 int num_rows;1093 1094 1151 tag_get_pt(&pane.caret_pos, &pt); 1095 spt_get_coord(&pt, &coord); 1096 coord.row = row; 1097 coord.column = 1; 1098 1099 /* Clamp coordinates. */ 1100 if (coord.row < 1) coord.row = 1; 1101 sheet_get_num_rows(&doc.sh, &num_rows); 1102 if (coord.row > num_rows) coord.row = num_rows; 1103 1104 /* 1105 * Select the point before the character at the designated 1106 * coordinates. The character can be wider than one cell (e.g. tab). 1107 */ 1108 sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt); 1109 sheet_remove_tag(&doc.sh, &pane.caret_pos); 1110 sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); 1111 1112 /* Set the new value for @c ideal_column. */ 1113 spt_get_coord(&pt, &coord); 1114 pane.ideal_column = coord.column; 1115 1116 caret_update(); 1152 spt_t word_right = pt_find_word_right(pt); 1153 caret_move(word_right, select, true); 1117 1154 } 1118 1155 … … 1131 1168 int line = strtol(sline, &endptr, 10); 1132 1169 if (*endptr != '\0') { 1170 free(sline); 1133 1171 status_display("Invalid number entered."); 1134 1172 return; 1135 1173 } 1136 1137 caret_move_to_line(line); 1138 } 1139 1174 free(sline); 1175 1176 caret_move_absolute(line, pane.ideal_column, dir_before, false); 1177 } 1178 1179 /* Search operations */ 1180 static 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 1189 static 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 1198 static 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 1211 static void search_spt_mark_free(void *data) 1212 { 1213 free(data); 1214 } 1215 1216 static 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 1223 static 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. */ 1231 static 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 1257 static 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 1267 static 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); 1322 } 1140 1323 1141 1324 /** Check for non-empty selection. */ … … 1176 1359 1177 1360 if (rel < 0) 1178 sheet_delete( &doc.sh, &pa, &pb);1361 sheet_delete(doc.sh, &pa, &pb); 1179 1362 else 1180 sheet_delete( &doc.sh, &pb, &pa);1363 sheet_delete(doc.sh, &pb, &pa); 1181 1364 1182 1365 if (ca.row == cb.row) … … 1200 1383 static void selection_sel_range(spt_t pa, spt_t pb) 1201 1384 { 1202 sheet_remove_tag( &doc.sh, &pane.sel_start);1203 sheet_place_tag( &doc.sh, &pa, &pane.sel_start);1204 sheet_remove_tag( &doc.sh, &pane.caret_pos);1205 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); 1206 1389 1207 1390 pane.rflags |= REDRAW_TEXT; 1208 1391 caret_update(); 1209 }1210 1211 /** Add the previous word to the selection */1212 static void selection_sel_prev_word(void)1213 {1214 spt_t cpt, wpt, spt, ept;1215 1216 selection_get_points(&spt, &ept);1217 1218 tag_get_pt(&pane.caret_pos, &cpt);1219 caret_move_word_left();1220 tag_get_pt(&pane.caret_pos, &wpt);1221 1222 if (spt_cmp(&spt, &cpt) == 0)1223 selection_sel_range(ept, wpt);1224 else1225 selection_sel_range(spt, wpt);1226 }1227 1228 /** Add the next word to the selection */1229 static void selection_sel_next_word(void)1230 {1231 spt_t cpt, wpt, spt, ept;1232 1233 selection_get_points(&spt, &ept);1234 1235 tag_get_pt(&pane.caret_pos, &cpt);1236 caret_move_word_right();1237 tag_get_pt(&pane.caret_pos, &wpt);1238 1239 if (spt_cmp(&ept, &cpt) == 0)1240 selection_sel_range(spt, wpt);1241 else1242 selection_sel_range(ept, wpt);1243 1392 } 1244 1393 … … 1286 1435 1287 1436 coord.row = coord.column = 1; 1288 sheet_get_cell_pt( &doc.sh, &coord, dir_before, pt);1437 sheet_get_cell_pt(doc.sh, &coord, dir_before, pt); 1289 1438 } 1290 1439 … … 1295 1444 int num_rows; 1296 1445 1297 sheet_get_num_rows( &doc.sh, &num_rows);1446 sheet_get_num_rows(doc.sh, &num_rows); 1298 1447 coord.row = num_rows + 1; 1299 1448 coord.column = 1; 1300 1449 1301 sheet_get_cell_pt( &doc.sh, &coord, dir_after, pt);1450 sheet_get_cell_pt(doc.sh, &coord, dir_after, pt); 1302 1451 } 1303 1452 … … 1310 1459 coord.column = 1; 1311 1460 1312 sheet_get_cell_pt( &doc.sh, &coord, dir_before, spt);1461 sheet_get_cell_pt(doc.sh, &coord, dir_before, spt); 1313 1462 } 1314 1463 … … 1320 1469 1321 1470 spt_get_coord(cpt, &coord); 1322 sheet_get_row_width( &doc.sh, coord.row, &row_width);1471 sheet_get_row_width(doc.sh, coord.row, &row_width); 1323 1472 coord.column = row_width - 1; 1324 1473 1325 sheet_get_cell_pt( &doc.sh, &coord, dir_after, ept);1474 sheet_get_cell_pt(doc.sh, &coord, dir_after, ept); 1326 1475 } 1327 1476 … … 1349 1498 1350 1499 coord.column -= 1; 1351 sheet_get_cell_pt( &doc.sh, &coord, dir_before, &lp);1500 sheet_get_cell_pt(doc.sh, &coord, dir_before, &lp); 1352 1501 1353 1502 return pt_is_delimiter(&lp) … … 1371 1520 1372 1521 coord.column += 1; 1373 sheet_get_cell_pt( &doc.sh, &coord, dir_after, &rp);1522 sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp); 1374 1523 1375 1524 ch = range_get_str(pt, &rp); … … 1397 1546 1398 1547 coord.column += 1; 1399 sheet_get_cell_pt( &doc.sh, &coord, dir_after, &rp);1548 sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp); 1400 1549 1401 1550 ch = range_get_str(pt, &rp); -
uspace/app/edit/sheet.c
rf3a37e28 r7eaeec1 57 57 58 58 #include "sheet.h" 59 #include "sheet_impl.h" 59 60 60 61 enum { … … 66 67 67 68 /** Initialize an empty sheet. */ 68 int sheet_init(sheet_t *sh) 69 { 69 int 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 70 77 sh->dbuf_size = INITIAL_SIZE; 71 78 sh->text_size = 0; … … 77 84 list_initialize(&sh->tags); 78 85 86 *rsh = sh; 79 87 return EOK; 80 88 } … … 315 323 } 316 324 325 /** Get a character at spt and return next spt */ 326 wchar_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 334 wchar_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 317 342 /** Place a tag on the specified s-point. */ 318 343 void sheet_place_tag(sheet_t *sh, spt_t const *pt, tag_t *tag) -
uspace/app/edit/sheet.h
rf3a37e28 r7eaeec1 50 50 51 51 /** 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; 52 struct sheet; 53 typedef struct sheet sheet_t; 61 54 62 55 /** Character cell coordinates … … 97 90 } tag_t; 98 91 99 extern int sheet_ init(sheet_t*);92 extern int sheet_create(sheet_t **); 100 93 extern int sheet_insert(sheet_t *, spt_t *, enum dir_spec, char *); 101 94 extern int sheet_delete(sheet_t *, spt_t *, spt_t *); … … 108 101 extern void spt_get_coord(spt_t const *, coord_t *); 109 102 extern bool spt_equal(spt_t const *, spt_t const *); 103 extern wchar_t spt_next_char(spt_t, spt_t *); 104 extern wchar_t spt_prev_char(spt_t, spt_t *); 110 105 111 106 extern void sheet_place_tag(sheet_t *, spt_t const *, tag_t *); -
uspace/app/ext2info/ext2info.c
rf3a37e28 r7eaeec1 40 40 #include <stdio.h> 41 41 #include <stdlib.h> 42 #include < libblock.h>42 #include <block.h> 43 43 #include <mem.h> 44 44 #include <loc.h> -
uspace/app/init/init.c
rf3a37e28 r7eaeec1 37 37 #include <stdio.h> 38 38 #include <unistd.h> 39 #include <stdarg.h> 39 40 #include <vfs/vfs.h> 40 41 #include <bool.h> … … 65 66 #define SRV_CONSOLE "/srv/console" 66 67 #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) 67 77 68 78 /** Print banner */ … … 143 153 } 144 154 145 static void spawn(const char *fname) 146 { 147 int rc; 155 static int srv_startl(const char *path, ...) 156 { 148 157 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); 163 177 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 164 193 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; 179 195 rc = task_wait(id, &texit, &retval); 180 196 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; 184 200 } 185 201 186 202 if (texit != TASK_EXIT_NORMAL) { 187 203 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) 193 209 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 215 static int console(const char *isvc, const char *osvc) 216 { 202 217 /* Wait for the input service to be ready */ 203 218 service_id_t service_id; … … 206 221 printf("%s: Error waiting on %s (%s)\n", NAME, isvc, 207 222 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 237 static 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 251 static 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; 224 276 } 225 277 … … 227 279 { 228 280 char term[LOC_NAME_MAXLEN]; 229 int rc;230 231 281 snprintf(term, LOC_NAME_MAXLEN, "%s/%s", LOCFS_MOUNT_POINT, svc); 232 282 … … 235 285 /* Wait for the terminal service to be ready */ 236 286 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); 238 288 if (rc != EOK) { 239 289 printf("%s: Error waiting on %s (%s)\n", NAME, term, … … 279 329 if (!mount_root(STRING(RDFMT))) { 280 330 printf("%s: Exiting\n", NAME); 281 return -1;331 return 1; 282 332 } 283 333 284 334 /* 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"); 291 340 292 341 if (!mount_locfs()) { 293 342 printf("%s: Exiting\n", NAME); 294 return -2;343 return 2; 295 344 } 296 345 297 346 mount_tmpfs(); 298 347 299 s pawn("/srv/devman");300 s pawn("/srv/apic");301 s pawn("/srv/i8259");302 s pawn("/srv/obio");348 srv_start("/srv/devman"); 349 srv_start("/srv/apic"); 350 srv_start("/srv/i8259"); 351 srv_start("/srv/obio"); 303 352 srv_start("/srv/cuda_adb"); 304 353 srv_start("/srv/s3c24xx_uart"); 305 354 srv_start("/srv/s3c24xx_ts"); 306 355 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"); 319 364 320 365 /* … … 325 370 srv_start("/srv/ata_bd"); 326 371 srv_start("/srv/gxe_bd"); 327 #else328 (void) srv_start;329 372 #endif 330 373 331 374 #ifdef CONFIG_MOUNT_DATA 332 375 /* Make sure fat is running. */ 333 if (str_cmp(STRING(RDFMT), "fat") != 0) {376 if (str_cmp(STRING(RDFMT), "fat") != 0) 334 377 srv_start("/srv/fat"); 335 }378 336 379 mount_data(); 337 380 #else … … 339 382 #endif 340 383 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 } 348 403 349 404 return 0; -
uspace/app/mkexfat/mkexfat.c
rf3a37e28 r7eaeec1 38 38 39 39 #include <stdio.h> 40 #include < libblock.h>40 #include <block.h> 41 41 #include <assert.h> 42 42 #include <errno.h> -
uspace/app/mkfat/mkfat.c
rf3a37e28 r7eaeec1 40 40 #include <stdio.h> 41 41 #include <stdlib.h> 42 #include < libblock.h>42 #include <block.h> 43 43 #include <mem.h> 44 44 #include <loc.h> -
uspace/app/mkmfs/mkmfs.c
rf3a37e28 r7eaeec1 39 39 #include <stdio.h> 40 40 #include <stdlib.h> 41 #include < libblock.h>41 #include <block.h> 42 42 #include <unistd.h> 43 43 #include <errno.h>
Note:
See TracChangeset
for help on using the changeset viewer.
