Exemple #1
0
int tagfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi){
  LOGCALL();
  (void) offset;
  (void) fi;
  struct dirent *dirent;

  int res = 0;

  char** tagsbuf;
  comm_getTags(path, &tagsbuf);

  int i;
  // Check tag existence and count tags
  if (tagsbuf != NULL)
    for (i = 0; tagsbuf[i]; ++i)
      if (!exist_tag(db, tagsbuf[i]))
        return FAILURE;

  struct G_file* files = NULL;
  struct G_tags* tags = NULL;

  (void) tags;
  if (i >= 1){
    // One: get files then union tags of files
    if (i == 1){
      struct Tag* t = get_tag(db, *tagsbuf);
      unsigned j;
      for (j = 0; j < t->t_files_size; ++j){
        // Add file to files
        // Send tags in UNION
      }
    } else if (i > 1){
      /*
       Files corresponding to the tags. Intersect.
      */
      files = common_files(db, tagsbuf[0], tagsbuf[1]);
      int j;
      for (j = 2; j < i; ++j)
         files = intersect_files(db, files, tagsbuf[j]);
      /*
       Remaining tags from files.
      */
      if (files != NULL){
         struct G_file *tmp;
         for (tmp = files; tmp != NULL; tmp = tmp->next){
           // Send tags in UNION
         }
      }
    }
      /*
        Cross-check with the request.
      */
      /*
        for (tmp2 = tags; tmp2 != NULL; tmp2 = tmp2->next){
          if (!strcmp(union_tagname, tagsbuf))
            // remove union_tag from union
        }
      */
  }

  /*
  	Show results
  	Files:
    Stat each file in the results then call filler
  */
  rewinddir(dir);
  while ((dirent = readdir(dir)) != NULL) {
    struct stat stbuf;
    res = tagfs_getattr(dirent->d_name, &stbuf);
    /* TODO only files whose contents matches tags in path */
    if (S_ISREG(stbuf.st_mode)){ /* only display files, no directories */
      int ok = exist_file(db, dirent->d_name), i = 0;
      if (tagsbuf != NULL)
	    while (ok && tagsbuf[i] != NULL){
          if (is_file_in_tag(db, dirent->d_name, tagsbuf[i]))
	        ++i;
	      else
	        ok = 0;
	    }
      if (ok)
	    filler(buf, dirent->d_name, NULL, 0);
    }
  }

  /*
    Tags:
  */
  if (tagsbuf != NULL){
    for (i = 0; tagsbuf[i]; ++i)
      filler(buf, tagsbuf[i], NULL, 0);
    comm_freeTags(tagsbuf);
  } else {
    // call filler on each tag
  }

  LOG("readdir returning %s\n", strerror(-res));
  return 0;
}
Exemple #2
0
Fichier : user.c Projet : dborca/mc
/*
 * If edit_widget is NULL then we are called from the mc menu,
 * otherwise we are called from the mcedit menu.
 */
