1 #include "apue.h" 2 3 #define TOK_ADD 5 4 5 void do_line(char *); 6 void cmd_add(void); 7 int get_token(void); 8 9 int 10 main(void) 11 { 12 char line[MAXLINE]; 13 14 while (fgets(line, MAXLINE, stdin) != NULL) 15 do_line(line); 16 exit(0); 17 } 18 19 char *tok_ptr; /* global pointer for get_token() */ 20 21 void 22 do_line(char *ptr) /* process one line of input */ 23 { 24 int cmd; 25 26 tok_ptr = ptr; 27 while ((cmd = get_token()) > 0) { 28 switch (cmd) { /* one case for each command */ 29 case TOK_ADD: 30 cmd_add(); 31 break; 32 } 33 } 34 } 35 36 void 37 cmd_add(void)
时间: 2024-11-02 13:38:57