genshell.c 12 KB

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