Beispiel #1
0
void perform(char ans, int &que, queue<string> &one, queue<string> &two)
{
   string item;
   bool repeat;
   char filename[80];
   ifstream in;
   ofstream out;
   switch(toupper(ans))
   {
      case 'S' : cout<<"Which queue do you wish to use (1 or 2)? ";
                 cin>>que;
                 if(que > 2 || que < 1) que = 1;
                 break;

      case 'R' :do
                {
                   repeat = false;
                   cout<<"Please enter a file name: ";
                   cin>>filename;
                   try
                   {
                     if(que == 1)
                        loadfile(one,filename);
                     else
                        loadfile(two,filename);
                   }
                   catch(int e)
                   {
                      cout<<"File not found. Please re-enter"<<endl;
                      repeat = true;
                   }
                 }while(repeat);
                 break;
      case 'W' : cout<<"Please enter a filename: ";
                 cin>>filename;
                 in.open(filename);
                 if(in.fail())
                 {
                   in.close();
                   out.open(filename);
                 }
                 else
                 {
                     in.close();
                     cout<<"This file exists. Do you want to (O)verwrite or (A)ppend, or (E)xit: ";
                     cin>>ans;
                     switch(toupper(ans))
                     {
                        case 'O' : out.open(filename);
                                   break;
                        case 'A' : out.open(filename,ios::app);
                                   break;
                        default  : return;
                     }
                 }
                 if(que == 1)
                       out<<one;
                 else
                       out<<two;
                 break;
      case 'P' : if(que == 1)
                    cout<<"The contents of queue one are: "<<endl<<one<<endl<<endl;
                 else
                    cout<<"The contents of queue two are: "<<endl<<two<<endl<<endl;
                 break;
      case '+' : cout<<"What is the item that you want to enqueue? ";
                 cin>>item;
                 if(que == 1) one << item;
                 else two << item;
                 break;
      case '-' :
                 if(que == 1) one >> item;
                 else two >> item;
                 cout<<"You dequeued: "<<item<<endl;
                 break;

     case 'Q' : cout<<"Good bye!!!"<<endl;
    }
Beispiel #2
0
/*
 * Copyright (c) 1992, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * Ralph Campbell.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)boot.c	8.1 (Berkeley) 6/10/93
 */

#include <lib/libsa/stand.h>
#include <lib/libkern/libkern.h>

#include <sys/param.h>
#include <sys/exec.h>
#include <sys/exec_ecoff.h>

#include <machine/autoconf.h>
#include <machine/prom.h>
#include <machine/rpb.h>

#include <machine/pte.h>

#include "common.h"

#if !defined(UNIFIED_BOOTBLOCK) && !defined(SECONDARY_BOOTBLOCK)
#error not UNIFIED_BOOTBLOCK and not SECONDARY_BOOTBLOCK
#endif

int loadfile __P((char *, u_int64_t *));

char boot_file[128];
char boot_flags[128];

struct bootinfo_v1 bootinfo_v1;

extern char bootprog_rev[], bootprog_date[], bootprog_maker[];

paddr_t ffp_save, ptbr_save;

extern vaddr_t ssym, esym;

int debug;

char *kernelnames[] = {
	"netbsd",		"netbsd.gz",
	"netbsd.bak",		"netbsd.bak.gz",
	"netbsd.old",		"netbsd.old.gz",
	"onetbsd",		"onetbsd.gz",
	NULL
};

void
#if defined(UNIFIED_BOOTBLOCK)
main(void)
#else /* defined(SECONDARY_BOOTBLOCK) */
main(long fd)
#endif
{
	char *name, **namep;
	u_int64_t entry;
	int win;

	/* Init prom callback vector. */
	init_prom_calls();

	/* print a banner */
	printf("\n");
	printf("NetBSD/alpha " NETBSD_VERS " " BOOT_TYPE_NAME " Bootstrap, Revision %s\n",
	    bootprog_rev);
	printf("(%s, %s)\n", bootprog_maker, bootprog_date);
	printf("\n");

	/* set up the booted device descriptor */
#if defined(UNIFIED_BOOTBLOCK)
        if (!booted_dev_open()) {
                printf("Boot device (%s) open failed.\n",
		    booted_dev_name[0] ? booted_dev_name : "unknown");
                goto fail;
        }
#else /* defined(SECONDARY_BOOTBLOCK) */
	booted_dev_setfd(fd);
#endif

	/* switch to OSF pal code. */
	OSFpal();

	printf("\n");

	prom_getenv(PROM_E_BOOTED_FILE, boot_file, sizeof(boot_file));
	prom_getenv(PROM_E_BOOTED_OSFLAGS, boot_flags, sizeof(boot_flags));

	if (boot_file[0] != 0)
		(void)printf("Boot file: %s\n", boot_file);
	(void)printf("Boot flags: %s\n", boot_flags);

	if (strchr(boot_flags, 'i') || strchr(boot_flags, 'I')) {
		printf("Boot file: ");
		gets(boot_file);
	}

	if (boot_file[0] != '\0')
		win = (loadfile(name = boot_file, &entry) == 0);
	else
		for (namep = kernelnames, win = 0; *namep != NULL && !win;
		    namep++)
			win = (loadfile(name = *namep, &entry) == 0);

	booted_dev_close();
	printf("\n");
	if (!win) {
		goto fail;
	}

	/*
	 * Fill in the bootinfo for the kernel.
	 */
	bzero(&bootinfo_v1, sizeof(bootinfo_v1));
	bootinfo_v1.ssym = ssym;
	bootinfo_v1.esym = esym;
	bcopy(name, bootinfo_v1.booted_kernel,
	    sizeof(bootinfo_v1.booted_kernel));
	bcopy(boot_flags, bootinfo_v1.boot_flags,
	    sizeof(bootinfo_v1.boot_flags));
	bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
	bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
	bootinfo_v1.cngetc = NULL;
	bootinfo_v1.cnputc = NULL;
	bootinfo_v1.cnpollc = NULL;

	(void)printf("Entering %s at 0x%lx...\n", name, entry);
	alpha_pal_imb();
	(*(void (*)(u_int64_t, u_int64_t, u_int64_t, void *, u_int64_t,
	    u_int64_t))entry)(ffp_save, ptbr_save, BOOTINFO_MAGIC,
	    &bootinfo_v1, 1, 0);

	(void)printf("KERNEL RETURNED!\n");

fail:
	(void)printf("Boot failed!  Halting...\n");
	halt();
}
Beispiel #3
0
/* boot linux kernel and initrd */
static int sl_boot_linux(lua_State * L)
{
    const char *kernel = luaL_checkstring(L, 1);
    const char *cmdline = luaL_optstring(L, 2, "");
    char *initrd;
    void *kernel_data, *file_data;
    size_t kernel_len, file_len;
    struct initramfs *initramfs;
    char *newcmdline;
    uint32_t mem_limit = luaL_optint(L, 3, 0);
    uint16_t video_mode = luaL_optint(L, 4, 0);
//  int ret, i;
    int ret;
    char **argv, **argp, *arg, *p;

    ret = __parse_argv(&argv, cmdline);

    newcmdline = malloc(strlen(kernel) + 12);
    if (!newcmdline)
	printf("Mem alloc failed: cmdline\n");

    strcpy(newcmdline, "BOOT_IMAGE=");
    strcpy(newcmdline + strlen(newcmdline), kernel);
    argv[0] = newcmdline;
    argp = argv;

    /* DEBUG
       for (i=0; i<ret; i++)
       printf("%d: %s\n", i, argv[i]);
     */

    newcmdline = make_cmdline(argp);
    if (!newcmdline)
	printf("Creating command line failed!\n");

    /* DEBUG
       printf("Command line: %s\n", newcmdline);
       msleep(1000);
     */

    /* Look for specific command-line arguments we care about */
    if ((arg = find_argument(argp, "mem=")))
	mem_limit = saturate32(suffix_number(arg));

    if ((arg = find_argument(argp, "vga="))) {
	switch (arg[0] | 0x20) {
	case 'a':		/* "ask" */
	    video_mode = 0xfffd;
	    break;
	case 'e':		/* "ext" */
	    video_mode = 0xfffe;
	    break;
	case 'n':		/* "normal" */
	    video_mode = 0xffff;
	    break;
	default:
	    video_mode = strtoul(arg, NULL, 0);
	    break;
	}
    }

    printf("Loading kernel %s...\n", kernel);
    if (loadfile(kernel, &kernel_data, &kernel_len))
	printf("failed!\n");
    else
	printf("ok\n");

    initramfs = initramfs_init();
    if (!initramfs)
	printf("Initializing initrd failed!\n");

    if ((arg = find_argument(argp, "initrd="))) {
	do {
	    p = strchr(arg, ',');
	    if (p)
		*p = '\0';

	    initrd = arg;
	    printf("Loading initrd %s... ", initrd);
	    if (initramfs_load_archive(initramfs, initrd)) {
		printf("failed!\n");
	    }
	    printf("ok\n");

	    if (p)
		*p++ = ',';
	} while ((arg = p));
    }

    if (!loadfile("/testfile1", &file_data, &file_len)) {
	if (initramfs_add_file(initramfs, file_data, file_len, file_len,
			       "/testfile1", 0, 0755))
	    printf("Adding extra file failed\n");
    } else
	printf("Loading extra file failed\n");

    /* DEBUG
       msleep(10000);
     */

    ret = syslinux_boot_linux(kernel_data, kernel_len, initramfs, newcmdline);

    printf("syslinux_boot_linux returned %d\n", ret);

    return 0;
}
Beispiel #4
0
void
xxboot_main(const char *boot_type)
{
	struct open_file f;
	char **npp;
	char *file;
	void *entry;
	int fd;
	u_long marks[MARK_MAX];

	memset(marks, 0, sizeof(marks));
	if (_is2)
		marks[MARK_START] = sun2_map_mem_load();
	printf(">> %s %s [%s]\n", bootprog_name, boot_type, bootprog_rev);
	prom_get_boot_info();

	/*
	 * Hold the raw device open so it will not be
	 * closed and reopened on every attempt to
	 * load files that did not exist.
	 */
	f.f_flags = F_RAW;
	if (devopen(&f, 0, &file)) {
		printf("%s: devopen failed\n", boot_type);
		return;
	}

	/*
	 * Edit the "extended" kernel name based on
	 * the type of machine we are running on.
	 */
	if (_is2)
		extname[EXTNAMEX - 1] = '2';
	if (_is3x == 0)
		extname[EXTNAMEX] = 0;

	/* If we got the "-a" flag, ask for the name. */
	if (prom_boothow & RB_ASKNAME)
		goto just_ask;

	/*
	 * If the PROM gave us a file name,
	 * it means the user asked for that
	 * kernel name explicitly.
	 */
	file = prom_bootfile;
	if (file && *file) {
		fd = loadfile(file, marks, LOAD_KERNEL);
		if (fd == -1) {
			goto err;
		} else {
			goto gotit;
		}
	}

	/*
	 * Try the default kernel names.
	 */
	for (npp = kernelnames; *npp; npp++) {
		file = *npp;
		printf("%s: trying %s\n", boot_type, file);
		fd = loadfile(file, marks, LOAD_KERNEL);
		if (fd != -1)
			goto gotit;
	}

	/*
	 * Ask what kernel name to load.
	 */
	for (;;) {

	just_ask:
		file = kernelnames[0];
		printf("filename? [%s]: ", file);
		gets(line);
		if (line[0])
			file = line;

		fd = loadfile(file, marks, LOAD_KERNEL);
		if (fd != -1)
			break;

	err:
		printf("%s: %s: loadfile() failed.\n", boot_type, file);
	}

gotit:
	entry = (void *)marks[MARK_ENTRY];
	if (_is2) {
		printf("relocating program...");
		entry = sun2_map_mem_run(entry);
	}
	printf("starting program at 0x%x\n", (u_int)entry);
	chain_to(entry);
}
Beispiel #5
0
std::string loadfile(const std::string& filename){
    std::string ret;
    loadfile(filename,ret);
	return ret;
}
Beispiel #6
0
int
main(int argc, char **argv)
{
	int		 ch;
	char		*path;
	char		*buf;
	PyObject	*self, *code, *module;

	log_init(-1);

	while ((ch = getopt(argc, argv, "")) != -1) {
		switch (ch) {
		default:
			log_warnx("warn: filter-python: bad option");
			return (1);
			/* NOTREACHED */
		}
	}
	argc -= optind;
	argv += optind;

	if (argc == 0)
		errx(1, "missing path");
	path = argv[0];

	Py_Initialize();
	self = Py_InitModule("filter", py_methods);
	PyModule_AddIntConstant(self, "FILTER_OK", FILTER_OK);
	PyModule_AddIntConstant(self, "FILTER_FAIL", FILTER_FAIL);
	PyModule_AddIntConstant(self, "FILTER_CLOSE", FILTER_CLOSE);

	buf = loadfile(path);
	code = Py_CompileString(buf, path, Py_file_input);
	free(buf);

	if (code == NULL) {
		PyErr_Print();
		log_warnx("warn: filter-python: failed to compile %s", path);
		return (1);
	}

	module = PyImport_ExecCodeModuleEx("myfilter", code, path);

	if (module == NULL) {
		PyErr_Print();
		log_warnx("warn: filter-python: failed to install module %s", path);
		return (1);
	}

	log_debug("debug: filter-python: starting...");

	filter_api_on_connect(on_connect);

	py_on_connect = PyObject_GetAttrString(module, "on_connect");
	if (py_on_connect && PyCallable_Check(py_on_connect))
		filter_api_on_connect(on_connect);

	py_on_helo = PyObject_GetAttrString(module, "on_helo");
	if (py_on_helo && PyCallable_Check(py_on_helo))
		filter_api_on_helo(on_helo);

	py_on_mail = PyObject_GetAttrString(module, "on_mail");
	if (py_on_mail && PyCallable_Check(py_on_mail))
		filter_api_on_mail(on_mail);

	py_on_rcpt = PyObject_GetAttrString(module, "on_rcpt");
	if (py_on_rcpt && PyCallable_Check(py_on_rcpt))
		filter_api_on_rcpt(on_rcpt);

	py_on_data = PyObject_GetAttrString(module, "on_data");
	if (py_on_data && PyCallable_Check(py_on_data))
		filter_api_on_data(on_data);

	py_on_eom = PyObject_GetAttrString(module, "on_eom");
	if (py_on_eom && PyCallable_Check(py_on_eom))
		filter_api_on_eom(on_eom);

	py_on_commit = PyObject_GetAttrString(module, "on_commit");
	if (py_on_commit && PyCallable_Check(py_on_commit))
		filter_api_on_commit(on_commit);

	py_on_rollback = PyObject_GetAttrString(module, "on_rollback");
	if (py_on_rollback && PyCallable_Check(py_on_rollback))
		filter_api_on_rollback(on_rollback);

	py_on_dataline = PyObject_GetAttrString(module, "on_dataline");
	if (py_on_dataline && PyCallable_Check(py_on_dataline))
		filter_api_on_dataline(on_dataline);

	py_on_disconnect = PyObject_GetAttrString(module, "on_disconnect");
	if (py_on_disconnect && PyCallable_Check(py_on_disconnect))
		filter_api_on_disconnect(on_disconnect);

	filter_api_loop();

	log_debug("debug: filter-python: exiting");
	Py_Finalize();

	return (1);
}
Beispiel #7
0
static void ls(char*path){
	loadfile(path,loadbuf);
	show_dir(loadbuf);
//	oprintf("%s\n",loadbuf);
}
int
main(int argc, char **argv)
{
	int ch;
	char *path, *buf;
	PyObject *self, *code, *module;

	log_init(1);

	while ((ch = getopt(argc, argv, "")) != -1) {
		switch (ch) {
		default:
			fatalx("bad option");
			/* NOTREACHED */
		}
	}
	argc -= optind;
	argv += optind;

	if (argc == 0)
		fatalx("missing path");
	path = argv[0];

	Py_Initialize();
	self = Py_InitModule("table", py_methods);

	PyModule_AddIntConstant(self, "K_NONE", K_NONE);
	PyModule_AddIntConstant(self, "K_ALIAS", K_ALIAS);
	PyModule_AddIntConstant(self, "K_DOMAIN", K_DOMAIN);
	PyModule_AddIntConstant(self, "K_CREDENTIALS", K_CREDENTIALS);
	PyModule_AddIntConstant(self, "K_NETADDR", K_NETADDR);
	PyModule_AddIntConstant(self, "K_USERINFO", K_USERINFO);
	PyModule_AddIntConstant(self, "K_SOURCE", K_SOURCE);
	PyModule_AddIntConstant(self, "K_MAILADDR", K_MAILADDR);
	PyModule_AddIntConstant(self, "K_ADDRNAME", K_ADDRNAME);

	buf = loadfile(path);
	code = Py_CompileString(buf, path, Py_file_input);
	free(buf);

	if (code == NULL) {
		PyErr_Print();
		fatalx("failed to compile %s", path);
	}

	module = PyImport_ExecCodeModuleEx("mytable", code, path);

	if (module == NULL) {
		PyErr_Print();
		fatalx("failed to install module %s", path);
	}

	log_debug("debug: starting...");

	py_on_update = PyObject_GetAttrString(module, "table_update");
	py_on_check = PyObject_GetAttrString(module, "table_check");
	py_on_lookup = PyObject_GetAttrString(module, "table_lookup");
	py_on_fetch = PyObject_GetAttrString(module, "table_fetch");

	table_api_on_update(table_python_update);
	table_api_on_check(table_python_check);
	table_api_on_lookup(table_python_lookup);
	table_api_on_fetch(table_python_fetch);

	table_api_dispatch();

	log_debug("debug: exiting");
	Py_Finalize();

	return 1;
}
Beispiel #9
0
int use_conf(char *test_path)
{
    int ret;
    size_t flags = 0;
    char filename[1024], errstr[1024];
    char *buffer;
    FILE *infile, *conffile;
    json_t *json;
    json_error_t error;

    sprintf(filename, "%s%cinput", test_path, dir_sep);
    if (!(infile = fopen(filename, "rb"))) {
        fprintf(stderr, "Could not open \"%s\"\n", filename);
        return 2;
    }

    sprintf(filename, "%s%cenv", test_path, dir_sep);
    conffile = fopen(filename, "rb");
    if (conffile) {
        read_conf(conffile);
        fclose(conffile);
    }

    if (conf.indent < 0 || conf.indent > 255) {
        fprintf(stderr, "invalid value for JSON_INDENT: %d\n", conf.indent);
        return 2;
    }

    if (conf.indent)
        flags |= JSON_INDENT(conf.indent);

    if (conf.compact)
        flags |= JSON_COMPACT;

    if (conf.ensure_ascii)
        flags |= JSON_ENSURE_ASCII;

    if (conf.preserve_order)
        flags |= JSON_PRESERVE_ORDER;

    if (conf.sort_keys)
        flags |= JSON_SORT_KEYS;

    if (conf.strip) {
        /* Load to memory, strip leading and trailing whitespace */
        buffer = loadfile(infile);
        json = json_loads(strip(buffer), 0, &error);
        free(buffer);
    }
    else
        json = json_loadf(infile, 0, &error);

    fclose(infile);

    if (!json) {
        sprintf(errstr, "%d %d %d\n%s\n",
                error.line, error.column, error.position,
                error.text);

        ret = cmpfile(errstr, test_path, "error");
        return ret;
    }

    buffer = json_dumps(json, flags);
    ret = cmpfile(buffer, test_path, "output");
    free(buffer);
    json_decref(json);

    return ret;
}
Beispiel #10
0
int main()
{


    // creates a window and GLES context
    if (makeContext() != 0)
        exit(-1);

    // all the shaders have at least texture unit 0 active so
    // activate it now and leave it active
    glActiveTexture(GL_TEXTURE0);

    flareTex = loadPNG("resources/textures/cloud.png");
	
	
    width = getDisplayWidth();
    height = getDisplayHeight();

    glViewport(0, 0, getDisplayWidth(), getDisplayHeight());

    // initialises glprint's matrix, shader and texture
    initGlPrint(getDisplayWidth(), getDisplayHeight());
    font1=createFont("resources/textures/font.png",0,256,16,16,16);
    initSprite(getDisplayWidth(), getDisplayHeight());
	

    fileid = 0;	
    loadfile();
    for (int i=0; i<max_flares; i++) {
        flares[i].x=rand_range(0,getDisplayWidth());
        flares[i].y=rand_range(0,getDisplayHeight());
        flares[i].vx=rand_range(0,10)-5;
        flares[i].vy=rand_range(0,10)-5;
    }
    /*for (int i=0; i<max_targets; i++) {
        targets[i].x=rand_range(0,getDisplayWidth());
        targets[i].y=rand_range(0,getDisplayHeight());
	targets[i].flares = 0;
    }*/

    /*for (int i=0; i<max_flares; i++) {
        flares[i].x=rand_range(0,getDisplayWidth());
        flares[i].y=rand_range(0,getDisplayHeight());
        flares[i].vx=rand_range(0,10)-5;
        flares[i].vy=rand_range(0,10)-5;
	flares[i].target = (int)rand_range(0,max_targets);
	targets[flares[i].target].flares ++;
    }*/


    // we don't want to draw the back of triangles
    // the blending is set up for glprint but disabled
    // while not in use
    glCullFace(GL_BACK);
    glEnable(GL_CULL_FACE);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glDisable(GL_DEPTH_TEST);
    glClearColor(0, 0.5, 1, 1);

    // count each frame
    int num_frames = 0;

    // set to true to leave main loop
    bool quit = false;
    
// get a pointer to the key down array
    keys = getKeys();
	int* mouse = getMouse();

    while (!quit) {		// the main loop

        doEvents();	// update mouse and key arrays

        if (keys[KEY_ESC])
            quit = true;	// exit if escape key pressed
        if (keys[KEY_SPACE])
            relocate_targets();	// exit if escape key pressed
        if (keys[KEY_RETURN])
            reassign_flares();	// exit if escape key pressed
        if (keys[KEY_S] && !lastkeys[KEY_S])
            save();	// exit if escape key pressed
        if (keys[KEY_CURSL] && !lastkeys[KEY_CURSL]){
            fileid--;
	    if (fileid <0) fileid = 0;
	    loadfile();	// exit if escape key pressed
	}
        if (keys[KEY_CURSR] && !lastkeys[KEY_CURSR]){
            fileid++;
	    loadfile();	// exit if escape key pressed
	}
        if (keys[KEY_C]){
            max_targets = 1;	// exit if escape key pressed
	    reassign_flares();    
	}
	lastkeys[KEY_S] = keys[KEY_S];
	lastkeys[KEY_CURSL] = keys[KEY_CURSL];
	lastkeys[KEY_CURSR] = keys[KEY_CURSR];
	
	mx = mouse[0];
	my = mouse[1];
	if(mouse[2] != 0){
		spawn_target(mx,my);
	}

	for (int i=0; i<RE_MULTIPLY; i++){
		random_events();
	}
	
	think();
        
        render();	// the render loop

        usleep(1600);	// no need to run cpu/gpu full tilt

    }

    closeContext();		// tidy up

    return 0;
}
Beispiel #11
0
static void sme_schedule_init(LinuxUserSpaceContext* context, int argc, char **argv)
{
    CsrBool wifion = FALSE;
    CsrBool flightmode = FALSE;
    int i;
#ifdef IPC_IP
    CsrUint32 ipc_portNumber = PORT_NUMBER_Q;
#ifdef CSR_AMP_ENABLE
    CsrUint32 ipc_hciPortNumber = HCI_PORT_NUMBER_Q;
    CsrUint32 ipc_aclPortNumber = ACL_PORT_NUMBER_Q;
#endif
#endif

#ifdef IPC_CHARDEVICE
    const char* connectStr = CHAR_DEVICE_Q;
#endif

    sme_trace_entry((TR_FSM, "sme_schedule_init()"));


    CsrMemSet(&getMainData(linuxContext)->address, 0xFF, sizeof(unifi_MACAddress));
    getMainData(linuxContext)->mibfiles.numElements = 0;
    getMainData(linuxContext)->mibfiles.dataList = (unifi_DataBlock*)CsrPmalloc(sizeof(unifi_DataBlock) * MAX_MIB_FILES);
    getMainData(linuxContext)->calibrationDataFile = NULL;
    getMainData(linuxContext)->calibrationData.length = 0;
    getMainData(linuxContext)->calibrationData.data = NULL;
    getMainData(linuxContext)->nextCaldataSaveTime = fsm_get_time_of_day_ms(context->fsmContext) + CALDATA_SAVE_INTERVAL_MS;
    getMainData(linuxContext)->exitOnError = FALSE;
    getMainData(linuxContext)->stopOnError = FALSE;

#ifdef CSR_AMP_ENABLE
    context->palDataFsmContext = paldata_init(linuxContext);
    sme_install_wakeup_callback(context->palDataFsmContext, fsm_wakeup_callback);
#endif

    /* Initialise basic constructs used by the SME */
    context->fsmContext = sme_init(context, NULL);
    sme_install_wakeup_callback(context->fsmContext, fsm_wakeup_callback);

#ifdef CSR_WIFI_NME_ENABLE
    context->nmeFsmContext = csr_wifi_nme_init(linuxContext, NULL);
    csr_wifi_nme_install_wakeup_callback(context->nmeFsmContext, fsm_wakeup_callback);
#endif

#ifdef FSM_DEBUG
    fsm_install_on_transition_callback(context->fsmContext, fsm_on_transition_trace_callback);
    fsm_install_unhandled_event_callback(context->fsmContext, fsm_on_unhandled_trace_callback);
    fsm_install_save_event_callback(context->fsmContext, fsm_on_saved_trace_callback);
    fsm_install_invalid_event_callback(context->fsmContext, fsm_on_invalid_trace_callback);
    fsm_install_ignore_event_callback(context->fsmContext, fsm_on_ignored_trace_callback);

#ifdef CSR_WIFI_NME_ENABLE
    fsm_install_on_transition_callback(context->nmeFsmContext, nme_on_transition_trace_callback);
    fsm_install_unhandled_event_callback(context->nmeFsmContext, nme_on_unhandled_trace_callback);
    fsm_install_save_event_callback(context->nmeFsmContext, nme_on_saved_trace_callback);
    fsm_install_invalid_event_callback(context->nmeFsmContext, nme_on_invalid_trace_callback);
    fsm_install_ignore_event_callback(context->nmeFsmContext, nme_on_ignored_trace_callback);
#endif

#endif

    registerSignalHandlers();

    /* If no args print the usage incase the user does not know what the help option is */
    if (argc == 1)
    {
        print_usage();
    }

    for (i = 1; i < argc; i++) {

        if (CsrStrNCmp(argv[i], "-ipc_port:", 10) == 0)
        {
#ifdef IPC_IP
            ipc_portNumber = (CsrUint32)atoi(&argv[i][10]);
            sme_trace_info((TR_IPC, "sme_schedule_init() : IPC Port override -> %s :: %d", argv[i], ipc_portNumber));
#endif
            continue;
        }

#ifdef CSR_AMP_ENABLE
        if (CsrStrNCmp(argv[i], "-ipc_hciport:", 13) == 0)
        {
#ifdef IPC_IP
            ipc_hciPortNumber = (CsrUint32)atoi(&argv[i][13]);
            sme_trace_info((TR_IPC, "sme_schedule_init() : HCI IPC Port override -> %s :: %d", argv[i], ipc_hciPortNumber));
#endif
            continue;
        }

        if (CsrStrNCmp(argv[i], "-ipc_aclport:", 13) == 0)
        {
#ifdef IPC_IP
            ipc_aclPortNumber = (CsrUint32)atoi(&argv[i][13]);
            sme_trace_info((TR_IPC, "sme_schedule_init() : ACL IPC Port override -> %s :: %d", argv[i], ipc_aclPortNumber));
#endif
            continue;
        }
#endif

        /* TODO :: This is depricated... Remove! */
        if (CsrStrNCmp(argv[i], "-ipc_connect=", 13) == 0)
        {
#ifdef IPC_CHARDEVICE
            connectStr = &argv[i][13];
            sme_trace_crit((TR_IPC, "sme_schedule_init() : -ipc_connect option is depricated. DO NOT USE!"));
            sme_trace_info((TR_IPC, "sme_schedule_init() : IPC Connect String -> %s :: %s", argv[i], connectStr));
#endif
            continue;
        }

        if (CsrStrNCmp(argv[i], "-dev=", 5) == 0)
        {
#ifdef IPC_CHARDEVICE
            connectStr = &argv[i][5];
            sme_trace_info((TR_IPC, "sme_schedule_init() : char device -> %s :: %s", argv[i], connectStr));
#endif
            continue;
        }
        if (CsrStrNCmp(argv[i], "-paldatadev=", 12) == 0)
        {
            continue;
        }
#ifdef CSR_AMP_ENABLE
        if (CsrStrNCmp(argv[i], "-palselectchannel=", 18) == 0)
        {
            int len = CsrStrLen(argv[i]);
            char* str = (char*)CsrPmalloc(len);
            CsrMemCpy(str,&(argv[i][1]), len-1);
            str[len-1] = '\0';

            sme_trace_info((TR_IPC, "sme_schedule_init() : pal channel to select -> %s :: %d , len-%d,str-%s", argv[i], (CsrUint8)atoi(&argv[i][18]),len,str));
            unifi_dbg_cmd_req(context->fsmContext, str);
            continue;
        }

        if (CsrStrNCmp(argv[i], "-paldisableqos", 18) == 0)
        {
            int len = CsrStrLen(argv[i]);
            char* str = (char*)CsrPmalloc(len);
            CsrMemCpy(str,&(argv[i][1]), len-1);
            str[len-1] = '\0';

            sme_trace_info((TR_IPC, "sme_schedule_init() : disable qos to select -%s , len-%d,str-%s", argv[i],len,str));
            unifi_dbg_cmd_req(context->fsmContext, str);

            continue;
        }

        if (CsrStrNCmp(argv[i], "-paldisablesecurity", 18) == 0)
        {
            int len = CsrStrLen(argv[i]);
            char* str = (char*)CsrPmalloc(len);
            CsrMemCpy(str,&(argv[i][1]), len-1);
            str[len-1] = '\0';

            sme_trace_info((TR_IPC, "sme_schedule_init() : disable qos to select -%s", argv[i]));
            unifi_dbg_cmd_req(context->fsmContext, str);

            continue;
        }
#endif
        if (CsrStrNCmp(argv[i], "-flightmode", 11) == 0)
        {
            flightmode = TRUE;
            sme_trace_info((TR_IPC, "sme_schedule_init() : unifi_mgt_wifi_flightmode_req will be sent on connect -> %s", argv[i]));
            continue;
        }

        if (CsrStrNCmp(argv[i], "-wifion", 7) == 0)
        {
            wifion = TRUE;
            sme_trace_info((TR_IPC, "sme_schedule_init() : unifi_mgt_wifi_on_req will be sent on connect -> %s", argv[i]));
            continue;
        }

        if (CsrStrNCmp(argv[i], "-mac=", 5) == 0)
        {
            loadMacAddress(&argv[i][5], &getMainData(linuxContext)->address);
            sme_trace_info((TR_IPC, "sme_schedule_init() : macAddress file -> %s", argv[i]));
            sme_trace_info((TR_IPC, "sme_schedule_init() : macAddress -> %s", trace_unifi_MACAddress(getMainData(linuxContext)->address, getMainData(linuxContext)->traceMacAddressBuffer)));
            continue;
        }
        if (CsrStrNCmp(argv[i], "-mib=", 5) == 0)
        {
            loadMibfile(&argv[i][5], &getMainData(linuxContext)->mibfiles);
            sme_trace_info((TR_IPC, "sme_schedule_init() : mib file -> %s", argv[i]));
            continue;
        }
        if (CsrStrNCmp(argv[i], "-cal=", 5) == 0)
        {
            getMainData(linuxContext)->calibrationDataFile = &argv[i][5];
            (void)loadfile(getMainData(linuxContext)->calibrationDataFile, &getMainData(linuxContext)->calibrationData);
            sme_trace_info((TR_IPC, "sme_schedule_init() : cal file -> %s", getMainData(linuxContext)->calibrationDataFile));
            continue;
        }
        /* Skip -sme_trace:... as the sme trace module will handle these */
        if (CsrStrNCmp(argv[i], "-sme_trace:", 11) == 0)
        {
            continue;
        }

        if (CsrStrNCmp(argv[i], "-v", CsrStrLen(argv[i])) == 0)
        {
            print_versions();
            exit(EXIT_CODE_NORMAL_EXIT);
        }

        if (CsrStrNCmp(argv[i], "-exitOnError", CsrStrLen(argv[i])) == 0)
        {
            getMainData(linuxContext)->exitOnError = TRUE;
            continue;
        }

        if (CsrStrNCmp(argv[i], "-stopOnError", CsrStrLen(argv[i])) == 0)
        {
            getMainData(linuxContext)->stopOnError = TRUE;
            continue;
        }

        if (CsrStrNCmp(argv[i], "-h", CsrStrLen(argv[i])) == 0)
        {
            print_usage();
            exit(EXIT_CODE_WIFION_ERROR);
        }

        print_usage();
        sme_trace_error((TR_IPC, "error : Unknown commandline option : %s", argv[i]));
        exit(EXIT_CODE_WIFION_ERROR);
    }

#ifdef IPC_CHARDEVICE
    if (connectStr)
    {
        getMainData(context)->charIpcCon = ipc_chardevice_connect(connectStr, NULL, NULL, NULL, NULL);
        if (getMainData(context)->charIpcCon == NULL)
        {
            sme_trace_crit((TR_IPC, "sme_schedule_init() : char device connect to %s failed", connectStr));
            exit(EXIT_CODE_WIFION_ERROR);
        }
    }
#endif

#ifdef IPC_IP
    getMainData(context)->ipIpcCon = ipc_ip_create((int)ipc_portNumber, NULL, NULL, NULL, NULL);
    if (getMainData(context)->ipIpcCon == NULL)
    {
        sme_trace_crit((TR_IPC, "sme_schedule_init() : ipc_create(port:%d) failed", ipc_portNumber));
        exit(EXIT_CODE_WIFION_ERROR);
    }

#ifdef CSR_AMP_ENABLE
    getMainData(context)->ipHciIpcCon = ipc_ip_create((int)ipc_hciPortNumber, NULL, NULL, NULL, NULL);
    if (getMainData(context)->ipHciIpcCon == NULL)
    {
        sme_trace_crit((TR_IPC, "sme_schedule_init() : ipc_create(port:%d) failed", ipc_hciPortNumber));
        exit(EXIT_CODE_WIFION_ERROR);
    }
    getMainData(context)->ipAclIpcCon = ipc_ip_create((int)ipc_aclPortNumber, NULL, NULL, NULL, NULL);
    if (getMainData(context)->ipAclIpcCon == NULL)
    {
        sme_trace_crit((TR_IPC, "sme_schedule_init() : ipc_create(port:%d) failed", ipc_aclPortNumber));
        exit(EXIT_CODE_WIFION_ERROR);
    }
#endif

#endif

    if (getMainData(linuxContext)->calibrationData.length)
    {
        unifi_AppValue appValue;
        appValue.id = unifi_CalibrationDataValue;
        appValue.unifi_Value_union.calibrationData = getMainData(linuxContext)->calibrationData;
        unifi_mgt_claim_sync_access(linuxContext->fsmContext);
        (void)unifi_mgt_set_value(linuxContext->fsmContext, &appValue);
        unifi_mgt_release_sync_access(linuxContext->fsmContext);
    }

    if (flightmode)
    {
        unifi_mgt_wifi_flightmode_req(linuxContext->fsmContext, NULL,
                                      &getMainData(context)->address,
                                      getMainData(linuxContext)->mibfiles.numElements,
                                      getMainData(linuxContext)->mibfiles.dataList);

    }

    if (wifion)
    {
        /* Set the nextCaldataSaveTime to 1 minute from now */
        getMainData(linuxContext)->nextCaldataSaveTime = fsm_get_time_of_day_ms(context->fsmContext) + CALDATA_INITIAL_SAVE_INTERVAL_MS;
        unifi_mgt_wifi_on_req(linuxContext->fsmContext, NULL,
                              &getMainData(context)->address,
                              getMainData(linuxContext)->mibfiles.numElements,
                              getMainData(linuxContext)->mibfiles.dataList);
    }
}
Beispiel #12
0
static void initmenu(void)
{
// Allocate Menu Background backup.
   menuback = new Back(MENUXS, MENUYS);
// Load menu screen.

   demoTexture.loadPointer(SDL_CreateTexture(render.getBase(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, HWXMAX, YMAX), true);
	clearmenu();

// Take a snapshot of the plain menu screen.
   menuback->save(MENUX, MENUY);
// .. freeze overlapping part of Title.
   head = (Sprite *)loadfile("pic\\ravage.spr", NULL);
	sHead.load(head, false);

// Load pointer.
   pointer = (Sprite *)loadfile("pic\\pointer.spr", NULL);
	sPointer.load(pointer, false);

// Set mouse area.
   //setmouselimits(MENUX, MENUY, MENUX+MENUXS-pointer->xs, MENUY+MENUYS-pointer->ys);
    setmouselimits(-BORDER, 0, 320, 240);
// Initialize POINTER animation buffer.
   back = new Back(pointer->xs, pointer->ys);
// Set events to initial values.
   pointer_enabled = 1;
   keys_enabled = 0;
   joy_enabled = 0;

// Several buttons & fonts.
   blue = new Font("fonts\\blue.fnt");
   tiny = new Font("fonts\\tiny.fnt");

   addsub = (Sprite *)loadfile("pic\\addsub.spr", NULL);
   sAddSub.load(addsub, false);

   yesno = (Sprite *)loadfile("pic\\yesno.spr", NULL);
   sYesNo.load(yesno, false);

// Write version information.
#ifdef SHAREWARE
   tiny->vanilla(215, 65, "shareware 1.1", 10);
#else
   tiny->vanilla(215, 65, "registered 1.1", 10);
#endif

// Save current game state in case the menu is in SHOP mode.
   gsave = gstate;
   psave = player[nowplayer];
   psave2 = player[1-nowplayer];
   player[1-nowplayer].active = 0;     // Deactivate unused player.

// Initialize DEMO GAME.
   cheatsave = cheatlevel;
   cheatlevel |= CHEAT_INVUL | CHEAT_NOMONEY;
   playback_start("demo1\\demo1.rec");
   player[nowplayer].control = playback_device;
   gstate.nplayers = 1; gstate.difficulty = 3;
   newgame(1);
   newlevel("demo1\\demo1");
   weapon_releaseall(nowplayer, STARTX1, STARTY);
// Start playing background music.
   s_loadmod("mods\\menu.uni");
   s_startmod();
// Fade In
   fadein(level.palette);
}
Beispiel #13
0
static void buildmenu(Menu *menu)
{
   int      index;
   int      x, y;
   int      i, n;

   destroymenu();
   nowmenu = menu;

// Set event handling to default.
   pointer_enabled = 1;
   keys_enabled = 0;
   joy_enabled = 0;

   index = 0;
   do {
      switch (menu->type) {
      case HEAD:
         blue->print_c(MENUX+(MENUXS+BORDER)/2, MENUY+menu->y, menu->text);
         break;
      case TEXT:
         if (menu->x == -1)
            tiny->vanilla_c(MENUX+(MENUXS+BORDER)/2, MENUY + menu->y, menu->text, menu->ys);
         else
            tiny->vanilla(MENUX + menu->x, MENUY + menu->y, menu->text, menu->ys);
         break;
      case STEXT:
         y = tiny->height() + 1;
         menu->back = new Back(MENUX1-7-MENUX, y);
         menu->back->save(MENUX, MENUY+menu->y);
         break;
      case ADD:
         y = tiny->height()*2 + 1;
         menu->back = new Back(MENUX1-23-MENUX, y);
         y = (addsub->ys - y) / 2;
         new Button(MENUX1-21, MENUY+menu->y, addsub, 0, index);
			anchor->up();
         menu->back->save(MENUX, MENUY+menu->y+y-1);
			anchor->up();
         break;
      case ADDSUB:
         y = tiny->height()*2 + 1;
         menu->back = new Back(MENUX1-27-MENUX, y);
         y = (addsub->ys - y) / 2;
         new Button(MENUX1-45, MENUY+menu->y, addsub, 0, index);
         new Button(MENUX1-21, MENUY+menu->y, addsub, 1, index);
         menu->back->save(MENUX, MENUY+menu->y+y-1);
         break;
      case YESNO:
         blue->print_c(MENUX+(MENUXS+BORDER)/2, 180, menu->text);
         new Button(MENUX+20, 205, yesno, 0, index);
         new Button(XMAX-10-yesno->xs, 205, yesno, 1, index);
			anchor->up();
         break;
      case YES:
         new Button(XMAX-yesno->xs, 215, yesno, 0, index);
         tiny->vanilla(XMAX-yesno->xs-tiny->textlen(menu->text)-10,
                       215+(yesno->ys-tiny->height())/2,
                       menu->text, 15);
         break;
      case UPDOWN:
         menu->spr = (Sprite *)loadfile("pic\\updown.spr", NULL);
         new Button(242, MENUY+menu->y, menu->spr, 0, index);
         new Button(266, MENUY+menu->y, menu->spr, 1, index);
         break;
      case CUSTOM:
         menu->spr = (Sprite *)loadfile(menu->sname, NULL);
         n = menu->spr->frames / 2;
         if (menu->x == -1)
            x = MENUX + (MENUXS+BORDER-menu->spr->xs)/2;
         else
            x = MENUX + menu->x;
         y = MENUY + menu->y;

         for (i = 0; i < n; i++) {
            new Button(x, y, menu->spr, i, index);
            y += menu->ys + menu->spr->ys;
				anchor->up();
         }
         break;
      case END:
         menu->action(M_INIT, 0);
         break;
		case NONE:
			break;
      }
      if (menu->type == END) break;
      menu++; index++;
   } while (1);

   back->invalidate();
}
Beispiel #14
0
int mus_thread(void *thread_arg) {
    struct hmp_file *hf;
    hmpopl *h;
    char buf[32];

    snd = oplsnd_init();
    if (oplsnd_open(snd)) {
        fprintf(stderr, "mus: %s\n", oplsnd_errmsg(snd));
        return 0;
    }
    for (;;) {
    while (!mus_switch || !mus_filename)
        SDL_Delay(1);
    mus_switch = 0;

    if (!(h = hmpopl_new())) {
    	fprintf(stderr, "create hmpopl failed\n");
    	continue;
    }

	if (loadbankfile(h, mus_melodic_file, 0)) {
    	fprintf(stderr, "load bnk %s failed\n", mus_melodic_file);
    	continue;
    }
	if (loadbankfile(h, mus_drum_file, 1)) {
    	fprintf(stderr, "load bnk %s failed\n", mus_drum_file);
    	continue;
    }

    int song_size;
	void *song_data;
	
    if (strlen(mus_filename) < sizeof(buf)) {
        strcpy(buf, mus_filename);
        buf[strlen(buf) - 1] = 'q';
        song_data = (void *)loadfile(buf, &song_size);
    } else
        song_data = NULL;
    if (!song_data && !(song_data = (void *)loadfile(mus_filename, &song_size))) {
        fprintf(stderr, "open %s failed\n", mus_filename);
        continue;
    }

    if (!(hf = hmp_open(song_data, song_size, 0xa009))) {
        fprintf(stderr, "read %s failed\n", mus_filename);
        continue;
    }
    free(song_data);

    hmpopl_set_write_callback(h, writereg, NULL);

    hmpopl_start(h);
    hmpopl_set_write_callback(h, writereg, NULL);

    hmpopl_start(h);

	int rc;
	do {
	hmp_event ev;
	hmp_reset_tracks(hf);
	hmpopl_reset(h);
	
	while (!(rc = hmp_get_event(hf, &ev)) && !mus_switch) {
	    if (ev.datalen)
	        continue;
        if ((ev.msg[0] & 0xf0) == 0xb0 && ev.msg[1] == 7) {
            int vol = ev.msg[2];
            vol = (vol * 127) >> 7;
            vol = (vol * 127) >> 7;
            ev.msg[2] = vol;
        }
        if (ev.delta) {
            if (snd)
                oplsnd_generate_samples(snd, (oplsnd_getfreq(snd) / 120) * ev.delta);
        }
        hmpopl_play_midi(h, ev.msg[0] >> 4, ev.msg[0] & 0x0f, ev.msg[1], ev.msg[2]);
	}
	} while (!mus_switch && mus_loop);
    hmpopl_done(h);
    hmp_close(hf);

    }
    return 0;
}
Beispiel #15
0
/**
 * Load and decompress a PCX file
 * @param filename Filename specified by path
 * @return Pointer to a bitmap_desc structure or null if an error occurred 
 */
bitmap_desc *
load_pcx (const char *filename)
{
  Uint32 width, height, depth, size, ptr;
  Uint16 *ptr16;
  unsigned char numof_bytes;
  unsigned char val;
  Uint32 i, j, total;
  unsigned char *filedata, *pixel;
  bitmap_desc *bmp;
  filedata = (unsigned char *) loadfile (filename, &size);
  if (filedata == NULL)
    {
      return NULL;
    }
  ptr16 = (Uint16 *) filedata;
  width = (little_endian_to_ushort (ptr16 + 4)
           - little_endian_to_ushort (ptr16 + 2)) + 1;
  height = (little_endian_to_ushort (ptr16 + 5)
            - little_endian_to_ushort (ptr16 + 3)) + 1;
  /* bits per pixel */
  depth = filedata[3];

  /* allocate bitmap description structure memory */
  bmp = (bitmap_desc *) memory_allocation (sizeof (bitmap_desc));
  if (bmp == NULL)
    {
      LOG_ERR ("not enough memory to allocate 'bmp'");
      return NULL;
    }
  bmp->width = width;
  bmp->height = height;
  bmp->depth = depth;
  bmp->size = width * height * (depth >> 3);
  /* allocate bitmap memory */
  bmp->pixel = memory_allocation (bmp->size);
  if (bmp->pixel == NULL)
    {
      LOG_ERR ("height=%i / width=%i", filename, width, height);
      LOG_ERR ("not enough memory to allocate %i bytes", bmp->size);
      free_memory ((char *) bmp);
      return NULL;
    }
  /* decompress rle */
  pixel = (unsigned char *) bmp->pixel;
  total = 0;
  i = size - 768;
  ptr = 128;
  while (ptr < i)
    {
      if ((filedata[ptr] & 0xC0) == 0xC0)
        {
          numof_bytes = filedata[ptr] & 0x3F;
          ptr++;
        }
      else
        {
          numof_bytes = 1;
        }
      val = filedata[ptr];
      /* bug fixed by Samuel Hocevar */
      total += numof_bytes;
      if (total >= bmp->size)
        {
          break;
        }
      for (j = 0; j < numof_bytes; j++)
        {
          *pixel = val;
          pixel++;
        }
      ptr++;
    }
  free_memory ((char *) filedata);
  LOG_DBG ("filename: \"%s\"; height:%i; width:%i; size:%i bytes", filename,
           width, height, bmp->size);
  return bmp;
}
Beispiel #16
0
int main(int argc, char **argv)
{
	struct termios term, term_saved;
	file_t *file;
	
	if(argc > 2)
	{
		printf("ERROR: Invalid arguments!\n");
		return 1;
	}
	
	newfile();
	
	file = files[0];
	
	if(argc == 2)
	{
		/* filename given */
		strcpy(file->filename, argv[1]);
		loadfile(file, argv[1]);
	}
	else
		file->filename[0] = 0;
	
	file->saved = 1;
	
	current = 0;
	
	/* make sure we got something */
	if(!file->line_count)
		insertline(file, 0);
	
	file->cursor_x = 0;
	file->cursor_y = 0;
	
	tcgetattr(0, &term_saved);
	
	/* initialize curses */
	screen = initscr();
	cbreak();
	nonl();
	noecho();
	
	keypad(screen, TRUE);
	
	/* modify terminal settings */
	tcgetattr(0, &term);
	term.c_lflag &= ~(IEXTEN | ISIG);
	term.c_iflag &= ~IXON;
	term.c_oflag &= ~OPOST;	
	tcsetattr(0, TCSANOW, &term);
	
	/* setup colors */
	start_color();
	init_pair(1, COLOR_YELLOW, COLOR_BLACK);
	init_pair(2, COLOR_WHITE, COLOR_BLACK);
	init_pair(3, COLOR_WHITE, COLOR_BLUE);
	init_pair(4, COLOR_WHITE, COLOR_BLUE);
	init_pair(5, COLOR_GREEN, COLOR_BLACK);
	init_pair(6, COLOR_BLUE, COLOR_BLACK);
	init_pair(7, COLOR_BLACK, COLOR_BLACK);
	attron(COLOR_PAIR(2));
	
	getmaxyx(screen, h, w);
	
	drawmenu();	
	drawscreen();
	drawpos();
	
	setcursor();
	refresh();
	
	/* main loop */
	while(!editor_loop());
	
	endwin();
	
	/* revert terminal settings */
	tcsetattr(0, TCSANOW, &term_saved);
	
	return 0;
}
Beispiel #17
0
/**
 * Allocate memory and load a file
 * @param filename Filename specified by path
 * @return File data buffer pointer
 */
char *
load_file (const char *const filename)
{
  Uint32 filesize;
  return loadfile (filename, &filesize);
}
Beispiel #18
0
/*
 * Copyright (c) 1992, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * Ralph Campbell.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)boot.c	8.1 (Berkeley) 6/10/93
 */

#include <lib/libsa/stand.h>
#include <lib/libkern/libkern.h>
#include <lib/libsa/loadfile.h>

#include <sys/param.h>
#include <sys/exec.h>
#include <sys/exec_ecoff.h>

#include "stand/common/common.h"
#include "stand/common/cfe_api.h"

#include <machine/autoconf.h>

#if !defined(UNIFIED_BOOTBLOCK) && !defined(SECONDARY_BOOTBLOCK)
#error not UNIFIED_BOOTBLOCK and not SECONDARY_BOOTBLOCK
#endif

char boot_file[128];
char boot_flags[128];
extern int debug;

struct bootinfo_v1 bootinfo;

paddr_t ffp_save, ptbr_save;

int debug;

char *kernelnames[] = {
	"netbsd",		"netbsd.gz",
	"netbsd.bak",		"netbsd.bak.gz",
	"netbsd.old",		"netbsd.old.gz",
	"onetbsd",		"onetbsd.gz",
	"netbsd.mips",		"netbsd.mips.gz",
	NULL
};

int
#if defined(UNIFIED_BOOTBLOCK)
main(long fwhandle,long evector,long fwentry,long fwseal)
#else /* defined(SECONDARY_BOOTBLOCK) */
main(long fwhandle,long fd,long fwentry)
#endif
{
	char *name, **namep;
	u_long marks[MARK_MAX];
	u_int32_t entry;
	int win;

	/* Init prom callback vector. */
	cfe_init(fwhandle,fwentry);

	/* Init the console device */
	init_console();

	/* print a banner */
	printf("\n");
	printf("NetBSD/sbmips " NETBSD_VERS " " BOOT_TYPE_NAME " Bootstrap, Revision %s\n",
	    bootprog_rev);
	printf("(%s, %s)\n", bootprog_maker, bootprog_date);
	printf("\n");

	/* set up the booted device descriptor */
#if defined(UNIFIED_BOOTBLOCK)
        if (!booted_dev_open()) {
                printf("Boot device (%s) open failed.\n",
		    booted_dev_name[0] ? booted_dev_name : "unknown");
                goto fail;
        }
#else /* defined(SECONDARY_BOOTBLOCK) */
	booted_dev_setfd(fd);
#endif

	printf("\n");

	boot_file[0] = 0;
	cfe_getenv("KERNEL_FILE",boot_file,sizeof(boot_file));

	boot_flags[0] = 0;
	cfe_getenv("BOOT_FLAGS",boot_flags,sizeof(boot_flags));

	if (boot_file[0] != 0)
		(void)printf("Boot file: %s\n", boot_file);
	(void)printf("Boot flags: %s\n", boot_flags);

	if (strchr(boot_flags, 'i') || strchr(boot_flags, 'I')) {
		printf("Boot file: ");
		gets(boot_file);
	}

	memset(marks, 0, sizeof marks);
	if (boot_file[0] != '\0')
		win = loadfile(name = boot_file, marks, LOAD_KERNEL) == 0;
	else
		for (namep = kernelnames, win = 0; *namep != NULL && !win;
		    namep++)
			win = loadfile(name = *namep, marks, LOAD_KERNEL) == 0;

	entry = marks[MARK_ENTRY];
	booted_dev_close();
	printf("\n");
	if (!win)
		goto fail;

	(void)printf("Entering %s at 0x%lx...\n", name, (long)entry);

	cfe_flushcache(0);

	bzero(&bootinfo,sizeof(bootinfo));
	bootinfo.version = BOOTINFO_VERSION;
	bootinfo.reserved = 0;
	bootinfo.ssym = marks[MARK_SYM];
	bootinfo.esym = marks[MARK_END];
	strncpy(bootinfo.boot_flags,boot_flags,sizeof(bootinfo.boot_flags));
	strncpy(bootinfo.booted_kernel,name,sizeof(bootinfo.booted_kernel));
	bootinfo.fwhandle = fwhandle;
	bootinfo.fwentry = fwentry;

	(*(void (*)(long,long,long,long))entry)(fwhandle,
						BOOTINFO_MAGIC,
						(long)&bootinfo,
						fwentry);

	(void)printf("KERNEL RETURNED!\n");

fail:
	(void)printf("Boot failed!  Halting...\n");
	halt();
	return 1;
}
Beispiel #19
0
int main(int argc, char *argv[])
{
    struct part_iter *iter = NULL;
    void *sbck = NULL;
    struct data_area fdat, hdat, sdat, data[3];
    int ndata = 0;

    console_ansi_raw();

    memset(&fdat, 0, sizeof fdat);
    memset(&hdat, 0, sizeof hdat);
    memset(&sdat, 0, sizeof sdat);

    opt_set_defs();
    if (opt_parse_args(argc, argv))
	goto bail;

#if 0
    /* Get max fixed disk number */
    fixed_cnt = *(uint8_t *)(0x475);

    /*
     * hmm, looks like we can't do that -
     * some bioses/vms just set it to 1
     * and go on living happily
     * any better options than hardcoded 0x80 - 0xFF ?
     */
#endif

    /* Get disk/part iterator matching user supplied options */
    if (find_dp(&iter))
	goto bail;

    /* Perform initial partition entry mangling */
    if (manglepe_fixchs(iter))
	goto bail;
    if (manglepe_hide(iter))
	goto bail;

    /* Load the boot file */
    if (opt.file) {
	fdat.base = (opt.fseg << 4) + opt.foff;

	if (loadfile(opt.file, &fdat.data, &fdat.size)) {
	    error("Couldn't read the boot file.");
	    goto bail;
	}
	if (fdat.base + fdat.size > dosmax) {
	    error("The boot file is too big to load at this address.");
	    goto bail;
	}
    }

    /* Load the sector */
    if (opt.sect) {
	sdat.base = (opt.sseg << 4) + opt.soff;
	sdat.size = iter->di.bps;

	if (sdat.base + sdat.size > dosmax) {
	    error("The sector cannot be loaded at such high address.");
	    goto bail;
	}
	if (!(sdat.data = disk_read_sectors(&iter->di, iter->abs_lba, 1))) {
	    error("Couldn't read the sector.");
	    goto bail;
	}
	if (opt.save) {
	    if (!(sbck = malloc(sdat.size))) {
		critm();
		goto bail;
	    }
	    memcpy(sbck, sdat.data, sdat.size);
	}
	if (opt.file && opt.maps && overlap(&fdat, &sdat)) {
	    warn("The sector won't be mmapped, as it would conflict with the boot file.");
	    opt.maps = false;
	}
    }

    /* Prep the handover */
    if (opt.hand) {
	if (setup_handover(iter, &hdat))
	    goto bail;
	/* Verify possible conflicts */
	if ( ( opt.file && overlap(&fdat, &hdat)) ||
	     ( opt.maps && overlap(&sdat, &hdat)) ) {
	    warn("Handover area won't be prepared,\n"
		  "as it would conflict with the boot file and/or the sector.");
	    opt.hand = false;
	}
    }

    /* Adjust registers */

    mangler_init(iter);
    mangler_handover(iter, &hdat);
    mangler_grldr(iter);

    /* Patching functions */

    if (manglef_isolinux(&fdat))
	goto bail;

    if (manglef_grub(iter, &fdat))
	goto bail;
#if 0
    if (manglef_drmk(&fdat))
	goto bail;
#endif
    if (manglef_bpb(iter, &fdat))
	goto bail;

    if (mangles_bpb(iter, &sdat))
	goto bail;

    if (mangles_save(iter, &sdat, sbck))
	goto bail;

    if (manglesf_bss(&sdat, &fdat))
	goto bail;

    /* This *must* be after BPB saving or copying */
    if (mangles_cmldr(&sdat))
	goto bail;

    /*
     * Prepare boot-time mmap data. We should to it here, as manglers could
     * potentially alter some of the data.
     */

    if (opt.file)
	memcpy(data + ndata++, &fdat, sizeof fdat);
    if (opt.maps)
	memcpy(data + ndata++, &sdat, sizeof sdat);
    if (opt.hand)
	memcpy(data + ndata++, &hdat, sizeof hdat);

#ifdef DEBUG
    dprintf("iter->di dsk, bps: %X, %u\niter->di lbacnt, C*H*S: %"PRIu64", %u\n"
	   "iter->di C, H, S: %u, %u, %u\n",
	iter->di.disk, iter->di.bps,
	iter->di.lbacnt, iter->di.cyl * iter->di.head * iter->di.spt,
	iter->di.cyl, iter->di.head, iter->di.spt);
    dprintf("iter idx: %d\n", iter->index);
    dprintf("iter lba: %"PRIu64"\n", iter->abs_lba);
    if (opt.hand)
	dprintf("hand lba: %u\n",
		((struct disk_dos_part_entry *)hdat.data)->start_lba);
#endif

    if (opt.warn) {
	puts("Press any key to continue booting...");
	wait_key();
    }

    if (ndata && !opt.brkchain) /* boot only if we actually chainload */
	do_boot(data, ndata);
    else
	puts("Service-only run completed, exiting.");
bail:
    pi_del(&iter);
    /* Free allocated areas */
    free(fdat.data);
    free(sdat.data);
    free(hdat.data);
    free(sbck);
    return 255;
}
Beispiel #20
0
int main(int argc, char *argv[])
{
	MACRO_VARS // :.
	int times,f_name_i = 1;
	byte b,nible,*loaded_file,stack_i;
	struct space *f;
	uint stack[256];
	/*	BF VM vars	*/
	byte *mem;
	uint pos = 0;
	/*	end	*/
	
	if(argc == 3){
		f_name_i = 2;
		if(argv[1][0] == '-' && argv[1][1] == 'v')
			v = 1;
	}

	f = loadfile(argv[f_name_i]);
	loaded_file = f->p;

	mem = alloc_mem(MEM_SIZE);

	nible = 0; // starting by nible 0
	times = 1; // run a command, at least once

	b = GETB();
	if(v) printf("b = 0x%x\n", b);
	while(b){
		if(b & BIT7){
			if(v) printf("Isn't a char\n");
			if(nible){
				if(v) printf("Second nible\n");
				if(b & BIT3){ // it is XXXX1XXXb?
					if(v) printf("Is a number of times to repeat\n");
					switch(b & 0x07){ // 00000111b
						case 0: times = 0;  break;
						case 1: times = 2;	break;
						case 2: times = 4;	break;
						case 3: times = 8;	break;
						case 4: times = 16;	break;
						case 5: times = 32;	break;
						case 6: times = 64;	break;
						case 7: times = 128;	break;
					}
					if(times == 0){				
					}
					if(v) printf("Repeat %i\n", times);
				}
				else{
					if(v) printf("Is a command\n");
					times = 1;
					b <<= 4;
					b |= 0x80; // set first bt
				}
			}
			else{
				if(v) printf("First nible\n");
				times = 1;
			}
			for(; times >= 1; times--){
				if(v) printf("Executando a %i_a vez\n", times);
				switch(b & 0x70){ // 01110000b
					case 0x00: // ,
						//if(v) printf("Digite um caracter:\n");
						mem[pos] = inC();
						break;
					case 0x10: // +
						if(times > 1){
							mem[pos] += times;
							if(v) printf("%i x +\n", times);
							times = 0;
						}
						else{
							if(v) printf("+\n");
							mem[pos]++;
						}
						break;
					case 0x20: // >
						if(v) printf(">\n");
						if(pos >= MEM_SIZE){
							printf("Fatal programer stupid!\nStop! traing to acess mem after end of BF machine\n");
							exit(1);
						}
						pos++;
						break;
					case 0x30: // [
						if(v) printf("[\n");
						if(mem[pos])
							stack[stack_i++] = MACRO_i;
						else
							while(b != ']') b = GETB();
						break;
					case 0x40: // .
						outC(mem[pos]);
						if(v) printf(" = 0x%x\n", mem[pos]);
						break;
					case 0x50: // -
						if(times > 1){
							mem[pos] -= times;
							if(v) printf("%i x -\n", times);
							times = 0;
						}
						else{
							if(v) printf("-\n");
							mem[pos]--;
						}
						break;
					case 0x60: // <
						if(v) printf("<\n");
						if(pos <= 0){
							printf("Fatal programer stupid!\nStop! traing to acess mem before star of BF machine\n");
							exit(1);
						}
						pos--;
						break;
					case 0x70: // ]
						if(v) printf("]\n");
						MACRO_i = stack[stack_i--];
						break;
				}
			}
			if(!nible) nible = 1;
			else{
				b = GETB();
				if(v) printf("b = 0x%x\n", b);
				nible = 0;
			}
		}
		else{
			if(v) printf("%c", b); //printf("Is a char: %c\n", b);
			nible = 0;
			b = GETB();
		}
	}
	//printf("%s", mem);
	printf("\n");
	return(0);
}
Beispiel #21
0
static void cat(char*path){
	loadfile(path,loadbuf);
	oprintf("%s\n",loadbuf);
}
int
main(int argc, char **argv)
{
	const char     *kernel = NULL;
	const char     *bootpath = NULL;
	char            bootfile[PATH_MAX];
	void            (*entry)(int, char *[], u_int, void *);
	u_long          marks[MARK_MAX];
	int             win = 0;
	int             i;
	int             ch;

	/* print a banner */
	printf("\n");
	printf("%s Bootstrap, Revision %s\n", bootprog_name, bootprog_rev);

	memset(marks, 0, sizeof marks);

	/* initialise bootinfo structure early */
	bi_init(bootinfo);

#ifdef BOOT_DEBUG
	for (i = 0; i < argc; i++)
		printf("argv[%d] = %s\n", i, argv[i]);
#endif

	/* Parse arguments, if present.  */
	while ((ch = getopt(argc, argv, "v")) != -1) {
		switch (ch) {
		case 'v':
			debug = 1;
			break;
		}
	}

	environment = &argv[1];

	bootpath = firmware_getenv("OSLoadPartition");
	if (bootpath == NULL)
		bootpath =
		    arcbios_GetEnvironmentVariable("OSLoadPartition");

	if (bootpath == NULL) {
		/* XXX need to actually do the fixup */
		printf("OSLoadPartition is not specified.\n");
		return 0;
	}
	DPRINTF("bootpath = %s\n", bootpath);

	/*
	 * Grab OSLoadFilename from ARCS.
	 */

	kernel = firmware_getenv("OSLoadFilename");
	if (kernel == NULL)
		kernel = arcbios_GetEnvironmentVariable("OSLoadFilename");

	DPRINTF("kernel = %s\n", kernel ? kernel : "<null>");

	/*
	 * The first arg is assumed to contain the name of the kernel to boot,
	 * if it a) does not start with a hyphen and b) does not contain
	 * an equals sign.
	 */

	for (i = 1; i < argc; i++) {
		if (((strchr(argv[i], '=')) == NULL) && (argv[i][0] != '-')) {
			kernel = argv[i];
			break;
		}
	}

	if (kernel != NULL) {
		/*
		 * if the name contains parenthesis, we assume that it
		 * contains the bootpath and ignore anything passed through
		 * the environment
		 */
		if (strchr(kernel, '('))
			win = loadfile(kernel, marks, LOAD_KERNEL);
		else {
			strcpy(bootfile, bootpath);
			strcat(bootfile, kernel);
			win = loadfile(bootfile, marks, LOAD_KERNEL);
		}

	} else {
		i = 1;
		while (kernelnames[i] != NULL) {
			strcpy(bootfile, bootpath);
			strcat(bootfile, kernelnames[i]);
			kernel = kernelnames[i];
			win = loadfile(bootfile, marks, LOAD_KERNEL);
			if (win != -1)
				break;
			i++;
		}

	}

	if (win < 0) {
		printf("Boot failed!  Halting...\n");
		(void)getchar();
		return 0;
	}

	strlcpy(bi_bpath.bootpath, kernel, BTINFO_BOOTPATH_LEN);
	bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));

	bi_syms.nsym = marks[MARK_NSYM];
	bi_syms.ssym = marks[MARK_SYM];
	bi_syms.esym = marks[MARK_END];
	bi_add(&bi_syms, BTINFO_SYMTAB, sizeof(bi_syms));

	entry = (void *)marks[MARK_ENTRY];

	if (debug) {
		printf("Starting at %p\n\n", entry);
		printf("nsym 0x%lx ssym 0x%lx esym 0x%lx\n", marks[MARK_NSYM],
		       marks[MARK_SYM], marks[MARK_END]);
	}
	(*entry)(argc, argv, BOOTINFO_MAGIC, bootinfo);

	printf("Kernel returned!  Halting...\n");
	return 0;
}
void
boot(uint32_t a0, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4,
    uint32_t a5)
{
	int fd, i;
	char *netbsd = "";
	int maxmem;
	u_long marks[MARK_MAX];
	char devname[32], file[32];
	void (*entry)(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t,
	    uint32_t);
	struct btinfo_symtab bi_sym;
	struct btinfo_bootarg bi_arg;
	struct btinfo_bootpath bi_bpath;
	struct btinfo_systype bi_sys;
	int loadflag;

	/* Clear BSS. */
	memset(_edata, 0, _end - _edata);

	/*
	 * XXX a3 contains:
	 *     maxmem (nws-3xxx)
	 *     argv   (apbus-based machine)
	 */
	if (a3 >= 0x80000000)
		apbus = 1;
	else
		apbus = 0;

	if (apbus)
		_sip = (void *)a4;

	printf("%s Secondary Boot, Revision %s\n",
	    bootprog_name, bootprog_rev);

	if (apbus) {
		char *bootdev = (char *)a1;
		int argc = a2;
		char **argv = (char **)a3;

		DPRINTF("APbus-based system\n");

		DPRINTF("argc = %d\n", argc);
		for (i = 0; i < argc; i++) {
			DPRINTF("argv[%d] = %s\n", i, argv[i]);
			if (argv[i][0] != '-' && *netbsd == 0)
				netbsd = argv[i];
		}
		maxmem = _sip->apbsi_memsize;
		maxmem -= 0x100000;	/* reserve 1MB for ROM monitor */

		DPRINTF("howto = 0x%x\n", a0);
		DPRINTF("bootdev = %s\n", (char *)a1);
		DPRINTF("bootname = %s\n", netbsd);
		DPRINTF("maxmem = 0x%x\n", maxmem);

		/* XXX use "sonic()" instead of "tftp()" */
		if (strncmp(bootdev, "tftp", 4) == 0)
			bootdev = "sonic";

		strcpy(devname, bootdev);
		if (strchr(devname, '(') == NULL)
			strcat(devname, "()");
	} else {
		int bootdev = a1;
		char *bootname = (char *)a2;
		int ctlr, unit, part, type;

		DPRINTF("HB system.\n");

		/* bootname is "/boot" by default on HB system. */
		if (bootname && strcmp(bootname, "/boot") != 0)
			netbsd = bootname;
		maxmem = a3;

		DPRINTF("howto = 0x%x\n", a0);
		DPRINTF("bootdev = 0x%x\n", a1);
		DPRINTF("bootname = %s\n", netbsd);
		DPRINTF("maxmem = 0x%x\n", maxmem);

		ctlr = BOOTDEV_CTLR(bootdev);
		unit = BOOTDEV_UNIT(bootdev);
		part = BOOTDEV_PART(bootdev);
		type = BOOTDEV_TYPE(bootdev);

		if (devs[type] == NULL) {
			printf("unknown bootdev (0x%x)\n", bootdev);
			_rtt();
		}

		snprintf(devname, sizeof(devname), "%s(%d,%d,%d)",
		    devs[type], ctlr, unit, part);
	}

	printf("Booting %s%s\n", devname, netbsd);

	/* use user specified kernel name if exists */
	if (*netbsd) {
		kernels[0] = netbsd;
		kernels[1] = NULL;
	}

	loadflag = LOAD_KERNEL;
	if (devname[0] == 'f')	/* XXX */
		loadflag &= ~LOAD_BACKWARDS;

	marks[MARK_START] = 0;

	for (i = 0; kernels[i]; i++) {
		snprintf(file, sizeof(file), "%s%s", devname, kernels[i]);
		DPRINTF("trying %s...\n", file);
		fd = loadfile(file, marks, loadflag);
		if (fd != -1)
			break;
	}
	if (kernels[i] == NULL)
		_rtt();

	DPRINTF("entry = 0x%x\n", (int)marks[MARK_ENTRY]);
	DPRINTF("ssym = 0x%x\n", (int)marks[MARK_SYM]);
	DPRINTF("esym = 0x%x\n", (int)marks[MARK_END]);

	bi_init(BOOTINFO_ADDR);

	bi_sym.nsym = marks[MARK_NSYM];
	bi_sym.ssym = marks[MARK_SYM];
	bi_sym.esym = marks[MARK_END];
	bi_add(&bi_sym, BTINFO_SYMTAB, sizeof(bi_sym));

	bi_arg.howto = a0;
	bi_arg.bootdev = a1;
	bi_arg.maxmem = maxmem;
	bi_arg.sip = (int)_sip;
	bi_add(&bi_arg, BTINFO_BOOTARG, sizeof(bi_arg));

	strcpy(bi_bpath.bootpath, file);
	bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));

	bi_sys.type = apbus ? NEWS5000 : NEWS3400;		/* XXX */
	bi_add(&bi_sys, BTINFO_SYSTYPE, sizeof(bi_sys));

	entry = (void *)marks[MARK_ENTRY];

	if (apbus)
		apcall_flushcache();
	else
		mips1_flushicache(entry, marks[MARK_SYM] - marks[MARK_ENTRY]);

	printf("\n");
	(*entry)(a0, a1, a2, a3, a4, a5);
}
Beispiel #24
0
int
pbsdboot(TCHAR *wkernel_name, int argc, char *argv[], struct bootinfo* bi)
{
	int i;
	caddr_t start, end;
	caddr_t argbuf, p;
	struct bootinfo *bibuf;
	int fd = -1;

	stat_printf(TEXT("open %s..."), wkernel_name);
	if (CheckCancel(0) || (fd = open((char*)wkernel_name, O_RDONLY)) < 0) {
		msg_printf(MSG_ERROR, whoami, TEXT("open failed.\n"));
		stat_printf(TEXT("open %s...failed"), wkernel_name);
		goto cancel;
	}

	stat_printf(TEXT("read information from %s..."), wkernel_name);
	if (CheckCancel(0) || getinfo(fd, &start, &end) < 0) {
		stat_printf(TEXT("read information failed"), wkernel_name);
		goto cancel;
	}

	stat_printf(TEXT("create memory map..."));
	if (CheckCancel(0) || vmem_init(start, end) < 0) {
		stat_printf(TEXT("create memory map...failed"));
		goto cancel;
	}
	//vmem_dump_map();

	stat_printf(TEXT("prepare boot information..."));
	if ((argbuf = vmem_alloc()) == NULL ||
		(bibuf = (struct bootinfo*)vmem_alloc()) == NULL) {
		msg_printf(MSG_ERROR, whoami, TEXT("can't allocate argument page\n"));
		stat_printf(TEXT("prepare boot information...failed"));
		goto cancel;
	}

	memcpy(bibuf, bi, sizeof(struct bootinfo));
	for (p = &argbuf[sizeof(char*) * argc], i = 0; i < argc; i++) {
		int arglen = strlen(argv[i]) + 1;
		((char**)argbuf)[i] = p;
		memcpy(p, argv[i], arglen);
		p += arglen;
	}

	stat_printf(TEXT("loading..."));
	if (CheckCancel(0) || loadfile(fd, &start) < 0) {
		stat_printf(TEXT("loading...failed"));
		goto cancel;
	}

	/* last chance to cancel */
	if (CheckCancel(-1)) {
		goto cancel;
	}

	stat_printf(TEXT("execute kernel..."));
	vmem_exec(start, argc, (char**)argbuf, bibuf);
	stat_printf(TEXT("execute kernel...failed"));

cancel:
	if (0 <= fd) {
		close(fd);
	}
	vmem_free();

	return (-1);
}
/*
 * Entry point.
 * Parse PROM boot string, load the kernel and jump into it
 */
