void do_search(char *search_word) { int i, temp_len = 0; char temp[100]; search_init(); for (i = 0;i<strlen(search_word); i++) { if (search_word[i]==' ' || search_word[i]=='\t' || search_word[i]=='\n') { temp[temp_len] = '\0'; get_the_file_and_index(temp); temp_len = 0; continue; } temp[temp_len++] = search_word[i]; } if (temp_len!=0) { temp[temp_len] = '\0'; get_the_file_and_index(temp); } merge_and_print_results(); cache_results(); printf("just before freeing the mem\n"); free_up_local_mem(); }
/* 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(); }
PyMODINIT_FUNC init_spotify(void) { PyObject *m; if (PyType_Ready(&SessionType) < 0) return; if (PyType_Ready(&ArtistType) < 0) return; if (PyType_Ready(&ArtistBrowserType) < 0) return; if (PyType_Ready(&LinkType) < 0) return; if (PyType_Ready(&PlaylistType) < 0) return; if (PyType_Ready(&PlaylistContainerType) < 0) return; if (PyType_Ready(&ResultsType) < 0) return; if (PyType_Ready(&ToplistBrowserType) < 0) return; if (PyType_Ready(&TrackType) < 0) return; if (PyType_Ready(&ImageType) < 0) return; if (PyType_Ready(&UserType) < 0) return; m = Py_InitModule("_spotify", module_methods); if (m == NULL) return; PyObject *spotify = PyImport_ImportModule("spotify"); PyObject *d = PyModule_GetDict(spotify); PyObject *s = PyUnicode_FromString("SpotifyError"); SpotifyError = PyDict_GetItem(d, s); Py_INCREF(SpotifyError); SpotifyApiVersion = Py_BuildValue("i", SPOTIFY_API_VERSION); Py_INCREF(SpotifyApiVersion); PyModule_AddObject(m, "api_version", SpotifyApiVersion); album_init(m); albumbrowser_init(m); artist_init(m); artistbrowser_init(m); link_init(m); playlist_init(m); playlistcontainer_init(m); session_init(m); search_init(m); toplistbrowser_init(m); track_init(m); image_init(m); user_init(m); }
void depsSearchStart(void) { if (!inState(DEPS_STATE_INIT)) { setErr(DEPS_ERROR_NOT_INIT); return; } search_init(); g_state |= DEPS_STATE_SEARCH; setErr(0); }
/* el_init(): * Initialize editline and set default parameters. */ public EditLine * el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr) { EditLine *el = (EditLine *) el_malloc(sizeof(EditLine)); if (el == NULL) return (NULL); memset(el, 0, sizeof(EditLine)); el->el_infile = fin; el->el_outfile = fout; el->el_errfile = ferr; el->el_infd = fileno(fin); if ((el->el_prog = el_strdup(prog)) == NULL) { el_free(el); return NULL; } /* * Initialize all the modules. Order is important!!! */ el->el_flags = 0; if (term_init(el) == -1) { el_free(el->el_prog); el_free(el); return NULL; } (void) key_init(el); (void) map_init(el); if (tty_init(el) == -1) el->el_flags |= NO_TTY; (void) ch_init(el); (void) search_init(el); (void) hist_init(el); (void) prompt_init(el); (void) sig_init(el); (void) read_init(el); return (el); }
/* this is the plugin entry point */ enum plugin_status plugin_start(const void* parameter) { int ok; const char *filename = parameter; char *p; if(!parameter) return PLUGIN_ERROR; DEBUGF("%s - %s\n", (char *)parameter, &filename[rb->strlen(filename)-4]); /* Check the extension. We only allow .m3u files. */ if (!(p = rb->strrchr(filename, '.')) || (rb->strcasecmp(p, ".m3u") && rb->strcasecmp(p, ".m3u8"))) { rb->splash(HZ, "Not a .m3u or .m3u8 file"); return PLUGIN_ERROR; } rb->strcpy(path, filename); p = rb->strrchr(path, '/'); if(p) *p = 0; rb->snprintf(resultfile, MAX_PATH, "%s/search_result.m3u", path); ok = search_init(parameter); if (!ok) return PLUGIN_ERROR; search_buffer(); clear_display(); rb->splash(HZ, "Done"); rb->close(fdw); rb->close(fd); /* We fake a USB connection to force a reload of the file browser */ return PLUGIN_USB_CONNECTED; }
int wikilib_run(void) { int sleep; long time_now; struct wl_input_event ev; int more_events = 0; unsigned long last_event_time = 0; int rc; /* * test searching code... */ article_buf_pointer = NULL; search_init(); history_list_init(); malloc_status_simple(); print_intro(); #ifndef INCLUDED_FROM_KERNEL if (!load_init_article(idx_init_article)) { display_mode = DISPLAY_MODE_ARTICLE; last_display_mode = DISPLAY_MODE_INDEX; } #endif render_string(SUBTITLE_FONT_IDX, -1, 55, MESSAGE_TYPE_A_WORD, strlen(MESSAGE_TYPE_A_WORD), 0); for (;;) { if (more_events) sleep = 0; else sleep = 1; if (!more_events && display_mode == DISPLAY_MODE_ARTICLE && render_article_with_pcf()) sleep = 0; else if (!more_events && display_mode == DISPLAY_MODE_INDEX && render_search_result_with_pcf()) sleep = 0; else if (!more_events && display_mode == DISPLAY_MODE_HISTORY && render_history_with_pcf()) sleep = 0; if (finger_move_speed != 0) { scroll_article(); sleep = 0; } #ifdef INCLUDED_FROM_KERNEL time_now = get_time_ticks(); if(display_mode == DISPLAY_MODE_INDEX) { if (press_delete_button && get_search_string_len()>0) { sleep = 0; if(time_diff(time_now, start_search_time) > seconds_to_ticks(3.5)) { if (!clear_search_string()) { search_string_changed_remove = true; search_reload_ex(SEARCH_RELOAD_NORMAL); } press_delete_button = false; } else if (time_diff(time_now, start_search_time) > seconds_to_ticks(0.5) && time_diff(time_now, last_delete_time) > seconds_to_ticks(0.25)) { if (!search_remove_char(0)) { search_string_changed_remove = true; search_reload_ex(SEARCH_RELOAD_NO_POPULATE); } last_delete_time = time_now; } } } else if (display_mode == DISPLAY_MODE_RESTRICTED) { if (press_delete_button && get_password_string_len()>0) { sleep = 0; time_now = get_time_ticks(); if(time_diff(time_now, start_search_time) > seconds_to_ticks(3.5)) { clear_password_string(); press_delete_button = false; } else if (time_diff(time_now, start_search_time) > seconds_to_ticks(0.5) && time_diff(time_now, last_delete_time) > seconds_to_ticks(0.25)) { password_remove_char(); last_delete_time = time_now; } } } #endif if (!more_events && display_mode == DISPLAY_MODE_INDEX && fetch_search_result(0, 0, 0)) { sleep = 0; } if (keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_CHECK)) // check if need to reset invert sleep = 0; if (check_invert_link()) // check if need to invert link sleep = 0; if (sleep) { if (time_diff(get_time_ticks(), last_event_time) > seconds_to_ticks(15)) rc = history_list_save(HISTORY_SAVE_POWER_OFF); else rc = history_list_save(HISTORY_SAVE_NORMAL); if (rc > 0) { #ifdef INCLUDED_FROM_KERNEL delay_us(200000); // for some reason, save may not work if no delay #endif } else if (rc < 0) sleep = 0; // waiting for last_event_time timeout to save the history } wl_input_wait(&ev, sleep); more_events = 1; switch (ev.type) { case WL_INPUT_EV_TYPE_CURSOR: handle_cursor(&ev); last_event_time = get_time_ticks(); break; case WL_INPUT_EV_TYPE_KEYBOARD: if (ev.key_event.value != 0) { b_show_scroll_bar = 0; handle_key_release(ev.key_event.keycode); } last_event_time = get_time_ticks(); break; case WL_INPUT_EV_TYPE_TOUCH: handle_touch(&ev); last_event_time = ev.touch_event.ticks; break; default: more_events = 0; break; } } /* never reached */ return 0; }
/* * b_search -- * Do a backward search. * * PUBLIC: int b_search __P((SCR *, * PUBLIC: MARK *, MARK *, CHAR_T *, size_t, CHAR_T **, u_int)); */ int b_search( SCR *sp, MARK *fm, MARK *rm, CHAR_T *ptrn, size_t plen, CHAR_T **eptrn, u_int flags) { busy_t btype; recno_t lno; regmatch_t match[1]; size_t coff, last, len; int cnt, eval, rval, wrapped; CHAR_T *l; if (search_init(sp, BACKWARD, ptrn, plen, eptrn, flags)) return (1); /* * If doing incremental search, set the "starting" position past the * current column, so that we search a minimal distance and still * match special patterns, e.g., \> for the end of a word. This is * safe when the cursor is at the end of a line because we only use * it for comparison with the location of the match. * * Otherwise, start searching immediately before the cursor. If in * the first column, start search on the previous line. */ if (LF_ISSET(SEARCH_INCR)) { lno = fm->lno; coff = fm->cno + 1; } else { if (fm->cno == 0) { if (fm->lno == 1 && !O_ISSET(sp, O_WRAPSCAN)) { if (LF_ISSET(SEARCH_MSG)) search_msg(sp, S_SOF); return (1); } lno = fm->lno - 1; } else lno = fm->lno; coff = fm->cno; } btype = BUSY_ON; for (cnt = INTERRUPT_CHECK, rval = 1, wrapped = 0;; --lno, coff = 0) { if (cnt-- == 0) { if (INTERRUPTED(sp)) break; if (LF_ISSET(SEARCH_MSG)) { search_busy(sp, btype); btype = BUSY_UPDATE; } cnt = INTERRUPT_CHECK; } if ((wrapped && lno < fm->lno) || lno == 0) { if (wrapped) { if (LF_ISSET(SEARCH_MSG)) search_msg(sp, S_NOTFOUND); break; } if (!O_ISSET(sp, O_WRAPSCAN)) { if (LF_ISSET(SEARCH_MSG)) search_msg(sp, S_SOF); break; } if (db_last(sp, &lno)) break; if (lno == 0) { if (LF_ISSET(SEARCH_MSG)) search_msg(sp, S_EMPTY); break; } ++lno; wrapped = 1; continue; } if (db_get(sp, lno, 0, &l, &len)) break; /* Set the termination. */ match[0].rm_so = 0; match[0].rm_eo = len; #if defined(DEBUG) && 0 TRACE(sp, "B search: %lu from 0 to %qu\n", lno, match[0].rm_eo); #endif /* Search the line. */ eval = regexec(&sp->re_c, l, 1, match, (match[0].rm_eo == len ? 0 : REG_NOTEOL) | REG_STARTEND); if (eval == REG_NOMATCH) continue; if (eval != 0) { if (LF_ISSET(SEARCH_MSG)) re_error(sp, eval, &sp->re_c); else (void)sp->gp->scr_bell(sp); break; } /* Check for a match starting past the cursor. */ if (coff != 0 && match[0].rm_so >= coff) continue; /* Warn if the search wrapped. */ if (wrapped && LF_ISSET(SEARCH_WMSG)) search_msg(sp, S_WRAP); #if defined(DEBUG) && 0 TRACE(sp, "B found: %qu to %qu\n", match[0].rm_so, match[0].rm_eo); #endif /* * We now have the first match on the line. Step through the * line character by character until find the last acceptable * match. This is painful, we need a better interface to regex * to make this work. */ for (;;) { last = match[0].rm_so++; if (match[0].rm_so >= len) break; match[0].rm_eo = len; eval = regexec(&sp->re_c, l, 1, match, (match[0].rm_so == 0 ? 0 : REG_NOTBOL) | REG_STARTEND); if (eval == REG_NOMATCH) break; if (eval != 0) { if (LF_ISSET(SEARCH_MSG)) re_error(sp, eval, &sp->re_c); else (void)sp->gp->scr_bell(sp); goto err; } if (coff && match[0].rm_so >= coff) break; } rm->lno = lno; /* See comment in f_search(). */ if (!LF_ISSET(SEARCH_EOL) && last >= len) rm->cno = len != 0 ? len - 1 : 0; else rm->cno = last; rval = 0; break; } err: if (LF_ISSET(SEARCH_MSG)) search_busy(sp, BUSY_OFF); return (rval); }
/* * f_search -- * Do a forward search. * * PUBLIC: int f_search __P((SCR *, * PUBLIC: MARK *, MARK *, CHAR_T *, size_t, CHAR_T **, u_int)); */ int f_search( SCR *sp, MARK *fm, MARK *rm, CHAR_T *ptrn, size_t plen, CHAR_T **eptrn, u_int flags) { busy_t btype; recno_t lno; regmatch_t match[1]; size_t coff, len; int cnt, eval, rval, wrapped; CHAR_T *l; if (search_init(sp, FORWARD, ptrn, plen, eptrn, flags)) return (1); if (LF_ISSET(SEARCH_FILE)) { lno = 1; coff = 0; } else { if (db_get(sp, fm->lno, DBG_FATAL, &l, &len)) return (1); lno = fm->lno; /* * If doing incremental search, start searching at the previous * column, so that we search a minimal distance and still match * special patterns, e.g., \< for beginning of a word. * * Otherwise, start searching immediately after the cursor. If * at the end of the line, start searching on the next line. * This is incompatible (read bug fix) with the historic vi -- * searches for the '$' pattern never moved forward, and the * "-t foo" didn't work if the 'f' was the first character in * the file. */ if (LF_ISSET(SEARCH_INCR)) { if ((coff = fm->cno) != 0) --coff; } else if (fm->cno + 1 >= len) { coff = 0; lno = fm->lno + 1; if (db_get(sp, lno, 0, &l, &len)) { if (!O_ISSET(sp, O_WRAPSCAN)) { if (LF_ISSET(SEARCH_MSG)) search_msg(sp, S_EOF); return (1); } lno = 1; } } else coff = fm->cno + 1; } btype = BUSY_ON; for (cnt = INTERRUPT_CHECK, rval = 1, wrapped = 0;; ++lno, coff = 0) { if (cnt-- == 0) { if (INTERRUPTED(sp)) break; if (LF_ISSET(SEARCH_MSG)) { search_busy(sp, btype); btype = BUSY_UPDATE; } cnt = INTERRUPT_CHECK; } if ((wrapped && lno > fm->lno) || db_get(sp, lno, 0, &l, &len)) { if (wrapped) { if (LF_ISSET(SEARCH_MSG)) search_msg(sp, S_NOTFOUND); break; } if (!O_ISSET(sp, O_WRAPSCAN)) { if (LF_ISSET(SEARCH_MSG)) search_msg(sp, S_EOF); break; } lno = 0; wrapped = 1; continue; } /* If already at EOL, just keep going. */ if (len != 0 && coff == len) continue; /* Set the termination. */ match[0].rm_so = coff; match[0].rm_eo = len; #if defined(DEBUG) && 0 TRACE(sp, "F search: %lu from %u to %u\n", lno, coff, len != 0 ? len - 1 : len); #endif /* Search the line. */ eval = regexec(&sp->re_c, l, 1, match, (match[0].rm_so == 0 ? 0 : REG_NOTBOL) | REG_STARTEND); if (eval == REG_NOMATCH) continue; if (eval != 0) { if (LF_ISSET(SEARCH_MSG)) re_error(sp, eval, &sp->re_c); else (void)sp->gp->scr_bell(sp); break; } /* Warn if the search wrapped. */ if (wrapped && LF_ISSET(SEARCH_WMSG)) search_msg(sp, S_WRAP); #if defined(DEBUG) && 0 TRACE(sp, "F search: %qu to %qu\n", match[0].rm_so, match[0].rm_eo); #endif rm->lno = lno; rm->cno = match[0].rm_so; /* * If a change command, it's possible to move beyond the end * of a line. Historic vi generally got this wrong (e.g. try * "c?$<cr>"). Not all that sure this gets it right, there * are lots of strange cases. */ if (!LF_ISSET(SEARCH_EOL) && rm->cno >= len) rm->cno = len != 0 ? len - 1 : 0; rval = 0; break; } if (LF_ISSET(SEARCH_MSG)) search_busy(sp, BUSY_OFF); return (rval); }
int main_real(int argc, char * const* argv) { xmlerror *error = NULL; char *config_file = NULL, *command=NULL, *startup_file=NULL; int opt; char *cp; struct attr navit, conf; GList *list = NULL, *li; main_argc=argc; main_argv=argv; #ifdef HAVE_GLIB event_glib_init(); #else _g_slice_thread_init_nomessage(); #endif atom_init(); main_init(argv[0]); navit_nls_main_init(); debug_init(argv[0]); cp = getenv("NAVIT_LOGFILE"); if (cp) { debug_set_logfile(cp); } #ifdef HAVE_API_WIN32_CE else { debug_set_logfile("/Storage Card/navit.log"); } #endif file_init(); #ifndef USE_PLUGINS builtin_init(); #endif route_init(); navigation_init(); tracking_init(); search_init(); linguistics_init(); geom_init(); config_file=NULL; #ifdef HAVE_GETOPT_H opterr=0; //don't bomb out on errors. #endif /* _MSC_VER */ /* ingore iphone command line argument */ if (argc == 2 && !strcmp(argv[1],"-RegisterForSystemEvents")) argc=1; if (argc > 1) { /* Don't forget to update the manpage if you modify theses options */ while((opt = getopt(argc, argv, ":hvc:d:e:s:")) != -1) { switch(opt) { case 'h': print_usage(); exit(0); break; case 'v': printf("%s %s\n", "navit", version); exit(0); break; case 'c': printf("config file n is set to `%s'\n", optarg); config_file = optarg; break; case 'd': debug_set_global_level(atoi(optarg), 1); break; case 'e': command=optarg; break; case 's': startup_file=optarg; break; #ifdef HAVE_GETOPT_H case ':': fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt); print_usage(); exit(2); break; case '?': fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt); print_usage(); exit(3); #endif } } // use 1st cmd line option that is left for the config file if (optind < argc) config_file = argv[optind]; } // if config file is explicitely given only look for it, otherwise try std paths if (config_file) { list = g_list_append(list,g_strdup(config_file)); } else { list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_USER_DATADIR"), "/navit.xml" , NULL)); list = g_list_append(list,g_strdup("navit.xml.local")); list = g_list_append(list,g_strdup("navit.xml")); #ifdef HAVE_API_ANDROID // new preferred location (the new one should have priority over the legacy!) list = g_list_append(list,g_strdup("/sdcard/navit/navit.xml")); // legacy location, still supported list = g_list_append(list,g_strdup("/sdcard/navit.xml")); #endif list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL)); list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL)); #ifndef _WIN32 list = g_list_append(list,g_strdup("/etc/navit/navit.xml")); #endif } li = list; for (;;) { if (li == NULL) { // We have not found an existing config file from all possibilities dbg(0, "%s", _("No config file navit.xml, navit.xml.local found\n")); return 4; } // Try the next config file possibility from the list config_file = li->data; dbg(1,"trying %s\n",config_file); if (file_exists(config_file)) { break; } g_free(config_file); li = g_list_next(li); } dbg(0,"Loading %s\n",config_file); if (!config_load(config_file, &error)) { dbg(0, _("Error parsing config file '%s': %s\n"), config_file, error ? error->message : ""); } else { dbg(0, _("Using config file '%s'\n"), config_file); } while (li) { g_free(li->data); li = g_list_next(li); } g_list_free(list); if (! config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok) { dbg(0, "%s", _("Internal initialization failed, exiting. Check previous error messages.\n")); exit(5); } conf.type=attr_config; conf.u.config=config; if (startup_file) { FILE *f=fopen(startup_file,"r"); if (f) { char buffer[4096]; while(fgets(buffer, sizeof(buffer), f)) { command_evaluate(&conf, buffer); } } } if (command) { command_evaluate(&conf, command); } event_main_loop_run(); /* TODO: Android actually has no event loop, so we can't free all allocated resources here. Have to find better place to * free all allocations on program exit. And don't forget to free all the stuff allocated in the code above. */ #ifndef HAVE_API_ANDROID linguistics_free(); debug_finished(); #endif return 0; }
/* Go to the specified line and column, or ask for them if interactive * is TRUE. Save the x-coordinate and y-coordinate if save_pos is TRUE. * Update the screen afterwards if allow_update is TRUE. Note that both * the line and column numbers should be one-based. */ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer, bool interactive, bool save_pos, bool allow_update) { if (interactive) { char *ans = mallocstrcpy(NULL, answer); functionptrtype func; /* Ask for the line and column. */ int i = do_prompt(FALSE, #ifndef DISABLE_TABCOMP TRUE, #endif MGOTOLINE, use_answer ? ans : "", #ifndef DISABLE_HISTORIES NULL, #endif /* TRANSLATORS: This is a prompt. */ edit_refresh, _("Enter line number, column number")); free(ans); /* Cancel, or Enter with blank string. */ if (i < 0) { statusbar(_("Cancelled")); display_main_list(); return; } func = func_from_key(&i); if (func == gototext_void) { /* Keep answer up on the statusbar. */ search_init(TRUE, TRUE); do_search(); return; } /* Do a bounds check. Display a warning on an out-of-bounds * line or column number only if we hit Enter at the statusbar * prompt. */ if (!parse_line_column(answer, &line, &column) || line < 1 || column < 1) { if (i == 0) statusbar(_("Invalid line or column number")); display_main_list(); return; } } else { if (line < 1) line = openfile->current->lineno; if (column < 1) column = openfile->placewewant + 1; } for (openfile->current = openfile->fileage; openfile->current != openfile->filebot && line > 1; line--) openfile->current = openfile->current->next; openfile->current_x = actual_x(openfile->current->data, column - 1); openfile->placewewant = column - 1; /* Put the top line of the edit window in range of the current line. * If save_pos is TRUE, don't change the cursor position when doing * it. */ edit_update(save_pos ? NONE : CENTER); /* If allow_update is TRUE, update the screen. */ if (allow_update) { edit_refresh(); display_main_list(); } }
/* 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(); }
int main_real(int argc, char **argv) { dbg(0, "in main loop 001 ##########################\n"); xmlerror *error = NULL; char *config_file = NULL; int opt; char *cp; struct attr navit; GList *list = NULL, *li; main_argc = argc; main_argv = argv; //dbg(0, "in main loop 002 ##########################\n"); #ifdef HAVE_GLIB event_glib_init(); //dbg(0,"in main loop 003 ##########################\n"); #else _g_slice_thread_init_nomessage(); //dbg(0, "in main loop 004 ##########################\n"); #endif atom_init(); main_init(argv[0]); main_init_nls(); debug_init(argv[0]); // ?? cp = getenv("NAVIT_LOGFILE"); if (cp) { debug_set_logfile(cp); } #ifdef HAVE_API_WIN32_CE else { debug_set_logfile("/Storage Card/navit.log"); } #endif //dbg(0, "in main loop 005 ##########################\n"); file_init(); //dbg(0, "in main loop 006 ##########################\n"); #ifndef USE_PLUGINS //dbg(0, "in main loop 007 ##########################\n"); builtin_init(); #endif //dbg(0, "in main loop 008 ##########################\n"); route_init(); //dbg(0, "in main loop 008.1 ##########################\n"); navigation_init(); //dbg(0, "in main loop 008.2 ##########################\n"); tracking_init(); //dbg(0, "in main loop 008.3 ##########################\n"); search_init(); //dbg(0, "in main loop 008.4 ##########################\n"); linguistics_init(); //dbg(0, "in main loop 0014 ##########################\n"); config_file = NULL; #ifdef HAVE_GETOPT_H opterr=0; //don't bomb out on errors. #endif /* _MSC_VER */ if (argc > 1) { /* DEVELOPPERS : don't forget to update the manpage if you modify theses options */ while ((opt = getopt(argc, argv, ":hvc:d:")) != -1) { switch (opt) { case 'h': print_usage(); exit(0); break; case 'v': printf("%s %s\n", "navit", version); exit(0); break; case 'c': printf("config file n is set to `%s'\n", optarg); config_file = optarg; break; case 'd': printf("TODO Verbose option is set to `%s'\n", optarg); break; #ifdef HAVE_GETOPT_H case ':': fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt); print_usage(); exit(1); break; case '?': fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt); print_usage(); exit(1); #endif } } // use 1st cmd line option that is left for the config file if (optind < argc) config_file = argv[optind]; } // if config file is explicitely given only look for it, otherwise try std paths //if (config_file) //{ // list = g_list_append(list, g_strdup(config_file)); //} //else //{ dbg(0, "navit_share_dir=%s\n", navit_share_dir); list = g_list_append(list, g_strjoin(NULL, navit_share_dir, "/navit.xml", NULL)); //list = g_list_append(list, g_strdup("navit.xml")); #ifdef HAVE_API_ANDROID // **disabled** // new preferred location (the new one should have priority over the legacy!) // **disabled** // list = g_list_append(list,g_strdup("/sdcard/zanavi/navit.xml")); #endif //list = g_list_append(list, g_strjoin(NULL, getenv("NAVIT_SHAREDIR"), "/navit.xml", NULL)); #ifndef _WIN32 //list = g_list_append(list, g_strdup("/etc/navit/navit.xml")); #endif //} li = list; for (;;) { if (li == NULL) { // We have not found an existing config file from all possibilities dbg(0, "No config file navit.xml, navit.xml.local found\n"); return 1; } // Try the next config file possibility from the list config_file = li->data; if (file_exists(config_file)) { break; } else { g_free(config_file); } li = g_list_next(li); } // ############### load XML config file, and call all the init/new functions ################ // ############### load XML config file, and call all the init/new functions ################ // ############### load XML config file, and call all the init/new functions ################ clock_t s_ = debug_measure_start(); if (!config_load(config_file, &error)) { } debug_mrp("load and init xmlconfig:", debug_measure_end(s_)); // ############### load XML config file, and call all the init/new functions ################ // ############### load XML config file, and call all the init/new functions ################ // ############### load XML config file, and call all the init/new functions ################ while (li) { g_free(li->data); li = g_list_next(li); } g_list_free(list); if (!config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok) { dbg(0, "No instance has been created, exiting\n"); exit(1); } dbg(0, "in main loop 026 ##########################\n"); event_main_loop_run(); dbg(0, "after main loop ##########################"); #ifndef HAVE_API_ANDROID debug_finished(); #endif return 0; }
/** * @brief edax main function. * * Do a global initialization and choose a User Interface protocol. * * @param argc Number of arguments. * @param argv Command line arguments. */ int main(int argc, char **argv) { UI *ui; int i, r, level = 0, size = 8; char *problem_file = NULL; char *wthor_file = NULL; char *count_type = NULL; int n_bench = 0; // options.n_task default to system cpu number options.n_task = get_cpu_number(); // options from edax.ini options_parse("edax.ini"); // allocate ui ui = (UI*) malloc(sizeof *ui); if (ui == NULL) fatal_error("Cannot allocate a user interface.\n"); ui->type = UI_EDAX; ui->init = ui_init_edax; ui->free = ui_free_edax; ui->loop = ui_loop_edax; // parse arguments for (i = 1; i < argc; i++) { char *arg = argv[i]; while (*arg == '-') ++arg; if (strcmp(arg, "v") == 0 || strcmp(arg, "version") == 0) version(); else if (ui_switch(ui, arg)) ; else if ((r = (options_read(arg, argv[i + 1]))) > 0) i += r - 1; else if (strcmp(arg, "solve") == 0 && argv[i + 1]) problem_file = argv[++i]; else if (strcmp(arg, "wtest") == 0 && argv[i + 1]) wthor_file = argv[++i]; else if (strcmp(arg, "bench") == 0 && argv[i + 1]) n_bench = atoi(argv[++i]); else if (strcmp(arg, "count") == 0 && argv[i + 1]) { count_type = argv[++i]; if (argv[i + 1]) level = string_to_int(argv[++i], 0); if (argv[i + 1] && strcmp(argv[i + 1], "6x6") == 0) { size = 6; ++i; } } else usage(); } options_bound(); // initialize edge_stability_init(); hash_code_init(); hash_move_init(); statistics_init(); eval_open(options.eval_file); search_global_init(); // solver & tester if (problem_file || wthor_file || n_bench) { Search search[1]; search_init(search); search->options.header = " depth|score| time | nodes (N) | N/s | principal variation"; search->options.separator = "------+-----+--------------+-------------+----------+---------------------"; if (options.verbosity) version(); if (problem_file) obf_test(search, problem_file, NULL); if (wthor_file) wthor_test(wthor_file, search); if (n_bench) obf_speed(search, n_bench); search_free(search); } else if (count_type){ Board board[1]; board_init(board); if (strcmp(count_type, "games") == 0) quick_count_games(board, level, size); else if (strcmp(count_type, "positions") == 0) count_positions(board, level, size); else if (strcmp(count_type, "shapes") == 0) count_shapes(board, level, size); } else if (ui->type == UI_CASSIO) { engine_loop(); // other protocols } else { ui_event_init(ui); ui->init(ui); ui->loop(ui); if (ui->free) ui->free(ui); ui_event_free(ui); } // display statistics statistics_print(stdout); // free; eval_close(); options_free(); free(ui); return 0; }
int main_real(int argc, char **argv) { xmlerror *error = NULL; char *config_file = NULL; int opt; char *cp; struct attr navit; GList *list = NULL, *li; main_argc=argc; main_argv=argv; #ifdef HAVE_GLIB event_glib_init(); #else _g_slice_thread_init_nomessage(); #endif atom_init(); main_init(argv[0]); main_init_nls(); debug_init(argv[0]); cp = getenv("NAVIT_LOGFILE"); if (cp) debug_set_logfile(cp); #ifdef HAVE_API_WIN32_CE else debug_set_logfile("/Storage Card/navit.log"); #endif file_init(); #ifndef USE_PLUGINS extern void builtin_init(void); builtin_init(); #endif route_init(); navigation_init(); tracking_init(); search_init(); linguistics_init(); config_file=NULL; opterr=0; //don't bomb out on errors. if (argc > 1) { /* DEVELOPPERS : don't forget to update the manpage if you modify theses options */ while((opt = getopt(argc, argv, ":hvc:d:")) != -1) { switch(opt) { case 'h': print_usage(); exit(0); break; case 'v': printf("%s %s\n", "navit", version); exit(0); break; case 'c': printf("config file n is set to `%s'\n", optarg); config_file = optarg; break; case 'd': printf("TODO Verbose option is set to `%s'\n", optarg); break; case ':': fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt); print_usage(); exit(1); break; case '?': fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt); print_usage(); exit(1); } } } // use 1st cmd line option that is left for the config file if (optind < argc) config_file = argv[optind]; // if config file is explicitely given only look for it, otherwise try std paths if (config_file) list = g_list_append(list,g_strdup(config_file)); else { list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_USER_DATADIR"), "/navit.xml" , NULL)); list = g_list_append(list,g_strdup("navit.xml.local")); list = g_list_append(list,g_strdup("navit.xml")); #ifdef HAVE_API_ANDROID list = g_list_append(list,g_strdup("/sdcard/navit.xml")); #endif list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL)); list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL)); #ifndef _WIN32 list = g_list_append(list,g_strdup("/etc/navit/navit.xml")); #endif } li = list; for (;;) { if (li == NULL) { // We have not found an existing config file from all possibilities dbg(0,_("No config file navit.xml, navit.xml.local found\n")); return 1; } // Try the next config file possibility from the list config_file = li->data; if (file_exists(config_file)) break; else g_free(config_file); li = g_list_next(li); } if (!config_load(config_file, &error)) { dbg(0, _("Error parsing '%s': %s\n"), config_file, error ? error->message : ""); } else { dbg(0, _("Using '%s'\n"), config_file); } while (li) { g_free(li->data); li = g_list_next(li); } g_list_free(list); if (! config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok) { dbg(0, _("No instance has been created, exiting\n")); exit(1); } event_main_loop_run(); #ifndef HAVE_API_ANDROID debug_finished(); #endif return 0; }
// main function. int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinst, LPSTR cmdline, int show) { instance = hinstance; InitCommonControls(); register_classes(); h_font = CreateFont(-11, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "MS Sans Serif"); GetModuleFileName(NULL, MyPath, sizeof(MyPath)); //fprintf (stderr, "MyPath = %s\n", MyPath); if (!SHGetSpecialFolderPath(NULL, ConfigPath, CSIDL_LOCAL_APPDATA, 0)) { //fprintf (stderr, "Cannot determine LocalAppData folder\n"); } else { } strcat (ConfigPath, "\\.sif2\\"); _mkdir (ConfigPath); //fprintf (stderr, "ConfigPath = %s\n", ConfigPath); config_init (); hMainWindow = create_wnd0(); memset (&clfnt, 0, sizeof(clfnt)); clfnt.lfHeight = -MulDiv(OptFontHeight, GetDeviceCaps(GetDC(hMainWindow), LOGPIXELSY), 72); clfnt.lfWidth = 0; clfnt.lfEscapement = 0; clfnt.lfOrientation = 0; clfnt.lfWeight = FW_NORMAL; clfnt.lfItalic = 0; clfnt.lfUnderline = 0; clfnt.lfStrikeOut = 0; clfnt.lfCharSet = RUSSIAN_CHARSET; clfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; clfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; clfnt.lfQuality = DEFAULT_QUALITY; clfnt.lfPitchAndFamily = DEFAULT_PITCH | FF_MODERN; strcpy (clfnt.lfFaceName, OptFontFace); h_font_code = CreateFontIndirect(&clfnt); create_wnd_content0(hMainWindow); _fullpath (CurrentPath, ".", sizeof(CurrentPath)); strcat (CurrentPath, "\\"); current_path_to_edit (); SetFocus(GetDlgItem(hMainWindow, IDC_TXT)); resize_controls (); recent_load (); recent_fill_combo (IDC_RECENT); set_options (); populate_dir (); search_init (); hDlgCurrent = hMainWindow; if (!SHGetSpecialFolderPath(NULL, SendtoPath, CSIDL_SENDTO, 0)) { //fprintf (stderr, "Cannot determine SendTo folder\n"); } else { //fprintf (stderr, "SendtoPath = %s\n", SendtoPath); } strcat (SendtoPath, "\\Search in files.lnk"); if (CreateShortCut(MyPath, "", SendtoPath, "Search in files", SW_SHOWNORMAL, "", "", 0) < 0) { //fprintf (stderr, "Error create shortcut %ld\n", GetLastError()); } do_gui_main_action (cmdline); return message_loop(); }