home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / oslib / Examples / p1-467 < prev    next >
Encoding:
Text File  |  1994-05-25  |  1.2 KB  |  46 lines

  1. /*Example of how to use OS_ReadArgs in C.*/
  2.  
  3. #include <stdio.h>
  4.  
  5. #include "os.h"
  6.  
  7. int main (void)
  8.  
  9. {  struct {char *programme, *from, *to, *since; bool help; os_gi *size;
  10.          os_gs *name; char argd [1024];} argl;
  11.  
  12.    os_read_args ("programme/a,from/a,to/a,since/k,help/s,size/e,name/g",
  13.          os_get_env (NULL, NULL), (char *) &argl, sizeof argl, NULL);
  14.    /*Each structure element must correspond to the keyword in that place:
  15.  
  16.             keyword qualifier       component type
  17.             ------- ---------       --------- ----
  18.             switch (/s)             bool
  19.             expression (/e)         os_gi
  20.             string (/g)             os_gs
  21.             everything else         char *
  22.    */
  23.  
  24.    printf
  25.    (  "programme: %s\n"
  26.       "from: %s\n"
  27.       "to: %s\n"
  28.       "since: %s\n"
  29.       "help: %s\n"
  30.       "size: %d\n"
  31.       "name: %.*s\n",
  32.       argl.programme,
  33.       argl.from,
  34.       argl.to,
  35.       argl.since? argl.since: "(not given)",
  36.       WHETHER (argl.help),
  37.       argl.size? WORD (argl.size->i): -1,
  38.       argl.name? SHORT (argl.name->size): 80,
  39.       argl.name? argl.name->s: "(not given)"
  40.    );
  41.    /*Note use of WORD and SHORT, since these are not necessarily word-
  42.          aligned pointers.*/
  43.  
  44.    return 0;
  45. }
  46.