5 * Time-stamp: "2012-02-28 19:49:32 bkorb"
7 * Automated Options Paged Usage module.
9 * This routine will run run-on options through a pager so the
10 * user may examine, print or edit them at their leisure.
12 * This file is part of AutoOpts, a companion to AutoGen.
13 * AutoOpts is free software.
14 * AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
16 * AutoOpts is available under any one of two licenses. The license
17 * in use must be one of these two and the choice is under the control
18 * of the user of the license.
20 * The GNU Lesser General Public License, version 3 or later
21 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
23 * The Modified Berkeley Software Distribution License
24 * See the file "COPYING.mbsd"
26 * These files have the following md5sums:
28 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
29 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
30 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
33 /*=export_func optionPagedUsage
36 * what: Decipher a boolean value
37 * arg: + tOptions* + pOpts + program options descriptor +
38 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
41 * Run the usage output through a pager.
42 * This is very handy if it is very long.
43 * This is disabled on platforms without a working fork() function.
46 optionPagedUsage(tOptions
* pOptions
, tOptDesc
* pOD
)
48 #if ! defined(HAVE_WORKING_FORK)
49 if ((pOD
->fOptState
& OPTST_RESET
) != 0)
52 (*pOptions
->pUsageProc
)(pOptions
, EXIT_SUCCESS
);
55 char zPageUsage
[ 1024 ];
58 * IF we are being called after the usage proc is done
59 * (and thus has called "exit(2)")
60 * THEN invoke the pager to page through the usage file we created.
63 case PAGER_STATE_INITIAL
:
65 if ((pOD
->fOptState
& OPTST_RESET
) != 0)
69 snprintf(zPageUsage
, sizeof(zPageUsage
), TMP_USAGE_FMT
, (tAoUL
)my_pid
);
73 * Set usage output to this temporary file
75 option_usage_fp
= fopen(zPageUsage
, "w" FOPEN_BINARY_FLAG
);
76 if (option_usage_fp
== NULL
)
79 pagerState
= PAGER_STATE_READY
;
82 * Set up so this routine gets called during the exit logic
84 atexit((void(*)(void))optionPagedUsage
);
87 * The usage procedure will now put the usage information into
88 * the temporary file we created above.
90 (*pOptions
->pUsageProc
)(pOptions
, EXIT_SUCCESS
);
96 case PAGER_STATE_READY
:
98 tCC
* pzPager
= (tCC
*)getenv(PAGER_NAME
);
101 * Use the "more(1)" program if "PAGER" has not been defined
107 * Page the file and remove it when done.
109 snprintf(zPageUsage
, sizeof(zPageUsage
), PAGE_USAGE_FMT
, pzPager
,
112 dup2(STDOUT_FILENO
, STDERR_FILENO
);
114 (void)system(zPageUsage
);
117 case PAGER_STATE_CHILD
:
119 * This is a child process used in creating shell script usage.
129 * c-file-style: "stroustrup"
130 * indent-tabs-mode: nil
132 * end of autoopts/pgusage.c */