//String Processor //v0.2.2 int Preprocess_Buffer[214747]; //Settings const int CHAR_EOS = 10; //Mark the end of a string read into the buffer. const int CHAR_EOS2 = 36; //... Default is either CHAR_LF (10) or CHAR_DOLLAR (36;) const int CHAR_ADDRESS = 36; // By default, we use $ to denote the start of an address. const int CHAR_ADR_END = 58; //By default, we mark the end of an address wirth a colon (:) //Array indices //arr_index[] //! We'll be using these to store the values used by the processor, instead of wasting a bunch of registers. const int STRP_STRING_PTR = 0; const int STRP_STR_INDEX = 1; const int STRP_END_ADR = 2; //3, 4, 5, reserved const int STRP_checking_adr = 6; const int STRP_end_of_string = 7; const int STRP_matched_adr = 8; const int STRP_adr_lookup = 9; const int STRP_q = 10; //loops const int STRP_w = 11; const int STRP_e = 12; const int STRP_r = 13; const int STRP_t = 14; const int STRP_y = 15; const int STRP_u = 16; const int STRP_i = 17; int PreProcessString(int address){ //Simple vars int adr_lookup; //A place to store the last located address in a string. int matched_adr; int end_of_string; int checking_adr; //Arrays and Buffers int adr_buffer[6]; //A place to store the string address as char. int read_adr_buffer[6]; arr_index[STRP_q] = 0; arr_index[STRP_w] = 0; arr_index[STRP_e] = 0; arr_index[STRP_r] = 0; arr_index[STRP_t] = 0; arr_index[STRP_y] = 0; arr_index[STRP_u] = 0; arr_index[STRP_i] = 0; int q = 0; int e = 0; int r = 0; int t = 0; int u; int i; int adr_index[20]; //3 is the length of the string tied to the address. //We will eventuall merge the q through i vars into this array as follows: //0 is the string pointer, 1 is the index with the $ token //2 is the index of the colon, so we know where to end the loop. //3, 4, 5, are reserved //checking_adr = 6, end_of_string = 7, matched_rd = 8, adr_lookup = 9 //q = 10, w = 11, e = 12, r = 13, t = 14, y = 15, u = 16, i = 17, //18, 19, 20 unused (thus far) //Create string tables, and load them with strings. The format is: // $######:String // DOLLAR NUMBER COLON TEXT int string1[]= "$00001:This is the first entry in our string table. $00002:This is the second.$00003:This is the third. "; int string2[]= "$00004:This is number four. $00005:THis is number five. "; int string3[]="$00006:This is our sixth string.$00007:Seven and counting. "; int string4[]="$00008:Eighth. "; int string5[]="$00009:Nine and still going. "; int string6[]="$00010:Address ten, anyone?$00011:Now address eleven. "; int string7[]="$00012:Twelve, aned climbing. "; int string8[]="$00013:Lucky thirteen. "; int string9[]="$00014:The burgular. "; int string10[]="$00015:Last set, last address, number fifteen. "; //Store all the string table pointers in an array. int strings[]={string1,string2,string3,string4,string5,string6,string7,string8,string9,string10}; //! Get the address: //Convert the addres to char and store it in the buffer. itoa(adr_buffer,address); //Load each big string table from the array with their pointers for ( ; arr_index[STRP_q] <= SizeOfArray(strings); arr_index[STRP_q]++ ) { //! <= is intentional here. if ( arr_index[STRP_q] == SizeOfArray(strings) return -1; //break; //A safety break from the loop if we scan every string for the address //and we don't find it. while ( !matched_adr && !end_of_string ) { //Scan the string, and find the $ char for ( ; arr_index[STRP_w] <= SizeOfArray(strings[arr_index[STRP_q]]); arr_index[STRP_w]++ ) { if ( arr_index[STRP_w] == SizeOfArray(strings[arr_index[STRP_q]]) { end_of_string = 1; //We finished parsing this string. Time to try the next one. break; //Returns to 'q' loop, and sets the next string pointer in the list, to scan it. } if ( matched_adr ) break; //Eits the for loop, back to tht while loop, and the string is copied to the processing buffer. //If the loop is still running... if ( IsChar(CHAR_ADDRESS,strings[arr_index[STRP_q[arr_index[STRP_w]]]]) ) { //We found an address, let's store it. adr_index[STRP_STRING_PTR] = arr_index[STRP_q]; adr_index[STRP_STR_INDEX] = arr_index[STRP_w]; //0 is the string pointer, 1 is the index with the $ token for ( e = adr_index[STRP_STR_INDEX]; e < SizeOfArray(adr_index[STRP_STR_INDEX]); e++ ) { //Find a colon if ( IsChar(CHAR_ADR_END,adr_index[STRP_STR_INDEX][e]) ) { //We found a colon, so store it... adr_index[STRP_END_ADR] = e; //2 is the index of the colon, so we know where to end the loop. //Copy the address into the buffer, and compare the two buffers. t = 0; //Clear this, as we'll need it. for ( r = adr_index[STRP_STR_INDEX]; r < adr_index[STRP_END_ADR]; r++ ) { read_adr_buffer[t] = adr_index[STRP_STRING_PTR][r]; t++; //Store into the buffer. checking_adr = 1; } if ( checking_adr ) break; } } //Compare the read buffer to the lookup buffer. //Store the value we read into read_adr_buffer by //converting it into a number: adr_lookup = atoi(read_adr_buffer); //See if it matches: if ( adr_lookup == address ) { matched_adr = 1; break; } else { matched_adr = 0; continue; } //for ( u = 0; q < 6; u++ ) { //if ( read_adr_buffer[u] == adr_buffer[u] ) matched_adr = 1; // else { // matched_adr = 0; //not a match // //Go back to w, and start on the position next in the list. // break; // } //} } } if ( matched_adr ) { break; //Exit the while loop. } } if ( matched_adr ) { i = 0; arr_index[STRP_END_ADR]++; //Start one char after the colon. //Store the string: //Use the values that we recorded for the pointer, the first index, and the last index, and copy the string to our main buffer for processing. for ( ; adr_index[STRP_END_ADR] < SizeOfArray(arr_index[STRP_STRING_PTR]; adr_index[STRP_END_ADR]++ ) { if ( arr_index[STRP_STRING_PTR][arr_index[STRP_END_ADR]] != CHAR_EOS || arr_index[STRP_STRING_PTR][arr_index[STRP_END_ADR]] != CHAR_EO2 ) { Preprocess_Buffer[i] = arr_index[STRP_STRING_PTR][arr_index[STRP_END_ADR]]; i++; } if ( arr_index[STRP_STRING_PTR][arr_index[STRP_END_ADR]] == CHAR_EOS || arr_index[STRP_STRING_PTR][arr_index[STRP_END_ADR]] == CHAR_EOS2 ) break; } break; //Exit the q loop... } } //If the q loop breaks, the function ends. return 1; //The function tells us that it was successful in finding a string, and that it stored it in the buffer. //We can call if ( PreProcessString(ADDRESS) ) and store it while we check that it was stored. }