int whattoken(char *token) { int i, chartype, prevchartype; char *ptr; if(isdigit(token[0])) return 0; //Unknown. if(isalpha(token[0])||token[0]=='_') { for(i=0; i<kwcount; i++) { if(strcmp(token, kw[i])==0) //Is a keyword { if(24<i&&i<31) //control instruction. return 2; //One among for, while, do, if, break, continue. if(i==31) return 3; return 4; //A keyword, but NOT a CI. } } ptr=token; while(*ptr!='\0') { i=whattype(*ptr); if(i!=2&&i!=3) return 0; //Unidentified expr. // printf("while"); ptr++; } } return 1; //An identifier. }
int main() { char *str1 = "test_123" ; char *type1 = whattype(str1); char *str2 = "_123" ; char *type2 = whattype(str2); char *str3 = "12345" ; char *type3 = whattype(str3); printf("Type 1: %s \n", type1); printf("Type 2: %s \n", type2); printf("Type 3: %s \n", type3); printf("Next for str1: %c \n", next(str1) ); printf("Next for str2: %c \n", next(str2) ); printf("Next for str3: %c \n", next(str3) ); int arr1[5] = {5, 6, 7, 8, 9}; int arr2[5] = {42, 57, 63, 90, 94}; int m1 = min(arr1); int m2 = max(arr1); int m3 = min(arr2); int m4 = max(arr2); printf("Min arr1: %d \n", m1); printf("Max arr1: %d \n", m2); printf("Min arr2: %d \n", m3); printf("Max arr2: %d \n", m4); return 0; }
void addflist(flist_t **fl,char *loc,char *rem,char kill,off_t off,FILE *lo,int fromlo) { flist_t **t,*q; int type; slist_t *i; DEBUG(('S',2,"Add file: '%s', sendas: '%s', kill: '%c', fromLO: %s, offset: %d", loc,rem?rem:"(null)",kill,lo?"yes":"no",off)); type=whattype(rem); if(type==IS_PKT&&fromlo)type=IS_FILE; if((checktimegaps(cfgs(CFG_MAILONLY))|| checktimegaps(cfgs(CFG_ZMH)))&&type!=IS_PKT)return; for(i=cfgsl(CFG_AUTOHOLD);i;i=i->next) if(!xfnmatch(i->str,loc,FNM_PATHNAME))return; switch(type) { case IS_REQ: if(rnode&&rnode->options&O_HRQ)return; if(rnode&&rnode->options&O_NRQ&&!cfgi(CFG_IGNORENRQ))return; break; case IS_PKT: if(rnode&&rnode->options&O_HAT)return; break; default: if(rnode&&rnode->options&(O_HXT|O_HAT)&&rem)return; break; } for(t=fl;*t&&((*t)->type<=type);t=&((*t)->next)); q=(flist_t*)xmalloc(sizeof(flist_t)); q->next=*t;*t=q; if(fromlo&&kill=='#'&&cfgi(CFG_ALWAYSKILLFILES))q->kill='^'; else q->kill=kill; q->loff=off; if(rnode&&(rnode->options&O_FNC)&&rem) { q->sendas=xstrdup(fnc(rem)); xfree(rem); } else q->sendas=rem; q->lo=lo;q->tosend=loc; q->type=type; }
int main(int argc, char *argv[]) { int tokenlen, i; char file[256], token[32], *sc, *ptr; long fsize; FILE *fp; if(argc<2) { __fpurge(stdin); printf("Enter the filename: "); scanf("%s", file); } else strcpy(file, argv[1]); fp=fopen(file, "rb"); if(fp==NULL) { printf("Error opening file!!!\n"); return 0; } fseek(fp, 0L, SEEK_END); fsize=ftell(fp); fclose(fp); sc=(char *)malloc(sizeof(char)*fsize); ptr=sc; fp=fopen(file, "r"); if(fp==NULL) { printf("Error opening file!!!\n"); return 0; } while((*ptr++=fgetc(fp))!=EOF) ; fclose(fp); ptr=sc; /* printf("\nYour file:\n"); while(*ptr!=EOF) printf("%c", *ptr++); */ // chartype=1; // prevchartype=-1; /* while(*ptr!=EOF) { if(whattype(*ptr)==2||whattype(*ptr)==3) { token[i++]=*ptr; ptr++; } else if(whattype(*ptr)==5) { parenthesis++; ptr++; while(parenthesis!=0) { if(whattype(*ptr)==5) parenthesis++; if(whattype(*ptr)==7) parenthesis--; ptr++; } } } * while(*ptr!=EOF) { i=0; if(whattype(*ptr)==2) { token[i++]=*ptr++; while(whattype(*ptr)==2||whattype(*ptr)==3) { token[i++]=*ptr++; } token[i]='\0'; printf("\n\nValid token: %s\n", token); } i=0; if(whattype(*ptr)!=2) { while(whattype(*ptr)!=19&&whattype(*ptr)!=0&&whattype(*ptr)!=5&&whattype(*ptr)!=7) { if(i==31) { token[i]='\0'; // printf("\nInvalid token: %s", token); i=0; } token[i++]=*ptr; ptr++; } ptr++; token[i]='\0'; // printf("\nInvalid token: %s", token); } } */ strcpy(sc, "if this is so then do this"); ptr=sc; while(*ptr!='\0') { i=0; if(whattype(*ptr)==2) { token[i++]=*ptr++; while(whattype(*ptr)==2||whattype(*ptr)==3) { token[i++]=*ptr++; } token[i]='\0'; printf("\n\nValid token: %s, of type %d\n", token, whattoken(token)); } i=0; if(whattype(*ptr)!=2) { while(whattype(*ptr)!=19&&whattype(*ptr)!=0&&whattype(*ptr)!=5&&whattype(*ptr)!=7) ptr++; } if(whattype(*ptr)!=2) ptr++; } return 0; }