.---------------------------------------------------------------------------- .- .- ximodel.gsl - Generate Xitami models .- .- Copyright (c) 1991-2003 iMatix Corporation .- .- ------------------ GPL Licensed Source Code ------------------ .- iMatix makes this software available under the GNU General .- Public License (GPL) license for open source projects. For .- details of the GPL license please see www.gnu.org or read the .- file license.gpl provided in this package. .- .- This program is free software; you can redistribute it and/or .- modify it under the terms of the GNU General Public License as .- published by the Free Software Foundation; either version 2 of .- the License, or (at your option) any later version. .- .- This program is distributed in the hope that it will be useful, .- but WITHOUT ANY WARRANTY; without even the implied warranty of .- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .- GNU General Public License for more details. .- .- You should have received a copy of the GNU General Public .- License along with this program in the file 'license.gpl'; if .- not, write to the Free Software Foundation, Inc., 59 Temple .- Place - Suite 330, Boston, MA 02111-1307, USA. .- .- You can also license this software under iMatix's General Terms .- of Business (GTB) for commercial projects. If you have not .- explicitly licensed this software under the iMatix GTB you may .- only use it under the terms of the GNU General Public License. .- .- For more information, send an email to info@imatix.com. .- -------------------------------------------------------------- .---------------------------------------------------------------------------- .- .for [include] . xml to models from filename . for models.models . abort "$(filename) is not a valid include file - use " . endfor .endfor .for model where defined (source) . if defined (class) . for models.model as classmodel where name = model.class . for . as child . copy child to model . endfor . endfor . endif . echo "Building $(source).c..." . output "$(source).c" /*===========================================================================* * Name: $(source).c * * Title: $(title:) * * * * Generated: $(date) from $(script), using GSLgen. * * * * Copyright (c) 1991-2003 iMatix Corporation * ============================================================================*/ #include "smtdefn.h" /* SMT definitions */ #include "smthttpl.h" /* SMT HTTP functions */ #include "xixlog.h" #include "version.h" #define SERVER_NAME "$(name:)/" VERSION #define USAGE \\ "Syntax: $(source:) [options...]\\n" \\ "Options:\\n" \\ " -w directory Working directory for server\\n" \\ " -r directory Root directory for web pages (webpages)\\n" \\ " -c directory Directory for CGI programs (cgi-bin)\\n" \\ " -b portbase Shift HTTP port 80 by this value. E.g. to run\\n" \\ " $(name:) on port 5080, do '$(source) -b 5000'\\n" \\ " -f directory Root directory for FTP files (webpages)\\n" \\ " -q Quiet mode: no messages\\n" \\ " -s Server mode: run as background job\\n" \\ " -S Console mode: run as foreground job\\n" \\ " -t Trace all socket i/o operations to log file\\n" \\ " -v Show $(name:) version information\\n" \\ " -h Show summary of command-line options\\n" \\ "\\nThe order of arguments is not important. Switches and filenames\\n" \\ "are case sensitive. See documentation for detailed information.\\n" /* Prototypes for agents used by this Xitami model */ . for use . for models.agent where name = agent . if "$(proto?1)" <> "0" int $(name)_init (void); /* $(title:) */ . endif . endfor . endfor int main (int argc, char *argv []) { int argn; /* Argument number */ Bool args_ok = TRUE, /* Were the arguments okay? */ quiet_mode = FALSE; /* -q means suppress messages */ char *workdir, /* Working directory */ *rootdir, /* Default root directory */ *cgidir, /* CGI program directory */ *ftproot, /* Default FTP root directory */ *portbase, /* Value for IP portbase */ *background, /* -s means run in background */ **argparm; /* Argument parameter to pick-up */ /* First off, switch to user's id */ set_uid_user (); /* These are the arguments we may get on the command line */ workdir = NULL; rootdir = NULL; cgidir = NULL; portbase = NULL; background = NULL; ftproot = NULL; argparm = NULL; /* Argument parameter to pick-up */ for (argn = 1; argn < argc; argn++) { /* If argparm is set, we have to collect an argument parameter */ if (argparm) { if (*argv [argn] != '-') /* Parameter can't start with '-' */ { *argparm = strdupl (argv [argn]); argparm = NULL; } else { args_ok = FALSE; break; } } else if (*argv [argn] == '-') { switch (argv [argn][1]) { /* These switches take a parameter */ case 'w': argparm = &workdir; break; case 'r': argparm = &rootdir; break; case 'c': argparm = &cgidir; break; case 'b': argparm = &portbase; break; case 'f': argparm = &ftproot; break; /* These switches have an immediate effect */ case 'q': quiet_mode = TRUE; break; case 's': background = "1"; break; case 'S': background = "0"; break; case 't': smtsock_trace (TRUE); break; case 'v': coprintf (PRODUCT); coprintf (BUILDMODEL); coprintf (COPYRIGHT); coprintf ("Built on: %s", BUILDDATE); exit (EXIT_SUCCESS); case 'h': coprintf (SERVER_NAME); coprintf (COPYRIGHT); coprintf (USAGE); exit (EXIT_SUCCESS); /* Anything else is an error */ default: args_ok = FALSE; } } else { args_ok = FALSE; break; } } /* If there was a missing parameter or an argument error, quit */ if (argparm) { puts ("Argument missing - type '$(source) -h' for help"); exit (EXIT_FAILURE); } else if (!args_ok) { puts ("Invalid arguments - type '$(source) -h' for help"); exit (EXIT_FAILURE); } /* Set server working directory if necessary */ if (workdir && set_curdir (workdir)) { printf ("Can't work in '%s' - %s\\n", workdir, strerror (errno)); exit (EXIT_FAILURE); } /* Load configuration data, if any, into the config_table */ config = ini_dyn_load (NULL, "xitami.cfg"); ini_dyn_load (config, CONFIG ("server:defaults")); /* Initialise arguments, taking defaults from the config_table */ if (!rootdir) rootdir = CONFIG ("server:webpages"); if (!cgidir) cgidir = CONFIG ("server:cgi-bin"); if (!portbase) portbase = CONFIG ("server:portbase"); if (!background) background = CONFIG ("server:background"); if (!ftproot) ftproot = CONFIG ("ftp:root"); /* Now, handle the remaining arguments we got */ ip_portbase = atoi (portbase); if (quiet_mode) { fclose (stdout); /* Kill standard output */ fclose (stderr); /* and standard error */ } else { puts (SERVER_NAME); puts (COPYRIGHT); } if (*background == '1') { const char *background_args [] = { "-s", NULL }; puts ("Moving into the background"); if (process_server (NULL, NULL, argc, argv, background_args) != 0) { puts ("Backgrounding failed. Giving up."); exit (EXIT_FAILURE); } } /* Initialise the SMT kernel */ smt_init (); server_name = "$(name:)"; /* Load the agents we want to use */ . for use . for models.agent where name = agent . if defined (config) if (*CONFIG ("$(config)") == '1') $(name)_init ($(params?:)); /* $(title:) */ . else $(name)_init ($(params?:)); /* $(title:) */ . endif . endfor . endfor smt_exec_full (); /* Run SMT until completed */ smt_term (); /* Deallocate configuration symbol table */ sym_delete_table (config); /* Check that all memory was cleanly released */ mem_assert (); return (EXIT_SUCCESS); } .endfor model .- .for core . if defined (class) . for models.model as classmodel where name = core.class . for . as child . copy child to core . endfor . endfor . endif . echo "Building $(source).d..." . output "$(source).d" /* ----------------------------------------------------------------- Name: $(source).d Title: $(title:) Generated: $(date) from $(script), using GSLgen. -------------------------------------------------------------------*/ /* Define the agents we want to use */ . for use . for models.agent where name = agent . if "$(proto?1)" <> "0" int $(name)_init (void); /* $(title:) */ . endif . endfor . endfor .- . echo "Building $(source).i..." . output "$(source).i" /* ----------------------------------------------------------------- Name: $(source).i Title: $(title:) Generated: $(date) from $(script), using GSLgen. -------------------------------------------------------------------*/ /* Initialise the SMT kernel */ smt_init (); server_name = "$(name:)"; /* Load the agents we want to use */ . for use . for models.agent where name = agent . if defined (config) if (*CONFIG ("$(config)")) $(name)_init ($(params?:)); /* $(title:) */ . else $(name)_init ($(params?:)); /* $(title:) */ . endif . endfor . endfor .endfor core