/*-------------------------------------------------------------------------- | | entryQ_length(autodir,filename) | | This function reads the file and returns the length of one automation Entry | | Author: Greg Brissey 9/3/96 +--------------------------------------------------------------------------*/ int entryQ_length(char *autodir, char *filename) { FILE *entryQ_file; char filepath[128]; char textline[80]; char eolch; int stat,lines; /* if autoinfo mapping file hase not be read do so now */ if (infomap.mapped != 1) /* true if autoinfo has been read for mapping */ { read_info_file(autodir); } if ( filename[0] != '/' ) /* if filename absolute path then don't use autodir */ { strncpy(filepath,autodir,110); strcat(filepath,"/"); strcat(filepath,filename); } else { strcpy(filepath,filename); } entryQ_file = fopen(filepath,"r"); if (entryQ_file == NULL) /* does file exist? */ { return(ERROR); } lines=0; while ( (stat = fscanf(entryQ_file,"%[^\n]%c", textline, &eolch)) != EOF ) { lines++; if ( stat != 2 ) { fprintf(stderr,"entryQ_length: '%s' file format error, line %d\n",filepath,lines); fclose(entryQ_file); return(ERROR); } if (strncmp(textline,infomap.eoe,10) == 0) { fclose(entryQ_file); return(lines); } } fclose(entryQ_file); fprintf(stderr,"Warning: No End-of-Entry Marker Found\n"); return(lines); }
/* cc -g -xF -xsb -DDBXTESTING asmfuncs.c */ main() { int len; struct sample_info s; SAMPLE_INFO ns; FILE *info_file; char info[120]; read_info_file("."); len = entryQ_length(".","GregAutoEntry"); printf("len: %d\n",len); len = entryQ_length(".","/vxwks/greg/inova/nautoproc/GregAutoEntry"); printf("len: %d\n",len); info_file = fopen("./GregAutoEntry","r"); read_sample_info(info_file,&ns); fclose(info_file); info_file = fopen("./tmpentry","w"); write_sample_info(info_file,&ns); fclose(info_file); len = get_sample_info (&ns,"DATA:",info,120,NULL); printf("DATA: '%s', len: %d\n",info,len); len = get_sample_info (&ns,"USERDIR:",info,120,NULL); printf("USERDIR: '%s', len: %d\n",info,len); len = get_sample_info (&ns,"STATUS:",info,120,NULL); printf("STATUS: '%s', len: %d\n",info,len); len = get_sample_info (&ns,"SAMPLE#:",info,120,NULL); printf("SAMPLE: '%s', len: %d\n",info,len); len = get_sample_info (&ns,"EOE:",info,120,NULL); printf("EOE: '%s', len: %d\n",info,len); update_sample_info(".","GregAutoEntry", "DATA:", "/userdir/greg/auto/file1234" , "STATUS:", "Complete" ); update_sample_info(".","GregAutoEntry", "DATA:", "/userdir/greg/auto/file1236" , "STATUS:", "Active" ); getPsgQentry("./psgQ",&ns); deletePsgQentry("./psgQ",&ns); deleteEnterQentry(".","enterQ"); }
WORD do_all( BYTE *filename ) { /* Hauptroutine */ BYTE *temp_file_name; /* Info-Datei lesen */ if( read_info_file() < 0 ) /* Fehler */ return( -1 ); /* Zeile zuruecksetzen */ zeile = 1; /* Grammatik-Datei lesen */ if( read_grammar_file( filename ) < 0 ) /* Fehler */ return( -1 ); /* Die Hash-Tabelle initialisieren */ if( ( hash_tab = ( HASH_TAB * ) calloc( lr_info.hash_tab_size, sizeof( HASH_TAB ) ) ) == NULL ) /* Fehler */ return( error( NOT_ENOUGH_MEMORY, 0, 0 ) ); /* Dateinamen ausgeben */ if( output_file_msg( filename ) < 0 ) /* Fehler */ return( -1 ); /* Ausgaben in Datei bzw. auf den Bildschirm */ if( lr_info.dest == DFILE ) { /* Dateinamen aufbereiten */ temp_file_name = strrchr( filename, ( WORD ) '.' ); strcpy( temp_file_name, ".TXT" ); /* Datei zum Schreiben �ffnen */ file = freopen( filename, "w", 0L ); } /* Ausgabe auf Bildschirm ? */ else if( lr_info.dest == DSCREEN ) /* Bildschirm */ file = stdout; else /* Drucker */ file = stdprn; /* Ausgabe der Fehler auf Bildschirm ? */ if( lr_info.err_dest == DSCREEN ) /* Bildschirm */ err_file = stderr; else /* Drucker */ err_file = stdprn; /* Grammatik analysieren */ if( analyze_grammar() < 0 ) /* Fehler */ return( -1 ); /* Speicher der Grammatik-Datei freigeben */ free_mem( ( VOID * ) &grammar ); /* Grammatik in BNF ausgeben ? */ if( !lr_info.output_grammar ) { /* Ja */ if( output_grammar() < 0 ) /* Fehler */ return( -1 ); } /* Items generieren */ if( generate_items() < 0 ) /* Fehler */ return( -1 ); /* Die LR-Tabelle erzeugen */ if( make_tab() < 0 ) /* Fehler */ return( -1 ); /* FIRST-Mengen ausgeben ? */ if( !lr_info.first ) { /* Ja */ if( output_first() < 0 ) /* Fehler */ return( -1 ); } /* FOLLOW-Mengen ausgeben ? */ if( !lr_info.follow ) { /* Ja */ if( output_follow() < 0 ) /* Fehler */ return( -1 ); } /* Items ausgeben ? */ if( !lr_info.lr_items ) { /* Ja */ if( output_items() < 0 ) /* Fehler */ return( -1 ); } /* LR-Tabelle ausgeben ? */ if( !lr_info.lr_tab ) { /* Ja */ if( output_lr_tab() < 0 ) /* Fehler */ return( -1 ); } /* LR-Tabelle optional komprimieren */ if( !lr_info.compress ) { /* LR-Tabelle komprimieren */ if( compress_lr_tab() < 0 ) /* Fehler */ return( -1 ); } /* Parser-Quelltext erzeugen */ if( generate_parser() < 0 ) /* Fehler */ return( -1 ); /* Alles OK */ return( 0 ); }
int main(int argc, char *argv[]) { /* TODO: refactor main() function */ char dir[PATH_MAX]; char lwin_path[PATH_MAX] = ""; char rwin_path[PATH_MAX] = ""; int lwin_handle = 0, rwin_handle = 0; int old_config; int no_configs; init_config(); if(is_in_string_array(argv + 1, argc - 1, "--logging")) { init_logger(1); } (void)setlocale(LC_ALL, ""); if(getcwd(dir, sizeof(dir)) == NULL) { perror("getcwd"); return -1; } #ifdef _WIN32 to_forward_slash(dir); #endif init_filelists(); init_registers(); set_config_paths(); reinit_logger(); init_commands(); init_builtin_functions(); update_path_env(1); if(init_status() != 0) { puts("Error during session status initialization."); return -1; } no_configs = is_in_string_array(argv + 1, argc - 1, "--no-configs"); /* Tell file type module what function to use to check availability of * external programs. */ config_filetypes(&external_command_exists); /* This should be called before loading any configuration file. */ reset_all_file_associations(curr_stats.env_type == ENVTYPE_EMULATOR_WITH_X); init_option_handlers(); old_config = is_old_config(); if(!old_config && !no_configs) read_info_file(0); ipc_pre_init(); parse_args(argc, argv, dir, lwin_path, rwin_path, &lwin_handle, &rwin_handle); ipc_init(&parse_recieved_arguments); init_background(); set_view_path(&lwin, lwin_path); set_view_path(&rwin, rwin_path); /* Force view switch when path is specified for invisible pane. */ if(lwin_path[0] != '\0' && rwin_path[0] == '\0' && curr_view != &lwin) { change_window(); } load_initial_directory(&lwin, dir); load_initial_directory(&rwin, dir); /* Force split view when two paths are specified on command-line. */ if(lwin_path[0] != '\0' && rwin_path[0] != '\0') { curr_stats.number_of_windows = 2; } /* Setup the ncurses interface. */ if(!setup_ncurses_interface()) return -1; colmgr_init(COLOR_PAIRS); init_modes(); init_undo_list(&perform_operation, NULL, &cfg.undo_levels); load_local_options(curr_view); curr_stats.load_stage = 1; if(!old_config && !no_configs) { load_scheme(); source_config(); } write_color_scheme_file(); setup_signals(); if(old_config && !no_configs) { convert_configs(); curr_stats.load_stage = 0; read_info_file(0); curr_stats.load_stage = 1; set_view_path(&lwin, lwin_path); set_view_path(&rwin, rwin_path); load_initial_directory(&lwin, dir); load_initial_directory(&rwin, dir); source_config(); } (void)create_trash_dir(cfg.trash_dir); check_path_for_file(&lwin, lwin_path, lwin_handle); check_path_for_file(&rwin, rwin_path, rwin_handle); curr_stats.load_stage = 2; exec_startup_commands(argc, argv); update_screen(UT_FULL); modes_update(); /* Update histories of the views to ensure that their current directories, * which might have been set using command-line parameters, are stored in the * history. This is not done automatically as history manipulation should be * postponed until views are fully loaded, otherwise there is no correct * information about current file and relative cursor position. */ save_view_history(&lwin, NULL, NULL, -1); save_view_history(&rwin, NULL, NULL, -1); curr_stats.load_stage = 3; main_loop(); return 0; }
int main(int argc, char *argv[]){ char *prog, *p; int32_t op; int32_t traceMask; Status_t status; /* * Set default values */ pm_lid = 0; //bm_lid = 0; dm_lid = 0; ConnDisconnect = FALSE; Shutdown = FALSE; /* Get the program name */ prog = argv[0]; p = prog; while (*p) { if (*p++ == '/') { prog = p; } } memset(mai_host,0,sizeof(mai_host)); /* Simulation host name */ mai_host_name = &mai_host[0]; mai_host_name = NULL; /* * Get the instance argument from the command line. */ // surpress getopt() error messages opterr = 0; snprintf(fe_env_str, sizeof(fe_env_str), "fe_0"); while ((op = getopt (argc, argv, "De:E:hH:l:C:X:")) != -1) { switch (op) { case 'D': fe_nodaemon = 0; break; case 'e': case 'E': strncpy (fe_env_str, optarg, 20); break; case 'h': case 'H': help((void *)prog); exit(1); case 'l': sscanf(optarg, "%u", (uint32_t *)&fe_log_level_arg); fe_log_level_override = 1; break; case 'C': sscanf(optarg, "%u", (uint32_t *)&fe_log_to_console); break; case 'X': sscanf(optarg, "%255s", fe_config_filename); break; } } /* * Get the environment variables before applying the command line overrides. * If this fails, we still continue because we have default values that we * can us. */ (void)read_info_file(); // initialize memory pool for FE XML parsing status = initFeXmlMemoryPool(); if (status != VSTATUS_OK) { IB_FATAL_ERROR("initFeXmlMemoryPool: fe_xml_pool vs_pool_create failure"); return 1; } // init callback function for XML parser so it can get pool memory initXmlPoolGetCallback(&getFeXmlParserMemory); initXmlPoolFreeCallback(&freeFeXmlParserMemory); // Parse the XML configuration fe_parse_xml_config(); fe_config.subnet_size = MAX(fe_config.subnet_size, MIN_SUPPORTED_ENDPORTS); mai_set_default_pkey(STL_DEFAULT_FM_PKEY); // enable rmpp debug messages if desired if (fe_config.debug_rmpp) if3RmppDebugOn(); // reset getopt() optind = 1; while ((op = getopt(argc,argv,"d:m:M:n:N:p:P:")) != EOF) { switch (op) { case 'd': fe_config.hca = atoi(optarg); break; case 'm': case 'M': fe_config.listen = atoi(optarg); break; case 'n': case 'N': fe_config.login = 0; break; case 'p': case 'P': fe_config.port = atoi(optarg); break; case 't': case 'T': sscanf(optarg, "0x%08x", (uint32_t *)&traceMask); IB_SET_LOG_MASK(traceMask); break; } } fe_compute_pool_size(); // compute sizes for FE resources fe_main(); return 0; }
/*--------------------------------------------------------------------------- | update_sample_info()/5 | | update_sample_info - | Takes a automation directory and filename of sample_info structure (e.g., doneQ,enterq,sampleinfo) | Searches through the file for a match between the match_target value | and the match_value; | Upon finding the match it then updates the update_target with the | update_value; | For example: You want to update the doneQ 'STATUS' entry to Complete, | for the experiment inwhich the DATA entry matches with | '/vnmr/auto/greg.1201' (i.e. DATA is a unique identifier). | The call would be: | update_sample_info("systemdir/auto","doneQ", | "DATA:","/vnmr/auto/greg.1201", | "STATUS","Complete"); | | Author: Greg Brissey 1/28/88 +--------------------------------------------------------------------------*/ int update_sample_info(char *autodir, char *filename, char *match_target, char *match_value, char *update_target, char *update_value) { FILE *update_file,*tmp_file; char filepath[128],value[MAX_TEXT_LEN]; struct sample_info sample_entry; int stat,entryline,foundit; strncpy(filepath,autodir,110); strcat(filepath,"/"); strcat(filepath,filename); /* if autoinfo mapping file hase not be read do so now */ if (infomap.mapped != 1) /* true if autoinfo has been read for mapping */ { read_info_file(autodir); } if (lockfile(filepath) == ERROR) /* lock file for excusive use */ { fprintf(stderr,"update_sample_info: could not lock '%s' file.\n",filepath); } update_file = fopen(filepath,"r"); if (update_file == NULL) /* does file exist? */ { unlockfile(filepath); /* unlock file */ fprintf(stderr,"update_sample_info: '%s' file is not present for reading.\n", filepath); return(ERROR); } tmp_file = fopen("/tmp/update_sample_info.tmp","w"); if (tmp_file == NULL) /* does file exist? */ { unlockfile(filepath); /* unlock file */ fclose(update_file); fprintf(stderr, "update_sample_info: temp file '/tmp/update_sample_info.tmp' could not be created.\n"); return(ERROR); } /* read through the the file writing to a tmp file as changes are made */ foundit = 0; while ( (stat = read_sample_info(update_file,&sample_entry)) != ENDOFFILE) { if (stat == ERROR) { unlockfile(filepath); /* unlock file */ fclose(update_file); fclose(tmp_file); fprintf(stderr, "update_sample_info: read error on file '%s'.\n",filepath); return(ERROR); } /* Once found and changed we can skip all this */ if (!foundit) { get_sample_info(&sample_entry,match_target,value,MAX_TEXT_LEN,&entryline); if (strncmp(value,match_value,MAX_TEXT_LEN) == 0) { get_sample_info(&sample_entry,update_target,value,MAX_TEXT_LEN,&entryline); /* If updating STATUS and STATUS: Shimming, then remove this entry */ if ( (strcmp(infomap.status,update_target) == 0) && ( (strcmp(update_value,"Complete") == 0) || (strcmp(update_value,"Error") == 0)) && (strcmp(sample_entry.prompt_entry[entryline].etext,"Shimming") == 0) ) { /* elimenate Shimming Experiment from doneQ */ foundit = 1; continue; /* don't update, don't write it out */ } strncpy(sample_entry.prompt_entry[entryline].etext,update_value,MAX_TEXT_LEN); sample_entry.prompt_entry[entryline].etext[MAX_TEXT_LEN-1] = '\0'; foundit = 1; } } if (write_sample_info(tmp_file,&sample_entry) == ERROR) { unlockfile(filepath); /* unlock file */ fclose(update_file); fclose(tmp_file); fprintf(stderr, "update_sample_info: write error to temp file '/tmp/update_sample_info.tmp'.\n"); return(ERROR); } } fclose(update_file); fclose(tmp_file); /* Changes are complete in the tmp file, now copy the tmp file into the orginal file */ tmp_file = fopen("/tmp/update_sample_info.tmp","r"); if (tmp_file == NULL) /* does file exist? */ { unlockfile(filepath); /* unlock file */ fprintf(stderr, "update_sample_info: temp file '/tmp/update_sample_info.tmp' could not be opened to be read.\n"); return(ERROR); } update_file = fopen(filepath,"w"); if (update_file == NULL) /* does file exist? */ { unlockfile(filepath); /* unlock file */ fclose(tmp_file); fprintf(stderr,"update_sample_info: '%s' file is not present for writing.\n", filepath); return(ERROR); } while ( ( stat = read_sample_info(tmp_file,&sample_entry)) != ENDOFFILE) { if (stat == ERROR) { unlockfile(filepath); /* unlock file */ fclose(update_file); fclose(tmp_file); fprintf(stderr, "update_sample_info: read error on file '/tmp/update_sample_info.tmp'.\n"); return(ERROR); } if (write_sample_info(update_file,&sample_entry) == ERROR) { unlockfile(filepath); /* unlock file */ fclose(update_file); fclose(tmp_file); fprintf(stderr, "update_sample_info: write error to file '%s'.\n",filepath); return(ERROR); } } fclose(update_file); fclose(tmp_file); unlockfile(filepath); /* unlock file */ return(OK); }
int main(int argc, char *argv[]) { char *tmpptr; struct stat statbuf; sigset_t blockmask; void TheGrimReaper(void*); void processMsge(void*); void set_output(); strncpy(ProcName,argv[0],256); ProcName[255] = '\0'; /* --- mask to block SIGALRM, SIGIO and SIGCHLD interrupts --- */ sigemptyset( &blockmask ); sigaddset( &blockmask, SIGALRM ); sigaddset( &blockmask, SIGIO ); sigaddset( &blockmask, SIGCHLD ); sigaddset( &blockmask, SIGQUIT ); sigaddset( &blockmask, SIGPIPE ); sigaddset( &blockmask, SIGALRM ); sigaddset( &blockmask, SIGTERM ); sigaddset( &blockmask, SIGUSR1 ); sigaddset( &blockmask, SIGUSR2 ); DebugLevel = 0; umask(000); /* clear file creation mode mask,so that open has control */ strcpy(autodir,argv[1]); set_output(); DPRINT1(1,"Automation Directory: '%s'\n",autodir); fprintf(stdout,"Start of Automation\n"); /* Lets use the syslog facility provide by the OS. */ logSysInit("Autoproc",AUTOLOG_FACILITY); /* initialize exception handlers */ setupexcepthandler(); /* initialize command parser */ initCmdParser(); /* Map in Expproc Experiment Queues */ initExpQs(0); /* Experiment waiting to be run */ initActiveExpQ(0); /* Experiment that is presently acquiring */ /* Map in Processing Queues */ initProcQs(0); /* pending processing */ initActiveQ(0); /* active processing */ /* initialize environment parameter vnmrsystem value */ tmpptr = getenv("vnmrsystem"); /* vnmrsystem */ if (tmpptr != NULL) { strcpy(systemdir,tmpptr); /* copy value into global */ } else { strcpy(systemdir,"/vnmr"); /* use /vnmr as default value */ } sprintf(enterpath,"%s/acqbin/Autolog",systemdir); if ( ! access(enterpath,F_OK) ) { DebugLevel = 1; } strcpy(enterpath,autodir); strcat(enterpath,"/enterQ"); strcpy(samplepath,autodir); strcat(samplepath,"/exp1/sampleinfo"); strcpy(psgQpath,autodir); strcat(psgQpath,"/psgQ"); strcpy(doneQpath,autodir); strcat(doneQpath,"/doneQ"); DPRINT3(1,"autodir:'%s', enter:'%s', psgQ:'%s'\n", autodir,enterpath,psgQpath); /* do any remapping of enterQ key words */ read_info_file(autodir); /* Obtain the owner of the Automation directory. Forked Vnmr(s) will be run under this owner uid & gid. */ if (stat(autodir, &statbuf) < 0) { perror("autoproc: stat() can't stat enterQ: "); /* OK, default to root */ enter_uid = (pid_t) 0; enter_gid = (gid_t) 0; } else { enter_uid = statbuf.st_uid; enter_gid = statbuf.st_gid; } /* Initialize the Event Handlers Queue */ setupForAsync(20, &blockmask); blockAllEvents(); /* here we register both the signal handler to be called and the non-interrupt function to handle the I/O */ registerAsyncHandlers( SIGCHLD, /* BG processing Signal */ childItrp, /* this puts the event on the eventQ */ TheGrimReaper ); /* setup key database, and Message Queue, facilities */ pRecvMsgQ = createMsgQ("Autoproc", (int) AUTOPROC_MSGQ_KEY, (int) AUTO_MSG_SIZE); if (pRecvMsgQ == NULL) exit(1); pExpMsgQ = openMsgQ("Expproc"); if (pExpMsgQ == NULL) exit(1); setMsgQAsync(pRecvMsgQ,processMsge); unblockAllEvents(); /* switch to root here so that autoproc will have permission to lock and unlock the various Qs it uses */ seteuid(getuid()); DPRINT4(1,"uid: %d, euid: %d, gid: %d, egid: %d\n",getuid(),geteuid(),getgid(),getegid()); /* * Used to get this first resume from Expproc, but there is a race between Expproc * sending the resume and Autoproc's createMsgQ() which may interpret that resume * as an old message and delete it */ Resume(""); asyncMainLoop(); closeMsgQ(pExpMsgQ); shutdownComm(); return(EXIT_SUCCESS); }
void vifm_restart(void) { view_t *tmp_view; curr_stats.restart_in_progress = 1; /* All user mappings in all modes. */ vle_keys_user_clear(); /* User defined commands. */ vle_cmds_run("comclear"); /* Autocommands. */ vle_aucmd_remove(NULL, NULL); /* All kinds of histories. */ cfg_resize_histories(0); /* Session status. Must be reset _before_ options, because options take some * of values from status. */ (void)stats_reset(&cfg); /* Options of current pane. */ vle_opts_restore_defaults(); /* Options of other pane. */ tmp_view = curr_view; curr_view = other_view; load_view_options(other_view); vle_opts_restore_defaults(); curr_view = tmp_view; /* File types and viewers. */ ft_reset(curr_stats.exec_env_type == EET_EMULATOR_WITH_X); /* Undo list. */ un_reset(); /* Directory stack. */ dir_stack_clear(); /* Registers. */ regs_reset(); /* Clear all marks and bookmarks. */ clear_all_marks(); bmarks_clear(); /* Reset variables. */ clear_envvars(); init_variables(); /* This update is needed as clear_variables() will reset $PATH. */ update_path_env(1); reset_views(); read_info_file(1); flist_hist_save(&lwin, NULL, NULL, -1); flist_hist_save(&rwin, NULL, NULL, -1); /* Color schemes. */ if(stroscmp(curr_stats.color_scheme, DEF_CS_NAME) != 0 && cs_exists(curr_stats.color_scheme)) { cs_load_primary(curr_stats.color_scheme); } else { cs_load_defaults(); } cs_load_pairs(); cfg_load(); /* Reloading of tabs needs to happen after configuration is read so that new * values from lwin and rwin got propagated. */ tabs_reload(); exec_startup_commands(&vifm_args); curr_stats.restart_in_progress = 0; /* Trigger auto-commands for initial directories. */ (void)vifm_chdir(flist_get_dir(&lwin)); vle_aucmd_execute("DirEnter", flist_get_dir(&lwin), &lwin); (void)vifm_chdir(flist_get_dir(&rwin)); vle_aucmd_execute("DirEnter", flist_get_dir(&rwin), &rwin); update_screen(UT_REDRAW); }
/* Entry-point. Has same semantics as main(). */ static int vifm_main(int argc, char *argv[]) { /* TODO: refactor vifm_main() function */ static const int quit = 0; char **files = NULL; int nfiles = 0; int lwin_cv, rwin_cv; char dir[PATH_MAX + 1]; if(get_start_cwd(dir, sizeof(dir)) != 0) { return -1; } args_parse(&vifm_args, argc, argv, dir); args_process(&vifm_args, 1); lwin_cv = (strcmp(vifm_args.lwin_path, "-") == 0 && vifm_args.lwin_handle); rwin_cv = (strcmp(vifm_args.rwin_path, "-") == 0 && vifm_args.rwin_handle); if(lwin_cv || rwin_cv) { files = read_stream_lines(stdin, &nfiles, 1, NULL, NULL); if(reopen_term_stdin() != 0) { free_string_array(files, nfiles); return EXIT_FAILURE; } } (void)setlocale(LC_ALL, ""); srand(time(NULL)); cfg_init(); if(vifm_args.logging) { init_logger(1, vifm_args.startup_log_path); } init_filelists(); tabs_init(); regs_init(); cfg_discover_paths(); reinit_logger(cfg.log_file); /* Commands module also initializes bracket notation and variables. */ init_commands(); init_builtin_functions(); update_path_env(1); if(stats_init(&cfg) != 0) { free_string_array(files, nfiles); puts("Error during session status initialization."); return -1; } /* Tell file type module what function to use to check availability of * external programs. */ ft_init(&external_command_exists); /* This should be called before loading any configuration file. */ ft_reset(curr_stats.exec_env_type == EET_EMULATOR_WITH_X); init_option_handlers(); if(!vifm_args.no_configs) { /* vifminfo must be processed this early so that it can restore last visited * directory. */ read_info_file(0); } curr_stats.ipc = ipc_init(vifm_args.server_name, &parse_received_arguments, &eval_received_expression); if(ipc_enabled() && curr_stats.ipc == NULL) { fputs("Failed to initialize IPC unit", stderr); return -1; } /* Export chosen server name to parsing unit. */ { var_t var = var_from_str(ipc_get_name(curr_stats.ipc)); setvar("v:servername", var); var_free(var); } args_process(&vifm_args, 0); bg_init(); fops_init(&enter_prompt_mode, &prompt_msg_custom); set_view_path(&lwin, vifm_args.lwin_path); set_view_path(&rwin, vifm_args.rwin_path); if(need_to_switch_active_pane(vifm_args.lwin_path, vifm_args.rwin_path)) { swap_view_roles(); } load_initial_directory(&lwin, dir); load_initial_directory(&rwin, dir); /* Force split view when two paths are specified on command-line. */ if(vifm_args.lwin_path[0] != '\0' && vifm_args.rwin_path[0] != '\0') { curr_stats.number_of_windows = 2; } /* Prepare terminal for further operations. */ curr_stats.original_stdout = reopen_term_stdout(); if(curr_stats.original_stdout == NULL) { free_string_array(files, nfiles); return -1; } if(!setup_ncurses_interface()) { free_string_array(files, nfiles); return -1; } init_modes(); un_init(&undo_perform_func, NULL, &ui_cancellation_requested, &cfg.undo_levels); load_view_options(curr_view); curr_stats.load_stage = 1; /* Make v:count exist during processing configuration. */ set_count_vars(0); if(!vifm_args.no_configs) { load_scheme(); cfg_load(); } if(lwin_cv || rwin_cv) { flist_custom_set(lwin_cv ? &lwin : &rwin, "-", dir, files, nfiles); } free_string_array(files, nfiles); cs_load_pairs(); cs_write(); setup_signals(); /* Ensure trash directories exist, it might not have been called during * configuration file sourcing if there is no `set trashdir=...` command. */ (void)set_trash_dir(cfg.trash_dir); check_path_for_file(&lwin, vifm_args.lwin_path, vifm_args.lwin_handle); check_path_for_file(&rwin, vifm_args.rwin_path, vifm_args.rwin_handle); curr_stats.load_stage = 2; /* Update histories of the views to ensure that their current directories, * which might have been set using command-line parameters, are stored in the * history. This is not done automatically as history manipulation should be * postponed until views are fully loaded, otherwise there is no correct * information about current file and relative cursor position. */ flist_hist_save(&lwin, NULL, NULL, -1); flist_hist_save(&rwin, NULL, NULL, -1); /* Trigger auto-commands for initial directories. */ if(!lwin_cv) { (void)vifm_chdir(flist_get_dir(&lwin)); vle_aucmd_execute("DirEnter", flist_get_dir(&lwin), &lwin); } if(!rwin_cv) { (void)vifm_chdir(flist_get_dir(&rwin)); vle_aucmd_execute("DirEnter", flist_get_dir(&rwin), &rwin); } update_screen(UT_FULL); modes_update(); /* Run startup commands after loading file lists into views, so that commands * like +1 work. */ exec_startup_commands(&vifm_args); curr_stats.load_stage = 3; event_loop(&quit); return 0; }
void vifm_restart(void) { FileView *tmp_view; curr_stats.restart_in_progress = 1; /* All user mappings in all modes. */ vle_keys_user_clear(); /* User defined commands. */ execute_cmd("comclear"); /* Autocommands. */ vle_aucmd_remove(NULL, NULL); /* Directory histories. */ ui_view_clear_history(&lwin); ui_view_clear_history(&rwin); /* All kinds of history. */ (void)hist_reset(&cfg.search_hist, cfg.history_len); (void)hist_reset(&cfg.cmd_hist, cfg.history_len); (void)hist_reset(&cfg.prompt_hist, cfg.history_len); (void)hist_reset(&cfg.filter_hist, cfg.history_len); cfg.history_len = 0; /* Session status. Must be reset _before_ options, because options take some * of values from status. */ (void)reset_status(&cfg); /* Options of current pane. */ reset_options_to_default(); /* Options of other pane. */ tmp_view = curr_view; curr_view = other_view; load_view_options(other_view); reset_options_to_default(); curr_view = tmp_view; /* File types and viewers. */ ft_reset(curr_stats.exec_env_type == EET_EMULATOR_WITH_X); /* Undo list. */ reset_undo_list(); /* Directory stack. */ dir_stack_clear(); /* Registers. */ regs_reset(); /* Clear all marks and bookmarks. */ clear_all_marks(); bmarks_clear(); /* Reset variables. */ clear_envvars(); init_variables(); /* This update is needed as clear_variables() will reset $PATH. */ update_path_env(1); reset_views(); read_info_file(1); flist_hist_save(&lwin, NULL, NULL, -1); flist_hist_save(&rwin, NULL, NULL, -1); /* Color schemes. */ if(stroscmp(curr_stats.color_scheme, DEF_CS_NAME) != 0 && cs_exists(curr_stats.color_scheme)) { if(cs_load_primary(curr_stats.color_scheme) != 0) { cs_load_defaults(); } } else { cs_load_defaults(); } cs_load_pairs(); cfg_load(); exec_startup_commands(&vifm_args); curr_stats.restart_in_progress = 0; /* Trigger auto-commands for initial directories. */ vle_aucmd_execute("DirEnter", lwin.curr_dir, &lwin); vle_aucmd_execute("DirEnter", rwin.curr_dir, &rwin); update_screen(UT_REDRAW); }
int main(int argc, char *argv[]) { /* TODO: refactor main() function */ static const int quit = 0; char dir[PATH_MAX]; char **files = NULL; int nfiles = 0; if(get_cwd(dir, sizeof(dir)) == NULL) { perror("getcwd"); return -1; } (void)vifm_chdir(dir); args_parse(&vifm_args, argc, argv, dir); args_process(&vifm_args, 1); if(strcmp(vifm_args.lwin_path, "-") == 0 || strcmp(vifm_args.rwin_path, "-") == 0) { files = read_stream_lines(stdin, &nfiles, 1, NULL, NULL); if(reopen_term_stdin() != 0) { return EXIT_FAILURE; } } (void)setlocale(LC_ALL, ""); srand(time(NULL)); cfg_init(); if(vifm_args.logging) { init_logger(1, vifm_args.startup_log_path); } init_filelists(); regs_init(); cfg_discover_paths(); reinit_logger(cfg.log_file); /* Commands module also initializes bracket notation and variables. */ init_commands(); init_builtin_functions(); update_path_env(1); if(init_status(&cfg) != 0) { puts("Error during session status initialization."); return -1; } /* Tell file type module what function to use to check availability of * external programs. */ ft_init(&external_command_exists); /* This should be called before loading any configuration file. */ ft_reset(curr_stats.exec_env_type == EET_EMULATOR_WITH_X); init_option_handlers(); if(!vifm_args.no_configs) { /* vifminfo must be processed this early so that it can restore last visited * directory. */ read_info_file(0); } ipc_init(vifm_args.server_name, &parse_received_arguments); /* Export chosen server name to parsing unit. */ { var_val_t value = { .string = (char *)ipc_get_name() }; var_t var = var_new(VTYPE_STRING, value); setvar("v:servername", var); var_free(var); } args_process(&vifm_args, 0); bg_init(); fops_init(&enter_prompt_mode, &prompt_msg_custom); set_view_path(&lwin, vifm_args.lwin_path); set_view_path(&rwin, vifm_args.rwin_path); if(need_to_switch_active_pane(vifm_args.lwin_path, vifm_args.rwin_path)) { swap_view_roles(); } load_initial_directory(&lwin, dir); load_initial_directory(&rwin, dir); /* Force split view when two paths are specified on command-line. */ if(vifm_args.lwin_path[0] != '\0' && vifm_args.rwin_path[0] != '\0') { curr_stats.number_of_windows = 2; } /* Prepare terminal for further operations. */ curr_stats.original_stdout = reopen_term_stdout(); if(curr_stats.original_stdout == NULL) { return -1; } if(!setup_ncurses_interface()) { return -1; } { const colmgr_conf_t colmgr_conf = { .max_color_pairs = COLOR_PAIRS, .max_colors = COLORS, .init_pair = &init_pair, .pair_content = &pair_content, .pair_in_use = &pair_in_use, .move_pair = &move_pair, }; colmgr_init(&colmgr_conf); } init_modes(); init_undo_list(&undo_perform_func, NULL, &ui_cancellation_requested, &cfg.undo_levels); load_view_options(curr_view); curr_stats.load_stage = 1; if(!vifm_args.no_configs) { load_scheme(); cfg_load(); if(strcmp(vifm_args.lwin_path, "-") == 0) { flist_custom_set(&lwin, "-", dir, files, nfiles); } else if(strcmp(vifm_args.rwin_path, "-") == 0) { flist_custom_set(&rwin, "-", dir, files, nfiles); } } /* Load colors in any case to load color pairs. */ cs_load_pairs(); cs_write(); setup_signals(); /* Ensure trash directories exist, it might not have been called during * configuration file sourcing if there is no `set trashdir=...` command. */ (void)set_trash_dir(cfg.trash_dir); check_path_for_file(&lwin, vifm_args.lwin_path, vifm_args.lwin_handle); check_path_for_file(&rwin, vifm_args.rwin_path, vifm_args.rwin_handle); curr_stats.load_stage = 2; /* Update histories of the views to ensure that their current directories, * which might have been set using command-line parameters, are stored in the * history. This is not done automatically as history manipulation should be * postponed until views are fully loaded, otherwise there is no correct * information about current file and relative cursor position. */ flist_hist_save(&lwin, NULL, NULL, -1); flist_hist_save(&rwin, NULL, NULL, -1); /* Trigger auto-commands for initial directories. */ vle_aucmd_execute("DirEnter", lwin.curr_dir, &lwin); vle_aucmd_execute("DirEnter", rwin.curr_dir, &rwin); update_screen(UT_FULL); modes_update(); /* Run startup commands after loading file lists into views, so that commands * like +1 work. */ exec_startup_commands(&vifm_args); curr_stats.load_stage = 3; event_loop(&quit); return 0; } /* Checks whether pair is being used at the moment. Returns non-zero if so and * zero otherwise. */ static int pair_in_use(short int pair) { int i; for(i = 0; i < MAXNUM_COLOR; ++i) { if(cfg.cs.pair[i] == pair || lwin.cs.pair[i] == pair || rwin.cs.pair[i] == pair) { return 1; } } return 0; }