genshell.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /* -*- buffer-read-only: t -*- vi: set ro:
  2. *
  3. * DO NOT EDIT THIS FILE (genshell.c)
  4. *
  5. * It has been AutoGen-ed Saturday May 5, 2007 at 12:02:35 PM PDT
  6. * From the definitions genshell.def
  7. * and the template file options
  8. *
  9. * Generated from AutoOpts 29:0:4 templates.
  10. */
  11. /*
  12. * This file was produced by an AutoOpts template. AutoOpts is a
  13. * copyrighted work. This source file is not encumbered by AutoOpts
  14. * licensing, but is provided under the licensing terms chosen by the
  15. * genshellopt author or copyright holder. AutoOpts is licensed under
  16. * the terms of the LGPL. The redistributable library (``libopts'') is
  17. * licensed under the terms of either the LGPL or, at the users discretion,
  18. * the BSD license. See the AutoOpts and/or libopts sources for details.
  19. *
  20. * This source file is copyrighted and licensed under the following terms:
  21. *
  22. * genshellopt copyright 1999-2007 Bruce Korb - all rights reserved
  23. *
  24. * genshellopt is free software; you can redistribute it and/or
  25. * modify it under the terms of the GNU Lesser General Public
  26. * License as published by the Free Software Foundation; either
  27. * version 2.1 of the License, or (at your option) any later version.
  28. *
  29. * genshellopt is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  32. * Lesser General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU Lesser General Public
  35. * License along with genshellopt. If not, write to:
  36. * The Free Software Foundation, Inc.,
  37. * 51 Franklin Street, Fifth Floor
  38. * Boston, MA 02110-1301, USA.
  39. */
  40. #include <limits.h>
  41. #define OPTION_CODE_COMPILE 1
  42. #include "genshell.h"
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. tSCC zCopyright[] =
  47. "genshellopt copyright (c) 1999-2007 Bruce Korb, all rights reserved";
  48. tSCC zCopyrightNotice[] =
  49. "genshellopt is free software; you can redistribute it and/or\n\
  50. modify it under the terms of the GNU Lesser General Public\n\
  51. License as published by the Free Software Foundation; either\n\
  52. version 2.1 of the License, or (at your option) any later version.\n\n\
  53. genshellopt is distributed in the hope that it will be useful,\n\
  54. but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
  55. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n\
  56. Lesser General Public License for more details.\n\n\
  57. You should have received a copy of the GNU Lesser General Public\n\
  58. License along with genshellopt. If not, write to:\n\
  59. \tThe Free Software Foundation, Inc.,\n\
  60. \t51 Franklin Street, Fifth Floor\n\
  61. \tBoston, MA 02110-1301, USA.";
  62. extern tUsageProc genshelloptUsage;
  63. #ifndef NULL
  64. # define NULL 0
  65. #endif
  66. #ifndef EXIT_SUCCESS
  67. # define EXIT_SUCCESS 0
  68. #endif
  69. #ifndef EXIT_FAILURE
  70. # define EXIT_FAILURE 1
  71. #endif
  72. /*
  73. * Script option description:
  74. */
  75. tSCC zScriptText[] =
  76. "Output Script File";
  77. tSCC zScript_NAME[] = "SCRIPT";
  78. tSCC zScript_Name[] = "script";
  79. #define SCRIPT_FLAGS (OPTST_DISABLED \
  80. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  81. /*
  82. * Shell option description:
  83. */
  84. tSCC zShellText[] =
  85. "Shell name (follows \"#!\" magic)";
  86. tSCC zShell_NAME[] = "SHELL";
  87. tSCC zNotShell_Name[] = "no-shell";
  88. tSCC zNotShell_Pfx[] = "no";
  89. #define zShell_Name (zNotShell_Name + 3)
  90. #define SHELL_FLAGS (OPTST_INITENABLED \
  91. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  92. /*
  93. * Help/More_Help/Version option descriptions:
  94. */
  95. tSCC zHelpText[] = "Display usage information and exit";
  96. tSCC zHelp_Name[] = "help";
  97. tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
  98. tSCC zMore_Help_Name[] = "more-help";
  99. tSCC zVersionText[] = "Output version information and exit";
  100. tSCC zVersion_Name[] = "version";
  101. /*
  102. * Declare option callback procedures
  103. */
  104. extern tOptProc
  105. optionPagedUsage, optionPrintVersion;
  106. static tOptProc
  107. doUsageOpt;
  108. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  109. *
  110. * Define the Genshellopt Option Descriptions.
  111. */
  112. static tOptDesc optDesc[ OPTION_CT ] = {
  113. { /* entry idx, value */ 0, VALUE_OPT_SCRIPT,
  114. /* equiv idx, value */ 0, VALUE_OPT_SCRIPT,
  115. /* equivalenced to */ NO_EQUIVALENT,
  116. /* min, max, act ct */ 0, 1, 0,
  117. /* opt state flags */ SCRIPT_FLAGS, 0,
  118. /* last opt argumnt */ { NULL },
  119. /* arg list/cookie */ NULL,
  120. /* must/cannot opts */ NULL, NULL,
  121. /* option proc */ NULL,
  122. /* desc, NAME, name */ zScriptText, zScript_NAME, zScript_Name,
  123. /* disablement strs */ NULL, NULL },
  124. { /* entry idx, value */ 1, VALUE_OPT_SHELL,
  125. /* equiv idx, value */ 1, VALUE_OPT_SHELL,
  126. /* equivalenced to */ NO_EQUIVALENT,
  127. /* min, max, act ct */ 0, 1, 0,
  128. /* opt state flags */ SHELL_FLAGS, 0,
  129. /* last opt argumnt */ { NULL },
  130. /* arg list/cookie */ NULL,
  131. /* must/cannot opts */ NULL, NULL,
  132. /* option proc */ NULL,
  133. /* desc, NAME, name */ zShellText, zShell_NAME, zShell_Name,
  134. /* disablement strs */ zNotShell_Name, zNotShell_Pfx },
  135. #ifdef NO_OPTIONAL_OPT_ARGS
  136. # define VERSION_OPT_FLAGS OPTST_IMM | OPTST_NO_INIT
  137. #else
  138. # define VERSION_OPT_FLAGS OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
  139. OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT
  140. #endif
  141. { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
  142. /* equiv idx value */ NO_EQUIVALENT, 0,
  143. /* equivalenced to */ NO_EQUIVALENT,
  144. /* min, max, act ct */ 0, 1, 0,
  145. /* opt state flags */ VERSION_OPT_FLAGS, 0,
  146. /* last opt argumnt */ { NULL },
  147. /* arg list/cookie */ NULL,
  148. /* must/cannot opts */ NULL, NULL,
  149. /* option proc */ optionPrintVersion,
  150. /* desc, NAME, name */ zVersionText, NULL, zVersion_Name,
  151. /* disablement strs */ NULL, NULL },
  152. #undef VERSION_OPT_FLAGS
  153. { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
  154. /* equiv idx value */ NO_EQUIVALENT, 0,
  155. /* equivalenced to */ NO_EQUIVALENT,
  156. /* min, max, act ct */ 0, 1, 0,
  157. /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
  158. /* last opt argumnt */ { NULL },
  159. /* arg list/cookie */ NULL,
  160. /* must/cannot opts */ NULL, NULL,
  161. /* option proc */ doUsageOpt,
  162. /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
  163. /* disablement strs */ NULL, NULL },
  164. { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
  165. /* equiv idx value */ NO_EQUIVALENT, 0,
  166. /* equivalenced to */ NO_EQUIVALENT,
  167. /* min, max, act ct */ 0, 1, 0,
  168. /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
  169. /* last opt argumnt */ { NULL },
  170. /* arg list/cookie */ NULL,
  171. /* must/cannot opts */ NULL, NULL,
  172. /* option proc */ optionPagedUsage,
  173. /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
  174. /* disablement strs */ NULL, NULL }
  175. };
  176. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  177. *
  178. * Define the Genshellopt Option Environment
  179. */
  180. tSCC zPROGNAME[] = "GENSHELLOPT";
  181. tSCC zUsageTitle[] =
  182. "genshellopt - Generate Shell Option Processing Script - Ver. 1\n\
  183. USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
  184. #define zRcName NULL
  185. #define apzHomeList NULL
  186. tSCC zBugsAddr[] = "autogen-users@lists.sourceforge.net";
  187. tSCC zExplain[] = "\n\
  188. Note that `shell' is only useful if the output file does not already\n\
  189. exist. If it does, then the shell name and optional first argument\n\
  190. will be extracted from the script file.\n";
  191. tSCC zDetail[] = "\n\
  192. If the script file already exists and contains Automated Option Processing\n\
  193. text, the second line of the file through the ending tag will be replaced\n\
  194. by the newly generated text. The first `#!' line will be regenerated.\n";
  195. tSCC zFullVersion[] = GENSHELLOPT_FULL_VERSION;
  196. /* extracted from optcode.tpl near line 408 */
  197. #if defined(ENABLE_NLS)
  198. # define OPTPROC_BASE OPTPROC_TRANSLATE
  199. static tOptionXlateProc translate_option_strings;
  200. #else
  201. # define OPTPROC_BASE OPTPROC_NONE
  202. # define translate_option_strings NULL
  203. #endif /* ENABLE_NLS */
  204. tOptions genshelloptOptions = {
  205. OPTIONS_STRUCT_VERSION,
  206. 0, NULL, /* original argc + argv */
  207. ( OPTPROC_BASE
  208. + OPTPROC_ERRSTOP
  209. + OPTPROC_SHORTOPT
  210. + OPTPROC_LONGOPT
  211. + OPTPROC_NO_REQ_OPT
  212. + OPTPROC_NEGATIONS
  213. + OPTPROC_NO_ARGS ),
  214. 0, NULL, /* current option index, current option */
  215. NULL, NULL, zPROGNAME,
  216. zRcName, zCopyright, zCopyrightNotice,
  217. zFullVersion, apzHomeList, zUsageTitle,
  218. zExplain, zDetail, optDesc,
  219. zBugsAddr, /* address to send bugs to */
  220. NULL, NULL, /* extensions/saved state */
  221. genshelloptUsage, /* usage procedure */
  222. translate_option_strings, /* translation procedure */
  223. /*
  224. * Indexes to special options
  225. */
  226. { INDEX_OPT_MORE_HELP,
  227. 0 /* no option state saving */,
  228. NO_EQUIVALENT /* index of '-#' option */,
  229. NO_EQUIVALENT /* index of default opt */
  230. },
  231. 5 /* full option count */, 2 /* user option count */
  232. };
  233. /*
  234. * Create the static procedure(s) declared above.
  235. */
  236. static void
  237. doUsageOpt(
  238. tOptions* pOptions,
  239. tOptDesc* pOptDesc )
  240. {
  241. USAGE( EXIT_SUCCESS );
  242. }
  243. /* extracted from optcode.tpl near line 514 */
  244. #if ENABLE_NLS
  245. #include <stdio.h>
  246. #include <stdlib.h>
  247. #include <string.h>
  248. #include <unistd.h>
  249. #include <autoopts/usage-txt.h>
  250. static char* AO_gettext( char const* pz );
  251. static void coerce_it(void** s);
  252. static char*
  253. AO_gettext( char const* pz )
  254. {
  255. char* pzRes;
  256. if (pz == NULL)
  257. return NULL;
  258. pzRes = _(pz);
  259. if (pzRes == pz)
  260. return pzRes;
  261. pzRes = strdup( pzRes );
  262. if (pzRes == NULL) {
  263. fputs( _("No memory for duping translated strings\n"), stderr );
  264. exit( EXIT_FAILURE );
  265. }
  266. return pzRes;
  267. }
  268. static void coerce_it(void** s) { *s = AO_gettext(*s); }
  269. #define COERSION(_f) \
  270. coerce_it((void*)&(genshelloptOptions._f))
  271. /*
  272. * This invokes the translation code (e.g. gettext(3)).
  273. */
  274. static void
  275. translate_option_strings( void )
  276. {
  277. /*
  278. * Guard against re-translation. It won't work. The strings will have
  279. * been changed by the first pass through this code. One shot only.
  280. */
  281. if (option_usage_text.field_ct == 0)
  282. return;
  283. /*
  284. * Do the translations. The first pointer follows the field count field.
  285. * The field count field is the size of a pointer.
  286. */
  287. {
  288. char** ppz = (char**)(void*)&(option_usage_text);
  289. int ix = option_usage_text.field_ct;
  290. do {
  291. ppz++;
  292. *ppz = AO_gettext(*ppz);
  293. } while (--ix > 0);
  294. }
  295. option_usage_text.field_ct = 0;
  296. {
  297. tOptDesc* pOD = genshelloptOptions.pOptDesc;
  298. int ix = genshelloptOptions.optCt;
  299. for (;;) {
  300. pOD->pzText = AO_gettext(pOD->pzText);
  301. pOD->pz_NAME = AO_gettext(pOD->pz_NAME);
  302. pOD->pz_Name = AO_gettext(pOD->pz_Name);
  303. pOD->pz_DisableName = AO_gettext(pOD->pz_DisableName);
  304. pOD->pz_DisablePfx = AO_gettext(pOD->pz_DisablePfx);
  305. if (--ix <= 0)
  306. break;
  307. pOD++;
  308. }
  309. }
  310. COERSION(pzCopyright);
  311. COERSION(pzCopyNotice);
  312. COERSION(pzFullVersion);
  313. COERSION(pzUsageTitle);
  314. COERSION(pzExplain);
  315. COERSION(pzDetail);
  316. }
  317. #endif /* ENABLE_NLS */
  318. #ifdef __cplusplus
  319. }
  320. #endif
  321. /* genshell.c ends here */