home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume19 / xodometr / part03 < prev    next >
Encoding:
Text File  |  1993-04-27  |  35.0 KB  |  895 lines

  1. Newsgroups: comp.sources.x
  2. From: lusol@Turkey.CC.Lehigh.EDU (Stephen O. Lidie)
  3. Subject: v19i039:  xodometer - Track pointer and measure distance moved, Part03/04
  4. Message-ID: <1993Mar11.161628.17444@sparky.imd.sterling.com>
  5. X-Md4-Signature: 2886fc330ffa9651aee3add14b9f7154
  6. Date: Thu, 11 Mar 1993 16:16:28 GMT
  7. Approved: chris@sparky.imd.sterling.com
  8.  
  9. Submitted-by: lusol@Turkey.CC.Lehigh.EDU (Stephen O. Lidie)
  10. Posting-number: Volume 19, Issue 39
  11. Archive-name: xodometer/part03
  12. Environment: X11
  13.  
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 3 (of 4)."
  22. # Contents:  evap/evap.h
  23. # Wrapped by lusol@Turkey.CC.Lehigh.EDU on Wed Mar 10 19:42:13 1993
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'evap/evap.h' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'evap/evap.h'\"
  27. else
  28. echo shar: Extracting \"'evap/evap.h'\" \(32868 characters\)
  29. sed "s/^X//" >'evap/evap.h' <<'END_OF_FILE'
  30. X/*
  31. X
  32. X  evap.h - header file for evaluate_parameters (PDT Version 1.2)
  33. X
  34. X  Copyright (C) 1990 - 1993 by Lehigh University.  All rights reserved.
  35. X
  36. X
  37. X                               Table of Contents
  38. X
  39. X  Revision History
  40. X  Introduction
  41. X  PDT Syntax
  42. X  Creating a PDT
  43. X  Usage Notes
  44. X  Separately Compiled Modules
  45. X  Further Information on Types
  46. X  Special Default Value $required
  47. X  Using Environment Variables as Default Values
  48. X  Customization of the PDT Structure
  49. X  Interface to X11 Release 4 XGetDefault
  50. X  Human Interface Guidlines
  51. X  Installation
  52. X  Display Command Information
  53. X  Adding New Message Modules
  54. X  Notes and Cautions
  55. X  Acknowledgment
  56. X
  57. X
  58. X                               Revision History                            
  59. X
  60. X  Stephen.O.Lidie@CDC1.CC.Lehigh.EDU, LUCC, 90/12/28. (PDT version 1.0)
  61. X    . Original release - evaluate_parameters and generate_pdt.
  62. X
  63. X  Stephen.O.Lidie@CDC1.CC.Lehigh.EDU, LUCC, 91/07/01. (PDT version 1.1)
  64. X    . Minor bug fixes in generate_pdt.
  65. X    . Add support for the name type.
  66. X    . Add the new command display_command_information (disci).
  67. X    . Add support for help message modules.
  68. X    . Add the new command add_message_modules (addmm).
  69. X    . Minor bug fix in evaluate_parameters handling of key type.
  70. X    . Improve evaluate_parameters error messages.
  71. X    . Provide an install script for VX/VE, EP/IX, SunOS, Stardent and AIX.
  72. X    . Add support for PDTEND file_list option.
  73. X    . Add -qualifier parameter to generate_pdt so that the PDT/PVT names
  74. X      can be qualified for 'multiple entry point' programs.  Similar to
  75. X      COMPASS QUAL blocks.
  76. X
  77. X   Stephen.O.Lidie@CDC1.CC.Lehigh.EDU, LUCC, 91/08/01. (PDT version 1.1)
  78. X    . Allow -- to end command line parameters.
  79. X    . Don't print the colon after the type for disci; generate_pdt supplies
  80. X      it for us.  This allows the description to be better customized.
  81. X    . When type-checking keywords, first search for an exact match (as is
  82. X      currently done) and if that fails, search for a substring match.
  83. X    . In a similar manner, when the exact match for a command line parameter
  84. X      fails, try a substring match (but not for the alias).
  85. X    . If the evaluate_parameters message module is missing, generate a short
  86. X      Usage: display.
  87. X    . If no parameter alias, use the full spelling for Usage: and -help.
  88. X
  89. X   Stephen.O.Lidie@CDC1.CC.Lehigh.EDU, LUCC, 91/12/02. (PDT version 1.2)
  90. X    . Do the 'which' function internally rather than using slow system.
  91. X    . exec the ar command to display the message module rather than
  92. X      using slow system.
  93. X    . If an environment variable is specified as a default value for a
  94. X      parameter, the variable is defined and the parameter is not 
  95. X      specified, use the value of the environment variable for the
  96. X      parameter's value.
  97. X  lusol@Lehigh.EDU 93/01/02. (PDT version 1.2)  Version 1.4
  98. X    . Evaluate parameter values within grave accents, or
  99. X      backticks.  Add -usage_help to display_command_information.
  100. X      Add support for parameter descriptions in the message module
  101. X      file for -full_help.
  102. X  lusol@Lehigh.EDU 93/02/19. (PDT version 1.2)  Version 1.5
  103. X    . Document the interface to X11 Release 4 XGetDefault.
  104. X    . For parameters of type File expand $HOME and ~.
  105. X    . Make evap.c more ANSI-like - define function prototypes and use returns
  106. X      consistently.
  107. X    . Make evap.h more ANSI-like - replace the #if .. #endif surrounding the 
  108. X      evaluate_parameters documentation with a C comment construct.  However,
  109. X      all the C comments embedded in the sample code are now PASCAL comments
  110. X      of the form {* ... *}.  Ugh, but that's the price I had to pay to make
  111. X      the code portable!
  112. X  
  113. X
  114. X
  115. X                                 Introduction
  116. X
  117. X  Function evaluate_parameters parses a U*X command line in a simple and
  118. X  consistent manner, performs type checking of parameter values, and provides
  119. X  the user with first-level help.  evaluate_parameters handles command lines
  120. X  in the following format:
  121. X
  122. X    command [-parameters] [file_list]
  123. X
  124. X  where parameters and file_list are all optional.  A typical example is the
  125. X  C compiler:
  126. X
  127. X    cc -O -o chunk chunk.c
  128. X
  129. X  In this case there are two parameters and a file_list consisting of a
  130. X  single file name for the cc command.
  131. X
  132. X  There are several advantages to using evaluate_parameters in all your C
  133. X  programs:
  134. X
  135. X    - Every program calling evaluate_parameters has a -help switch which
  136. X      lists all the command line arguments and their aliases, the types
  137. X      of parameter values they expect, and their default values.  Many U*X
  138. X      commands have no man pages so this first-level help is the only help
  139. X      available to a user.  This is provided automatically as part of
  140. X      evaluate_parameters; no code is required in your application.  
  141. X
  142. X      An optional help message module can be defined to provide additional
  143. X      help.  (See the section Adding New Message Modules.)
  144. X
  145. X    - The command display_command_information is available which emulates its
  146. X      NOS/VE counterpart.  This command displays information about any command
  147. X      using evaluate_parameters.
  148. X
  149. X    - Because evaluate_parameters allows command line arguments to have an
  150. X      alias, parameters can be given meaningful names which a user can readily
  151. X      understand.  Hackers, on the other hand, can use the abbreviation to
  152. X      speed their work.
  153. X
  154. X    - evaluate_parameters verifies that the value specified for a command
  155. X      line argument is of the appropriate type. Types currently supported are
  156. X      switch, string, real, integer, boolean, file, key, application and name.
  157. X      Parameter values are available in two forms; unconverted C strings and
  158. X      type-converted values.
  159. X
  160. X    - Your job of developing applications is simplified because you don't
  161. X      waste time writing code to process arguments again, and again, and again!
  162. X
  163. X    - Automatic man page generation for programs calling evaluate_parameters.
  164. X
  165. X    - New versions of evaluate_parameters will guarantee backward compatability
  166. X      with previous versions until the Universe ends.
  167. X
  168. X    - Most importantly, as long as you adhere to the Human Interface Guidlines,
  169. X      evaluate_parameters provides for a consistent user interface.
  170. X
  171. X  Using evaluate_parameters is extremely easy:
  172. X
  173. X    1) Create a Parameter Description Table, analogous to a C function
  174. X       prototype, which names all command line arguments and their types.
  175. X       Additionally, a PDT specifies the parameter alias and a default value.
  176. X       (Optionally, a help message module can be defined which names a text
  177. X       file of additional help information.  See Adding New Message Modules
  178. X       for more information.)
  179. X
  180. X    2) Feed the PDT to program generate_pdt, which generates a C structure
  181. X       that can be #included into your application.  This structure, known
  182. X       as a Parameter Description Table (PDT) assists evaluate_parameters in
  183. X       parsing the command line.
  184. X
  185. X    3) Call evaluate_parameters in function main.  Command line parameters
  186. X       are scanned and their values are stored in the PDT for later use.
  187. X
  188. X    4) (Optionally, add a help message module to the message module archive
  189. X       file.  See Adding New Message Modules for more details.)
  190. X
  191. X  Examine addmm.c for an extremely simple example of using evaluate_parameters.
  192. X
  193. X
  194. X                                 PDT Syntax
  195. X
  196. X  Here is the PDT syntax.  Optional constructs are enclosed in [], and the
  197. X  | character separates possible values in a list.
  198. X
  199. X    PDT [(message_module_name.mm)] [program_name, program_alias]
  200. X      [parameter_name[, parameter_alias]: parameter_type [ = default_value]]
  201. X    PDTEND [optional_file_list | required_file_list | no_file_list]
  202. X
  203. X  So, the simplest possible PDT would be:
  204. X
  205. X    PDT
  206. X    PDTEND
  207. X
  208. X  This PDT would simply define a -help switch for the command, but is rather
  209. X  useless. 
  210. X
  211. X  A typical PDT would look more like this:
  212. X
  213. X    PDT (frog.mm) frog
  214. X      number, n: integer = 1
  215. X    PDTEND no_file_list
  216. X
  217. X  This PDT, for command frog, defines a help message module frog.mm and a
  218. X  single parameter, number (or n), of type integer with a default value of 1.
  219. X  The PDTEND no_file_list indicator indicates that no trailing file_list
  220. X  can appear on the command line.  Of course, the -help switch is defined
  221. X  automatically.
  222. X
  223. X  The default_value can also be an environment variable - see the section
  224. X  Using Environment Variables as Default Values for complete details.
  225. X
  226. X
  227. X                                Creating a PDT
  228. X
  229. X  evaluate_parameters requires a Parameter Description Table (PDT) to guide it
  230. X  in parsing the command line.  The program generate_pdt interprets a
  231. X  Parameter Description Table (PDT) and generates C statements that declare
  232. X  and initialize the PDT.  Here is generate_pdt's PDT; it declares -input (or
  233. X  -i) and -output (or -o) parameters, of type file, and that default to
  234. X  standard input and standard output, respectively.  The -qualifier (or -q)
  235. X  parameter, of type string, defaults to an empty string.
  236. X
  237. X    PDT (genpdt.mm) generate_pdt, genpdt
  238. X      input, i: file = stdin
  239. X      output, o: file = stdout
  240. X      qualifier, q: string = ""
  241. X    PDTEND no_file_list
  242. X
  243. X  A PDT for the 'mini' C compiler example described in the Introduction could
  244. X  be:
  245. X
  246. X    PDT cc
  247. X      Optimize, O: switch
  248. X      object, o: file
  249. X    PDTEND optional_file_list
  250. X
  251. X  The PDT says that the Optimize parameter can have no parameter value; that
  252. X  is, it must stand alone.  The object parameter is of type file.  An
  253. X  optional file_list can follow the command line parameters.
  254. X
  255. X  If cc used evaluate_parameters with this PDT a user could envoke the
  256. X  compiler in various ways, some of which are more obvious than others (of
  257. X  course, the command line parameters could be specified in any order):
  258. X
  259. X    cc -Optimize -object chunk chunk.c
  260. X    cc -Optimize -o chunk chunk.c
  261. X    cc -O -object chunk chunk.c
  262. X    cc -O -o chunk chunk.c
  263. X
  264. X  A special -help (or -disci) parameter is automatically generated.  Executing
  265. X  any command that uses evaluate_parameters and specifying the -help option
  266. X  produces a display of all command line arguments for that command, similar
  267. X  to NOS/VE's DISPLAY_COMMAND_INFORMATION.  Continuing our cc example, the
  268. X  following command:
  269. X
  270. X    cc -help
  271. X
  272. X  would produce this first-level help display:
  273. X
  274. X    Name:  cc
  275. X
  276. X    Parameters:
  277. X
  278. X    -help, disci: Display Command Information
  279. X    -Optimize, O: switch
  280. X    -object, o: file
  281. X
  282. X     [file(s)] optionally required by this command
  283. X
  284. X  The first line of a Parameter Description Table declaration must be PDT (or
  285. X  pdt) and the last line must be PDTEND (or pdtend).  Everything in between
  286. X  defines one or more command line arguments, one per line.  The synatx is
  287. X  similar to CYBIL, Pascal and C function headers:  a parameter name followed
  288. X  by an optional alias, a colon followed by the type of parameter (switch,
  289. X  string, real, integer, boolean, file, key, application, name) and an equal
  290. X  sign followed by the parameter's default value.
  291. X
  292. X  With this information evaluate_parameters can parse a command line in a
  293. X  consistent manner, perform type checking, and provide first-level help via
  294. X  the -help parameter, similar to NOS/VE's System Command Language.
  295. X
  296. X  Here are examples of all the supported types:
  297. X
  298. X    PDT beam
  299. X      verbose, v: switch
  300. X      command, c: string = "ps -el"
  301. X      scale_factor, sf: real = 1.23408900023456e-1
  302. X      millisecond_update_interval, mui: integer = 500
  303. X      ignore_output_file_column_one, iofco: boolean = TRUE
  304. X      output, o: file = stdout
  305. X      queue, q: key plotter, postscript, text, printer, keyend = printer
  306. X      destination, d: application = `hostname`
  307. X      tty, t: name = /dev/console
  308. X    PDTEND optional_file_list
  309. X
  310. X
  311. X                                 Usage Notes
  312. X
  313. X  Here are two sample main programs that simply print the envoking command's
  314. X  name, command line arguments as described by the PDT, and all file names.
  315. X  They are essentially identical, although the first uses the array approach
  316. X  and prints the unconverted values (stored as C strings), while the second
  317. X  uses pointers and prints the converted values (stored as a type appropriate
  318. X  for the parameter).  These programs are patterned after the examples in K&R,
  319. X  page 115, second edition.  There are a few items worth noting in each:
  320. X
  321. X    1) The first executable statement in your C application must be a call
  322. X       to evaluate_parameters.
  323. X
  324. X                                    NOTE
  325. X
  326. X            Because of variations in U*X implementations, the actual
  327. X            name of evaluate_parameters is evap.  This unobvious name
  328. X            was chosen simply because it was short enough to prevent
  329. X            problems with C compilers, loaders and archive programs.
  330. X            The real name, evaluate_parameters, will continue to be
  331. X            used everywhere except in actual examples.
  332. X
  333. X    2) evaluate_parameters increments argv and decrements argc as it parses
  334. X       the command line, leaving argv pointing to just before the file
  335. X       names (if any).  The net result is that argc will be >= 1.  If it is
  336. X       one, there are no trailing file names.  This is analogous to the
  337. X       situation where a command, not using evaluate_parameters, is envoked
  338. X       with no parameters; argc = 1 and argv simply points to the envoking
  339. X       program's name.
  340. X
  341. X    3) Parameter values are stored in the Parameter Value Table structure
  342. X       (pvt) in a format appropriate for the type (string for string, long
  343. X       double for real, int for integer, short for boolean, etcetera).  The
  344. X       unconverted parameter value is also available as a C string.
  345. X
  346. X    4) Because of item #2 above, the name of the program in argv[0] is no
  347. X       longer available.  Therefore, evaluate_parameters stores it in the PDT
  348. X       structure pvt[P_HELP].unconverted_value just in case you need it.
  349. X
  350. X  Assume that the file beam_pdt_in contains the PDT described at the end of
  351. X  the section Creating a PDT.  First use the command generate_pdt to convert
  352. X  the file beam_pdt_in into a C structure declaration for use by your
  353. X  application and evaluate_parameters:
  354. X
  355. X      generate_pdt -input beam_pdt_in -output beam_pdt_out
  356. X
  357. X  The resulting PDT declaration on file beam_pdt_out can be included in main:
  358. X
  359. X  Sample main using arrays:
  360. X
  361. X    #include <evap.h>
  362. X    #include "beam_pdt_out"
  363. X
  364. X    main (argc, argv)
  365. X          int argc;
  366. X          char *argv[];
  367. X
  368. X    {* evaluate_parameters, array version, unconverted values. *}
  369. X
  370. X    {
  371. X      int i;
  372. X
  373. X      evap (&argc, &argv, pdt, NULL, pvt);
  374. X      printf("\nProgram name:\n  %s\n", pvt[P_HELP].unconverted_value);
  375. X
  376. X      if (P_NUMBER_OF_PARAMETERS > 1 ) {
  377. X        printf("\nCommand line parameters and values:\n");
  378. X        for (i=1; i < P_NUMBER_OF_PARAMETERS; i++)
  379. X          printf("  Parameter %s=\"%s\"\n", pvt[i].parameter,
  380. X                pvt[i].unconverted_value);
  381. X      }
  382. X
  383. X      if (argc > 1) {
  384. X        printf("\nFile names:\n  ");
  385. X        for(i=1; i < argc; i++)
  386. X          printf("%s%s", argv[i], (i < argc-1) ? " " : "");
  387. X        printf("\n");
  388. X      }
  389. X    } {* end main *}
  390. X
  391. X
  392. X  Sample main using pointers:
  393. X
  394. X    #include <evap.h>
  395. X    #include "beam_pdt_out"
  396. X
  397. X    main (argc, argv)
  398. X          int argc;
  399. X          char *argv[];
  400. X
  401. X    {* evaluate_parameters, pointer version, type-converted values. *}
  402. X
  403. X    {
  404. X      Parameter_Value *pvte; {* parameter value table entry *}
  405. X
  406. X      evap (&argc, &argv, pdt, NULL, pvt);
  407. X      printf("\nProgram name:\n  %s\n", pvt[P_HELP].unconverted_value);
  408. X
  409. X      if (P_NUMBER_OF_PARAMETERS > 1) {
  410. X        printf("\nCommand parameters and values:\n");
  411. X        pvte = &pvt[1];
  412. X        while (pvte->parameter != NULL) {
  413. X          switch (pvte->type) {
  414. X
  415. X          case P_TYPE_SWITCH:
  416. X            printf("  switch      parameter %s=%d\n", pvte->parameter,
  417. X                  pvte->value.switch_value);
  418. X            break;
  419. X
  420. X          case P_TYPE_STRING:
  421. X            printf("  string      parameter %s=\"%s\"\n", pvte->parameter,
  422. X                  pvte->value.string_value);
  423. X            break;
  424. X
  425. X          case P_TYPE_REAL:
  426. X            printf("  real        parameter %s=%.15lg\n", pvte->parameter,
  427. X                  pvte->value.real_value);
  428. X            break;
  429. X
  430. X          case P_TYPE_INTEGER:
  431. X            printf("  integer     parameter %s=%d\n", pvte->parameter,
  432. X                  pvte->value.integer_value);
  433. X            break;
  434. X
  435. X          case P_TYPE_BOOLEAN:
  436. X            printf("  boolean     parameter %s=%d\n", pvte->parameter,
  437. X                  pvte->value.boolean_value);
  438. X            break;
  439. X
  440. X          case P_TYPE_FILE:
  441. X            printf("  file        parameter %s=\"%s\"\n", pvte->parameter,
  442. X                  pvte->value.file_value);
  443. X            break;
  444. X
  445. X          case P_TYPE_KEY:
  446. X            printf("  key         parameter %s=\"%s\"\n", pvte->parameter,
  447. X                  pvte->value.key_value);
  448. X            break;
  449. X
  450. X          case P_TYPE_APPLICATION:
  451. X            printf("  application parameter %s=\"%s\"\n", pvte->parameter,
  452. X                  pvte->value.application_value);
  453. X            break;
  454. X
  455. X          case P_TYPE_NAME:
  456. X            printf("  name        parameter %s=\"%s\"\n", pvte->parameter,
  457. X                  pvte->value.name_value);
  458. X            break;
  459. X
  460. X          default:
  461. X            printf("Error!  Murphy says 'Plugh'!\n");
  462. X            break;
  463. X          } {* casend *}
  464. X
  465. X          pvte++; {* next parameter value table entry *}
  466. X
  467. X        } {* whilend *}
  468. X      }
  469. X
  470. X      if (argc > 1) {
  471. X        printf("\nFile names:\n  ");
  472. X          while (*++argv != NULL)
  473. X            printf("%s%s",*argv, (*argv != NULL) ? " " : "");
  474. X        printf("\n");
  475. X      }
  476. X    } {* end main *}
  477. X
  478. X
  479. X  Parameter names and their aliases can be at most 31 characters long.
  480. X
  481. X  The values for parameters are stored in a format appropriate for their type.
  482. X  Please examine the pvt structure (below) for complete details.  Parameter
  483. X  values are also available, as a C string, exactly as they appeared on the
  484. X  command line.
  485. X
  486. X  Each parameter has a structure of type parameter_value, which is defined
  487. X  below.  All the parameter structures are grouped together in a Parameter
  488. X  Value Table array named pvt, which is an array of elements of type
  489. X  parameter_value.  An application indexes into the pvt array using a defined
  490. X  symbol of the form P_FULL_PARAMETER_NAME.  So, to access the parameter_value
  491. X  structure for the scale_factor, references of the following form would be
  492. X  used:
  493. X
  494. X    sf = pvt[P_SCALE_FACTOR].value.real_value; {* get long double value *}
  495. X
  496. X  After calling evaluate_parameters, a program accesses the PDT structure for
  497. X  information on what parameters were specified and their values.  To
  498. X  determine if the verbose switch in the example above was specified code such
  499. X  as the following could be used:
  500. X
  501. X    if(pvt[P_VERBOSE].specified)
  502. X        ... do verbose stuff ...
  503. X    else
  504. X        ... do quiet stuff ...
  505. X
  506. X  Of course, there are numerous examples of PDT code in the C source files
  507. X  genpdt.c, disci.c and addmm.c.
  508. X
  509. X
  510. X                          Separately Compiled Modules
  511. X
  512. X  evaluate_parameters can be used when you compile C functions separately from
  513. X  main.  Include <evap.h> as usual and include the PDT structure created by
  514. X  generate_pdt too.  Define the symbol P_EVAP_EXTERN somewhere before the
  515. X  include for the PDT structure.  This will declare the Parameter Value Table
  516. X  (pvt) as an external and will not allocate storage.  For example:
  517. X
  518. X    #include <evap.h>
  519. X    #define P_EVAP_EXTERN
  520. X    #include "beam_pdt_out"
  521. X
  522. X    void test_func()
  523. X    {
  524. X      printf("Program name is %s\n", pvt[P_HELP].unconverted_value);
  525. X    }
  526. X
  527. X
  528. X                         Further Information on Types
  529. X
  530. X  The switch type is a special type that emulates the typical U*X standalone
  531. X  switch.  It means that no parameter value can appear after the switch.
  532. X  evaluate_parameters treats this type similarly to a boolean type:  the value
  533. X  in the PDT structure is initialized to FALSE, and if the switch parameter is
  534. X  specified the value is reset to TRUE.  You can therefore use either of the
  535. X  structure members specified or value to test if the parameter was specified
  536. X  on the command line.  The switch type is short int.
  537. X
  538. X  The string type is simply a C string.
  539. X
  540. X  The real type is a floating point number.  Currently, there is no type
  541. X  checking for this type.  A real number on my machine (a CYBER) ranges from
  542. X  -5.221944407065762533458763552E+1232 to 5.221944407065762533458763552E+1232.
  543. X  The real type is long double.
  544. X
  545. X  The integer type is an integer number.  Range is -9223372036854775808 to
  546. X  9223372036854775807, at least on real machines :-).  The integer type is
  547. X  int.
  548. X
  549. X  The boolean type is either TRUE or FALSE.  The boolean type is short int.
  550. X
  551. X  The file type is a standard U*X file name, which as far as I can tell can be
  552. X  any random string of characters, as long as its length is less than 256.
  553. X  Here is sample C code to process the output file defined previously (o is a
  554. X  variable of type FILE *):
  555. X
  556. X    if (pvt[P_OUTPUT].specified) {
  557. X      if ((o=fopen(pvt[P_OUTPUT].value.file_value, "w")) == NULL) {
  558. X        printf("Cannot open output file!\n");
  559. X        exit(1);
  560. X      }
  561. X    } else  {* just use standard output *}
  562. X      o = stdout;
  563. X
  564. X  The key type is a special type that enumerates valid values.  The queue
  565. X  parameter in a previous example above only recognizes the values plotter,
  566. X  postscript, text, and printer.  evaluate_parameters will not accept other
  567. X  values for this parameter.  Currently, a maximum of 32 values can be
  568. X  specified.  The key type is a C string.
  569. X
  570. X  The applicaton type is a special type that is not type checked because its
  571. X  interpretation is application specific.  This means that anything can be
  572. X  specified for this type of parameter.
  573. X
  574. X  The name type is a string of characters without imbedded spaces.  It is just
  575. X  like a string except that it can be specified without the bounding quotes.
  576. X  If you require a parameter that may included imbedded spaces use a string.
  577. X
  578. X
  579. X                        Special Default Value $required
  580. X
  581. X  All parameters can have a special default value $required.  When this
  582. X  default is specified, evaluate_parameters will ensure that the parameter is
  583. X  specified and given a valid value.
  584. X
  585. X
  586. X                  Using Environment Variables as Default Values
  587. X
  588. X  Consider the following PDT:
  589. X
  590. X    PDT (frog.mm) frog
  591. X      number, n: integer = D_FROG_NUMBER, 1
  592. X    PDTEND no_file_list
  593. X
  594. X  The integer parameter number (or n) has a default value of 1.  However,
  595. X  if the environment variable D_FROG_NUMBER is defined AND if number is
  596. X  not specified on the command line, evaluate_parameters will use the value
  597. X  of the environment variable as the parameter's default value.  With this
  598. X  feature users can easily customize command parameters to their liking.
  599. X
  600. X  Although the name of the environment variable can be whatever you choose,
  601. X  the following scheme is suggested for consistency and to avoid conflicts
  602. X  in names:  
  603. X
  604. X    . Use all uppercase characters.
  605. X    . Begin the variable name with D_, to suggest a default variable.
  606. X    . Continue with the name of the command followed by an underscore.
  607. X    . Complete the variable name with the name of the parameter or its
  608. X      alias.
  609. X
  610. X  So, for example, D_DISCI_DO would name a default variable for the
  611. X  display_option (do) parameter of the display_command_information
  612. X  (disci) command.
  613. X
  614. X
  615. X                       Customization of the PDT Structure
  616. X
  617. X  The PDT structure parameter_value is defined below, and, although
  618. X  initialized by generate_pdt, can be customized in the following ways:
  619. X
  620. X    . You can change the description as displayed by -help.
  621. X    . You can change the changeable member to -1 so that a parameter is
  622. X      not advertised in response to a -help, although it can still be
  623. X      changed by the user, similar to the NOS/VE HIDDEN attribute.
  624. X
  625. X
  626. X                     Interface to X11 Release 4 XGetDefault
  627. X
  628. X  For X11 applications call evaluate_parameters as usual then open the X
  629. X  display.  You can then use code similar to the following to establish
  630. X  default X values for all unspecified command line parameters:
  631. X
  632. X  {*
  633. X     For all unspecified parameters see if there is an X default value. 
  634. X     Variable "i" is type integer and "X_default" is type char *.       
  635. X  *}
  636. X
  637. X  for ( i = 0 ; i < P_NUMBER_OF_PARAMETERS; i++ ) {
  638. X    if ( ! pvt[i].specified ) {
  639. X      X_default = XGetDefault( theDisplay, ProgramName, pvt[i].parameter );
  640. X      if ( X_default != NULL ) {
  641. X        pvt[i].unconverted_value = X_default;
  642. X        evap_type_conversion( &pvt[i] ); {* convert string to proper type *}
  643. X      } {* ifend non-null X default for this parameter *}
  644. X    } {* ifend unspecified parameter *}
  645. X  } {* forend all evaluate_parameters parameters *}
  646. X
  647. X
  648. X
  649. X                           Human Interface Guidlines
  650. X
  651. X  To make evaluate_parameters successful, you, the application developer, must
  652. X  follow certain conventions when choosing parameter names and aliases.
  653. X
  654. X  Parameter names consist of one or more words, separated by underscores, and
  655. X  describe the parameter (for example, OUTPUT and TERMINAL_MODEL).
  656. X
  657. X  You can abbreviate parameters:  use the first letter of each word in the
  658. X  parameter name.  Do not use underscores.  For example, you can abbreviate
  659. X  Command as C and Delay_Period as DP.
  660. X
  661. X  There are exceptions to this standard:
  662. X
  663. X    - PASSWORD is abbreviated PW.
  664. X    - The words MINIMUM and MAXIMUM are abbreviated MIN and MAX.  So, the
  665. X      abbreviation for the parameter maximum_byte_count is maxbc.
  666. X
  667. X
  668. X                                 Installation
  669. X
  670. X  Execute the shell script install_evap, probably as root, which seems to
  671. X  work on EP/IX, SunOS, AIX and Stardent; changes may be required for your
  672. X  particular flavor of U*x.  For VX/VE use the install_evap_vxve script.
  673. X
  674. X  The default catalog for the install is /usr/local.  If this is not
  675. X  appropriate for your machine then edit the script and change the value
  676. X  of the variables INC, LIB and BIN.
  677. X
  678. X
  679. X                           Display Command Information
  680. X
  681. X  Besides evap.c, genpdt.c and addmm.c, this package includes the
  682. X  special command display_command_information (disci).  disci does just what
  683. X  it says:  it displays information about any evap-compliant command (that is,
  684. X  any application that uses evaluate_parameters to parse its command line).
  685. X  There are usage, brief and full display options on the command.  For example,
  686. X  try disci on itself:
  687. X
  688. X    display_command_information -command disci
  689. X
  690. X  This will give brief command information.  Then examine the full display:
  691. X
  692. X    disci -c disci -do f
  693. X
  694. X  Try disci on generate_pdt and add_message_modules too.
  695. X
  696. X
  697. X                            Adding New Message Modules
  698. X
  699. X  A message module is simply a text file of additional information used by
  700. X  disci (in reality evaluate_parameters).  Message modules for applications
  701. X  using evaluate_parameters are maintained in an archive file named
  702. X  libevapmm.a, typically in the catalog /usr/local/lib.  The name of the
  703. X  message module associated with a command is stored in the command's PDT. 
  704. X  Please examine the files in the directory message_module for examples.
  705. X  So, to create a message module for your command you must do two things:
  706. X
  707. X    1) Use the add_message_modules (addmm) command to add your help text
  708. X       to the ar message module database.  Use a text editor and create
  709. X       your file, with a name of the form hhhh.mm, where hhhh is the
  710. X       name of your application (the .mm 'extension' implies a message
  711. X       module).  The file name cannot exceed 14 characters, a limit 
  712. X       imposed by the ar utility.  Then:
  713. X
  714. X         add_message_modules hhhh.mm
  715. X
  716. X    2) Modify the command's PDT to include the name of this file.  Either
  717. X       manually change the pdt_header structure member help_module_name
  718. X       from NULL to "hhhh.mm" (not recommended), or re-create your PDT
  719. X       using generate_pdt (highly recommended).  The message module name 
  720. X       is specified on the PDT statement:
  721. X
  722. X         PDT (hhhh.mm) command_hhhh
  723. X           parameter declarations ...
  724. X         PDTEND required_file_list
  725. X
  726. X       Examine the sample PDTs in the catalog pdt.  Then simply re-compile.
  727. X
  728. X  You can maintain a private message module too.  If the message module name
  729. X  specified in the PDT header has one or more slashes in it, then the
  730. X  message module name specifies BOTH a path name to the message module
  731. X  archive file and the name of the message module contained in that library.
  732. X  For instance, in the following PDT declaration the message module name is
  733. X  again hhhh.mm, but this time it resides in the archive file my_mm_library
  734. X  rather than in libevapmm.a in the installation catalog:
  735. X
  736. X       PDT (my_mm_library/hhhh.mm) command_hhhh
  737. X         parameter declarations ...
  738. X       PDTEND required_file_list
  739. X
  740. X  Now use add_message_modules:
  741. X
  742. X       addmm -mml my_mm_library hhhh.mm
  743. X
  744. X  Use display_command_information -command add_message_modules -display_option
  745. X  full (disci -c addmm -do f) to see further information.
  746. X    
  747. X
  748. X                               Notes and Cautions
  749. X
  750. X  The PDT parsing code in genpdt.c is really pretty stupid.  Although most of
  751. X  the PDT declaration is free-form there are two contructs that must be
  752. X  entered in a particular fashion:
  753. X
  754. X    1) A key type declaration MUST be entered such that a trailing comma
  755. X       separates all the valid keywords, as in this example:
  756. X
  757. X         display_option, do: key brief, b, full, f, keyend = brief
  758. X
  759. X       The following key declaration would not parse properly:
  760. X
  761. X         display_option, do: key brief b full f keyend = brief
  762. X
  763. X    2) When specifying a help message module on the PDT statement, the
  764. X       message module name MUST be surrounded by parentheses without any
  765. X       embedded spaces.  Here is a valid example:
  766. X
  767. X         PDT (disci.mm) display_command_information, disci
  768. X
  769. X       This example is illegal and will not parse correctly:
  770. X
  771. X         PDT ( disci.mm ) display_command_information, disci
  772. X
  773. X  Finally, be sure to end the last line of the PDT declaration, the PDTEND
  774. X  statement, with a <cr>.  Failure to do so will cause generate_pdt to sense
  775. X  end-of-file prematurely.  
  776. X
  777. X
  778. X                                 Acknowledgment
  779. X
  780. X  Many thanks to Control Data Corporation for pioneering the concept of a
  781. X  typed, consistent user interface; an interface used by the NOS/VE operating
  782. X  system and ALL its applications; an interface that has meaningful command
  783. X  and parameter names instead of short, cryptic ones.  Control Data invented
  784. X  the concept of first-level help for ALL commands with
  785. X  DISPLAY_COMMAND_INFORMATION and DISPLAY_FUNCTION_INFORMATION, providing a
  786. X  level of global consistency not found in any other OS in the world (well,
  787. X  as I write this on my Mac I might have to reconsider (-:)!
  788. X
  789. X  Also, many thanks to Mark 'dog' Miller for coding the alpha version of
  790. X  evaluate_parameters.
  791. X
  792. X  Copyright (C) 1990 - 1993 by Lehigh University.  All rights reserved.
  793. X
  794. X*/
  795. X
  796. X#define P_PDT_VERSION "1.2"    /* PDT version */
  797. X
  798. X#ifndef NULL
  799. X#define NULL 0            /* NULL */
  800. X#endif
  801. X#ifndef TRUE
  802. X#define TRUE  1            /* TRUE */
  803. X#endif
  804. X#ifndef FALSE
  805. X#define FALSE 0            /* FALSE */
  806. X#endif
  807. X
  808. X#define P_TYPE_SWITCH      0    /* type ordinals */
  809. X#define P_TYPE_STRING      1
  810. X#define P_TYPE_REAL        2
  811. X#define P_TYPE_INTEGER     3
  812. X#define P_TYPE_BOOLEAN     4
  813. X#define P_TYPE_FILE        5
  814. X#define P_TYPE_KEY         6
  815. X#define P_TYPE_APPLICATION 7
  816. X#define P_TYPE_NAME        8
  817. X#define P_MAXIMUM_TYPES    9    /* maximum types supported */
  818. X
  819. X#define P_MAX_KEYWORD_LENGTH 31    /* maximum parameter length */
  820. X#define P_MAX_KEYWORD_VALUE_LENGTH 256 /* maximum parameter value length */
  821. X#define P_MAX_PARAMETER_HELP 256 /* maximum parameters that can have full_help */
  822. X#define P_MAX_PARAMETER_HELP_LENGTH 1024 /* maximum parameter help length */
  823. X#define P_MAX_VALID_VALUES 32    /* maximum number of key values */
  824. X
  825. X#define P_HELP 0        /* display command information */
  826. X
  827. Xstruct pdt_header {        /* PDT header */
  828. X  char *version;        /* PDT version */
  829. X  char *help_module_name;    /* help module */
  830. X  char *file_list;        /* trailing file list flag */
  831. X};
  832. X
  833. Xstruct parameter_value {    /* parameter value */
  834. X  char  *parameter;        /* official parameter spelling */
  835. X  char  *alias;            /* this parameter also known as */
  836. X  short int specified;        /* if this param entered by user */
  837. X  short int changeable;        /* if param changeable by user */
  838. X  short int type;        /* this parameter's type */
  839. X  char  *default_variable;    /* default environment variable */
  840. X  char  *unconverted_value;    /* value before type converstion */
  841. X  char  *description;        /* for usage information */
  842. X  char  *valid_values[P_MAX_VALID_VALUES]; /* valid values, last one NULL */
  843. X  union {            /* type dependent value */
  844. X    short int switch_value;
  845. X    char *string_value;
  846. X#ifdef nosve
  847. X    long double real_value;
  848. X#else
  849. X    double real_value;
  850. X#endif
  851. X    int integer_value;
  852. X    short int boolean_value;
  853. X    char *file_value;
  854. X    char *key_value;
  855. X    char *application_value;
  856. X    char *name_value;
  857. X  } value;
  858. X};
  859. X
  860. Xtypedef struct parameter_value Parameter_Value; /* an alias */
  861. END_OF_FILE
  862. if test 32868 -ne `wc -c <'evap/evap.h'`; then
  863.     echo shar: \"'evap/evap.h'\" unpacked with wrong size!
  864. fi
  865. chmod +x 'evap/evap.h'
  866. # end of 'evap/evap.h'
  867. fi
  868. echo shar: End of archive 3 \(of 4\).
  869. cp /dev/null ark3isdone
  870. MISSING=""
  871. for I in 1 2 3 4 ; do
  872.     if test ! -f ark${I}isdone ; then
  873.     MISSING="${MISSING} ${I}"
  874.     fi
  875. done
  876. if test "${MISSING}" = "" ; then
  877.     echo You have unpacked all 4 archives.
  878.     echo "Read README for installation instructions."
  879.     rm -f ark[1-9]isdone
  880. else
  881.     echo You still need to unpack the following archives:
  882.     echo "        " ${MISSING}
  883. fi
  884. ##  End of shell archive.
  885. exit 0
  886.  
  887. exit 0 # Just in case...
  888. -- 
  889.   // chris@IMD.Sterling.COM            | Send comp.sources.x submissions to:
  890. \X/  Amiga - The only way to fly!      |
  891.  "It's intuitively obvious to the most |    sources-x@imd.sterling.com
  892.   casual observer..."                  |
  893.