home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / utils / cli.c < prev    next >
C/C++ Source or Header  |  1996-12-11  |  9KB  |  286 lines

  1. /*
  2.     Ixprefs v.2.4--ixemul.library configuration program
  3.     Copyright © 1995,1996 Kriton Kyrimis
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include <dos/dos.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include "getopt.h"
  24.  
  25. extern void defaults(void), use(void), save(void), last_saved(void);
  26. extern int ixprefsabout(void);
  27.  
  28. extern int translateslash, membuf, blocks, cases, suppress,
  29.        amigawildcard, noflush, ignoreenv, networking, enforcerhit,
  30.        profilemethod;
  31.  
  32. void
  33. usage(char *prog)
  34. {
  35.   printf("Usage: %s [OPTION]...\n\nOptions:\n", prog);
  36.   printf("-a 1, --allow-amiga-wildcard\n");
  37.   printf("  accept AmigaOS wildcard notation\n");
  38.   printf("-a 0, --no-allow-amiga-wildcard\n");
  39.   printf("  do not accept AmigaOS wildcard notation\n");
  40.   printf("-s 1, --unix-pattern-matching-case-sensitive\n");
  41.   printf("  use case sensitive UNIX pattern matching\n");
  42.   printf("-s 0, --no-unix-pattern-matching-case-sensitive\n");
  43.   printf("  use case insensitive UNIX patter matching\n");
  44.   printf("-/ 1, --translate-slash\n");
  45.   printf("  translate /foo -> foo: and a//b -> a/b\n");
  46.   printf("-/ 0, --no-translate-slash\n");
  47.   printf("  do not translate /foo -> foo: and a//b -> a/b\n");
  48.   printf("-m N, --membuf-limit N\n");
  49.   printf("  files up to N bytes are cached in memory\n");
  50.   printf("-b N, --fs-buf-factor N\n");
  51.   printf("  N physical blocks map into 1 logical (stdio) block\n");
  52.   printf("-i 1, --ignore-global-env\n");
  53.   printf("  ignore global environment (ENV:)\n");
  54.   printf("-i 0, --no-ignore-global-env\n");
  55.   printf("  do not ignore global environment (ENV:)\n");
  56.   printf("-e 1, --enforcer-hit\n");
  57.   printf("  generate Enforcer hit when a trap occurs\n");
  58.   printf("-e 0, --no-enforcer-hit\n");
  59.   printf("  do not generate Enforcer hit when a trap occurs\n");
  60.   printf("-v 0, --insert-disk-requester\n");
  61.   printf("  suppress the \"Insert volume in drive\" requester\n");
  62.   printf("-v 1, --no-insert-disk-requester\n");
  63.   printf("  do not suppress the \"Insert volume in drive\" requester\n");
  64.   printf("-f 0, --flush-library\n");
  65.   printf("  prevent ixemul.library from being flushed from memory\n");
  66.   printf("-f 1, --no-flush-library\n");
  67.   printf("  do not prevent ixemul.library from being flushed from memory\n");
  68.   printf("-n 0, --auto-detect\n");
  69.   printf("  set networking support to auto detect\n");
  70.   printf("-n 1, --no-networking\n");
  71.   printf("  turn off networking support\n");
  72.   printf("-n 2, --as225\n");
  73.   printf("  use AS225 networking support\n");
  74.   printf("-n 3, --amitcp\n");
  75.   printf("  use AmiTCP networking support\n");
  76.   printf("-p 0, --profile-program\n");
  77.   printf("  profile the program only\n");
  78.   printf("-p 1, --profile-task\n");
  79.   printf("  profile while the task is running\n");
  80.   printf("-p 2, --profile-always\n");
  81.   printf("  always profile your program\n");
  82.   printf("-d, --default\n");
  83.   printf("  reset settings to defaults (other options are ignored)\n");
  84.   printf("-L, --last-saved\n");
  85.   printf("  reset settings from configuration file (other options are ignored)\n");
  86.   printf("-S, --save\n");
  87.   printf("  save new configuration\n");
  88.   printf("-R, --report\n");
  89.   printf("  display new configuration\n");
  90.   printf("-V, --version\n");
  91.   printf("  display program version information (other options are ignored)\n");
  92.   printf("-h, --help\n");
  93.   printf("  display this text\n");
  94.   printf("\nUse no arguments to get the GUI\n");
  95. }
  96.  
  97. void
  98. display_config(void)
  99. {
  100.   printf((amigawildcard ? "A" : "Do not a"));
  101.   printf("ccept AmigaOS wildcard notation,\n");
  102.   printf("Case ");
  103.   printf((cases ? "" : "in"));
  104.   printf("sensitive UNIX pattern matching,\n");
  105.   printf((translateslash ? "" : "do not "));
  106.   printf("translate /, ");
  107.   printf("membuf size = %d,\n", membuf);
  108.   printf("%d physical block", blocks);
  109.   printf(((blocks == 1) ? "" : "s"));
  110.   printf(" build");
  111.   printf(((blocks == 1) ? "s" : ""));
  112.   printf(" one logical block (for stdio),\n");
  113.   printf((ignoreenv ? "" : "do not "));
  114.   printf("ignore global environment (ENV:),\n");
  115.   printf((enforcerhit ? "" : "do not "));
  116.   printf("generate Enforcer hit when a trap occurs,\n");
  117.   printf((suppress ? "" : "do not "));
  118.   printf("suppress the \"Insert volume in drive\" requester,\n");
  119.   printf("use ");
  120.   switch (networking)
  121.   {
  122.     case 0: printf("auto-detect"); break;
  123.     case 1: printf("no"); break;
  124.     case 2: printf("AS225"); break;
  125.     case 3: printf("AmiTCP"); break;
  126.     default: printf("unknown"); break;
  127.   }
  128.   printf(" networking support,\n");
  129.   printf("profile ");
  130.   switch (profilemethod)
  131.   {
  132.     case 0: printf("your program,\n"); break;
  133.     case 1: printf("while your task is running,\n"); break;
  134.     case 2: printf("always,\n"); break;
  135.   }
  136.   printf((noflush ? "" : "do not "));
  137.   printf("prevent ixemul.library from being flushed from memory.\n");
  138. }
  139.  
  140. int
  141. parse_cli_commands(int argc, char *argv[])
  142. {
  143.   int c, error = 0, status;
  144.   static int reset_defaults = 0, save_config = 0, help = 0, report = 0,
  145.          last = 0, version = 0;
  146.  
  147.   while (1) {
  148.     int option_index = 0;
  149.     static struct option long_options[] = {
  150.       {"insert-disk-requester", 0, &suppress, 0},        /* -v */
  151.       {"no-insert-disk-requester", 0, &suppress, 1},
  152.       {"unix-pattern-matching-case-sensitive", 0, &cases, 1},    /* -s */
  153.       {"no-unix-pattern-matching-case-sensitive", 0, &cases, 0},
  154.       {"translate-slash", 0, &translateslash, 1},        /* -/ */
  155.       {"no-translate-slash", 0, &translateslash, 0},
  156.       {"allow-amiga-wildcard", 0, &amigawildcard, 1},        /* -a */
  157.       {"no-allow-amiga-wildcard", 0, &amigawildcard, 0},
  158.       {"flush-library", 0, &noflush, 0},            /* -f */
  159.       {"no-flush-library", 0, &noflush, 1},
  160.       {"ignore-global-env", 0, &ignoreenv, 1},            /* -i */
  161.       {"no-ignore-global-env", 0, &ignoreenv, 0},
  162.       {"enforcer-hit", 0, &enforcerhit, 1},            /* -e */
  163.       {"no-enforcer-hit", 0, &enforcerhit, 0},
  164.       {"auto-detect", 0, &networking, 0},            /* -n */
  165.       {"no-networking", 0, &networking, 1},
  166.       {"as225", 0, &networking, 2},
  167.       {"amitcp", 0, &networking, 3},
  168.       {"auto-detect", 0, &networking, 0},
  169.       {"no-networking", 0, &networking, 1},
  170.       {"as225", 0, &networking, 2},
  171.       {"profile-program", 0, &profilemethod, 0},        /* -p */
  172.       {"profile-task", 0, &profilemethod, 1},
  173.       {"profile-always", 0, &profilemethod, 2},
  174.       {"membuf-limit", 1, 0, 'm'},                /* -m */
  175.       {"fs-buf-factor", 1, 0, 'b'},                /* -b */
  176.       {"default", 0, &reset_defaults, 1},            /* -d */
  177.       {"save", 0, &save_config, 1},                /* -S */
  178.       {"report", 0, &report, 1},                /* -R */
  179.       {"last-saved", 0, &last, 1},                /* -L */
  180.       {"version", 0, &version, 1},                /* -V */
  181.       {"help", 0, &help, 1},                    /* -h */
  182.       {0, 0, 0, 0}
  183.     };
  184.     c = getopt_long (argc, argv, "v:s:x:a:/:f:i:e:m:n:b:p:dShRLV",
  185.                  long_options, &option_index);
  186.     if (c == EOF) {
  187.       break;
  188.     }
  189.     switch (c) {
  190.       case 0:
  191.     break;
  192.       case 'v':
  193.     suppress = (atoi(optarg) ? 0 : 1);
  194.     break;
  195.       case 's':
  196.     cases = (atoi(optarg) ? 1 : 0);
  197.     break;
  198.       case 'a':
  199.     amigawildcard = (atoi(optarg) ? 1 : 0);
  200.     break;
  201.       case '/':
  202.     translateslash = (atoi(optarg) ? 1 : 0);
  203.     break;
  204.       case 'f':
  205.         noflush = (atoi(optarg) ? 0 : 1);
  206.     break;
  207.       case 'i':
  208.         ignoreenv = atoi(optarg);
  209.     break;
  210.       case 'e':
  211.         enforcerhit = atoi(optarg);
  212.     break;
  213.       case 'm':
  214.     membuf = atoi(optarg);
  215.     break;
  216.       case 'n':
  217.     networking = atoi(optarg);
  218.     break;
  219.       case 'p':
  220.     profilemethod = atoi(optarg);
  221.     break;
  222.       case 'b':
  223.     blocks = atoi(optarg);
  224.     break;
  225.       case 'd':
  226.     reset_defaults = 1;
  227.     break;
  228.       case 'S':
  229.     save_config = 1;
  230.     break;
  231.       case 'h':
  232.         help = 1;
  233.     break;
  234.       case 'R':
  235.         report = 1;
  236.     break;
  237.       case 'L':
  238.         last = 1;
  239.     break;
  240.       case 'V':
  241.         version = 1;
  242.     break;
  243.       default:
  244.     error = 1;
  245.     break;
  246.     }
  247.   }
  248.   if (optind < argc) {
  249.     error = 1;
  250.   }
  251.   if (error) {
  252.     fprintf(stderr, "\n");
  253.     usage(argv[0]);
  254.     status = RETURN_FAIL;
  255.   }else{
  256.     status = RETURN_OK;
  257.     if (version) {
  258.       (void)ixprefsabout();
  259.     }else{
  260.       if (help) {
  261.     usage(argv[0]);
  262.       }else{
  263.     if (last) {
  264.       if (reset_defaults) {
  265.         fprintf(stderr,
  266.   "--last-saved and --default specified together.  --default ignored.\n");
  267.       }
  268.       last_saved();
  269.     }
  270.     if (reset_defaults) {
  271.       defaults();
  272.     }
  273.     if (save_config) {
  274.       save();
  275.     }else{
  276.       use();
  277.     }
  278.     if (report) {
  279.       display_config();
  280.     }
  281.       }
  282.     }
  283.   }
  284.   return status;
  285. }
  286.