home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / utilslib / c / OsCmd < prev    next >
Encoding:
Text File  |  1991-05-12  |  2.0 KB  |  80 lines

  1. /* Check whether a command is an OS command (binary search on the table
  2.  * os_commands of valid OS commands).
  3.  *
  4.  * this is a supplementary routine used in C.Popen and C.Filter.
  5.  */
  6.  
  7. #include <ctype.h>
  8.  
  9. static int cmp_cmd (char *, char *);
  10.  
  11. static char *os_commands[] =
  12. {
  13.     "access",    "adfs",        "alphabet",    "alphabets",
  14.     "append",    "audio",    "basic",    "breakclr",
  15.     "breaklist",    "breakset",    "build",    "cat",
  16.     "cdir",        "channelvoice",    "close",    "configure",
  17.     "continue",    "copy",        "count",    "countries",
  18.     "country",    "create",    "debug",    "delete",
  19.     "deskfs",    "dir",        "dump",        "echo",
  20.     "enumdir",    "error",    "eval",        "ex",
  21.     "exec",        "fileinfo",    "fontcat",    "fontlist",
  22.     "fx",        "go",        "gos",        "help",
  23.     "iconsprites",    "if",        "ignore",    "info",
  24.     "initstore",    "key",        "keyboard",    "lcat",
  25.     "lex",        "lib",        "list",        "load",
  26.     "memory",    "memorya",    "memoryi",    "modules",
  27.     "obey",        "opt",        "poduleload",    "podules",
  28.     "podulesave",    "pointer",    "print",    "qsound",
  29.     "quit",        "ram",        "remove",    "rename",
  30.     "rmclear",    "rmensure",    "rmfaster",    "rmkill",
  31.     "rmload",    "rmreinit",    "rmrun",    "rmtidy",
  32.     "rommodules",    "run",        "save",        "schoose",
  33.     "scopy",    "screenload",    "screensave",    "sdelete",
  34.     "set",        "seteval",    "setmacro",    "settype",
  35.     "sflipx",    "sflipy",    "sget",        "shadow",
  36.     "shellcli",    "show",        "showregs",    "shut",
  37.     "shutdown",    "sinfo",    "slist",    "sload",
  38.     "smerge",    "snew",        "sound",    "speaker",
  39.     "spool",    "spoolon",    "srename",    "ssave",
  40.     "stamp",    "status",    "stereo",    "tempo",
  41.     "time",        "tuning",    "tv",        "type",
  42.     "unplug",    "unset",    "up",        "voices",
  43.     "volume",    "wimppalette",    "wimpslot",    "wimptask",
  44.     "wipe"
  45. };
  46.  
  47. #define NUM_CMDS (sizeof(os_commands) / sizeof(char *))
  48.  
  49. int _os_cmd (char *cmd)
  50. {
  51.     int low = 0;
  52.     int high = NUM_CMDS - 1;
  53.  
  54.     while (low <= high)
  55.     {
  56.         int mid = (high + low) / 2;
  57.         int i = cmp_cmd(cmd,os_commands[mid]);
  58.  
  59.         if (i == 0)
  60.             return 1;
  61.         else if (i < 0)
  62.             high = mid - 1;
  63.         else
  64.             low = mid + 1;
  65.     }
  66.  
  67.     return 0;
  68. }
  69.  
  70. static int cmp_cmd (char *cmd, char *name)
  71. {
  72.     while (*name && tolower(*cmd) == *name)
  73.         ++name, ++cmd;
  74.  
  75.     if (*name)
  76.         return (tolower(*cmd) - *name);
  77.  
  78.     return (*cmd != '\0' && !isspace(*cmd));
  79. }
  80.