options.C 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 libraries 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. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include "util/copyright.h"
  39. #if defined(__linux__) || defined(sgi) || defined(CSRG_BASED)
  40. #include <getopt.h>
  41. #endif
  42. #include "dbck.h"
  43. #include "options.h"
  44. #include "util/tt_iostream.h"
  45. #include "util/tt_gettext.h"
  46. Dbck_options::
  47. Dbck_options()
  48. {
  49. _dbdirectories = new _Tt_string_list;
  50. _sel_filename_p = 0;
  51. _sel_filename = (char *) 0;
  52. _sel_objid_p = 0;
  53. _sel_objid_key = (_Tt_db_key *) 0;
  54. _sel_type_p = 0;
  55. _sel_type = (char *) 0;
  56. _diag_badform_p = 0;
  57. _diag_exist_p = 0;
  58. _disp_id_p = 0;
  59. _disp_mand_p = 0;
  60. _disp_prop_p = 0;
  61. _repair_netisam_p = 0;
  62. _repair_type_p = 0;
  63. _repair_type = (char *) 0;
  64. _repair_delete_p = 0;
  65. _debug_level = 0;
  66. }
  67. int Dbck_options::
  68. set_opts(int argc, char **argv)
  69. {
  70. int c;
  71. char *opts = optstring();
  72. while (-1 != (c = getopt(argc,(char **)argv,opts))) {
  73. if (!set_option(c, optarg)) {
  74. //print help
  75. return 0;
  76. }
  77. }
  78. _dbdirectories = new _Tt_string_list;
  79. for (; optind<argc; ++optind) {
  80. _Tt_string s(argv[optind]);
  81. _dbdirectories->append(s);
  82. }
  83. return 1;
  84. }
  85. int Dbck_options::
  86. set_common_option(int optchar, const char *optval)
  87. {
  88. switch (optchar) {
  89. case '?':
  90. case 'h': // treat h as illegal, forces Usage: msg
  91. return 0;
  92. case 'v':
  93. _TT_PRINT_VERSIONS(progname)
  94. exit(0);
  95. case 'd':
  96. _debug_level = atoi(optval);
  97. break;
  98. case 'f':
  99. _sel_filename_p = 1;
  100. _sel_filename = optval;
  101. break;
  102. case 'k':
  103. _sel_objid_p = 1;
  104. _sel_objid_key = new _Tt_db_key(_Tt_string(optval));
  105. break;
  106. case 't':
  107. _sel_type_p = 1;
  108. _sel_type = optval;
  109. break;
  110. case 'b':
  111. _diag_badform_p = 1;
  112. break;
  113. case 'x':
  114. _diag_exist_p = 1;
  115. break;
  116. case 'i':
  117. _disp_id_p = 1;
  118. break;
  119. case 'm':
  120. _disp_mand_p = 1;
  121. break;
  122. case 'p':
  123. _disp_prop_p = 1;
  124. break;
  125. case 'I':
  126. _repair_netisam_p = 1;
  127. break;
  128. case 'T':
  129. _repair_type_p = 1;
  130. _repair_type = optval;
  131. break;
  132. case 'Z':
  133. _repair_delete_p = 1;
  134. break;
  135. default:
  136. return 0;
  137. }
  138. return 1;
  139. }
  140. void Dbck_options::
  141. print(FILE *f) const
  142. {
  143. fprintf(f,"%s <\n",type_string());
  144. fprintf(f,"\nDirectories:\n");
  145. dbdirectories()->print(_tt_string_print,f);
  146. fprintf(f,"\n");
  147. if (_sel_filename_p) {
  148. fprintf(f,catgets(_ttcatd, 6, 7, "Select by filename: %s\n"),
  149. (char *)_sel_filename);
  150. }
  151. if (_sel_objid_p) {
  152. fprintf(f, "%s", catgets(_ttcatd, 6, 8, "Select by objid key:"));
  153. _sel_objid_key->print(f);
  154. fprintf(f,"\n");
  155. }
  156. if (_sel_type_p) {
  157. fprintf(f,catgets(_ttcatd, 6, 9, "Select by type: %s\n"),
  158. (char *)_sel_type);
  159. }
  160. if (_diag_badform_p) {
  161. fprintf(f, "%s", catgets(_ttcatd, 6, 10,
  162. "Diagnose badly formed entities\n"));
  163. }
  164. if (_diag_exist_p) {
  165. fprintf(f, "%s", catgets(_ttcatd, 6, 11, "Diagnose references to "
  166. "non-existent entities\n"));
  167. }
  168. if (_disp_id_p) {
  169. fprintf(f, "%s", catgets(_ttcatd, 6, 12, "Display ids\n"));
  170. }
  171. if (_disp_mand_p) {
  172. fprintf(f, "%s", catgets(_ttcatd, 6, 13, "Display mandatory data\n"));
  173. }
  174. if (_disp_prop_p) {
  175. fprintf(f, "%s", catgets(_ttcatd, 6, 14,
  176. "Display properties and values data\n"));
  177. }
  178. if (_repair_netisam_p) {
  179. fprintf(f, "%s", catgets(_ttcatd, 6, 15,
  180. "Invoke NetISAM isrepair() function before "
  181. "inspecting\n"));
  182. }
  183. if (_repair_type_p) {
  184. fprintf(f,catgets(_ttcatd, 6, 16,
  185. "Repair by setting to type: %s\n"),
  186. (char *)_repair_type);
  187. }
  188. if (_repair_delete_p) {
  189. fprintf(f, "%s", catgets(_ttcatd, 6, 17, "Repair by deleting\n"));
  190. }
  191. fprintf(f,catgets(_ttcatd, 6, 18, "Debugging printout level %d\n"),
  192. _debug_level);
  193. }