gsch2pcb: Make --m4-file and -m4-pcbdir arguments work again.
[geda-gaf/peter-b.git] / gattrib / src / parsecmd.c
blobd19ee6ed62191f785304bb8b1a68d29ccdce4634
1 /* gEDA - GPL Electronic Design Automation
2 * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
3 * Copyright (C) 2003-2010 Stuart D. Brorson.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 /*!
20 * \file
21 * \brief Functions to parse the command line.
23 * Functions to parse the command line and to provide usage
24 * information.
27 #include <config.h>
29 #include <stdio.h>
30 #ifdef HAVE_STRING_H
31 #include <string.h>
32 #endif
33 #ifdef HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif
38 #ifdef HAVE_GETOPT_H
39 #include <getopt.h>
40 #endif /* Checking for getopt */
42 #if !defined(HAVE_GETOPT_LONG) || !defined(HAVE_GETOPT_H)
43 /*! \brief Command line option string for getopt.
45 * Command line option string for getopt. Defines "q" for quiet,
46 * "v" for verbose and "h" for help.
48 #define OPTIONS "qvh"
49 #ifndef OPTARG_IN_UNISTD
50 extern char *optarg;
51 extern int optind;
52 #endif
53 #endif /* Checking for getopt_long */
56 #ifdef HAVE_LIBDMALLOC
57 #include <dmalloc.h>
58 #endif
61 /*------------------------------------------------------------------
62 * Gattrib specific includes
63 *------------------------------------------------------------------*/
64 #include <libgeda/libgeda.h> /* geda library fcns */
65 #include "../include/struct.h" /* typdef and struct declarations */
66 #include "../include/prototype.h" /* function prototypes */
67 #include "../include/globals.h"
69 /*!
70 * \brief Print usage message
72 * Prints gattrib usage information to stdout.
73 * \param cmd Unused parameter.
77 void usage(char *cmd)
79 printf("\n");
80 printf("Gattrib: The gEDA project\'s attribute editor.\n");
81 printf("Presents schematic attributes in easy-to-edit spreadsheet format.\n");
82 printf("\n");
83 printf("Usage: %s [OPTIONS] filename1 ... filenameN\n", cmd);
84 printf(" -q, --quiet Quiet mode\n");
85 printf(" -v, --verbose Verbose mode on\n");
86 printf(" -h, --help This help menu\n");
87 printf("\n");
88 printf(" FAQ:\n");
89 printf(" * What do the colors of the cell text mean?\n");
90 printf(" The cell colors indicate the visibility of the attribute.\n");
91 printf(" Black = Visible attribute, value displayed only.\n");
92 printf(" Grey = Invisible attribute.\n");
93 printf(" Red = Visible attribute, name displayed only.\n");
94 printf(" Blue = Visible attribute, both name and value displayed.\n");
95 printf("\n");
96 printf(" * What does the period (\".\") at the end of some component refdeses mean?\n");
97 printf(" The period is placed after the refdeses of slotted components.\n");
98 printf(" If slots are present on the component, then the different slots appear\n");
99 printf(" in different rows with the slot number after the period. Example: C101.2.\n");
100 printf("\n");
101 printf("Copyright (C) 2003 -- 2006 Stuart D. Brorson. E-mail: sdb (AT) cloud9 (DOT) net.\n");
102 printf("\n");
103 exit(0);
107 * \brief Parse command line switches.
109 * Parse command line switches at startup. There are only 3 command
110 * line switches:
111 * - verbose
112 * - quiet
113 * - help
114 * \param argc Number of command line arguments
115 * \param argv Command line arguments (array of strings)
116 * \returns I don't know what - looks uninitialised in some circumstances.
119 int parse_commandline(int argc, char *argv[])
121 int ch;
123 #if defined(HAVE_GETOPT_LONG) && defined(HAVE_GETOPT_H)
124 /* Use getopt_long if it is available */
125 int option_index = 0;
126 static struct option long_options[] = {
127 {"help", 0, 0, 'h'},
128 {"quiet", 0, 0, 'q'},
129 {"verbose", 0, 0, 'v'},
130 {0, 0, 0, 0}
133 while (1) {
134 ch = getopt_long(argc, argv, "hqv", long_options, &option_index);
135 if (ch == -1)
136 break;
137 #else
138 /* Otherwise just use regular getopt */
139 while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
140 #endif
142 switch (ch) {
144 case 'v':
145 verbose_mode = TRUE;
146 break;
148 case 'q':
149 quiet_mode = TRUE;
150 break;
152 case 'h':
153 usage(argv[0]);
154 break;
156 case '?':
157 default:
158 usage(argv[0]);
159 break;
163 if (quiet_mode) {
164 verbose_mode = FALSE;
167 return (optind);