コード例 #1
0
ファイル: strarg.c プロジェクト: Sakura-IT/adoc
int main(int argc, char *argv[])
{
  if(argc > 1)
    printf( "%d\n", strarg(argv[1], "tobi", "gnu", "foo", "bar", "gnubbel", "42", "blubb", "") );

  return 0;
}
コード例 #2
0
ファイル: quh.c プロジェクト: BackupTheBerlios/quh
int
main (int argc, char **argv)
{
//  int i = 0;
//  char buf[MAXBUFSIZE];
  int c = 0, option_index = 0;
  int x = 0, y = 0;
  struct option long_only_options[ARGS_MAX];
  int result = 0;
//  const char *p = NULL; 
  const st_property_t props[] =
    {
      {
        "ansi_color", "1",
        "use ANSI colors in output? (1=yes; 0=no)"
      },
      {
        "default_cmdline", "",
        "will be used when quh is started w/o args"
      },
      {
        "settings", "100",
        "internal settings like volume, etc."
      },
#if 0
      {
        "quh_configdir",
        PROPERTY_MODE_DIR ("quh"),
        "directory with additional config files"
      },
#endif
      {NULL, NULL, NULL}
    };

  memset (&quh, 0, sizeof (st_quh_t));

  // defaults
  quh.pid = 1;
  tmpnam3 (quh.tmp_file, 0);
  set_suffix (quh.tmp_file, ".wav");

  if(!(quh.o = cache_open (MAXBUFSIZE, CACHE_MEM|CACHE_LIFO)))
    {
      fprintf (stderr, "ERROR: Could not malloc %d bytes\n", MAXBUFSIZE);
      return -1;
    }

  realpath2 (PROPERTY_HOME_RC ("quh"), quh.configfile);

  result = property_check (quh.configfile, QUH_CONFIG_VERSION, 1);
  if (result == 1) // update needed
    result = set_property_array (quh.configfile, props);
  if (result == -1) // property_check() or update failed
    return -1;

  signal (SIGINT, quh_signal_handler);
  signal (SIGTERM, quh_signal_handler);

  atexit (quh_exit);

  quh.ansi_color = get_property_int (quh.configfile, "ansi_color");
  quh.settings = get_property_int (quh.configfile, "settings");

  quh.argc = argc;
  quh.argv = argv;

#if 0
  // memorize cmdline
  if (quh.argc > 2)
    { 
      for (; quh.argv[i] && i < quh.argc; i++)
        sprintf (strchr (buf, 0), "%s ", quh.argv[i]);

      set_property (quh.configfile, "default_cmdline", buf,
                    "will be used when quh is started w/o args");
    }
  else
    {
      p = get_property (quh.configfile, "default_cmdline", PROPERTY_MODE_TEXT);

      if (p)
        { 
          strncpy (buf, p, MAXBUFSIZE)[MAXBUFSIZE - 1] = 0;
          quh.argc = strarg (quh.argv, buf, " ", QUH_MAX_ARGS);
        }
    }
#endif

  // set default filter chain
  filters = 0;
  quh.filter_id[filters++] = QUH_CACHE_PASS;
  quh.filter_id[filters++] = QUH_CONSOLE_PASS;
#ifdef  USE_ID3
//  quh.filter_id[filters++] = QUH_ID3_IN;
#endif
//  quh.filter_id[filters++] = QUH_CDDB_IN;
#ifdef  USE_OSS
  quh.filter_id[filters++] = QUH_OSS_OUT;
#elif   defined USE_SDL
  quh.filter_id[filters++] = QUH_SDL_OUT;
#endif

  // convert (st_getopt2_t **) to (st_getopt2_t *)
  memset (&options, 0, sizeof (st_getopt2_t) * QUH_MAX_ARGS);
  for (c = x = 0; option[x]; x++)
    for (y = 0; option[x][y].name || option[x][y].help; y++)
      if (c < QUH_MAX_ARGS)
        {
          memcpy (&options[c], &option[x][y], sizeof (st_getopt2_t));
          c++;
        }

#if 0
  for (x = 0; quh_decode_usage[x]; x++)
    if (c < QUH_MAX_ARGS)
      {
        memcpy (&options[c], quh_decode_usage[x], sizeof (st_getopt2_t));
        c++;
      }
#endif

  for (x = 0; quh_filter_usage[x]; x++)
    if (c < QUH_MAX_ARGS)
      {
        memcpy (&options[c], quh_filter_usage[x], sizeof (st_getopt2_t));
        c++;
      }

  for (x = 0; option2[x]; x++)
    for (y = 0; option2[x][y].name || option2[x][y].help; y++)
      if (c < QUH_MAX_ARGS)
        {
          memcpy (&options[c], &option2[x][y], sizeof (st_getopt2_t));
          c++;
        }

  getopt2_long_only (long_only_options, options, ARGS_MAX);

#if 0
  // if no options or filenames were specified we use a default cmdline
  if (argc < 2) // || !optind)
    {
      p = get_property (quh.configfile, "default_cmdline", PROPERTY_MODE_TEXT);
      if (p)
        {
          strncpy (quh.cmdline, p, ARGS_MAX)[ARGS_MAX - 1] = 0;
          quh.argc = strarg (quh.argv, quh.cmdline, " ", QUH_MAX_ARGS);
        }
    }
  else // store cmdline
    {
      strcpy (quh.cmdline, argv[0]);
      for (x = 1; x < argc; x++)
        sprintf (strchr (quh.cmdline, 0), " \"%s\"", quh.argv[x]);
      set_property (quh.configfile, "default_cmdline", quh.cmdline, NULL);
    }

  for (x = 0; x < quh.argc; x++)
    printf ("quh.argv[%d] == %s\n", x, quh.argv[x]);
  fflush (stdout);
#endif

  while ((c = getopt_long_only (quh.argc, quh.argv, "", long_only_options, &option_index)) != -1)
    quh_opts (c);

//  if (quh.verbose)
  if (!quh.quiet)
    fputs ("Quh " QUH_VERSION_S " 'Having ears makes sense again' 2005-2006 by NoisyB\n"
           "This may be freely redistributed under the terms of the GNU Public License\n\n", stdout);

  if (quh.argc < 2) // || !optind)
    {
      getopt2_usage (options);
      return -1;
    }

#warning files?
#if 0
  if (!getfile (quh.argc, quh.argv, quh_set_fname,
                (GETFILE_FILES_ONLY | (quh.flags & QUH_RECURSIVE ? GETFILE_RECURSIVE : 0)))) // recursively?
    {
      if (!quh.quiet)
        getopt2_usage (options);
      return -1;
    }
#endif

  if (!quh.filter_id[0])
    {
      fputs ("ERROR: you haven't specified any filters\n", stderr);
      fflush (stderr);
      return -1;
    }

  if (!quh.files)
    {
      fputs ("ERROR: you haven't specified any files to play\n", stderr);
      fflush (stderr);
      return -1;
    }

  if (!(quh.filter_chain = filter_malloc_chain (quh_filter)))
    {
      fputs ("ERROR: filter_malloc_chain() failed\n", stderr);
      fflush (stderr);
      return -1;
    }

  if (filter_init (quh.filter_chain, NULL, NULL) == -1)
    {
      fputs ("ERROR: filter_init() failed\n", stderr);
      fflush (stderr);
      return -1;
    }

  quh_play ();

  return 0;
}
コード例 #3
0
ファイル: cmndline.c プロジェクト: DexterWard/comanche
void process_command_line (int argc, char *argv[])
{
	char
		*s1,
		*s2;

	debug_log ("%s command line (argc = %d)", *argv, argc);

	//
	// skip program name in command line
	//

	argc--;
	argv++;

	while (argc--)
	{
		s1 = *argv++;

		////////////////////////////////////////
		if ((s2 = strarg (s1, "command_line_game_initialisation_phase_path")) || (s2 = strarg (s1, "path")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%s", command_line_game_initialisation_phase_path);
			}
			else
			{
				strcpy (command_line_game_initialisation_phase_path, "/0");
			}

			if (strlen (command_line_game_initialisation_phase_path) == 0)
			{
				strcpy (command_line_game_initialisation_phase_path, "/0");
			}

			debug_log ("ARG:%s, RESPONSE:command_line_game_initialisation_phase_path = %s", s1, command_line_game_initialisation_phase_path);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "command_line_game_initialisation_phase_directory")) || (s2 = strarg (s1, "directory")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%s", command_line_game_initialisation_phase_directory);
			}
			else
			{
				strcpy (command_line_game_initialisation_phase_directory, "/0");
			}

			if (strlen (command_line_game_initialisation_phase_directory) == 0)
			{
				strcpy (command_line_game_initialisation_phase_directory, "/0");
			}

			debug_log ("ARG:%s, RESPONSE:command_line_game_initialisation_phase_directory = %s", s1, command_line_game_initialisation_phase_directory);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "command_line_game_initialisation_phase_filename")) || (s2 = strarg (s1, "filename")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%s", command_line_game_initialisation_phase_filename);
			}
			else
			{
				strcpy (command_line_game_initialisation_phase_filename, "/0");
			}

			if (strlen (command_line_game_initialisation_phase_filename) == 0)
			{
				strcpy (command_line_game_initialisation_phase_filename, "/0");
			}

			debug_log ("ARG:%s, RESPONSE:command_line_game_initialisation_phase_filename = %s", s1, command_line_game_initialisation_phase_filename);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "entity_update_frame_rate")) || (s2 = strarg (s1, "eufr")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_entity_update_frame_rate);
			}
			else
			{
				command_line_entity_update_frame_rate = 2.0;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_entity_update_frame_rate = %d", s1, command_line_entity_update_frame_rate);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "3dw")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_3d_visual_screen_width);
			}
			else
			{
				command_line_3d_visual_screen_width = 640;
			}

			set_global_3d_visual_screen_width (command_line_3d_visual_screen_width);

			debug_log ("ARG:%s, RESPONSE:command_line_3d_visual_screen_width = %d", s1, command_line_3d_visual_screen_width);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "3dh")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_3d_visual_screen_height);
			}
			else
			{
				command_line_3d_visual_screen_height = 480;
			}

			set_global_3d_visual_screen_height (command_line_3d_visual_screen_height);

			debug_log ("ARG:%s, RESPONSE:command_line_3d_visual_screen_height = %d", s1, command_line_3d_visual_screen_height);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "3dce")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_3d_visual_clear_edges);
			}
			else
			{
				command_line_3d_visual_clear_edges = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_3d_visual_clear_edges = %d", s1, command_line_3d_visual_clear_edges);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "cbt")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_cpu_blit_textures);
			}
			else
			{
				command_line_cpu_blit_textures = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_cpu_blit_textures = %d", s1, command_line_cpu_blit_textures);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "3dreset")))
		////////////////////////////////////////
		{
			set_global_3d_visual_screen_width (640.0);

			set_global_3d_visual_screen_height (480.0);

			debug_log ("ARG:%s", s1);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "version_number")) || (s2 = strarg (s1, "vn")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_version_number);
			}

			if (command_line_version_number != IGNORE_COMMAND_LINE_VERSION_NUMBER)
			{
				set_global_version_number (command_line_version_number);
			}

			debug_log ("ARG:%s, RESPONSE:command_line_version_number = %d", s1, command_line_version_number);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "dynamics_cyclic_dead_zone")) || (s2 = strarg (s1, "dcdz")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_dynamics_cyclic_dead_zone);
			}
			else
			{
				command_line_dynamics_cyclic_dead_zone = 0.0;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_dynamics_cyclic_dead_zone = %f", s1, command_line_dynamics_cyclic_dead_zone);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "dynamics_yaw_altitude_loss")) || (s2 = strarg (s1, "dyal")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_dynamics_yaw_altitude_loss);
			}
			else
			{
				command_line_dynamics_yaw_altitude_loss = 5.0;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_dynamics_yaw_altitude_loss = %f", s1, command_line_dynamics_yaw_altitude_loss);
		}

		////////////////////////////////////////
		else if ((s2 = strarg (s1, "aitool_grid_pitch")) || (s2 = strarg (s1, "agp")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_aitool_grid_pitch);
			}
			else
			{
				command_line_aitool_grid_pitch = 0.0;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_aitool_grid_pitch = %f", s1, command_line_aitool_grid_pitch);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "comms_packet_timer")) || (s2 = strarg (s1, "cpt")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_comms_packet_resend_timer);
			}
			else
			{
				command_line_comms_packet_resend_timer = 5.0;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_packet_resend_timer = %f", s1, command_line_comms_packet_resend_timer);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "city_block_approximation_range")) || (s2 = strarg (s1, "cbar")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_city_block_approximation_range);
			}
			else
			{
				command_line_city_block_approximation_range = 500.0;
			}

			debug_log ("ARG:%s, RESPONSE:= %f", s1, command_line_city_block_approximation_range);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "user_invulnerable_time")) || (s2 = strarg (s1, "uit")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_user_invulnerable_time);
			}
			else
			{
				command_line_user_invulnerable_time = 5.0;
			}

			debug_log ("ARG:%s, RESPONSE:= %f", s1, command_line_user_invulnerable_time);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "chaff")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_chaff_effectiveness);

				command_line_chaff_effectiveness = bound (command_line_chaff_effectiveness, 0.0, 1.0);
			}
			else
			{
				command_line_chaff_effectiveness = 1.0;
			}

			debug_log ("ARG:%s, RESPONSE:= %f", s1, command_line_chaff_effectiveness);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "flare")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_flare_effectiveness);

				command_line_flare_effectiveness = bound (command_line_flare_effectiveness, 0.0, 1.0);
			}
			else
			{
				command_line_flare_effectiveness = 1.0;
			}

			debug_log ("ARG:%s, RESPONSE:= %f", s1, command_line_flare_effectiveness);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "smoke")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_smoke_effectiveness);

				command_line_smoke_effectiveness = bound (command_line_smoke_effectiveness, 0.0, 1.0);
			}
			else
			{
				command_line_smoke_effectiveness = 1.0;
			}

			debug_log ("ARG:%s, RESPONSE:= %f", s1, command_line_smoke_effectiveness);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "fog")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_fog_of_war_maximum_value);
			}
			else
			{
				command_line_fog_of_war_maximum_value = DEFAULT_FOG_OF_WAR_MAXIMUM_VALUE;
			}

			debug_log ("ARG:%s, RESPONSE:= %f", s1, command_line_fog_of_war_maximum_value);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "comms_show_stats")) || (s2 = strarg (s1, "css")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_show_stats);
			}
			else
			{
				command_line_comms_show_stats = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_show_stats= %d", s1, command_line_comms_show_stats);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "comms_packet_throttle_limit")) || (s2 = strarg (s1, "cptl")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_packet_throttle_limit);
			}
			else
			{
				command_line_comms_packet_throttle_limit = 10;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_packet_throttle_limit= %d", s1, command_line_comms_packet_throttle_limit);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "comms_resend_list_size")) || (s2 = strarg (s1, "crls")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_resend_list_size);
			}
			else
			{
				command_line_comms_resend_list_size = 1000;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_resend_list_size = %d", s1, command_line_comms_resend_list_size);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "comms_packet_data_size")) || (s2 = strarg (s1, "cpds")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_packet_data_size);
			}
			else
			{
				command_line_comms_packet_data_size = 512;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_packet_data_size = %d", s1, command_line_comms_packet_data_size);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "comms_rerequest_limit")) || (s2 = strarg (s1, "crl")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_packet_rerequest_limit);
			}
			else
			{
				command_line_comms_packet_rerequest_limit = 10;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_packet_rerequest_limit = %d", s1, command_line_comms_packet_rerequest_limit);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "comms_connection_receive_size")) || (s2 = strarg (s1, "ccrs")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_connection_receive_size);
			}
			else
			{
				command_line_comms_connection_receive_size = (200 * 1024);
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_connection_receive_size = %d", s1, command_line_comms_connection_receive_size);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "comms_data_record_size")) || (s2 = strarg (s1, "cdrs")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_data_record_size);
			}
			else
			{
				command_line_comms_data_record_size = (200 * 1024);
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_data_record_size = %d", s1, command_line_comms_data_record_size);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "comms_timeout")) || (s2 = strarg (s1, "cto")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_timeout);
			}
			else
			{
				command_line_comms_timeout = 5.0;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_timeout = %d", s1, command_line_comms_timeout);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "comms_resend_timeout")) || (s2 = strarg (s1, "crto")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_comms_resend_timeout);
			}
			else
			{
				command_line_comms_resend_timeout = (2.0);
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_resend_timeout = %f", s1, command_line_comms_resend_timeout);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "comms_pack_buffer_size")) || (s2 = strarg (s1, "cpbs")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_pack_buffer_size);
			}
			else
			{
				command_line_comms_pack_buffer_size = (200 * 1024);
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_pack_buffer_size = %d", s1, command_line_comms_pack_buffer_size);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "command_line_comms_initial_sleep_time")) || (s2 = strarg (s1, "cist")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_initial_sleep_time);
			}
			else
			{
				command_line_comms_initial_sleep_time = 500;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_initial_sleep_time = %d", s1, command_line_comms_initial_sleep_time);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "command_line_comms_guaranteed_send")) || (s2 = strarg (s1, "cgs")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_guaranteed_send);
			}
			else
			{
				command_line_comms_guaranteed_send = FALSE;
			}

			/////////////////////////////////////////////////////////////////
			if (command_line_comms_guaranteed_send)
			{

				direct_play_use_guaranteed_packets = TRUE;
			}
			else
			{

				direct_play_use_guaranteed_packets = FALSE;
			}
			/////////////////////////////////////////////////////////////////

			debug_log ("ARG:%s, RESPONSE:command_line_comms_guaranteed_send = %d", s1, command_line_comms_guaranteed_send);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "command_line_comms_dedicated_server")) || (s2 = strarg (s1, "dedicated")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_dedicated_server);
			}
			else
			{
				command_line_comms_dedicated_server = FALSE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_dedicated_server = %d", s1, command_line_comms_dedicated_server);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "command_line_comms_interpolate_gunships")) || (s2 = strarg (s1, "cig")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_interpolate_gunships);
			}
			else
			{
				command_line_comms_interpolate_gunships = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_interpolate_gunships= %d", s1, command_line_comms_interpolate_gunships);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "command_line_comms_validate_connections")) || (s2 = strarg (s1, "cvc")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_comms_validate_connections);
			}
			else
			{
				command_line_comms_validate_connections = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_comms_validate_connections= %d", s1, command_line_comms_validate_connections);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "command_line_game_initialisation_phase_game_type")) || (s2 = strarg (s1, "game_type")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_game_initialisation_phase_game_type);
			}
			else
			{
				command_line_game_initialisation_phase_game_type = GAME_TYPE_INVALID;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_game_initialisation_phase_game_type = %d", s1, command_line_game_initialisation_phase_game_type);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "command_line_game_initialisation_phase_gunship_type")) || (s2 = strarg (s1, "gunship_type")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_game_initialisation_phase_gunship_type);
			}
			else
			{
				command_line_game_initialisation_phase_gunship_type = NUM_GUNSHIP_TYPES;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_game_initialisation_phase_gunship_type = %d", s1, command_line_game_initialisation_phase_gunship_type);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "max_frame_rate")) || (s2 = strarg (s1, "mfr")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_max_frame_rate);
			}
			else
			{
				command_line_max_frame_rate = 30;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_max_frame_rate = %d", s1, command_line_max_frame_rate);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "max_update_rate")) || (s2 = strarg (s1, "mur")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_max_game_update_rate);

				command_line_max_game_update_rate_set = TRUE;
			}
			else
			{
				command_line_max_game_update_rate = 15;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_max_game_update_rate = %d", s1, command_line_max_game_update_rate);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "run_mode")) || (s2 = strarg (s1, "rm")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_run_mode);
			}
			else
			{
				command_line_run_mode = RUN_MODE_NORMAL;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_run_mode = %d", s1, command_line_run_mode);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "cdrom")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%c", &command_line_cdrom_drive_letter);
			}
			else
			{
				command_line_cdrom_drive_letter = 'Z';
			}

			debug_log ("ARG:%s, RESPONSE:command_line_cdrom_drive_letter = %c", s1, command_line_cdrom_drive_letter);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "new_graphics")) || (s2 = strarg (s1, "ng")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_new_graphics);
			}
			else
			{
				command_line_new_graphics = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_new_graphics = %d", s1, command_line_new_graphics);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "clean_graphics")) || (s2 = strarg (s1, "cg")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_clean_graphics);
			}
			else
			{
				command_line_clean_graphics = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_clean_graphics = %d", s1, command_line_clean_graphics);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "max_time_acceleration")) || (s2 = strarg (s1, "mta")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_max_time_acceleration);
			}
			else
			{
				command_line_max_time_acceleration = 4;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_max_time_acceleration= %d", s1, command_line_max_time_acceleration);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "ai_use_route_generator")) || (s2 = strarg (s1, "aurg")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_ai_use_route_generator);
			}
			else
			{
				command_line_ai_use_route_generator = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_ai_use_route_generator = %d", s1, command_line_ai_use_route_generator);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "no_convert_graphics")) || (s2 = strarg (s1, "ncg")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_no_graphics_conversion);
			}
			else
			{
				command_line_no_graphics_conversion = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_no_graphics_conversion = %d", s1, command_line_no_graphics_conversion);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "vector_flight_model")) || (s2 = strarg (s1, "vfm")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_vector_flight_model);
			}
			else
			{
				command_line_vector_flight_model = FALSE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_vector_flight_model = %d", s1, command_line_vector_flight_model);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "target_point")) || (s2 = strarg (s1, "tp")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_target_point_check);
			}
			else
			{
				command_line_target_point_check = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_target_point_check = %d", s1, command_line_target_point_check);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "no_pilot_rejection")) || (s2 = strarg (s1, "npr")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_no_pilot_rejection);
			}
			else
			{
				command_line_no_pilot_rejection = FALSE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_no_pilot_rejection = %d", s1, command_line_no_pilot_rejection);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "planner_goto_button")) || (s2 = strarg (s1, "goto")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_planner_goto_button);
			}
			else
			{
				command_line_planner_goto_button = FALSE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_planner_goto_button = %d", s1, command_line_planner_goto_button);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "cheats_on")) || (s2 = strarg (s1, "cheats")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_cheats_on);
			}
			else
			{
				command_line_cheats_on = FALSE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_cheats_on = %d", s1, command_line_cheats_on);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "capture_aircraft")) || (s2 = strarg (s1, "cpac")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_capture_aircraft);
			}
			else
			{
				command_line_capture_aircraft = FALSE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_capture_aircraft = %d", s1, command_line_capture_aircraft);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "dynamics_sonic_buildup")) || (s2 = strarg (s1, "dsb")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_dynamics_sonic_buildup);
			}
			else
			{

				command_line_dynamics_sonic_buildup = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_dynamics_sonic_buildup = %d", s1, command_line_dynamics_sonic_buildup);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "player_start_rank")) || (s2 = strarg (s1, "psr")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_player_start_rank);
			}
			else
			{

				command_line_player_start_rank = PILOT_RANK_LIEUTENANT;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_player_start_rank = %d", s1, command_line_player_start_rank);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "command_line_dynamics_retreating_blade_stall_effect")) || (s2 = strarg (s1, "drbs")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_dynamics_retreating_blade_stall_effect);
			}
			else
			{
				command_line_dynamics_retreating_blade_stall_effect = 1.0;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_dynamics_retreating_blade_stall_effect = %f", s1, command_line_dynamics_retreating_blade_stall_effect);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "dynamics_rudder_value")) || (s2 = strarg (s1, "drv")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_dynamics_rudder_value);
			}
			else
			{
				command_line_dynamics_rudder_value = 1.0;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_dynamics_rudder_value = %f", s1, command_line_dynamics_rudder_value);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "dynamics_rudder_acceleration")) || (s2 = strarg (s1, "dra")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_dynamics_rudder_acceleration);
			}
			else
			{
				command_line_dynamics_rudder_acceleration = 0.8;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_dynamics_rudder_acceleration = %f", s1, command_line_dynamics_rudder_acceleration);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "dynamics_rotor_drag")) || (s2 = strarg (s1, "drd")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_dynamics_main_rotor_drag);
			}
			else
			{
				command_line_dynamics_main_rotor_drag = 1.0;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_dynamics_main_rotor_drag = %f", s1, command_line_dynamics_main_rotor_drag);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "dynamics_main_rotor_lift")) || (s2 = strarg (s1, "dmrl")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_dynamics_main_rotor_lift);
			}
			else
			{
				command_line_dynamics_main_rotor_lift = 1.0;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_dynamics_main_rotor_lift = %f", s1, command_line_dynamics_main_rotor_lift);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "dynamics_tail_rotor_drag")) || (s2 = strarg (s1, "dtrd")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_dynamics_tail_rotor_drag);
			}
			else
			{
				command_line_dynamics_tail_rotor_drag = 1.0;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_dynamics_tail_rotor_drag = %f", s1, command_line_dynamics_tail_rotor_drag);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "object_level_of_detail")) || (s2 = strarg (s1, "olod")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%f", &command_line_object_lod_factor);
			}
			else
			{
				command_line_object_lod_factor = 1.0;
			}

			debug_log ("ARG:%s, RESPONSE:= %f", s1, command_line_object_lod_factor);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "directx_texture_management")) || (s2 = strarg (s1, "dxtm")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_d3d_use_texture_management );
			}
			else
			{
				command_line_d3d_use_texture_management = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:= %f", s1, command_line_d3d_use_texture_management);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "debug_input")) || (s2 = strarg (s1, "di")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_debug_input);
			}
			else
			{
				command_line_debug_input = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_debug_input = %d", s1, command_line_debug_input);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "debug_log_timing_info")) || (s2 = strarg (s1, "dt")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_debug_log_timing_info);
			}
			else
			{
				command_line_debug_log_timing_info = TRUE;
			}

			suppress_debug_log_timing_info (!command_line_debug_log_timing_info);

			debug_log ("ARG:%s, RESPONSE:command_line_debug_log_timing_info = %d", s1, command_line_debug_log_timing_info);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "debug_log")) || (s2 = strarg (s1, "dl")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%s", command_line_debug_log_name);
			}
			else
			{
				strcpy (command_line_debug_log_name, "DEBUG.LOG");
			}

			if (strlen (command_line_debug_log_name) == 0)
			{
				strcpy (command_line_debug_log_name, "DEBUG.LOG");
			}

			debug_log ("ARG:%s, RESPONSE:command_line_debug_log_name = %s", s1, command_line_debug_log_name);

			rename_debug_log_file (command_line_debug_log_name);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "ip_address")) || (s2 = strarg (s1, "ipa")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%s", command_line_ip_address);
			}
			else
			{
				strcpy (command_line_ip_address, "\0");
			}

			if (strlen (command_line_ip_address) == 0)
			{
				strcpy (command_line_ip_address, "\0");
			}

			debug_log ("ARG:%s, RESPONSE:command_line_ip_address = %s", s1, command_line_ip_address);

			strcpy (global_options.ip_address, command_line_ip_address);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "dump_session")) || (s2 = strarg (s1, "ds")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_dump_session);
			}
			else
			{
				command_line_dump_session = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_dump_session = %d", s1, command_line_dump_session);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "full_screen")) || (s2 = strarg (s1, "fs")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_full_screen);
			}
			else
			{
				command_line_full_screen = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_full_screen = %d", s1, command_line_full_screen);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "hardware_render")) || (s2 = strarg (s1, "hw")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_hardware_render);
			}
			else
			{
				command_line_hardware_render = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_hardware_render = %d", s1, command_line_hardware_render);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "no_sound")) || (s2 = strarg (s1, "ns")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_no_sound);
			}
			else
			{
				command_line_no_sound = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_no_sound = %d", s1, command_line_no_sound);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "notnl")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_no_hardware_tnl);
			}
			else
			{
				command_line_no_hardware_tnl = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_no_hardware_tnl = %d", s1, command_line_no_hardware_tnl);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "nrt")))
		////////////////////////////////////////
		{
			if (*s2 == ':')
			{
				sscanf (s2 + 1, "%d", &command_line_no_render_to_texture);
			}
			else
			{
				command_line_no_render_to_texture = TRUE;
			}

			debug_log ("ARG:%s, RESPONSE:command_line_render_to_texture = %d", s1, command_line_no_render_to_texture);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "32bit")))
		////////////////////////////////////////
		{

			command_line_display_bpp = 32;

			debug_log ("ARG:%s, RESPONSE:command_line_render_to_texture = %d", s1, command_line_no_render_to_texture);
		}
		////////////////////////////////////////
		else if ((s2 = strarg (s1, "nomcm")))
		////////////////////////////////////////
		{
			command_line_no_mission_complete_music = TRUE;

			debug_log ("ARG:%s, RESPONSE:command_line_no_mission_complete_music = %d", s1, command_line_no_mission_complete_music);
		}
		////////////////////////////////////////
		else
		////////////////////////////////////////
		{
			debug_log ("ARG:%s, RESPONSE:not recognized", s1);
		}
	}
}
コード例 #4
0
ファイル: main.c プロジェクト: BlueBolt/BB_GridEngine
int main(int argc, char *argv[])
{
  int err= 0; /* return code */

  char *outfile    = (char *)0;      /* --output-file       */
  char *errfile    = (char *)0;      /* --error-file        */
  char *headerfile = (char *)0;      /* --texi-header-file  */
  char *yank_type  = "*";            /* --yank-type         */
  char *body_env   = "smallexample"; /* -B<environment>     */

  int page_width         = 80;       /* --page-width        */
  int tabsize            = 8;        /* --tab-size          */
  int tabs_to_spaces     = 0;        /* --tabs-to-spaces    */
  int output_type        = 1;        /* --output-type       */
  int table_of_contents  = 0;        /* --table-of-contents */
  int sort_entries       = 1;        /* --preserve-order    */
  int texi_flags         = TEXI_CREATE_HEADER | TEXI_PARSE_REFERENCES | TEXI_ITEMIZE_REFERENCES;
  int adoc_flags         = ADOC_FORM_FEEDS;
  int warn_mask          = WARN_NORMAL;
  int scanner_flags      = 0;        /* --indented-comments */
                                     /* --unindent-bodytext */
  int minimum_indentation = -1;      /* --reindent-bodytext */

  /* handles for the macro tables */

  int texi_macros = 0;
  int body_macros = 0;

#ifdef _DCC /* Dice */
  expand_args(argc,argv, &argc,&argv);
#endif /* _DCC */

  /* filenames on MS-DOG systems look very ugly: all uppercase and
   * backslashes.  Perform some cosmetics */

#ifdef __MSDOS__
  whoami= "adoc";

#else
  whoami= argv[0];

#endif /*__MSDOS__*/


  /* set the debugging defaults */
  D(bug_init(0,stdout));

  /* initialize the default error stream */
  ferr= stderr;

  if(err == 0)
  {
    /* prepare the texinfo macro table */
    texi_macros= mactab_new( 4+10 );

    if(!texi_macros)
      err= 1;
  }

  if(err == 0)
  {
    /* prepare the body-text macro table */
    body_macros= mactab_new( 2 );

    if(!body_macros)
      err= 2;
  }

  if(err)
    echo("error %d creating macro tables -- not enough memory?", err);

  else

  /* BEGIN scanning command line arguments */

  while( (--argc > 0) && (err <= 0) )
  {
    char *arg= *++argv;

#ifdef DEBUG
    if(argc > 1)  { D(bug("examining command line argument `%s' ( `%s', ... ) [%d]", argv[0], argv[1], argc-1)); }
    else          { D(bug("examining command line argument `%s' ( ) [%d]", argv[0], argc-1)); }
#endif /* DEBUG */

    if(*arg=='-')
    {
      /* remember the original command-line option string */
      char *opt= arg;

      if(arg[1]=='-')
        arg= convert_args(*argv);

      switch(*++arg)
      {

/*-0*/  case '0':
          output_type= 0;
          break;

/*-1*/  case '1':
          output_type= 1;
          break;

/*-2*/  case '2':
          output_type= 2;
          tabs_to_spaces= 1;
          minimum_indentation= 0;
          break;

/*-b*/  case 'b':
          texi_flags |= TEXI_TABLE_FUNCTIONS;
          break;

/*-B*/  case 'B':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            body_env= arg;
          }
          else
          {
            echo("missing texinfo body text environment after %s option",opt);
            err= 1;
          }
          break;

/*-c*/  case 'c':
          err= mactab_add(body_macros, "\\*", "/*", "*\\", "*/", (char *)0);

          if(err)
            echo("error %d adding comment convertion macros",err);
          break;

/*-d*/  case 'd':

#ifdef DEBUG

          if(arg[1]) { D(bug_level= atoi( &(arg[1]) )); }
          else       { D(bug_level= 1); }

#else /* !DEBUG */
          echo("not compiled w/ -DDEBUG.  No debug information available -- Sorry");
          /* no error */

#endif /* DEBUG */

          break;


/*-D*/  case 'D':
          if(arg[1] && --argc > 0)
          {
            char *lhs= &arg[1];
            char *rhs= *(++argv);

            err= mactab_add(texi_macros, lhs, rhs, (char *)0);

            if(err)
              echo("error adding texinfo macro `%s' = `%s'", lhs, rhs);
          }
          else
          {
            echo("missing macro %s after `%s' option",(arg[1] ? "value":"name"),opt);
            err= 1;
          }
          break;

/*-E*/  case 'E':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            if(errfile)
            {
              echo("warning: option `%s' has already been seen", opt);
              D(bug("%s \"%s\" superseeds -E \"%s\"", opt, arg, errfile));
            }

            /*errfile= strcmp(arg,"-") ? arg : (char *)0;*/
            errfile= arg;
          }
          else /* !(arg && *arg) */
          {
            echo("missing filename after `%s' option", opt);
            err= 1;
          }
          break;

/*-f*/  case 'f':
          if(arg[1])
          {
            while(*++arg) switch(*arg)
            {
              case 'f':
                adoc_flags |= ADOC_FORM_FEEDS;
                texi_flags |= TEXI_FUNCTION_NEWPAGE;
                break;

              default:
                echo("unknown paging option: `%s'",opt);
                break;
            }
          }
          else /* !arg[1] */
          {
            adoc_flags &= ~ADOC_FORM_FEEDS;
            texi_flags &= ~TEXI_FUNCTION_NEWPAGE;
          }
          break;

/*-g*/  case 'g':
          if(arg[1])
          {
            while(*++arg) switch(*arg)
            {
              case 's':
                texi_flags |= TEXI_GROUP_SECTIONS;
                break;

              default:
                echo("unknown grouping option: `%s'",opt);
                err= 1;
                break;
            }
          }
          else texi_flags &= ~TEXI_GROUP_SECTIONS;
          break;

/*-H*/  case 'H':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            if(headerfile)
            {
              echo("warning: option `%s' has already been seen", opt);
              D(bug("%s \"%s\" superseeds -H \"%s\"", opt, arg, headerfile));
            }

            headerfile= arg;
          }
          else /* !(arg && *arg) */
          {
            echo("missing texinfo header filename after `%s' option", opt);
            err= 1;
          }
          break;

/*-h*/  case 'h':
          printf("usage: %s [options] [-o outfile] [@ listfile] [infiles...]\n\n", whoami);
          display_args( arg[1] ? atoi(&arg[1]) : 3 );
          err= -1;    /* negative means exit w/o error */
          break;

/*-I*/  case 'I':
          table_of_contents= 1;
          break;

/*-i*/  case 'i':
          yank_type= "i";
          break;

/*-j*/  case 'j':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            if( (minimum_indentation= atoi(arg)) < 0 )
            {
              echo("illegal indentation: %d  (must be >= 0)", minimum_indentation);
              err= 1;
            }
          }
          else /* !(arg && *arg) */
          {
            echo("missing indentation after `%s' option", opt);
            err= 1;
          }
          break;

