7_9:Typical program skeleton for command processing

来源:互联网 发布:plc编程sfc和梯形图 编辑:程序博客网 时间:2024/06/05 09:35
 1 #include "apue.h"
  2 #define TOKEN 5
  3 void do_line (char *ptr);
  4 void cmd_add (void);
  5 int get_token(void);
  6 #define MAXLINE 1024
  7
  8 char *tok_ptr;
  9
 10 int main()
 11 {
 12         char line[MAXLINE];
 13         while (fgets(line,MAXLINE,stdin) != NULL){
 14                 do_line(line);
 15         }
 16         exit(0);
 17 }
 18
 19 char *tok_ptr;
 20
 21 void do_line(char *ptr)
 22 {
 23 //      tok_ptr = ptr;
 24 //      tok_ptr = ptr;
 25         int cmd;
 26         while ( (cmd = get_token()) > 0){
 27                 switch (cmd){
 28                         case TOKEN:
 29                                 cmd_add();
 30                                 break;
 31                 }
 32         }
 33
 34 }
 35
 36 int get_token(void)
 37 {
 38         /* fetch the next token from the line pointed to by tok_ptr;*/
 39 }
 40
 41 void cmd_add(void)
 42 {

 43         int token;

 44         token = get_token;
 45         /* rest of processing for this commad */
 46 }

0 0
原创粉丝点击