Esempio n. 1
0
void    read_master(int fail_on_open_error)
{
    const char *myname = "read_master";
    char   *path;
    VSTRING *buf;
    VSTREAM *fp;
    const char *err;
    int     entry_count = 0;
    int     line_count = 0;

    /*
     * Sanity check.
     */
    if (master_table != 0)
	msg_panic("%s: master table is already initialized", myname);

    /*
     * Get the location of master.cf.
     */
    if (var_config_dir == 0)
	set_config_dir();
    path = concatenate(var_config_dir, "/", MASTER_CONF_FILE, (char *) 0);

    /*
     * Initialize the in-memory master table.
     */
    master_table = (PC_MASTER_ENT *) mymalloc(sizeof(*master_table));

    /*
     * Skip blank lines and comment lines. Degrade gracefully if master.cf is
     * not available, and master.cf is not the primary target.
     */
    if ((fp = vstream_fopen(path, O_RDONLY, 0)) == 0) {
	if (fail_on_open_error)
	    msg_fatal("open %s: %m", path);
	msg_warn("open %s: %m", path);
    } else {
	buf = vstring_alloc(100);
	while (readlline(buf, fp, &line_count) != 0) {
	    master_table = (PC_MASTER_ENT *) myrealloc((char *) master_table,
				 (entry_count + 2) * sizeof(*master_table));
	    if ((err = parse_master_line(master_table + entry_count,
					 STR(buf))) != 0)
		msg_fatal("file %s: line %d: %s", path, line_count, err);
	    entry_count += 1;
	}
	vstream_fclose(fp);
	vstring_free(buf);
    }

    /*
     * Null-terminate the master table and clean up.
     */
    master_table[entry_count].argv = 0;
    myfree(path);
}
Esempio n. 2
0
int main(int argc,char * argv[]) 
{
  FailureType fail = 0 ;
  FailureType should_fail_on = 0;
  int i;
  boolean doinfo = FALSE;
  boolean noaddnumbers = FALSE;
  MethodTypeSet * mts;
  MethodTypeSet * cp;
  boolean no_config_mts = FALSE;
  int prot_level = 0;
  int should_hard_link = 0;
  boolean should_warn_undoc = FALSE;
  char * prot_str;
  char * runner;
  char *config_dir=NULL;
  char buffer[64]; /** really for removing files **/
  char * telegraph;
  
  APIpara api;

  char * pack;
	
  /** we no longer read in configs **/

  mts = standard_dynamite_MethodTypeSet();


  if( strip_out_boolean_argument(&argc,argv,"h") == TRUE 
      || strip_out_boolean_argument(&argc,argv,"u") == TRUE /* arve */
      || argc == 1 ) {
	show_usage(stdout);
	exit(1);
	}

  noaddnumbers   = strip_out_boolean_argument(&argc,argv,"m");
  doinfo        = strip_out_boolean_argument(&argc,argv,"i");
  no_config_mts = strip_out_boolean_argument(&argc,argv,"U");
  should_hard_link = strip_out_boolean_argument(&argc,argv,"l");
  prot_str      = strip_out_assigned_argument(&argc,argv,"P");
  should_warn_undoc = strip_out_boolean_argument(&argc,argv,"D");
  telegraph    = strip_out_assigned_argument(&argc,argv,"tele");

  pack = strip_out_assigned_argument(&argc,argv,"n");

  api.xs_ext = NULL;
  api.typemap_ext = NULL;
  api.pod_ext = NULL;

  api.c_extension_name = strip_out_assigned_argument(&argc,argv,"a");
  api.t_extension_name = strip_out_assigned_argument(&argc,argv,"b");
  api.pfdoc_ext = strip_out_assigned_argument(&argc,argv,"p");
  api.xs_ext = strip_out_assigned_argument(&argc,argv,"x");
  api.typemap_ext = strip_out_assigned_argument(&argc,argv,"tym");
  api.all_callable = strip_out_boolean_argument(&argc,argv,"c");
  api.make_perl = strip_out_boolean_argument(&argc,argv,"perl");
  api.latex_ext = strip_out_assigned_argument(&argc,argv,"exttex");
  api.make_latex = strip_out_boolean_argument(&argc,argv,"latex");


  if( api.make_perl == TRUE) {
   
    if( api.xs_ext == NULL ) {
      api.xs_ext = ".xs";
    }
    if( api.typemap_ext == NULL ) {
      api.typemap_ext = ".typemap";
    }
    if( api.pod_ext == NULL ) {
      api.pod_ext = ".pod";
    }
  }


  if( strip_out_boolean_argument(&argc,argv,"F") == TRUE) {
    should_fail_on = FailureType_dyc_All;
  }

  /* do DPImplementation */

  dpi = new_DPImplementation_from_argstr(&argc,argv);

  if( prot_str != NULL ) {
      if( is_integer_string(prot_str,&prot_level) == FALSE ) {
	  warn("Protection level %s is no integer!");
	  prot_level = 0;
      }
  }

				/* Override/set WISECONFIGDIR on the cmdline. (arve) */
  config_dir = strip_out_assigned_argument(&argc, argv, "I");
  if (config_dir != NULL) {
      set_config_dir(config_dir); 
  }

  if( read_into_MethodTypeSet_filename(mts,"methods") == FALSE){
    warn("You have no config file called 'methods'. This is bad news for dynamite matrices. I will attempt to compile, but you cannot use logical types. 'methods' should be either in the current directory, the $WISECONFIGDIR or your $WISEPERSONALDIR");
  }



  /*** ok,loop over and do it ***/

  if( argc < 1 ) {
    warn("You must have at least one dynamite source file to compile!");
    show_usage(stdout);
    exit(1);
  }

  if( telegraph != NULL ) {
    tele_file= fopen(telegraph,"w");
  }

  
  for(i=1;i<argc;i++) {
    if( mts != NULL) 
      cp = copy_MethodTypeSet(mts); /* actually very cheap */
    if( do_a_file(argv[i],mts,FALSE,prot_level,should_hard_link,should_warn_undoc,noaddnumbers == TRUE ? FALSE : TRUE,pack,&api,&fail) == FALSE ) {
      
      fatal("Terminated dyc one %d argument %s",i,argv[i]);
    }
    if( (should_fail_on == 01 && fail != 0) || (fail & should_fail_on) ) {

      /*** remove files which fail ****/

      /*** ugh this should be done better ***/

      for(runner=argv[i]+strlen(argv[i]) - 1;runner > argv[i] && *runner != '.';runner--)
	;
      if( runner != argv[i] ) {
	*runner = '\0';
	sprintf(buffer,"%s.c",argv[i]);
	if( remove_file(buffer) == FALSE ) {
	  warn("Could not remove file %s from filesystem",buffer);
	}
	sprintf(buffer,"%s.h",argv[i]);
	if( remove_file(buffer) == FALSE ) {
	  warn("Could not remove file %s from filesystem",buffer);
	}
      }
      /* else - well - something bad has happened */
      
      fatal("Failed on file %s due to user defined fails",argv[i]);
    }

    if( mts != NULL ) {
      free_MethodTypeSet(mts);
      mts = cp;
    }
  }

  free_MethodTypeSet(mts);

  return 0;
}  
Esempio n. 3
0
void    edit_parameters(int mode, int argc, char **argv)
{
    char   *path;
    EDIT_FILE *ep;
    VSTREAM *src;
    VSTREAM *dst;
    VSTRING *buf = vstring_alloc(100);
    VSTRING *key = vstring_alloc(10);
    char   *cp;
    char   *edit_key;
    char   *edit_val;
    HTABLE *table;
    struct cvalue {
	char   *value;
	int     found;
    };
    struct cvalue *cvalue;
    HTABLE_INFO **ht_info;
    HTABLE_INFO **ht;
    int     interesting;
    const char *err;

    /*
     * Store command-line parameters for quick lookup.
     */
    table = htable_create(argc);
    while ((cp = *argv++) != 0) {
	if (strchr(cp, '\n') != 0)
	    msg_fatal("-e or -# accepts no multi-line input");
	while (ISSPACE(*cp))
	    cp++;
	if (*cp == '#')
	    msg_fatal("-e or -# accepts no comment input");
	if (mode & EDIT_MAIN) {
	    if ((err = split_nameval(cp, &edit_key, &edit_val)) != 0)
		msg_fatal("%s: \"%s\"", err, cp);
	} else if (mode & COMMENT_OUT) {
	    if (*cp == 0)
		msg_fatal("-# requires non-blank parameter names");
	    if (strchr(cp, '=') != 0)
		msg_fatal("-# requires parameter names only");
	    edit_key = mystrdup(cp);
	    trimblanks(edit_key, 0);
	    edit_val = 0;
	} else {
	    msg_panic("edit_parameters: unknown mode %d", mode);
	}
	cvalue = (struct cvalue *) mymalloc(sizeof(*cvalue));
	cvalue->value = edit_val;
	cvalue->found = 0;
	htable_enter(table, edit_key, (char *) cvalue);
    }

    /*
     * Open a temp file for the result. This uses a deterministic name so we
     * don't leave behind thrash with random names.
     */
    set_config_dir();
    path = concatenate(var_config_dir, "/", MAIN_CONF_FILE, (char *) 0);
    if ((ep = edit_file_open(path, O_CREAT | O_WRONLY, 0644)) == 0)
	msg_fatal("open %s%s: %m", path, EDIT_FILE_SUFFIX);
    dst = ep->tmp_fp;

    /*
     * Open the original file for input.
     */
    if ((src = vstream_fopen(path, O_RDONLY, 0)) == 0) {
	/* OK to delete, since we control the temp file name exclusively. */
	(void) unlink(ep->tmp_path);
	msg_fatal("open %s for reading: %m", path);
    }

    /*
     * Copy original file to temp file, while replacing parameters on the
     * fly. Issue warnings for names found multiple times.
     */
#define STR(x) vstring_str(x)

    interesting = 0;
    while (vstring_get(buf, src) != VSTREAM_EOF) {
	for (cp = STR(buf); ISSPACE(*cp) /* including newline */ ; cp++)
	     /* void */ ;
	/* Copy comment, all-whitespace, or empty line. */
	if (*cp == '#' || *cp == 0) {
	    vstream_fputs(STR(buf), dst);
	}
	/* Copy, skip or replace continued text. */
	else if (cp > STR(buf)) {
	    if (interesting == 0)
		vstream_fputs(STR(buf), dst);
	    else if (mode & COMMENT_OUT)
		vstream_fprintf(dst, "#%s", STR(buf));
	}
	/* Copy or replace start of logical line. */
	else {
	    vstring_strncpy(key, cp, strcspn(cp, " \t\r\n="));
	    cvalue = (struct cvalue *) htable_find(table, STR(key));
	    if ((interesting = !!cvalue) != 0) {
		if (cvalue->found++ == 1)
		    msg_warn("%s: multiple entries for \"%s\"", path, STR(key));
		if (mode & EDIT_MAIN)
		    vstream_fprintf(dst, "%s = %s\n", STR(key), cvalue->value);
		else if (mode & COMMENT_OUT)
		    vstream_fprintf(dst, "#%s", cp);
		else
		    msg_panic("edit_parameters: unknown mode %d", mode);
	    } else {
		vstream_fputs(STR(buf), dst);
	    }
	}
    }

    /*
     * Generate new entries for parameters that were not found.
     */
    if (mode & EDIT_MAIN) {
	for (ht_info = ht = htable_list(table); *ht; ht++) {
	    cvalue = (struct cvalue *) ht[0]->value;
	    if (cvalue->found == 0)
		vstream_fprintf(dst, "%s = %s\n", ht[0]->key, cvalue->value);
	}
	myfree((char *) ht_info);
    }

    /*
     * When all is well, rename the temp file to the original one.
     */
    if (vstream_fclose(src))
	msg_fatal("read %s: %m", path);
    if (edit_file_close(ep) != 0)
	msg_fatal("close %s%s: %m", path, EDIT_FILE_SUFFIX);

    /*
     * Cleanup.
     */
    myfree(path);
    vstring_free(buf);
    vstring_free(key);
    htable_free(table, myfree);
}
Esempio n. 4
0
void    read_master(int fail_on_open_error)
{
    const char *myname = "read_master";
    char   *path;
    VSTRING *buf;
    ARGV   *argv;
    VSTREAM *fp;
    int     entry_count = 0;
    int     line_count = 0;

    /*
     * Sanity check.
     */
    if (master_table != 0)
	msg_panic("%s: master table is already initialized", myname);

    /*
     * Get the location of master.cf.
     */
    if (var_config_dir == 0)
	set_config_dir();
    path = concatenate(var_config_dir, "/", MASTER_CONF_FILE, (char *) 0);

    /*
     * We can't use the master daemon's master_ent routines in their current
     * form. They convert everything to internal form, and they skip disabled
     * services.
     * 
     * The postconf command needs to show default fields as "-", and needs to
     * know about all service names so that it can generate service-dependent
     * parameter names (transport-dependent etc.).
     */
#define MASTER_BLANKS	" \t\r\n"		/* XXX */

    /*
     * Initialize the in-memory master table.
     */
    master_table = (PC_MASTER_ENT *) mymalloc(sizeof(*master_table));

    /*
     * Skip blank lines and comment lines. Degrade gracefully if master.cf is
     * not available, and master.cf is not the primary target.
     */
    if ((fp = vstream_fopen(path, O_RDONLY, 0)) == 0) {
	if (fail_on_open_error)
	    msg_fatal("open %s: %m", path);
	msg_warn("open %s: %m", path);
    } else {
	buf = vstring_alloc(100);
	while (readlline(buf, fp, &line_count) != 0) {
	    master_table = (PC_MASTER_ENT *) myrealloc((char *) master_table,
				 (entry_count + 2) * sizeof(*master_table));
	    argv = argv_split(STR(buf), MASTER_BLANKS);
	    if (argv->argc < PC_MASTER_MIN_FIELDS)
		msg_fatal("file %s: line %d: bad field count",
			  path, line_count);
	    normalize_options(argv);
	    master_table[entry_count].name_space =
		concatenate(argv->argv[0], ".", argv->argv[1], (char *) 0);
	    master_table[entry_count].argv = argv;
	    master_table[entry_count].valid_names = 0;
	    master_table[entry_count].all_params = 0;
	    entry_count += 1;
	}
	vstream_fclose(fp);
	vstring_free(buf);
    }

    /*
     * Null-terminate the master table and clean up.
     */
    master_table[entry_count].argv = 0;
    myfree(path);
}
Esempio n. 5
0
File: vifm.c Progetto: kotobot/vifm
int
main(int argc, char *argv[])
{
	char dir[PATH_MAX];
	char config_dir[PATH_MAX];
	char *console = NULL;
	int x;
	int rwin_args = 0;
	int lwin_args = 0;
	struct stat stat_buf;

	setlocale(LC_ALL, "");
	getcwd(dir, sizeof(dir));

	/* Window initializations */
	rwin.curr_line = 0;
	rwin.top_line = 0;
	rwin.list_rows = 0;
	rwin.list_pos = 0;
	rwin.selected_filelist = NULL;
	rwin.history_num = 0;
	rwin.invert = 0;
	rwin.color_scheme = 0;

	lwin.curr_line = 0;
	lwin.top_line = 0;
	lwin.list_rows = 0;
	lwin.list_pos = 0;
	lwin.selected_filelist = NULL;
	lwin.history_num = 0;
	lwin.invert = 0;
	lwin.color_scheme = 0;

	/* These need to be initialized before reading the configuration file */
	cfg.command_num = 0;
	cfg.filetypes_num = 0;
	cfg.nmapped_num = 0;
	cfg.vim_filter = 0;
	cfg.show_one_window = 0;
	command_list = NULL;
	filetypes = NULL;

	cfg.search_history_len = 15;
	cfg.search_history_num = -1;
	cfg.search_history = (char **)calloc(cfg.search_history_len, sizeof(char*));
	cfg.cmd_history_len = 15;
	cfg.cmd_history_num = -1;
	cfg.cmd_history = (char **)calloc(cfg.cmd_history_len, sizeof(char *));
	cfg.auto_execute = 0;
	cfg.color_scheme_num = 0;
	cfg.color_pairs_num = 0;

	col_schemes = malloc(sizeof(Col_scheme) * 8);

	/* Maximum argument length to pass to the shell */
	if (! (cfg.max_args = sysconf(_SC_ARG_MAX)) > 0)
		cfg.max_args = 4096; /* POSIX MINIMUM */


	init_config();
	set_config_dir();
	read_config_file();

	/* Safety check for existing vifmrc file without FUSE_HOME */
	if (cfg.fuse_home == NULL)
		cfg.fuse_home = strdup("/tmp/vifm_FUSE");

	/* Misc configuration */

	lwin.prev_invert = lwin.invert;
	lwin.hide_dot = 1;
	strncpy(lwin.regexp, "\\..~$", sizeof(lwin.regexp));
	rwin.prev_invert = rwin.invert;
	rwin.hide_dot = 1;
	strncpy(rwin.regexp, "\\..~$", sizeof(rwin.regexp));
	cfg.timer = 10;
	curr_stats.yanked_files = NULL;
	curr_stats.num_yanked_files = 0;
	curr_stats.need_redraw = 0;
	curr_stats.getting_input = 0;
	curr_stats.menu = 0;
	curr_stats.redraw_menu = 0;
	curr_stats.is_updir = 0;
	curr_stats.last_char = 0;
	curr_stats.is_console = 0;
	curr_stats.search = 0;
	curr_stats.save_msg = 0;
	curr_stats.use_register = 0;
	curr_stats.curr_register = -1;
	curr_stats.register_saved = 0;
	curr_stats.show_full = 0;
	curr_stats.view = 0;

	if (cfg.show_one_window)
		curr_stats.number_of_windows = 1;
	else
		curr_stats.number_of_windows = 2;

	snprintf(config_dir, sizeof(config_dir), "%s/vifmrc", cfg.config_dir);

	if(stat(config_dir, &stat_buf) == 0)
		curr_stats.config_file_mtime = stat_buf.st_mtime;
	else
		curr_stats.config_file_mtime = 0;


	/* Check if running in X */
	console = getenv("DISPLAY");
	if(!console || !*console)
		curr_stats.is_console = 1;


	/* Setup the ncurses interface. */
	if(!setup_ncurses_interface())
		return -1;

	/* Load the initial directory */
	snprintf(rwin.curr_dir, sizeof(rwin.curr_dir), "%s", dir);
	snprintf(lwin.curr_dir, sizeof(lwin.curr_dir), "%s", dir);
	rwin.dir_entry = (dir_entry_t *)malloc(sizeof(dir_entry_t));
	lwin.dir_entry = (dir_entry_t *)malloc(sizeof(dir_entry_t));
	rwin.dir_entry[0].name = malloc(sizeof("../") +1);
	lwin.dir_entry[0].name = malloc(sizeof("../") +1);
	strcpy(rwin.dir_entry[0].name, "../");
	strcpy(lwin.dir_entry[0].name, "../");
	change_directory(&rwin, dir);
	change_directory(&lwin, dir);
	other_view = &lwin;
	curr_view = &rwin;

/* Get Command Line Arguments */ 
	for(x = 1; x < argc; x++)
	{
		if(argv[x] != NULL)
		{
				if(!strcmp(argv[x], "-f"))
				{
					cfg.vim_filter = 1;
				}
				else if(!strcmp(argv[x], "--version"))
				{
					endwin();
					printf("\n\nvifm %s\n\n", VERSION);
					exit(0);
				}
				else if(!strcmp(argv[x], "--help"))
				{
					endwin();
					show_help_msg();
					exit(0);
				}
				else if(is_dir(argv[x]))
				{
					if(lwin_args)
					{
						snprintf(rwin.curr_dir, sizeof(rwin.curr_dir), 
								"%s", argv[x]);

						rwin_args++;

					}
					else
					{
						snprintf(lwin.curr_dir, sizeof(lwin.curr_dir),
							   	"%s", argv[x]);


						lwin_args++;
					}
				}
				else
				{
					endwin();
					show_help_msg();
					exit(0);
				}
		}
	}

	
	load_dir_list(&rwin, 0);

	if (rwin_args)
	{
		change_directory(&rwin, rwin.curr_dir);
		load_dir_list(&rwin, 0);
	}

	mvwaddstr(rwin.win, rwin.curr_line, 0, "*"); 
	wrefresh(rwin.win);

	/* This is needed for the sort_dir_list() which uses curr_view */
	switch_views();

	load_dir_list(&lwin, 0);

	if (lwin_args)
	{
		change_directory(&lwin, lwin.curr_dir);
		load_dir_list(&lwin, 0);
	}

	moveto_list_pos(&lwin, 0);
	update_all_windows();
	setup_signals();

	werase(status_bar);
	wnoutrefresh(status_bar);



	/* Need to wait until both lists are loaded before changing one of the
	 * lists to show the file stats.  This is only used for starting vifm 
	 * from the vifm.vim script
	 */
	
	if(cfg.vim_filter)
		curr_stats.number_of_windows = 1;

	/* Enter the main loop. */
	main_key_press_cb(curr_view);

	return 0;
}