Przeglądaj źródła

缩减代码空间

Meco Man 4 lat temu
rodzic
commit
082fb521c6
3 zmienionych plików z 15 dodań i 29 usunięć
  1. 13 14
      vi.c
  2. 1 6
      vi_utils.c
  3. 1 9
      vi_utils.h

+ 13 - 14
vi.c

@@ -478,7 +478,7 @@ static struct optparse options;
 
 static void write1(const char *out)
 {
-    fputs(out, stdout);
+    rt_kprintf(out);
 }
 
 static int vi_main(int argc, char **argv)
@@ -547,8 +547,7 @@ static int vi_main(int argc, char **argv)
             show_help();
             // fall through
         default:
-            bb_show_usage();
-            FREE_PTR_TO_GLOBALS(); // RT-Thread team added
+            rt_kprintf("Usage: vi [FILE]\n"); /*bb_show_usage()*/
             return 1;
         }
     }
@@ -1056,7 +1055,7 @@ static void colon(char *buf)
         cookmode();
         retcode = system(orig_buf + 1); // run the cmd
         if (retcode)
-            printf("\nshell returned %i\n\n", retcode);
+            rt_kprintf("\nshell returned %i\n\n", retcode);
         rawmode();
         Hit_Return();           // let user see results
     }
@@ -1381,14 +1380,14 @@ static void colon(char *buf)
         size = r - q + 1;
         //if (useforce) {
             // if "fn" is not write-able, chmod u+w
-            // sprintf(syscmd, "chmod u+w %s", fn);
+            // rt_sprintf(syscmd, "chmod u+w %s", fn);
             // system(syscmd);
             // forced = TRUE;
         //}
         l = file_write(fn, q, r);
         //if (useforce && forced) {
             // chmod u-w
-            // sprintf(syscmd, "chmod u-w %s", fn);
+            // rt_sprintf(syscmd, "chmod u-w %s", fn);
             // system(syscmd);
             // forced = FALSE;
         //}
@@ -2554,7 +2553,7 @@ static void start_new_cmd_q(char c)
     // get buffer for new cmd
     // if there is a current cmd count put it in the buffer first
     if (cmdcnt > 0) {
-        lmc_len = sprintf(last_modifying_cmd, "%u%c", cmdcnt, c);
+        lmc_len = rt_sprintf(last_modifying_cmd, "%u%c", cmdcnt, c);
     } else { // just save char c onto queue
         last_modifying_cmd[0] = c;
         lmc_len = 1;
@@ -2758,7 +2757,7 @@ static int readit(void) // read (maybe cursor) key from stdin
             goto again;
         go_bottom_and_clear_to_eol();
         cookmode(); // terminal to "cooked"
-        bb_simple_error_msg_and_die("can't read user input");
+        rt_kprintf("can't read user input");
     }
     return c;
 }
@@ -2965,7 +2964,7 @@ static void place_cursor(int row, int col)
     if (col < 0) col = 0;
     if (col >= columns) col = columns - 1;
 
-    sprintf(cm1, ESC_SET_CURSOR_POS, row + 1, col + 1);
+    rt_sprintf(cm1, ESC_SET_CURSOR_POS, row + 1, col + 1);
     write1(cm1);
 }
 
@@ -3069,7 +3068,7 @@ static void status_line_bold(const char *format, ...)
 
     va_start(args, format);
     strcpy(status_buffer, ESC_BOLD_TEXT);
-    vsnprintf(status_buffer + (sizeof(ESC_BOLD_TEXT)-1),
+    rt_vsnprintf(status_buffer + (sizeof(ESC_BOLD_TEXT)-1),
         STATUS_BUFFER_LEN - sizeof(ESC_BOLD_TEXT) - sizeof(ESC_NORM_TEXT),
         format, args
     );
@@ -3090,7 +3089,7 @@ static void status_line(const char *format, ...)
     va_list args;
 
     va_start(args, format);
-    vsnprintf(status_buffer, STATUS_BUFFER_LEN, format, args);
+    rt_vsnprintf(status_buffer, STATUS_BUFFER_LEN, format, args);
     va_end(args);
 
     have_status_msg = 1;
@@ -3186,7 +3185,7 @@ static int format_edit_status(void)
     trunc_at = columns < STATUS_BUFFER_LEN-1 ?
         columns : STATUS_BUFFER_LEN-1;
 
-    ret = snprintf(status_buffer, trunc_at+1,
+    ret = rt_snprintf(status_buffer, trunc_at+1,
 #if ENABLE_FEATURE_VI_READONLY
         "%c %s%s%s %d/%d %d%%",
 #else
@@ -4428,7 +4427,7 @@ static void crash_test()
     }
 
     if (msg[0]) {
-        printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s",
+        rt_kprintf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s",
             totalcmds, last_input_char, msg, ESC_BOLD_TEXT, ESC_NORM_TEXT);
         fflush_all();
         while (safe_read(STDIN_FILENO, d, 1) > 0) {
@@ -4438,7 +4437,7 @@ static void crash_test()
     }
     tim = time(NULL);
     if (tim >= (oldtim + 3)) {
-        sprintf(status_buffer,
+        rt_sprintf(status_buffer,
                 "Tot=%d: M=%d N=%d I=%d D=%d Y=%d P=%d U=%d size=%d",
                 totalcmds, M, N, I, D, Y, P, U, end - text + 1);
         oldtim = tim;

+ 1 - 6
vi_utils.c

@@ -205,7 +205,7 @@ int safe_poll(struct pollfd *ufds, nfds_t nfds, int timeout)
         /* I doubt many callers would handle this correctly! */
         if (errno == ENOMEM)
             continue;
-        bb_simple_perror_msg("poll");
+        rt_kprintf("poll");
         return n;
     }
 }
@@ -262,11 +262,6 @@ char *xstrndup(const char *s, size_t n)
     return mem_sandbox_strndup(vi_sandbox, s, n);
 }
 
-void bb_show_usage(void)
-{
-    printf("Usage: vi [FILE]\n");
-}
-
 int64_t read_key(int fd, char *buffer, int timeout)
 {
     struct pollfd pfd;

+ 1 - 9
vi_utils.h

@@ -263,11 +263,6 @@
     (*(struct globals**)&ptr_to_globals) = (void*)(x); \
     barrier(); \
 } while (0)
-#define FREE_PTR_TO_GLOBALS() do { \
-    if (ENABLE_FEATURE_CLEAN_UP) { \
-        xfree(ptr_to_globals); \
-    } \
-} while (0)
 
 /* "Keycodes" that report an escape sequence.
  * We use something which fits into signed char,
@@ -344,9 +339,7 @@ int isatty (int  fd);
 
 #define bb_putchar putchar
 #define bb_strtou strtoul
-#define bb_simple_error_msg_and_die(...) printf(__VA_ARGS__)
-#define bb_simple_perror_msg(...) printf(__VA_ARGS__)
-#define fflush_all() fflush(NULL)
+#define fflush_all() /*fflush(NULL)*/
 
 unsigned char vi_mem_init(void);
 void vi_mem_release(void);
@@ -356,7 +349,6 @@ void xfree(void *ptr);
 void* xzalloc(size_t size);
 char *xstrdup(const char *s);
 char *xstrndup(const char *s, size_t n);
-void bb_show_usage(void);
 int64_t read_key(int fd, char *buffer, int timeout);
 void *memrchr(const void* ptr, int ch, size_t pos);