コード例 #1
0
ファイル: main.c プロジェクト: Gr3yR0n1n/SAINTCON-2015-Badge
/**
 * \brief Callback of the HTTP client.
 *
 * \param[in]  module_inst     Module instance of HTTP client module.
 * \param[in]  type            Type of event.
 * \param[in]  data            Data structure of the event. \refer http_client_data
 */
static void http_client_callback(struct http_client_module *module_inst, int type, union http_client_data *data)
{
	switch (type) {
	case HTTP_CLIENT_CALLBACK_SOCK_CONNECTED:
		printf("Http client socket connected\r\n");
		break;

	case HTTP_CLIENT_CALLBACK_REQUESTED:
		printf("Request completed\r\n");
		add_state(GET_REQUESTED);
		break;

	case HTTP_CLIENT_CALLBACK_RECV_RESPONSE:
		printf("Received response %u data size %u\r\n",
				(unsigned int)data->recv_response.response_code,
				(unsigned int)data->recv_response.content_length);
		if ((unsigned int)data->recv_response.response_code == 200) {
			http_file_size = data->recv_response.content_length;
			received_file_size = 0;
		} 
		else {
			add_state(CANCELED);
			return;
		}

		break;

	case HTTP_CLIENT_CALLBACK_RECV_CHUNKED_DATA:
		store_file_packet(data->recv_chunked_data.data, data->recv_chunked_data.length);
		if (data->recv_chunked_data.is_complete) {
			add_state(COMPLETED);
		}

		break;

	case HTTP_CLIENT_CALLBACK_DISCONNECTED:
		printf("Disconnected reason:%d\r\n", data->disconnected.reason);

		/* If disconnect reason is equal to -ECONNRESET(-104),
		 * It means the server has closed the connection (timeout).
		 * This is normal operation.
		 */
		if (data->disconnected.reason == -EAGAIN) {
			/* Server has not responded. Retry immediately. */
			if (is_state_set(DOWNLOADING)) {
				f_close(&file_object);
				clear_state(DOWNLOADING);
			}

			if (is_state_set(GET_REQUESTED)) {
				clear_state(GET_REQUESTED);
			}

			start_download();
		}

		break;
	}
}
コード例 #2
0
ファイル: kb_mkbp.c プロジェクト: Basavaraja-MS/ec_local
int fifo_underrun(void)
{
	keyboard_clear_buffer();
	clear_state();
	TEST_ASSERT(press_key(0, 0, 1) == EC_SUCCESS);

	clear_state();
	TEST_ASSERT(verify_key(0, 0, 1));

	/* When FIFO under run, host command reutns last known state */
	TEST_ASSERT(verify_key(-1, -1, -1));

	return EC_SUCCESS;
}
コード例 #3
0
ファイル: compdic32hs.c プロジェクト: cisocrgroup/csl
void main (int argc, uchar **argv) {
    int i, j, c;
    struct stat f_stat;

    printf("compdic: Utility for compilation of word dictionaries\n");
    if (argc!=4) error("Usage:\ncompdic <alphabet> <text_dic> <comp_dic>");

    if ((fi=fopen(argv[1],"rb"))==NULL) error("Error opening alphabet file");
    memset(codes, 0, 256);
    for (letter_count=1; (c=getc(fi))>=' '; codes[c] = letter_count++) ;
    fclose(fi);

    stat(argv[2],&f_stat);
    init_mem(letter_count, f_stat.st_size + 50000);

    if ((fi=fopen(argv[2],"rb"))==NULL) error("Error opening input file");

    clear_state(0);
    owf[0]=0;

    wf1[0]=0;
    get_word_info(wf); // init of get_word_inf()

    while (get_word_info(wf)) {

        for (i=0; wf[i]==owf[i]; i++) ;		// find difference location

        for (j=strlen(owf)-1; j>=i; j--) state(j, codes[owf[j]]) = save_state(j+1);

        for (j=i+1; j<=strlen(wf); j++) clear_state(j);

        state(--j,0) = 1;

        strcpy(owf, wf);
    }
    fclose(fi);

    for (j=strlen(owf)-1; j>=0; j--) state(j, codes[owf[j]]) = save_state(j+1);

    save_cell(0, 'S', save_state(0));
    save_cell(1, 'T', last_full_cell+1);

    fo = fopen(argv[3], "wb");
    fwrite (cells, sizeof(tcell), last_full_cell+1, fo);
    fwrite (strings, 1, last_string, fo);
    fclose(fo);

    print_statistics();
}
コード例 #4
0
ファイル: game.cpp プロジェクト: Luminoth/eblocks
const bool game_init(Video* const video, Audio* const audio, struct State* const game_state, const int window_width, const int window_height, const int desired_bpp)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    std::cout << "Detected big endian" << std::endl;
#else
    std::cout << "Detected little endian" << std::endl;
#endif

    srand(time(NULL));

    if(!video->create_window(window_width, window_height, desired_bpp, "EBlocks"))
        return false;

    if(!audio->start())
        return false;

    Block::calc_size(video->width(), video->height(), Tetrion::NUM_ROWS, Tetrion::NUM_COLS, video->width()/3);

    clear_state(game_state);

    game_state->tetrion = new Tetrion();

    g_step_time = LEVEL_1;

    return true;
}
コード例 #5
0
ファイル: dut.c プロジェクト: coreboot/chrome-ec
void cts_task(void)
{
	enum cts_rc rc;
	int i;

	gpio_enable_interrupt(GPIO_CTS_IRQ1);
	gpio_enable_interrupt(GPIO_CTS_IRQ2);
	interrupt_enable();
	for (i = 0; i < CTS_TEST_ID_COUNT; i++) {
		clear_state();
		sync();
		rc = tests[i].run();
		interrupt_enable();
		CPRINTF("\n%s %d\n", tests[i].name, rc);
		cflush();
	}

	CPRINTS("Interrupt test suite finished");
	cflush();

	while (1) {
		watchdog_reload();
		sleep(1);
	}
}
コード例 #6
0
ファイル: kb_mkbp.c プロジェクト: Basavaraja-MS/ec_local
int test_fifo_size(void)
{
	keyboard_clear_buffer();
	clear_state();
	TEST_ASSERT(set_fifo_size(1));
	TEST_ASSERT(press_key(0, 0, 1) == EC_SUCCESS);
	TEST_ASSERT(press_key(0, 0, 0) == EC_ERROR_OVERFLOW);

	clear_state();
	TEST_ASSERT(verify_key(0, 0, 1));
	TEST_ASSERT(FIFO_EMPTY());

	/* Restore FIFO size */
	TEST_ASSERT(set_fifo_size(100));

	return EC_SUCCESS;
}
コード例 #7
0
ファイル: kb_mkbp.c プロジェクト: Basavaraja-MS/ec_local
int single_key_press(void)
{
	keyboard_clear_buffer();
	clear_state();
	TEST_ASSERT(press_key(0, 0, 1) == EC_SUCCESS);
	TEST_ASSERT(FIFO_NOT_EMPTY());
	TEST_ASSERT(press_key(0, 0, 0) == EC_SUCCESS);
	TEST_ASSERT(FIFO_NOT_EMPTY());

	clear_state();
	TEST_ASSERT(verify_key(0, 0, 1));
	TEST_ASSERT(FIFO_NOT_EMPTY());
	TEST_ASSERT(verify_key(0, 0, 0));
	TEST_ASSERT(FIFO_EMPTY());

	return EC_SUCCESS;
}
コード例 #8
0
ファイル: opt_context.cpp プロジェクト: killbug2004/Snippets
 void context::pop(unsigned n) {
     for (unsigned i = 0; i < n; ++i) {
         m_scoped_state.pop();
     }
     clear_state();
     reset_maxsmts();
     m_optsmt.reset();        
     m_hard_constraints.reset();
 }
