⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conf.c

📁 GNUnet是一个安全的点对点网络框架
💻 C
📖 第 1 页 / 共 2 页
字号:
            {              if (i > 0)                {                  printf ("\b");        /* this does not work */                  i--;                }              continue;            }#endif          if ((buf[i] == 'd') && (i == 0))            {              val->Double.val = val->Double.def;              printf ("%f\n", val->Double.val);              return GNUNET_YES;        /* default */            }          if (buf[i] == '?')            {              printf (_("Help\n"));              return GNUNET_NO;            }          if (buf[i] != '\n')            {              if (i < 1023)                {                  printf ("%c", buf[i]);                  fflush (stdout);                  i++;                }              continue;            }          if (i == 0)            {              printf ("%f\n", val->Double.val);              return GNUNET_YES;        /* keep */            }          buf[i + 1] = '\0';          if (1 == sscanf (buf, "%lf", &val->Double.val))            {              printf ("\n");              return GNUNET_OK;            }          i = 0;          printf (_("\nInvalid entry, try again (use '?' for help): "));          fflush (stdout);        }      break;    case GNUNET_GNS_TYPE_UINT64:      i = 0;      while (1)        {          buf[i] = rd ();          if (buf[i] == 'q')            {              printf (_("Abort\n"));              return GNUNET_SYSERR;            }#if 0          if (buf[i] == '\b')            {              if (i > 0)                {                  printf ("\b");        /* does not work */                  i--;                }              continue;            }#endif          if ((buf[i] == 'd') && (i == 0))            {              val->UInt64.val = val->UInt64.def;              printf ("%llu\n", val->UInt64.val);              return GNUNET_YES;        /* default */            }          if (buf[i] == '?')            {              printf (_("Help\n"));              return GNUNET_NO;            }          if (buf[i] != '\n')            {              if (i < 1023)                {                  printf ("%c", buf[i]);                  fflush (stdout);                  i++;                }              continue;            }          if (i == 0)            {              printf ("%llu\n", val->UInt64.val);              return GNUNET_YES;        /* keep */            }          buf[i + 1] = '\0';          if ((1 == sscanf (buf,                            "%llu",                            &l)) &&              (l >= val->UInt64.min) && (l <= val->UInt64.max))            {              val->UInt64.val = l;              printf ("\n");              return GNUNET_OK;            }          i = 0;          printf (_("\nInvalid entry, try again (use '?' for help): "));          fflush (stdout);        }      break;    default:      fprintf (stderr,               _("Unknown kind %x (internal error).  Skipping option.\n"),               type & GNUNET_GNS_TYPE_MASK);      return GNUNET_OK;    }  return GNUNET_OK;}static intconf (int indent,      struct GNUNET_GC_Configuration *cfg,      struct GNUNET_GE_Context *ectx, struct GNUNET_GNS_TreeNode *tree){  char choice;  char *value;  char *ovalue;  int i;  if (!tree->visible)    return GNUNET_OK;  switch (tree->type & GNUNET_GNS_KIND_MASK)    {    case GNUNET_GNS_KIND_LEAF:      ovalue = getValueAsString (tree->type, &tree->value);      while (1)        {          iprintf (indent,                   "[%s] %s = \"%s\"\n", tree->section, tree->option, ovalue);          iprintf (indent, "%s\n", gettext (tree->description));          printChoice (indent, tree->type, &tree->value);          i = readValue (tree->type, &tree->value);          if (i == GNUNET_SYSERR)            {              GNUNET_free (ovalue);              return GNUNET_SYSERR;            }          if (i == GNUNET_OK)            break;          printf ("\n\n");          iprintf (0, "%s\n", gettext (tree->help));          printf ("\n");        }      value = getValueAsString (tree->type, &tree->value);      if ((0 != strcmp (value, ovalue)) &&          (0 != GNUNET_GC_set_configuration_value_string (cfg,                                                          ectx,                                                          tree->section,                                                          tree->option,                                                          value)))        {          GNUNET_free (value);          GNUNET_free (ovalue);          return conf (indent, cfg, ectx, tree);        /* try again */        }      GNUNET_free (value);      GNUNET_free (ovalue);      return GNUNET_OK;    case GNUNET_GNS_KIND_NODE:      choice = '\0';      while (choice == '\0')        {          iprintf (indent, "%s\n", gettext (tree->description));          iprintf (indent, _(   /* do not translate y/n/? */                              "\tDescend? (y/n/?) "));          choice = rd ();          switch (choice)            {            case 'N':            case 'n':              iprintf (indent, "%c\n", choice);              return GNUNET_OK;            case 'q':              iprintf (indent, _("Aborted.\n"));              return GNUNET_SYSERR;     /* escape */            case '?':              iprintf (indent, "%c\n", choice);              iprintf (indent, "%s\n", gettext (tree->help));              choice = '\0';              break;            case 'Y':            case 'y':              iprintf (indent, "%c\n", choice);              break;            default:              iprintf (indent, "%c\n", choice);              iprintf (indent, _("Invalid entry.\n"));              choice = '\0';              break;            }        }      /* fall-through! */    case GNUNET_GNS_KIND_ROOT:      i = 0;      while (tree->children[i] != NULL)        {          if (GNUNET_SYSERR ==              conf (indent + 1, cfg, ectx, tree->children[i]))            return GNUNET_SYSERR;          i++;        }      return GNUNET_OK;    default:      fprintf (stderr,               _("Unknown kind %x (internal error).  Aborting.\n"),               tree->type & GNUNET_GNS_KIND_MASK);      return GNUNET_SYSERR;    }  return GNUNET_SYSERR;}intmain_setup_text (int argc,                 const char **argv,                 struct GNUNET_PluginHandle *self,                 struct GNUNET_GE_Context *ectx,                 struct GNUNET_GC_Configuration *cfg,                 struct GNUNET_GNS_Context *gns, const char *filename,                 int is_daemon){  struct GNUNET_GNS_TreeNode *root;  struct termios oldT;  struct termios newT;  char c;  int ret;#if OSX || SOMEBSD#  define TCGETS TIOCGETA#  define TCSETS TIOCSETA#endif  ioctl (0, TCGETS, &oldT);  newT = oldT;  newT.c_lflag &= ~ECHO;  newT.c_lflag &= ~ICANON;  ioctl (0, TCSETS, &newT);  printf (_("You can always press ENTER to keep the current value.\n"));  printf (_("Use the '%s' key to abort.\n"), "q");  root = GNUNET_GNS_get_tree_root (gns);  c = 'r';  while (c == 'r')    {      if (GNUNET_OK != conf (-1, cfg, ectx, root))        {          ioctl (0, TCSETS, &oldT);          return 1;        }      if ((0 == GNUNET_GC_test_dirty (cfg)) && (0 == ACCESS (filename, R_OK)))        {          printf (_("Configuration unchanged, no need to save.\n"));          ioctl (0, TCSETS, &oldT);          return 0;        }      printf ("\n");      printf (_              ("Save configuration?  Answer 'y' for yes, 'n' for no, 'r' to repeat configuration. "));      fflush (stdout);      do        {          c = rd ();        }      while ((c != 'y') && (c != 'n') && (c != 'r'));      printf ("%c\n", c);      fflush (stdout);    }  if (c == 'y')    {      ret = GNUNET_GC_write_configuration (cfg, filename);      if (ret == 1)        {          printf (_("Configuration was unchanged, no need to save.\n"));        }      else if (ret == -1)        {                       /* error */          ioctl (0, TCSETS, &oldT);          return 1;        }      else        {          printf (_("Configuration file `%s' written.\n"), filename);        }    }  ioctl (0, TCSETS, &oldT);  return 0;}/** * Generate defaults, runs without user interaction. */intdump_setup_text (int argc,                 const char **argv,                 struct GNUNET_PluginHandle *self,                 struct GNUNET_GE_Context *ectx,                 struct GNUNET_GC_Configuration *cfg,                 struct GNUNET_GNS_Context *gns, const char *filename,                 int is_daemon){  return GNUNET_GC_write_configuration (cfg, filename);}

⌨️ 快捷键说明

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