void
user_menu_cmd (struct WEdit *edit_widget)
{
    char *p;
    char *data, **entries;
    int  max_cols, menu_lines, menu_limit;
    int  col, i, accept_entry = 1;
    int  selected, old_patterns;
    Listbox *listbox;
    
    if (!vfs_current_is_local ()){
	message (1, MSG_ERROR,
		 _(" Cannot execute commands on non-local filesystems"));
	return;
    }
    
    menu = g_strdup (edit_widget ? CEDIT_LOCAL_MENU : MC_LOCAL_MENU);
    if (!exist_file (menu) || !menu_file_own (menu)){
	g_free (menu);
        menu = concat_dir_and_file \
                            (home_dir, edit_widget ? CEDIT_HOME_MENU : MC_HOME_MENU);
	if (!exist_file (menu)){
	    g_free (menu);
	    menu = concat_dir_and_file \
                        (mc_home, edit_widget ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
	}
    }

    if ((data = load_file (menu)) == NULL){
	message (1, MSG_ERROR, _(" Cannot open file %s \n %s "),
		 menu, unix_error_string (errno));
	g_free (menu);
	menu = NULL;
	return;
    }
    
    max_cols = 0;
    selected = 0;
    menu_limit = 0;
    entries = 0;

    /* Parse the menu file */
    old_patterns = easy_patterns;
    p = check_patterns (data);
    for (menu_lines = col = 0; *p; p++){
	if (menu_lines >= menu_limit){
	    char ** new_entries;
	    
	    menu_limit += MAX_ENTRIES;
	    new_entries = g_realloc (entries, sizeof (new_entries[0]) * menu_limit);

	    if (new_entries == 0)
		break;

	    entries = new_entries;
	    new_entries += menu_limit;
	    while (--new_entries >= &entries[menu_lines])
		*new_entries = 0;
	}
	if (col == 0 && !entries [menu_lines]){
	    if (*p == '#'){
		/* A commented menu entry */
		accept_entry = 1;
	    } else if (*p == '+'){
		if (*(p+1) == '='){
		    /* Combined adding and default */
		    p = test_line (edit_widget, p + 1, &accept_entry);
		    if (selected == 0 && accept_entry)
			selected = menu_lines;
		} else {
		    /* A condition for adding the entry */
		    p = test_line (edit_widget, p, &accept_entry);
		}
	    } else if (*p == '='){
		if (*(p+1) == '+'){
		    /* Combined adding and default */
		    p = test_line (edit_widget, p + 1, &accept_entry);
		    if (selected == 0 && accept_entry)
			selected = menu_lines;
		} else {
		    /* A condition for making the entry default */
		    i = 1;
		    p = test_line (edit_widget, p, &i);
		    if (selected == 0 && i)
			selected = menu_lines;
		}
	    }
	    else if (*p != ' ' && *p != '\t' && is_printable (*p)) {
		/* A menu entry title line */
		if (accept_entry)
		    entries [menu_lines] = p;
		else
		    accept_entry = 1;
	    }
	}
	if (*p == '\n'){
	    if (entries [menu_lines]){
		menu_lines++;
		accept_entry = 1;
	    }
	    max_cols = max (max_cols, col);
	    col = 0;
	} else {
	    if (*p == '\t')
		*p = ' ';
	    col++;
	}
    }

    if (menu_lines == 0) {
	message (1, MSG_ERROR, _(" No suitable entries found in %s "), menu);
    } else {

    max_cols = min (max (max_cols, col), MAX_ENTRY_LEN);
 
    /* Create listbox */
    listbox = create_listbox_window (max_cols+2, menu_lines, _(" User menu "),
				     "[Menu File Edit]");
    /* insert all the items found */
    for (i = 0; i < menu_lines; i++) {
	p = entries [i];
	LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0],
			     extract_line (p, p + MAX_ENTRY_LEN), p
			    );
    }
    /* Select the default entry */
    listbox_select_by_number (listbox->list, selected);
    
    selected = run_listbox (listbox);
    if (selected >= 0)
	execute_menu_command (edit_widget, entries [selected]);

    do_refresh ();
    }

    easy_patterns = old_patterns;
    g_free (menu);
    menu = NULL;
    g_free (entries);
    g_free (data);
}
Exemple #3
0
static void
init_subshell_child (const char *pty_name)
{
    char *init_file = NULL;
    char *putenv_str = NULL;
    pid_t mc_sid;

    (void) pty_name;
    setsid ();                  /* Get a fresh terminal session */

    /* Make sure that it has become our controlling terminal */

    /* Redundant on Linux and probably most systems, but just in case: */

#ifdef TIOCSCTTY
    ioctl (subshell_pty_slave, TIOCSCTTY, 0);
#endif

    /* Configure its terminal modes and window size */

    /* Set up the pty with the same termios flags as our own tty */
    if (tcsetattr (subshell_pty_slave, TCSANOW, &shell_mode))
    {
        fprintf (stderr, "Cannot set pty terminal modes: %s\r\n", unix_error_string (errno));
        my_exit (FORK_FAILURE);
    }

    /* Set the pty's size (80x25 by default on Linux) according to the */
    /* size of the real terminal as calculated by ncurses, if possible */
    tty_resize (subshell_pty_slave);

    /* Set up the subshell's environment and init file name */

    /* It simplifies things to change to our home directory here, */
    /* and the user's startup file may do a 'cd' command anyway   */
    {
        int ret;

        ret = chdir (mc_config_get_home_dir ());        /* FIXME? What about when we re-run the subshell? */
        (void) ret;
    }

    /* Set MC_SID to prevent running one mc from another */
    mc_sid = getsid (0);
    if (mc_sid != -1)
    {
        char sid_str[BUF_SMALL];

        g_snprintf (sid_str, sizeof (sid_str), "MC_SID=%ld", (long) mc_sid);
        putenv (g_strdup (sid_str));
    }

    switch (mc_global.shell->type)
    {
    case SHELL_BASH:
        /* Do we have a custom init file ~/.local/share/mc/bashrc? */
        init_file = mc_config_get_full_path ("bashrc");

        /* Otherwise use ~/.bashrc */
        if (!exist_file (init_file))
        {
            g_free (init_file);
            init_file = g_strdup (".bashrc");
        }

        /* Make MC's special commands not show up in bash's history and also suppress
         * consecutive identical commands*/
        putenv ((char *) "HISTCONTROL=ignoreboth");

        /* Allow alternative readline settings for MC */
        {
            char *input_file;

            input_file = mc_config_get_full_path ("inputrc");
            if (exist_file (input_file))
            {
                putenv_str = g_strconcat ("INPUTRC=", input_file, (char *) NULL);
                putenv (putenv_str);
            }
            g_free (input_file);
        }

        break;

    case SHELL_ASH_BUSYBOX:
    case SHELL_DASH:
        /* Do we have a custom init file ~/.local/share/mc/ashrc? */
        init_file = mc_config_get_full_path ("ashrc");

        /* Otherwise use ~/.profile */
        if (!exist_file (init_file))
        {
            g_free (init_file);
            init_file = g_strdup (".profile");
        }

        /* Put init file to ENV variable used by ash */
        putenv_str = g_strconcat ("ENV=", init_file, (char *) NULL);
        putenv (putenv_str);
        /* Do not use "g_free (putenv_str)" here, otherwise ENV will be undefined! */

        break;

        /* TODO: Find a way to pass initfile to TCSH, ZSH and FISH */
    case SHELL_TCSH:
    case SHELL_ZSH:
    case SHELL_FISH:
        break;

    default:
        fprintf (stderr, __FILE__ ": unimplemented subshell type %u\r\n", mc_global.shell->type);
        my_exit (FORK_FAILURE);
    }

    /* Attach all our standard file descriptors to the pty */

    /* This is done just before the fork, because stderr must still      */
    /* be connected to the real tty during the above error messages; */
    /* otherwise the user will never see them.                   */

    dup2 (subshell_pty_slave, STDIN_FILENO);
    dup2 (subshell_pty_slave, STDOUT_FILENO);
    dup2 (subshell_pty_slave, STDERR_FILENO);

    close (subshell_pipe[READ]);
    close (subshell_pty_slave); /* These may be FD_CLOEXEC, but just in case... */
    /* Close master side of pty.  This is important; apart from */
    /* freeing up the descriptor for use in the subshell, it also       */
    /* means that when MC exits, the subshell will get a SIGHUP and     */
    /* exit too, because there will be no more descriptors pointing     */
    /* at the master side of the pty and so it will disappear.  */
    close (mc_global.tty.subshell_pty);

    /* Execute the subshell at last */

    switch (mc_global.shell->type)
    {
    case SHELL_BASH:
        execl (mc_global.shell->path, "bash", "-rcfile", init_file, (char *) NULL);
        break;

    case SHELL_ZSH:
        /* Use -g to exclude cmds beginning with space from history
         * and -Z to use the line editor on non-interactive term */
        execl (mc_global.shell->path, "zsh", "-Z", "-g", (char *) NULL);

        break;

    case SHELL_ASH_BUSYBOX:
    case SHELL_DASH:
    case SHELL_TCSH:
    case SHELL_FISH:
        execl (mc_global.shell->path, mc_global.shell->path, (char *) NULL);
        break;

    default:
        break;
    }

    /* If we get this far, everything failed miserably */
    g_free (init_file);
    g_free (putenv_str);
    my_exit (FORK_FAILURE);
}
Exemple #4
0
Fichier : ext.c Projet : inso/mc
int
regex_command_for (void *target, const vfs_path_t * filename_vpath, const char *action,
                   vfs_path_t ** script_vpath)
{
    char *p, *q, *r, c;
    size_t file_len;
    gboolean found = FALSE;
    gboolean error_flag = FALSE;
    int ret = 0;
    struct stat mystat;
    int view_at_line_number;
    char *include_target;
    int include_target_len;
    int have_type = 0;          /* Flag used by regex_check_type() */

    if (filename_vpath == NULL)
        return 0;

    if (script_vpath != NULL)
        *script_vpath = NULL;

    /* Check for the special View:%d parameter */
    if (strncmp (action, "View:", 5) == 0)
    {
        view_at_line_number = atoi (action + 5);
        action = "View";
    }
    else
    {
        view_at_line_number = 0;
    }

    if (data == NULL)
    {
        char *extension_file;
        gboolean mc_user_ext = TRUE;
        gboolean home_error = FALSE;

        extension_file = mc_config_get_full_path (MC_FILEBIND_FILE);
        if (!exist_file (extension_file))
        {
            g_free (extension_file);
          check_stock_mc_ext:
            extension_file = mc_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
            if (!exist_file (extension_file))
            {
                g_free (extension_file);
                extension_file = mc_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
            }
            mc_user_ext = FALSE;
        }

        g_file_get_contents (extension_file, &data, NULL, NULL);
        g_free (extension_file);
        if (data == NULL)
            return 0;

        if (strstr (data, "default/") == NULL)
        {
            if (strstr (data, "regex/") == NULL && strstr (data, "shell/") == NULL &&
                strstr (data, "type/") == NULL)
            {
                g_free (data);
                data = NULL;

                if (!mc_user_ext)
                {
                    char *title;

                    title = g_strdup_printf (_(" %s%s file error"),
                                             mc_global.sysconfig_dir, MC_LIB_EXT);
                    message (D_ERROR, title, _("The format of the %smc.ext "
                                               "file has changed with version 3.0. It seems that "
                                               "the installation failed. Please fetch a fresh "
                                               "copy from the Midnight Commander package."),
                             mc_global.sysconfig_dir);
                    g_free (title);
                    return 0;
                }

                home_error = TRUE;
                goto check_stock_mc_ext;
            }
        }

        if (home_error)
        {
            char *filebind_filename;
            char *title;

            filebind_filename = mc_config_get_full_path (MC_FILEBIND_FILE);
            title = g_strdup_printf (_("%s file error"), filebind_filename);
            message (D_ERROR, title,
                     _("The format of the %s file has "
                       "changed with version 3.0. You may either want to copy "
                       "it from %smc.ext or use that file as an example of how to write it."),
                     filebind_filename, mc_global.sysconfig_dir);
            g_free (filebind_filename);
            g_free (title);
        }
    }

    mc_stat (filename_vpath, &mystat);

    include_target = NULL;
    include_target_len = 0;
    file_len = vfs_path_len (filename_vpath);

    for (p = data; *p != '\0'; p++)
    {
        for (q = p; *q == ' ' || *q == '\t'; q++)
            ;
        if (*q == '\n' || *q == '\0')
            p = q;              /* empty line */
        if (*p == '#')          /* comment */
            while (*p != '\0' && *p != '\n')
                p++;
        if (*p == '\n')
            continue;
        if (*p == '\0')
            break;
        if (p == q)
        {                       /* i.e. starts in the first column, should be
                                 * keyword/descNL
                                 */
            gboolean case_insense;

            found = FALSE;
            q = strchr (p, '\n');
            if (q == NULL)
                q = strchr (p, '\0');
            c = *q;
            *q = '\0';
            if (include_target)
            {
                if ((strncmp (p, "include/", 8) == 0)
                    && (strncmp (p + 8, include_target, include_target_len) == 0))
                    found = TRUE;
            }
            else if (strncmp (p, "regex/", 6) == 0)
            {
                mc_search_t *search;

                p += 6;
                case_insense = (strncmp (p, "i/", 2) == 0);
                if (case_insense)
                    p += 2;

                search = mc_search_new (p, -1);
                if (search != NULL)
                {
                    search->search_type = MC_SEARCH_T_REGEX;
                    search->is_case_sensitive = !case_insense;
                    found =
                        mc_search_run (search, vfs_path_as_str (filename_vpath), 0, file_len, NULL);
                    mc_search_free (search);
                }
            }
            else if (strncmp (p, "directory/", 10) == 0)
            {
                if (S_ISDIR (mystat.st_mode)
                    && mc_search (p + 10, vfs_path_as_str (filename_vpath), MC_SEARCH_T_REGEX))
                    found = TRUE;
            }
            else if (strncmp (p, "shell/", 6) == 0)
            {
                int (*cmp_func) (const char *s1, const char *s2, size_t n) = strncmp;

                p += 6;
                case_insense = (strncmp (p, "i/", 2) == 0);
                if (case_insense)
                {
                    p += 2;
                    cmp_func = strncasecmp;
                }

                if (*p == '.' && file_len >= (size_t) (q - p))
                {
                    if (cmp_func
                        (p, vfs_path_as_str (filename_vpath) + file_len - (q - p), q - p) == 0)
                        found = TRUE;
                }
                else
                {
                    if ((size_t) (q - p) == file_len
                        && cmp_func (p, vfs_path_as_str (filename_vpath), q - p) == 0)
                        found = TRUE;
                }
            }
            else if (strncmp (p, "type/", 5) == 0)
            {
                GError *error = NULL;

                p += 5;

                case_insense = (strncmp (p, "i/", 2) == 0);
                if (case_insense)
                    p += 2;

                found = regex_check_type (filename_vpath, p, &have_type, case_insense, &error);
                if (error != NULL)
                {
                    g_error_free (error);
                    error_flag = TRUE;  /* leave it if file cannot be opened */
                }
            }
            else if (strncmp (p, "default/", 8) == 0)
                found = TRUE;

            *q = c;
            p = q;
            if (*p == '\0')
                break;
        }
        else
        {                       /* List of actions */
            p = q;
            q = strchr (p, '\n');
            if (q == NULL)
                q = strchr (p, '\0');
            if (found && !error_flag)
            {
                r = strchr (p, '=');
                if (r != NULL)
                {
                    c = *r;
                    *r = '\0';
                    if (strcmp (p, "Include") == 0)
                    {
                        char *t;

                        include_target = p + 8;
                        t = strchr (include_target, '\n');
                        if (t != NULL)
                            *t = '\0';
                        include_target_len = strlen (include_target);
                        if (t != NULL)
                            *t = '\n';

                        *r = c;
                        p = q;
                        found = FALSE;

                        if (*p == '\0')
                            break;
                        continue;
                    }

                    if (strcmp (action, p) != 0)
                        *r = c;
                    else
                    {
                        *r = c;

                        for (p = r + 1; *p == ' ' || *p == '\t'; p++)
                            ;

                        /* Empty commands just stop searching
                         * through, they don't do anything
                         */
                        if (p < q)
                        {
                            vfs_path_t *sv;

                            sv = exec_extension (target, filename_vpath, r + 1,
                                                 view_at_line_number);
                            if (script_vpath != NULL)
                                *script_vpath = sv;
                            else
                                exec_cleanup_script (sv);

                            ret = 1;
                        }
                        break;
                    }
                }
            }
            p = q;
            if (*p == '\0')
                break;
        }
    }
    if (error_flag)
        ret = -1;
    return ret;
}
Exemple #5
0
/* The second argument is action, i.e. Open, View or Edit
 *
 * This function returns:
 *
 * -1 for a failure or user interrupt
 * 0 if no command was run
 * 1 if some command was run
 *
 * If action == "View" then a parameter is checked in the form of "View:%d",
 * if the value for %d exists, then the viewer is started up at that line number.
 */
