/*
 * File automatically generated by
 * gengen 1.4.3 by Lorenzo Bettini 
 * http://www.gnu.org/software/gengen
 */

#include "generic_option.h"

void
generic_option_gen_class::generate_generic_option(ostream &stream, unsigned int indent)
{
  string indent_str (indent, ' ');
  indent = 0;

  if (has_short_option)
    {
      stream << "case '";
      generate_string (short_option, stream, indent + indent_str.length ());
      stream << "':	/* ";
      generate_string (option_comment, stream, indent + indent_str.length ());
      stream << ".  */";
      stream << "\n";
      stream << indent_str;
      if (( short_option == "?" ))
        {
          stream << "\n";
          stream << indent_str;
          stream << "  if (optopt) /* '?' represents an unrecognized option */";
          stream << "\n";
          stream << indent_str;
          stream << "    goto failure;";
          stream << "\n";
          stream << indent_str;
        }
    }
  else
    {
      stream << "/* ";
      generate_string (option_comment, stream, indent + indent_str.length ());
      stream << ".  */";
      stream << "\n";
      stream << indent_str;
      generate_string (gen_else, stream, indent + indent_str.length ());
      stream << "if (strcmp (long_options[option_index].name, \"";
      generate_string (long_option, stream, indent + indent_str.length ());
      stream << "\") == 0)";
      stream << "\n";
      stream << indent_str;
      stream << "{";
      stream << "\n";
      stream << indent_str;
    }
  if (option_has_mode)
    {
      stream << "  args_info->";
      generate_string (group_var_name, stream, indent + indent_str.length ());
      stream << "_mode_counter += 1;";
      stream << "\n";
      stream << indent_str;
    }
  stream << "\n";
  stream << indent_str;
  if (multiple)
    {
      if (option_has_type)
        {
          stream << "  if (update_multiple_arg_temp(&";
          generate_string (structure, stream, indent + indent_str.length ());
          stream << ", ";
          stream << "\n";
          stream << indent_str;
          stream << "      &(local_args_info.";
          generate_string (option_var_name, stream, indent + indent_str.length ());
          stream << "_given), optarg, ";
          generate_string (possible_values, stream, indent + indent_str.length ());
          stream << ", ";
          generate_string (default_value, stream, indent + indent_str.length ());
          stream << ", ";
          generate_string (arg_type, stream, indent + indent_str.length ());
          stream << ",";
          stream << "\n";
          stream << indent_str;
          stream << "      \"";
          generate_string (long_option, stream, indent + indent_str.length ());
          stream << "\", '";
          generate_string (short_option, stream, indent + indent_str.length ());
          stream << "',";
          stream << "\n";
          stream << indent_str;
          stream << "      additional_error))";
          stream << "\n";
          stream << indent_str;
          stream << "    goto failure;";
          stream << "\n";
          stream << indent_str;
        }
      else
        {
          stream << "  local_args_info.";
          generate_string (option_var_name, stream, indent + indent_str.length ());
          stream << "_given++;";
          stream << "\n";
          stream << indent_str;
        }
      if (option_has_group)
        {
          stream << "  if (!args_info->";
          generate_string (option_var_name, stream, indent + indent_str.length ());
          stream << "_group)";
          stream << "\n";
          stream << indent_str;
          stream << "    {";
          stream << "\n";
          stream << indent_str;
          stream << "      args_info->";
          generate_string (option_var_name, stream, indent + indent_str.length ());
          stream << "_group = 1;";
          stream << "\n";
          stream << indent_str;
          stream << "      args_info->";
          generate_string (group_var_name, stream, indent + indent_str.length ());
          stream << "_group_counter += 1;";
          stream << "\n";
          stream << indent_str;
          stream << "    }";
          stream << "\n";
          stream << indent_str;
        }
    }
  else
    {
      if (option_has_group)
        {
          stream << "  if (args_info->";
          generate_string (group_var_name, stream, indent + indent_str.length ());
          stream << "_group_counter && override)";
          stream << "\n";
          stream << indent_str;
          stream << "    reset_group_";
          generate_string (group_var_name, stream, indent + indent_str.length ());
          stream << " (args_info);";
          stream << "\n";
          stream << indent_str;
          stream << "  args_info->";
          generate_string (group_var_name, stream, indent + indent_str.length ());
          stream << "_group_counter += 1;";
          stream << "\n";
          stream << indent_str;
        }
      stream << "\n";
      stream << indent_str;
      if (( arg_type == "ARG_FLAG" ))
        {
          stream << "  if (update_arg((void *)&(args_info->";
          generate_string (option_var_name, stream, indent + indent_str.length ());
          stream << "_flag), 0, &(args_info->";
          generate_string (option_var_name, stream, indent + indent_str.length ());
          stream << "_given),";
          stream << "\n";
          stream << indent_str;
          stream << "      &(local_args_info.";
          generate_string (option_var_name, stream, indent + indent_str.length ());
          stream << "_given), optarg, 0, 0, ";
          generate_string (arg_type, stream, indent + indent_str.length ());
          stream << ",";
          stream << "\n";
          stream << indent_str;
          stream << "      check_ambiguity, override, 1, 0, \"";
          generate_string (long_option, stream, indent + indent_str.length ());
          stream << "\", '";
          generate_string (short_option, stream, indent + indent_str.length ());
          stream << "',";
          stream << "\n";
          stream << indent_str;
          stream << "      additional_error))";
          stream << "\n";
          stream << indent_str;
          stream << "    goto failure;";
          stream << "\n";
          stream << indent_str;
        }
      else
        {
          stream << "  if (update_arg(";
          if (( arg_type == "ARG_NO" ))
            {
              stream << " 0 ";
            }
          else
            {
              stream << " (void *)&(args_info->";
              generate_string (option_var_name, stream, indent + indent_str.length ());
              stream << "_arg)";
            }
          stream << ", ";
          stream << "\n";
          stream << indent_str;
          indent = 6;
          stream << "      ";
          if (( arg_type == "ARG_NO" ))
            {
              stream << " 0 ";
            }
          else
            {
              stream << " &(args_info->";
              generate_string (option_var_name, stream, indent + indent_str.length ());
              stream << "_orig)";
            }
          stream << ", &(args_info->";
          generate_string (option_var_name, stream, indent + indent_str.length ());
          stream << "_given),";
          indent = 0;
          stream << "\n";
          stream << indent_str;
          stream << "      &(local_args_info.";
          generate_string (option_var_name, stream, indent + indent_str.length ());
          stream << "_given), optarg, ";
          generate_string (possible_values, stream, indent + indent_str.length ());
          stream << ", ";
          generate_string (default_value, stream, indent + indent_str.length ());
          stream << ", ";
          generate_string (arg_type, stream, indent + indent_str.length ());
          stream << ",";
          stream << "\n";
          stream << indent_str;
          stream << "      check_ambiguity, override, 0, 0,";
          stream << "\n";
          stream << indent_str;
          stream << "      \"";
          generate_string (long_option, stream, indent + indent_str.length ());
          stream << "\", '";
          generate_string (short_option, stream, indent + indent_str.length ());
          stream << "',";
          stream << "\n";
          stream << indent_str;
          stream << "      additional_error))";
          stream << "\n";
          stream << indent_str;
          stream << "    goto failure;";
          stream << "\n";
          stream << indent_str;
        }
      if (( final_instructions != "" ))
        {
          indent = 2;
          stream << "  ";
          generate_string (final_instructions, stream, indent + indent_str.length ());
          indent = 0;
          stream << "\n";
          stream << indent_str;
        }
    }
  if (has_short_option)
    {
      stream << "\n";
      stream << indent_str;
      stream << "  break;";
    }
  else
    {
      stream << "\n";
      stream << indent_str;
      stream << "}";
      stream << "\n";
      stream << indent_str;
    }
}
