tf5-5.0beta8/.git/
tf5-5.0beta8/.git/info/
tf5-5.0beta8/.git/logs/
tf5-5.0beta8/.git/logs/refs/heads/
tf5-5.0beta8/.git/objects/00/
tf5-5.0beta8/.git/objects/01/
tf5-5.0beta8/.git/objects/04/
tf5-5.0beta8/.git/objects/05/
tf5-5.0beta8/.git/objects/07/
tf5-5.0beta8/.git/objects/09/
tf5-5.0beta8/.git/objects/0a/
tf5-5.0beta8/.git/objects/0c/
tf5-5.0beta8/.git/objects/0e/
tf5-5.0beta8/.git/objects/12/
tf5-5.0beta8/.git/objects/13/
tf5-5.0beta8/.git/objects/14/
tf5-5.0beta8/.git/objects/16/
tf5-5.0beta8/.git/objects/17/
tf5-5.0beta8/.git/objects/19/
tf5-5.0beta8/.git/objects/1c/
tf5-5.0beta8/.git/objects/1d/
tf5-5.0beta8/.git/objects/1e/
tf5-5.0beta8/.git/objects/1f/
tf5-5.0beta8/.git/objects/20/
tf5-5.0beta8/.git/objects/21/
tf5-5.0beta8/.git/objects/23/
tf5-5.0beta8/.git/objects/27/
tf5-5.0beta8/.git/objects/29/
tf5-5.0beta8/.git/objects/2a/
tf5-5.0beta8/.git/objects/2b/
tf5-5.0beta8/.git/objects/2f/
tf5-5.0beta8/.git/objects/30/
tf5-5.0beta8/.git/objects/33/
tf5-5.0beta8/.git/objects/34/
tf5-5.0beta8/.git/objects/35/
tf5-5.0beta8/.git/objects/39/
tf5-5.0beta8/.git/objects/3c/
tf5-5.0beta8/.git/objects/3d/
tf5-5.0beta8/.git/objects/3f/
tf5-5.0beta8/.git/objects/40/
tf5-5.0beta8/.git/objects/41/
tf5-5.0beta8/.git/objects/42/
tf5-5.0beta8/.git/objects/44/
tf5-5.0beta8/.git/objects/46/
tf5-5.0beta8/.git/objects/47/
tf5-5.0beta8/.git/objects/48/
tf5-5.0beta8/.git/objects/4a/
tf5-5.0beta8/.git/objects/4d/
tf5-5.0beta8/.git/objects/4f/
tf5-5.0beta8/.git/objects/53/
tf5-5.0beta8/.git/objects/54/
tf5-5.0beta8/.git/objects/58/
tf5-5.0beta8/.git/objects/5b/
tf5-5.0beta8/.git/objects/5c/
tf5-5.0beta8/.git/objects/5e/
tf5-5.0beta8/.git/objects/5f/
tf5-5.0beta8/.git/objects/60/
tf5-5.0beta8/.git/objects/61/
tf5-5.0beta8/.git/objects/62/
tf5-5.0beta8/.git/objects/63/
tf5-5.0beta8/.git/objects/66/
tf5-5.0beta8/.git/objects/67/
tf5-5.0beta8/.git/objects/6c/
tf5-5.0beta8/.git/objects/6e/
tf5-5.0beta8/.git/objects/72/
tf5-5.0beta8/.git/objects/73/
tf5-5.0beta8/.git/objects/75/
tf5-5.0beta8/.git/objects/77/
tf5-5.0beta8/.git/objects/7a/
tf5-5.0beta8/.git/objects/7b/
tf5-5.0beta8/.git/objects/7c/
tf5-5.0beta8/.git/objects/7e/
tf5-5.0beta8/.git/objects/7f/
tf5-5.0beta8/.git/objects/81/
tf5-5.0beta8/.git/objects/84/
tf5-5.0beta8/.git/objects/86/
tf5-5.0beta8/.git/objects/87/
tf5-5.0beta8/.git/objects/88/
tf5-5.0beta8/.git/objects/8b/
tf5-5.0beta8/.git/objects/8c/
tf5-5.0beta8/.git/objects/8f/
tf5-5.0beta8/.git/objects/91/
tf5-5.0beta8/.git/objects/93/
tf5-5.0beta8/.git/objects/96/
tf5-5.0beta8/.git/objects/97/
tf5-5.0beta8/.git/objects/99/
tf5-5.0beta8/.git/objects/9a/
tf5-5.0beta8/.git/objects/9b/
tf5-5.0beta8/.git/objects/9c/
tf5-5.0beta8/.git/objects/9d/
tf5-5.0beta8/.git/objects/9e/
tf5-5.0beta8/.git/objects/a1/
tf5-5.0beta8/.git/objects/a3/
tf5-5.0beta8/.git/objects/a4/
tf5-5.0beta8/.git/objects/a6/
tf5-5.0beta8/.git/objects/a7/
tf5-5.0beta8/.git/objects/a8/
tf5-5.0beta8/.git/objects/a9/
tf5-5.0beta8/.git/objects/ab/
tf5-5.0beta8/.git/objects/ac/
tf5-5.0beta8/.git/objects/ae/
tf5-5.0beta8/.git/objects/b1/
tf5-5.0beta8/.git/objects/b2/
tf5-5.0beta8/.git/objects/b3/
tf5-5.0beta8/.git/objects/b7/
tf5-5.0beta8/.git/objects/b9/
tf5-5.0beta8/.git/objects/bb/
tf5-5.0beta8/.git/objects/bc/
tf5-5.0beta8/.git/objects/bd/
tf5-5.0beta8/.git/objects/bf/
tf5-5.0beta8/.git/objects/c0/
tf5-5.0beta8/.git/objects/c1/
tf5-5.0beta8/.git/objects/c2/
tf5-5.0beta8/.git/objects/c3/
tf5-5.0beta8/.git/objects/c5/
tf5-5.0beta8/.git/objects/c7/
tf5-5.0beta8/.git/objects/ca/
tf5-5.0beta8/.git/objects/ce/
tf5-5.0beta8/.git/objects/d1/
tf5-5.0beta8/.git/objects/d3/
tf5-5.0beta8/.git/objects/d4/
tf5-5.0beta8/.git/objects/d5/
tf5-5.0beta8/.git/objects/d8/
tf5-5.0beta8/.git/objects/d9/
tf5-5.0beta8/.git/objects/dc/
tf5-5.0beta8/.git/objects/dd/
tf5-5.0beta8/.git/objects/e1/
tf5-5.0beta8/.git/objects/e4/
tf5-5.0beta8/.git/objects/e5/
tf5-5.0beta8/.git/objects/e6/
tf5-5.0beta8/.git/objects/e7/
tf5-5.0beta8/.git/objects/e8/
tf5-5.0beta8/.git/objects/ea/
tf5-5.0beta8/.git/objects/eb/
tf5-5.0beta8/.git/objects/ed/
tf5-5.0beta8/.git/objects/ee/
tf5-5.0beta8/.git/objects/ef/
tf5-5.0beta8/.git/objects/f0/
tf5-5.0beta8/.git/objects/f4/
tf5-5.0beta8/.git/objects/f5/
tf5-5.0beta8/.git/objects/f6/
tf5-5.0beta8/.git/objects/f8/
tf5-5.0beta8/.git/objects/f9/
tf5-5.0beta8/.git/objects/fa/
tf5-5.0beta8/.git/objects/fb/
tf5-5.0beta8/.git/objects/fc/
tf5-5.0beta8/.git/objects/fd/
tf5-5.0beta8/.git/refs/heads/
tf5-5.0beta8/.git/refs/tags/
tf5-5.0beta8/autom4te.cache/
tf5-5.0beta8/macos/
tf5-5.0beta8/unix/
tf5-5.0beta8/win32/
/*************************************************************************
 *  TinyFugue - programmable mud client
 *  Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2004, 2005, 2006-2007 Ken Keys
 *
 *  TinyFugue (aka "tf") is protected under the terms of the GNU
 *  General Public License.  See the file "COPYING" for details.
 ************************************************************************/