/*-l*/  case 'l':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            page_width= atoi(arg);

            if(page_width < 1)
            {
              echo("illegal page width: `%s'  (must be > 0)", arg);
              err= 1;
            }
          }
          else /* !(arg && *arg) */
          {
            echo("missing page width after `%s' option", opt);
            err= 1;
          }
          break;

/*-M*/  case 'M':
          if(arg[1] && --argc > 0)
          {
            char *lhs= &arg[1];
            char *rhs= *(++argv);

            err= mactab_add(body_macros, lhs, rhs, (char *)0);

            if(err)
              echo("error adding body macro `%s' -> `%s'", lhs, rhs);
          }
          else
          {
            echo("missing macro %s after `%s' option",(arg[1] ? "value":"name"),opt);
            err= 1;
          }
          break;

/*-n*/  case 'n':
          output_type= 0;
          break;

/*-o*/  case 'o':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            if(outfile)
              echo("warning: option `%s' has already been seen", opt);

            outfile= arg;
          }
          else /* !(arg && *arg) */
          {
            echo("missing filename after `%s' option", opt);
            err= 1;
          }
          break;

/*-p*/  case 'p':
          sort_entries= arg[1] ? 1:0;
          break;

/*-q*/  case 'q':
          break;

/*-T*/  case 'T':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            tabs_to_spaces= 1;
            tabsize= atoi(arg);

            if(tabsize < 1)
            {
              echo("illegal tab step: `%d'  (must be >= 1)", tabsize);
              err= 1;
            }
          }
          else /* !(arg && *arg) */
          {
            echo("missing tab size after `%s' option", opt);
            err= 1;
          }
          break;

