int builtin_export(char **av, t_env *env) { char const *export_options = "n"; char options[2]; char wrong_opt; int i; if (!av[1]) return (display_global_env(env->env_list)); i = 0; while (av[++i] && av[i][0] == '-' && ft_strcmp("--", av[i])) { if (!av[i][1]) { ft_putendl_fd("42sh: export: `-': not a valid identifier", 2); return (1); } if ((wrong_opt = check_arg_opt(av[i] + 1, export_options, options))) return (export_usage(wrong_opt)); } if (ft_strchr(options, 'n')) return (export_option_n(env, av + i)); else if (is_valid_variable_name(av[1])) return (set_to_global(env, av[1], av[2])); return (ft_dprintf(STDERR_FILENO, "%s: not a valid variable name\n", av[1])); }
static void export_command_line (int argc, char * const *argv) { int c; gchar *str; /* Parse command-line arguments */ while ((c = getopt_long (argc, argv, export_short_options, export_long_options, NULL)) != -1) { switch (c) { case 0: /* This is a long-form-only flag option, and has already been * dealt with by getopt_long(). */ break; case 2: /* --no-color */ settings.color = FALSE; break; case 'a': str = export_command_line__utf8_check (optarg, "-a,--align"); if (!export_parse_align (str)) { fprintf (stderr, bad_arg_msg, optarg, "-a,--align"); fprintf (stderr, see_help_msg); exit (1); } g_free (str); break; case 'c': settings.color = TRUE; break; case 'd': settings.dpi = strtod (optarg, NULL); if (settings.dpi <= 0) { fprintf (stderr, bad_arg_msg, optarg, "-d,--dpi"); fprintf (stderr, see_help_msg); exit (1); } break; case 'f': g_free (settings.format); settings.format = export_command_line__utf8_check (optarg, "-f,--format"); break; case 'F': str = export_command_line__utf8_check (optarg, "-F,--font"); g_free (settings.font); settings.font = str; break; case 'h': export_usage (); break; case 'k': str = export_command_line__utf8_check (optarg, "-k,--scale"); if (!export_parse_scale (str)) { fprintf (stderr, bad_arg_msg, optarg, "-k,--scale"); fprintf (stderr, see_help_msg); exit (1); } g_free (str); /* Since a specific scale was provided, ditch the paper size * setting */ if (settings.paper != NULL) { gtk_paper_size_free (settings.paper); settings.paper = NULL; } break; case 'l': if (!export_parse_layout (optarg)) { fprintf (stderr, bad_arg_msg, optarg, "-l,--layout"); fprintf (stderr, see_help_msg); exit (1); } break; case 'm': str = export_command_line__utf8_check (optarg, "-m,--margins"); if (!export_parse_margins (str)) { fprintf (stderr, bad_arg_msg, optarg, "-m,--margins"); fprintf (stderr, see_help_msg); exit (1); } g_free (str); break; case 'o': settings.outfile = optarg; break; case 'p': str = export_command_line__utf8_check (optarg, "-p,--paper"); if (!export_parse_paper (str)) { fprintf (stderr, bad_arg_msg, optarg, "-p,--paper"); fprintf (stderr, see_help_msg); exit (1); } g_free (str); break; case 's': str = export_command_line__utf8_check (optarg, "-s,--size"); if (!export_parse_size (str)) { fprintf (stderr, bad_arg_msg, optarg, "-s,--size"); fprintf (stderr, see_help_msg); exit (1); } g_free (str); /* Since a specific size was provided, ditch the paper size * setting */ if (settings.paper != NULL) { gtk_paper_size_free (settings.paper); settings.paper = NULL; } break; case '?': /* getopt_long already printed an error message */ fprintf (stderr, see_help_msg); exit (1); break; default: g_assert_not_reached (); } } /* Check that some schematic files to print were provided */ if (argc <= optind) { fprintf (stderr, _("ERROR: You must specify at least one input filename.\n")); fprintf (stderr, see_help_msg); exit (1); } settings.infilec = argc - optind; settings.infilev = &argv[optind]; if (settings.outfile == NULL) { fprintf (stderr, _("ERROR: You must specify an output filename.\n")); fprintf (stderr, see_help_msg); exit (1); } }