Updated copyright text/header in most source files.
[geda-gaf.git] / gattrib / src / parsecmd.c
blobe6e9c5f810d8f3f780f7562c2f146b03b5c9aabb
1 /* gEDA - GPL Electronic Design Automation
2 * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
3 * Copyright (C) 2003-2007 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., 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
31 #ifdef HAVE_GETOPT_H
32 #include <getopt.h>
33 #endif /* Checking for getopt */
35 #if !defined(HAVE_GETOPT_LONG) || !defined(HAVE_GETOPT_H)
36 #define OPTIONS "qvh"
37 #ifndef OPTARG_IN_UNISTD
38 extern char *optarg;
39 extern int optind;
40 #endif
41 #endif /* Checking for getopt_long */
44 #ifdef HAVE_LIBDMALLOC
45 #include <dmalloc.h>
46 #endif
49 /*------------------------------------------------------------------
50 * Gattrib specific includes
51 *------------------------------------------------------------------*/
52 #include <libgeda/libgeda.h> /* geda library fcns */
53 #include "../include/struct.h" /* typdef and struct declarations */
54 #include "../include/prototype.h" /* function prototypes */
55 #include "../include/globals.h"
58 void usage(char *cmd)
60 printf("\n");
61 printf("Gattrib: The gEDA project\'s attribute editor.\n");
62 printf("Presents schematic attributes in easy-to-edit spreadsheet format.\n");
63 printf("\n");
64 printf("Usage: %s [OPTIONS] filename1 ... filenameN\n", cmd);
65 printf(" -q, --quiet Quiet mode\n");
66 printf(" -v, --verbose Verbose mode on\n");
67 printf(" -h, --help This help menu\n");
68 printf("\n");
69 printf(" FAQ:\n");
70 printf(" * What do the colors of the cell text mean?\n");
71 printf(" The cell colors indicate the visibility of the attribute.\n");
72 printf(" Black = Visible attribute, value displayed only.\n");
73 printf(" Grey = Invisible attribute.\n");
74 printf(" Red = Visible attribute, name displayed only.\n");
75 printf(" Blue = Visible attribute, both name and value displayed.\n");
76 printf("\n");
77 printf(" * What does the period (\".\") at the end of some component refdeses mean?\n");
78 printf(" The period is placed after the refdeses of slotted components.\n");
79 printf(" If slots are present on the component, then the different slots appear\n");
80 printf(" in different rows with the slot number after the period. Example: C101.2.\n");
81 printf("\n");
82 printf("Copyright (C) 2003 -- 2006 Stuart D. Brorson. E-mail: sdb (AT) cloud9 (DOT) net.\n");
83 printf("\n");
84 exit(0);
88 int parse_commandline(int argc, char *argv[])
90 int ch;
92 #if defined(HAVE_GETOPT_LONG) && defined(HAVE_GETOPT_H)
93 /* Use getopt_long if it is available */
94 int option_index = 0;
95 static struct option long_options[] = {
96 {"help", 0, 0, 'h'},
97 {"quiet", 0, 0, 'q'},
98 {"verbose", 0, 0, 'v'},
99 {0, 0, 0, 0}
102 while (1) {
103 ch = getopt_long(argc, argv, "hqv", long_options, &option_index);
104 if (ch == -1)
105 break;
106 #else
107 /* Otherwise just use regular getopt */
108 while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
109 #endif
111 switch (ch) {
113 case 'v':
114 verbose_mode = TRUE;
115 break;
117 case 'q':
118 quiet_mode = TRUE;
119 break;
121 case 'h':
122 usage(argv[0]);
123 break;
125 case '?':
126 default:
127 usage(argv[0]);
128 break;
132 if (quiet_mode) {
133 verbose_mode = FALSE;
136 return (optind);