static const char RCSid[] = "$Id: main.c,v 35004.115 2007/01/13 23:12:39 kkeys Exp $";


/***********************************************
 * Fugue main routine                          *
 *                                             *
 * Initializes many internal global variables, *
 * determines initial world (if any), reads    *
 * configuration file, and calls main loop in  *
 * socket.c                                    *
 ***********************************************/

#include "tfconfig.h"
#include "port.h"
#include "tf.h"
#include "util.h"
#include "pattern.h"	/* for tfio.h */
#include "search.h"
#include "tfio.h"
#include "history.h"
#include "world.h"
#include "socket.h"
#include "macro.h"
#include "output.h"
#include "attr.h"
#include "signals.h"
#include "command.h"
#include "keyboard.h"
#include "variable.h"
#include "tty.h"	/* no_tty */
#include "expand.h"
#include "expr.h"
#include "process.h"

const char sysname[] = UNAME;

/* For customized versions, please add a unique identifer (e.g., your initials)
 * to the version number, and put a brief description of the modifications
 * in the mods[] string.
 */
const char version[] =
#if DEVELOPMENT
    "DEVELOPMENT VERSION: "
#endif
    "TinyFugue version 5.0 beta 8";

const char mods[] = "";

const char copyright[] =
    "Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2004, 2005, 2006-2007 Ken Keys (kenkeys@users.sourceforge.net)";

