//=-- Options.h - This class manages the MagicStats.cfg file -----------------=
//
//  By using the ConfigFile class, this class keeps track of the specific data
//    that resides in the MagicStats.cfg file.  This class is also responsible
//    for parsing the command line and for keeping track of all of the options
//    that the user selects.
//
//=---------------------------------------------------------------------------=
//  This file is copyright (c) 1997-2000 Chris Lattner
//=---------------------------------------------------------------------------=

#ifndef OPTIONS_H
#define OPTIONS_H

#include "Date.h"
#include "LinkedList.h"
#include "MSFilename.h"

// MAXUPDATEFREQ - Keep in sync with include/Plugin.h.  This hack is to avoid 
// adding a dependency from Options.h to Plugin.h...
//
#define MAXUPDATEFREQ 5

class CFileSection;
class VTExp;
template <class Key, class Value> class Table;

class MSOptions {
public :
  MSOptions() { 
    Verbose = Debug = Progress = PrintPlugins = PrintThemes = 0;
    MaxAccesses = CatchupAccessLog = -1;
  }

  int init(int argc, char *argv[]);
  inline static void SetDate(const Date &D) { CurDate = D; }

  static LinkedList<CFileSection> *ConfigFile;

  // Current State
  static Date CurDate;

  // Configuration flags...
  static int Verbose, Debug, Progress, PrintPlugins, PrintThemes;
  static int MaxAccesses;
  static int CatchupAccessLog;

  static CSString *ThemeToLint;  // Null, if not linting theme...

  // Static Options...
  static String  Version;
  static String  MagicStatsURL;
  static String  CurrentUserName;
  static Date    StartDate[MAXUPDATEFREQ]; // Date/Time MagicStats started...

  // Read from the server configuration file
  static String MagicStatsCfgFilename;     // Can be specified on command line
  static String DataFilename;

  // Server Settings
  static CSString AccessLogType;
  static VTExp *AccessLog;
  
  // Security Settings
  static int MinimumRefreshDelay;
  static int AllowAlternateLogs;
  static int AllowWebUserAdmin;
  static int AllowWebServerAdmin;
  static int AllowDynaStats;
  
  inline static String &GetBuiltInPluginResURL()  { return BuiltInURL; }
  inline static String &GetBuiltInPluginResPath() { return BuiltInPath; }
private :
  static String BuiltInPath, BuiltInURL;

  // PrintHelpMessage - Print the useful help message if the user specified 
  // '-h' on the command line...
  //
  static void PrintHelpMessage();

  // ProcessCommandLine - Incorporate the information in the command line into
  // the local variables in this Options object.
  //
  static int ProcessCommandLine(int argc, char *argv[]);

  // LoadServerConfig - If the server configuration file is available, load it 
  // and incorporate the settings in it into this Options object...
  //
  static int LoadServerConfig(const MSFilename &);

  // SetGlobalVariables - Add all of the standard global variables in the MS
  // namespace into the specified variable table.
  //
  void SetGlobalVariables(Table<CSString,VTExp*> &Vars);

  // LintTheme - Load and lint the specified theme.  This should be used by 
  // theme authors to make sure their themes are clean before distributing 
  // them.
  //
  void LintTheme(const String &ThemeName);
};

#endif