/*-t*/  case 't':
          tabs_to_spaces= arg[1] ? atoi(&arg[1]) : 1;
          break;

/*-U*/  case 'U':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            mactab_remove(texi_macros, arg, (char *)0);
            mactab_remove(body_macros, arg, (char *)0);
          }

          else /* !(arg && *arg) */
          {
            echo("missing macro after `%s' option", opt);
            err= 1;
          }
          break;

/*-u*/  case 'u':
          if(arg[1])
          {
            scanner_flags &= ~SCANNER_UNINDENT_BODYTEXT;
            minimum_indentation= -1;
          }
          else scanner_flags |= SCANNER_UNINDENT_BODYTEXT;
          break;

/*-v*/  case 'v':
          printf("ADOC Version " VERSION " (compiled " __DATE__ ", " __TIME__ ")\n"
                 "(c)Copyright 1995 by Tobias Ferber,  All Rights Reserved\n" );
          err= -1;
          break;

/*-W*/  case 'W':
          if(arg[1])
          {
            ++arg;

            if( isdigit(*arg) )
              warn_mask |= atoi(arg);

            else switch( strarg(arg, "none",       /* 1 */
                                     "arnings",    /* 2 */
                                     "keywords",   /* 3 */
                                     "absence",    /* 4 */
                                     "untitled",   /* 5 */
                                     "all", "") )  /* 6 */
            {
              case 1:   warn_mask  = WARN_NONE;                 break;
              case 2:   warn_mask |= WARN_NORMAL;               break;
              case 3:   warn_mask |= WARN_UNKNOWN_KEYWORDS;     break;
              case 4:   warn_mask |= WARN_MISSING_KEYWORDS;     break;
              case 5:   warn_mask |= WARN_UNTITLED_SECTION;     break;
              case 6:   warn_mask |= WARN_ALL;                  break;

              default:
                echo("unknown warning method: `%s'",opt);
                err= 1;
                break;
            }
          }
          else warn_mask= WARN_NONE;
          break;

