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

📄 wizard_curs.c

📁 GNUnet是一个安全的点对点网络框架
💻 C
📖 第 1 页 / 共 2 页
字号:
/*     This file is part of GNUnet.     (C) 2005, 2006 Christian Grothoff (and other contributing authors)     GNUnet is free software; you can redistribute it and/or modify     it under the terms of the GNU General Public License as published     by the Free Software Foundation; either version 2, or (at your     option) any later version.     GNUnet is distributed in the hope that it will be useful, but     WITHOUT ANY WARRANTY; without even the implied warranty of     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     General Public License for more details.     You should have received a copy of the GNU General Public License     along with GNUnet; see the file COPYING.  If not, write to the     Free Software Foundation, Inc., 59 Temple Place - Suite 330,     Boston, MA 02111-1307, USA.*//** * @file setup/ncurses/wizard_curs.c * @brief A easy-to-use configuration assistant for curses * @author Nils Durner * @author Christian Grothoff * * TODO: * - use ectx to capture error messages and show them to *   the user properly (some currently printf'ed to console!) * - additional autodetections (IP, etc) * - share helper functions with mconf.c (refactoring) */#include "platform.h"#ifdef HAVE_CDIALOG_DIALOG_H# undef PACKAGE# undef _# include <cdialog/dialog.h>#else# ifdef HAVE_DIALOG_H#  include <dialog.h># endif#endif#include "gnunet_util.h"#include "wizard_util.h"#include "gnunet_setup_lib.h"#include "wizard_curs.h"#include "mconf.h"#ifndef MINGW#include <termios.h>#include <grp.h>#endifstatic struct GNUNET_GE_Context *ectx;static struct GNUNET_GC_Configuration *cfg;static int last;static const char *cfg_fn;static voidshowCursErr (const char *prefix, const char *error){  char *err;  err = GNUNET_malloc (strlen (prefix) + strlen (error) + 2);  sprintf (err, "%s %s", prefix, error);  dialog_msgbox (_("Error"), err, 70, 15, 1);  GNUNET_free (err);}static voidshow_help (const char *helptext){  dialog_vars.help_button = 0;  dialog_msgbox (_("Help"), helptext, 20, 70, TRUE);}static voidshow_error (const char *msg){  dialog_vars.help_button = 0;  dialog_msgbox (_("Error!"), msg, 20, 70, TRUE);}static intquery_yesno (const char *title,             const char *question,             const char *help, const char *section, const char *option){  int ret;  if (help == NULL)    dialog_vars.help_button = 0;  else    dialog_vars.help_button = 1;  dialog_vars.cancel_label = _("No");  dialog_vars.ok_label = _("Yes");  while (true)    {      ret = dialog_yesno (title, question, 20, 70);      switch (ret)        {        case DLG_EXIT_OK:        case DLG_EXIT_CANCEL:          if (0 != GNUNET_GC_set_configuration_value_string (cfg,                                                             ectx,                                                             section,                                                             option,                                                             ret ==                                                             DLG_EXIT_OK ?                                                             "YES" : "NO"))            {              show_error (_("Internal error! (Choice invalid?)"));              break;            }          return 1;             /* advance */        case DLG_EXIT_ESC:          return 0;             /* abort */        case DLG_EXIT_HELP:          show_help (help);          break;        case DLG_EXIT_EXTRA:          return -1;            /* back */        default:          GNUNET_GE_BREAK (ectx, 0);          break;        }    }}static intquery_string (const char *title,              const char *question,              const char *help,              const char *section, const char *option, const char *def){  int ret;  int msel;  DIALOG_FORMITEM fitem;  if (help == NULL)    dialog_vars.help_button = 0;  else    dialog_vars.help_button = 1;  dialog_vars.cancel_label = _("Abort");  dialog_vars.ok_label = _("Ok");  fitem.type = 0;  fitem.name = GNUNET_strdup (question);  fitem.name_len = strlen (question);  fitem.name_y = 3;  fitem.name_x = 5;  fitem.name_free = 0;  fitem.text_y = 5;  fitem.text_x = 5;  fitem.text_flen = 55;  fitem.text_ilen = 63;  fitem.text_free = 0;  fitem.help_free = 0;  fitem.text = GNUNET_malloc (65536);  strcpy (fitem.text, def);  fitem.text_len = strlen (fitem.text);  fitem.help = GNUNET_strdup (help);  msel = 0;  ret = 2;  while (ret == 2)    {      ret = dlg_form (title, "", 20, 70, 15, 1, &fitem, &msel);      switch (ret)        {        case DLG_EXIT_OK:          if (0 != GNUNET_GC_set_configuration_value_string (cfg,                                                             ectx,                                                             section,                                                             option,                                                             fitem.text))            {              show_error (_("Internal error! (Choice invalid?)"));              ret = 2;            }          else            {              ret = 1;          /* advance */            }          break;        case DLG_EXIT_CANCEL:        case DLG_EXIT_ESC:          ret = 0;              /* abort */          break;        case DLG_EXIT_HELP:          show_help (help);          ret = 2;          break;        case DLG_EXIT_EXTRA:          ret = -1;             /* back */          break;        default:          GNUNET_GE_BREAK (ectx, 0);          ret = 0;          break;        }    }  GNUNET_free (fitem.name);  GNUNET_free (fitem.text);  GNUNET_free (fitem.help);  return ret;}static intwelcome (){  dialog_vars.help_button = 0;  dialog_msgbox (_("GNUnet configuration"),                 _                 ("Welcome to GNUnet!\n\nThis assistant will ask you a few basic questions "                  "in order to configure GNUnet.\n\nPlease visit our homepage at\n\t"                  "http://gnunet.org/\nand join our community at\n\t"                  "http://gnunet.org/drupal/\n\nHave a lot of fun,\n\nthe GNUnet team"),                 20, 70, TRUE);  return 1;}#define MAX_NIC 64static intinsert_nic_curs (const char *name, int defaultNIC, void *cls){  DIALOG_LISTITEM *nic_items = cls;  DIALOG_LISTITEM *item;  unsigned int pos;  pos = 0;  while ((pos < MAX_NIC) && (nic_items[pos].text != NULL))    pos++;  if (pos == MAX_NIC)    return GNUNET_SYSERR;  item = &nic_items[pos];  item->name = "";  item->text = GNUNET_strdup (name);  item->help = "";  item->state = defaultNIC;  return GNUNET_OK;}static intnetwork_interface (){  DIALOG_LISTITEM nic_items[MAX_NIC];  unsigned int total;  int ret;  int msel;  DIALOG_FORMITEM fitem;  fitem.type = 0;  fitem.name = "";  fitem.name_len = strlen (fitem.name);  fitem.name_y = 3;  fitem.name_x = 5;  fitem.name_free = 0;  fitem.text_y = 5;  fitem.text_x = 5;  fitem.text_flen = 55;  fitem.text_ilen = 63;  fitem.text_free = 0;  fitem.help_free = 0;  memset (nic_items, 0, sizeof (DIALOG_LISTITEM) * MAX_NIC);  GNUNET_list_network_interfaces (NULL, &insert_nic_curs, nic_items);  total = 0;  while ((total < MAX_NIC) && (nic_items[total].text != NULL))    {      if (nic_items[total].state)        msel = total;      total++;    }  if (total > 0)    {      while (true)        {          ret = dlg_menu (_("GNUnet configuration"),                          _                          ("Choose the network interface that connects your computer to "                           "the internet from the list below."), 20, 70, 10,                          total, nic_items, &msel, NULL);          switch (ret)            {            case DLG_EXIT_OK:              if (0 != GNUNET_GC_set_configuration_value_choice (cfg,                                                                 ectx,                                                                 "NETWORK",                                                                 "INTERFACE",                                                                 nic_items                                                                 [msel].name))                {                  show_error (_("Internal error! (Choice invalid?)"));                  break;                }              return 1;

⌨️ 快捷键说明

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