int
regex_command (char *filename, char *action, int *move_dir)
{
    char *p, *q, *r, c;
    int file_len = strlen (filename);
    int found = 0;
    int error_flag = 0;
    int ret = 0;
    struct stat mystat;
    int view_at_line_number;
    char *include_target;
    int include_target_len;
    int have_type = 0;		/* Flag used by regex_check_type() */

    /* Check for the special View:%d parameter */
    if (strncmp (action, "View:", 5) == 0) {
	view_at_line_number = atoi (action + 5);
	action[4] = 0;
    } else {
	view_at_line_number = 0;
    }

    if (data == NULL) {
	char *extension_file;
	int mc_user_ext = 1;
	int home_error = 0;

	extension_file = concat_dir_and_file (home_dir, MC_USER_EXT);
	if (!exist_file (extension_file)) {
	    g_free (extension_file);
	  check_stock_mc_ext:
	    extension_file = concat_dir_and_file (mc_home, MC_LIB_EXT);
	    mc_user_ext = 0;
	}
	data = load_file (extension_file);
	g_free (extension_file);
	if (data == NULL)
	    return 0;

	if (!strstr (data, "default/")) {
	    if (!strstr (data, "regex/") && !strstr (data, "shell/")
		&& !strstr (data, "type/")) {
		g_free (data);
		data = NULL;
		if (mc_user_ext) {
		    home_error = 1;
		    goto check_stock_mc_ext;
		} else {
		    char *msg;
		    char *msg2;
		    msg =
			g_strconcat (" ", mc_home, MC_LIB_EXT,
				     _(" file error "), NULL);
		    msg2 =
			g_strconcat (_("Format of the "), mc_home,
				     _("mc.ext file has changed\n"
				       "with version 3.0. It seems that installation\n"
				       "failed. Please fetch a fresh new copy from the\n"
				       "Midnight Commander package."),
				     NULL);
		    message (1, msg, "%s", msg2);
		    g_free (msg);
		    g_free (msg2);
		    return 0;
		}
	    }
	}
	if (home_error) {
	    char *msg;
	    char *msg2;
	    msg =
		g_strconcat (" ~/", MC_USER_EXT, _(" file error "), NULL);
	    msg2 =
		g_strconcat (_("Format of the "), "~/", MC_USER_EXT,
			     _(" file has changed\n"
			       "with version 3.0. You may want either to\n"
			       "copy it from "), mc_home,
			     _("mc.ext or use that\n"
			       "file as an example of how to write it.\n"),
			     mc_home,
			     _("mc.ext will be used for this moment."),
			     NULL);
	    message (1, msg, "%s", msg2);
	    g_free (msg);
	    g_free (msg2);
	}
    }
    mc_stat (filename, &mystat);

    include_target = NULL;
    include_target_len = 0;
    for (p = data; *p; p++) {
	for (q = p; *q == ' ' || *q == '\t'; q++);
	if (*q == '\n' || !*q)
	    p = q;		/* empty line */
	if (*p == '#')		/* comment */
	    while (*p && *p != '\n')
		p++;
	if (*p == '\n')
	    continue;
	if (!*p)
	    break;
	if (p == q) {		/* i.e. starts in the first column, should be
				 * keyword/descNL
				 */
	    found = 0;
	    q = strchr (p, '\n');
	    if (q == NULL)
		q = strchr (p, 0);
	    c = *q;
	    *q = 0;
	    if (include_target) {
		if ((strncmp (p, "include/", 8) == 0)
		    && (strncmp (p + 8, include_target, include_target_len)
			== 0))
		    found = 1;
	    } else if (!strncmp (p, "regex/", 6)) {
		p += 6;
		/* Do not transform shell patterns, you can use shell/ for
		 * that
		 */
		if (regexp_match (p, filename, match_regex))
		    found = 1;
	    } else if (!strncmp (p, "directory/", 10)) {
		if (S_ISDIR (mystat.st_mode)
		    && regexp_match (p + 10, filename, match_regex))
		    found = 1;
	    } else if (!strncmp (p, "shell/", 6)) {
		p += 6;
		if (*p == '.' && file_len >= (q - p)) {
		    if (!strncmp (p, filename + file_len - (q - p), q - p))
			found = 1;
		} else {
		    if (q - p == file_len && !strncmp (p, filename, q - p))
			found = 1;
		}
	    } else if (!strncmp (p, "type/", 5)) {
		int res;
		p += 5;
		res = regex_check_type (filename, p, &have_type);
		if (res == 1)
		    found = 1;
		if (res == -1)
		    error_flag = 1;	/* leave it if file cannot be opened */
	    } else if (!strncmp (p, "default/", 8)) {
		found = 1;
	    }
	    *q = c;
	    p = q;
	    if (!*p)
		break;
	} else {		/* List of actions */
	    p = q;
	    q = strchr (p, '\n');
	    if (q == NULL)
		q = strchr (p, 0);
	    if (found && !error_flag) {
		r = strchr (p, '=');
		if (r != NULL) {
		    c = *r;
		    *r = 0;
		    if (strcmp (p, "Include") == 0) {
			char *t;

			include_target = p + 8;
			t = strchr (include_target, '\n');
			if (t)
			    *t = 0;
			include_target_len = strlen (include_target);
			if (t)
			    *t = '\n';

			*r = c;
			p = q;
			found = 0;

			if (!*p)
			    break;
			continue;
		    }
		    if (!strcmp (action, p)) {
			*r = c;
			for (p = r + 1; *p == ' ' || *p == '\t'; p++);

			/* Empty commands just stop searching
			 * through, they don't do anything
			 *
			 * We need to copy the filename because exec_extension
			 * may end up invoking update_panels thus making the
			 * filename parameter invalid (ie, most of the time,
			 * we get filename as a pointer from current_panel->dir).
			 */
			if (p < q) {
			    char *filename_copy = g_strdup (filename);

			    exec_extension (filename_copy, r + 1, move_dir,
					    view_at_line_number);
			    g_free (filename_copy);

			    ret = 1;
			}
			break;
		    } else
			*r = c;
		}
	    }
	    p = q;
	    if (!*p)
		break;
	}
    }
    if (error_flag)
	return -1;
    return ret;
}
Exemple #6
0
gboolean
user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_entry)
{
    char *p;
    char *data, **entries;
    int max_cols, menu_lines, menu_limit;
    int col, i, accept_entry = 1;
    int selected, old_patterns;
    gboolean res = FALSE;
    gboolean interactive = TRUE;

    if (!vfs_current_is_local ())
    {
        message (D_ERROR, MSG_ERROR, "%s", _("Cannot execute commands on non-local filesystems"));
        return FALSE;
    }
    if (menu_file != NULL)
        menu = g_strdup (menu_file);
    else
        menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU);
    if (!exist_file (menu) || !menu_file_own (menu))
    {
        if (menu_file != NULL)
        {
            message (D_ERROR, MSG_ERROR, _("Cannot open file %s\n%s"), menu,
                     unix_error_string (errno));
            MC_PTR_FREE (menu);
            return FALSE;
        }

        g_free (menu);
        if (edit_widget)
            menu = mc_config_get_full_path (EDIT_HOME_MENU);
        else
            menu = mc_config_get_full_path (MC_USERMENU_FILE);


        if (!exist_file (menu))
        {
            g_free (menu);
            menu =
                mc_build_filename (mc_config_get_home_dir (),
                                   edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL);
            if (!exist_file (menu))
            {
                g_free (menu);
                menu =
                    mc_build_filename (mc_global.sysconfig_dir,
                                       edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL);
                if (!exist_file (menu))
                {
                    g_free (menu);
                    menu = mc_build_filename
                        (mc_global.share_data_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU,
                         NULL);
                }
            }
        }
    }

    if (!g_file_get_contents (menu, &data, NULL, NULL))
    {
        message (D_ERROR, MSG_ERROR, _("Cannot open file%s\n%s"), menu, unix_error_string (errno));
        MC_PTR_FREE (menu);
        return FALSE;
    }

    max_cols = 0;
    selected = 0;
    menu_limit = 0;
    entries = 0;

    /* Parse the menu file */
    old_patterns = easy_patterns;
    p = check_patterns (data);
    for (menu_lines = col = 0; *p; str_next_char (&p))
    {
        if (menu_lines >= menu_limit)
        {
            char **new_entries;

            menu_limit += MAX_ENTRIES;
            new_entries = g_try_realloc (entries, sizeof (new_entries[0]) * menu_limit);

            if (new_entries == NULL)
                break;

            entries = new_entries;
            new_entries += menu_limit;
            while (--new_entries >= &entries[menu_lines])
                *new_entries = NULL;
        }
        if (col == 0 && !entries[menu_lines])
        {
            if (*p == '#')
            {
                /* show prompt if first line of external script is #interactive */
                if (selected_entry >= 0 && strncmp (p, "#silent", 7) == 0)
                    interactive = FALSE;
                /* A commented menu entry */
                accept_entry = 1;
            }
            else if (*p == '+')
            {
                if (*(p + 1) == '=')
                {
                    /* Combined adding and default */
                    p = test_line (edit_widget, p + 1, &accept_entry);
                    if (selected == 0 && accept_entry)
                        selected = menu_lines;
                }
                else
                {
                    /* A condition for adding the entry */
                    p = test_line (edit_widget, p, &accept_entry);
                }
            }
            else if (*p == '=')
            {
                if (*(p + 1) == '+')
                {
                    /* Combined adding and default */
                    p = test_line (edit_widget, p + 1, &accept_entry);
                    if (selected == 0 && accept_entry)
                        selected = menu_lines;
                }
                else
                {
                    /* A condition for making the entry default */
                    i = 1;
                    p = test_line (edit_widget, p, &i);
                    if (selected == 0 && i)
                        selected = menu_lines;
                }
            }
            else if (*p != ' ' && *p != '\t' && str_isprint (p))
            {
                /* A menu entry title line */
                if (accept_entry)
                    entries[menu_lines] = p;
                else
                    accept_entry = 1;
            }
        }
        if (*p == '\n')
        {
            if (entries[menu_lines])
            {
                menu_lines++;
                accept_entry = 1;
            }
            max_cols = max (max_cols, col);
            col = 0;
        }
        else
        {
            if (*p == '\t')
                *p = ' ';
            col++;
        }
    }

    if (menu_lines == 0)
    {
        message (D_ERROR, MSG_ERROR, _("No suitable entries found in %s"), menu);
        res = FALSE;
    }
    else
    {
        if (selected_entry >= 0)
            selected = selected_entry;
        else
        {
            Listbox *listbox;

            max_cols = min (max (max_cols, col), MAX_ENTRY_LEN);

            /* Create listbox */
            listbox = create_listbox_window (menu_lines, max_cols + 2, _("User menu"),
                                             "[Menu File Edit]");
            /* insert all the items found */
            for (i = 0; i < menu_lines; i++)
            {
                p = entries[i];
                LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0],
                                     extract_line (p, p + MAX_ENTRY_LEN), p);
            }
            /* Select the default entry */
            listbox_select_entry (listbox->list, selected);

            selected = run_listbox (listbox);
        }
        if (selected >= 0)
        {
            execute_menu_command (edit_widget, entries[selected], interactive);
            res = TRUE;
        }

        do_refresh ();
    }

    easy_patterns = old_patterns;
    MC_PTR_FREE (menu);
    g_free (entries);
    g_free (data);
    return res;
}
Exemple #7
0
void
load_setup (void)
{
    const char *profile;
    size_t i;
    const char *kt;

#ifdef HAVE_CHARSET
    char *buffer;

    load_codepages_list ();
#endif /* HAVE_CHARSET */

    profile = setup_init ();

    /* mc.lib is common for all users, but has priority lower than
       ${XDG_CONFIG_HOME}/mc/ini.  FIXME: it's only used for keys and treestore now */
    global_profile_name =
        g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
    if (!exist_file (global_profile_name))
    {
        g_free (global_profile_name);
        global_profile_name =
            g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
    }

    panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);

    mc_main_config = mc_config_init (profile, FALSE);

    if (!exist_file (panels_profile_name))
        setup__move_panels_config_into_separate_file (profile);

    mc_panels_config = mc_config_init (panels_profile_name, FALSE);

    /* Load integer boolean options */
    for (i = 0; int_options[i].opt_name != NULL; i++)
        *int_options[i].opt_addr =
            mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
                               *int_options[i].opt_addr);
