Changeset 69cf3a4 in mainline
- Timestamp:
- 2012-08-16T10:26:02Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- be2a38ad
- Parents:
- c8444d8
- Location:
- uspace/app/edit
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
rc8444d8 r69cf3a4 91 91 typedef struct { 92 92 char *file_name; 93 sheet_t sh;93 sheet_t *sh; 94 94 } doc_t; 95 95 … … 175 175 coord_t coord; 176 176 bool new_file; 177 int rc; 177 178 178 179 spt_t pt; … … 189 190 190 191 /* Start with an empty sheet. */ 191 sheet_init(&doc.sh); 192 rc = sheet_create(&doc.sh); 193 if (rc != EOK) { 194 printf("Out of memory.\n"); 195 return -1; 196 } 192 197 193 198 /* Place caret at the beginning of file. */ 194 199 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);200 sheet_get_cell_pt(doc.sh, &coord, dir_before, &pt); 201 sheet_place_tag(doc.sh, &pt, &pane.caret_pos); 197 202 pane.ideal_column = coord.column; 198 203 … … 216 221 /* Place selection start tag. */ 217 222 tag_get_pt(&pane.caret_pos, &pt); 218 sheet_place_tag( &doc.sh, &pt, &pane.sel_start);223 sheet_place_tag(doc.sh, &pt, &pane.sel_start); 219 224 220 225 /* Initial display */ … … 447 452 if (select == false) { 448 453 /* Move sel_start to the same point as caret. */ 449 sheet_remove_tag( &doc.sh, &pane.sel_start);454 sheet_remove_tag(doc.sh, &pane.sel_start); 450 455 tag_get_pt(&pane.caret_pos, &pt); 451 sheet_place_tag( &doc.sh, &pt, &pane.sel_start);456 sheet_place_tag(doc.sh, &pt, &pane.sel_start); 452 457 } 453 458 … … 670 675 671 676 do { 672 sheet_copy_out( &doc.sh, &sp, epos, buf, BUF_SIZE, &bep);677 sheet_copy_out(doc.sh, &sp, epos, buf, BUF_SIZE, &bep); 673 678 bytes = str_size(buf); 674 679 … … 705 710 706 711 while (true) { 707 sheet_copy_out( &doc.sh, &sp, epos, &buf[bpos], buf_size - bpos,712 sheet_copy_out(doc.sh, &sp, epos, &buf[bpos], buf_size - bpos, 708 713 &bep); 709 714 bytes = str_size(&buf[bpos]); … … 727 732 int sh_rows, rows; 728 733 729 sheet_get_num_rows( &doc.sh, &sh_rows);734 sheet_get_num_rows(doc.sh, &sh_rows); 730 735 rows = min(sh_rows - pane.sh_row + 1, pane.rows); 731 736 … … 797 802 rbc.row = pane.sh_row + i; 798 803 rbc.column = pane.sh_column; 799 sheet_get_cell_pt( &doc.sh, &rbc, dir_before, &rb);804 sheet_get_cell_pt(doc.sh, &rbc, dir_before, &rb); 800 805 801 806 /* Ending point for row display */ 802 807 rec.row = pane.sh_row + i; 803 808 rec.column = pane.sh_column + pane.columns; 804 sheet_get_cell_pt( &doc.sh, &rec, dir_before, &re);809 sheet_get_cell_pt(doc.sh, &rec, dir_before, &re); 805 810 806 811 /* Copy the text of the row to the buffer. */ 807 sheet_copy_out( &doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep);812 sheet_copy_out(doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep); 808 813 809 814 /* Display text from the buffer. */ … … 874 879 spt_t caret_pt; 875 880 coord_t coord; 881 int last_row; 876 882 877 883 tag_get_pt(&pane.caret_pos, &caret_pt); 878 884 spt_get_coord(&caret_pt, &coord); 879 885 886 sheet_get_num_rows(doc.sh, &last_row); 887 880 888 const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>"; 881 889 882 890 console_set_pos(con, 0, scr_rows - 1); 883 891 console_set_style(con, STYLE_INVERTED); 884 int n = printf(" %d, %d : File '%s'. Ctrl-Q Quit Ctrl-S Save "885 "Ctrl-E Save As", coord.row, coord.column, fname);892 int n = printf(" %d, %d (%d): File '%s'. Ctrl-Q Quit Ctrl-S Save " 893 "Ctrl-E Save As", coord.row, coord.column, last_row, fname); 886 894 887 895 int pos = scr_columns - 1 - n; … … 919 927 cbuf[offs] = '\0'; 920 928 921 (void) sheet_insert( &doc.sh, &pt, dir_before, cbuf);929 (void) sheet_insert(doc.sh, &pt, dir_before, cbuf); 922 930 923 931 pane.rflags |= REDRAW_ROW; … … 936 944 937 945 coord.column -= 1; 938 sheet_get_cell_pt( &doc.sh, &coord, dir_before, &sp);939 940 (void) sheet_delete( &doc.sh, &sp, &ep);946 sheet_get_cell_pt(doc.sh, &coord, dir_before, &sp); 947 948 (void) sheet_delete(doc.sh, &sp, &ep); 941 949 942 950 pane.rflags |= REDRAW_ROW; … … 954 962 spt_get_coord(&sp, &sc); 955 963 956 sheet_get_cell_pt( &doc.sh, &sc, dir_after, &ep);964 sheet_get_cell_pt(doc.sh, &sc, dir_after, &ep); 957 965 spt_get_coord(&ep, &ec); 958 966 959 (void) sheet_delete( &doc.sh, &sp, &ep);967 (void) sheet_delete(doc.sh, &sp, &ep); 960 968 961 969 pane.rflags |= REDRAW_ROW; … … 1029 1037 else { 1030 1038 coord.row--; 1031 sheet_get_row_width( &doc.sh, coord.row, &coord.column);1039 sheet_get_row_width(doc.sh, coord.row, &coord.column); 1032 1040 } 1033 1041 } 1034 1042 if (drow > 0) { 1035 sheet_get_num_rows( &doc.sh, &num_rows);1043 sheet_get_num_rows(doc.sh, &num_rows); 1036 1044 if (coord.row > num_rows) coord.row = num_rows; 1037 1045 } … … 1046 1054 * coordinates. The character can be wider than one cell (e.g. tab). 1047 1055 */ 1048 sheet_get_cell_pt( &doc.sh, &coord, align_dir, &pt);1049 sheet_remove_tag( &doc.sh, &pane.caret_pos);1050 sheet_place_tag( &doc.sh, &pt, &pane.caret_pos);1056 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); 1051 1059 1052 1060 /* For non-vertical movement set the new value for @c ideal_column. */ … … 1068 1076 tag_get_pt(&pane.caret_pos, &pt); 1069 1077 1070 sheet_remove_tag( &doc.sh, &pane.sel_start);1071 sheet_place_tag( &doc.sh, &pt, &pane.sel_start);1078 sheet_remove_tag(doc.sh, &pane.sel_start); 1079 sheet_place_tag(doc.sh, &pt, &pane.sel_start); 1072 1080 } while (!pt_is_word_beginning(&pt)); 1073 1081 … … 1084 1092 tag_get_pt(&pane.caret_pos, &pt); 1085 1093 1086 sheet_remove_tag( &doc.sh, &pane.sel_start);1087 sheet_place_tag( &doc.sh, &pt, &pane.sel_start);1094 sheet_remove_tag(doc.sh, &pane.sel_start); 1095 sheet_place_tag(doc.sh, &pt, &pane.sel_start); 1088 1096 } while (!pt_is_word_beginning(&pt)); 1089 1097 … … 1163 1171 1164 1172 if (rel < 0) 1165 sheet_delete( &doc.sh, &pa, &pb);1173 sheet_delete(doc.sh, &pa, &pb); 1166 1174 else 1167 sheet_delete( &doc.sh, &pb, &pa);1175 sheet_delete(doc.sh, &pb, &pa); 1168 1176 1169 1177 if (ca.row == cb.row) … … 1187 1195 static void selection_sel_range(spt_t pa, spt_t pb) 1188 1196 { 1189 sheet_remove_tag( &doc.sh, &pane.sel_start);1190 sheet_place_tag( &doc.sh, &pa, &pane.sel_start);1191 sheet_remove_tag( &doc.sh, &pane.caret_pos);1192 sheet_place_tag( &doc.sh, &pb, &pane.caret_pos);1197 sheet_remove_tag(doc.sh, &pane.sel_start); 1198 sheet_place_tag(doc.sh, &pa, &pane.sel_start); 1199 sheet_remove_tag(doc.sh, &pane.caret_pos); 1200 sheet_place_tag(doc.sh, &pb, &pane.caret_pos); 1193 1201 1194 1202 pane.rflags |= REDRAW_TEXT; … … 1273 1281 1274 1282 coord.row = coord.column = 1; 1275 sheet_get_cell_pt( &doc.sh, &coord, dir_before, pt);1283 sheet_get_cell_pt(doc.sh, &coord, dir_before, pt); 1276 1284 } 1277 1285 … … 1282 1290 int num_rows; 1283 1291 1284 sheet_get_num_rows( &doc.sh, &num_rows);1292 sheet_get_num_rows(doc.sh, &num_rows); 1285 1293 coord.row = num_rows + 1; 1286 1294 coord.column = 1; 1287 1295 1288 sheet_get_cell_pt( &doc.sh, &coord, dir_after, pt);1296 sheet_get_cell_pt(doc.sh, &coord, dir_after, pt); 1289 1297 } 1290 1298 … … 1297 1305 coord.column = 1; 1298 1306 1299 sheet_get_cell_pt( &doc.sh, &coord, dir_before, spt);1307 sheet_get_cell_pt(doc.sh, &coord, dir_before, spt); 1300 1308 } 1301 1309 … … 1307 1315 1308 1316 spt_get_coord(cpt, &coord); 1309 sheet_get_row_width( &doc.sh, coord.row, &row_width);1317 sheet_get_row_width(doc.sh, coord.row, &row_width); 1310 1318 coord.column = row_width - 1; 1311 1319 1312 sheet_get_cell_pt( &doc.sh, &coord, dir_after, ept);1320 sheet_get_cell_pt(doc.sh, &coord, dir_after, ept); 1313 1321 } 1314 1322 … … 1336 1344 1337 1345 coord.column -= 1; 1338 sheet_get_cell_pt( &doc.sh, &coord, dir_before, &lp);1346 sheet_get_cell_pt(doc.sh, &coord, dir_before, &lp); 1339 1347 1340 1348 return pt_is_delimiter(&lp) … … 1358 1366 1359 1367 coord.column += 1; 1360 sheet_get_cell_pt( &doc.sh, &coord, dir_after, &rp);1368 sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp); 1361 1369 1362 1370 ch = range_get_str(pt, &rp); … … 1384 1392 1385 1393 coord.column += 1; 1386 sheet_get_cell_pt( &doc.sh, &coord, dir_after, &rp);1394 sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp); 1387 1395 1388 1396 ch = range_get_str(pt, &rp); -
uspace/app/edit/sheet.c
rc8444d8 r69cf3a4 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 } -
uspace/app/edit/sheet.h
rc8444d8 r69cf3a4 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 *);
Note:
See TracChangeset
for help on using the changeset viewer.