int
main(unsigned int memsize)
{
	char **namep, *dev, *kernel, *bi_addr;
	char bootpath[PATH_MAX];
	int win;
	u_long marks[MARK_MAX];
	void (*entry)(unsigned int, u_int, char *);

	struct btinfo_flags bi_flags;
	struct btinfo_symtab bi_syms;
	struct btinfo_bootpath bi_bpath;
	struct btinfo_howto bi_howto;
	int addr, speed, howto;

	try_bootp = 1;

	/* Initialize boot info early */
	dev = NULL;
	kernel = NULL;
	howto = 0x0;
	bi_flags.bi_flags = 0x0;
	bi_addr = bi_init();

	lcd_init();
	cobalt_id = read_board_id();
	prominit(memsize);
	if (cninit(&addr, &speed) != NULL)
		bi_flags.bi_flags |= BI_SERIAL_CONSOLE;

	print_banner(memsize);

	memset(marks, 0, sizeof marks);
	get_bsdbootname(&dev, &kernel, &howto);

	if (kernel != NULL) {
		DPRINTF(("kernel: %s\n", kernel));
		kernelnames[0] = kernel;
		kernelnames[1] = NULL;
	} else {
		DPRINTF(("kernel: NULL\n"));
	}

	win = 0;
	DPRINTF(("Kernel names: %p\n", kernelnames));
	for (namep = kernelnames, win = 0; (*namep != NULL) && !win; namep++) {
		kernel = *namep;

		bootpath[0] = '\0';

		strcpy(bootpath, dev ? dev : DEFBOOTDEV);
		strcat(bootpath, ":");
		strcat(bootpath, kernel);

		lcd_loadfile(bootpath);
		printf("Loading: %s", bootpath);
		if (howto)
			printf(" (howto 0x%x)", howto);
		printf("\n");
		patch_bootstring(bootpath);
		win = (loadfile(bootpath, marks, LOAD_ALL) != -1);
	}

	if (win) {
		strncpy(bi_bpath.bootpath, kernel, BTINFO_BOOTPATH_LEN);
		bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));

		entry = (void *)marks[MARK_ENTRY];
		bi_syms.nsym = marks[MARK_NSYM];
		bi_syms.ssym = marks[MARK_SYM];
		bi_syms.esym = marks[MARK_END];
		bi_add(&bi_syms, BTINFO_SYMTAB, sizeof(bi_syms));

		bi_add(&bi_flags, BTINFO_FLAGS, sizeof(bi_flags));

		bi_howto.bi_howto = howto;
		bi_add(&bi_howto, BTINFO_HOWTO, sizeof(bi_howto));

		entry = (void *)marks[MARK_ENTRY];

		DPRINTF(("Bootinfo @ 0x%lx\n", (u_long)bi_addr));
		printf("Starting at 0x%lx\n\n", (u_long)entry);
		(*entry)(memsize, BOOTINFO_MAGIC, bi_addr);
	}

	delay(20000);
	lcd_failed();
	(void)printf("Boot failed! Rebooting...\n");
	return 0;
}
Beispiel #26
0
int
main(int argc, char *argv[])
{
    //RECSTRU *recp; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */
    LONGX maxmfrl=MAXMFRL;   // default

    char *serverhost=SERVERHOST;
    uint16_t port=PORT;
    LONGX xval;

    char *wwwcgip=NULL;     // allocated in cicgi0
    char *parmwtmsg=NULL;   // wtrig2 command line - calling argument wtrig2
    char *wtmsg=NULL;   // wtrig2 command line - allocated if not parmwtmsg

    char *parmhtmsg=NULL;   // http command line - calling argument http
    char *htmsg=NULL;       // http command line - allocated if not parmhtmsg

    char *parmxtmsg=NULL;   // xttt command line - calling argument xttt
    char *xtmsg=NULL;       // xttt command line - allocated if not parmxtmsg

    int debug=0;
    int force=0;
    int outfmthtml=0;

    char *txtvp="";        // text parameter
    int txtvlen=0;         // text parameter
    char *txt1vp="";        // text1 parameter
    int txt1vlen=0;         // text1 parameter
    
    char *p,*q,*x;
    char *hhp;
//    char *hdatap;

    int len,y;
    char *np,*vp;
    int nlen,vlen;
    int npairs; //=0;

    char *buffer;//=NULL    // reply from mainserver/wtrig2
    int buffersize;

    char *cgimsg=NULL;      // reply from mainserver/wtrig2
    LONGX cgimsgsize;


    int rc; //=0;

    int i;


    /* go
    */
    for (i=1; i < argc; i++) {
        p=argv[i];
        if (strcmp(p,"hello") == 0) {
            //serc_syntax();
            printf("%s",cicopyr("Utility SERC"));
            printf("\n");
            printf("serc [hello] [debug] [cipar=<file>] \n");
            printf("     [port=1417|<port>] \n");
            printf("     [host=localhost|<host>]  \n");
            printf("     \"wtrig2 c=col [maxrel=n] [minsim=0.n] [text1=x] [text=x]\" \n");
            printf("\n");
            exit(1);
        }
        if (strcmp(p,"force") == 0) {
            force=1;
            continue;
        }
        if (strcmp(p,"debug") == 0) {
            debug=1;
            continue;
        }
        if (strncmp(p,"cipar=",6) == 0) {
            if ((dbxcipfp=fopen(p+6,"r")) == NULL) fatal(p);
            continue;
        }
        if (strncmp(p,"port=",5) == 0) {
            if (sscanf(p+5,"%"_LD_,&xval) != 1) fatal(p);
            port=(uint16_t)xval;
            continue;
        }
        if (strncmp(p,"host=",5) == 0) {
            if (!*(p+5)) fatal(p);
            serverhost=p+5;
            continue;
        }
        if (strncmp(p,"wtrig2 ",6) == 0) {
            parmwtmsg=p;
            continue;
        }
        if (strncmp(p,"xttp ",5) == 0) {
            parmxtmsg=p;
            continue;
        }
        parmhtmsg=p;
        //if (strncmp(p,"http ",5) == 0) {
        //    continue;
        //}
        //printf("Content-type: text/plain\n\n");
        //fatal(p);
    }
    
    
        if (force) {
            putenv("REQUEST_METHOD=GET");
//putenv("QUERY_STRING=wtrig2=on&c=lilrelff&text1=Jose+Meio+Silva&text=titulo+1%0D%0A%0D%0Atitulo+2%0D%0Atitulo+3%0D%0A&maxrel=3&minsim=0.20&serc.go=submit");
          //putenv("QUERY_STRING=wtrig2=on&collection=lilrelff&text1=Jos%E9+da+Silva+Junior&text=Publica%E7%E3o+eletr%F4nica+hoje%0D%0AElectronic+publishing+today%0D%0AOn+the+Virtual+Health+Library&maxrel=3&minsim=0.20&serc.go=submit");

putenv("QUERY_STRING=wtrig2=on&cipar=similar/jdlilacs.cip&collection=lilrelff&text1=Jose+da+Silva+Junior&text=Publicacao+eletronica+hoje%0D%0AElectronic+publishing+today%0D%0AOn+the+Virtual+Health+Library&maxrel=3&minsim=0.20&serc.goxml=submit");

        }

        
    /* setup alloc
    */
    p=dbxcipar(NULL,"maxmfrl",'='); if (dbxcipok) sscanf(p,"%"_LD_,&maxmfrl);
    if (maxmfrl < (LONGX)MSNVSPLT || (RECHSIZE+maxmfrl) > ALLOMAXV) maxmfrl=MAXMFRL;
    rec_maxmfrl=maxmfrl;
    //fmt_fsiz=maxmfrl;
    cgimsgsize=maxmfrl;
    buffersize=(int)maxmfrl;

    /* reply header
    */
    if (outfmthtml) {
        printf("Content-type: text/html\n\n");
        printf("<html><body><pre>\n");
    }
    else {
        //printf("Content-type: text/plain\n\n");
        printf("Content-type: text/xml\n\n");
        printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n");

        fprintf(stdout, "<sercla-jd version=\"1.0\">\n");
    }

    /* setup wtrig2 parms
    */
    if (!parmwtmsg) {
        /* get CGI data
        */
        p=getenv("REQUEST_METHOD"); if (debug) if (p) printf("+++ REQUEST_METHOD=%s<br />\n",p);
        q=getenv("QUERY_STRING");   if (debug) if (q) printf("+++ QUERY_STRING=%s<br />\n",q);
        if (p) cicgi0(NULL, NULL, &wwwcgip, (UWORD)1, "tag");  // H1 10 ^ndbn^vcdsH1 10 ^ncount^v2H1 7 ^nnow^vH1 10 ^nbtell^v0H1 20 ^nbool^vplants*waterH1 15 ^npft^vmfn/v24/
        if (debug) if (!wwwcgip) printf("+++ wwwcgip=%s<br />\n","void");

        /* setup service parameters
        */
        //drive mainserver to wtrig2
        if (wwwcgip) if (strstr(wwwcgip,"^nwtrig2^von")) {

            if (debug) printf("+++ wwwcgip=%s<br />\n",wwwcgip);

            // alloc cgi message
            cgimsg=loadfile(NULL,'@',"",NULL,cgimsgsize,'\0');
            if (!cgimsg) fatal("serc/alloc/cgimsg");
            x=cgimsg;

            /* loop throught cgi data pairs ^nNam^v[Val]
            */
            // H1.len.^nNam^v[Val]
            // <--y--><---len---->
            for (p=wwwcgip, npairs=0; strncmp(p,"H1 ",3) == 0; ) {

                hhp=p;
                p+=3; y=3;
                for (len=0; isdigit(*p); p++, y++)
                    len=10*len+(int)(*p)-(int)'0';
                p++; y++;
                // ^nNam^v[Val]
                p+=2;
                // Nam^v[Val]
                np=p;
                for (nlen=0; *p; p++) if (*p == SFLDCHR) break; else nlen++;
                // ^v[Val]
                p+=2;
                // [Val]
                vp=p;
                p=hhp+y+len;
                npairs++;
                //
                np[nlen]='\0';                        // Nam dlm
                vlen=len-nlen-2-2;                    // memmove
                if (debug) printf("+++ pair %d: %s[%d+%d,%d,%d]<br />\n",npairs,hhp,y,len,nlen,vlen);
                if (vlen < 0) fatal("serc/vlen");

                  //internal parms - execute 
                  if (strcmp(np,"debug") == 0) {
                      if (!vlen) debug=1;
                      else sscanf(vp,"%d",&debug);
                      continue;
                  }
                  if (strcmp(np,"cipar") == 0) {
                      if (vlen) { char c=vp[vlen]; vp[vlen]='\0'; if ((dbxcipfp=fopen(vp,"r")) == NULL) fatal(vp); vp[vlen]=c; }
                      continue;
                  }
                  if (strcmp(np,"port") == 0) {
                      if (sscanf(vp,"%"_LD_,&xval) != 1) fatal(np);
                      port=(uint16_t)xval;
                      continue;
                  }
//                  if (strcmp(np,"host") == 0) {
//                      if (!vp) fatal(np);
//                      serverhost=vp;   // falta delimitar
//                      continue;
//                  }
                          
                  //start wtrig2 parms
                  if (strcmp(np,"wtrig2") == 0) {
                      wtmsg=x;                           //trig move parms from now on
                      sprintf(x,"wtrig2"); x+=strlen(x); //drive
                      continue;
                  }
                  // text1= text= parms
                  if (strcmp(np,"text") == 0) {
                      txtvp=vp; txtvlen=vlen;
                      continue;
                  }
                  if (strcmp(np,"text1") == 0) {
                      txt1vp=vp; txt1vlen=vlen;
                      continue;
                  }
                  // normalize c= d= parms
                  if (strcmp(np,"c") == 0 || strcmp(np,"collection") == 0) {
                      np="c";
                  }
                  if (strcmp(np,"d") == 0 || strcmp(np,"document") == 0) {
                      np="d";
                  }
                  //move wtrig2/other parms - w2p0.c now discart non-w2 parms
                  if (wtmsg) {
                      if (!vlen) { sprintf(x," %s" ,np); x+=strlen(x); }
                      else       { sprintf(x," %s=",np); x+=strlen(x); memmove(x,vp,vlen); x+=vlen; }
                  }
                  else if (debug) printf("+++ pair %d: %s[%d+%d,%d,%d] - ignored <br />\n",npairs,hhp,y,len,nlen,vlen);
                  
            } // end loop
            
            *x='\0';
            if (*p) fatal("serc/wwwcgip");

        } //end drive mainserver to wtrig2

    } /* end if !parmwtmsg */



    /* Run
    */

    // alloc reply buffer / move nul to 1st byte
    buffer=loadfile(NULL,'@',"",NULL,(LONGX)buffersize,'\0');
    if (!buffer) fatal("serc/alloc/buffer");

    // drive mainserver to wtrig2
    if (parmwtmsg || wtmsg) {

       int cmd=debug;
       char *message=parmwtmsg;
       int maxrds=1;
                      
       if (wtmsg) {  //cgi overrides parms!
           char *x=wtmsg+strlen(wtmsg);
           message=wtmsg;           
           if (txt1vlen) {
             sprintf(x," text1="); x+=strlen(x); memmove(x,txt1vp,txt1vlen); x+=txt1vlen; *x='\0';
           }
           if (txtvlen) {
             sprintf(x," text=" ); x+=strlen(x); memmove(x,txtvp,txtvlen);   x+=txtvlen;  *x='\0';
           }
       } /* end wtmsg */

       if (debug) printf("serc: message=%s<br />\n",message);
       if (message) {
           if (debug || cmd >= 3) printf("serc: \"%s\" %s %d [%d read]\n",message,serverhost,port,maxrds);
#if !PC
           rc=mainclient(cmd, message, serverhost, port, buffer, buffersize, maxrds);
#else
           rc=0;
#endif
           if (debug || cmd >= 3) if (rc < 0) printf("serc: failure %d \n", rc);
       }

    } /* end parmwtmsg || wtmsg */


    // reply
    if (buffer) printf("%s",buffer);

    // reply trailer
    if (outfmthtml) 
        printf("</pre></body></html>\n");
    else
        printf("</sercla-jd>\n");


    /* release working areas
    */
    //if (buffer)  FREE(buffer);
    //if (cgimsg)  FREE(cgimsg);
    //if (wwwcgip) FREE(wwwcgip);

    /* Done
    */
    return 0;
}
IO_stat MCDispatch::startup(void)
{
	IO_stat stat;
	MCStack *sptr;

	// set up image cache before the first stack is opened
	MCCachedImageRep::init();
	
	startdir = MCS_getcurdir();
	enginedir = strclone(MCcmd);

	char *eptr;
	eptr = strrchr(enginedir, PATH_SEPARATOR);
	if (eptr != NULL)
		*eptr = '\0';
	else
		*enginedir = '\0';

	MCExecPoint ep;
	ep . setstaticbytes(MCstartupstack, MCstartupstack_length);
	MCDecompress::do_decompress(ep, 0, 0);

	IO_handle stream = MCS_fakeopen(ep . getsvalue());
	if ((stat = MCdispatcher -> readfile(NULL, NULL, stream, sptr)) != IO_NORMAL)
	{
		MCS_close(stream);
		return stat;
	}

	MCS_close(stream);

	memset((void *)ep . getsvalue() . getstring(), 0, ep . getsvalue() . getlength());
	ep . clear();
	
	// Temporary fix to make sure environment stack doesn't get lost behind everything.
#if defined(_MACOSX)
	ProcessSerialNumber t_psn = { 0, kCurrentProcess };
	SetFrontProcess(&t_psn);
#elif defined(_WINDOWS)
	SetForegroundWindow(((MCScreenDC *)MCscreen) -> getinvisiblewindow());
#endif
	
	MCenvironmentactive = True;
	sptr -> setfilename(strclone(MCcmd));
	MCdefaultstackptr = MCstaticdefaultstackptr = stacks;

	{
		MCdefaultstackptr -> setextendedstate(true, ECS_DURING_STARTUP);
		MCdefaultstackptr -> message(MCM_start_up, nil, False, True);
		MCdefaultstackptr -> setextendedstate(false, ECS_DURING_STARTUP);
	}
	
	if (!MCquit)
	{
		MCresult -> fetch(ep);
		ep . appendchar('\0');
		if (ep . getsvalue() . getlength() == 1)
		{
			sptr -> open();
			MCImage::init();
			
			X_main_loop();

			MCresult -> fetch(ep);
			ep . appendchar('\0');
			if (ep . getsvalue() . getlength() == 1)
				return IO_NORMAL;
		}

		if (sptr -> getscript() != NULL)
			memset(sptr -> getscript(), 0, strlen(sptr -> getscript()));

		destroystack(sptr, True);
		MCtopstackptr = NULL;
		MCquit = False;
		MCenvironmentactive = False;

		send_relaunch();

		sptr = findstackname(ep . getsvalue() . getstring());

		if (sptr == NULL && (stat = loadfile(ep . getsvalue() . getstring(), sptr)) != IO_NORMAL)
			return stat;
	}

	if (!MCquit)
	{
		// OK-2007-11-13 : Bug 5525, after opening the IDE engine, the allowInterrupts should always default to false,
		// regardless of what the environment stack may have set it to.
		MCallowinterrupts = true;
		sptr -> setparent(this);
		MCdefaultstackptr = MCstaticdefaultstackptr = stacks;
		send_startup_message(false);
		if (!MCquit)
			sptr -> open();
	}

	return IO_NORMAL;
}
Beispiel #28
0
static int
common_load_kernel(const char *file, u_long *basemem, u_long *extmem,
    physaddr_t loadaddr, int floppy, u_long marks[MARK_MAX])
{
	int fd;
#ifdef XMS
	u_long		xmsmem;
	physaddr_t	origaddr = loadaddr;
#endif

	*extmem = getextmem();
	*basemem = getbasemem();

#ifdef XMS
	if ((getextmem1() == 0) && (xmsmem = checkxms())) {
	        u_long kernsize;

		/*
		 * With "CONSERVATIVE_MEMDETECT", extmem is 0 because
		 *  getextmem() is getextmem1(). Without, the "smart"
		 *  methods could fail to report all memory as well.
		 * xmsmem is a few kB less than the actual size, but
		 *  better than nothing.
		 */
		if (xmsmem > *extmem)
			*extmem = xmsmem;
		/*
		 * Get the size of the kernel
		 */
		marks[MARK_START] = loadaddr;
		if ((fd = loadfile(file, marks, COUNT_KERNEL)) == -1)
			return EIO;
		close(fd);

		kernsize = marks[MARK_END];
		kernsize = (kernsize + 1023) / 1024;

		loadaddr = xmsalloc(kernsize);
		if (!loadaddr)
			return ENOMEM;
	}
#endif
	marks[MARK_START] = loadaddr;
	if ((fd = loadfile(file, marks,
	    LOAD_KERNEL & ~(floppy ? LOAD_BACKWARDS : 0))) == -1)
		return EIO;

	close(fd);

	/* Now we know the root fs type, load modules for it. */
	if (fsmod != NULL)
		module_add(fsmod);
	if (fsmod !=NULL && fsmod2 != NULL && strcmp(fsmod, fsmod2) != 0)
		module_add(fsmod2);

	/*
	 * Gather some information for the kernel. Do this after the
	 * "point of no return" to avoid memory leaks.
	 * (but before DOS might be trashed in the XMS case)
	 */
#ifdef PASS_BIOSGEOM
	bi_getbiosgeom();
#endif
#ifdef PASS_MEMMAP
	bi_getmemmap();
#endif

#ifdef XMS
	if (loadaddr != origaddr) {
		/*
		 * We now have done our last DOS IO, so we may
		 * trash the OS. Copy the data from the temporary
		 * buffer to its real address.
		 */
		marks[MARK_START] -= loadaddr;
		marks[MARK_END] -= loadaddr;
		marks[MARK_SYM] -= loadaddr;
		marks[MARK_END] -= loadaddr;
		ppbcopy(loadaddr, origaddr, marks[MARK_END]);
	}
#endif
	marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) &
	    (-sizeof(int));
	image_end = marks[MARK_END];
	kernel_loaded = true;

	return 0;
}
void Load()
{
	string line;
	ifstream myfile ("PlayerCharacter.txt");
	if (myfile.is_open())
	{
		getline (myfile,line);
		if (line != "")
		{
			Combatant temp;
			int roomNum = 0;
						
			PC->SetName(line);
			getline (myfile,line);
			PC->SetDesc(line);
			getline (myfile,line);
			PC->SetLevel(atoi(line.c_str()));
			getline (myfile,line);
			PC->SetPrimeStat(line);
			getline (myfile,line);
			PC->SetSecondStat(line);
			getline (myfile,line);
			PC->SetCurrentRoom(World::GetInstance()->GetRooms()[atoi(line.c_str())]);
			getline (myfile,line);
			temp.SetMaxHp(atoi(line.c_str()));
			getline (myfile,line);
			temp.SetMaxMp(atoi(line.c_str()));
			getline (myfile,line);
			temp.SetMaxStr(atoi(line.c_str()));
			getline (myfile,line);
			temp.SetMaxAgi(atoi(line.c_str()));
			getline (myfile,line);
			temp.SetMaxAs(atoi(line.c_str()));
			getline (myfile,line);
			temp.SetHp(atoi(line.c_str()));
			getline (myfile,line);
			temp.SetMp(atoi(line.c_str()));
			getline (myfile,line);
			temp.SetStr(atoi(line.c_str()));
			getline (myfile,line);
			temp.SetAgi(atoi(line.c_str()));
			getline (myfile,line);
			temp.SetAs(atoi(line.c_str()));
			getline (myfile,line);
			temp.SetExp(atoi(line.c_str()));
			getline (myfile,line);
			temp.SetHp(temp.GetHp()-atoi(line.c_str())); //reduce the player's stats by the equipment boost so that it isn't doubled when items are loaded
			temp.SetMaxHp(temp.GetMaxHp()-atoi(line.c_str()));
			getline (myfile,line);
			temp.SetMp(temp.GetMp()-atoi(line.c_str()));
			temp.SetMaxMp(temp.GetMaxMp()-atoi(line.c_str()));
			getline (myfile,line);
			temp.SetAgi(temp.GetAgi()-atoi(line.c_str()));
			temp.SetMaxAgi(temp.GetMaxAgi()-atoi(line.c_str()));
			getline (myfile,line);
			temp.SetStr(temp.GetStr()-atoi(line.c_str()));
			temp.SetMaxStr(temp.GetMaxStr()-atoi(line.c_str()));
			getline (myfile,line);
			temp.SetAs(temp.GetAs()-atoi(line.c_str()));
			temp.SetMaxAs(temp.GetMaxAs()-atoi(line.c_str()));

			PC->SetStats(temp);
		}
	}
	else
		cout << "Unable to open load file. Load failed." << endl;
	myfile.close();

	ifstream loadfile ("NPCload.txt");
	line = "";

	if (loadfile.is_open())
	{	
		for(int a = 0; a < World::GetInstance()->RoomCount(); a++)
		{
			if(World::GetInstance()->GetRooms()[a]->NpcList().size() > 0)
			{
				for(int b = 0; b < World::GetInstance()->GetRooms()[a]->NpcList().size(); b++)
				{
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->SetNumNpc(atoi(line.c_str()));
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetLife(line);
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetMaxHp(atoi(line.c_str()));
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetMaxMp(atoi(line.c_str()));
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetMaxStr(atoi(line.c_str()));
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetMaxAgi(atoi(line.c_str()));
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetMaxAs(atoi(line.c_str()));
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetHp(atoi(line.c_str()));
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetMp(atoi(line.c_str()));
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetStr(atoi(line.c_str()));
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetAgi(atoi(line.c_str()));
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetAs(atoi(line.c_str()));
					getline(loadfile, line);
					World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetExp(atoi(line.c_str()));
				}
			}
		}
		cout << endl <<"Load Completed" << endl << endl;
		loadfile.close();
	}
	else
		cout << "Unable to Load file";
}
Beispiel #30
0
/*
 * This gets arguments from the first stage boot lader, calls PROM routines
 * to open and load the program to boot, and then transfers execution to
 * that new program.
 */
