int main () { int c, prevchar = '\0', write_flag = WRITE_NONE; while ( ( c = getchar() ) != EOF ) { /* Case 1 */ if ( write_flag == WRITE_NONE && isalpha(c) ) { write_flag = WRITE_TAG; } /* Case 1a, there is no value string, = and ; sit next to each other */ else if ( c == ENTITY_DELIM && prevchar == PAIR_DELIM ) { write_flag = WRITE_NONE; } /* Case 2 - at the end of reading the tag chars to the array */ else if ( write_flag == WRITE_TAG && prevchar == PAIR_DELIM ) { write_flag = WRITE_VAL; } /* Case 3 at the end of writing the value to its array */ else if ( (write_flag == WRITE_VAL && c == ENTITY_DELIM) || (write_flag == WRITE_VAL && c == RECORD_DELIM) ) { write_flag = WRITE_NONE; } /* Case 4, there is no value string, = and ; sit next to each other */ else if ( c == ENTITY_DELIM && prevchar == PAIR_DELIM ) { write_flag = WRITE_NONE; } /* Case 5 - call to error - WRITE_TAG does not see its proper closing delimiter (PAIR_DELIM) */ else if ( (write_flag == WRITE_TAG && prevchar == ENTITY_DELIM) || ( write_flag == WRITE_TAG && c == RECORD_DELIM) ) { printf("\ncase 4 - Here we call fatal\n"); } prevchar = c; build_arrays (c, write_flag); } }
void __set_default_sort() { build_arrays(); char tmp[20]; bool dsc = 0; int n = 0; strncpy(tmp, CFG.sort, sizeof(tmp)); char * ptr = strchr(tmp, '-'); if (ptr) { *ptr = '\0'; dsc = (*(ptr+1) == 'd' || *(ptr+1) == 'D'); } for (; n<sortCnt; n++) { if (!strncmp(sortTypes[n].cfg_val, tmp, strlen(tmp))) { sort_index = default_sort_index = n; if (!dsc) { default_sort_function = (*sortTypes[sort_index].sortAsc); sort_desc = default_sort_desc = 0; } else { default_sort_function = (*sortTypes[sort_index].sortDsc); sort_desc = default_sort_desc = 1; } return; } } sort_index = default_sort_index = 0; default_sort_function = (*sortTypes[sort_index].sortAsc); }
int get_record(symtab_t *tp, FILE *fp) { int c, prevchar = '\0', write_flag = WRITE_NONE; struct arr_builder curr_vals; //while( ( c = fgetc(fp)) != EOF ) while( ( c = fgetc(fp) ) ) { /* Case 1 */ if ( write_flag == WRITE_NONE && isalpha(c) ) { write_flag = WRITE_TAG; } /* Case 2a, there is no value string, = and ; sit next to each other */ else if ( c == ENTITY_DELIM && prevchar == PAIR_DELIM ) { write_flag = WRITE_NONE; } /* Case 2 - at the end of writing the tag to the array */ else if ( write_flag == WRITE_TAG && prevchar == PAIR_DELIM ) { write_flag = WRITE_VAL; } /* Case 3 at the end of writing the value to its array */ else if ( (write_flag == WRITE_VAL && c == ENTITY_DELIM) || (write_flag == WRITE_VAL && c == RECORD_DELIM) || ( write_flag == WRITE_VAL && c == EOF ) ) { write_flag = WRITE_NONE; } /* Case 4 - call to error - WRITE_TAG does not see its proper closing delimiter (PAIR_DELIM) */ //else if ( (write_flag == WRITE_TAG && prevchar == ENTITY_DELIM) || ( write_flag == WRITE_TAG && c == RECORD_DELIM) ) { else if ( write_flag == WRITE_TAG && prevchar == ENTITY_DELIM ) { fatal("Badly formed data file", " "); } prevchar = c; curr_vals = build_arrays(c, write_flag); if ( write_flag == WRITE_NONE && c != RECORD_DELIM ) { //printf("\nINSIDE BUILD RECORD else if\n"); insert( tp, curr_vals.tag, curr_vals.val ); //show_table(tp); } else if ( write_flag == WRITE_NONE && c == RECORD_DELIM ){ //printf("\nINSIDE COMMIT RECORD else if\n"); insert( tp, curr_vals.tag, curr_vals.val ); insert( tp, "complete", "complete"); //show_table(tp); return YES; } else if ( write_flag == WRITE_NONE && c == EOF ){ printf("\nINSIDE COMMIT RECORD EOF\n"); insert( tp, curr_vals.tag, curr_vals.val ); insert( tp, "complete", "complete"); //show_table(tp); } } return NO; }
int main() { binary_numbers[0]=(char*)"0111111"; binary_numbers[1]=(char*)"0001010"; binary_numbers[2]=(char*)"1011101"; binary_numbers[3]=(char*)"1001111"; binary_numbers[4]=(char*)"1101010"; binary_numbers[5]=(char*)"1100111"; binary_numbers[6]=(char*)"1110111"; binary_numbers[7]=(char*)"0001011"; binary_numbers[8]=(char*)"1111111"; binary_numbers[9]=(char*)"1101011"; build_arrays(); //print_arrays(); while(1) { char calc[CALC_SIZE]; memset(calc,'\0',CALC_SIZE); scanf("%s",calc); if(strcmp(calc,"BYE")==0) { return 0; } char number1[CALC_SIZE]; char number2[CALC_SIZE]; memset(number1,'\0',CALC_SIZE); memset(number2,'\0',CALC_SIZE); int count=0; while(1) { char c = calc[count]; if(c=='+') break; number1[count]=calc[count]; count++; } count++; int count_n=0; while(1){ char c = calc[count]; if(c=='=') break; number2[count_n]=calc[count]; count_n++; count++; } //printf("number1=%s, get_int(number1)=%d\n",number1, get_int(number1)); //printf("number2=%s, get_int(number2)=%d\n",number2, get_int(number2)); //printf("\n\n"); int total=get_int(number1)+get_int(number2); printf("%s%s\n", calc, get_digits(total)); //printf("number 1=%s number2=%s\n",number1, number2); } }