#ifndef USE_INTERNAL_EDIT
    /* reset forced in case of build without internal editor */
    use_internal_edit = 0;
#endif /* USE_INTERNAL_EDIT */

    if (option_tab_spacing <= 0)
        option_tab_spacing = DEFAULT_TAB_SPACING;

#ifdef USE_INTERNAL_EDIT
    if (option_word_wrap_line_length <= 0)
        option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
#endif /* USE_INTERNAL_EDIT */

    /* overwrite old_esc_mode_timeout */
    kt = getenv ("KEYBOARD_KEY_TIMEOUT_US");
    if ((kt != NULL) && (kt[0] != '\0'))
        old_esc_mode_timeout = atoi (kt);

    /* Load string options */
    for (i = 0; str_options[i].opt_name != NULL; i++)
        *str_options[i].opt_addr =
            mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
                                  str_options[i].opt_defval);

    load_layout ();
    panels_load_options ();
    load_panelize ();

    startup_left_mode = setup__load_panel_state ("New Left Panel");
    startup_right_mode = setup__load_panel_state ("New Right Panel");

    /* At least one of the panels is a listing panel */
    if (startup_left_mode != view_listing && startup_right_mode != view_listing)
        startup_left_mode = view_listing;

    boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);

    /* Load time formats */
    user_recent_timeformat =
        mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_recent", FMTTIME);
    user_old_timeformat =
        mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "timeformat_old", FMTYEAR);

