oop set_sic_params_prim(oop r, char* which, objVectorOop params, void* FH) { ResourceMark rm; IntBList* l = stringToList(which); if (!l) { failure(FH, SIC_PARAMS_ERROR_MSG); return 0; } fint len = params->length(); fint *n= NEW_RESOURCE_ARRAY(fint, len); fint i; for (i = 0; i < len; i++) { oop param = params->obj_at(i); if (!param->is_smi() || smiOop(param)->value() < 1) { char msg[BUFSIZ]; sprintf(msg, "arg2[%ld]: invalid parameter (not a positive integer)", long(i)); failure(FH, msg); return 0; } n[i] = smiOop(param)->value(); } oop res = get_sic_params_prim(r, which, NULL); l->clear(); for (i = 0; i < len; i++) l->push(n[i]); return res; }
// this recursively searches out/replaces the key from a LinkedList node *rec_replace( node *head, char key, char *str ) { node *temp, *trash, *n; if(head == NULL) return NULL; // if the current node's data does not match the key, // continue searching through the LinkedList if(head->data != key) { head->next = rec_replace( head->next, key, str ); return head; } // trash the current node, replace it with the intended String. trash = head; n = head->next; free( trash ); head = stringToList( str ); // go to the last node of the replacement String and attach the // rest of the LinkedList. continue searching out they key. for(temp = head; temp->next != NULL; temp = temp->next) ; temp->next = rec_replace( n, key, str ); return head; }
int main( int argc, char **argv ) { FILE *fin; char str[1024], command, key; node *word; int i; // iterate through multiple input files at the command line for(i = 1; i < argc; i++) { //open the input file fin = fopen( argv[i], "r" ); if(fin == NULL) { fprintf(stderr, "ERROR: Unable to open %s\n", argv[i]); exit(1); } // scan in the String to be manipulated and store as a LinkedList fscanf(fin, "%s", str); word = stringToList( str ); // scan in commands until EOF while(fscanf(fin, "%c", &command) != EOF) { switch( command ) { case( '@' ): { fscanf( fin, " %c %s", &key, str ); word = replaceChar( word, key, str ); break; } case( '-' ): { fscanf( fin, " %c", &key ); word = replaceChar( word, key, NULL ); break; } case( '~' ): { word = reverseList( word ); break; } case( '!' ): { printList( word ); break; } } // end switch } // end while } // end for return 0; }
std::string removeRedundantSubstrings(const std::string &s) { // Convert the string into a list of strings and separate out the redundant entries std::list<std::string> XStringList = stringToList(s); XStringList.sort(); XStringList.unique(); return listToString(XStringList); }
oop get_sic_params_prim(oop, char* which, void* FH) { IntBList* l = stringToList(which); if (!l) { failure(FH, SIC_PARAMS_ERROR_MSG); return 0; } objVectorOop res= Memory->objVectorObj->cloneSize(l->length()); for (fint i = 0; i < l->length(); i++) { res->obj_at_put(i, as_smiOop(l->nth(i))); } return res; }
std::string removePseudoRedundantSubstrings(const std::string &s) { // Convert the string into a list of strings and separate out the redundant entries std::list<std::string> XStringList = stringToList(s); XStringList.sort(); XStringList.unique(); // Build a list of the strings that will be modified std::list<std::string> modifiedStringList; std::list<std::string> listOfStringsToRemove; std::list<std::string>::iterator i; // Two loops over the list of strings represents a quadratic complexity! for (i = XStringList.begin(); i != XStringList.end(); i++) { std::string i_modifiedString; // printf ("At top of loop over XStringList \n"); // Build list of the differences between strings std::list<std::string> listOfDifferences; for (std::list<std::string>::iterator j = XStringList.begin(); j != XStringList.end(); j++) { // compare *i and *j and check for pseudo-redundence // printf ("top of loop through string: compare *i and *j and check for pseudo-redundence \n"); // build information about *i std::string::const_iterator i_diffpos = find_if ( (*i).begin(), (*i).end(), isNumber ); // build information about *j std::string::const_iterator j_diffpos = find_if ( (*j).begin(), (*j).end(), isNumber ); unsigned int i_subStringLength = i_diffpos - (*i).begin(); unsigned int j_subStringLength = j_diffpos - (*j).begin(); // printf ("i_subStringLength = %d j_subStringLength = %d \n",i_subStringLength,j_subStringLength); // Must be the same length string AND // the same length substring occuring before the first number AND // there must have been a number in the string if ( ((*i).size() == (*j).size()) && (i_subStringLength == j_subStringLength) && (i_diffpos != (*i).end()) ) { // printf ("substrings could be the same ... \n"); i_modifiedString = *i; i_modifiedString[i_subStringLength] = '$'; std::string j_modifiedString = *j; j_modifiedString[j_subStringLength] = '$'; // After modifying the strings (uniformly) see if we have a match if ( i_modifiedString == j_modifiedString ) { // (*i) and (*j) match upto the value of the number // record this as a modified string // modifiedStringList.push_back(i_modifiedString); // Remove these strings (after we finish these nested loops) listOfStringsToRemove.push_back(*i); // Build a string from the number that differentiates the two strings std::string i_numberString(1, *i_diffpos); std::string j_numberString(1, *j_diffpos); // Save the differences between the pseudo matching strings listOfDifferences.push_back(i_numberString); listOfDifferences.push_back(j_numberString); } } } // printf ("listOfDifferences.size() = %" PRIuPTR " \n",listOfDifferences.size()); // If there are any elements then we can proceed if (!listOfDifferences.empty()) { listOfDifferences.sort(); listOfDifferences.unique(); std::string maxvalue = listOfDifferences.back(); ROSE_ASSERT (!maxvalue.empty()); // char* diffpos = find_if ( modifiedString.c_str(), modifiedString.c_str()+modifiedString.length(), isMarker ); std::string::iterator diffpos = find_if (i_modifiedString.begin(), i_modifiedString.end(), isMarker ); *diffpos = maxvalue[0]; // modifiedString = copyEdit(modifiedString,string("$Y"),maxvalue); modifiedStringList.push_back(i_modifiedString); } } // Remove strings we identified for removal listOfStringsToRemove.sort(); listOfStringsToRemove.unique(); for (i = listOfStringsToRemove.begin(); i != listOfStringsToRemove.end(); i++) { XStringList.remove(*i); } // Add the strings the we saved (the resort) XStringList.insert(XStringList.end(), modifiedStringList.begin(), modifiedStringList.end()); XStringList.remove(std::string("\n")); XStringList.sort(); XStringList.unique(); return listToString(XStringList); }