control.c

来自「压缩包里面的都是精致的基本C语言小程序」· C语言 代码 · 共 84 行

C
84
字号
#include "str.h"#include "error.h"#include "hash.h"#include "nat.h"#include "control.h"int controlBfs = 0;static str dashBfs;int controlDfs = 0;static str dashDfs;int controlKeepDot = 0;static str dashDot;int controlKeepS = 0;static str dashS;static hash hashAll;static void neg (nat n);static void controlInit ();static void neg (nat n){  int *p = (int *) (natToInt (n));  switch (*p)  {    case 0:      {        *p = 1;        break;      };    case 1:       {        *p = 0;        break;      };    default: exception ("invalid argument: control.c\n");  }  //return 0;}static void controlInit (){  hashAll = newHash ();    dashBfs = newStr ("-bfs");  hashInsert (hashAll, dashBfs, newNat ((int)&controlBfs));    dashDfs = newStr ("-dfs");  hashInsert (hashAll, dashDfs, newNat ((int)&controlDfs));    dashDot = newStr ("-dot");  hashInsert (hashAll, dashDot, newNat ((int)&controlKeepDot));    dashS = newStr ("-S");  hashInsert (hashAll, dashS, newNat ((int)&controlKeepS));      return;}void controlArgs (int argc, char *argv[]){  controlInit ();    for (int i=1; i<argc; i++)  {    str current = newStr (argv[i]);    nat n = hashLookup (hashAll, current);    if (!n)    {      strOutput (current);      exception (": no this argument\n");    }    neg (n);  }  return;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?