int main(int argc, char **argv) { int res[2], v, numIn; char **in, *out, *blah[3], *option = NULL; int n, *ints, numN; hestOpt *opt = NULL; hestParm *parm; char *err = NULL, info[] = "This program does nothing in particular, though it does attempt " "to pose as some sort of command-line image processing program. " "As usual, any implied functionality is purely coincidental, " "especially since this is the output of a unicyclist."; parm = hestParmNew(); parm->respFileEnable = AIR_TRUE; parm->verbosity = 3; opt = NULL; hestOptAdd(&opt, "v,verbose", "level", airTypeInt, 0, 1, &v, "0", "verbosity level"); hestOptAdd(&opt, "out", "file", airTypeString, 1, 1, &out, "output.ppm", "PPM image output"); hestOptAdd(&opt, "blah", "input", airTypeString, 3, 3, blah, "a b c", "input image file(s)"); hestOptAdd(&opt, "option","opt", airTypeString, 0, 1, &option, "default", "this is just a test"); hestOptAdd(&opt, NULL, "input", airTypeString, 1, -1, &in, NULL, "input image file(s)", &numIn); hestOptAdd(&opt, "ints", "N", airTypeInt, 1, -1, &ints, "10 20 30", "a list of integers", &numN); hestOptAdd(&opt, "res", "sx sy", airTypeInt, 2, 2, res, NULL, "image resolution"); printf("what 0\n"); if (1 == argc) { /* didn't get anything at all on command line */ /* print program information ... */ hestInfo(stderr, argv[0], info, parm); /* ... and usage information ... */ hestUsage(stderr, opt, argv[0], parm); hestGlossary(stderr, opt, parm); /* ... and avoid memory leaks */ opt = hestOptFree(opt); parm = hestParmFree(parm); exit(1); } printf("what 1\n"); /* else we got something, see if we can parse it */ if (hestParse(opt, argc-1, argv+1, &err, parm)) { fprintf(stderr, "ERROR: %s\n", err); free(err); /* print usage information ... */ hestUsage(stderr, opt, argv[0], parm); hestGlossary(stderr, opt, parm); /* ... and then avoid memory leaks */ opt = hestOptFree(opt); parm = hestParmFree(parm); printf(" ---- in = %lx\n", (unsigned long)in); printf(" ---- blah[0] = %lx\n", (unsigned long)(blah[0])); printf(" ---- option = %lx\n", (unsigned long)option); exit(1); } printf("what 2\n"); printf("(err = %s)\n", err ? err : "(null)"); printf(" v = %d\n", v); printf("out = \"%s\"\n", out ? out : "(null)"); printf("blah = \"%s\" \"%s\" \"%s\"\n", blah[0], blah[1], blah[2]); printf("option = \"%s\"\n", option ? option : "(null)"); printf("res = %d %d\n", res[0], res[1]); /* printf(" ---- in = %lx\n", (unsigned long)in); printf(" in = %d files:", numIn); for (n=0; n<=numIn-1; n++) { printf(" \"%s\"", in[n] ? in[n] : "(null)"); } printf("\n"); */ printf(" ints = %d ints:", numN); for (n=0; n<=numN-1; n++) { printf(" %d", ints[n]); } printf("\n"); printf("what 3\n"); /* free the memory allocated by parsing ... */ hestParseFree(opt); /* ... and the other stuff */ opt = hestOptFree(opt); parm = hestParmFree(parm); exit(0); }
int main(int argc, char **argv) { static int res[2], v, numIn; static char **in, *out; static int *mm, mmm; int n; hestOpt opt[] = { {"res", "sx sy", airTypeInt, 2, 2, res, NULL, "image resolution"}, {"v", "level", airTypeInt, 0, 1, &v, NULL /* "0" */, "verbosity level"}, {"VV", "level", airTypeInt, 0, 5, &mm, "33 22 11", "gonzo level", &mmm}, {"out", "file", airTypeString, 1, 1, &out, "output.ppm", "PPM image output"}, {NULL, "input", airTypeString, 1, -1, &in, NULL, "input image file(s)", &numIn}, {NULL, NULL, 0} }; hestParm *parm; char *err = NULL, info[] = "This program does nothing in particular, though it does attempt " "to pose as some sort of command-line image processing program. " "Any implied functionality is purely coincidental, especially since " "this software was written by a sleep-deprived grad student."; parm = hestParmNew(); parm->respFileEnable = AIR_TRUE; if (1 == argc) { /* didn't get anything at all on command line */ hestInfo(stderr, argv[0], info, parm); hestUsage(stderr, opt, argv[0], parm); hestGlossary(stderr, opt, parm); parm = hestParmFree(parm); exit(1); } /* else we got something, see if we can parse it */ if (hestParse(opt, argc-1, argv+1, &err, parm)) { fprintf(stderr, "ERROR: %s\n", err); free(err); hestUsage(stderr, opt, argv[0], parm); hestGlossary(stderr, opt, parm); parm = hestParmFree(parm); exit(1); } printf("(err = %s)\n", err); printf("res = %d %d\n", res[0], res[1]); printf(" v = %d\n", v); printf("out = \"%s\"\n", out); printf(" mm = %d ints:", mmm); for (n=0; n<=mmm-1; n++) { printf(" %d", mm[n]); } printf("\n"); printf(" in = %d files:", numIn); for (n=0; n<=numIn-1; n++) { printf(" \"%s\"", in[n]); } printf("\n"); hestParseFree(opt); parm = hestParmFree(parm); exit(0); }
int unrrdu_envMain(int argc, const char **argv, const char *me, hestParm *hparm) { FILE *out; AIR_UNUSED(argc); AIR_UNUSED(argv); AIR_UNUSED(me); out = stdout; hestInfo(out, me, _unrrdu_envInfoL, hparm); fprintf(out, "\n"); _hestPrintStr(out, 0, 0, hparm->columns, ("Each variable in the listing below starts with the name of " "the environment variable (\"NRRD_...\"), what type of value " "it represents (e.g. \"int\", \"bool\"), what the " "environment variable is currently set to, what the " "corresponding Nrrd global variable is set to, and a " "description of the variable."), AIR_FALSE); fprintf(out, "\n"); _hestPrintStr(out, 0, 0, hparm->columns, ("Bool variables may be set to true simply by setting the " "environment variable; setting the value to \"true\" or " "\"false\" sets the bool accordingly. Enum variables may " "be set by setting the environment variable to any string " "that parses as one of the enum values. Int and unsigned " "int variables are set via a string parse-able as a numeric " "value."), AIR_FALSE); fprintf(out, "\n"); /* UNRRDU_QUIET_QUIT functionality implemented in privateUnrrdu.h */ _hestPrintStr(out, 0, 0, hparm->columns, ("In addition to the the \"NRRD_\" environment variables, " "there is this one, " UNRRDU_QUIET_QUIT_ENV ", which " "determines whether unu exits " "quietly (without error and usage info) when it fails " "because an input nrrd read immediately hit EOF (as " "happens when many unu invocations are piped together). " "This is currently detected by seeing if the error message " "ends with \n \"" UNRRDU_QUIET_QUIT_STR "\"."), AIR_FALSE); fprintf(out, "\n"); fprintf(out, "%s: ", UNRRDU_QUIET_QUIT_ENV); if (getenv(UNRRDU_QUIET_QUIT_ENV)) { fprintf(out, "is set (to what doesn't matter); quiet-quit enabled\n"); } else { fprintf(out, "is NOT set; quiet-quit NOT enabled\n"); } fprintf(out, "\n"); _unrrdu_envBool(out, nrrdEnvVarStateKeyValuePairsPropagate, nrrdStateKeyValuePairsPropagate, "nrrdStateKeyValuePairsPropagate", "When true, key/value pairs are copied from input " "nrrd to output nrrd just like other basic info that hasn't " "just been modified (e.g. type, dimension, block size).", hparm->columns); _unrrdu_envEnum(out, nrrdCenter, nrrdEnvVarDefaultCenter, nrrdDefaultCenter, "nrrdDefaultCenter", "The type of sample centering to use when none has been " "set but one has to be chosen for some operation " "(e.g. resampling).", hparm->columns); _unrrdu_envEnum(out, nrrdEncodingType, nrrdEnvVarDefaultWriteEncodingType, nrrdDefaultWriteEncodingType, "nrrdDefaultWriteEncodingType", "When writing nrrds, what encoding to use. Only " "\"unu save\" affords explicit control of output encoding.", hparm->columns); _unrrdu_envBool(out, nrrdEnvVarStateKindNoop, nrrdStateKindNoop, "nrrdStateKindNoop", "When true, Nrrd makes not even the slightest effort to be " "smart about setting the \"kind\" field of an axis after " "some operation that modified its samples.", hparm->columns); _unrrdu_envInt(out, nrrdEnvVarStateVerboseIO, nrrdStateVerboseIO, "nrrdStateVerboseIO", "The verbosity level of Nrrd input/output operations.", hparm->columns); _unrrdu_envBool(out, nrrdEnvVarStateBlind8BitRange, nrrdStateBlind8BitRange, "nrrdStateBlind8BitRange", "When true, the determined range of 8-bit data will always " "be [0,255] (for uchar) or [-128,127] (for signed char), " "instead of actually looking into the data to find its " "range.", hparm->columns); _unrrdu_envBool(out, nrrdEnvVarDefaultWriteBareText, nrrdDefaultWriteBareText, "nrrdDefaultWriteBareText", "When false, text files used for saving nrrds start with " "comment (\"# ...\") lines containing nrrd fields.", hparm->columns); _unrrdu_envEnum(out, nrrdType, nrrdEnvVarStateMeasureType, nrrdStateMeasureType, "nrrdStateMeasureType", "For measurements (\"unu project\") like sum and product, " "the type of the output result, when one hasn't been " "explicitly requested.", hparm->columns); _unrrdu_envInt(out, nrrdEnvVarStateMeasureModeBins, nrrdStateMeasureModeBins, "nrrdStateMeasureModeBins", "When measuring mode but without a given histogram, how many " "bins to use in the temporary internal histogram.", hparm->columns); _unrrdu_envEnum(out, nrrdType, nrrdEnvVarStateMeasureHistoType, nrrdStateMeasureHistoType, "nrrdStateMeasureHistoType", "Output type for most measurements of histograms, when one " "hasn't been explicitly requested", hparm->columns); _unrrdu_envBool(out, nrrdEnvVarStateAlwaysSetContent, nrrdStateAlwaysSetContent, "nrrdStateAlwaysSetContent", "If true, the output content string is set even when the " "input content string is not set.", hparm->columns); _unrrdu_envBool(out, nrrdEnvVarStateDisableContent, nrrdStateDisableContent, "nrrdStateDisableContent", "If true, output content is never set.", hparm->columns); _unrrdu_envUInt(out, nrrdEnvVarDefaultWriteCharsPerLine, nrrdDefaultWriteCharsPerLine, "nrrdDefaultWriteCharsPerLine", "When using text encoding, maximum # characters allowed " "per line.", hparm->columns); _unrrdu_envUInt(out, nrrdEnvVarDefaultWriteValsPerLine, nrrdDefaultWriteValsPerLine, "nrrdDefaultWriteValsPerLine", "When using text encoding, maximum # values allowed " "per line", hparm->columns); _unrrdu_envBool(out, nrrdEnvVarStateGrayscaleImage3D, nrrdStateGrayscaleImage3D, "nrrdStateGrayscaleImage3D", "If true, reading a 2-D grayscale image results in a " "3-D image with a single sample (size=1) on the first " "(fastest) axis.", hparm->columns); #if 0 /* GLK is ambivalent about the continued existence of these ... */ nrrdGetenvDouble(/**/ &nrrdDefaultKernelParm0, nrrdEnvVarDefaultKernelParm0); nrrdGetenvDouble(/**/ &nrrdDefaultSpacing, nrrdEnvVarDefaultSpacing); #endif /* NOTE: this is an exceptional unu command that doesn't rely on privateUnrrdu.h USAGE() macro; so we determine our own return value */ return 0; }