2 * gEDA/gaf command-line utility
3 * Copyright (C) 2012 Peter Brett <peter@peter-b.co.uk>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 /* Gettext translation */
38 #define short_options "+hV"
40 static struct option long_options
[] =
42 {"help", 0, NULL
, 'h'},
43 {"version", 0, NULL
, 'V'},
44 {"no-rcfiles", 0, NULL
, 2},
48 struct internal_command
{
50 int (*func
)(int, char **);
53 static struct internal_command commands
[] =
56 {"config", cmd_config
},
57 {"export", cmd_export
},
61 /* Print help info and exit */
65 printf (_("Usage: gaf [OPTION...] COMMAND [ARGS ...]\n"
67 "gEDA/gaf command-line utility.\n"
70 " --no-rcfiles inhibit loading of 'gafrc' files\n"
71 " -h, --help display usage information and exit\n"
72 " -V, --version display version information and exit\n"
74 "Commonly-used commands (type `gaf <cmd> --help' for usage):\n"
75 " shell Scheme REPL for interactive gEDA data processing\n"
76 " config Edit gEDA configuration\n"
77 " export Export gEDA files in various image formats.\n"
79 "Please report bugs to %s.\n"),
84 /* Print version info and exit */
88 printf(_("gEDA/gaf %s (g%.7s)\n"
89 "Copyright (C) 1998-2012 gEDA developers\n"
90 "This is free software, and you are welcome to redistribute it under\n"
91 "certain conditions. For details, see the file `COPYING', which is\n"
92 "included in the gEDA distribution.\n"
93 "There is NO WARRANTY, to the extent permitted by law.\n"),
94 PACKAGE_DOTTED_VERSION
, PACKAGE_GIT_COMMIT
);
99 main (int argc
, char **argv
)
104 char **cmd_argv
= NULL
;
105 int (*cmd_func
)(int, char **) = NULL
;
109 setlocale (LC_ALL
, "");
110 bindtextdomain ("geda-gaf", LOCALEDIR
);
111 textdomain ("geda-gaf");
112 bind_textdomain_codeset ("geda-gschem", "UTF-8");
115 while (-1 != (c
= getopt_long (argc
, argv
, short_options
,
116 long_options
, NULL
))) {
120 /* This is a long-form-only flag option, and has already been
121 * dealt with by getopt_long(). */
124 case 2: /* --no-rcfiles */
125 setenv ("GAF_INHIBIT_RCFILES", "1", 1);
135 /* getopt_long already printed an error message */
136 fprintf (stderr
, _("\nRun `gaf --help' for more information.\n"));
141 g_assert_not_reached ();
145 /* The next argument should be a command */
146 if (optind
== argc
) {
148 _("ERROR: You must specify a command to run.\n"
150 "Run `gaf --help' for more information.\n"));
156 /* Look up the command */
158 for (i
= 0; commands
[i
].name
!= NULL
; i
++) {
159 if (strcmp (cmd
, commands
[i
].name
) == 0) {
160 cmd_func
= commands
[i
].func
;
164 if (cmd_func
== NULL
) {
166 _("ERROR: Unrecognised command `%s'.\n"
168 "Run `gaf --help' for more information.\n"),
173 cmd_argc
= argc
- optind
;
174 cmd_argv
= argv
+ optind
;
177 return cmd_func (cmd_argc
, cmd_argv
);