int checkSize(const char * arg) { if (! isDecNum(arg) ) { cout << "size must be a positive integer: [" << arg << "]" << endl; exit(1); } return atoi(arg); }
int getNextElem(char *str, int *pos, char *token) { int i; token[0] = '\0'; i=0; while (str[*pos]!='\0') { /*bracelet*/ if (str[*pos]=='(') { *pos = *pos+1; strcpy(token,"("); return 1; } else if (str[*pos]==')') { *pos = *pos+1; strcpy(token,")"); return 1; } /*induction register*/ else if (str[*pos]=='$') { token[i++]=str[*pos]; *pos = *pos+1; while (isDecNum(str[*pos])) { token[i++]=str[*pos]; *pos = *pos+1; if (str[*pos]=='\0') break; } token[i]='\0'; return 1; } /*numerical value, 0x1234abcdef*/ else if ( isHexNum(str[*pos]) ) { while( isHexNum(str[*pos]) ) { token[i++]=str[*pos]; *pos = *pos+1; if (str[*pos]=='\0') break; } token[i]='\0'; return 1; } else if (str[*pos]=='T') {//unknown var token[i++]=str[*pos]; token[i]='\0'; *pos = *pos+1; return 1; } /*oprator, hopefully*/ else if (str[*pos]!=' ') { while (str[*pos]!='$' && !isHexNum(str[*pos]) && str[*pos]!='T' && str[*pos]!='(' && str[*pos]!=')' && str[*pos]!=' ') { token[i++]=str[*pos]; *pos = *pos+1; if (str[*pos]=='\0') break; } token[i]='\0'; return 1; } //blank space else *pos = *pos + 1; } return 0; }