#ifdef ENABLE_VFS_FTP
    ftpfs_proxy_host =
        mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "ftp_proxy_host", "gate");
    ftpfs_ignore_chattr_errors =
        mc_config_get_bool (mc_main_config, CONFIG_APP_SECTION, "ignore_ftp_chattr_errors", TRUE);
    ftpfs_init_passwd ();
#endif /* ENABLE_VFS_FTP */

    /* The default color and the terminal dependent color */
    mc_global.tty.setup_color_string =
        mc_config_get_string (mc_main_config, "Colors", "base_color", "");
    mc_global.tty.term_color_string =
        mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), "");
    mc_global.tty.color_terminal_string =
        mc_config_get_string (mc_main_config, "Colors", "color_terminals", "");

    /* Load the directory history */
    /*    directory_history_load (); */
    /* Remove the temporal entries */

#ifdef HAVE_CHARSET
    if (codepages->len > 1)
    {
        buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "display_codepage", "");
        if (buffer[0] != '\0')
        {
            mc_global.display_codepage = get_codepage_index (buffer);
            cp_display = get_codepage_id (mc_global.display_codepage);
        }
        g_free (buffer);
        buffer = mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "source_codepage", "");
        if (buffer[0] != '\0')
        {
            default_source_codepage = get_codepage_index (buffer);
            mc_global.source_codepage = default_source_codepage;        /* May be source_codepage doesn't need this */
            cp_source = get_codepage_id (mc_global.source_codepage);
        }
        g_free (buffer);
    }

    autodetect_codeset =
        mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "autodetect_codeset", "");
    if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0))
        is_autodetect_codeset_enabled = TRUE;

    g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage));
    buffer = (char *) get_codepage_id (mc_global.display_codepage);
    if (buffer != NULL)
        mc_global.utf8_display = str_isutf8 (buffer);
#endif /* HAVE_CHARSET */

#ifdef HAVE_ASPELL
    spell_language =
        mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "spell_language", "en");