/*-x*/  case 'x':
          if(arg[1])
          {
            switch( strarg(++arg, "off",        /* 1 */
                                  "on",         /* 2 */
                                  "itemize",    /* 3 */
                                  "", "") )     /* 4 */
            {
              case 1:   texi_flags &= ~TEXI_PARSE_REFERENCES;
                        texi_flags &= ~TEXI_ITEMIZE_REFERENCES;   break;

              case 2:   texi_flags |=  TEXI_PARSE_REFERENCES;
                        texi_flags &= ~TEXI_ITEMIZE_REFERENCES;   break;

              case 3:   texi_flags |=  TEXI_PARSE_REFERENCES;
                        texi_flags |=  TEXI_ITEMIZE_REFERENCES;   break;

              default:
                echo("unknown reference handlig option: `%s'",opt);
                err= 1;
                break;
            }
          }
          else texi_flags &= ~(TEXI_PARSE_REFERENCES | TEXI_ITEMIZE_REFERENCES);
          break;


/*-Y*/  case 'Y':
          if(arg[1]) scanner_flags &= ~SCANNER_ALLOW_INDENTED_COMMENTS;
          else       scanner_flags |=  SCANNER_ALLOW_INDENTED_COMMENTS;
          break;

/*-y*/  case 'y':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0L;

          if(arg && *arg)
            yank_type= arg;

          else /* !(arg && *arg) */
          {
            echo("missing comment type string after `%s' option", opt);
            err= 1;
          }
          break;

