Example #1
0
/* printing functions */
void PrintValue(VALUE value)
{
    switch (value.type)
    {
        case VAL_PRIMITIVE: 
//#ifdef WIN32
//            printf("%l64i", value.data.primitive); 
//#else
            printf("%lli", value.data.primitive); 
//#endif
            break;
        case VAL_FLOATING_POINT: 
            if (_SUPPORTS_80BIT_FLOATING_POINT)
            {
                printf("%.18Lg", value.data.floatp);
                break;
            } else {
                printf("%.16Lg", value.data.floatp); 
                break;
            }
        case VAL_STRING: printf("%s", value.data.string); break;
        case VAL_REFERENCE: PrintObject(value.data.reference); break;
        case VAL_FUNCTION: PrintFunction(value.data.function); break;
        case VAL_DICTIONARY: PrintDictionary(value.data.dictionary); break;
    default:
        case VAL_NIL: printf("[NIL]"); break;
    }
}
Example #2
0
void PrintFunction(const Proto* tf)
{
 int i,n=tf->nkproto;
 PrintHeader(tf);
 PrintCode(tf);
 for (i=0; i<n; i++) PrintFunction(tf->kproto[i]);
}
Example #3
0
static void PrintFunction(const LuaProto* f, int full)
{
 int i,n=(int)f->subprotos_.size();
 PrintHeader(f);
 PrintCode(f);
 if (full) PrintDebug(f);
 for (i=0; i<n; i++) PrintFunction(f->subprotos_[i],full);
}
Example #4
0
File: luac.c Project: bysdxt/xLua
static void PrintFunction(const Proto* f, int full)
{
 int i,n=f->sizep;
 PrintHeader(f);
 PrintCode(f);
 if (full) PrintDebug(f);
 for (i=0; i<n; i++) PrintFunction(f->p[i],full);
}
Example #5
0
void PrintFunction(const Proto *f, int full) {
    int i, n = f->sizep;
    PrintHeader(f);
    PrintCode(f);
    if (full) {
        PrintConstants(f);
        PrintLocals(f);
        PrintUpvalues(f);
    }
    for (i = 0; i < n; i++) PrintFunction(f->p[i], full);
}
/**
**	Set a* parameter (cost of FIXED unit tile crossing).
*/
local SCM CclAStarSetFixedUCC(SCM cost)
{
    int i;

    i=gh_scm2int(cost);
    if( i<=0) {
	PrintFunction();
	fprintf(stdout,"Fixed unit crossing cost must be strictly positive\n");
	i=TheMap.Width*TheMap.Height;
    }
    AStarFixedUnitCrossingCost=i;

    return SCM_UNSPECIFIED;
}
/**
**	Set a* parameter (cost of MOVING unit tile crossing).
*/
local SCM CclAStarSetMovingUCC(SCM cost)
{
    int i;

    i=gh_scm2int(cost);
    if( i<=0) {
	PrintFunction();
	fprintf(stdout,"Moving unit crossing cost must be strictly positive\n");
	i=1;
    }
    AStarMovingUnitCrossingCost=i;

    return SCM_UNSPECIFIED;
}
Example #8
0
/**
**  Set forest regeneration speed.
**
**  @param l  Lua state.
**
**  @return   Old speed
*/
static int CclSetForestRegeneration(lua_State *l)
{
	LuaCheckArgs(l, 1);
	int i = LuaToNumber(l, 1);
	if (i < 0 || i > 255) {
		PrintFunction();
		fprintf(stdout, "Regeneration speed should be 0 - 255\n");
		i = 100;
	}
	const int old = ForestRegeneration;
	ForestRegeneration = i;

	lua_pushnumber(l, old);
	return 1;
}
Example #9
0
// print to output
BoundaryCondition *MatPtFluxBC::PrintBC(ostream &os)
{
    char nline[200];
    
    sprintf(nline,"%7d %2d   %2d  %2d %15.7e %15.7e",ptNum,direction,face,style,
			UnitsController::Scaling(1.e3)*GetBCValueOut(),GetBCFirstTimeOut());
    os << nline;
	PrintFunction(os);
	
	// for function input scale for Legacy units
	if(style==FUNCTION_VALUE)
		scale = UnitsController::Scaling(1.e-3);
	
    return (BoundaryCondition *)GetNextObject();
}
Example #10
0
/**
**  Fog of war opacity.
**
**  @param l  Lua state.
*/
static int CclSetFogOfWarOpacity(lua_State *l)
{
	LuaCheckArgs(l, 1);
	int i = LuaToNumber(l, 1);
	if (i < 0 || i > 255) {
		PrintFunction();
		fprintf(stdout, "Opacity should be 0 - 256\n");
		i = 100;
	}
	FogOfWarOpacity = i;

	if (!CclInConfigFile) {
		Map.Init();
	}
	return 0;
}
Example #11
0
// print to output
BoundaryCondition *MatPtLoadBC::PrintBC(ostream &os)
{
    char nline[200];
    
    sprintf(nline,"%7d %2d %2d %15.7e %15.7e",ptNum,direction,style,
			UnitsController::Scaling(1.e-6)*GetBCValueOut(),GetBCFirstTimeOut());
    os << nline;
	PrintFunction(os);
    
    // initial value is F in N or N/numParticles if net, but if function
    //      initial value is 1 or 1/numParticles if net
	
	// rescale ... for fuction value is 1 or 1/numParticles if net force
	if(style==FUNCTION_VALUE)
		scale = GetBCValue();
	
    return (BoundaryCondition *)GetNextObject();
}
Example #12
0
// print to output
BoundaryCondition *MatPtLoadBC::PrintBC(ostream &os)
{
    char nline[200];
    
    sprintf(nline,"%7d %2d %2d %15.7e %15.7e",ptNum,direction,style,value,ftime);
    os << nline;
	PrintFunction(os);
    
    // initial value is F in N or N/numParticles if net, but if function
    //      initial value is 1 or 1/numParticles if net
	
	// rescale
	value*=1.e6;		// Multiply by 1e6 to get N (kg-m/sec^2) to g-mm/sec^2
	if(style==FUNCTION_VALUE)
		scale=value;		// ... value is now 1.e6 or 1.e6/numParticles if net force
	else
		scale*=1.e6;		// ... same in case using a function
	
    return (BoundaryCondition *)GetNextObject();
}
static bool DumpFrame(void *process, DWORD_PTR frameAddress)
{
	const int functionLength = 255;
	IMAGEHLP_SYMBOL *symbol = (IMAGEHLP_SYMBOL*)malloc(sizeof(IMAGEHLP_SYMBOL) + functionLength);
	DWORD_PTR moduleBase = SymGetModuleBase(process, frameAddress);
	const char *moduleName = NULL, *functionName = NULL;
	DWORD_PTR displacement;
	char moduleFilename[MAX_PATH];

	symbol->SizeOfStruct = (sizeof(*symbol)) + functionLength;
	symbol->MaxNameLength = functionLength - 1;

	if (moduleBase && GetModuleFileName((HINSTANCE)moduleBase, moduleFilename, MAX_PATH))
		moduleName = moduleFilename;

	if (SymGetSymFromAddr(process, frameAddress, &displacement, symbol))
		functionName = symbol->Name;

	PrintFunction(moduleName, functionName, frameAddress, displacement);

	free(symbol);
}
Example #14
0
void PrintStackTrace()
{
    CALLSTACK* stack = &gStackTrace;
    printf("Program halted on line %i.\n", (line_error+1));
    if (failed_production) {
        printf("Failed production: ");
        /* PrintParseTree(failed_production, CONTEXT_FREE_GRAMMAR); */
        PrintParseTreeFormat(failed_production, CONTEXT_FREE_GRAMMAR);
        printf("\n");
    }

    if (stack->fn_name) {
        printf("Printing stack trace:\n\n");
        int depth = 0; int i;
        while (stack) {
            for (i = 0; i < depth; i++) printf("  ");
            //printf("%i. %s:\n", depth, stack->fn_name);
            PrintFunction(stack->function);
            printf("\n");
            stack = stack->next;
            depth++;
        }
    }
}
Example #15
0
/*
============
main
============
*/
int main (int argc, char **argv)
{
	const char	*psrc;
	void		*src, *src2;
	char	filename[1024];
	char	*nameptr; /* filename[] without the parent sourcedir */
	int		p, crc;
	double	start, stop;

	myargc = argc;
	myargv = argv;

	if (CheckParm("-?") || CheckParm("-h") || CheckParm("-help") || CheckParm("--help"))
	{
		printf(" Compiles progs.dat using progs.src in the current directory\n");
		printf(" -src <directory> : Specify source directory\n");
		printf(" -name <source>   : Specify the name of the .src file\n");
		printf(" -version <n>     : Output progs as version n (either 6 or 7)\n");
		printf(" -v6              : Output progs as version 6\n");
		printf(" -v7              : Output progs as version 7\n");
		printf(" -dcc (or -dec)   : decompile progs.dat in current directory\n");
		printf(" -dcc -name <progsname> : specify name of progs to decompile\n");
		printf(" -dcc -info : only print brief info about the progs and exit\n");
		printf(" -dcc -fix : fixes mangled names during decompile\n");
		printf(" -dcc -fields     : dumps all fielddefs to stdout\n");
		printf(" -dcc -functions  : dumps all functions to stdout\n");
		printf(" -dcc -globaldefs : dumps all globaldefs to stdout\n");
		printf(" -dcc -prglobals  : dumps all pr_globals to stdout\n");
		printf(" -dcc -statements : dumps all statements to stdout\n");
		printf(" -dcc -strings    : dumps all pr_strings to stdout\n");
		printf(" -dcc -asm <functionname> : decompile filename to the console\n");
		printf(" -dcc -dump -asm <functionname> : same as above but will show\n\t\tinstructions (opcodes and parms) as well\n");
		exit(0);
	}

	ValidateByteorder ();

	if (CheckParm("-dcc") || CheckParm("-dec"))
	{
		Dcc_main (argc, argv);
		exit (0);
	}

	start = COM_GetTime ();

	hcc_version_req = -1;	/* output as v6 if possible, otherwise as v7 */
	p = CheckParm("-version");
	if (p != 0)
	{
		if (p >= argc - 1)
			COM_Error ("No num specified for -version");
		p = atoi(argv[p+1]);
		switch (p)
		{
		case 6:
			hcc_version_req = PROG_VERSION_V6;
			break;
		case 7:
			hcc_version_req = PROG_VERSION_V7;
			break;
		default:
			COM_Error ("Version must be either 6 or 7");
			break;
		}
	}

	if (CheckParm("-v6"))	hcc_version_req = PROG_VERSION_V6;
	if (CheckParm("-v7"))	hcc_version_req = PROG_VERSION_V7;

	p = CheckParm("-src");
	if (p != 0)
	{
	/* everything will now be relative to sourcedir: */
		if (p >= argc - 1)
			COM_Error ("No source dirname specified with -src");
		strcpy(sourcedir, argv[p+1]);
		p = strlen (sourcedir);
		if (p && !IS_DIR_SEPARATOR(sourcedir[p - 1]))
		{
			sourcedir[p] = DIR_SEPARATOR_CHAR;
			sourcedir[p + 1] = '\0';
		}
		printf("Source directory: %s\n", sourcedir);
		strcpy(filename, sourcedir);
		nameptr = strchr(filename, '\0');
	}
	else
	{
		sourcedir[0] = '\0';
		nameptr = filename;
	}

	p = CheckParm("-name");
	if (p != 0)
	{
		if (p >= argc - 1)
			COM_Error ("No input filename specified with -name");
		strcpy(nameptr, argv[p+1]);
		printf("Input file: %s\n", nameptr);
	}
	else
	{
		strcpy(nameptr, "progs.src");
	}
	LoadFile(filename, &src);
	psrc = (char *) src;

	psrc = COM_Parse(psrc);
	if (!psrc)
		COM_Error("No destination filename. dhcc -help for info.");
	q_snprintf(destfile, sizeof(destfile), "%s%s", sourcedir, com_token);
	printf("outputfile: %s\n", destfile);

	hcc_OptimizeStringHeap = 1;

	InitData ();

	PR_BeginCompilation();

	// compile all the files
	do
	{
		psrc = COM_Parse(psrc);
		if (!psrc)
			break;

		strcpy (nameptr, com_token);
		printf ("compiling %s\n", nameptr);
		LoadFile (filename, &src2);

		if (!PR_CompileFile((char *)src2, nameptr))
			exit (1);
	} while (1);

	if (!PR_FinishCompilation())
		COM_Error ("compilation errors");

	p = CheckParm("-asm");
	if (p != 0)
	{
		for (p++; p < argc; p++)
		{
			if (argv[p][0] == '-')
				break;
			PrintFunction(argv[p]);
		}
	}

	// write progdefs.h
	strcpy(nameptr, "progdefs.h");
	crc = PR_WriteProgdefs(filename);

	// write data file
	WriteData(crc);

	// write files.dat
	WriteFiles();
	printf(" precache_sound: %10d / %10d\n", numsounds, MAX_SOUNDS);
	printf(" precache_model: %10d / %10d\n", nummodels, MAX_MODELS);
	printf("  precache_file: %10d / %10d\n", numfiles, MAX_FILES);

	stop = COM_GetTime ();
	printf("\n%d seconds elapsed.\n", (int)(stop - start));

	return 0;
}
Example #16
0
/*
============
main
============
*/
int main (int argc, char **argv)
{
	const char	*psrc;
	void		*src, *src2;
	char	filename[1024];
	char	*nameptr; /* filename[] without the parent sourcedir */
	int		p, crc;
	double	start, stop;
	int		registerCount, registerSize;
	int		statementCount, statementSize;
	int		functionCount, functionSize;
	int		fileInfo;
	int		quiet;

	myargc = argc;
	myargv = argv;

	if (CheckParm("-?") || CheckParm("-h") || CheckParm("-help") || CheckParm("--help"))
	{
		printf(" -oi              : Optimize Immediates\n");
		printf(" -on              : Optimize Name Table\n");
		printf(" -os              : Optimize String Heap\n");
		printf(" -quiet           : Quiet mode\n");
		printf(" -fileinfo        : Show object sizes per file\n");
		printf(" -pf              : precache_file() calls go into progs (old HCC compat)\n");
		printf(" -sc              : STR_ constants can be saved globals (old HCC compat)\n");
		printf(" -old             : Combined -pf and -sc (as above) for old HCC behavior\n");
		printf(" -src <directory> : Specify source directory\n");
		printf(" -name <source>   : Specify the name of the .src file\n");
		printf(" -version <n>     : Output progs as version n (either 6 or 7)\n");
		printf(" -v6              : Output progs as version 6\n");
		printf(" -v7              : Output progs as version 7\n");
		exit(0);
	}

	ValidateByteorder ();

	start = COM_GetTime ();

	hcc_version_req = -1;	/* output as v6 if possible, otherwise as v7 */
	p = CheckParm("-version");
	if (p != 0)
	{
		if (p >= argc - 1)
			COM_Error ("No num specified for -version");
		p = atoi(argv[p+1]);
		switch (p)
		{
		case 6:
			hcc_version_req = PROG_VERSION_V6;
			break;
		case 7:
			hcc_version_req = PROG_VERSION_V7;
			break;
		default:
			COM_Error ("Version must be either 6 or 7");
			break;
		}
	}

	if (CheckParm("-v6"))	hcc_version_req = PROG_VERSION_V6;
	if (CheckParm("-v7"))	hcc_version_req = PROG_VERSION_V7;

	p = CheckParm("-src");
	if (p != 0)
	{
	/* everything will now be relative to sourcedir: */
		if (p >= argc - 1)
			COM_Error ("No source dirname specified with -src");
		strcpy(sourcedir, argv[p+1]);
		p = strlen (sourcedir);
		if (p && !IS_DIR_SEPARATOR(sourcedir[p - 1]))
		{
			sourcedir[p] = DIR_SEPARATOR_CHAR;
			sourcedir[p + 1] = '\0';
		}
		printf("Source directory: %s\n", sourcedir);
		strcpy(filename, sourcedir);
		nameptr = strchr(filename, '\0');
	}
	else
	{
		sourcedir[0] = '\0';
		nameptr = filename;
	}

	p = CheckParm("-name");
	if (p != 0)
	{
		if (p >= argc - 1)
			COM_Error ("No input filename specified with -name");
		strcpy(nameptr, argv[p+1]);
		printf("Input file: %s\n", nameptr);
	}
	else
	{
		strcpy(nameptr, "progs.src");
	}
	LoadFile(filename, &src);
	psrc = (char *) src;

	psrc = COM_Parse(psrc);
	if (!psrc)
		COM_Error("No destination filename. hcc -help for info.");
	q_snprintf(destfile, sizeof(destfile), "%s%s", sourcedir, com_token);

	hcc_Compat_precache_file = CheckParm("-pf");
	hcc_Compat_STR_SAVEGLOBL = CheckParm("-sc");
	if (CheckParm("-old"))
	{
		hcc_Compat_precache_file = 1;
		hcc_Compat_STR_SAVEGLOBL = 1;
	}
	hcc_OptimizeImmediates = CheckParm("-oi");
	hcc_OptimizeNameTable = CheckParm("-on");
	hcc_OptimizeStringHeap = CheckParm("-os");
	hcc_WarningsActive = CheckParm("-nowarnings") ? false : true;
	hcc_ShowUnrefFuncs = CheckParm("-urfunc") ? true : false;

	fileInfo = CheckParm("-fileinfo");
	quiet = CheckParm("-quiet");

	InitData ();
	LX_Init ();
	CO_Init ();
	EX_Init ();

	PR_BeginCompilation();

	// compile all the files
	do
	{
		psrc = COM_Parse(psrc);
		if (!psrc)
			break;

		registerCount = numpr_globals;
		statementCount = numstatements;
		functionCount = numfunctions;
		strcpy (nameptr, com_token);
		if (!quiet)
			printf("compiling %s\n", nameptr);
		LoadFile (filename, &src2);

		if (!CO_CompileFile((char *)src2, nameptr))
			exit (1);
		if (!quiet && fileInfo)
		{
			registerCount = numpr_globals-registerCount;
			registerSize = registerCount*sizeof(float);
			statementCount = numstatements-statementCount;
			statementSize = statementCount*sizeof(dstatement_t);
			functionCount = numfunctions-functionCount;
			functionSize = functionCount*sizeof(dfunction_t);
			printf("      registers: %10d (%10d bytes)\n", registerCount, registerSize);
			printf("     statements: %10d (%10d bytes)\n", statementCount, statementSize);
			printf("      functions: %10d (%10d bytes)\n", functionCount, functionSize);
			printf("     total size: %10d bytes\n", registerSize+statementSize+functionSize);
		}
	} while (1);

	if (!PR_FinishCompilation())
		COM_Error ("compilation errors");

	p = CheckParm("-asm");
	if (p != 0)
	{
		for (p++; p < argc; p++)
		{
			if (argv[p][0] == '-')
				break;
			PrintFunction(argv[p]);
		}
	}

	// write progdefs.h
	strcpy(nameptr, "progdefs.h");
	crc = PR_WriteProgdefs(filename);

	// write data file
	WriteData(crc);

	// write files.dat
	WriteFiles();
	printf(" precache_sound: %10d / %10d\n", numsounds, MAX_SOUNDS);
	printf(" precache_model: %10d / %10d\n", nummodels, MAX_MODELS);
	printf("  precache_file: %10d / %10d\n", numfiles, MAX_FILES);

	stop = COM_GetTime ();
	printf("\n%d seconds elapsed.\n", (int)(stop - start));

	return 0;
}
Example #17
0
/*
============
main
============
*/
int main (int argc, char **argv)
{
	const char	*psrc;
	void		*src, *src2;
	char	filename[1024];
	int		p, c;
	unsigned short		crc;
	double	start, stop;
	FILE	*f;

	myargc = argc;
	myargv = argv;

	if (CheckParm("-?") || CheckParm("-h") || CheckParm("-help") || CheckParm("--help"))
	{
		printf(" Compiles progs.dat using progs.src in the current directory\n");
		printf(" -src <directory> : Specify source directory\n");
		printf(" -dcc : decompile the progs.dat in the current directory\n");
		printf(" -dcc -fix : fixes mangled names during decompilation\n");
		printf(" -dcc -asm <functionname> : decompile filename to the console\n");
		printf(" -dcc -dump -asm <functionname> : same as above but will show\n\t\tinstructions (opcodes and parms) as well\n");
		exit(0);
	}

	ValidateByteorder ();

	start = GetTime ();

	p = CheckParm("-src");
	if (p && p < argc-1)
	{
		strcpy(sourcedir, argv[p+1]);
		strcat(sourcedir, "/");
		printf("Source directory: %s\n", sourcedir);
	}
	else
	{
		sourcedir[0] = '\0';
	}

	InitData ();

	PR_FILE = stdout;

	p = CheckParm("-dump");
	if (p)
		pr_dumpasm = true;

	// do a crc of the file
	p = CheckParm("-crc");
	if (p)
	{
		CRC_Init (&crc);
		f = fopen ("progdefs.h", "r");
		while ((c = fgetc(f)) != EOF)
			CRC_ProcessByte (&crc, (byte)c);

		printf ("#define PROGHEADER_CRC %i %d\n", crc, (int)crc);
		fclose (f);
		exit (0);
	}

	p = CheckParm("-dcc");
	if (p)
	{
		DEC_ReadData ("progs.dat");
		//fix mangled names if asked
		p = CheckParm ("-fix");
		if (p)
			FILE_NUM_FOR_NAME = 1;

		memset(func_headers, 0, MAX_FUNCTIONS * sizeof(char *));
		memset(temp_val, 0, MAX_REGS * sizeof(char *));

		p = CheckParm("-bbb");
		if (p)
		{
		/*	i= -999;
			for (p = 0; p < numstatements; p++)
				if ((statements+p)->op > i)
					i = (statements+p)->op;
			printf("largest op %d\n", i); */
			FindBuiltinParameters(1);

			exit (0);
		}

		p = CheckParm("-ddd");
		if (p)
		{
			for (p++ ; p < argc ; p++)
			{
				if (argv[p][0] == '-')
					break;
				DccFunctionOP (atoi(argv[p]));
			}
			exit (0);
		}

		p = CheckParm("-info2");
		if (p)
		{
			printf("\n=======================\n");
			printf("fields\n");
			printf("=======================\n");
			PrintFields ();
			printf("\n=======================\n");
			printf("globals\n");
			printf("=======================\n");
			PrintGlobals ();
			exit (0);
		}

		p = CheckParm("-info");
		if (p)
		{
			printf("\n=======================\n");
			printf("strings\n");
			printf("=======================\n");
			PrintStrings ();
			printf("\n=======================\n");
			printf("functions");
			printf("\n=======================\n");
			PrintFunctions ();
			printf("\n=======================\n");
			printf("fields\n");
			printf("=======================\n");
			PrintFields ();
			printf("\n=======================\n");
			printf("globals\n");
			printf("=======================\n");
			PrintGlobals ();
			printf("\n=======================\n");
			printf("pr_globals\n");
			printf("=======================\n");
			PrintPRGlobals ();
			printf("\n=======================\n");
			printf("statements\n");
			printf("=======================\n");
			Printstatements();
			exit (0);
		}

		p = CheckParm("-asm");
		if (p)
		{
			for (p++; p < argc; p++)
			{
				if (argv[p][0] == '-')
					break;
				PR_PrintFunction(argv[p]);
			}
		}
		else
		{
			Dcc_Functions ();
			stop = GetTime ();
			printf("\n%d seconds elapsed.\n", (int)(stop-start));
		}

		exit (0);
	}

	sprintf(filename, "%sprogs.src", sourcedir);
	LoadFile(filename, &src);
	psrc = (char *) src;

	psrc = COM_Parse(psrc);
	if (!psrc)
	{
		Error("No destination filename.  HCC -help for info.\n");
	}

	strcpy(destfile, com_token);
	printf("outputfile: %s\n", destfile);

	pr_dumpasm = false;

	PR_BeginCompilation();

	// compile all the files
	do
	{
		psrc = COM_Parse(psrc);
		if (!psrc)
			break;

		sprintf (filename, "%s%s", sourcedir, com_token);
		printf ("compiling %s\n", filename);
		LoadFile (filename, &src2);

		if (!PR_CompileFile((char *)src2, filename))
			exit (1);

	} while (1);

	if (!PR_FinishCompilation())
	{
		Error ("compilation errors");
	}

	p = CheckParm("-asm");
	if (p)
	{
		for (p++; p < argc; p++)
		{
			if (argv[p][0] == '-')
			{
				break;
			}
			PrintFunction(argv[p]);
		}
	}

	// write progdefs.h
	crc = PR_WriteProgdefs("progdefs.h");
//	crc = 14046;	// FIXME: cheap hack for now!!!!!!!!!!!!!

	// write data file
	WriteData(crc);

	// write files.dat
	WriteFiles();

	stop = GetTime ();
	printf("\n%d seconds elapsed.\n", (int)(stop-start));

	exit (0);
}
Example #18
0
/*
============
main
============
*/
int main (int argc, char **argv)
{
	char    *src2;
	int      p, crc;
	double   start, stop;
	int	   i;
	FILE    *input;

	start = I_FloatTime ();

	myargc = argc;
	myargv = argv;

	for (i=1;i<argc;i++)
	{
		if (!strcmp(argv[i],"-h"))
   	{
   		printf ("%s [-o destfile] file\n",argv[0]);
   		return 0;
   	}
		if (!strcmp(argv[i],"-o"))
		{
			strcpy(destfile,argv[++i]);
			continue;
		}
		if (!strcmp(argv[i],"-p"))
		{
			strcpy(defsfile,argv[++i]);
			continue;
		}
		if (!strcmp(argv[i],"-asm"))
		{
			i++;
			continue;
		}
		break;
	}

	InitData ();

	if (!destfile[0])
		strcpy(destfile,"progs.dat");
	if (!defsfile[0])
		strcpy(defsfile,"progdefs.h");
		
	printf ("outputfile: %s\n", destfile);
	
	pr_dumpasm = false;

	PR_BeginCompilation (malloc (0x100000), 0x100000);


// compile all the files
	if (i==argc || !strcmp(argv[i],"-"))
		input=stdin;
	else
	{
		char buf[1024];
		char *cc;

		cc=getenv("CC");
		if (!cc) cc="gcc";
		sprintf(buf,"%s -x c -E %s",cc,argv[i]);
		input=popen(buf,"r");
		if (!input)
			Error("failed to open pipe to cpp ('%s')",buf);
	}
	
	{
		int size=0;
		src2=NULL;
		while (!feof(input))
		{
			src2=Q_realloc(src2,size+1024);
			size+=fread(&src2[size],1,1024,input);
		}
		src2=Q_realloc(src2,size+1);
		src2[size]=0;
	}

	if (input!=stdin)
		pclose(input);

	if (!PR_CompileFile (src2))
		return 1;

	if (!PR_FinishCompilation ())
		Error ("compilation errors");

	p = CheckParm ("-asm");
	if (p)
		PrintFunction (argv[++p]);

// write progdefs.h
	crc = PR_WriteProgdefs (defsfile);

// write data file
	WriteData (crc);

// write files.dat
#ifdef FILES_DAT
	WriteFiles ();
#endif

	stop = I_FloatTime ();
	printf ("%i seconds elapsed.\n", (int)(stop-start));
	return 0;
}