Changeset 4642


Ignore:
Timestamp:
2003-06-13T12:24:12+12:00 (21 years ago)
Author:
sjboddie
Message:

Added command line arguments to server.exe so the GLI can tell it to use
an alternative config file.

Location:
trunk/gsdl/src/w32server
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/w32server/fnord.cpp

    r4339 r4642  
    631631   
    632632    find_location();
    633     strcpy (winsockpath, data_location);
     633    char *data_location_c = data_location.getcstr();
     634    strcpy (winsockpath, data_location_c);
     635    delete data_location_c;
    634636   
    635637    // remove all the slashes at the end of billpath
     
    824826}
    825827
     828// possible command line options are
     829// --location=directory (the path to GSDLHOME which defaults to the
     830// directory where server.exe lives)
     831// --config=file (the path to the configuration file to use which defaults
     832// to GSDLHOME\gsdlsite.cfg)
     833static void parse_args(const text_t cmdline, text_t &location, text_t &config_file) {
     834
     835  location.clear();
     836  config_file.clear();
     837
     838  if (cmdline.size() < 3) return;
     839
     840  text_t name, val;
     841  bool foundname = false;
     842  text_t::const_iterator here = cmdline.begin();
     843  text_t::const_iterator end = cmdline.end();
     844  while (here != end) {
     845    if (*here == '-' && ((here+1) != end) && (*(here+1) == '-')) {
     846      here++;
     847      if (name == "location") {
     848    location = val;
     849      } else if (name == "config") {
     850    config_file = val;
     851      }
     852      foundname = false;
     853      name.clear();
     854      val.clear();
     855    } else if (*here == '=') {
     856      foundname = true;
     857    } else {
     858      if (foundname) {
     859    val.push_back(*here);
     860      } else {
     861    name.push_back(*here);
     862      }
     863    }
     864    here++;
     865  }
     866  if (name == "location") {
     867    location = val;
     868  } else if (name == "config") {
     869    config_file = val;
     870  }
     871}
     872
    826873
    827874int __stdcall WinMain(HINSTANCE Instance, HINSTANCE /*PrevInstance*/, LPSTR CmdLineStr, int /*CmdShow*/) {
    828875  HWND MainWindow;  MSG Message;  WNDCLASS MainClass; 
    829  
     876
     877  // parse arguments
     878  text_t location, config_file;
     879  parse_args(CmdLineStr, location, config_file);
     880  gsdl_conffile = config_file;
     881
    830882  //Create a window class
    831883  MainClass.style = CS_HREDRAW | CS_VREDRAW;
     
    865917 
    866918  ShowWindow(MainWindow, SW_SHOW);
    867   set_location(CmdLineStr);
     919  set_location(location);
    868920 
    869921  // get ready to draw the main window
  • trunk/gsdl/src/w32server/locate.cpp

    r2286 r4642  
    4141
    4242static int location_found=0;
    43 char data_location[MAX_FILENAME_SIZE];
    44 
    45 void set_location(char *possible)
     43text_t data_location;
     44
     45void set_location(text_t possible)
    4646{
    4747  if (location_found != 0) return;
    48   if (possible != NULL && *possible != 0) {
    49     strcpy(data_location, possible);
    50     if (data_location[strlen(data_location)-1] != '\\')
    51       strcat(data_location,"\\");
     48  if (!possible.empty()) {
     49    data_location = possible;
     50    if (*(data_location.end()-1) != '\\') {
     51      data_location.push_back('\\');
     52    }
    5253    location_found = 1;
    5354  }
     
    5657void find_location(void)
    5758{
     59  if (location_found != 0) return;
     60 
     61  char here[MAX_FILENAME_SIZE];
    5862  char *send;
    59   if (location_found != 0) return;
    60   if (GetModuleFileName(NULL,data_location,MAX_FILENAME_SIZE) <= 0)
    61     send = data_location;
    62   else {
    63     send = strrchr(data_location,'\\');
    64     if (send != NULL)
     63
     64  if (GetModuleFileName(NULL,here,MAX_FILENAME_SIZE) <= 0) {
     65    // failed
     66    data_location.clear();
     67  } else {
     68    send = strrchr(here,'\\');
     69    if (send != NULL) {
    6570      send++;
    66     else {
    67       send = strchr(data_location,':');
    68       if (send != NULL)
     71    } else {
     72      send = strchr(here,':');
     73      if (send != NULL) {
    6974        send++;
    70       else
    71         send == data_location;
    72       }
    73     }
     75      } else {
     76        send = here;
     77      }
     78    }
     79  }
    7480  *send = 0;
     81  data_location.setcstr(here);
    7582  location_found = 1;
    7683}
  • trunk/gsdl/src/w32server/locate.h

    r2286 r4642  
    3030#endif
    3131
     32#include "text_t.h"
     33
    3234extern HWND GSDL_Window;
    3335extern int line_spacing;
     
    3638void refresh_console(HDC dc);
    3739
    38 extern char data_location[MAX_FILENAME_SIZE];
     40extern text_t data_location;
    3941
    40 extern void set_location(char *possible);
     42extern void set_location(text_t possible);
    4143extern void find_location(void);
    4244
  • trunk/gsdl/src/w32server/settings.cpp

    r4339 r4642  
    2727
    2828#include "text_t.h"
     29#include "fileutil.h"
    2930
    3031#if defined(GSDL_USE_OBJECTSPACE)
     
    6364char gsdl_browser_exe[MAX_FILENAME_SIZE] = "";
    6465text_t gsdl_url;
     66text_t gsdl_conffile;
    6567int gsdl_start_browser = 1;
    6668
     
    269271
    270272void write_settings (const text_t url) {
    271   char conffile[MAX_FILENAME_SIZE];
    272  
    273   strcpy (conffile, data_location);
    274   remove_end_slashes (conffile);
    275   strcat (conffile, "\\gsdlsite.cfg");
    276  
    277   ofstream fout (conffile);
     273 
     274  if (gsdl_conffile.empty()) {
     275    find_location();
     276    gsdl_conffile = filename_cat(data_location, "gsdlsite.cfg");
     277  }
     278
     279  char *conffile_c = gsdl_conffile.getcstr();
     280  ofstream fout (conffile_c);
     281  delete conffile_c;
    278282  if (fout) {
    279283   
     
    397401
    398402void read_settings (int netscapeneeded) {
    399   char conffile[MAX_FILENAME_SIZE];
    400  
    401   find_location();
    402  
    403   strcpy (conffile, data_location);
    404   remove_end_slashes (conffile);
    405   strcat (conffile, "\\gsdlsite.cfg");
     403 
     404  if (gsdl_conffile.empty()) {
     405    find_location();
     406    gsdl_conffile = filename_cat(data_location, "gsdlsite.cfg");
     407  }
    406408 
    407409  // set up defaults
     
    410412  text_t key, value, section;
    411413  char *cstr_value;
     414  char *conffile_c = gsdl_conffile.getcstr();
    412415#if defined (GSDL_USE_IOS_H)
    413   ifstream conf (conffile, ios::nocreate);
     416  ifstream conf (conffile_c, ios::nocreate);
    414417#else
    415   ifstream conf (conffile);
     418  ifstream conf (conffile_c);
    416419#endif
     420  delete conffile_c;
    417421  if (conf) {
    418422    while (read_ini_line(conf, key, value) >= 0) {
  • trunk/gsdl/src/w32server/settings.h

    r4339 r4642  
    5858extern char gsdl_browser_exe[MAX_FILENAME_SIZE];
    5959extern text_t gsdl_url;
     60extern text_t gsdl_conffile;
    6061extern int gsdl_start_browser;
    6162
Note: See TracChangeset for help on using the changeset viewer.