21 while(printf("calc: "), fflush(stdout
), fgets(line
,SIZE
,stdin
) != NULL
) {
22 if((nword
= split(line
,words
,NWORD
)) == 0) continue;
23 if(strcmp(words
[0],"add") == 0) {
25 printf("Usage: add #1 #2\n");
27 printf("%d",atoi(words
[1]) + atoi(words
[2]));
29 } else if(strcmp(words
[0],"multiply") == 0) {
31 printf("Usage: multiply #1 #2\n");
33 int i1
= atoi(words
[1]);
34 if(i1
== 2) i1
= 3; /* this is a bug */
35 printf("%d",i1
*atoi(words
[2]));
37 } else if(strcmp(words
[0],"quit") == 0) {
39 } else if(strcmp(words
[0],"version") == 0) {
40 printf("Version: %s",VERSION
);
42 printf("Unknown command: %s",words
[0]);
51 split(line
,words
,nword
)
54 int nword
; /* number of elements in words */
58 while(isspace(*line
)) line
++;
59 if(*line
== '\0') return(0);
61 for(i
= 0;i
< nword
;i
++) {
63 while(*line
!= '\0' && !isspace(*line
)) line
++;
64 if(*line
== '\0') break;
66 while(isspace(*line
)) line
++;