home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games (Alt) / INFESPGAMES.iso / os2 / backgam / source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-25  |  4.3 KB  |  142 lines

  1. /*************************************************************
  2.  *    ______                                                 *
  3.  *   /     /\  TinyFugue was derived from a client initially *
  4.  *  /   __/  \ written by Anton Rang (Tarrant) and later     *
  5.  *  |  / /\  | modified by Leo Plotkin (Grod).  The early    *
  6.  *  |  |/    | versions of TinyFugue written by Greg Hudson  *
  7.  *  |  X__/  | (Explorer_Bob).  The current version is       *
  8.  *  \ /      / written and maintained by Ken Keys (Hawkeye), *
  9.  *   \______/  who can be reached at kkeys@ucsd.edu.         *
  10.  *                                                           *
  11.  *             No copyright 1992, no rights reserved.        *
  12.  *             Fugue is in the public domain.                *
  13.  *************************************************************/
  14.  
  15. /***********************************************
  16.  * Fugue main routine                          *
  17.  *                                             *
  18.  * Initializes many internal global variables, *
  19.  * determines initial world (if any), reads    *
  20.  * configuration file, and calls main loop in  *
  21.  * socket.c                                    *
  22.  ***********************************************/
  23.  
  24. #include <stdio.h>
  25. #include <ctype.h>
  26. #include "tf.h"
  27. #include "dstring.h"
  28. #include "util.h"
  29. #include "history.h"
  30. #include "world.h"
  31. #include "socket.h"
  32. #include "macro.h"
  33. #include "output.h"
  34. #include "signal.h"
  35. #include "keyboard.h"
  36. #include "command1.h"
  37. #include "command2.h"
  38.  
  39. char version[] = "TinyFugue version 2.1 beta 2 (FIBS patch 1.003)";
  40. static int autologin = TRUE;
  41.  
  42. static void   FDECL(read_configuration,(char *fname));
  43. static World *FDECL(boot_world,(int argc, char *argv[]));
  44.  
  45. int main(argc, argv)
  46.     int argc;
  47.     char *argv[];
  48. {
  49.     char *opt, *argv0 = argv[0], *configfile = NULL;
  50.     int opterror = FALSE;
  51.     int worldflag = TRUE;
  52.  
  53.     while (--argc > 0 && (*++argv)[0] == '-') {
  54.         for (opt = *argv + 1; *opt; )
  55.             switch (*opt++) {
  56.             case 'l':
  57.                 autologin = FALSE;
  58.                 break;
  59.             case 'n':
  60.                 worldflag = FALSE;
  61.                 break;
  62.             case 'f':
  63.                 if (configfile) FREE(configfile);
  64.                 configfile = STRDUP(opt);
  65.                 while (*opt) opt++;
  66.                 break;
  67.             default:
  68.                 opterror = TRUE;
  69.                 break;
  70.             }
  71.     }
  72.     if (opterror || argc > 2) {
  73.         char usage[256];
  74.         sprintf(usage,
  75.             "Usage: %s [-f<file>] [-ln] [<world>]\n       %s [-f<file>] <host> <port>\n",
  76.             argv0, argv0);
  77.         die(usage);
  78.     }
  79.  
  80.     init_table();                            /* util.c     */
  81.     init_signals();                          /* signal.c   */
  82.     init_term();                             /* output.c   */
  83.     init_histories();                        /* history.c  */
  84.     init_prefixes();                         /* command2.c */
  85.     init_macros();                           /* macro.c    */
  86. #ifndef BSD
  87.     srand(getpid());
  88. #else
  89.     srandom(getpid());
  90. #endif
  91.     init_keyboard();                         /* keyboard.c */
  92.     oprintf("Welcome to %s", version);
  93.     read_configuration(configfile);
  94.     main_loop(worldflag ? boot_world(argc, argv) : NULL, autologin);
  95.     return 0;
  96. }
  97.  
  98. static World *boot_world(argc, argv)
  99.     register int argc;
  100.     register char *argv[];
  101. {
  102.     World *temp;
  103.  
  104.     if (argc == 0)
  105.         temp = get_world_header();
  106.     else if (argc == 1) {
  107.         if ((temp = find_world(argv[0])) == NULL)
  108.             oprintf("%% The world %s is unknown.",argv[0]);
  109.     } else { /* (argc <= 2) guaranteed by main() */
  110.         temp = new_world("(unnamed)", "", "", argv[0], argv[1], "");
  111.         temp->flags |= WORLD_TEMP;
  112.     }
  113.     return temp;
  114. }
  115.  
  116. static void read_configuration(fname)
  117.     char *fname;
  118. {
  119.     Stringp filename;
  120.     TFILE *file;
  121.  
  122.     do_file_load(TFLIBRARY);
  123.  
  124.     if (fname) {
  125.         if (*fname) do_file_load(fname);
  126.         return;
  127.     }
  128.  
  129.     do_file_load(PRIVATEINIT);
  130.  
  131.     Stringinit(filename);
  132.     Stringcpy(filename, (fname = getenv("TINYTALK")) ? fname : CONFIGFILE);
  133.     Stringexpand(filename);
  134.     if (file = tfopen(filename->s, NULL, "r")) {
  135.         do_hook(H_LOAD, "%% Loading commands from %S.", "%S", filename);
  136.         read_file_commands(file, TRUE);
  137.         tfclose(file);
  138.     }
  139.     Stringfree(filename);
  140. }
  141.  
  142.