Jabber WindowGram Client (JWGC)

Introduction Screenshots Installation Downloads
Documentation Browse Source Resources Project Site

Stable Version
-none-

Latest Version
beta5



Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

standard_ports.c

Go to the documentation of this file.
00001 /*
00002  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
00003  *      For copying and distribution information, see the file
00004  *      "mit-copyright.h".
00005  *
00006  *      Modified for jwgc by Daniel Henninger.
00007  */
00008 
00009 #include "mit-copyright.h"
00010 
00011 /****************************************************************************/
00012 /* */
00013 /* Code to setup standard ports:                     */
00014 /* */
00015 /****************************************************************************/
00016 
00017 #include "port.h"
00018 #include "variables.h"
00019 #include "error.h"
00020 #include "main.h"
00021 
00022 extern string tty_filter();
00023 extern int tty_filter_init();
00024 
00025 #ifndef X_DISPLAY_MISSING
00026 extern char *X_driver();
00027 extern int X_driver_init();
00028 #endif
00029 
00030 extern void usage();
00031 
00032 /*
00033  *
00034  */
00035 
00036 char *
00037 plain_driver(input)
00038         string input;
00039 {
00040         string processed_input = tty_filter(input, 0);
00041 
00042         fputs(processed_input, stdout);
00043         fflush(stdout);
00044         free(processed_input);
00045         return (NULL);
00046 }
00047 
00048 /*
00049  *
00050  */
00051 
00052 char *
00053 tty_driver(input)
00054         string input;
00055 {
00056         string processed_input = tty_filter(input, 1);
00057 
00058         fputs(processed_input, stdout);
00059         fflush(stdout);
00060         free(processed_input);
00061         return (NULL);
00062 }
00063 
00064 /*
00065  *
00066  */
00067 
00068 string 
00069 noop_filter(input)
00070         string input;
00071 {
00072         return (input);
00073 }
00074 
00075 /*
00076  *
00077  */
00078 
00079 string 
00080 plain_filter(input)
00081         string input;
00082 {
00083         return (tty_filter(input, 0));
00084 }
00085 
00086 /*
00087  *
00088  */
00089 
00090 string 
00091 fancy_filter(input)
00092         string input;
00093 {
00094         return (tty_filter(input, 1));
00095 }
00096 
00097 /*
00098  *
00099  */
00100 
00101 static struct standard_port_info {
00102         char *port_name;
00103         /*
00104          * 0 = ok to use as the default output port
00105          * 1 = not ok to use as the default output port
00106          * 2 = disabled
00107          */
00108 #define DEFAULT_OK      0
00109 #define DEFAULT_NOTOK   1
00110 #define DISABLED        2
00111 
00112         int port_setup_status;
00113         int (*port_init) ();
00114 #define  INPUT_DESC  0
00115 #define  OUTPUT_DESC 1
00116 #define  FILTER      2
00117 #define  OUTPUT_PROC 3
00118         int type;
00119         char *(*function) ();
00120         int setup_arg;
00121 } standard_port_info_table[] = {
00122 #ifndef X_DISPLAY_MISSING
00123         {
00124                 "X", DEFAULT_OK, X_driver_init, OUTPUT_PROC, X_driver, 0
00125         },
00126         {
00127                 "tty", DEFAULT_NOTOK, tty_filter_init, OUTPUT_PROC, tty_driver, 0
00128         },
00129 #else
00130         {
00131                 "tty", DEFAULT_OK, tty_filter_init, OUTPUT_PROC, tty_driver, 0
00132         },
00133 #endif
00134         {
00135                 "plain", DEFAULT_NOTOK, tty_filter_init, OUTPUT_PROC, plain_driver, 0
00136         },
00137         {
00138                 "stdout", DEFAULT_NOTOK, NULL, OUTPUT_DESC, NULL, 1
00139         },
00140         {
00141                 "stderr", DEFAULT_NOTOK, NULL, OUTPUT_DESC, NULL, 2
00142         },
00143 
00144         {
00145                 "stdin", DEFAULT_NOTOK, NULL, INPUT_DESC, NULL, 0
00146         },
00147         {
00148                 "loopback", DEFAULT_NOTOK, NULL, FILTER, noop_filter, 0
00149         },
00150         {
00151                 "plain_filter", DEFAULT_NOTOK, tty_filter_init, FILTER, plain_filter, 0
00152         },
00153         {
00154                 "tty_filter", DEFAULT_NOTOK, tty_filter_init, FILTER, fancy_filter, 0
00155         },
00156 
00157         {
00158                 NULL, DISABLED, NULL, FILTER, NULL, 0
00159         }
00160 };
00161 
00162 /*
00163  * <<<>>>
00164  */
00165 
00166 static struct standard_port_info *
00167 get_standard_port_info(port_name)
00168         string port_name;
00169 {
00170         struct standard_port_info *p;
00171 
00172         for (p = standard_port_info_table; p->port_name; p++)
00173                 if (string_Eq(p->port_name, port_name) && p->port_setup_status != DISABLED)
00174                         return (p);
00175 
00176         return (NULL);
00177 }
00178 
00179 /*
00180  *
00181  */
00182 
00183 void 
00184 init_standard_ports(pargc, argv)
00185         int *pargc;
00186         char **argv;
00187 {
00188         struct standard_port_info *p;
00189         string first_working_port = "";
00190         string default_port = "";
00191         char **new, **current;
00192         int fallback = 0;
00193 
00194         /*
00195          * Process argument list handling "-disable <port>" and
00196          * "-default <output port>" arguments, as well as "-ttymode"
00197          */
00198         for (new = current = argv + 1; *current; current++) {
00199                 if (string_Eq((string) * current, "-disable")) {
00200                         current++;
00201                         *pargc -= 2;
00202                         if (!*current)
00203                                 usage();
00204                         if ((p = get_standard_port_info((string) * current)))
00205                                 p->port_setup_status = DISABLED;
00206                 }
00207                 else if (string_Eq((string) * current, "-default")) {
00208                         current++;
00209                         *pargc -= 2;
00210                         if (!*current)
00211                                 usage();
00212                         default_port = (string) * current;
00213                         if ((p = get_standard_port_info((string) * current)))
00214                                 p->port_setup_status = DEFAULT_OK;
00215                 }
00216                 else if (string_Eq((string) * current, "-ttymode")) {
00217                         default_port = (string) "tty";
00218                         (*pargc)--;
00219                         if ((p = get_standard_port_info(default_port))) {
00220                                 p->port_setup_status = DEFAULT_OK;
00221                                 if ((p = get_standard_port_info((string) "X")))
00222                                         p->port_setup_status = DISABLED;
00223                         }
00224                 }
00225                 else
00226                         *(new++) = *current;
00227         }
00228         *new = *current;
00229 
00230         /*
00231          * Initialize all non-disabled ports.  If a port reports an error,
00232          * disable that port.  Set default_port if not already set
00233          * by the -default argument to the first non-disabled port.
00234          */
00235         for (p = standard_port_info_table; p->port_name; p++) {
00236                 if (p->port_setup_status == DISABLED)
00237                         continue;
00238 
00239                 if (p->port_init && (*(p->port_init)) (p->port_name,
00240                                                        *first_working_port,
00241                                                        pargc, argv)) {
00242                         p->port_setup_status = DISABLED;
00243                         continue;
00244                 }
00245 
00246                 if (fallback == 1) {
00247                         /*
00248                          * we are doing fallback,  make DEFAULT_NOTOK ports
00249                          * OK
00250                          */
00251                         p->port_setup_status = DEFAULT_OK;
00252                 }
00253                 if (!*first_working_port)
00254                         first_working_port = p->port_name;
00255                 switch (p->type) {
00256                         case INPUT_DESC:
00257                                 create_port_from_files(p->port_name, fdopen(p->setup_arg, "r"), 0);
00258                                 break;
00259 
00260                         case OUTPUT_DESC:
00261                                 create_port_from_files(p->port_name, 0, fdopen(p->setup_arg, "w"));
00262                                 break;
00263 
00264                         case FILTER:
00265                                 create_port_from_filter(p->port_name, p->function);
00266                                 break;
00267 
00268                         case OUTPUT_PROC:
00269                                 create_port_from_output_proc(p->port_name, p->function);
00270                                 break;
00271                 }
00272         }
00273 
00274         if (!default_port[0]) {
00275                 /* no default port has been set */
00276                 for (p = get_standard_port_info(first_working_port); p->port_name; p++)
00277                         if ((p->port_setup_status == DEFAULT_OK))
00278                                 break;
00279                 if (p->port_name)
00280                         var_set_variable("output_driver", p->port_name);
00281                 else {          /* no suitable default has been found */
00282                         if (fallback == -1)     /* complain, since
00283                                                  * indeterminate */
00284                                 ERROR2(
00285                                        "To receive Jabbergrams, (type `%s -ttymode').\n",
00286                                        progname);
00287                         exit(1);
00288                 }
00289         }
00290         else
00291                 var_set_variable("output_driver", default_port);
00292 
00293 }


Last updated at Tue Dec 18 21:07:42 PST 2007. This site and project hosted by...SourceForge.net Logo
Source Perspective by Fisheye