#endif /* HAVE_ASPELL */

    clipboard_store_path =
        mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_store", "");
    clipboard_paste_path =
        mc_config_get_string (mc_main_config, CONFIG_MISC_SECTION, "clipboard_paste", "");
}
Exemple #8
0
void load_setup (void)
{
    static char *buffer;
    char   *profile;
    char   *inifile;
    int    i;
#ifdef USE_NETCODE
    extern char *ftpfs_proxy_host;
#endif
    buffer = concat_dir_and_file (home_dir, PROFILE_NAME);
    inifile = concat_dir_and_file (mc_home, "mc.ini");
    if (exist_file (buffer)){
	profile = buffer;
    } else if (exist_file (inifile)){
	profile = strdup (inifile);
	free (buffer);
    } else {
	profile = buffer;
    }
    free (inifile);
    
    profile_name = profile;

    /* Load integer boolean options */
    for (i = 0; options [i].opt_name; i++)
	*options [i].opt_addr =
	    get_int (profile, options [i].opt_name, *options [i].opt_addr);

    load_layout (profile);

    load_panelize ();

    startup_left_mode = load_mode ("New Left Panel");
    startup_right_mode = load_mode ("New Right Panel");

    /* At least one of the panels is a listing panel */
    if (startup_left_mode != view_listing && startup_right_mode!=view_listing)
	startup_left_mode = view_listing;
    
    if (!other_dir){
	buffer = (char*) malloc (MC_MAXPATHLEN);
	load_string ("Dirs", "other_dir", ".", buffer,
			     MC_MAXPATHLEN);
	if (vfs_file_is_local (buffer))
	    other_dir = buffer;
	else
	    free (buffer);
    }
#ifdef USE_NETCODE
    ftpfs_proxy_host = do_load_string ("Misc", "ftp_proxy_host", "gate");
#endif
    boot_current_is_left =
	GetPrivateProfileInt ("Dirs", "current_is_left", 1, profile);
    
    load_string ("Misc", "find_ignore_dirs", "", setup_color_string,
		 sizeof (setup_color_string));
    if (setup_color_string [0])
	find_ignore_dirs = copy_strings (":", setup_color_string, ":", 0);
    
    /* The default color and the terminal dependent color */
    load_string ("Colors", "base_color", "", setup_color_string,
			     sizeof (setup_color_string));
    load_string ("Colors", getenv ("TERM"), "",
			     term_color_string, sizeof (term_color_string));
    load_string ("Colors", "color_terminals", "",
			     color_terminal_string, sizeof (color_terminal_string));

    /* Load the directory history */
/*    directory_history_load (); */
    /* Remove the temporal entries */
    profile_clean_section ("Temporal:New Left Panel", profile_name);
    profile_clean_section ("Temporal:New Right Panel", profile_name);
#ifdef USE_VFS
#ifdef USE_NETCODE
    ftpfs_init_passwd ();
#endif
#endif
}
Exemple #9
0
static char *
load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
{
    /*
       TODO: IMHO, in future, this function shall be placed in mcconfig module.
     */
    char *lc_basename, *ret;
    char *file_name;

    if (config_file_name == NULL)
        return NULL;

    /* check for .keymap suffix */
    if (g_str_has_suffix (config_file_name, ".keymap"))
        file_name = g_strdup (config_file_name);
    else
        file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);

    canonicalize_pathname (file_name);

    if (g_path_is_absolute (file_name))
        return file_name;

    lc_basename = g_path_get_basename (file_name);
    g_free (file_name);

    if (lc_basename == NULL)
        return NULL;

    if (subdir != NULL)
        ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
    else
        ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);

    if (exist_file (ret))
    {
        g_free (lc_basename);
        canonicalize_pathname (ret);
        return ret;
    }
    g_free (ret);

    if (subdir != NULL)
        ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL);
    else
        ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL);

    if (exist_file (ret))
    {
        g_free (lc_basename);
        canonicalize_pathname (ret);
        return ret;
    }
    g_free (ret);

    if (subdir != NULL)
        ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL);
    else
        ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL);

    g_free (lc_basename);

    if (exist_file (ret))
    {
        canonicalize_pathname (ret);
        return ret;
    }

    g_free (ret);
    return NULL;
}
Exemple #10
0
info_lib::info_lib(char** set_name_array, char** list_name_array,
                   char* info_lib_dir, char* selected_base_name, 
		   char* infoLibName, int des) :
set_nm_list(set_name_array), list_nm_list(list_name_array),
f_bad_base_array_size(0), f_bad_info_bases(0), 
f_bad_info_base_names(0), f_bad_info_base_paths(0), f_descriptor(des)