コード例 #9
0
ファイル: lattr.c プロジェクト: bstreiff/joe-editor
void reset_all_lattr_db(struct lattr_db *db)
{
	struct lattr_db *n;
	for (n = db; n; n=n->next) {
		n->hole = 1;
		n->ehole = n->end;
		n->first_invalid = 1;
		n->invalid_window = -1;
		clear_state(n->buffer+0);
	}
}
コード例 #10
0
ファイル: main.c プロジェクト: Gr3yR0n1n/SAINTCON-2015-Badge
/**
 * \brief Callback to get the Wi-Fi status update.
 *
 * \param[in] u8MsgType type of Wi-Fi notification. Possible types are:
 *  - [M2M_WIFI_RESP_CURRENT_RSSI](@ref M2M_WIFI_RESP_CURRENT_RSSI)
 *  - [M2M_WIFI_RESP_CON_STATE_CHANGED](@ref M2M_WIFI_RESP_CON_STATE_CHANGED)
 *  - [M2M_WIFI_RESP_CONNTION_STATE](@ref M2M_WIFI_RESP_CONNTION_STATE)
 *  - [M2M_WIFI_RESP_SCAN_DONE](@ref M2M_WIFI_RESP_SCAN_DONE)
 *  - [M2M_WIFI_RESP_SCAN_RESULT](@ref M2M_WIFI_RESP_SCAN_RESULT)
 *  - [M2M_WIFI_REQ_WPS](@ref M2M_WIFI_REQ_WPS)
 *  - [M2M_WIFI_RESP_IP_CONFIGURED](@ref M2M_WIFI_RESP_IP_CONFIGURED)
 *  - [M2M_WIFI_RESP_IP_CONFLICT](@ref M2M_WIFI_RESP_IP_CONFLICT)
 *  - [M2M_WIFI_RESP_P2P](@ref M2M_WIFI_RESP_P2P)
 *  - [M2M_WIFI_RESP_AP](@ref M2M_WIFI_RESP_AP)
 *  - [M2M_WIFI_RESP_CLIENT_INFO](@ref M2M_WIFI_RESP_CLIENT_INFO)
 * \param[in] pvMsg A pointer to a buffer containing the notification parameters
 * (if any). It should be casted to the correct data type corresponding to the
 * notification type. Existing types are:
 *  - tstrM2mWifiStateChanged
 *  - tstrM2MWPSInfo
 *  - tstrM2MP2pResp
 *  - tstrM2MAPResp
 *  - tstrM2mScanDone
 *  - tstrM2mWifiscanResult
 */
