~ubuntu-branches/ubuntu/saucy/gnutls28/saucy

« back to all changes in this revision

Viewing changes to src/libopts/pgusage.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-07-30 21:40:07 UTC
  • mfrom: (14.1.9 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130730214007-9mrd08xo61kla008
Tags: 3.2.3-1ubuntu1
* Sync with Debian (LP: #1068029). Remaining change:
  - Drop gnutls-bin and -doc since we want to use the versions
    in gnutls26 as the defaults instead

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/**
3
3
 * \file pgusage.c
4
4
 *
5
 
 * Time-stamp:      "2012-02-28 19:49:32 bkorb"
6
 
 *
7
5
 *   Automated Options Paged Usage module.
8
6
 *
 
7
 * @addtogroup autoopts
 
8
 * @{
 
9
 */
 
10
/*
9
11
 *  This routine will run run-on options through a pager so the
10
12
 *  user may examine, print or edit them at their leisure.
11
13
 *
12
14
 *  This file is part of AutoOpts, a companion to AutoGen.
13
15
 *  AutoOpts is free software.
14
 
 *  AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
 
16
 *  AutoOpts is Copyright (C) 1992-2013 by Bruce Korb - all rights reserved
15
17
 *
16
18
 *  AutoOpts is available under any one of two licenses.  The license
17
19
 *  in use must be one of these two and the choice is under the control
23
25
 *   The Modified Berkeley Software Distribution License
24
26
 *      See the file "COPYING.mbsd"
25
27
 *
26
 
 *  These files have the following md5sums:
 
28
 *  These files have the following sha256 sums:
27
29
 *
28
 
 *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
29
 
 *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
30
 
 *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
 
30
 *  8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95  COPYING.gplv3
 
31
 *  4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b  COPYING.lgplv3
 
32
 *  13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239  COPYING.mbsd
31
33
 */
32
34
 
33
35
/*=export_func  optionPagedUsage
34
36
 * private:
35
37
 *
36
38
 * what:  Decipher a boolean value
37
 
 * arg:   + tOptions* + pOpts    + program options descriptor +
38
 
 * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
 
39
 * arg:   + tOptions* + opts + program options descriptor +
 
40
 * arg:   + tOptDesc* + od   + the descriptor for this arg +
39
41
 *
40
42
 * doc:
41
43
 *  Run the usage output through a pager.
43
45
 *  This is disabled on platforms without a working fork() function.
44
46
=*/
45
47
void
46
 
optionPagedUsage(tOptions * pOptions, tOptDesc * pOD)
 
48
optionPagedUsage(tOptions * opts, tOptDesc * od)
47
49
{
48
50
#if ! defined(HAVE_WORKING_FORK)
49
 
    if ((pOD->fOptState & OPTST_RESET) != 0)
 
51
    if ((od->fOptState & OPTST_RESET) != 0)
50
52
        return;
51
53
 
52
 
    (*pOptions->pUsageProc)(pOptions, EXIT_SUCCESS);
 
54
    (*opts->pUsageProc)(opts, EXIT_SUCCESS);
53
55
#else
54
56
    static pid_t     my_pid;
55
 
    char zPageUsage[ 1024 ];
 
57
    char fil_name[1024];
56
58
 
57
59
    /*
58
60
     *  IF we are being called after the usage proc is done
62
64
    switch (pagerState) {
63
65
    case PAGER_STATE_INITIAL:
64
66
    {
65
 
        if ((pOD->fOptState & OPTST_RESET) != 0)
 
67
        if ((od->fOptState & OPTST_RESET) != 0)
66
68
            return;
67
69
 
68
70
        my_pid  = getpid();
69
 
        snprintf(zPageUsage, sizeof(zPageUsage), TMP_USAGE_FMT, (tAoUL)my_pid);
70
 
        unlink(zPageUsage);
 
71
        snprintf(fil_name, sizeof(fil_name), TMP_USAGE_FMT,
 
72
                 (unsigned long)my_pid);
 
73
        unlink(fil_name);
71
74
 
72
75
        /*
73
76
         *  Set usage output to this temporary file
74
77
         */
75
 
        option_usage_fp = fopen(zPageUsage, "w" FOPEN_BINARY_FLAG);
 
78
        option_usage_fp = fopen(fil_name, "w" FOPEN_BINARY_FLAG);
76
79
        if (option_usage_fp == NULL)
77
80
            _exit(EXIT_FAILURE);
78
81
 
87
90
         *  The usage procedure will now put the usage information into
88
91
         *  the temporary file we created above.
89
92
         */
90
 
        (*pOptions->pUsageProc)(pOptions, EXIT_SUCCESS);
 
93
        (*opts->pUsageProc)(opts, EXIT_SUCCESS);
91
94
 
92
95
        /* NOTREACHED */
93
96
        _exit(EXIT_FAILURE);
95
98
 
96
99
    case PAGER_STATE_READY:
97
100
    {
98
 
        tCC* pzPager  = (tCC*)getenv(PAGER_NAME);
 
101
        char const * pager  = (char const *)getenv(PAGER_NAME);
99
102
 
100
103
        /*
101
104
         *  Use the "more(1)" program if "PAGER" has not been defined
102
105
         */
103
 
        if (pzPager == NULL)
104
 
            pzPager = MORE_STR;
 
106
        if (pager == NULL)
 
107
            pager = MORE_STR;
105
108
 
106
109
        /*
107
110
         *  Page the file and remove it when done.
108
111
         */
109
 
        snprintf(zPageUsage, sizeof(zPageUsage), PAGE_USAGE_FMT, pzPager,
110
 
                 (tAoUL)my_pid);
 
112
        snprintf(fil_name, sizeof(fil_name), PAGE_USAGE_FMT, pager,
 
113
                 (unsigned long)my_pid);
111
114
        fclose(stderr);
112
115
        dup2(STDOUT_FILENO, STDERR_FILENO);
113
116
 
114
 
        (void)system(zPageUsage);
 
117
        ignore_val( system( fil_name));
115
118
    }
116
119
 
117
120
    case PAGER_STATE_CHILD:
123
126
#endif
124
127
}
125
128
 
126
 
/*
 
129
/** @}
 
130
 *
127
131
 * Local Variables:
128
132
 * mode: C
129
133
 * c-file-style: "stroustrup"