1
0

genshell.c 9.8 KB

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