.- .- adfgen.gsl - GSL script to generate brokers .- .- 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 server .echo "Generating broker program $(name).c..." .output "$(name).c" /*============================================================================ * * $(name) - $(title) broker * Generated by adfgen from $(script) on $(date), $(time). * .if model = "wtp" * WTP broker - must be run from Xitami/Studio. .else * CGI broker - run as CGI command. .endif * *===========================================================================*/ #define USE_WTP_BROKER 1 #include "sfl.h" /* SFL prototypes & definitions */ #include "formio.h" /* Formio definitions */ .if model = "wtp" #include "wtplib.h" /* WTP definitions */ #include "wtpmsg.h" /* WTP message API */ #include "browtp.h" /* WTP broker definitions */ .else #include "brocgi.h" /* CGI broker definitions */ .endif .if model = "wtp" .- .- Generate main() function for WTP broker .- static void handle_signal (int the_signal); int main (int argc, char *argv []) { char *version, /* WTP version string */ *protocol, /* Protocol to use */ *port, /* Port number */ *callback; /* Callback key */ signal (SIGINT, handle_signal); signal (SIGTERM, handle_signal); console_set_mode (CONSOLE_DATETIME); if (argc < 4) { puts ("Must be run from WTP manager!"); exit (0); } else { version = argv [1]; protocol = argv [2]; port = argv [3]; callback = argv [4]; } wtp_open (version, protocol, port); wtp_connect (callback, argv [0]); .for program . if name = application.root wtp_register ("$(name)", 1); . else wtp_register ("$(name)", 0); . endif .endfor wtp_ready (); /* Pass to WTP manager */ wtp_broker (); return (EXIT_SUCCESS); } local handle_signal (int the_signal) { switch (the_signal) { case SIGINT: case SIGTERM: puts (" - interrupted"); break; } exit (1); } /* We must define each program that the broker contains, with a C * prototype and an entry in the broker map table. */ .for program int $(name)_program (SESSION *session); .endfor BROKER_MAP wtp_broker_map [] = { .for program { "$(name)", $(name)_program }, .endfor { NULL, NULL } }; /* This function initialises the broker and returns the name of the * application root program. */ char * wtp_root (void) { return ("$(root)"); } .- .- Generate main() function for CGI broker .- .else int main (int argc, char *argv []) { int rc, /* CGI broker return code */ read_size; /* Amount of data read from stdin */ char *uri_data, /* Arguments to URI (session key) */ *form_data = NULL; /* Posted form data, if any */ /* Collect URI request from argument [1] or from the environment */ if (argc > 1) uri_data = argv [1]; else uri_data = env_get_string ("QUERY_STRING", NULL); /* Collect query string from stdin if present */ if (env_get_number ("HTTP_CONTENT_LENGTH", 0) != 0) { read_size = (int) env_get_number ("HTTP_CONTENT_LENGTH", 0); form_data = mem_alloc (read_size + 1); read_size = fread (form_data, 1, read_size, stdin); form_data [read_size] = '\0'; } else form_data = mem_strdup (uri_data); /* Pass to Transaction Manager */ rc = cgi_broker (uri_data, form_data, "/cgi-bin/$(name)"); mem_free (form_data); return (rc); } /* We must define each program that the broker contains, with a C * prototype and an entry in the broker map table. */ .for program int $(name)_program (SESSION *session); .endfor BROKER_MAP cgi_broker_map [] = { .for program { "$(name)", $(name)_program }, .endfor { NULL, NULL } }; /* This function initialises the broker and returns the name of the * application root program. */ char * cgi_root (void) { return ("$(root)"); } .endif .close .for program .if !file.exists ("$(name).l") .output "$(name).l" .echo "Generating $(name).l..." !*===========================================================================* ! ! $(name).l ! ! Written: $(date) Your name ! Revised: $(date) Your name ! !*===========================================================================* -schema=lrstudio.c -opt:model=$(model) After-Init: (--) Ok -> Showing-Screen + (--) Error -> + Terminate-The-Program Showing-Screen: (--) Enter -> Showing-Screen + (--) Exit -> + Terminate-The-Program Defaults: (--) Exception -> + .close .endif .endfor program .endfor server