void labelToNum(string& str,string from,unsigned int num) { //only perform replacements on instructions that use immediate operands //make sure to do so only on the correct portion of the string string prefix; string postfix; if (str.substr(0,4)=="jmpi") { postfix = str.substr(4,str.size()); prefix = str.substr(0,4); str = prefix + do_replace(postfix,from,to_string(num)); } else if (str.substr(0,4)=="byte") { postfix = str.substr(4,str.size()); prefix = str.substr(0,4); str = prefix + do_replace(postfix,from,to_string(num)); } else if (str.substr(0,3)=="jci") { postfix = str.substr(3,str.size()); prefix = str.substr(0,3); str = prefix + do_replace(postfix,from,to_string(num)); } else if (str.substr(0,3)=="jzi") { postfix = str.substr(3,str.size()); prefix = str.substr(0,3); str = prefix + do_replace(postfix,from,to_string(num)); } else if (str.substr(0,3)=="jsi") { postfix = str.substr(3,str.size()); prefix = str.substr(0,3); str = prefix + do_replace(postfix,from,to_string(num)); } else if (str.substr(0,3)=="joi") { postfix = str.substr(3,str.size()); prefix = str.substr(0,3); str = prefix + do_replace(postfix,from,to_string(num)); } else if (str.substr(0,3)=="jli") { postfix = str.substr(3,str.size()); prefix = str.substr(0,3); str = prefix + do_replace(postfix,from,to_string(num)); } else if (str.substr(0,3)=="ldi") {//ldix,immediate postfix = str.substr(5,str.size()); prefix = str.substr(0,5); str = prefix + do_replace(postfix,from,to_string(num)); } else { str=str; } //str = do_replace(str,from,to_string(num)); }
int main(int argc, char **argv) { check_for_root_maybe_die(); if (argc <= 1) usage(); argc--; argv++; if (!strncmp("help", argv[0], strlen("help"))) usage(); else if (!strncmp("version", argv[0], strlen("version"))) version(); else if (!strncmp("preload", argv[0], strlen("preload"))) do_preload(--argc, ++argv); else if (!strncmp("add", argv[0], strlen("add"))) do_add(--argc, ++argv); else if (!strncmp("set", argv[0], strlen("set"))) do_set(--argc, ++argv); else if (!strncmp("rm", argv[0], strlen("rm"))) do_rm(--argc, ++argv); else if (!strncmp("flag", argv[0], strlen("flag"))) do_flag(--argc, ++argv); else if (!strncmp("unflag", argv[0], strlen("unflag"))) do_unflag(--argc, ++argv); else if (!strncmp("bind-e", argv[0], strlen("bind-e"))) do_bind(--argc, ++argv, BIND_TYPE_EGR); else if (!strncmp("bind-i", argv[0], strlen("bind-i"))) do_bind(--argc, ++argv, BIND_TYPE_INGR); else if (!strncmp("bind", argv[0], strlen("bind"))) do_bind(--argc, ++argv, BIND_TYPE_NORM); else if (!strncmp("unbind-e", argv[0], strlen("unbind-e"))) do_unbind(--argc, ++argv, BIND_TYPE_EGR); else if (!strncmp("unbind-i", argv[0], strlen("unbind-i"))) do_unbind(--argc, ++argv, BIND_TYPE_INGR); else if (!strncmp("unbind", argv[0], strlen("unbind"))) do_unbind(--argc, ++argv, BIND_TYPE_NORM); else if (!strncmp("replace", argv[0], strlen("replace"))) do_replace(--argc, ++argv, 0); else if (!strncmp("replace-drop", argv[0], strlen("replace-drop"))) do_replace(--argc, ++argv, 1); else if (!strncmp("subscribe", argv[0], strlen("subscribe"))) do_subscribe(--argc, ++argv); else if (!strncmp("unsubscribe", argv[0], strlen("unsubscribe"))) do_unsubscribe(--argc, ++argv); else usage(); return 0; }
void buffer_replace_bytes(long del_count, const char *inserted, long ins_count) { char *deleted = NULL; view_reset_preferred_x(view); if (del_count == 0) { buffer_insert_bytes(inserted, ins_count); return; } if (ins_count == 0) { buffer_delete_bytes(del_count); return; } // check if all newlines from EOF would be deleted if (would_delete_last_bytes(del_count)) { if (inserted[ins_count - 1] != '\n') { // don't replace last newline if (--del_count == 0) { buffer_insert_bytes(inserted, ins_count); return; } } } deleted = do_replace(del_count, inserted, ins_count); record_replace(deleted, del_count, ins_count); if (buffer->views.count > 1) fix_cursors(block_iter_get_offset(&view->cursor), del_count, ins_count); }
static void reverse_change(struct change *change) { if (buffer->views.count > 1) fix_cursors(change->offset, change->ins_count, change->del_count); block_iter_goto_offset(&view->cursor, change->offset); if (!change->ins_count) { // convert delete to insert do_insert(change->buf, change->del_count); if (change->move_after) block_iter_skip_bytes(&view->cursor, change->del_count); change->ins_count = change->del_count; change->del_count = 0; free(change->buf); change->buf = NULL; } else if (change->del_count) { // reverse replace long del_count = change->ins_count; long ins_count = change->del_count; char *buf = do_replace(del_count, change->buf, ins_count); free(change->buf); change->buf = buf; change->ins_count = ins_count; change->del_count = del_count; } else { // convert insert to delete change->buf = do_delete(change->ins_count); change->del_count = change->ins_count; change->ins_count = 0; } }
/* Search for a string. */ void do_search(void) { linestruct *fileptr = openfile->current; size_t fileptr_x = openfile->current_x; size_t pww_save = openfile->placewewant; int i; bool didfind; i = search_init(FALSE, FALSE); if (i == -1) /* Cancel, Go to Line, blank search string, or regcomp() failed. */ search_replace_abort(); else if (i == -2) /* Replace. */ do_replace(); #if !defined(NANO_TINY) || defined(HAVE_REGEX_H) else if (i == 1) /* Case Sensitive, Backwards, or Regexp search toggle. */ do_search(); #endif if (i != 0) return; /* If answer is now "", copy last_search into answer. */ if (*answer == '\0') answer = mallocstrcpy(answer, last_search); else last_search = mallocstrcpy(last_search, answer); #ifndef DISABLE_HISTORIES /* If answer is not "", add this search string to the search history * list. */ if (answer[0] != '\0') update_history(&search_history, answer); #endif findnextstr_wrap_reset(); didfind = findnextstr( #ifndef DISABLE_SPELLER FALSE, #endif openfile->current, openfile->current_x, answer, NULL); /* If we found something, and we're back at the exact same spot where * we started searching, then this is the only occurrence. */ if (fileptr == openfile->current && fileptr_x == openfile->current_x && didfind) { statusbar(_("This is the only occurrence")); } openfile->placewewant = xplustabs(); edit_redraw(fileptr, pww_save); search_replace_abort(); }
int drslot_chrp_pci(struct options *opts) { int rc; struct dr_node *all_nodes; all_nodes = get_hp_nodes(); if (all_nodes == NULL) { say(ERROR, "There are no PCI hot plug slots on this system.\n"); return -1; } #ifdef DBG_HOT_PLUG print_slots_list(all_nodes); #endif if (!opts->usr_drc_name) opts->usr_drc_name = find_drc_name(opts->usr_drc_index, all_nodes); switch (opts->action) { case ADD: rc = do_add(opts, all_nodes); break; case REMOVE: rc = do_remove(opts, all_nodes); break; case REPLACE: rc = do_replace(opts, all_nodes); break; case IDENTIFY: rc = do_identify(opts, all_nodes); break; default: say(ERROR, "Invalid operation specified!\n"); rc = -1; break; } free_node(all_nodes); return rc; }
static void search_dialog_response_cb (PlumaSearchDialog *dialog, gint response_id, PlumaWindow *window) { pluma_debug (DEBUG_COMMANDS); switch (response_id) { case PLUMA_SEARCH_DIALOG_FIND_RESPONSE: do_find (dialog, window); break; case PLUMA_SEARCH_DIALOG_REPLACE_RESPONSE: do_replace (dialog, window); break; case PLUMA_SEARCH_DIALOG_REPLACE_ALL_RESPONSE: do_replace_all (dialog, window); break; default: last_search_data_store_position (dialog); gtk_widget_hide (GTK_WIDGET (dialog)); } }
Dialog::Dialog() : QDialog(0, 0, TRUE) { Q3VBoxLayout * vbox = new Q3VBoxLayout(this); Q3VGroupBox * gbox; Q3HButtonGroup * bg; Q3HBox * htab; vbox->setMargin(5); gbox = new Q3VGroupBox("Filters" , this); vbox->addWidget(gbox); htab = new Q3HBox(gbox); //htab->setMargin(5); new QLabel("filter 1 : ", htab); filter1_le = new LineEdit(htab); new QLabel(" ", htab); bg = new Q3HButtonGroup(htab); bg->setRadioButtonExclusive(TRUE); with1_rb = new QRadioButton("with", bg); new QRadioButton("without", bg); with1_rb->setChecked(TRUE); // htab = new Q3HBox(gbox); //htab->setMargin(5); new QLabel("", htab); bg = new Q3HButtonGroup(htab); bg->setRadioButtonExclusive(TRUE); and12_rb = new QRadioButton("and", bg); new QRadioButton("or", bg); and12_rb->setChecked(TRUE); new QLabel("", htab); // htab = new Q3HBox(gbox); //htab->setMargin(5); new QLabel("filter 2 : ", htab); filter2_le = new LineEdit(htab); new QLabel(" ", htab); bg = new Q3HButtonGroup(htab); bg->setRadioButtonExclusive(TRUE); with2_rb = new QRadioButton("with", bg); new QRadioButton("without", bg); with2_rb->setChecked(TRUE); // htab = new Q3HBox(gbox); //htab->setMargin(5); new QLabel("", htab); bg = new Q3HButtonGroup(htab); bg->setRadioButtonExclusive(TRUE); and23_rb = new QRadioButton("and", bg); new QRadioButton("or", bg); and23_rb->setChecked(TRUE); new QLabel("", htab); // htab = new Q3HBox(gbox); //htab->setMargin(5); new QLabel("filter 3 : ", htab); filter3_le = new LineEdit(htab); new QLabel(" ", htab); bg = new Q3HButtonGroup(htab); bg->setRadioButtonExclusive(TRUE); with3_rb = new QRadioButton("with", bg); new QRadioButton("without", bg); with3_rb->setChecked(TRUE); // // gbox = new Q3VGroupBox("Stereotype" , this); vbox->addWidget(gbox); htab = new Q3HBox(gbox); //htab->setMargin(5); bg = new Q3HButtonGroup(htab); bg->setRadioButtonExclusive(TRUE); any_rb = new QRadioButton("any", bg); is_rb = new QRadioButton("is", bg); isnot_rb = new QRadioButton("is not", bg); any_rb->setChecked(TRUE); stereotype_le = new QLineEdit(htab); // // gbox = new Q3VGroupBox("Targets" , this); vbox->addWidget(gbox); htab = new Q3HBox(gbox); //htab->setMargin(5); artifact_cb = new QCheckBox("artifact", htab); class_cb = new QCheckBox("class", htab); operation_cb = new QCheckBox("operation", htab); attribute_cb = new QCheckBox("attribute", htab); relation_cb = new QCheckBox("relation", htab); // // gbox = new Q3VGroupBox("Languages" , this); vbox->addWidget(gbox); htab = new Q3HBox(gbox); //htab->setMargin(5); cpp_cb = new QCheckBox("C++", htab); java_cb = new QCheckBox("Java", htab); php_cb = new QCheckBox("Php", htab); python_cb = new QCheckBox("Python", htab); idl_cb = new QCheckBox("Idl", htab); // // Q3Grid * grid = new Q3Grid(2, this); vbox->addWidget(grid); grid->setMargin(5); grid->setSpacing(5); new QLabel("current : ", grid); current_le = new LineEdit(grid); new QLabel("new : ", grid); new_le = new LineEdit(grid); // // htab = new Q3HBox(this); htab->setMargin(5); vbox->addWidget(htab); new QLabel(htab); QPushButton * replace = new QPushButton("Replace", htab); new QLabel(htab); QPushButton * quit = new QPushButton("Quit", htab); new QLabel(htab); QSize bs(replace->sizeHint()); quit->setFixedSize(bs); connect(replace, SIGNAL(clicked()), this, SLOT(do_replace())); connect(quit, SIGNAL(clicked()), this, SLOT(reject())); }
/* Replace a string. */ void do_replace(void) { linestruct *edittop_save, *begin; size_t begin_x, pww_save; ssize_t numreplaced; int i; if (ISSET(VIEW_MODE)) { print_view_warning(); search_replace_abort(); return; } i = search_init(TRUE, FALSE); if (i == -1) { /* Cancel, Go to Line, blank search string, or regcomp() failed. */ search_replace_abort(); return; } else if (i == -2) { /* No Replace. */ do_search(); return; } else if (i == 1) /* Case Sensitive, Backwards, or Regexp search toggle. */ do_replace(); if (i != 0) return; /* If answer is not "", add answer to the search history list and * copy answer into last_search. */ if (answer[0] != '\0') { #ifndef DISABLE_HISTORIES update_history(&search_history, answer); #endif last_search = mallocstrcpy(last_search, answer); } last_replace = mallocstrcpy(last_replace, ""); i = do_prompt(FALSE, #ifndef DISABLE_TABCOMP TRUE, #endif MREPLACEWITH, last_replace, #ifndef DISABLE_HISTORIES &replace_history, #endif /* TRANSLATORS: This is a prompt. */ edit_refresh, _("Replace with")); #ifndef DISABLE_HISTORIES /* If the replace string is not "", add it to the replace history list. */ if (i == 0) update_history(&replace_history, answer); #endif if (i != 0 && i != -2) { if (i == -1) { /* Cancel. */ if (last_replace[0] != '\0') answer = mallocstrcpy(answer, last_replace); statusbar(_("Cancelled")); } search_replace_abort(); return; } last_replace = mallocstrcpy(last_replace, answer); /* Save where we are. */ edittop_save = openfile->edittop; begin = openfile->current; begin_x = openfile->current_x; pww_save = openfile->placewewant; numreplaced = do_replace_loop( #ifndef DISABLE_SPELLER FALSE, #endif NULL, begin, &begin_x, last_search); /* Restore where we were. */ openfile->edittop = edittop_save; openfile->current = begin; openfile->current_x = begin_x; openfile->placewewant = pww_save; edit_refresh(); if (numreplaced >= 0) statusbar(P_("Replaced %lu occurrence", "Replaced %lu occurrences", (unsigned long)numreplaced), (unsigned long)numreplaced); search_replace_abort(); }
/** regexp_replace_all : 'regexp -> from:string -> by:string -> string <doc>Perform a replacement of all matched substrings using a regexp</doc> **/ static value regexp_replace_all( value o, value s, value s2 ) { return do_replace(o,s,s2,true); }
/** regexp_replace : 'regexp -> from:string -> by:string -> string <doc>Perform a replacement using a regexp</doc> **/ static value regexp_replace( value o, value s, value s2 ) { return do_replace(o,s,s2,false); }
Dialog::Dialog() : QDialog(0) { setModal(true); QVBoxLayout * vbox = new QVBoxLayout(this); VGridBox * gbox; BButtonGroup * bg; HHBox * htab; vbox->setMargin(5); gbox = new VGridBox(10,this,"Filters"); vbox->addWidget(gbox); gbox->addWidget(htab = new HHBox(gbox)); //htab->setMargin(5); htab->addWidget(new QLabel("filter 1 : ", htab)); htab->addWidget(filter1_le = new LineEdit(htab)); htab->addWidget(new QLabel(" ", htab)); htab->addWidget(bg = new BButtonGroup(htab)); //bg->setRadioButtonExclusive(TRUE); bg->addWidget(with1_rb = new QRadioButton("with", bg)); bg->addWidget(new QRadioButton("without", bg)); with1_rb->setChecked(TRUE); // gbox->addWidget(htab = new HHBox(gbox)); //htab->setMargin(5); htab->addWidget(new QLabel("", htab)); htab->addWidget(bg = new BButtonGroup(htab)); //bg->setRadioButtonExclusive(TRUE); bg->addWidget(and12_rb = new QRadioButton("and", bg)); bg->addWidget(new QRadioButton("or", bg)); and12_rb->setChecked(TRUE); htab->addWidget(new QLabel("", htab)); // gbox->addWidget(htab = new HHBox(gbox)); //htab->setMargin(5); htab->addWidget(new QLabel("filter 2 : ", htab)); htab->addWidget(filter2_le = new LineEdit(htab)); htab->addWidget(new QLabel(" ", htab)); htab->addWidget(bg = new BButtonGroup(htab)); //bg->setRadioButtonExclusive(TRUE); bg->addWidget(with2_rb = new QRadioButton("with", bg)); bg->addWidget(new QRadioButton("without", bg)); with2_rb->setChecked(TRUE); // gbox->addWidget(htab = new HHBox(gbox)); //htab->setMargin(5); htab->addWidget(new QLabel("", htab)); htab->addWidget(bg = new BButtonGroup(htab)); //bg->setRadioButtonExclusive(TRUE); bg->addWidget(and23_rb = new QRadioButton("and", bg)); bg->addWidget(new QRadioButton("or", bg)); and23_rb->setChecked(TRUE); htab->addWidget(new QLabel("", htab)); // gbox->addWidget(htab = new HHBox(gbox)); //htab->setMargin(5); htab->addWidget(new QLabel("filter 3 : ", htab)); htab->addWidget(filter3_le = new LineEdit(htab)); htab->addWidget(new QLabel(" ", htab)); htab->addWidget(bg = new BButtonGroup(htab)); //bg->setRadioButtonExclusive(TRUE); bg->addWidget(with3_rb = new QRadioButton("with", bg)); bg->addWidget(new QRadioButton("without", bg)); with3_rb->setChecked(TRUE); // // gbox = new VGridBox(2,this,"Stereotype" ); vbox->addWidget(gbox); gbox->addWidget(htab = new HHBox(gbox)); //htab->setMargin(5); htab->addWidget(bg = new BButtonGroup(htab)); //bg->setRadioButtonExclusive(TRUE); bg->addWidget(any_rb = new QRadioButton("any", bg)); bg->addWidget(is_rb = new QRadioButton("is", bg)); bg->addWidget(isnot_rb = new QRadioButton("is not", bg)); any_rb->setChecked(TRUE); htab->addWidget(stereotype_le = new QLineEdit(htab)); // // gbox = new VGridBox(2,this,"Targets" ); vbox->addWidget(gbox); gbox->addWidget(htab = new HHBox(gbox)); //htab->setMargin(5); htab->addWidget(artifact_cb = new QCheckBox("artifact", htab)); htab->addWidget(class_cb = new QCheckBox("class", htab)); htab->addWidget(operation_cb = new QCheckBox("operation", htab)); htab->addWidget(attribute_cb = new QCheckBox("attribute", htab)); htab->addWidget(relation_cb = new QCheckBox("relation", htab)); // // gbox = new VGridBox(2,this,"Languages"); vbox->addWidget(gbox); gbox->addWidget(htab = new HHBox(gbox)); //htab->setMargin(5); htab->addWidget(cpp_cb = new QCheckBox("C++", htab)); htab->addWidget(java_cb = new QCheckBox("Java", htab)); htab->addWidget(php_cb = new QCheckBox("Php", htab)); htab->addWidget(python_cb = new QCheckBox("Python", htab)); htab->addWidget(idl_cb = new QCheckBox("Idl", htab)); // // GridBox * grid = new GridBox(2, this); vbox->addWidget(grid); grid->setMargin(5); grid->setSpacing(5); grid->addWidget(new QLabel("current : ", grid)); grid->addWidget(current_le = new LineEdit(grid)); grid->addWidget(new QLabel("new : ", grid)); grid->addWidget(new_le = new LineEdit(grid)); // // htab = new HHBox(this); htab->setMargin(5); vbox->addWidget(htab); htab->addWidget(new QLabel(htab)); QPushButton * replace; htab->addWidget(replace = new QPushButton("Replace", htab)); htab->addWidget(new QLabel(htab)); QPushButton * quit; htab->addWidget(quit = new QPushButton("Quit", htab)); htab->addWidget(new QLabel(htab)); QSize bs(replace->sizeHint()); quit->setFixedSize(bs); connect(replace, SIGNAL(clicked()), this, SLOT(do_replace())); connect(quit, SIGNAL(clicked()), this, SLOT(reject())); }
int main ( int argc, char** argv, char** env) { struct arg_struct* the_args = NULL; // size_t arg_sz = 0; size_t files_renamed = 0; int return_code = 0; #ifdef BOEHM_GC GC_INIT(); #endif if (argc < 2 ) /* gotta have at least 2 arguments */ { usage(stderr); return_code = EXIT_FAILURE; goto bye; } setlocale(LC_CTYPE, ""); /* we know the characters if we set baseline locale */ if (geteuid() == 0) root_warning(stderr); /* root is dangerous */ /* if we can't set an undo file we are broken */ /*clear out garbage */ replace_undo_home = NULL; replace_undo_dir = NULL; replace_undo_file = NULL; replace_undo_path = NULL; if (! set_undo_file() ) { fprintf( stderr, "ERROR setting undo file\n" ); return_code = EXIT_FAILURE; goto bye; } /* not in final compilation */ #ifdef DEBUG_ARGS do{ fprintf(stderr, "argc:%d \n", argc); int a; for (a = 0; a < argc ; a++) fprintf(stderr, "argv[%d]:\t %s \n", a, argv[a]); fprintf(stderr, "\n"); fflush(stderr); }while(0); #endif options( argc, argv ); /* get the command options */ if (undo) /* check if this is an undo op -- if so get filenames from the undo file */ { files_renamed = do_undo(); return_code = EXIT_SUCCESS; goto bye; } /* make mem space for arg struct*/ the_args = (struct arg_struct*) calloc(1, sizeof(struct arg_struct) ); if (! the_args) { fprintf(stderr, "[the_args] calloc failed\n" ); return_code = EXIT_FAILURE; goto bye; } if ( ! set_and_check_args(argc, argv, the_args) ) /* check the arguments and if good do the renaming */ { if (verbose) fprintf(stderr , "check_args failed\n"); return_code = EXIT_FAILURE; } else { files_renamed = do_replace( the_args->num_files, the_args->match, the_args->replace, the_args->files ); /* GO! */ } /* we have reached the end */ bye: if (verbose ) { if ( test_mode) fprintf( stdout , "test mode -- no files renamed. -- would have " ); fprintf( stdout , "renamed %zu files.\n", files_renamed ); } replace_undo_home = NULL; replace_undo_dir = NULL; replace_undo_file = NULL; replace_undo_path = NULL; the_args = NULL; #ifdef BOEHM_GC GC_gcollect(); #endif return return_code; /* YAY! bye */ } /* main */