static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
{
	switch (u8MsgType) {
	case M2M_WIFI_RESP_CON_STATE_CHANGED:
	{
		tstrM2mWifiStateChanged *pstrWifiState = (tstrM2mWifiStateChanged *)pvMsg;
		if (pstrWifiState->u8CurrState == M2M_WIFI_CONNECTED) {
			printf("Wi-Fi connected\r\n");
			m2m_wifi_request_dhcp_client();
		} else if (pstrWifiState->u8CurrState == M2M_WIFI_DISCONNECTED) {
			printf("Wi-Fi disconnected\r\n");
			clear_state(WIFI_CONNECTED);
			if (is_state_set(DOWNLOADING)) {
				f_close(&file_object);
				clear_state(DOWNLOADING);
			}

			if (is_state_set(GET_REQUESTED)) {
				clear_state(GET_REQUESTED);
			}

			m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID),
					MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL);
		}

		break;
	}

	case M2M_WIFI_REQ_DHCP_CONF:
	{
		uint8_t *pu8IPAddress = (uint8_t *)pvMsg;
		printf("Wi-Fi IP is %u.%u.%u.%u\r\n", pu8IPAddress[0], pu8IPAddress[1], pu8IPAddress[2], pu8IPAddress[3]);
		add_state(WIFI_CONNECTED);
		start_download();
		break;
	}

	default:
		break;
	}
}
コード例 #11
0
/*******************************************************************************
**
** Function         btif_hf_client_init
**
** Description     initializes the hf interface
**
** Returns         bt_status_t
**
*******************************************************************************/
static bt_status_t init( bthf_client_callbacks_t* callbacks )
{
    BTIF_TRACE_EVENT("%s", __FUNCTION__);

    bt_hf_client_callbacks = callbacks;

    btif_enable_service(BTA_HFP_HS_SERVICE_ID);

    clear_state();

    return BT_STATUS_SUCCESS;
}
コード例 #12
0
ファイル: backend.c プロジェクト: DruSatori/AEMud
static void
runtask(struct task *t)
{
    struct gdexception exception_frame;
    
    exception_frame.e_exception = NULL;
    exception_frame.e_catch = 0;
    exception = &exception_frame;
    clear_state();
    tmpclean(); 		/* Free all temporary memory */
    remove_destructed_objects(); /* marion - before ref checks! */
    eval_cost = 0;

    if (setjmp(exception_frame.e_context) == 0) {
	t->fkn(t->arg);
    }
    clear_state();
    tmpclean(); 		/* Free all temporary memory */
    remove_destructed_objects(); /* marion - before ref checks! */
    eval_cost = 0;
}
コード例 #13
0
ファイル: Enemy.cpp プロジェクト: RKX1209/Dnscript
Enemy::Enemy() : speed(0),life(0),bomb_num(0),graze(0),
                  move_frame(0), state(0){
  api = Api::instance();
  keyboard = Keyboard::instance();
  frame = Frame::instance();
  bullets.resize(bullet_num);
  for(int i = 0; i < bullet_num; i++){
    bullets[i] = new Bullet();
  }
  obj_pos->x = Play::win_rect.w / 2;
  obj_pos->y = 10;
  clear_state();
}
コード例 #14
0
ファイル: kb_mkbp.c プロジェクト: Basavaraja-MS/ec_local
int test_enable(void)
{
	keyboard_clear_buffer();
	clear_state();
	TEST_ASSERT(set_kb_scan_enabled(0));
	TEST_ASSERT(press_key(0, 0, 1) == EC_SUCCESS);
	TEST_ASSERT(FIFO_EMPTY());

	TEST_ASSERT(set_kb_scan_enabled(1));
	TEST_ASSERT(press_key(0, 0, 1) == EC_SUCCESS);
	TEST_ASSERT(FIFO_NOT_EMPTY());
	TEST_ASSERT(verify_key(0, 0, 1));

	return EC_SUCCESS;
}
コード例 #15
0
ファイル: lattr.c プロジェクト: bstreiff/joe-editor
struct lattr_db *mk_lattr_db(B *new_b, struct high_syntax *new_syn)
{
	struct lattr_db *db = (struct lattr_db *)joe_malloc(SIZEOF(struct lattr_db));
	db->next = 0;
	db->syn = new_syn;
	db->b = new_b;
	db->end = 512;
	db->hole = 1;
	db->ehole = db->end;
	db->buffer = (HIGHLIGHT_STATE *)joe_malloc(db->end * SIZEOF(HIGHLIGHT_STATE));
	db->first_invalid = 1;
	db->invalid_window = -1;
	/* State of first line is idle */
	clear_state(db->buffer+0);
	return db;
}
コード例 #16
0
ファイル: opt_context.cpp プロジェクト: killbug2004/Snippets
 lbool context::optimize() {
     if (m_pareto) {
         return execute_pareto();
     }
     if (m_box_index != UINT_MAX) {
         return execute_box();
     }
     clear_state();
     init_solver(); 
     import_scoped_state(); 
     normalize();
     internalize();
     update_solver();
     solver& s = get_solver();
     for (unsigned i = 0; i < m_hard_constraints.size(); ++i) {
         TRACE("opt", tout << "Hard constraint: " << mk_ismt2_pp(m_hard_constraints[i].get(), m) << std::endl;);
         s.assert_expr(m_hard_constraints[i].get());
     }
コード例 #17
0
ファイル: dut.c プロジェクト: coreboot/chrome-ec
void cts_task(void)
{
	enum cts_rc rc;
	int i;

	task_wake(TASK_ID_TICK);

	for (i = 0; i < CTS_TEST_ID_COUNT; i++) {
		clear_state();
		rc = tests[i].run();
		CPRINTF("\n%s %d\n", tests[i].name, rc);
		cflush();
	}

	CPRINTS("Task test suite finished");
	cflush();

	/* Sleep forever */
	task_wait_event(-1);
}
コード例 #18
0
ファイル: gdm-x-session.c プロジェクト: zhulianhai/gdm
int
main (int    argc,
      char **argv)
{
        State           *state = NULL;
        GOptionContext  *context = NULL;
        static char    **args = NULL;
        static gboolean  run_script = FALSE;
        static gboolean  allow_remote_connections = FALSE;
        gboolean         debug = FALSE;
        gboolean         ret;
        int              exit_status = EX_OK;
        static GOptionEntry entries []   = {
                { "run-script", 'r', 0, G_OPTION_ARG_NONE, &run_script, N_("Run program through /etc/gdm/Xsession wrapper script"), NULL },
                { "allow-remote-connections", 'a', 0, G_OPTION_ARG_NONE, &allow_remote_connections, N_("Listen on TCP socket"), NULL },
                { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, "", "" },
                { NULL }
        };

        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
        textdomain (GETTEXT_PACKAGE);
        setlocale (LC_ALL, "");

        gdm_log_init ();

        context = g_option_context_new (_("GNOME Display Manager X Session Launcher"));
        g_option_context_add_main_entries (context, entries, NULL);

        g_option_context_parse (context, &argc, &argv, NULL);
        g_option_context_free (context);

        if (args == NULL || args[0] == NULL || args[1] != NULL) {
                g_warning ("gdm-x-session takes one argument (the session)");
                exit_status = EX_USAGE;
                goto out;
        }

        init_state (&state);

        state->session_command = args[0];

        state->settings = gdm_settings_new ();
        ret = gdm_settings_direct_init (state->settings, DATADIR "/gdm/gdm.schemas", "/");

        if (!ret) {
                g_printerr ("Unable to initialize settings");
                exit_status = EX_DATAERR;
                goto out;
        }

        gdm_settings_direct_get_boolean (GDM_KEY_DEBUG, &debug);
        state->debug_enabled = debug;

        gdm_log_set_debug (debug);

        state->main_loop = g_main_loop_new (NULL, FALSE);
        state->cancellable = g_cancellable_new ();

        g_unix_signal_add (SIGTERM, (GSourceFunc) on_sigterm, state);

        ret = spawn_x_server (state, allow_remote_connections, state->cancellable);

        if (!ret) {
                g_printerr ("Unable to run X server");
                exit_status = EX_SOFTWARE;
                goto out;
        }

        ret = spawn_bus (state, state->cancellable);

        if (!ret) {
                g_printerr ("Unable to run session message bus");
                exit_status = EX_SOFTWARE;
                goto out;
        }

        ret = register_display (state, state->cancellable);

        if (!ret) {
                g_printerr ("Unable to register display with display manager");
                exit_status = EX_SOFTWARE;
                goto out;
        }

        ret = spawn_session (state, run_script, state->cancellable);

        if (!ret) {
                g_printerr ("Unable to run session");
                exit_status = EX_SOFTWARE;
                goto out;
        }

        g_main_loop_run (state->main_loop);

        /* Only use exit status of session if we're here because it exit */

        if (state->session_subprocess == NULL) {
                exit_status = state->session_exit_status;
        }

out:
        signal_subprocesses (state);
        wait_on_subprocesses (state);
        clear_state (&state);

        return exit_status;
}
コード例 #19
0
ファイル: opt_context.cpp プロジェクト: killbug2004/Snippets
 unsigned context::add_objective(app* t, bool is_max) {
     clear_state();
     return m_scoped_state.add(t, is_max);
 }
コード例 #20
0
ファイル: opt_context.cpp プロジェクト: killbug2004/Snippets
 unsigned context::add_soft_constraint(expr* f, rational const& w, symbol const& id) { 
     clear_state();
     return m_scoped_state.add(f, w, id);
 }
コード例 #21
0
ファイル: opt_context.cpp プロジェクト: killbug2004/Snippets
 void context::add_hard_constraint(expr* f) { 
     m_scoped_state.add(f);
     clear_state();
 }
コード例 #22
0
ファイル: opt_context.cpp プロジェクト: killbug2004/Snippets
 void context::set_hard_constraints(ptr_vector<expr>& fmls) {
     if (m_scoped_state.set(fmls)) {
         clear_state();
     }
 }
コード例 #23
0
ファイル: backend.c プロジェクト: DruSatori/AEMud
/*
 * The start_boot() in master.c is supposed to return an array of files to load.
 * The array returned by apply() will be freed at next call of apply(),
 * which means that the ref count has to be incremented to protect against
 * deallocation.
 *
 * The master object is asked to do the actual loading.
 */
void 
preload_objects(int eflag)
{
    struct gdexception exception_frame;
    struct vector *prefiles;
    struct svalue *ret = NULL;
    volatile int ix;

    set_current_time();


    if (setjmp(exception_frame.e_context)) 
    {
	clear_state();
	(void)add_message("Error in start_boot() in master_ob.\n");
	exception = NULL;
	return;
    }
    else
    {
	exception_frame.e_exception = NULL;
	exception_frame.e_catch = 0;
	exception = &exception_frame;
	push_number(eflag);
	ret = apply_master_ob(M_START_BOOT, 1);
    }

    if ((ret == 0) || (ret->type != T_POINTER))
	return;
    else
	prefiles = ret->u.vec;

    if ((prefiles == 0) || (prefiles->size < 1))
	return;

    INCREF(prefiles->ref); /* Otherwise it will be freed next sapply */

    ix = -1;
    if (setjmp(exception_frame.e_context)) 
    {
	clear_state();
	(void)add_message("Anomaly in the fabric of world space.\n");
    }

    while (++ix < prefiles->size) 
    {
        set_current_time();
	if (s_flag)
	    reset_mudstatus();
	eval_cost = 0;
	push_svalue(&(prefiles->item[ix]));
	(void)apply_master_ob(M_PRELOAD_BOOT, 1);
	if (s_flag)
	    print_mudstatus(prefiles->item[ix].u.string, eval_cost,
			    get_millitime(), get_processtime());
	tmpclean();
    }
    free_vector(prefiles);
    exception = NULL;
    set_current_time();
}
コード例 #24
0
ファイル: main.c プロジェクト: cotillion/cd-gamedriver
int 
main(int argc, char **argv)
{
    extern int game_is_being_shut_down;
    char *p;
    int i = 0;
    struct svalue *ret;
    extern struct svalue catch_value;
    extern void init_cfuns(void);
    struct gdexception exception_frame;

    (void)setlinebuf(stdout);

    parse_args(argc, argv);
    
    const0.type = T_NUMBER; const0.u.number = 0;
    const1.type = T_NUMBER; const1.u.number = 1;
    constempty.type = T_FUNCTION; constempty.u.func = &funcempty;
    funcempty.funtype = FUN_EMPTY;
    catch_value = const0;
    
    /*
     * Check that the definition of EXTRACT_UCHAR() is correct.
     */
    p = (char *)&i;
    *p = -10;
    if (EXTRACT_UCHAR(p) != 0x100 - 10)
    {
	(void)fprintf(stderr, "Bad definition of EXTRACT_UCHAR() in config.h.\n");
	exit(1);
    }
    set_current_time();

#ifdef PROFILE_LPC
    set_profile_timebase(60.0); /* One minute */
#endif

#if RESERVED_SIZE > 0
    reserved_area = malloc(RESERVED_SIZE);
#endif

    init_random();
    init_tasks();
    query_load_av();
    init_num_args();
    init_machine();
    init_cfuns();
    init_hash();

    /*
     * Set up the signal handling.
     */
    init_signals();

    if (chdir(mudlib_path) == -1) {
        (void)fprintf(stderr, "Bad mudlib directory: %s\n", MUD_LIB);
	exit(1);
    }

    if (setjmp(exception_frame.e_context))
    {
	clear_state();
	add_message("Anomaly in the fabric of world space.\n");
    } 
    else
    {
	exception_frame.e_exception = NULL;
	exception_frame.e_catch = 0;
	exception = &exception_frame;
	auto_ob = 0;
	master_ob = 0;
	
	if ((auto_ob = load_object("secure/auto", 1, 0, 0)) != NULL)
	{
	    add_ref(auto_ob, "main");
	    auto_ob->prog->flags |= PRAGMA_RESIDENT;
	}

	get_simul_efun();
	master_ob = load_object("secure/master", 1, 0, 0);
	if (master_ob)
	{
	    /*
	     * Make sure master_ob is never made a dangling pointer.
	     * Look at apply_master_ob() for more details.
	     */
	    add_ref(master_ob, "main");
	    master_ob->prog->flags |= PRAGMA_RESIDENT;
            resolve_master_fkntab();
	    create_object(master_ob);
            load_parse_information();
	    clear_state();
	}
    }
    exception = NULL;
    if (auto_ob == 0) 
    {
	(void)fprintf(stderr, "The file secure/auto must be loadable.\n");
	exit(1);
    }
    if (master_ob == 0) 
    {
	(void)fprintf(stderr, "The file secure/master must be loadable.\n");
	exit(1);
    }
    set_inc_list(apply_master_ob(M_DEFINE_INCLUDE_DIRS, 0));
    
    {
	struct svalue* ret1;

	ret1 = apply_master_ob(M_PREDEF_DEFINES, 0);
	if (ret1 && ret1->type == T_POINTER)
	{
	    int ii;

	    for (ii = 0; ii < ret1->u.vec->size; ii++)
		if (ret1->u.vec->item[ii].type == T_STRING)
		{
                    add_pre_define(ret1->u.vec->item[ii].u.string);
		}
	}
    }

    if (flag != NULL)
    {
        printf("Applying driver flag: %s\n", flag);
        push_string(flag, STRING_MSTRING);
        (void)apply_master_ob(M_FLAG, 1);

        if (game_is_being_shut_down)
        {
            (void)fprintf(stderr, "Shutdown by master object.\n");
            exit(0);
        }
    }

    /*
     * See to it that the mud name is always defined in compiled files
     */
    ret = apply_master_ob(M_GET_MUD_NAME, 0);

    if (ret && ret->type == T_STRING)
    {
	struct lpc_predef_s *tmp;
		
	tmp = (struct lpc_predef_s *)
	    xalloc(sizeof(struct lpc_predef_s));
	if (!tmp) 
	    fatal("xalloc failed\n");
	tmp->flag = string_copy(ret->u.string);
	tmp->next = lpc_predefs;
	lpc_predefs = tmp;
    }

    ret = apply_master_ob(M_GET_VBFC_OBJECT, 0);
    if (ret && ret->type == T_OBJECT)
    {
	vbfc_object = ret->u.ob;
	INCREF(vbfc_object->ref);
    }
    else
	vbfc_object = 0;

    if (game_is_being_shut_down)
	exit(1);

    init_call_out();
    preload_objects(e_flag);
    (void)apply_master_ob(M_FINAL_BOOT, 0);
    
    mainloop();

    return 0;
}
コード例 #25
0
ファイル: device.cpp プロジェクト: george-kuo/GoSysWare
__uint CNetListern::run()
{
	/*
	WORD wVersionRequested;
	WSADATA wsaData;
	int err;

	wVersionRequested = MAKEWORD(2, 2);

	err = WSAStartup(wVersionRequested, &wsaData);
	if(err != 0){
		return err;
	}

	if(LOBYTE( wsaData.wVersion ) != 2 ||
		HIBYTE( wsaData.wVersion ) != 2){
		WSACleanup();
		return 0;
	}
	*/
    //创建套接口
	SOCKET sockSrv1=socket(AF_INET,SOCK_DGRAM,0);
	SOCKET sockSrv2=socket(AF_INET,SOCK_DGRAM,0);
    
	//将套接口设置为:允许非阻塞模式
	unsigned long ul = 1;
	int nRet;
	nRet = ioctlsocket(sockSrv1, FIONBIO, &ul);
	nRet = ioctlsocket(sockSrv2, FIONBIO, &ul);

	SOCKADDR_IN addrSrv;
	//将INADDR_ANY从主机字节顺序转化为网络字节顺序
	addrSrv.sin_addr.S_un.S_addr=htonl(INADDR_ANY);
	addrSrv.sin_family=AF_INET;

	addrSrv.sin_port=htons(F8_DBSYNCD_PORT);/*TCP/IP网络字节顺序*/
	bind(sockSrv1,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));

	addrSrv.sin_port=htons(F8_DBSYNCD_PORT + 1);
	bind(sockSrv2,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));//将本地地址addrSrv与套接口sockSrv2捆绑

	SOCKADDR_IN addrClient;
	int len=sizeof(SOCKADDR);
	char recvBuf[1500];
	int i;
	int datalen;//成功接收的字符数
	int addr;

	while(isListern){
		len = sizeof(SOCKADDR);
		/*接收远程主机经指定的socket传来的数据,并把数据传到由参数buf指向的内存空间。*/
		datalen = recvfrom(sockSrv1,recvBuf,sizeof(recvBuf),0,(SOCKADDR*)&addrClient,&len);
		if(datalen > 0){
			addr = addrClient.sin_addr.S_un.S_un_b.s_b4;
			n1[addr] = NETCOUNTER;
			clear_state(addr);//r s p u
			if(datalen == 1152){
				r[addr] = NETCOUNTER;
			}else{
				if(strncmp(recvBuf, "cpu - stop!", 11) == 0){
					s[addr] = NETCOUNTER;
				}else if(strncmp(recvBuf, "cpu - sync!", 14) == 0){
					p[addr] = NETCOUNTER;					
				}else if(strncmp(recvBuf, "cpu - standby!", 14) == 0){
					u[addr] = NETCOUNTER;
				}else if(strncmp(recvBuf, "host - alive!", 13) == 0){
					h[addr] = NETCOUNTER;
				}else if(strncmp(recvBuf, "rtdb - run!", 11) == 0){
					dr[addr] = NETCOUNTER;
				}else if(strncmp(recvBuf, "rtdb - stop!", 12) == 0){
					ds[addr] = NETCOUNTER;
				}else if(strncmp(recvBuf, "rtdb - standby!", 15) == 0){
					dp[addr] = NETCOUNTER;
				}
			}
		}

		len = sizeof(SOCKADDR);
		datalen = recvfrom(sockSrv2,recvBuf,sizeof(recvBuf),0,(SOCKADDR*)&addrClient,&len);
		if(datalen > 0){
			addr = addrClient.sin_addr.S_un.S_un_b.s_b4;
			n2[addr] = NETCOUNTER;
			clear_state(addr);
			if(datalen == 1152){
				r[addr] = NETCOUNTER;
			}else{
				if(strncmp(recvBuf, "cpu - stop!", 11) == 0){
					s[addr] = NETCOUNTER;
				}else if(strncmp(recvBuf, "cpu - sync!", 14) == 0){
					p[addr] = NETCOUNTER;
				}else if(strncmp(recvBuf, "cpu - standby!", 14) == 0){
					u[addr] = NETCOUNTER;
				}else if(strncmp(recvBuf, "host - alive!", 13) == 0){
					h[addr] = NETCOUNTER;
				}else if(strncmp(recvBuf, "rtdb - run!", 11) == 0){
					dr[addr] = NETCOUNTER;
				}else if(strncmp(recvBuf, "rtdb - stop!", 12) == 0){
					ds[addr] = NETCOUNTER;
				}else if(strncmp(recvBuf, "rtdb - standby!", 15) == 0){
					dp[addr] = NETCOUNTER;
				}					
			}
		}

		Sleep(10);

		for(i = 0; i < 255; i++){
			if(r[i] > 0){
				r[i]--;
			}
			if(s[i] > 0){
				s[i]--;
			}
			if(p[i] > 0){
				p[i]--;
			}
			if(u[i] > 0){
				u[i]--;
			}
			if(h[i] > 0){
				h[i]--;
			}
			if(n1[i] > 0){
				n1[i]--;
			}
			if(n2[i] > 0){
				n2[i]--;
			}
			if(dr[i] > 0){
				dr[i]--;
			}
			if(ds[i] > 0){
				ds[i]--;
			}
			if(dp[i] > 0){
				dp[i]--;
			}
		}
	}

	closesocket(sockSrv1);
	//WSACleanup(); 

	return 0;
}
コード例 #26
0
ファイル: arcfour.c プロジェクト: marik332000/arcfour
/* Destroy the key stored in the keystream struct. */
void clear_keystream (keystream *k)
{
  clear_key (k);
  clear_state (k);
}
コード例 #27
0
ファイル: vt52.c プロジェクト: klamonte/qodem
/**
 * Push one byte through the VT52 emulator.
 *
 * @param from_modem one byte from the remote side.
 * @param to_screen if the return is Q_EMUL_FSM_ONE_CHAR or
 * Q_EMUL_FSM_MANY_CHARS, then to_screen will have a character to display on
 * the screen.
 * @return one of the Q_EMULATION_STATUS constants.  See emulation.h.
 */