/*-z*/  case 'z':
          texi_flags &= ~TEXI_CREATE_HEADER;
          break;

/*-Z*/  case 'Z':
          if(arg[1]) texi_flags &= ~TEXI_NO_INDEX;
          else       texi_flags |=  TEXI_NO_INDEX;
          break;

          /*
           *  The following options are ignored for compatibility
           *  with Bill Koester's original version `autodoc' which
           *  is part of C=ommodore's Native Developer Kit (NDK).
           */

/*-C*/  case 'C':
/*-F*/  case 'F':
/*-s*/  case 's':
/*-a*/  case 'a':
/*-r*/  case 'r':
/*-w*/  case 'w':
          echo("warning: option `%s' ignored for compatibility", opt);
          break;

/*- */  case '\0':
          if( (err= flist_addfile("")) )
             echo("out of memory... hmmmmmmmmmpf!");
           break;

/*??*/  default:
          echo("unrecognized option `%s'", opt);
          err= 1;
          break;
      }
    }
    else if(*arg=='@')
    {
      if(arg[1]) ++arg;
      else arg= (--argc > 0) ? *(++argv) : (char *)0L;

      if(arg && *arg)
      {
        if( (err= flist_from_file(arg)) )
          echo("out of memory... aaarrrrrrgggggghh!");
      }
      else /* !(arg && *arg) */
      {
        echo("missing filename after `%s'", *argv);
        err= 1;
      }
    }
    else /* *arg != '@' */
    {
      if(arg && *arg)
      {
        if( (err= flist_addfile(arg)) )
          echo("out of memory... aaaiiiiiieeeeeeeee!");
      }
      else echo("internal problem parsing command line arguments: arg is empty");
    }
  }
  /* END scanning command line arguments */
  D(bug("command line argument parsing done"));

  if(err == 0)
  {
    /* prepare the error stream */

    if(errfile && *errfile)
    {
      D(bug("opening error stream `%s'",errfile));

      if( !(ferr= fopen(errfile,"w")) )
      {
        echo("could not write error messages to `%s'",errfile);
        err= __LINE__;
      }
    }
    /*else ferr is initialized to stderr */

    /* if no filename is given then read from stdin */

    if( !flist_getname() )
      flist_addfile("");


    /* read the input files (the scanner takes them from the flist queue) */

    D(bug("reading autodocs of type `%s'", yank_type));

    if(err == 0)
      err= read_source(yank_type, warn_mask, scanner_flags);

    if(err < 0)
      err= -err;  /* I/O error */

    D(bug("disposing file list"));
    flist_dispose();

    /*
     */

    if( (err == 0) && (minimum_indentation >= 0) )
    {
      if( (err= funindent(minimum_indentation, tabsize)) )
        echo("error %d reworking body text indentation -- not enough memory?",err);

      /* funindent() already performed that conversion */
      else tabs_to_spaces= 0;
    }


    if( (err == 0) && (output_type > 0) )
    {
      FILE *fout;

      /* prepare the output file */

      if(outfile && *outfile)
      {
        D(bug("opening output stream `%s'",outfile));

        if(!(fout= fopen(outfile,"w")) )
        {
          echo("could not write to `%s'",outfile);
          err= __LINE__;
        }
      }
      else fout= stdout;


      if( fout && (err==0) )
      {
        if(sort_entries)
        {
          D(bug("sorting entries"));
          funsort();
        }

        switch(output_type)
        {
          case 1: /* --autodoc */

            if(table_of_contents)
            {
              D(bug("writing table of contents"));
              err= gen_autodoc_toc(fout);
            }
            if(err == 0)
            {
              D(bug("writing autodocs"));
              err= gen_autodoc( fout, page_width, tabs_to_spaces ? tabsize : 0, adoc_flags, mactab(body_macros) );
            }
            break;

          case 2: /* --texinfo */
            if(texi_flags & TEXI_CREATE_HEADER)
            {
              D(bug("creating texinfo header"));
              err= gen_texinfo_header( fout, headerfile, mactab(texi_macros) );
            }

            if(err == 0)
            {
              D(bug("adding texinfo body macros"));
              err= mactab_add( body_macros,  "@",        "@@",
                                             "{",        "@{",
                                             "}",        "@}",
                                          /* "...",      "@dots{}", */
                                          /* "TeX",      "@TeX{}",  */
                                             "e.g. ",    "e.g.@: ",
                                             "E.g. ",    "E.g.@: ",
                                             "i.e. ",    "i.e.@: ",
                                             "I.e. ",    "I.e.@: ",   (char *)0 );
            }

            if(err == 0)
            {
              D(bug("creating texinfo output"));
              err+= gen_texinfo( fout, tabs_to_spaces ? tabsize : 0, texi_flags, body_env, mactab(body_macros) );
            }

            if(err)
              echo("error creating texinfo output");
            break;

          default: /* --dry-run */
            break;
        }
      }

      if(fout && (fout != stdout))
        fclose(fout);
    }

    D(bug("disposing libfun entries"));
    funfree();
  }

#ifdef DEBUG
  mactab_debug(bug_stream);
#endif

  D(bug("disposing macro tables"));
  mactab_dispose(body_macros);
  mactab_dispose(texi_macros);

  /*
  */

  if(err > 0)
  {
    echo("[%s] *** Error %d", (outfile && *outfile) ? outfile : "stdout", err);
    fprintf(ferr,"%s terminated abnormally (error %d)\n", whoami, err);
  }

  D(bug("closing I/O streams"));

  if( ferr && (ferr != stderr) && (ferr != stdout) )
    fclose(ferr);

  D(bug("exiting adoc returning %d (%s)", (err>0) ? 1:0, (err>0) ? "error":"success" ));
  D(bug_exit());

#ifdef DEBUG

  if(bug_stream && (bug_stream != stdout))
    fclose(bug_stream);

#endif /*DEBUG*/

  return (err > 0) ? 1:0;
}