int
main(int argc, char **argv)
{
	char *name, **namep, *dev, *kernel;
	char bootname[PATH_MAX], bootpath[PATH_MAX];
	int win;
	u_long marks[MARK_MAX];
	struct btinfo_symtab bi_syms;
	struct btinfo_bootpath bi_bpath;
	extern void prom_init(void);
	void (*entry)(int, char **, char **, u_int, char *);

	prom_init();

	/* print a banner */
	printf("\n");
	printf("NetBSD/mipsco " NETBSD_VERS " " BOOT_TYPE_NAME 
	       " Bootstrap, Revision %s\n", bootprog_rev);

	/* initialise bootinfo structure early */
	bi_init(BOOTINFO_ADDR);

	dev = name = NULL;
	if (argc > 1) {
		kernel = devsplit(argv[1], bootname);
		if (*bootname) {
			dev = bootname;
			if (*kernel)
				name = argv[1];
			++argv;
			--argc;
		}

	}
	if (dev == NULL) {
		(void) devsplit(argv[0], bootname);
		dev = bootname;
	}

	memset(marks, 0, sizeof marks);
	if (name != NULL)
		win = (loadfile(name, marks, LOAD_KERNEL) == 0);
	else {
		win = 0;
		for (namep = kernelnames, win = 0; *namep != NULL && !win;
		    namep++) {
			kernel = *namep;
			strcpy(bootpath, dev);
			strcat(bootpath, kernel);
			printf("Loading: %s\n", bootpath);
			win = (loadfile(bootpath, marks, LOAD_ALL) != -1);
			if (win) {
				name = bootpath;
			}
		}
	}
	if (!win)
		goto fail;

	strncpy(bi_bpath.bootpath, kernel, BTINFO_BOOTPATH_LEN);
	bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath));

	entry = (void *) marks[MARK_ENTRY];
	bi_syms.nsym = marks[MARK_NSYM];
	bi_syms.ssym = marks[MARK_SYM];
	bi_syms.esym = marks[MARK_END];
	bi_add(&bi_syms, BTINFO_SYMTAB, sizeof(bi_syms));

	printf("Starting at 0x%x\n\n", (u_int)entry);

	(*entry)(argc, argv, NULL, BOOTINFO_MAGIC, (char *)BOOTINFO_ADDR);

	(void)printf("KERNEL RETURNED!\n");

fail:
	(void)printf("Boot failed!  Halting...\n");
	return (0);
}