Q_EMULATION_STATUS vt52(const unsigned char from_modem, wchar_t * to_screen) {
    static unsigned char *count;
    static attr_t attributes;
    int new_row;
    int new_col;
    unsigned char from_modem2;

    /*
     * The VT52 spec only supports 7-bit ASCII. Strip the high bit off every
     * character.
     */
    from_modem2 = from_modem & 0x7F;

    DLOG(("STATE: %d CHAR: 0x%02x '%c'\n", scan_state, from_modem2,
          from_modem2));

vt52_start:

    switch (scan_state) {

    case SCAN_NONE:
        /*
         * ESC
         */
        if (from_modem2 == C_ESC) {
            save_char(from_modem2, to_screen);
            scan_state = SCAN_ESC;
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        /*
         * Only a few control chars to handle here.  CR and LF are in
         * emulation.c .
         */
        if (from_modem2 == 0x05) {

            DLOG(("Enquire\n"));

            /*
             * ENQ - transmit the answerback message.
             */
            qodem_write(q_child_tty_fd, get_option(Q_OPTION_ENQ_ANSWERBACK),
                        strlen(get_option(Q_OPTION_ENQ_ANSWERBACK)), Q_TRUE);
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 0x08) {

            DLOG(("Backspace\n"));

            /*
             * Backspace.
             */
            cursor_left(1, Q_FALSE);
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 0x09) {

            DLOG(("Tab\n"));

            /*
             * Tab.
             */
            while (q_status.cursor_x < 80) {
                cursor_right(1, Q_FALSE);
                if (q_status.cursor_x % 8 == 0) {
                    break;
                }
            }

            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 0x7F) {

            DLOG(("Del\n"));

            /*
             * Del - consume but do nothing.
             */
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        /*
         * Any other control characters.
         */
        if (iscntrl(from_modem2)) {
            /*
             * Consume but do nothing.
             */
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        /*
         * This is a printable character.
         */
        *to_screen = map_character(from_modem2);
        return Q_EMUL_FSM_ONE_CHAR;

    case SCAN_Y_1:
        save_char(from_modem2, to_screen);
        scan_state = SCAN_Y_2;
        return Q_EMUL_FSM_NO_CHAR_YET;

    case SCAN_Y_2:
        /*
         * q_emul_buffer[0] = ESC
         * q_emul_buffer[1] = 'Y'
         */
        new_row = q_emul_buffer[2] - 32;
        new_col = from_modem2 - 32;
        if (new_row < 0) {
            new_row = 0;
        }
        if (new_col < 0) {
            new_col = 0;
        }

        DLOG(("Cursor position: %d %d\n", new_row, new_col));

        cursor_position(new_row, new_col);
        clear_state(to_screen);
        return Q_EMUL_FSM_NO_CHAR_YET;

    case SCAN_ESC:

        if (from_modem2 == 'A') {

            DLOG(("Cursor up\n"));

            cursor_up(1, Q_FALSE);
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'B') {

            DLOG(("Cursor down\n"));

            cursor_down(1, Q_FALSE);
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'C') {

            DLOG(("Cursor right\n"));

            cursor_right(1, Q_FALSE);
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'D') {

            DLOG(("Cursor left\n"));

            cursor_left(1, Q_FALSE);
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'E') {

            DLOG(("Erase entire screen\n"));

            /*
             * Cursor position to (0,0) and erase entire screen.
             */
            cursor_formfeed();
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'F') {

            DLOG(("Graphics mode ON\n"));

            graphics_mode = Q_TRUE;
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'G') {

            DLOG(("Graphics mode OFF\n"));

            graphics_mode = Q_FALSE;
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'H') {

            DLOG(("Cursor home\n"));

            cursor_position(0, 0);
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'I') {

            DLOG(("Reverse linefeed\n"));

            /*
             * Move up one column, inserting a line if already at the top.
             */
            if (q_status.cursor_y == 0) {
                scroll_down(1);
            } else {
                cursor_up(1, Q_FALSE);
            }

            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'J') {

            DLOG(("Erase to end of screen\n"));

            /*
             * Erase from here to end of screen.
             */
            erase_screen(q_status.cursor_y, q_status.cursor_x,
                         HEIGHT - STATUS_HEIGHT - 1, WIDTH - 1, Q_FALSE);

            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'K') {

            DLOG(("Erase to end of line\n"));

            /*
             * Erase from here to end of line.
             */
            erase_line(q_status.cursor_x, q_scrollback_current->length,
                       Q_FALSE);

            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'Y') {
            /*
             * Cursor position.
             */
            save_char(from_modem2, to_screen);
            scan_state = SCAN_Y_1;
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'Z') {

            DLOG(("DECID\n"));

            /*
             * Identify
             */

            /*
             * Note the VT100 and above will send <ESC>/Z, but the DECScope
             * manual claims the VT52 will send <ESC>/K if it does not have
             * an "integral electrolytic copier" (an internal printer that
             * used wet paper).
             */
            qodem_write(q_child_tty_fd, "\033/K", 3, Q_TRUE);

            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == '=') {

            DLOG(("Alternate keypad ON\n"));

            q_vt52_alternate_keypad_mode = Q_TRUE;
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == '>') {

            DLOG(("Alternate keypad OFF\n"));

            q_vt52_alternate_keypad_mode = Q_FALSE;
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == '[') {
            if (q_status.vt52_color == Q_TRUE) {
                /*
                 * Fall into SCAN_CSI only if VT52_COLOR is enabled.
                 */
                save_char(from_modem2, to_screen);
                scan_state = SCAN_CSI;
                return Q_EMUL_FSM_NO_CHAR_YET;
            }

            DLOG(("Hold screen mode ON\n"));

            q_status.hold_screen_mode = Q_TRUE;
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == '\\') {

            DLOG(("Hold screen mode OFF\n"));

            q_status.hold_screen_mode = Q_FALSE;
            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        break;

    case SCAN_CSI:
        /*
         * We are only going to support CSI Pn [ ; Pn ... ] m a.k.a. ANSI
         * Select Graphics Rendition.  We can see only a digit or 'm'.
         */
        if (q_isdigit(from_modem2)) {
            /*
             * Save the position for the counter.
             */
            count = q_emul_buffer + q_emul_buffer_n;
            save_char(from_modem2, to_screen);
            scan_state = SCAN_CSI_PARAM;
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'm') {
            /*
             * ESC [ m mean ESC [ 0 m, all attributes off.
             */

            DLOG(("ANSI SGR: reset\n"));

            q_current_color =
                Q_A_NORMAL | scrollback_full_attr(Q_COLOR_CONSOLE_TEXT);

            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        /*
         * This means we entered HOLD SCREEN mode.
         */

        DLOG(("Hold screen mode ON\n"));

        q_status.hold_screen_mode = Q_TRUE;

        /*
         * Reprocess the character from the top.
         */
        clear_state(to_screen);
        goto vt52_start;

    case SCAN_CSI_PARAM:
        /*
         * Following through on the SGR code, we are now looking only for a
         * digit, semicolon, or 'm'
         *
         */
        if ((q_isdigit(from_modem2)) || (from_modem2 == ';')) {
            save_char(from_modem2, to_screen);
            scan_state = SCAN_CSI_PARAM;
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        if (from_modem2 == 'm') {

            DLOG(("ANSI SGR: change text attributes\n"));

            /*
             * Text attributes.
             */
            if (ansi_color(&attributes, &count) == Q_TRUE) {
                q_current_color = attributes;
            } else {
                break;
            }

            clear_state(to_screen);
            return Q_EMUL_FSM_NO_CHAR_YET;
        }

        break;
    }

    /*
     * This point means we got most, but not all, of a sequence.
     */
    q_emul_buffer[q_emul_buffer_n] = from_modem2;
    q_emul_buffer_n++;
    *to_screen = q_emul_buffer[q_emul_buffer_i];
    q_emul_buffer_i++;
    scan_state = SCAN_NONE;

    /*
     * Special case: one character returns Q_EMUL_FSM_ONE_CHAR.
     */
    if (q_emul_buffer_n == 1) {
        q_emul_buffer_i = 0;
        q_emul_buffer_n = 0;
        return Q_EMUL_FSM_ONE_CHAR;
    }

    return Q_EMUL_FSM_MANY_CHARS;
}
コード例 #28
0
ファイル: lattr.c プロジェクト: bstreiff/joe-editor
HIGHLIGHT_STATE lattr_get(struct lattr_db *db, struct high_syntax *y, P *p, ptrdiff_t line)
{
	/* Past end of file? */
	if (line > p->b->eof->line) {
		HIGHLIGHT_STATE x;
		clear_state(&x);
		return x;
	}

	/* Check if we need to expand */
	if (line >= lattr_size(db)) {
		/* Expand by this amount */
		ptrdiff_t amnt = line - lattr_size(db) + 1;
		/* Set position to end */
		lattr_hole(db, lattr_size(db));
		lattr_check(db, amnt);
		db->ehole -= amnt;
		/* Set invalid window to cover new space */
		if (db->invalid_window == -1) {
			db->first_invalid = lattr_size(db) - amnt;
			db->invalid_window = amnt;
		} else {
			db->invalid_window = lattr_size(db) - db->first_invalid;
		}
	}

	/* Check if we need to shrink */
	/* if (p->b->eof->line + 1 < lattr_size(db)) {
		lattr_hole(db, p->b->eof->line + 1);
		db->ehole = db->end;
		if (db->first_invalid > lattr_size(db)) {
			db->first_invalid = lattr_size(db);
			db->invalid_window = -1;
		}
		if (db->invalid_window != -1 && db->first_invalid + db->invalid_window > lattr_size(db)) {
			db->invalid_window = lattr_size(db) - db->first_invalid;
		}
	} */

	/* Check if we are pointing to a valid record */
	if (line >= db->first_invalid) {
		ptrdiff_t ln;
		P *tmp = 0;
		HIGHLIGHT_STATE state;
		tmp = pdup(p, "lattr_get");
		ln = db->first_invalid; /* First line with known good state */
		state = lattr_lvalue(db, ln - 1); /* Known good state */
		/* Compute up to requested line */
		pline(tmp, ln - 1);

		/* Recompute everything in invalid window */
		while (ln < db->first_invalid + db->invalid_window) {
			state = parse(y, tmp, state, p->b->o.charmap);
			lattr_st(db, ln, &state);
			++ln;
		}

		/* Update invalid window: hopefully we did the whole window */
		db->invalid_window -= ln - db->first_invalid;
		db->first_invalid = ln;

		/* Recompute until match found.  If match is found, we can assume rest is valid */
		while (ln < lattr_size(db)) {
			HIGHLIGHT_STATE *prev;
			state = parse(y, tmp, state, p->b->o.charmap);
			prev = lattr_gt(db, ln);
			if (!eq_state(prev, &state))
				lattr_st(db, ln, &state);
			else {
				db->first_invalid = lattr_size(db);
				db->invalid_window = -1;
				++ln;
				break;
			}
			++ln;
		}

		/* Update invalid pointer */
		if (ln > db->first_invalid) {
			db->first_invalid = ln;
			db->invalid_window = 0;
		}
		if (ln == lattr_size(db)) {
			db->first_invalid = ln;
			db->invalid_window = -1;
		}
		prm(tmp);
	}

	/* Check it */

#ifdef junk
	{
		HIGHLIGHT_STATE st;
		P *tmp =pdup(p, "lattr_get");
		pline(tmp, 0);
		clear_state(&st);

		for (z = 0; z != db->first_invalid; ++z) {
			HIGHLIGHT_STATE *prev;
			prev = lattr_gt(db, z);
			if (prev->state != st.state) {
				printf("** Mismatch!! %d %d %d %d **\n",z,tmp->line,prev->state,st.state);
				abort();
			}
			st = parse(y, tmp, st, p->b->o.charmap);
		}
		prm(tmp);
	}
#endif

	/* Return with attribute */
	return lattr_lvalue(db, line);
}
コード例 #29
0
ファイル: object.c プロジェクト: carriercomm/cd-gamedriver
void
remove_all_objects()
{
    extern struct object *master_ob, *vbfc_object, *auto_ob, *simul_efun_ob;
    struct gdexception exception_frame;
    struct object *ob;
    int n;

    exception_frame.e_exception = NULL;
    exception_frame.e_catch = 0;

    for (;;) {
	ob = obj_list;
	n = 0;
	while (ob == master_ob ||
	       ob == vbfc_object ||
	       ob == auto_ob ||
	       ob == simul_efun_ob) {
	    ob = ob->next_all;
	    if (n++ > 3)
		break;
	}
	if (n > 3 || ob == 0)
	    break;
	if (setjmp(exception_frame.e_context))
	    clear_state();
	else {
	    exception = &exception_frame;
	    ob->prog->flags &= ~PRAGMA_RESIDENT;
	    destruct_object(ob);
	    exception = NULL;
	}
    }
    /*
     * In case we have objects referenced through
     * closure cache
     */
    clear_closure_cache();
    /*
     * Remove VBFC object
     */
    force_remove_object(vbfc_object);
    free_object(vbfc_object, "remove_all_objects");
    vbfc_object = NULL;
    /*
     * Remove master object
     */
    force_remove_object(master_ob);
    free_object(master_ob, "remove_all_objects");
    master_ob = NULL;
    /*
     * Remove simul_efun object
     */
    force_remove_object(simul_efun_ob);
    free_object(simul_efun_ob, "remove_all_objects");
    simul_efun_ob = NULL;
    /*
     * Remove auto object
     */
    force_remove_object(auto_ob);
    free_object(auto_ob, "remove_all_objects");
    auto_ob = NULL;
}
コード例 #30
0
int 
main(int argc, char **argv)
{
    extern int game_is_being_shut_down;
    int i, new_mudlib = 0;
    char *p;
    struct svalue *ret;
    extern struct svalue catch_value;
    extern void init_cfuns(void);
    struct gdexception exception_frame;

    (void)setlinebuf(stdout);

    const0.type = T_NUMBER; const0.u.number = 0;
    const1.type = T_NUMBER; const1.u.number = 1;
    constempty.type = T_FUNCTION; constempty.u.func = &funcempty;
    funcempty.funtype = FUN_EMPTY;
    catch_value = const0;
    
    /*
     * Check that the definition of EXTRACT_UCHAR() is correct.
     */
    p = (char *)&i;
    *p = -10;
    if (EXTRACT_UCHAR(p) != 0x100 - 10)
    {
	(void)fprintf(stderr, "Bad definition of EXTRACT_UCHAR() in config.h.\n");
	exit(1);
    }
    set_current_time();
#ifdef PROFILE_LPC
    set_profile_timebase(60.0); /* One minute */
#endif

#ifdef DRAND48
    srand48((long)current_time);
#else
#ifdef RANDOM
    srandom(current_time);
#else
#error No random generator specified!\n
#endif /* RANDOM */
#endif /* DRAND48 */

#if RESERVED_SIZE > 0
    reserved_area = malloc(RESERVED_SIZE);
#endif
    init_tasks();
    query_load_av();
    init_num_args();
    init_machine();
    init_cfuns();

    /*
     * Set up the signal handling.
     */
    init_signals();

    /*
     * The flags are parsed twice !
     * The first time, we only search for the -m flag, which specifies
     * another mudlib, and the D-flags, so that they will be available
     * when compiling master.c.
     */
    for (i = 1; i < argc; i++)
    {
	if (atoi(argv[i]))
	    port_number = atoi(argv[i]);
	else if (argv[i][0] != '-')
	    continue;
	switch(argv[i][1])
	{
	case 'D':
	    if (argv[i][2]) { /* Amylaar : allow flags to be passed down to
				 the LPC preprocessor */
		struct lpc_predef_s *tmp;
		
		tmp = (struct lpc_predef_s *)
		    xalloc(sizeof(struct lpc_predef_s));
		if (!tmp)
		    fatal("xalloc failed\n");
		tmp->flag = string_copy(argv[i]+2);
		tmp->next = lpc_predefs;
		lpc_predefs = tmp;
		continue;
	    }
	    (void)fprintf(stderr, "Illegal flag syntax: %s\n", argv[i]);
	    exit(1);
	    /* NOTREACHED */
	case 'N':
	    no_ip_demon++; continue;
	case 'm':
	    if (chdir(argv[i]+2) == -1)
	    {
	        (void)fprintf(stderr, "Bad mudlib directory: %s\n", argv[i]+2);
		exit(1);
	    }
	    new_mudlib = 1;
	    break;
	}
    }

    if (!new_mudlib && chdir(MUD_LIB) == -1) {
        (void)fprintf(stderr, "Bad mudlib directory: %s\n", MUD_LIB);
	exit(1);
    }

    if (setjmp(exception_frame.e_context))
    {
	clear_state();
	add_message("Anomaly in the fabric of world space.\n");
    } 
    else
    {
	exception_frame.e_exception = NULL;
	exception_frame.e_catch = 0;
	exception = &exception_frame;
	auto_ob = 0;
	master_ob = 0;
	
	if ((auto_ob = load_object("secure/auto", 1, 0, 0)) != NULL)
	{
	    add_ref(auto_ob, "main");
	    auto_ob->prog->flags |= PRAGMA_RESIDENT;
	}

	get_simul_efun();
	master_ob = load_object("secure/master", 1, 0, 0);
	if (master_ob)
	{
	    /*
	     * Make sure master_ob is never made a dangling pointer.
	     * Look at apply_master_ob() for more details.
	     */
	    add_ref(master_ob, "main");
	    master_ob->prog->flags |= PRAGMA_RESIDENT;
            resolve_master_fkntab();
	    create_object(master_ob);
            load_parse_information();
	    clear_state();
	}
    }
    exception = NULL;
    if (auto_ob == 0) 
    {
	(void)fprintf(stderr, "The file secure/auto must be loadable.\n");
	exit(1);
    }
    if (master_ob == 0) 
    {
	(void)fprintf(stderr, "The file secure/master must be loadable.\n");
	exit(1);
    }
    set_inc_list(apply_master_ob(M_DEFINE_INCLUDE_DIRS, 0));
    {
	struct svalue* ret1;

	ret1 = apply_master_ob(M_PREDEF_DEFINES, 0);
	if (ret1 && ret1->type == T_POINTER)
	{
	    int ii;
	    struct lpc_predef_s *tmp;

	    for (ii = 0; ii < ret1->u.vec->size; ii++)
		if (ret1->u.vec->item[ii].type == T_STRING)
		{
		    tmp = (struct lpc_predef_s *)
			xalloc(sizeof(struct lpc_predef_s));
		    tmp->flag = string_copy(ret1->u.vec->item[ii].u.string);
		    tmp->next = lpc_predefs;
		    lpc_predefs = tmp;
		}
	}
    }
    for (i = 1; i < argc; i++)
    {
	if (atoi(argv[i]))
	    ;
	else if (argv[i][0] != '-')
	{
	    (void)fprintf(stderr, "Bad argument %s\n", argv[i]);
	    exit(1);
	}
	else 
	{
	    /*
	     * Look at flags. -m has already been tested.
	     */
	    switch(argv[i][1])
	    {
	    case 'f':
		push_string(argv[i]+2, STRING_MSTRING);
		(void)apply_master_ob(M_FLAG, 1);
		if (game_is_being_shut_down)
		{
		    (void)fprintf(stderr, "Shutdown by master object.\n");
		    exit(0);
		}
		continue;
	    case 'e':
		e_flag++; continue;
	    case 'O':
		warnobsoleteflag++; continue;
	    case 'D':
		continue;
	    case 'N':
		continue;
	    case 'm':
		continue;
	    case 'd':
		d_flag = atoi(argv[i] + 2);
		continue;
	    case 'c':
		comp_flag++; continue;
	    case 'l':
		unlimited++;
		continue;
	    case 't':
		t_flag++; continue;
	    case 'S':
		s_flag++; 
		mudstatus_set(1, -1, -1); /* Statistics, default limits */
		continue;
	    case 'u':
#ifdef CATCH_UDP_PORT
		udp_port = atoi (&argv[i][2]);
#endif
		continue;
	    case 'p':
#ifdef SERVICE_PORT
		service_port = atoi (&argv[i][2]);
#endif
		continue;
	    case 'y':
#ifdef YYDEBUG
		yydebug = 1;
#endif
		continue;
	    default:
		(void)fprintf(stderr, "Unknown flag: %s\n", argv[i]);
		exit(1);
	    }
	}
    }

    /*
     * See to it that the mud name is always defined in compiled files
     */
    ret = apply_master_ob(M_GET_MUD_NAME, 0);

    if (ret && ret->type == T_STRING)
    {
	struct lpc_predef_s *tmp;
		
	tmp = (struct lpc_predef_s *)
	    xalloc(sizeof(struct lpc_predef_s));
	if (!tmp) 
	    fatal("xalloc failed\n");
	tmp->flag = string_copy(ret->u.string);
	tmp->next = lpc_predefs;
	lpc_predefs = tmp;
    }

    ret = apply_master_ob(M_GET_VBFC_OBJECT, 0);
    if (ret && ret->type == T_OBJECT)
    {
	vbfc_object = ret->u.ob;
	INCREF(vbfc_object->ref);
    }
    else
	vbfc_object = 0;

    if (game_is_being_shut_down)
	exit(1);

    if (!t_flag)
	init_call_out();

    preload_objects(e_flag);
    (void)apply_master_ob(M_FINAL_BOOT, 0);
    

    mainloop();
    /* backend(); */

    return 0;
}