missing NULL terminator in set_config_x
[geda-gaf.git] / gattrib / src / parsecmd.c
blobd9bc541d393c1fd46f709595c8247d723a55dfb9
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 /*------------------------------------------------------------------
57 * Gattrib specific includes
58 *------------------------------------------------------------------*/
59 #include <libgeda/libgeda.h> /* geda library fcns */
60 #include "../include/struct.h" /* typdef and struct declarations */
61 #include "../include/prototype.h" /* function prototypes */
62 #include "../include/globals.h"
63 #include "../include/gettext.h"
65 /*!
66 * \brief Print usage message
68 * Prints gattrib usage information to stdout.
69 * \param cmd Unused parameter.
73 void usage(char *cmd)
75 printf(_(
76 "\n"
77 "Gattrib: The gEDA project\'s attribute editor.\n"
78 "Presents schematic attributes in easy-to-edit spreadsheet format.\n"
79 "\n"
80 "Usage: %s [OPTIONS] filename1 ... filenameN\n"
81 " -q, --quiet Quiet mode\n"
82 " -v, --verbose Verbose mode on\n"
83 " -h, --help This help menu\n"
84 "\n"
85 " FAQ:\n"
86 " * What do the colors of the cell text mean?\n"
87 " The cell colors indicate the visibility of the attribute.\n"
88 " Black = Visible attribute, value displayed only.\n"
89 " Grey = Invisible attribute.\n"
90 " Red = Visible attribute, name displayed only.\n"
91 " Blue = Visible attribute, both name and value displayed.\n"
92 "\n"
93 " * What does the period (\".\") at the end of some component refdeses mean?\n"
94 " The period is placed after the refdeses of slotted components.\n"
95 " If slots are present on the component, then the different slots appear\n"
96 " in different rows with the slot number after the period. Example: C101.2.\n"
97 "\n"
98 "Copyright (C) 2003 -- 2006 Stuart D. Brorson. E-mail: sdb (AT) cloud9 (DOT) net.\n"
99 "\n"), cmd);
100 exit(0);
104 * \brief Parse command line switches.
106 * Parse command line switches at startup. There are only 3 command
107 * line switches:
108 * - verbose
109 * - quiet
110 * - help
111 * \param argc Number of command line arguments
112 * \param argv Command line arguments (array of strings)
113 * \returns I don't know what - looks uninitialised in some circumstances.
116 int parse_commandline(int argc, char *argv[])
118 int ch;
120 #if defined(HAVE_GETOPT_LONG) && defined(HAVE_GETOPT_H)
121 /* Use getopt_long if it is available */
122 int option_index = 0;
123 static struct option long_options[] = {
124 {"help", 0, 0, 'h'},
125 {"quiet", 0, 0, 'q'},
126 {"verbose", 0, 0, 'v'},
127 {0, 0, 0, 0}
130 while (1) {
131 ch = getopt_long(argc, argv, "hqv", long_options, &option_index);
132 if (ch == -1)
133 break;
134 #else
135 /* Otherwise just use regular getopt */
136 while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
137 #endif
139 switch (ch) {
141 case 'v':
142 verbose_mode = TRUE;
143 break;
145 case 'q':
146 quiet_mode = TRUE;
147 break;
149 case 'h':
150 usage(argv[0]);
151 break;
153 case '?':
154 default:
155 usage(argv[0]);
156 break;
160 if (quiet_mode) {
161 verbose_mode = FALSE;
164 return (optind);