{
//debug(cerr, info_lib_dir);
//debug(cerr, infoLibName);

   f_obj_dict = new object_dict;

   if ( info_lib_dir == 0 ) {
      throw(stringException("NULL info lib path"));
   }

   if ( check_and_create_dir(info_lib_dir) == false )
      throw(stringException(
        form("infolib %s does not exist or can't be created", info_lib_dir)
                           )
           );

   strcpy(info_lib_path, info_lib_dir);
   strcpy(info_lib_name, infoLibName);

   fstream *map_in = 0;

   if ( exist_file(MAP_FILE_8_3, info_lib_dir) == true ) {

      map_in = new fstream(form("%s/%s", info_lib_dir, MAP_FILE_8_3), ios::in);

      g_mode_8_3 = 1;

      if ( !map_in -> getline(info_lib_name, PATHSIZ, '\t') ||
           !map_in -> getline(info_lib_uid, UIDSIZ, '\n')
         )
      {
         throw(stringException(
           form("infolib %s does not have correct name-id entry", info_lib_dir)
                              )
              );
      }
   } else
   if ( exist_file(MAP_FILE, info_lib_dir) == true )
      map_in = new fstream(form("%s/%s", info_lib_dir, MAP_FILE), ios::in);
   else {
      return;
   }

   char base_name[PATHSIZ];
   char base_desc[PATHSIZ];
   char base_uid[UIDSIZ];
   char base_locale[PATHSIZ];
   char db_path_name[PATHSIZ];

   int major_mm_version = 0;
   int minor_mm_version = 0;


   while ( map_in -> getline(base_name, PATHSIZ, '\t') ) {

      map_in -> getline(base_desc, PATHSIZ, '\t');

      if ( g_mode_8_3 == 1 ) {
         map_in -> getline(base_uid, PATHSIZ, '\t');
	 map_in -> getline(base_locale, PATHSIZ, '\t');
      }
      else
         base_uid[0] = 0;

      (*map_in) >> major_mm_version >> minor_mm_version;

      map_in -> get();

      if ( base_name[0] != CommentChar ) {

//debug(cerr, base_name);
//debug(cerr, base_desc);
//fprintf(stderr, "base_name = %s\n", base_name);

	 char* mmdb_lang = getenv("MMDB_LANG");
#ifdef MMDB_LANG_DEBUG
	 cerr << "base_locale=" << base_locale << endl;
	 if (mmdb_lang)
	   cerr << "mmdb_lang=" << mmdb_lang << endl;
#endif

         if ((selected_base_name == 0 ||
	      strcmp(selected_base_name, base_name) == 0) &&
	     (mmdb_lang == NULL ||
	      strcmp(mmdb_lang, base_locale) == 0 ||
	      strcmp("C.ISO-8859-1", base_locale) == 0))
         {

            strcpy(db_path_name, 
                   form("%s/%s", info_lib_dir, base_name)
                  );
 
            mm_version mmv_code(MAJOR, MINOR);
            mm_version mmv_base_data(2, 1);
            mm_version mmv_data(major_mm_version, minor_mm_version);

///////////////////////////////////////////////
// Hardcoded knowledge of discontinuation of 
// backward compatibility
///////////////////////////////////////////////
            if ( mmv_data < mmv_base_data ||
                 mmv_data == mmv_base_data || 
	         mmv_code < mmv_data
               ) 
	    {


               if ( f_bad_base_array_size == 0 ||
                    f_bad_base_array_size <= f_bad_info_bases 
                  ) 
               {
                 
                 if ( f_bad_base_array_size == 0 ) {
                    f_bad_base_array_size = 10;
                    f_bad_info_base_names = new charPtr[f_bad_base_array_size];
                    f_bad_info_base_paths = new charPtr[f_bad_base_array_size];

                    for (int i=0; i<f_bad_base_array_size; i++) {
                      f_bad_info_base_paths[i] = 0;
                      f_bad_info_base_names[i] = 0;
                    }

                 } else {
                    char** x = new charPtr[2*f_bad_base_array_size];
                    char** y = new charPtr[2*f_bad_base_array_size];

                    for (int i=0; i<2*f_bad_base_array_size; i++) {
                      x[i] = 0;
                      y[i] = 0;
                    }

                    memcpy(x, f_bad_info_base_names, sizeof(charPtr)*f_bad_base_array_size);
                    memcpy(y, f_bad_info_base_paths, sizeof(charPtr)*f_bad_base_array_size);
                    f_bad_base_array_size *= 2;

                    delete f_bad_info_base_names;
                    delete f_bad_info_base_paths;

                    f_bad_info_base_names = x;
                    f_bad_info_base_paths = y;
                     
                 }


               } 


               f_bad_info_base_paths[f_bad_info_bases] = strdup(info_lib_dir);
               f_bad_info_base_names[f_bad_info_bases] = strdup(base_name);

               f_bad_info_bases++;

               MESSAGE(cerr, "Data and code version mismatch");

               MESSAGE(cerr, form("Data version: v%d.%d",
                    major_mm_version, minor_mm_version
                           ));

               MESSAGE(cerr, form("Code version: v%d.%d", 
               		MAJOR, MINOR
    			   ));

               MESSAGE(cerr, form("infobase %s is not available.", base_name));

               continue;
            }

//reset_total();
            _init_info_base(db_path_name, base_name, base_desc, base_uid, base_locale,
		            mm_version(major_mm_version, minor_mm_version));
//report_total();
         }
      }

   }
   map_in -> close();
   delete map_in ;
}
Exemple #11
0
Boolean 
info_lib::define_info_base( char* base_name, char* base_desc, 
                            char* spec_file_path
                          )
{
//MESSAGE(cerr, "define_info_base()");
//debug(cerr, base_name);
//debug(cerr, base_desc);
//debug(cerr, spec_file_path);

   char new_db_path[PATHSIZ]; 
   char f_name[PATHSIZ]; 
   char base_uid[UIDSIZ]; 

   strcpy(new_db_path, form("%s/%s", info_lib_path, base_name));

   strcpy(base_uid, unique_id());

   g_mode_8_3 = 1;

   info_base* base = get_info_base(base_name) ;

/* no checking here. DDK assures unique base name case
   if ( base == 0 ) {
*/
      
//////////////////////////
// check info base path
//////////////////////////
      if ( check_and_create_dir(new_db_path) == false ) {
         throw(stringException(form("bad base bath %s", new_db_path)));
      }

//////////////////////////
// remove any old files 
//////////////////////////

      strcpy(f_name, form("%s.%s", base_name, DATA_FILE_SUFFIX));
      if ( exist_file(f_name, new_db_path) == true )
         del_file(f_name, new_db_path);

      strcpy(f_name, form("%s.%s", base_name, INDEX_FILE_SUFFIX));
      if ( exist_file(f_name, new_db_path) == true )
         del_file(f_name, new_db_path);

      strcpy(f_name, form("%s.%s", base_name, SCHEMA_FILE_SUFFIX));
      if ( exist_file(f_name, new_db_path) == true )
         del_file(f_name, new_db_path);


      f_obj_dict -> init_a_base(spec_file_path, new_db_path, base_name);

      const char* lang;
      if ((lang = getenv("LC_ALL")) == NULL)
	if ((lang = getenv("LC_CTYPE")) == NULL)
	  if ((lang = getenv("LANG")) == NULL)
	    lang = "C";

#ifdef DtinfoClient
      _DtXlateDb db    = NULL;
      char* std_locale = NULL;

      if (_DtLcxOpenAllDbs(&db) == 0)
      {
	char platform[_DtPLATFORM_MAX_LEN + 1];
	int execver, compver;

	if (_DtXlateGetXlateEnv(db, platform, &execver, &compver) == 0)
	{
	  _DtLcxXlateOpToStd(db, platform, compver, DtLCX_OPER_SETLOCALE,
					lang, &std_locale, NULL, NULL, NULL);
	}
	_DtLcxCloseDb(&db);
	db = NULL;
      }
#endif

      base = new info_base(*f_obj_dict, set_nm_list, list_nm_list,
                           new_db_path, base_name, base_desc, base_uid,
#ifdef DtinfoClient
			   std_locale ? std_locale : lang,
#else
			   lang,
#endif
                           mm_version(MAJOR, MINOR)
                          );

      info_base_list.insert_as_tail(new dlist_void_ptr_cell(base));

/*************************************/
// add the base name and description
// to the names file
/*************************************/
      char* lib_nm = form("%s/%s", info_lib_path, MAP_FILE_8_3);

      fstream nm_out(lib_nm, ios::app, open_file_prot());

      if ( !nm_out ) {
         MESSAGE(cerr, form("can't open %s/%s for append", 
                            info_lib_path, MAP_FILE_8_3)
                );
         throw(streamException(nm_out.rdstate()));
      }

      if ( bytes(nm_out) == 0 ) {
         char* lib_entry = form("%s\t%s\n", info_lib_name, unique_id());

         if ( !(nm_out << lib_entry) ) {
            MESSAGE(cerr, 
	       form("write %s.%s failed", info_lib_path, MAP_FILE_8_3));
            throw(streamException(nm_out.rdstate()));
         }
      }

      char* base_entry = form("%s\t%s\t%s\t%s\t%d\t%d\n", 
                              base_name, base_desc, base_uid,
#ifdef DtinfoClient
			      std_locale ? std_locale: lang,
#else
			      lang,
#endif
			      MAJOR, MINOR
                             );
#ifdef DtinfoClient
      if (std_locale)
	free(std_locale);
#endif

      if ( !(nm_out << base_entry) ) {
         MESSAGE(cerr, form("write %s.%s failed", info_lib_path, MAP_FILE_8_3));
         throw(streamException(nm_out.rdstate()));
      }

      nm_out.close();

      if ( nm_out.fail() ) {
         MESSAGE(cerr, form("close %s.%s failed", info_lib_path, MAP_FILE_8_3));
         throw(streamException(nm_out.rdstate()));
      }

   //}


//MESSAGE(cerr, "define() done");
   return true;
}
Exemple #12
0
void user_menu_cmd (void)
{
    char *menu, *p;
    int  col, i, accept_entry = 1;
    int  selected, old_patterns;
    Listbox *listbox;

    if (!vfs_current_is_local ()){
    message (1, _(" Oops... "),
         _(" I can't run programs while logged on a non local directory "));
    return;
    }

    menu = strdup (MC_LOCAL_MENU);
    if (!exist_file (menu) || !menu_file_own (menu)){
    free (menu);
#ifdef OS2_NT
    menu = strdup("NC.MNU");
    if (!exist_file (menu))
#endif
        {
        menu = concat_dir_and_file (home_dir, MC_HOME_MENU);
    if (!exist_file (menu)){
        free (menu);
        menu = concat_dir_and_file (mc_home, MC_GLOBAL_MENU);
    }
    }
    }

    if ((data = load_file (menu)) == NULL){
    message (1, MSG_ERROR, _(" Can't open file %s \n %s "),
         menu, unix_error_string (errno));
    free (menu);
    return;
    }
    free (menu);

    max_cols = 0;
    for (i = 0; i < MAX_ENTRIES; i++)
    entries [i] = 0;
    selected = 0;

    /* Parse the menu file */
    old_patterns = easy_patterns;
    p = check_patterns (data);
    for (menu_lines = col = 0; *p; p++){
    if (col == 0 && !entries [menu_lines]){
        if (*p == '#'){
        /* A commented menu entry */
        accept_entry = 1;
        } else if (*p == '+'){
        if (*(p+1) == '='){
            /* Combined adding and default */
            char *q = p++;

            p = test_line (q, &accept_entry);
            if (selected == 0 && accept_entry)
            selected = menu_lines;
        } else {
            /* A condition for adding the entry */
            p = test_line (p, &accept_entry);
        }
        } else if (*p == '='){
        if (*(p+1) == '+'){
            char *q = p++;
            /* Combined adding and default */
            p = test_line (q, &accept_entry);
            if (selected == 0 && accept_entry)
            selected = menu_lines;
        } else {
            /* A condition for making the entry default */
            i = 1;
            p = test_line (p, &i);
            if (selected == 0 && i)
            selected = menu_lines;
        }
        }
        else if (*p > ' ' && *p < 127){
        /* A menu entry title line */
        if (accept_entry)
            entries [menu_lines] = p;
        else
            accept_entry = 1;
        }
    }
    if (menu_lines == MAX_ENTRIES)
        break;
    if (*p == '\t')
        *p = ' ';
    col++;
    if (*p == '\n'){
        if (entries [menu_lines]){
        menu_lines++;
        accept_entry = 1;
        }
        max_cols = max (max_cols, col);
        col = 0;
    }
    }
    max_cols = min (max (max_cols, col), MAX_ENTRY_LEN);

    /* Create listbox */
    listbox = create_listbox_window (max_cols+2, menu_lines, _(" User menu "),
                     "[Menu File Edit]");

    /* insert all the items found */
    for (i = 0; i < menu_lines; i++)
    LISTBOX_APPEND_TEXT (listbox, entries [i][0],
                 extract_line (entries [i],
                       entries [i]+MAX_ENTRY_LEN),
                 entries [i]);

    /* Select the default entry */
    listbox_select_by_number (listbox->list, selected);

    selected = run_listbox (listbox);
    if (selected >= 0)
    execute_menu_command (entries [selected]);

    easy_patterns = old_patterns;
    do_refresh ();
    free (data);
}
//	ファイルから読み込み
//	bRenderTargetをTRUEにした場合はPOOLも D3DPOOL_MANAGED として読み込まれる。
//void CMglTexture::CreateTextureFromFile( LPCSTR szFileName, BOOL bRenderTarget, D3DCOLOR colorKey )
void CMglTexture::CreateTextureFromFileEx( LPCSTR szFileName, int nForceBmpWidth, int nForceBmpHeight,
	BOOL bRenderTarget, D3DCOLOR colorKey, DWORD dwFilter, DWORD dwMapFilter )
{
	InitCheck();	//	初期化チェック

	//	二回目以降の呼び出しを考慮し一端Release
	Release();

	//	2009/09/27  ファイルの存在チェックをここでしよう
	//	(ファイルが存在しない場合、D3DXERR_INVALIDDATA を返すっぽいが、
	//	 ファイルが壊れてる場合とか、その他の場合でも返す可能性があるしね。)
	if ( exist_file( szFileName ) != true )
	{
		MyuThrow( MGLMSGNO_IMAGE_FILE_NOT_FOUND, "%s の読み込みに失敗。ファイルが存在しません。", szFileName );
	}

	/////////////////////////////////////////////////////////////////

	//	bRenderTargetの反映
	DWORD usage;
	D3DPOOL pool;
	if ( bRenderTarget ){
		usage = D3DUSAGE_RENDERTARGET;
		pool = D3DPOOL_DEFAULT; // D3DPOOL_MANAGED; <= 逆…?
	}
	else{
		usage = 0;
		pool = D3DPOOL_MANAGED; // D3DPOOL_DEFAULT; <= 逆…?
	}

	//	記憶しておく
	m_colorKey = colorKey;
	m_bRenderTarget = bRenderTarget;

	/*	2007/01/10  D3DX_FILTER_NONE にしたら要らなくなる系じゃない系みたいな系?
	m_imgInfo.Width = nForceBmpWidth;
	m_imgInfo.Height = nForceBmpHeight;*/

	//	作成
	//DWORD r = D3DXCreateTextureFromFileEx( d3d, szFileName, x, y, D3DX_DEFAULT,
	DWORD r = D3DXCreateTextureFromFileEx(
		d3d, szFileName,
/*		D3DX_DEFAULT,	//	Width -  この値が 0 または D3DX_DEFAULT の場合、ディメンジョンはファイルから取得される。
		D3DX_DEFAULT,	//	Height - この値が 0 または D3DX_DEFAULT の場合、ディメンジョンはファイルから取得される。*/
		nForceBmpWidth,	//	Width -  この値が 0 または D3DX_DEFAULT の場合、ディメンジョンはファイルから取得される。
		nForceBmpHeight,//	Height - この値が 0 または D3DX_DEFAULT の場合、ディメンジョンはファイルから取得される。
		D3DX_DEFAULT,	//	MipLevels
		usage,			//	Usage - 0 または D3DUSAGE_RENDERTARGET。このフラグに D3DUSAGE_RENDERTARGET を設定すると、そのサーフェスはレンダリング ターゲットとして使用されることを示す。
		m_myudg->GetFormat(),//	Format - テクスチャに対して要求されたピクセル フォーマットを記述する、D3DFORMAT 列挙型のメンバ。
		pool,			//	Pool - テクスチャの配置先となるメモリ クラスを記述する、D3DPOOL 列挙型のメンバ。
		dwFilter, dwMapFilter, colorKey, &m_imgInfo, NULL, &m_pTexture );
//		D3DX_FILTER_NONE, D3DX_FILTER_NONE, colorKey, &m_imgInfo, NULL, &m_pTexture );
//		D3DX_FILTER_POINT, D3DX_FILTER_POINT, colorKey, &m_imgInfo, NULL, &m_pTexture );

	//	エラーコードによってメッセージを変更する
	if ( r == E_OUTOFMEMORY )
		MyuThrow2( r, 0x0201, "%s の読み込みに失敗。VRAMまたはメモリが不足しています。", szFileName );
	else if ( r == D3DERR_OUTOFVIDEOMEMORY )
		MyuThrow2( r, 0x0202, "%s の読み込みに失敗。VRAMが不足しています。", szFileName );
	else if ( r == D3DERR_NOTAVAILABLE ) 
		MyuThrow2( r, 0x0202, "%s の読み込みに失敗。(DxErr=D3DERR_NOTAVAILABLE)", szFileName );
	else if ( r == D3DERR_INVALIDCALL ) 
		MyuThrow2( r, 0x0202, "%s の読み込みに失敗。(DxErr=D3DERR_INVALIDCALL)", szFileName );
	else if ( r == D3DXERR_INVALIDDATA ) 
		MyuThrow2( r, 0x0202, "%s の読み込みに失敗。(DxErr=D3DXERR_INVALIDDATA)", szFileName );
	else if ( r != S_OK ) 
		MyuThrow2( r, 0x0203, "CMglImage::CreateFromFile()  D3DXCreateTextureFromFileEx(%s)に失敗", szFileName );

	//	SetRenderとかで必要なのでサーフェス取得しておく
	_GetSurface();
}