/*
 * This is the main function for dumping any node.
 */
SV *
load_node(perl_yaml_loader_t *loader)
{
    /* Get the next parser event */
    if (!yaml_parser_parse(&loader->parser, &loader->event))
        goto load_error;

    /* Return NULL when we hit the end of a scope */
    if (loader->event.type == YAML_DOCUMENT_END_EVENT ||
        loader->event.type == YAML_MAPPING_END_EVENT ||
        loader->event.type == YAML_SEQUENCE_END_EVENT) return NULL;

    /* Handle loading a mapping */
    if (loader->event.type == YAML_MAPPING_START_EVENT) {
        SV *hash_ref;
        char *tag = (char *)loader->event.data.mapping_start.tag;

        /* Handle mapping tagged as a Perl hard reference */
        if (tag && strEQ(tag, TAG_PERL_REF))
            return load_scalar_ref(loader);
        
        /* Handle mapping tagged as a Perl typeglob */
        if (tag && strEQ(tag, TAG_PERL_GLOB))
            return load_glob(loader);

        /* Load the mapping into a hash ref and return it */
        return load_mapping(loader, NULL);
    }

    /* Handle loading a sequence into an array */
    if (loader->event.type == YAML_SEQUENCE_START_EVENT)
        return load_sequence(loader);

    /* Handle loading a scalar */
    if (loader->event.type == YAML_SCALAR_EVENT)
        return load_scalar(loader);

    /* Handle loading an alias node */
    if (loader->event.type == YAML_ALIAS_EVENT)
        return load_alias(loader);

    /* Some kind of error occurred */
    if (loader->event.type == YAML_NO_EVENT)
        croak(loader_error_msg(loader, NULL));

    croak(ERRMSG "Invalid event '%d' at top level", (int) loader->event.type);

load_error:
    croak(loader_error_msg(loader, NULL));
}
Beispiel #2
0
int
main(int argc, char **argv)
{
	char c;
	const char *p, *browser = NULL, *definition = NULL;
	STRBUF *arg = strbuf_open(0);
	STRBUF *URL = strbuf_open(0);

	while (--argc > 0 && ((c = (++argv)[0][0]) == '-' || c == '+')) {
		if (argv[0][1] == '-') {
			if (!strcmp("--help", argv[0]))
				help();
			else if (!strcmp("--version", argv[0]))
				show_version++;
			else if (!strcmp("--quiet", argv[0])) {
				qflag++;
				vflag = 0;
			} else if (!strcmp("--verbose", argv[0])) {
				vflag++;
				qflag = 0;
			} else
				usage();
			continue;
		}
		if (c == '+') {
			linenumber = atoi(argv[0] + 1);
			continue;
		}
		p = argv[0] + 1;
		switch (*p) {
		case 'b':
			browser = argv[1];
			--argc; ++argv;
			break;
		case 'd':
			definition = argv[1];
			--argc; ++argv;
			break;
		case 'p':
			pflag++;
			break;
		case 'q':
			qflag++;
			setquiet();
			break;
		case 'v':
			vflag++;
			setverbose();
			break;
		default:
			usage();
		}
	}
	if (show_version)
		version(progname, vflag);
	/*
	 * Load aliases from .gozillarc.
	 */
	load_alias();

	/*
	 * Decide browser.
	 */
	if (!browser && getenv("BROWSER"))
		browser = getenv("BROWSER");
	if (!browser && alias("BROWSER"))
		browser = alias("BROWSER");
	/*
	 * In DOS & Windows, let the file: association handle it.
	 */
#if !(_WIN32 || __DJGPP__)
	if (!browser)
		browser = "mozilla";
#endif

	/*
	 * Replace alias name.
	 */
	if (definition == NULL) {
		if (argc == 0)
			usage();
		strbuf_puts(arg, argv[0]);
		/*
		 * Replace with alias value.
		 */
		if ((p = alias(strbuf_value(arg))) != NULL) {
			strbuf_reset(arg);
			strbuf_puts(arg, p);
		}
	}
	/*
	 * Get URL.
	 */
	{
		char *argument = strbuf_value(arg);

		/*
		 * Protocol (xxx://...)
		 */
		if (!definition && isprotocol(argument)) {
			strbuf_puts(URL, argument);
		} else {
			const char *HTMLdir = NULL;

			if (setupdbpath(0) == 0) {
				cwd = get_cwd();
				root = get_root();
				dbpath = get_dbpath();
				HTMLdir = locate_HTMLdir();
			} 
			/*
			 * Make a URL of hypertext from the argument.
			 */
			if (HTMLdir != NULL) {
				if (definition)
					getdefinitionURL(definition, HTMLdir, URL);
				else
					getURL(argument, HTMLdir, URL);
			}
			/*
			 * Make a file URL.
			 */
			else if (test("fr", argument) || test("dr", argument)) {
				char cwd[MAXPATHLEN];
				char result[MAXPATHLEN];

				if (getcwd(cwd, sizeof(cwd)) == NULL)
					die("cannot get current directory.");
				if (rel2abs(argument, cwd, result, sizeof(result)) == NULL)
					die("rel2abs failed.");
				strbuf_puts(URL, "file://");
				strbuf_puts(URL, result);
			} else {
				die_with_code(1, "file '%s' not found.", argument);
			}
		}
	}
	if (pflag) {
		fprintf(stdout, "%s\n", strbuf_value(URL));
		if (vflag)
			fprintf(stdout, "using browser '%s'.\n", browser);
		exit(0);
	}
	/*
	 * Show URL's page.
	 */
	show_page_by_url(browser, strbuf_value(URL));
	exit(0);
}
Beispiel #3
0
uint STDCALL ge_load( pbuf in )
{
   pubyte   cur, end, ptemp;
   uint     size;
   pgehead  phead = ( pgehead )buf_ptr( in );

   // Проверка заголовка и целостности
   // Сравниваем с 'GE' с двумя нулями на конце

   if ( *( puint )phead != GE_STRING )//0x00004547 )
      msg( MNotGE | MSG_EXIT );
   if ( phead->crc != crc( ( pubyte )phead + 12, phead->size - 12, 0xFFFFFFFF ))
      msg( MCrcGE | MSG_EXIT );
   if ( phead->vermajor != GEVER_MAJOR || phead->verminor > GEVER_MINOR )
      msg( MVerGE | MSG_EXIT );

   _vm.loadmode = VMLOAD_GE;
   _vm.icnv = arr_count( &_vm.objtbl ) - KERNEL_COUNT;
//   print("icnv=%i\n", _vm.icnv );
   cur = ( pubyte )phead + phead->headsize;
   end = ( pubyte )phead + phead->size;
   while ( cur < end )
   {
      ptemp = cur + 5; // type + flag
      _vm.ipack = ( *( puint )( cur + 1 )) & GHCOM_PACK ? 1 : 0;

      size = load_bwd( &ptemp );
      ptemp = cur;
//      print("size=%i type=%i flag = %x\n", size, *cur, *( puint )( cur + 1 ) );
      switch ( *cur )
      {
         case OVM_NONE:
            load_none();
            break;
         case OVM_BYTECODE:
            load_bytecode( &cur, VMLOAD_GE );
            break;
         case OVM_EXFUNC:
            load_exfunc( &cur, 0 );
            _vm.loadmode = VMLOAD_GE;
            break;
        case OVM_TYPE:
            load_type( &cur );
            break;
        case OVM_GLOBAL:
            load_global( &cur );
            break;
        case OVM_DEFINE:
            load_define( &cur );
            break;
        case OVM_IMPORT:
            load_import( &cur );
            break;
         case OVM_RESOURCE:
            load_resource( &cur );
            break;
         case OVM_ALIAS:
            load_alias( &cur );
            break;
         default: 
            msg( MUnkGE | MSG_DVAL, cur - ( pubyte )phead );
      }
      cur = ptemp + size;
   }
   _vm.loadmode = VMLOAD_G;
   _vm.icnv  = 0;
   return 1;
}
Beispiel #4
0
int
main(int argc, char **argv)
{
	char c;
	const char *p, *browser = NULL, *definition = NULL;
	STRBUF *arg = strbuf_open(0);
	STRBUF *URL = strbuf_open(0);

	while (--argc > 0 && ((c = (++argv)[0][0]) == '-' || c == '+')) {
		if (argv[0][1] == '-') {
			if (!strcmp("--help", argv[0]))
				help();
			else if (!strcmp("--version", argv[0]))
				show_version++;
			else if (!strcmp("--quiet", argv[0])) {
				qflag++;
				vflag = 0;
			} else if (!strcmp("--verbose", argv[0])) {
				vflag++;
				qflag = 0;
			} else
				usage();
			continue;
		}
		if (c == '+') {
			linenumber = atoi(argv[0] + 1);
			continue;
		}
		p = argv[0] + 1;
		switch (*p) {
		case 'b':
			browser = argv[1];
			--argc; ++argv;
			break;
		case 'd':
			definition = argv[1];
			--argc; ++argv;
			break;
		case 'p':
			pflag++;
			break;
		case 'q':
			qflag++;
			setquiet();
			break;
		case 'v':
			vflag++;
			break;
		default:
			usage();
		}
	}
	if (show_version)
		version(progname, vflag);
	/*
	 * Load aliases from .gozillarc.
	 */
	load_alias();

	/*
	 * Decide browser.
	 */
	if (!browser && getenv("BROWSER"))
		browser = getenv("BROWSER");
	if (!browser && alias("BROWSER"))
		browser = alias("BROWSER");
	if (!browser)
		browser = "mozilla";

	/*
	 * Replace alias name.
	 */
	if (definition == NULL) {
		if (argc == 0)
			usage();
		strbuf_puts(arg, argv[0]);
		/*
		 * Replace with alias value.
		 */
		if ((p = alias(strbuf_value(arg))) != NULL) {
			strbuf_reset(arg);
			strbuf_puts(arg, p);
		}
	}
	/*
	 * Get URL.
	 */
	if (!definition && isprotocol(strbuf_value(arg))) {
		strbuf_puts(URL, strbuf_value(arg));
	} else {
		getdbpath(cwd, root, dbpath, 0);
		if (definition)
			getdefinitionURL(definition, URL);
		else
			getURL(strbuf_value(arg), URL);
	}
	if (pflag) {
		fprintf(stdout, "%s\n", strbuf_value(URL));
		if (vflag)
			fprintf(stdout, "using browser '%s'.\n", browser);
		exit(0);
	}
	/*
	 * Show URL's page.
	 */
	show_page_by_url(browser, strbuf_value(URL));
	exit(0);
}
/*
 * This is the main function for dumping any node.
 */
