930d6adc3b344b485e4dc36997f2304186e453d9
[oweals/cde.git] / cde / lib / tt / bin / dbck / options.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 //%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                  
24 //%%  (c) Copyright 1993, 1994 International Business Machines Corp.    
25 //%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                   
26 //%%  (c) Copyright 1993, 1994 Novell, Inc.                             
27 //%%  $TOG: options.C /main/4 1998/03/20 14:26:44 mgreess $                                                     
28 /*
29  *
30  * options.cc
31  *
32  * Common option handling routines
33  *
34  * Copyright (c) 1990 by Sun Microsystems, Inc.
35  */
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include "util/copyright.h"
40 #if defined(linux) || defined(sgi) || defined(__FreeBSD__)
41 #include <getopt.h>
42 #endif     
43 #include "dbck.h"     
44 #include "options.h"
45 #include "util/tt_iostream.h"
46 #include "util/tt_gettext.h"
47      
48 Dbck_options::
49 Dbck_options()
50 {
51         _dbdirectories = new _Tt_string_list;
52         _sel_filename_p = 0;
53         _sel_filename = (char *) 0;
54         _sel_objid_p = 0;
55         _sel_objid_key = (_Tt_db_key *) 0;
56         _sel_type_p = 0;
57         _sel_type = (char *) 0;
58         _diag_badform_p = 0;
59         _diag_exist_p = 0;
60         _disp_id_p = 0;
61         _disp_mand_p = 0;
62         _disp_prop_p = 0;
63         _repair_netisam_p = 0;
64         _repair_type_p = 0;
65         _repair_type = (char *) 0;
66         _repair_delete_p = 0;
67         _debug_level = 0;
68 }
69
70 int Dbck_options::
71 set_opts(int argc, char **argv)
72 {
73         int c;
74         char *opts = optstring();
75
76         while (-1 != (c = getopt(argc,(char **)argv,opts))) {
77                 if (!set_option(c, optarg)) {
78                         //print help
79                         return 0;
80                 }
81         }
82         _dbdirectories = new _Tt_string_list;
83         for (; optind<argc; ++optind) {
84                 _Tt_string s(argv[optind]);
85                 _dbdirectories->append(s);
86         }
87         return 1;
88 }
89
90
91 int Dbck_options::
92 set_common_option(int optchar, const char *optval)
93 {
94         switch (optchar) {
95               case '?':
96               case 'h':         // treat h as illegal, forces Usage: msg
97                 return 0;
98               case 'v':
99                 _TT_PRINT_VERSIONS(progname)
100                 exit(0);
101               case 'd':
102                 _debug_level = atoi(optval);
103                 break;
104               case 'f':
105                 _sel_filename_p = 1;
106                 _sel_filename = optval;
107                 break;
108               case 'k':
109                 _sel_objid_p = 1;
110                 _sel_objid_key = new _Tt_db_key(_Tt_string(optval));
111                 break;
112               case 't':
113                 _sel_type_p = 1;
114                 _sel_type = optval;
115                 break;
116               case 'b':
117                 _diag_badform_p = 1;
118                 break;
119               case 'x':
120                 _diag_exist_p = 1;
121                 break;
122               case 'i':
123                 _disp_id_p = 1;
124                 break;
125               case 'm':
126                 _disp_mand_p = 1;
127                 break;
128               case 'p':
129                 _disp_prop_p = 1;
130                 break;
131               case 'I':
132                 _repair_netisam_p = 1;
133                 break;
134               case 'T':
135                 _repair_type_p = 1;
136                 _repair_type = optval;
137                 break;
138               case 'Z':
139                 _repair_delete_p = 1;
140                 break;
141               default:
142                 return 0;
143         }
144         return 1;
145 }
146
147 void Dbck_options::
148 print(FILE *f) const
149 {
150         fprintf(f,"%s <\n",type_string());
151         fprintf(f,"\nDirectories:\n");
152         dbdirectories()->print(_tt_string_print,f);
153         fprintf(f,"\n");
154                         
155         if (_sel_filename_p) {
156                 fprintf(f,catgets(_ttcatd, 6, 7, "Select by filename: %s\n"),
157                         (char *)_sel_filename);
158         }
159         if (_sel_objid_p) {
160                 fprintf(f,catgets(_ttcatd, 6, 8, "Select by objid key:"));
161                 _sel_objid_key->print(f);
162                 fprintf(f,"\n");
163         }
164         if (_sel_type_p) {
165                 fprintf(f,catgets(_ttcatd, 6, 9, "Select by type: %s\n"),
166                         (char *)_sel_type);
167         }
168         if (_diag_badform_p) {
169                 fprintf(f,catgets(_ttcatd, 6, 10,
170                                   "Diagnose badly formed entities\n"));
171         }
172         if (_diag_exist_p) {
173                 fprintf(f,catgets(_ttcatd, 6, 11, "Diagnose references to "
174                                   "non-existent entities\n"));
175         }
176         if (_disp_id_p) {
177                 fprintf(f,catgets(_ttcatd, 6, 12, "Display ids\n"));
178         }
179         if (_disp_mand_p) {
180                 fprintf(f,catgets(_ttcatd, 6, 13, "Display mandatory data\n"));
181         }
182         if (_disp_prop_p) {
183                 fprintf(f,catgets(_ttcatd, 6, 14,
184                                   "Display properties and values data\n"));
185         }
186         if (_repair_netisam_p) {
187                 fprintf(f,catgets(_ttcatd, 6, 15,
188                                   "Invoke NetISAM isrepair() function before "
189                                   "inspecting\n"));
190         }
191         if (_repair_type_p) {
192                 fprintf(f,catgets(_ttcatd, 6, 16,
193                                   "Repair by setting to type: %s\n"),
194                         (char *)_repair_type);
195         }       
196         if (_repair_delete_p) {
197                 fprintf(f,catgets(_ttcatd, 6, 17, "Repair by deleting\n"));
198         }
199         fprintf(f,catgets(_ttcatd, 6, 18, "Debugging printout level %d\n"),
200                 _debug_level);
201 }
202
203
204
205