vrtc / pjass (public) (License: BSD) (since 2023-08-03) (hash sha1)
pjass is a free Jass scripting language parser. This repository is a fork of lep/pjass. The goal is to add Debian packaging. As of the time of this writing, it works for current stable, that is Debian 12 (bookworm).

/main.c (e50f3c6407908ffbd851b8de72229baf649c3e64) (6470 bytes) (mode 100644) (type blob)

#include "token.yy.h"
#include "grammar.tab.h"

#include "misc.h"

#ifndef VERSIONSTR
#define VERSIONSTR "1.0-git"
#endif

static struct typenode* addPrimitiveType(const char *name)
{
    struct typenode *newty= newtypenode(name, NULL);
    put(&types, name, newty);
    return newty;
}


static void init()
{
    ht_init(&functions, 1 << 13);
    ht_init(&globals, 1 << 13);
    ht_init(&locals, 1 << 6);
    ht_init(&params, 1 << 5);
    ht_init(&types, 1 << 7);
    ht_init(&initialized, 1 << 11);

    ht_init(&bad_natives_in_globals, 1 << 4);
    ht_init(&shadowed_variables, 1 << 4);
    
    ht_init(&uninitialized_globals, 1 << 11);
    
    ht_init(&string_literals, 1 << 10);
    
    tree_init(&stringlit_hashes);

    gHandle = addPrimitiveType("handle");
    gInteger = addPrimitiveType("integer");
    gReal = addPrimitiveType("real");
    gBoolean = addPrimitiveType("boolean");
    gString = addPrimitiveType("string");
    gCode = addPrimitiveType("code");

    gCodeReturnsBoolean = newtypenode("codereturnsboolean", gCode);
    gCodeReturnsNoBoolean = newtypenode("codereturnsboolean", gCode);

    gNothing = newtypenode("nothing", NULL);
    gNull = newtypenode("null", NULL);

    gAny = newtypenode("any", NULL);
    gNone = newtypenode("none", NULL);
    gEmpty = newtypenode("empty", NULL);

    curtab = &globals;

    pjass_flags = 0;

    fno = 0;
    fnannotations = 0;
    annotations = 0;
    haderrors = 0;
    ignorederrors = 0;
    islinebreak = 1;
    inblock = false;
    isconstant = false;
    inconstant = false;
    infunction = false;

    fCurrent = NULL;
    fFilter = NULL;
    fCondition = NULL;
    fStringHash = NULL;

    ht_init(&available_flags, 16);
    ht_put(&available_flags, "rb", (void*)flag_rb);
    ht_put(&available_flags, "shadow", (void*)flag_shadowing);
    ht_put(&available_flags, "filter", (void*)flag_filter);
    ht_put(&available_flags, "nosyntaxerror", (void*)flag_syntaxerror);
    ht_put(&available_flags, "nosemanticerror", (void*)flag_semanticerror);
    ht_put(&available_flags, "noruntimeerror", (void*)flag_runtimeerror);
    ht_put(&available_flags, "checkglobalsinit", (void*)flag_checkglobalsinit);
    ht_put(&available_flags, "checkstringhash", (void*)flag_checkstringhash);
    

    ht_put(&bad_natives_in_globals, "OrderId", (void*)NullInGlobals);
    ht_put(&bad_natives_in_globals, "OrderId2String", (void*)NullInGlobals);
    ht_put(&bad_natives_in_globals, "UnitId2String", (void*)NullInGlobals);

    ht_put(&bad_natives_in_globals, "GetObjectName", (void*)CrashInGlobals);
    ht_put(&bad_natives_in_globals, "CreateQuest", (void*)CrashInGlobals);
    ht_put(&bad_natives_in_globals, "CreateMultiboard", (void*)CrashInGlobals);
    ht_put(&bad_natives_in_globals, "CreateLeaderboard", (void*)CrashInGlobals);
}

static void dofile(FILE *fp, const char *name)
{
    lineno = 1;
    islinebreak = 1;
    isconstant = false;
    inconstant = false;
    inblock = false;
    afterendglobals = false;
    encoutered_first_function = false;
    inglobals = false;
    int olderrs = haderrors;
    yy_switch_to_buffer(yy_create_buffer(fp, BUFSIZE));
    curfile = name;

    while ( yyparse() ) ;

    if (olderrs == haderrors){
        printf("Parse successful: %8d lines: %s\n", lineno, curfile);
    }else{
        printf("%s failed with %d error%s\n", curfile, haderrors - olderrs,(haderrors == olderrs + 1) ? "" : "s");
    }
    totlines += lineno;
    fno++;
}

static void printversion()
{
	printf("Pjass version %s by Rudi Cilibrasi, modified by AIAndy, PitzerMike, Deaod and lep\n", VERSIONSTR);
}

