Added .cvsignore
[geda-gaf.git] / gnetlist / src / parsecmd.c
blob89f894f38585e563b28d692015962e928457efeb
1 /* gEDA - GPL Electronic Design Automation
2 * gnetlist - gEDA Netlist
3 * Copyright (C) 1998-2000 Ales V. Hvezda
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 USA
20 #include <config.h>
22 #include <stdio.h>
23 #ifdef HAVE_STRING_H
24 #include <string.h>
25 #endif
26 #ifdef HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
30 #ifdef HAVE_GETOPT_H
31 #include <getopt.h>
32 #endif
34 #include <libgeda/libgeda.h>
36 #include "../include/globals.h"
37 #include "../include/prototype.h"
39 #ifdef HAVE_LIBDMALLOC
40 #include <dmalloc.h>
41 #endif
43 #define OPTIONS "o:qieIhvsg:c:l:m:O:"
45 #ifndef OPTARG_IN_UNISTD
46 extern char *optarg;
47 extern int optind;
48 #endif
51 /* Added by SDB 3.3.2006. */
52 #ifdef HAVE_GETOPT_LONG
53 struct option long_options[] =
55 {"help", 0, 0, 0},
56 /* will add other args later */
57 {0, 0, 0, 0}
59 #endif
63 void usage(char *cmd)
65 printf("Usage: %s [OPTIONS] filename1 ... filenameN\n", cmd);
66 printf(" -e Force embedding contents of .include file\n");
67 printf(" -h --help Print this help string\n");
68 printf(" -i Interactive scheme mode\n");
69 printf(" -I Put .INCLUDE <filename> in output file instead\n");
70 printf(" of model file's contents\n");
71 printf(" -q Quiet mode\n");
72 printf(" -l filename Load scheme file before loading backend\n");
73 printf(" -m filename Load scheme file after loading backend,\n");
74 printf(" but still before executing procedure\n");
75 printf(" -g proc Scheme procedure to execute.\n");
76 printf(" Use '-g help' to list available backends.\n");
77 printf(" -o filename Output netlist filename\n");
78 printf(" -c string Execute string as a scheme script\n");
79 printf(" -O option Pass the given option to the backend\n");
80 printf(" -v Verbose mode on\n");
81 printf(" -s Sort output netlist (for Gnucap)\n");
82 printf("\n");
83 exit(0);
86 /* --------------------------------------------------------------- *
87 * create_command_line takes argc and argv, and returns a single
88 * string which is the command line used to invoke the program.
89 * It is used to pass the command invocation to the SPICE netlist
90 * for inclusion on the first SPICE line.
91 * 8.22.2004 -- SDB.
92 * --------------------------------------------------------------- */
93 char *create_command_line(int argc, char *argv[])
95 int i;
96 char *local_command_line = NULL;
98 local_command_line = g_strdup (argv[0]); /* Initialize command line string */
99 for (i = 1; i < argc; i++) {
100 local_command_line = g_strconcat (local_command_line, " ", argv[i], NULL);
102 return local_command_line;
107 /* from guile (libguile/gh_init.c) */
108 static SCM
109 catch_handler (void *data, SCM tag, SCM throw_args)
111 fprintf (stderr, "\nJust got an error; tag is\n ");
112 scm_display (tag, scm_current_output_port ());
113 scm_newline (scm_current_output_port ());
114 scm_newline (scm_current_output_port ());
115 return SCM_BOOL_F;
119 int parse_commandline(int argc, char *argv[])
121 int ch;
123 /* Converted to getopt_long by SDB 3.3.2006 */
124 #ifdef HAVE_GETOPT_LONG
125 int option_index = 0;
127 while ((ch = getopt_long(argc, argv, OPTIONS, long_options, &option_index)) != -1) {
128 #else
129 while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
130 #endif
131 switch (ch) {
133 case 'v':
134 backend_params = g_slist_append(backend_params, "verbose_mode");
135 verbose_mode = TRUE;
136 break;
138 case 'i':
139 backend_params = g_slist_append(backend_params, "interactive_mode");
140 interactive_mode = TRUE;
141 break;
143 case 'I':
144 backend_params = g_slist_append(backend_params, "include_mode");
145 include_mode = TRUE;
146 break;
148 case 'e':
149 backend_params = g_slist_append(backend_params, "embedd_mode");
150 embedd_mode = TRUE;
151 break;
153 case 'q':
154 backend_params = g_slist_append(backend_params, "quiet_mode");
155 quiet_mode = TRUE;
156 break;
158 case 'g':
159 guile_proc = (char *) g_malloc(sizeof(char) *
160 (strlen(optarg) + 1));
161 strcpy(guile_proc, optarg);
163 break;
165 case 'l':
166 pre_backend_list = g_slist_append(pre_backend_list, optarg);
167 break;
169 case 'm':
170 post_backend_list = g_slist_append(post_backend_list, optarg);
171 break;
173 case 'o':
174 if (output_filename) {
175 g_free(output_filename);
177 output_filename = (char *) g_malloc(sizeof(char) *
178 (strlen(optarg) + 1));
179 strcpy(output_filename, optarg);
180 break;
182 case 'O':
183 backend_params = g_slist_append(backend_params, optarg);
184 break;
186 case 'c':
187 scm_internal_stack_catch (SCM_BOOL_T,
188 (scm_t_catch_body) scm_c_eval_string,
189 (void *) optarg,
190 (scm_t_catch_handler) catch_handler,
191 (void *) optarg);
192 break;
194 case 's':
195 backend_params = g_slist_append(backend_params, "sort_mode");
196 sort_mode = TRUE;
197 break;
200 case 'h':
201 usage(argv[0]);
202 break;
204 case '?':
205 default:
206 usage(argv[0]);
207 break;
211 if (quiet_mode) {
212 verbose_mode = FALSE;
215 return (optind);