Updated copyright text/header in most source files.
[geda-gaf.git] / gnetlist / src / parsecmd.c
blobc7b85923ce65c835c79635f354bb1a1a0d9eeb65
1 /* gEDA - GPL Electronic Design Automation
2 * gnetlist - gEDA Netlist
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
21 #include <config.h>
23 #include <stdio.h>
24 #ifdef HAVE_STRING_H
25 #include <string.h>
26 #endif
27 #ifdef HAVE_UNISTD_H
28 #include <unistd.h>
29 #endif
31 #ifdef HAVE_GETOPT_H
32 #include <getopt.h>
33 #endif
35 #include <libgeda/libgeda.h>
37 #include "../include/globals.h"
38 #include "../include/prototype.h"
40 #ifdef HAVE_LIBDMALLOC
41 #include <dmalloc.h>
42 #endif
44 #define OPTIONS "o:qieIhvsg:c:l:m:O:n"
46 #ifndef OPTARG_IN_UNISTD
47 extern char *optarg;
48 extern int optind;
49 #endif
52 /* Added by SDB 3.3.2006. */
53 #ifdef HAVE_GETOPT_LONG
54 struct option long_options[] =
56 {"help", 0, 0, 'h'},
57 {"nomunge", 0, 0, 'n'},
58 {"verbose", 0, 0, 'v'},
59 {"sort", 0, 0, 's'},
60 {"embedd", 0, 0, 'e'},
61 {"include", 0, 0, 'I'},
62 {0, 0, 0, 0}
64 #endif
68 void usage(char *cmd)
70 printf("Usage: %s [OPTIONS] filename1 ... filenameN\n", cmd);
71 printf(" -e --embedd Force embedding contents of .include file (spice-sdb)\n");
72 printf(" -h --help Print this help string\n");
73 printf(" -i Interactive scheme mode\n");
74 printf(" -I --include Put .INCLUDE <filename> in output file instead\n");
75 printf(" of model file's contents (spice-sdb)\n");
76 printf(" -q Quiet mode\n");
77 printf(" -l filename Load scheme file before loading backend\n");
78 printf(" -m filename Load scheme file after loading backend,\n");
79 printf(" but still before executing procedure\n");
80 printf(" -n --nomunge Don't autocorrect refdeses (spice-sdb)\n");
81 printf(" -g proc Scheme procedure (netlister backend) to execute.\n");
82 printf(" Use '-g help' to list available backends.\n");
83 printf(" -o filename Output netlist filename\n");
84 printf(" -c string Execute string as a scheme script\n");
85 printf(" -O option Pass the given option to the backend\n");
86 printf(" -v --verbose Verbose mode on\n");
87 printf(" -s --sort Sort output netlist (spice-sdb)\n");
88 printf("\n");
89 exit(0);
92 /* --------------------------------------------------------------- *
93 * create_command_line takes argc and argv, and returns a single
94 * string which is the command line used to invoke the program.
95 * It is used to pass the command invocation to the SPICE netlist
96 * for inclusion on the first SPICE line.
97 * 8.22.2004 -- SDB.
98 * --------------------------------------------------------------- */
99 char *create_command_line(int argc, char *argv[])
101 int i;
102 char *local_command_line = NULL;
104 local_command_line = g_strdup (argv[0]); /* Initialize command line string */
105 for (i = 1; i < argc; i++) {
106 local_command_line = g_strconcat (local_command_line, " ", argv[i], NULL);
108 return local_command_line;
113 /* from guile (libguile/gh_init.c) */
114 static SCM
115 catch_handler (void *data, SCM tag, SCM throw_args)
117 fprintf (stderr, "\nJust got an error; tag is\n ");
118 scm_display (tag, scm_current_output_port ());
119 scm_newline (scm_current_output_port ());
120 scm_newline (scm_current_output_port ());
121 return SCM_BOOL_F;
125 int parse_commandline(int argc, char *argv[])
127 int ch;
129 /* Converted to getopt_long by SDB 3.3.2006 */
130 #ifdef HAVE_GETOPT_LONG
131 /* int option_index = 0; */
133 while ((ch = getopt_long(argc, argv, OPTIONS, long_options, NULL /* &option_index */)) != -1) {
134 #else
135 while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
136 #endif
137 switch (ch) {
139 case 'v':
140 backend_params = g_slist_append(backend_params, "verbose_mode");
141 verbose_mode = TRUE;
142 break;
144 case 'i':
145 backend_params = g_slist_append(backend_params, "interactive_mode");
146 interactive_mode = TRUE;
147 break;
149 case 'I':
150 backend_params = g_slist_append(backend_params, "include_mode");
151 include_mode = TRUE;
152 break;
154 case 'e':
155 backend_params = g_slist_append(backend_params, "embedd_mode");
156 embedd_mode = TRUE;
157 break;
159 case 'q':
160 backend_params = g_slist_append(backend_params, "quiet_mode");
161 quiet_mode = TRUE;
162 break;
164 case 'g':
165 guile_proc = g_strdup(optarg);
167 break;
169 case 'l':
170 pre_backend_list = g_slist_append(pre_backend_list, optarg);
171 break;
173 case 'm':
174 post_backend_list = g_slist_append(post_backend_list, optarg);
175 break;
177 case 'n':
178 backend_params = g_slist_append(backend_params, "nomunge_mode");
179 nomunge_mode = TRUE;
180 break;
182 case 'o':
183 g_free(output_filename);
184 output_filename = g_strdup(optarg);
185 break;
187 case 'O':
188 backend_params = g_slist_append(backend_params, optarg);
189 break;
191 case 'c':
192 scm_internal_stack_catch (SCM_BOOL_T,
193 (scm_t_catch_body) scm_c_eval_string,
194 (void *) optarg,
195 (scm_t_catch_handler) catch_handler,
196 (void *) optarg);
197 break;
199 case 's':
200 backend_params = g_slist_append(backend_params, "sort_mode");
201 sort_mode = TRUE;
202 break;
205 case 'h':
206 usage(argv[0]);
207 break;
209 case '?':
210 default:
211 usage(argv[0]);
212 break;
216 if (quiet_mode) {
217 verbose_mode = FALSE;
220 return (optind);