-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.c
More file actions
49 lines (44 loc) · 897 Bytes
/
command.c
File metadata and controls
49 lines (44 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*************************************************************************
> File Name: command.c
> Author: jianghechao
> Mail: 591378033@qq.com
> Created Time: Sun 04 May 2014 12:07:41 AM CST
************************************************************************/
#include<stdio.h>
#include"apue.h"
#define TOK_ADD 5
#define MAXLINE 100
void do_line(char *);
void cmd_add(void);
int get_token(void);
int main()
{
char line[MAXLINE];
while(fgets(line,sizeof(line),stdin)!=NULL)
do_line(line);
return 0;
}
char *tok_ptr;/*global pointer for get_token()*/
void do_line(char *ptr)
{
int cmd;
tok_ptr = NULL;
while((cmd=get_token())>0)
{
switch(cmd){
case TOK_ADD:
cmd_add();
break;
}
}
}
void cmd_add(void)
{
int token;
token = get_token();
/*rest of processing for this command*/
}
int get_token(void)
{
/*fetch next token from line pointed to by tok_ptr*/
}