static void doparse(int argc, char **argv)
{
	int i;
	for (i = 1; i < argc; ++i) {
		if (argv[i][0] == '-' && argv[i][1] == 0) {
			dofile(stdin, "<stdin>");
			didparse = 1;
			continue;
		}
		if (strcmp(argv[i], "-h") == 0) {
			printversion();
printf(
"To use this program, list the files you would like to parse in order.\n"
"If you would like to parse from standard input (the keyboard), then\n"
"use - as an argument.  If you supply no arguments to pjass, it will\n"
"parse the console standard input by default.\n"
"To test this program, go into your Scripts directory, and type:\n"
"pjass common.j common.ai Blizzard.j\n"
"pjass accepts some options:\n"
"pjass -h               Display this help\n"
"pjass -v               Display version information and exit\n"
"pjass +rb              Enable returnbug checking\n"
"pjass -rb              Disable returnbug checking\n"
"pjass +checkstringhash Enable StringHash collision checking"
"pjass -checkstringhash Disable StringHash collision checking"
"pjass +shadow          Enable error on variable shadowing\n"
"pjass -shadow          Disable error on variable shadowing\n"
"pjass +filter          Enable error on inappropriate code usage for Filter\n"
"pjass -filter          Disable error on inappropriate code usage for Filter\n"
"pjass +nosyntaxerror   Disable all syntax errors\n"
"pjass -nosyntaxerror   Enable syntax error reporting\n"
"pjass +nosemanticerror Disable all semantic errors\n"
"pjass -nosemanticerror Enable semantic error reporting\n"
"pjass +noruntimeerror  Disable all runtime errors\n"
"pjass -noruntimeerror  Enable runtime error reporting\n"
"pjass -                Read from standard input (may appear in a list)\n"
);
			exit(0);
		}
		if (strcmp(argv[i], "-v") == 0) {
			printf("%s version %s\n", argv[0], VERSIONSTR);
			exit(0);
		}
        if( isflag(argv[i], &available_flags)){
            pjass_flags = updateflag(pjass_flags, argv[i], &available_flags);
            continue;
        }

		FILE *fp;
		fp = fopen(argv[i], "rb");
		if (fp == NULL) {
			printf("Error: Cannot open %s\n", argv[i]);
			haderrors++;
			continue;
		}

		dofile(fp, argv[i]);
		didparse = 1;
		fclose(fp);
	}
    if (argc == 1) {
        didparse = 1;
        dofile(stdin, "<stdin>");
    }
}

int main(int argc, char **argv)
{
    init();
    doparse(argc, argv);

    if (!haderrors && didparse) {
        printf("Parse successful: %8d lines: %s\n", totlines, "<total>");
        if (ignorederrors) {
            printf("%d errors ignored\n", ignorederrors);
        }
        return 0;
    } else {
        if (haderrors) {
            printf("Parse failed: %d error%s total\n", haderrors, haderrors == 1 ? "" : "s");
        } else {
            printf("Parse failed\n");
        }
        if (ignorederrors) {
            printf("%d errors ignored\n", ignorederrors);
        }
        return 1;
    }
}


Mode Type Size Ref File
100644 blob 170 28f83f8deb57bbc09c713a866975355fd9225827 .gitignore
100644 blob 48 3bfb16e6c32903fb8e4db429b412ee6e8ef23a14 AUTHORS
100644 blob 3557 a62ad00cdae7cd8a72c80d1d6ce2796e53b6d58c GNUmakefile
100644 blob 1313 4dc80d23e5c4804173171f9e03724a7d9fff66a1 LICENSE
100644 blob 1431 176e50b9b24ded89c009136a2386586cacd5fcd2 blocks.c
100644 blob 282 7e063255643b647d598dadd7832458b24af8999d blocks.h
100755 blob 428 cc6218cbb759cfd1deef9a20b246b8ed7697bd02 check.sh
100755 blob 273 b0e5e8c7418adb04f6a7d76e9c011b4ba4ef3092 fail.sh
100644 blob 266 88a7c9f4c9cfca968c1b863d4fd49131b5c2e175 funcdecl.c
100644 blob 276 f409be6b975f0a454de860058f1bf91849f1de96 funcdecl.h
100644 blob 22316 d468d760ea15a1302b551138f6f2e51bed797982 grammar.y
100644 blob 1684 3f87f5c4542560d5ded7bd36438657a5869771ca hashtable.c
100644 blob 501 2185dc1cb949f6fa3a1b0985b4caaf7769456156 hashtable.h
100644 blob 6470 e50f3c6407908ffbd851b8de72229baf649c3e64 main.c
100644 blob 24837 9de9d46a2eb5f8cc19b170d035009e064f9c1ca3 misc.c
100644 blob 4680 d0822164a1e66dfe614ebbfa8cb24bd904d4fe00 misc.h
100644 blob 330 92a4597d6df5097c58649391541d54f06b3bda1b paramlist.c
100644 blob 256 bb253362ef26a0ea881856aebeb8503fb82646fb paramlist.h
100644 blob 3680 0d3a55aa2bd7911e71390008b7723399c094eba1 readme.md
100644 blob 2419 2da92786104975ea22a86ebfa36e70351bd5503f sstrhash.c
100644 blob 142 554d4f7e4b94fb54dc58105adfc9cb4afac6887a sstrhash.h
040000 tree - 353c2b19d039ebd6ba45c6cfa887ee3975b60ace tests
100644 blob 6881 5b807517d3865b302cbde97aa949347c60a27a1d token.l
100644 blob 1265 7fe0fbe5c32390cfd7a0629649fccc5899738aeb tree.c
100644 blob 356 d943f2d407216cea33c9931439d6802af7d08ce6 tree.h
100644 blob 2363 84b80d18c7006a12bf02635dcd3ad47f459f6a61 typeandname.c
100644 blob 914 c7c2ecbf5459c7cb80bd2661e6ca78c32a780e10 typeandname.h
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/vrtc/pjass

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/vrtc/pjass

Clone this repository using git:
git clone git://git.rocketgit.com/user/vrtc/pjass

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main