about summary refs log tree commit diff
path: root/generator/ppmcolors.c
blob: ecbadf72d4b25d3109b7b15d4c73d8beb0d19a0e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/******************************************************************************
                                ppmcolors
*******************************************************************************
  Generate a color map containing all the colors representable with a certain
  maxval.

  THIS PROGRAM IS OBSOLETE.  USE PAMSEQ INSTEAD.  WE KEEP THIS AROUND
  FOR BACKWARD COMPATIBILITY.

******************************************************************************/

#include "pm_c_util.h"
#include "ppm.h"
#include "shhopt.h"
#include "nstring.h"

struct cmdlineInfo {
    /* All the information the user supplied in the command line,
       in a form easy for the program to use.
    */
    unsigned int maxval;
};



static void
parseCommandLine(int argc, char ** argv, struct cmdlineInfo *cmdlineP) {
/*----------------------------------------------------------------------------
   Note that the file spec array we return is stored in the storage that
   was passed to us as the argv array.
-----------------------------------------------------------------------------*/
    optStruct3 opt;  /* set by OPTENT3 */
    optEntry *option_def = malloc(100*sizeof(optEntry));
    unsigned int option_def_index;

    option_def_index = 0;   /* incremented by OPTENT3 */
    OPTENT3(0,   "maxval",       OPT_UINT,
            &cmdlineP->maxval,  NULL, 0);


    opt.opt_table = option_def;
    opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
    opt.allowNegNum = FALSE;  /* We may have parms that are negative numbers */

    /* defaults */
    cmdlineP->maxval = 5;

    pm_optParseOptions3(&argc, argv, opt, sizeof(opt), 0);
        /* Uses and sets argc, argv, and some of *cmdlineP and others. */

    if (cmdlineP->maxval < 1)
        pm_error("-maxval must be at least 1");
    else if (cmdlineP->maxval > PPM_OVERALLMAXVAL)
        pm_error("-maxval too high.  The maximum allowable value is %u",
                 PPM_OVERALLMAXVAL);

    if (argc-1 > 0)
        pm_error("This program takes no arguments.  You specified %d",
                 argc-1);
}



int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;
    const char * cmd;   /* malloc'ed */
    int rc;

    ppm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    pm_asprintf(&cmd, "pamseq 3 %u -tupletype=RGB | pamtopnm", cmdline.maxval);

    rc = system(cmd);

    if (rc != 0)
        pm_error("pamseq|pamtopnm pipeline failed.  system() rc = %d", rc);

    pm_strfree(cmd);

    return rc;
}