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

📄 cmdline.c

📁 NGN-3G核心部件SGSN的代码实现
💻 C
📖 第 1 页 / 共 3 页
字号:
            args_info->statedir_given = 1;
            args_info->statedir_arg = strdup (optarg);
            break;
          }
          /* DNS Server to use.  */
          else if (strcmp (long_options[option_index].name, "dns") == 0)
          {
            if (args_info->dns_given)
              {
                fprintf (stderr, "%s: `--dns' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->dns_given = 1;
            args_info->dns_arg = strdup (optarg);
            break;
          }
          /* Number of contexts.  */
          else if (strcmp (long_options[option_index].name, "contexts") == 0)
          {
            if (args_info->contexts_given)
              {
                fprintf (stderr, "%s: `--contexts' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->contexts_given = 1;
            args_info->contexts_arg = strtol (optarg,&stop_char,0);
            break;
          }
          /* Exit after timelimit seconds.  */
          else if (strcmp (long_options[option_index].name, "timelimit") == 0)
          {
            if (args_info->timelimit_given)
              {
                fprintf (stderr, "%s: `--timelimit' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->timelimit_given = 1;
            args_info->timelimit_arg = strtol (optarg,&stop_char,0);
            break;
          }
          /* GTP version to use.  */
          else if (strcmp (long_options[option_index].name, "gtpversion") == 0)
          {
            if (args_info->gtpversion_given)
              {
                fprintf (stderr, "%s: `--gtpversion' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->gtpversion_given = 1;
            args_info->gtpversion_arg = strtol (optarg,&stop_char,0);
            break;
          }
          /* Selection mode.  */
          else if (strcmp (long_options[option_index].name, "selmode") == 0)
          {
            if (args_info->selmode_given)
              {
                fprintf (stderr, "%s: `--selmode' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->selmode_given = 1;
            args_info->selmode_arg = strtol (optarg,&stop_char,0);
            break;
          }
          /* NSAPI.  */
          else if (strcmp (long_options[option_index].name, "nsapi") == 0)
          {
            if (args_info->nsapi_given)
              {
                fprintf (stderr, "%s: `--nsapi' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->nsapi_given = 1;
            args_info->nsapi_arg = strtol (optarg,&stop_char,0);
            break;
          }
          /* Charging characteristics.  */
          else if (strcmp (long_options[option_index].name, "charging") == 0)
          {
            if (args_info->charging_given)
              {
                fprintf (stderr, "%s: `--charging' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->charging_given = 1;
            args_info->charging_arg = strtol (optarg,&stop_char,0);
            break;
          }
          /* Create local network interface.  */
          else if (strcmp (long_options[option_index].name, "createif") == 0)
          {
            if (args_info->createif_given)
              {
                fprintf (stderr, "%s: `--createif' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->createif_given = 1;
            args_info->createif_flag = !(args_info->createif_flag);
            break;
          }
          /* Create default route.  */
          else if (strcmp (long_options[option_index].name, "defaultroute") == 0)
          {
            if (args_info->defaultroute_given)
              {
                fprintf (stderr, "%s: `--defaultroute' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->defaultroute_given = 1;
            args_info->defaultroute_flag = !(args_info->defaultroute_flag);
            break;
          }
          /* Script to run after link-up.  */
          else if (strcmp (long_options[option_index].name, "ipup") == 0)
          {
            if (args_info->ipup_given)
              {
                fprintf (stderr, "%s: `--ipup' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->ipup_given = 1;
            args_info->ipup_arg = strdup (optarg);
            break;
          }
          /* Script to run after link-down.  */
          else if (strcmp (long_options[option_index].name, "ipdown") == 0)
          {
            if (args_info->ipdown_given)
              {
                fprintf (stderr, "%s: `--ipdown' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->ipdown_given = 1;
            args_info->ipdown_arg = strdup (optarg);
            break;
          }
          /* Ping remote host.  */
          else if (strcmp (long_options[option_index].name, "pinghost") == 0)
          {
            if (args_info->pinghost_given)
              {
                fprintf (stderr, "%s: `--pinghost' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->pinghost_given = 1;
            args_info->pinghost_arg = strdup (optarg);
            break;
          }
          /* Number of ping req per second.  */
          else if (strcmp (long_options[option_index].name, "pingrate") == 0)
          {
            if (args_info->pingrate_given)
              {
                fprintf (stderr, "%s: `--pingrate' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->pingrate_given = 1;
            args_info->pingrate_arg = strtol (optarg,&stop_char,0);
            break;
          }
          /* Number of ping data bytes.  */
          else if (strcmp (long_options[option_index].name, "pingsize") == 0)
          {
            if (args_info->pingsize_given)
              {
                fprintf (stderr, "%s: `--pingsize' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->pingsize_given = 1;
            args_info->pingsize_arg = strtol (optarg,&stop_char,0);
            break;
          }
          /* Number of ping req to send.  */
          else if (strcmp (long_options[option_index].name, "pingcount") == 0)
          {
            if (args_info->pingcount_given)
              {
                fprintf (stderr, "%s: `--pingcount' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->pingcount_given = 1;
            args_info->pingcount_arg = strtol (optarg,&stop_char,0);
            break;
          }
          /* Do not print ping packet info.  */
          else if (strcmp (long_options[option_index].name, "pingquiet") == 0)
          {
            if (args_info->pingquiet_given)
              {
                fprintf (stderr, "%s: `--pingquiet' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->pingquiet_given = 1;
            args_info->pingquiet_flag = !(args_info->pingquiet_flag);
            break;
          }

        case '?':	/* Invalid option.  */
          /* `getopt_long' already printed an error message.  */
          exit (EXIT_FAILURE);

        default:	/* bug: option not considered.  */
          fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
          abort ();
        } /* switch */
    } /* while */


  if ( missing_required_options )
    exit (EXIT_FAILURE);

  return 0;
}

#define CONFIGPARSERBUFSIZE 1024

int
cmdline_parser_configfile (char * const filename, struct gengetopt_args_info *args_info, int override)
{
  FILE* file;
  char linebuf[CONFIGPARSERBUFSIZE];
  int line_num = 0;
  int len;
  int fnum;
  char fopt[CONFIGPARSERBUFSIZE], farg[CONFIGPARSERBUFSIZE];
  char *stop_char;

  if ((file = fopen(filename, "r")) == NULL)
    {
      fprintf (stderr, "%s: Error opening configuration file '%s'\n",
               PACKAGE, filename);
      exit (EXIT_FAILURE);
    }

  while ((fgets(linebuf, CONFIGPARSERBUFSIZE, file)) != NULL)
    {
      ++line_num;
      len = strlen(linebuf);
      if (len == CONFIGPARSERBUFSIZE-1)
        {
          fprintf (stderr, "%s: Line longer than %d characters found in configuration file '%s'\n",
                   PACKAGE, CONFIGPARSERBUFSIZE, filename);
          exit (EXIT_FAILURE);
        }

      if (linebuf[0] == '#')
        continue; /* Line was a comment */
    
      /* Get the option */
      if ((fnum = sscanf(linebuf, "%s %s", fopt, farg)) > 0)
        {
          if (!strcmp(fopt, "help"))
            {
              if (override || !args_info->help_given)
                {
                  args_info->help_given = 1;
                  
                }
              continue;
            }
          if (!strcmp(fopt, "version"))
            {
              if (override || !args_info->version_given)
                {
                  args_info->version_given = 1;
                  
                }
              continue;
            }
          if (!strcmp(fopt, "debug"))
            {
              if (override || !args_info->debug_given)
                {
                  args_info->debug_given = 1;
                  args_info->debug_flag = !(args_info->debug_flag);
                }
              continue;
            }
          if (!strcmp(fopt, "conf"))
            {
              if (override || !args_info->conf_given)
                {
                  args_info->conf_given = 1;
                  if (fnum == 2)
                    args_info->conf_arg = strdup (farg);
                  else
                    {
                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
                               filename, line_num);
                      exit (EXIT_FAILURE);
                    }
                }
              continue;
            }
          if (!strcmp(fopt, "pidfile"))
            {
              if (override || !args_info->pidfile_given)
                {
                  args_info->pidfile_given = 1;
                  if (fnum == 2)
                    args_info->pidfile_arg = strdup (farg);
                  else
                    {
                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
                               filename, line_num);
                      exit (EXIT_FAILURE);
                    }
                }
              continue;
            }
          if (!strcmp(fopt, "statedir"))
            {
              if (override || !args_info->statedir_given)
                {
                  args_info->statedir_given = 1;
                  if (fnum == 2)
                    args_info->statedir_arg = strdup (farg);
                  else
                    {
                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
                               filename, line_num);
                      exit (EXIT_FAILURE);
                    }
                }
              continue;
            }
          if (!strcmp(fopt, "dns"))
            {
              if (override || !args_info->dns_given)
                {
                  args_info->dns_given = 1;
                  if (fnum == 2)
                    args_info->dns_arg = strdup (farg);
                  else
                    {
                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
                               filename, line_num);
                      exit (EXIT_FAILURE);
                    }
                }
              continue;
            }
          if (!strcmp(fopt, "listen"))
            {
              if (override || !args_info->listen_given)
                {
                  args_info->listen_given = 1;
                  if (fnum == 2)
                    args_info->listen_arg = strdup (farg);
                  else
                    {
                      fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",

⌨️ 快捷键说明

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