//String Processor //v0.3.5 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 //adr_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; PreProcessString(address); TraceNL(); TraceS(Preprocess_Buffer); TraceNL(); } 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]; int q = 0; int e = 0; int r = 0; int t = 0; int u; int i; int w; int a; int s; int d; int f; int g; int h; int j; int b; 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}; int sttr[]="Pointer for string: "; TraceNL(); TraceS(sttr); Trace(string1); TraceNL(); TraceS(sttr); Trace(string2); TraceNL(); TraceS(sttr); Trace(string3); TraceNL(); TraceS(sttr); Trace(string4); TraceNL(); TraceS(sttr); Trace(string5); TraceNL(); TraceS(sttr); Trace(string6); TraceNL(); TraceS(sttr); Trace(string7); TraceNL(); TraceS(sttr); Trace(string8); TraceNL(); TraceS(sttr); Trace(string9); TraceNL(); TraceS(sttr); Trace(string10); //! Get the address: int y; // Temporarily holds array pointers. //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 ( ; q <= SizeOfArray(strings); q++ ) { //! <= is intentional here. int debug_q[]="THe present 'q' loop is: "; TraceNL(); TraceS(debug_q); Trace(q); TraceNL(); if ( 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 s = strings[q]; for ( ; w <= SizeOfArray(strings[q]); w++ ) { if ( w == SizeOfArray(s) ) { 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... a = strings[q]; b = a[w]; int trc[]="Tracing a: "; TraceNL(); TraceS(trc); Trace(a); TraceNL(); if ( IsChar(CHAR_ADDRESS,b) ) { int tr[]="Tracing b: "; TraceNL(); TraceS(tr); Trace(b); //We found an address, let's store it. adr_index[STRP_STRING_PTR] = strings[q]; adr_index[STRP_STR_INDEX] = w; int tr2[]="tracing adr_index[STRP_STRING_PTR]): "; TraceNL(); TraceS(tr2); Trace(adr_index[STRP_STRING_PTR]); int tr3[]="Tracing adr_index[STRP_STR_INDEX]): "; TraceNL(); TraceS(tr3); Trace(adr_index[STRP_STR_INDEX]); //0 is the string pointer, 1 is the index with the $ token d = adr_index[STRP_STRING_PTR]; int tr4[]="Assigned d"; TraceNL(); TraceS(tr4); TraceNL(); for ( e = adr_index[STRP_STR_INDEX]; e < SizeOfArray(adr_index[STRP_STRING_PTR]); e++ ) { //Find a colon //y = adr_index[STRP_STR_INDEX]; y = adr_index[STRP_STRING_PTR]; if ( IsChar(CHAR_ADR_END,y[e]) ) { //We found a colon, so store it... adr_index[STRP_END_ADR] = e; int str_end_addr[]="We've found the end of an address, at index: "; TraceNL(); TraceS(str_end_addr); Trace(e); TraceNL(); //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. int str_flush_t[]="Flushing 't'"; TraceNL(); TraceS(str_flush_t); TraceNL(); t = 0; //Clear this, as we'll need it. int str_rloop[]="We've reached the 'r' loop"; TraceNL(); TraceS(str_rloop); TraceNL(); for ( r = adr_index[STRP_STR_INDEX]; r < adr_index[STRP_END_ADR]; r++ ) { y = adr_index[STRP_STRING_PTR]; int str_debug[]="Tracing the pointer during r-loop $address xfer."; TraceNL(); TraceS(str_debug); Trace(y); read_adr_buffer[t] = y[r+1]; t++; //Store into the buffer. checking_adr = 1; } if ( checking_adr ) { //read_adr_buffer[t+1] = 0; //Set NULL. int debug2[]="Print the address that we read into the buffer: "; TraceNL(); TraceS(debug2); TraceS(read_adr_buffer); TraceNL(); break; } } } //Compare the read buffer to the lookup buffer. //Store the value we read into read_adr_buffer by //converting it into a number: int str_atoi[]="We reached atio()"; TraceNL(); TraceS(str_atoi); TraceNL(); adr_lookup = atoi(read_adr_buffer); int str_atoi2[]="The atoi result is: "; TraceS(str_atoi2); Trace(adr_lookup); TraceNL(); //See if it matches: if ( adr_lookup == address ) { int str_adl[]= "We reached the address lookup == address check"; TraceNL(); TraceS(str_adl); TraceNL(); matched_adr = 1; break; } else { int str_adl0[]="We reached address_lookup = 0"; TraceNL(); TraceS(str_adl0); TraceNL(); 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 ) { int str_mb1[]="We reached the matched_adr break #1"; TraceNL(); TraceS(str_mb1); TraceNL(); break; //Exit the while loop. } } if ( matched_adr ) { int str_mb2[]="We reached the matched_adr break #2"; TraceNL(); TraceS(str_mb2); TraceNL(); i = 0; adr_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. int striy[]="We've reached the i-y loop"; TraceNL(); TraceS(striy); TraceNL(); for ( ; adr_index[STRP_END_ADR] < SizeOfArray(adr_index[STRP_STRING_PTR]); adr_index[STRP_END_ADR]++ ) { y = adr_index[STRP_STRING_PTR]; //u = adr_index[STRP_STRING_PTR]; if ( y[adr_index[STRP_END_ADR]] != CHAR_EOS || y[adr_index[STRP_END_ADR]] != CHAR_EOS2 ) { Preprocess_Buffer[i] = y[adr_index[STRP_END_ADR]]; i++; } if ( y[adr_index[STRP_END_ADR]] == CHAR_EOS || y[adr_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. } global script active{ void run(){ Testpreprocessor(3); } } //As preProcessString, except that it is supplied with the pointer to an array with pointers stored in it, externally. //Thus you can build a custom table function, and call PreProcessString from anywhere, globally. int PreProcessString(int lookup_list, 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]; int q = 0; int e = 0; int r = 0; int t = 0; int u; int i; int w; int a; int s; int d; int f; int g; int h; int j; int b; 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}; int sttr[]="Pointer for string: "; TraceNL(); TraceS(sttr); Trace(string1); TraceNL(); TraceS(sttr); Trace(string2); TraceNL(); TraceS(sttr); Trace(string3); TraceNL(); TraceS(sttr); Trace(string4); TraceNL(); TraceS(sttr); Trace(string5); TraceNL(); TraceS(sttr); Trace(string6); TraceNL(); TraceS(sttr); Trace(string7); TraceNL(); TraceS(sttr); Trace(string8); TraceNL(); TraceS(sttr); Trace(string9); TraceNL(); TraceS(sttr); Trace(string10); //! Get the address: int y; // Temporarily holds array pointers. //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 ( ; q <= SizeOfArray(strings); q++ ) { //! <= is intentional here. if ( 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 s = strings[q]; for ( ; w <= SizeOfArray(strings[q]); w++ ) { if ( w == SizeOfArray(s) ) { 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... a = strings[q]; b = a[w]; int trc[]="Tracing a: "; TraceNL(); TraceS(trc); Trace(a); TraceNL(); if ( IsChar(CHAR_ADDRESS,b) ) { int tr[]="Tracing b: "; TraceNL(); TraceS(tr); Trace(b); //We found an address, let's store it. adr_index[STRP_STRING_PTR] = strings[q]; adr_index[STRP_STR_INDEX] = w; int tr2[]="tracing adr_index[STRP_STRING_PTR]): "; TraceNL(); TraceS(tr2); Trace(adr_index[STRP_STRING_PTR]); int tr3[]="Tracing adr_index[STRP_STR_INDEX]): "; TraceNL(); TraceS(tr3); Trace(adr_index[STRP_STR_INDEX]); //0 is the string pointer, 1 is the index with the $ token d = adr_index[STRP_STRING_PTR]; int tr4[]="Assigned d"; TraceNL(); TraceS(tr4); TraceNL(); for ( e = adr_index[STRP_STR_INDEX]; e < SizeOfArray(adr_index[STRP_STRING_PTR]); e++ ) { //Find a colon //y = adr_index[STRP_STR_INDEX]; y = adr_index[STRP_STRING_PTR]; if ( IsChar(CHAR_ADR_END,y[e]) ) { //We found a colon, so store it... adr_index[STRP_END_ADR] = e; int str_end_addr[]="We've found the end of an address, at index: "; TraceNL(); TraceS(str_end_addr); Trace(e); TraceNL(); //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. int str_flush_t[]="Flushing 't'"; TraceNL(); TraceS(str_flush_t); TraceNL(); t = 0; //Clear this, as we'll need it. int str_rloop[]="We've reached the 'r' loop"; TraceNL(); TraceS(str_rloop); TraceNL(); for ( r = adr_index[STRP_STR_INDEX]; r < adr_index[STRP_END_ADR]; r++ ) { y = adr_index[STRP_STRING_PTR]; int str_debug[]="Tracing the pointer during r-loop $address xfer."; TraceNL(); TraceS(str_debug); Trace(y); read_adr_buffer[t] = y[r+1]; t++; //Store into the buffer. checking_adr = 1; } if ( checking_adr ) { //read_adr_buffer[t+1] = 0; //Set NULL. int debug2[]="Print the address that we read into the buffer: "; TraceNL(); TraceS(debug2); TraceS(read_adr_buffer); TraceNL(); break; } } } //Compare the read buffer to the lookup buffer. //Store the value we read into read_adr_buffer by //converting it into a number: int str_atoi[]="We reached atio()"; TraceNL(); TraceS(str_atoi); TraceNL(); adr_lookup = atoi(read_adr_buffer); int str_atoi2[]="The atoi result is: "; TraceS(str_atoi2); Trace(adr_lookup); TraceNL(); //See if it matches: if ( adr_lookup == address ) { int str_adl[]= "We reached the address lookup == address check"; TraceNL(); TraceS(str_adl); TraceNL(); matched_adr = 1; break; } else { int str_adl0[]="We reached address_lookup = 0"; TraceNL(); TraceS(str_adl0); TraceNL(); 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 ) { int str_mb1[]="We reached the matched_adr break #1"; TraceNL(); TraceS(str_mb1); TraceNL(); break; //Exit the while loop. } } if ( matched_adr ) { int str_mb2[]="We reached the matched_adr break #2"; TraceNL(); TraceS(str_mb2); TraceNL(); i = 0; adr_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. int striy[]="We've reached the i-y loop"; TraceNL(); TraceS(striy); TraceNL(); for ( ; adr_index[STRP_END_ADR] < SizeOfArray(adr_index[STRP_STRING_PTR]); adr_index[STRP_END_ADR]++ ) { y = adr_index[STRP_STRING_PTR]; //u = adr_index[STRP_STRING_PTR]; if ( y[adr_index[STRP_END_ADR]] != CHAR_EOS || y[adr_index[STRP_END_ADR]] != CHAR_EOS2 ) { Preprocess_Buffer[i] = y[adr_index[STRP_END_ADR]]; i++; } if ( y[adr_index[STRP_END_ADR]] == CHAR_EOS || y[adr_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. }