const char contrib[] =
#ifdef PLATFORM_OS2
    "OS/2 support written by Andreas Sahlbach (asa@stardiv.de)";
#else
    "";
#endif

int restriction = 0;
int debug = 0;

static void read_configuration(const char *fname);
int main(int argc, char **argv);

int main(int argc, char *argv[])
{
    char *opt, *argv0 = argv[0];
    char *configfile = NULL, *command = NULL, *libdir = NULL;
    int worldflag = TRUE;
    int autologin = -1, quietlogin = -1, autovisual = TRUE;
    String *scratch;

    puts("");
    puts(version);
    puts(copyright);

    while (--argc > 0 && (*++argv)[0] == '-') {
        if (!(*argv)[1]) { argc--; argv++; break; }
        for (opt = *argv + 1; *opt; )
            switch (*opt++) {
            case 'd':
                debug = TRUE;
                break;
            case 'l':
                autologin = FALSE;
                break;
            case 'q':
                quietlogin = TRUE;
                break;
            case 'n':
                worldflag = FALSE;
                break;
            case 'v':
                autovisual = FALSE;
                break;
            case 'f':
                configfile = opt;
                goto nextarg;
            case 'c':
                command = opt;
                goto nextarg;
            case 'L':
                libdir = opt;
                goto nextarg;
            default:
                fprintf(stderr, "\n%s: illegal option -- %c\n", argv0, *--opt);
                goto error;
            }
        nextarg: /* empty statement */;
    }
    if (argc > 2) {
    error:
        fputs("\n", stderr);
        fprintf(stderr, "Usage: %s [-L<dir>] [-f[<file>]] [-c<cmd>] [-vnlq] [<world>]\n", argv0);
        fprintf(stderr, "       %s [-L<dir>] [-f[<file>]] [-c<cmd>] [-vlq] <host> <port>\n", argv0);
        fputs("Options:\n", stderr);
        fputs("  -L<dir>   use <dir> as library directory (%TFLIBDIR)\n", stderr);
        fputs("  -f        don't load personal config file (.tfrc)\n", stderr);
        fputs("  -f<file>  load <file> instead of config file\n", stderr);
        fputs("  -c<cmd>   execute <cmd> after loading config file\n", stderr);
        fputs("  -n        no automatic first connection\n", stderr);
        fputs("  -l        no automatic login/password\n", stderr);
        fputs("  -q        quiet login\n", stderr);
        fputs("  -v        no automatic visual mode\n", stderr);
        fputs("Arguments:\n", stderr);
        fputs("  <host>    hostname or IP address\n", stderr);
        fputs("  <port>    port number or name\n", stderr);
        fputs("  <world>   connect to <world> defined by addworld()\n", stderr);
        fputs("\n", stderr);
        exit(1);
    }

#if SOCKS
    SOCKSinit(argv0);  /* writes message to stdout */
#endif
    init_exename(argv0);

    SRAND(getpid() + time(NULL));	/* seed random generator */
    init_malloc();			/* malloc.c   */
    init_tfio();			/* tfio.c     */
    init_util1();			/* util.c     */
    init_expand();			/* expand.c   */
    init_variables();			/* variable.c */
    init_signals();			/* signals.c  */
    init_sock();			/* socket.c   */
    init_macros();			/* macro.c    */
    init_histories();			/* history.c  */
    init_output();			/* output.c   */
    init_attrs();			/* attr.c     */
    init_keyboard();			/* keyboard.c */

    oputs(version);
    oputs(copyright);
    oputs("Type `/help copyright' for more information.");
    if (*contrib) oputs(contrib);
    if (*mods) oputs(mods);
    oprintf("Using PCRE version %s", pcre_version());
    oputs("Type `/help', `/help topics', or `/help intro' for help.");
    oputs("Type `/quit' to quit tf.");
    oputs("");

    init_util2();			/* util.c     */

    if (libdir) {
        set_str_var_by_name("TFLIBDIR", Stringnew(libdir, -1, 0));
    }
    if (!ffindglobalvar("TFLIBRARY")) {
        scratch = Stringnew(NULL, 0, 0);
        Sprintf(scratch, "%s/stdlib.tf", TFLIBDIR);
        set_str_var_by_name("TFLIBRARY", scratch);
    }
    if (!ffindglobalvar("TFHELP")) {
        scratch = Stringnew(NULL, 0, 0);
        Sprintf(scratch, "%s/tf-help", TFLIBDIR);
        set_str_var_by_name("TFHELP", scratch);
    }

    read_configuration(configfile);

    if (command) {
	String *scmd;
	(scmd = Stringnew(command, -1, 0))->links++;
        macro_run(CS(scmd), 0, NULL, 0, sub, "\bSTART");
	Stringfree(scmd);
    }

    /* If %visual was not explicitly set, set it now. */
    if (getintvar(VAR_visual) < 0 && !no_tty)
        set_var_by_id(VAR_visual, autovisual);

    /* If %interactive was not explicitly set, set it now. */
    if (getintvar(VAR_interactive) < 0)
        set_var_by_id(VAR_interactive, !no_tty);

    if (argc > 0 || worldflag) {
	int flags = 0;
        if (autologin < 0) autologin = login;
        if (quietlogin < 0) quietlogin = quietflag;
	if (autologin) flags |= CONN_AUTOLOGIN;
	if (quietlogin) flags |= CONN_QUIETLOGIN;
        if (argc == 0)
            openworld(NULL, NULL, flags);
        else if (argc == 1)
            openworld(argv[0], NULL, flags);
        else /* if (argc == 2) */
            openworld(argv[0], argv[1], flags);
    } else {
        world_hook("---- No world ----", NULL);
    }

    main_loop();

    kill_procs();
#if USE_DMALLOC
    free_screen_lines(default_screen);
#endif
    minimal_fix_screen();
    reset_tty();

#if USE_DMALLOC
    free_macros();
    free_worlds();
    free_histories();
    free_output();
    free_vars();
    free_keyboard();
    free_search();
    free_expand();
    free_expr();
    free_help();
    free_util();
    free_patterns();
    free_dstring();
    free_reserve();
    fflush(stdout);
    fflush(stderr);
    debug_mstats("tf");
#endif

    return 0;
}

static void read_configuration(const char *fname)
{
#if 1 /* XXX */
    if (do_file_load(getvar("TFLIBRARY"), FALSE) < 0)
        die("Can't read required library.", 0);
#endif

    if (fname) {
        if (*fname) do_file_load(fname, FALSE);
        return;
    }

    (void)(   /* ignore value of expression */
	/* Try the next file if a file can't be read, but not if there's
	 * an error _within_ a file. */
        do_file_load("~/.tfrc", TRUE) >= 0 ||
        do_file_load("~/tfrc",  TRUE) >= 0 ||
        do_file_load("./.tfrc", TRUE) >= 0 ||
        do_file_load("./tfrc",  TRUE)
    );

    /* support for old fashioned .tinytalk files */
    do_file_load((fname = getvar("TINYTALK")) ? fname : "~/.tinytalk", TRUE);
}