SV *
load_node(perl_yaml_loader_t *loader)
{
    SV* return_sv = NULL;
    /* This uses stack, but avoids (severe!) memory leaks */
    yaml_event_t uplevel_event;

    uplevel_event = loader->event;

    /* Get the next parser event */
    if (!yaml_parser_parse(&loader->parser, &loader->event))
        goto load_error;

    /* These events don't need yaml_event_delete */
    /* Some kind of error occurred */
    if (loader->event.type == YAML_NO_EVENT)
        goto load_error;

    /* Return NULL when we hit the end of a scope */
    if (loader->event.type == YAML_DOCUMENT_END_EVENT ||
        loader->event.type == YAML_MAPPING_END_EVENT ||
        loader->event.type == YAML_SEQUENCE_END_EVENT) {
            /* restore the uplevel event, so it can be properly deleted */
            loader->event = uplevel_event;
            return return_sv;
    }

    /* The rest all need cleanup */
    switch (loader->event.type) {
        char *tag;

        /* Handle loading a mapping */
        case YAML_MAPPING_START_EVENT:
            tag = (char *)loader->event.data.mapping_start.tag;

            /* Handle mapping tagged as a Perl hard reference */
            if (tag && strEQ(tag, TAG_PERL_REF)) {
                return_sv = load_scalar_ref(loader);
                break;
            }

            /* Handle mapping tagged as a Perl typeglob */
            if (tag && strEQ(tag, TAG_PERL_GLOB)) {
                return_sv = load_glob(loader);
                break;
            }

            return_sv = load_mapping(loader, NULL);
            break;

        /* Handle loading a sequence into an array */
        case YAML_SEQUENCE_START_EVENT:
            return_sv = load_sequence(loader);
            break;

        /* Handle loading a scalar */
        case YAML_SCALAR_EVENT:
            return_sv = load_scalar(loader);
            break;

        /* Handle loading an alias node */
        case YAML_ALIAS_EVENT:
            return_sv = load_alias(loader);
            break;

        default:
            croak("%sInvalid event '%d' at top level", ERRMSG, (int) loader->event.type);
    }

    yaml_event_delete(&loader->event);

    /* restore the uplevel event, so it can be properly deleted */
    loader->event = uplevel_event;

    return return_sv;

    load_error:
        croak("%s", loader_error_msg(loader, NULL));
}