1
0

genshell.c 11 KB

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