Changes in uspace/app/edit/edit.c [48b77ed:cf13b17] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
r48b77ed rcf13b17 955 955 coord_t coord; 956 956 int last_row; 957 char *fname;958 char *p;959 char *text;960 size_t n;961 int pos;962 size_t nextra;963 size_t fnw;964 957 965 958 tag_get_pt(&pane.caret_pos, &caret_pt); … … 968 961 sheet_get_num_rows(doc.sh, &last_row); 969 962 970 if (doc.file_name != NULL) { 971 /* Remove directory component */ 972 p = str_rchr(doc.file_name, '/'); 973 if (p != NULL) 974 fname = str_dup(p + 1); 975 else 976 fname = str_dup(doc.file_name); 977 } else { 978 fname = str_dup("<unnamed>"); 979 } 980 981 if (fname == NULL) 982 return; 963 const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>"; 983 964 984 965 console_set_pos(con, 0, scr_rows - 1); 985 966 console_set_style(con, STYLE_INVERTED); 986 987 /* 988 * Make sure the status fits on the screen. This loop should 989 * be executed at most twice. 990 */ 991 while (true) { 992 int rc = asprintf(&text, " %d, %d (%d): File '%s'. Ctrl-Q Quit Ctrl-S Save " 993 "Ctrl-E Save As", coord.row, coord.column, last_row, fname); 994 if (rc < 0) { 995 n = 0; 996 goto finish; 997 } 998 999 /* If it already fits, we're done */ 1000 n = str_width(text); 1001 if (n <= scr_columns - 2) 1002 break; 1003 1004 /* Compute number of excess characters */ 1005 nextra = n - (scr_columns - 2); 1006 /** With of the file name part */ 1007 fnw = str_width(fname); 1008 1009 /* 1010 * If reducing file name to two characters '..' won't help, 1011 * just give up and print a blank status. 1012 */ 1013 if (nextra > fnw - 2) 1014 goto finish; 1015 1016 /* Compute position where we overwrite with '..\0' */ 1017 if (fnw >= nextra + 2) { 1018 p = fname + str_lsize(fname, fnw - nextra - 2); 1019 } else { 1020 p = fname; 1021 } 1022 1023 /* Shorten the string */ 1024 p[0] = p[1] = '.'; 1025 p[2] = '\0'; 1026 1027 /* Need to format the string once more. */ 1028 free(text); 1029 } 1030 1031 printf("%s", text); 1032 free(text); 1033 free(fname); 1034 finish: 1035 /* Fill the rest of the line */ 1036 pos = scr_columns - 1 - n; 967 int n = printf(" %d, %d (%d): File '%s'. Ctrl-Q Quit Ctrl-S Save " 968 "Ctrl-E Save As", coord.row, coord.column, last_row, fname); 969 970 int pos = scr_columns - 1 - n; 1037 971 printf("%*s", pos, ""); 1038 972 console_flush(con);
Note:
See TracChangeset
for help on using the changeset viewer.