Summary

  This file contains 4 classes:
    ArgumentExpander
      which reads the command line arguments and stores them.
      It handles @file redirection so arguments can be in files.
    KeywordMap
      simple struct class that holds keyword information.
    OptionError
      simple class to store bad option information.
    Option
      storage class that reads the command line arguments from an
      ArgumentExpander class and sets class-public booleans.
  

Source

// $Id: option.h,v 1.6 1999/03/10 19:59:21 shields Exp $
copyright notice

#ifndef option_INCLUDED
#define option_INCLUDED

#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "bool.h"
#include "code.h"
#include "tuple.h"


ArgumentExpander is a utility class that programs can use to handle
command line processing. The command line is broken up into strings, some
of which can come from files. Files named on the command line are prefixed
with the character @ as in @filename. There are 3 methods, one for handling
main's standard arguments, one for handling internally generated command
lines and one for handling file input.

class ArgumentExpander
{
public:


These are the two standard arguments to main. Main's argument list is
deconstructed by ArgumentExpander and stored here. The argument list 
might have come from a file if one of the command line arguments begins
with an @. 

    int argc;
    char **argv;

ArgumentExpander is the primary constructor that processes command line
arguments. An example of use is:
  ArgumentExpander *arguments = new ArgumentExpander(argc, argv);
This will eventually be passed to the Option class constructor.

    ArgumentExpander::ArgumentExpander(int, char **);

ArgumentExpander can be used internally to parse a line that contains
command line style arguments. This would be useful for constructing argument
lists for further function calls.

    ArgumentExpander(Tuple<char> &);

~ArgumentExpander will free the storage held by argv.

    ~ArgumentExpander()
    {
        for (int i = 0; i < argc; i++)
            delete [] argv[i];
        delete [] argv;
    }

ArgumentExpanded will interpret it's second argument as a filename and
will append arguments found in the file to the first argument. If the
first argument is NOT a file then this will return false.

    bool ArgumentExpanded(Tuple<char *> &, char *);
};


KeywordMap is a simple storage class for type information related to 
symbols. It is used by the +K= option on the command line.

class KeywordMap
{
public:
    wchar_t *name;
    int length,
        key;
};


OptionError is a storage class that saves information about failures
that occur during processing of command line options.

class OptionError
{
public:
    int kind;
    wchar_t *name;

    OptionError(int kind_, char *str) : kind(kind_)
    {
        int length = strlen(str);
        name = new wchar_t[length + 1];
        for (int i = 0; i < length; i++)
            name[i] = str[i];
        name[length] = U_NULL;

        return;
    }

    ~OptionError() { delete [] name; }
};


Option takes an ArgumentExpander class and sets boolean flags for
each of the options that have been selected.

class Option
{
#ifdef WIN32_FILE_SYSTEM


The Windows File System has the notion of a "current directory" associated
with each logical disk. The main_disk is the zeroth entry in the array of
current_directory. current_directory uses the int value of the character
code as it's index (efficient but crufty).

    char main_disk,
         *current_directory[128];

public:

If BadMainDisk returns true then we were unable to determine the correct
logical drive and path at startup.
    bool BadMainDisk() { return main_disk == 0; }

IsMainDisk is not used anywhere.
    bool IsMainDisk(char c) { return c != 0 && current_directory[c] == current_directory[main_disk]; }

    void SaveCurrentDirectoryOnDisk(char);

We have switched logical disks to we point at the current directory for that
disk
    void ResetCurrentDirectoryOnDisk(char d)
    {
        if (d != 0)
        {
assert(current_directory[d]);
            SetCurrentDirectory(current_directory[d]);
        }
    }

SetMainCurrentDirectory changes back to the logical drive and path
where we started. 
    void SetMainCurrentDirectory()
    {
        SetCurrentDirectory(current_directory[main_disk]);
    }

GetMainCurrentDirectory is a pwd (print working directory) command.
    char *GetMainCurrentDirectory()
    {
        return current_directory[main_disk];
    }
#endif

public:
    char *default_path,
         *classpath,
         *directory,
         *makefile_name;

    Tuple<KeywordMap> keyword_map;

    Tuple<OptionError *> bad_options;

    bool nowrite,
         deprecation,
         O,
         g,
         verbose,
         depend,
         nowarn,
         one_one,
         zero_defect;
    int first_file_index;

    bool debug_dump_lex,
         debug_dump_ast,
         debug_dump_class,
         debug_trap_op,
         applet_author,
         incremental,
         makefile,
         bytecode,
         full_check,
         unzip,
         dump_errors,
         errors,
         ascii, // used on EBCDIC systems to AVOID input translation from EBCDIC to ASCII
         comments,
         pedantic;

    Option(ArgumentExpander &);

    ~Option();
};

#endif /* option_INCLUDED */