Beispiel #1
0
void Crunch_Load(void)
{
	// COMMANDLINEPARM: -crnf: CrnLib: select CRNF compressor
	if (CheckParm("-crnf"))    crnlib_compressor_type = cCRNDXTCompressorCRNF;
	// COMMANDLINEPARM: -ryg:  CrnLib: select RYG compressor
	if (CheckParm("-ryg"))     crnlib_compressor_type = cCRNDXTCompressorRYG;
	// note options
	if (crnlib_compressor_type != cCRNDXTCompressorCRN)
	{
		if (crnlib_compressor_type == cCRNDXTCompressorCRNF)
			Print("%s: using CRNF compressor\n", TOOL_CRUNCH.name);
		else if (crnlib_compressor_type == cCRNDXTCompressorRYG)
			Print("%s: using RYG compressor\n", TOOL_CRUNCH.name);
	}
}
Beispiel #2
0
/*
=================
BspModels

Runs qbsp and light on all of the models with a .bsp extension
=================
*/
void BspModels (void)
{
	int		p;
	char	*gamedir;
	int		i;
	char	*m;
	char	cmd[1024];
	char	name[256];

	p = CheckParm ("-bspmodels");
	if (!p)
		return;
	if (p == myargc-1)
		Error ("-bspmodels must preceed a game directory");
	gamedir = myargv[p+1];
	
	for (i=0 ; i<nummodels ; i++)
	{
		m = precache_models[i];
		if (strcmp(m+strlen(m)-4, ".bsp"))
			continue;
		strcpy (name, m);
		name[strlen(m)-4] = 0;
		sprintf (cmd, "qbsp %s/%s ; light -extra %s/%s", gamedir, name, gamedir, name);
		system (cmd);
	}
}
Beispiel #3
0
int FArgs::CheckParmList(const char *check, FString **strings, int start) const
{
	unsigned int i, parmat = CheckParm(check, start);

	if (parmat == 0)
	{
		if (strings != NULL)
		{
			*strings = NULL;
		}
		return 0;
	}
	for (i = ++parmat; i < Argv.Size(); ++i)
	{
		if (Argv[i][0] == '-' || Argv[i][1] == '+')
		{
			break;
		}
	}
	if (strings != NULL)
	{
		*strings = &Argv[parmat];
	}
	return i - parmat;
}
Beispiel #4
0
void DArgs::CollectFiles(const char *param, const char *extension)
{
	TArray<FString> work;
	DArgs *out = new DArgs;
	unsigned int i;
	size_t extlen = extension == NULL ? 0 : strlen(extension);

	// Step 1: Find suitable arguments before the first switch.
	i = 1;
	while (i < Argv.Size() && Argv[i][0] != '-' && Argv[i][0] != '+')
	{
		bool useit;

		if (extlen > 0)
		{ // Argument's extension must match.
			size_t len = Argv[i].Len();
			useit = (len >= extlen && stricmp(&Argv[i][len - extlen], extension) == 0);
		}
		else
		{ // Anything will do so long as it's before the first switch.
			useit = true;
		}
		if (useit)
		{
			work.Push(Argv[i]);
			Argv.Delete(i);
		}
		else
		{
			i++;
		}
	}

	// Step 2: Find each occurence of -param and add its arguments to work.
	while ((i = CheckParm(param, i)) > 0)
	{
		Argv.Delete(i);
		while (i < Argv.Size() && Argv[i][0] != '-' && Argv[i][0] != '+')
		{
			work.Push(Argv[i]);
			Argv.Delete(i);
		}
	}

	// Optional: Replace short path names with long path names
#ifdef _WIN32
	for (i = 0; i < work.Size(); ++i)
	{
		work[i] = I_GetLongPathName(work[i]);
	}
#endif

	// Step 3: Add work back to Argv, as long as it's non-empty.
	if (work.Size() > 0)
	{
		Argv.Push(param);
		AppendArgs(work.Size(), &work[0]);
	}
}
Beispiel #5
0
const char *DArgs::CheckValue (const char *check) const
{
	if(!check)
		return 0;

	size_t i = CheckParm (check);

	if (i > 0 && i < args.size() - 1)
		return args[i + 1].c_str();
	else
		return NULL;
}
Beispiel #6
0
void GimpDDS_Load(void)
{
	if (CheckParm("-dither"))    gimpdds_dithering = 1;
	if (CheckParm("-distance"))  gimpdds_colorBlockMethod = DDS_COLOR_DISTANCE;
	if (CheckParm("-luminance")) gimpdds_colorBlockMethod = DDS_COLOR_LUMINANCE;
	if (CheckParm("-insetbox"))  gimpdds_colorBlockMethod = DDS_COLOR_INSET_BBOX;
	if (CheckParm("-colormax"))  gimpdds_colorBlockMethod = DDS_COLOR_MAX;

	// note
	if (gimpdds_dithering)
		Print("%s tool: enabled dithering\n", TOOL_GIMPDDS.name);
	if (gimpdds_colorBlockMethod != DDS_COLOR_MAX)
	{
		if (gimpdds_colorBlockMethod == DDS_COLOR_DISTANCE)
			Print("%s: COLOR_DISTANCE method for  block compression\n", TOOL_GIMPDDS.name);
		else if (gimpdds_colorBlockMethod == DDS_COLOR_LUMINANCE)
			Print("%s: COLOR_LUMINANCE method for block compression\n", TOOL_GIMPDDS.name);
		else if (gimpdds_colorBlockMethod == DDS_COLOR_INSET_BBOX)
			Print("%s: INSET_BBOX method for block compression\n", TOOL_GIMPDDS.name);
	}
}
Beispiel #7
0
void FArgs::RemoveArgs(const char *check)
{
	int i = CheckParm(check);

	if (i > 0 && i < (int)Argv.Size() - 1)
	{
		do 
		{
			RemoveArg(i);
		}
		while (Argv[i][0] != '+' && Argv[i][0] != '-' && i < (int)Argv.Size() - 1);
	}
}
Beispiel #8
0
const char *FArgs::CheckValue(const char *check) const
{
	int i = CheckParm(check);

	if (i > 0 && i < (int)Argv.Size() - 1)
	{
		i++;
		return Argv[i][0] != '+' && Argv[i][0] != '-' ? Argv[i].GetChars() : NULL;
	}
	else
	{
		return NULL;
	}
}
Beispiel #9
0
void Dial (void)
{
	char	cmd[80];
	int		p;

	ModemCommand(startup);
	ModemResponse ("OK");

	printf ("\n"STR_DIALING"\n\n");
	p = CheckParm ("-dial");
	sprintf (cmd,"ATDT%s",myargv[p+1]);

	ModemCommand(cmd);
	ModemResponse (STR_CONNECT);
	doomcom.consoleplayer = 1;
}
Beispiel #10
0
FString FArgs::TakeValue(const char *check)
{
	int i = CheckParm(check);
	FString out;

	if (i > 0 && i < (int)Argv.Size())
	{
		if (i < (int)Argv.Size() - 1 && Argv[i+1][0] != '+' && Argv[i+1][0] != '-')
		{
			out = Argv[i+1];
			Argv.Delete(i, 2);	// Delete the parm and its value.
		}
		else
		{
			Argv.Delete(i);		// Just delete the parm, since it has no value.
		}
	}
	return out;
}
Beispiel #11
0
DArgs DArgs::GatherFiles (const char *param, const char *extension, bool acceptNoExt) const
{
	DArgs out;
	size_t i;
	unsigned extlen = strlen (extension);

	for (i = 1; i < args.size() && args[i].length() && args[i][0] != '-' && args[i][0] != '+'; i++)
	{
		if (args[i].length() >= extlen && stricmp (args[i].c_str() + args[i].length() - extlen, extension) == 0)
			out.AppendArg (args[i].c_str());
		else if (acceptNoExt && !strrchr (args[i].c_str(), '.'))
			out.AppendArg (args[i].c_str());
	}
	i = CheckParm (param);
	if (i)
	{
		for (i++; i < args.size() && args[i].length() && args[i][0] != '-' && args[i][0] != '+'; i++)
			out.AppendArg (args[i].c_str());
	}
	return out;
}
Beispiel #12
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;
}
Beispiel #13
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;
}
Beispiel #14
0
void Connect (void)
{
	struct time	time;
	int			oldsec;
	int			localstage, remotestage;
	char		str[20];
	char		idstr[7];
	char		remoteidstr[7];
	unsigned long		idnum;
	int			i;
	
//
// wait for a good packet
//
	printf (STR_ATTEMPT"\n");

//
// build a (hopefully) unique id string by hashing up the current milliseconds
// and the interrupt table
//
	if (CheckParm ("-player1"))
		idnum = 0;
	else if (CheckParm ("-player2"))
		idnum = 999999;
	else
	{
		gettime (&time);
		idnum = time.ti_sec*100+time.ti_hund;
		for (i=0 ; i<512 ; i++)
			idnum += ((unsigned far *)0)[i];
		idnum %= 1000000;
	}
	
	idstr[0] = '0' + idnum/ 100000l;
	idnum -= (idstr[0]-'0')*100000l;
	idstr[1] = '0' + idnum/ 10000l;
	idnum -= (idstr[1]-'0')*10000l;
	idstr[2] = '0' + idnum/ 1000l;
	idnum -= (idstr[2]-'0')*1000l;
	idstr[3] = '0' + idnum/ 100l;
	idnum -= (idstr[3]-'0')*100l;
	idstr[4] = '0' + idnum/ 10l;
	idnum -= (idstr[4]-'0')*10l;
	idstr[5] = '0' + idnum;
	idstr[6] = 0;
	
//
// sit in a loop until things are worked out
//
// the packet is:  ID000000_0
// the first field is the idnum, the second is the acknowledge stage
// ack stage starts out 0, is bumped to 1 after the other computer's id
// is known, and is bumped to 2 after the other computer has raised to 1
//
	oldsec = -1;
	localstage = remotestage = 0;

	do
	{
		while ( bioskey(1) )
		{
			if ( (bioskey (0) & 0xff) == 27)
				Error ("\n\n"STR_NETABORT);
		}

		if (ReadPacket ())
		{
			packet[packetlen] = 0;
			printf ("read : %s\n",packet);
			if (packetlen != 10)
				continue;
			if (strncmp(packet,"ID",2) )
				continue;
			if (!strncmp (packet+2,idstr,6))
				Error ("\n\n"STR_DUPLICATE);
			strncpy (remoteidstr,packet+2,6);
				
			remotestage = packet[9] - '0';
			localstage = remotestage+1;
			oldsec = -1;
		}

		gettime (&time);
		if (time.ti_sec != oldsec)
		{
			oldsec = time.ti_sec;
			sprintf (str,"ID%s_%i",idstr,localstage);
			WritePacket (str,strlen(str));
			printf ("wrote: %s\n",str);
		}

	} while (localstage < 2);

//
// decide who is who
//
	if (strcmp(remoteidstr,idstr) > 0)
		doomcom.consoleplayer = 0;
	else
		doomcom.consoleplayer = 1;
	

//
// flush out any extras
//
	while (ReadPacket ())
	;
}
Beispiel #15
0
void main(void)
{
	int				p;

//
// set network characteristics
//
	doomcom.ticdup = 1;
	doomcom.extratics = 0;
	doomcom.numnodes = 2;
	doomcom.numplayers = 2;
	doomcom.drone = 0;

	printf("\n"
		   "---------------------------------\n"
		   #ifdef DOOM2
		   STR_DOOMSERIAL"\n"
		   #else
		   "DOOM SERIAL DEVICE DRIVER v1.4\n"
		   #endif
		   "---------------------------------\n");
	myargc = _argc;
	myargv = _argv;
	FindResponseFile();

//
// allow override of automatic player ordering to allow a slower computer
// to be set as player 1 allways
//

//
// establish communications
//

	baudbits = 0x08;		// default to 9600 if not specified on cmd line
							// or in modem.cfg

	if (CheckParm ("-dial") || CheckParm ("-answer") )
		ReadModemCfg ();		// may set baudbits

//
// allow command-line override of modem.cfg baud rate
//
	if (CheckParm ("-9600")) baudbits = 0x0c;
	else if (CheckParm ("-14400")) baudbits = 0x08;
	else if (CheckParm ("-19200")) baudbits = 0x06;
	else if (CheckParm ("-38400")) baudbits = 0x03;
	else if (CheckParm ("-57600")) baudbits = 0x02;
	else if (CheckParm ("-115200")) baudbits = 0x01;

	InitPort ();

	if (CheckParm ("-dial"))
		Dial ();
	else if (CheckParm ("-answer"))
		Answer ();

	Connect ();

//
// launch DOOM
//
	LaunchDOOM ();

	Error (NULL);
}
Beispiel #16
0
/*
==============
Eng_Load

Try to load the engine with specified command line, etc. etc. and the specified .dll
==============
*/
int Eng_Load( const char *cmdline, struct exefuncs_s *pef, int memory, void *pmembase, const char *psz, int iSubMode )
{
	char	szLastDLL[ 100 ];
	long hMod = (long)NULL;

#if defined( _DEBUG )
	char *p;

	if ( psz && !stricmp( psz, "swds.dll" ) && CheckParm( "-force", &p ) && p )
	{
		psz = p;
	}
#endif

	// Are we loading a different engine?
	if ( psz && ghMod && !strcmp( psz, szLastDLL ) )
	{
		return 1;
	}

	if ( ghMod )
	{
		Eng_KillEngine( &hMod );
	}
	
	if ( !psz )
	{
		hMod = 0;
		Eng_LoadStubs();
	}
	else if ( !ghMod )
	{
		hMod = Sys_LoadLibrary( (char *)psz );
		if ( !hMod )
		{
			return 0;
		}

		// Load function table from engine
		if ( !Eng_LoadFunctions( hMod ) )
		{
			Sys_FreeLibrary( hMod );
			Eng_LoadStubs();
			return 0;
		}

		// Activate engine
		Eng_SetState( DLL_ACTIVE );
	}

	Eng_SetSubState( iSubMode );

	snprintf( szLastDLL, sizeof( szLastDLL ), "%s", psz );

	ghMod		= hMod;

	if ( ghMod )
	{
		static char *szEmpty = "";

		char *p = (char *)cmdline;
		if ( !p )
		{
			p = szEmpty;
		}

		if ( !engineapi.Game_Init( p, (unsigned char *)pmembase, memory, pef, NULL, 1) )
		{
			Sys_FreeLibrary(ghMod);
			ghMod = hMod = 0;
			return 0;
		}
		
		if ( engineapi.SetStartupMode )
		{
			engineapi.SetStartupMode( 1 );
		}
		
		if ( engineapi.Host_Frame )
		{
			Eng_Frame( 1, 0.05 );
		}

		if ( engineapi.SetStartupMode )
		{
			engineapi.SetStartupMode( 0 );
		}
	}
	return 1;
}
Beispiel #17
0
/*
==============
InitConProc

==============
*/   
void InitConProc ( void )
{
	unsigned	threadAddr;
	HANDLE		hFile			= (HANDLE)0;
	HANDLE		heventParent	= (HANDLE)0;
	HANDLE		heventChild		= (HANDLE)0;
	int			WantHeight = 50;
	char		*p;

	// give external front ends a chance to hook into the console
	if ( CheckParm ( "-HFILE", &p ) && p )
	{
		hFile = (HANDLE)atoi ( p );
	}

	if ( CheckParm ( "-HPARENT", &p ) && p )
	{
		heventParent = (HANDLE)atoi ( p );
	}

	if ( CheckParm ( "-HCHILD", &p ) && p )
	{
		heventChild = (HANDLE)atoi ( p );
	}

	// ignore if we don't have all the events.
	if ( !hFile || !heventParent || !heventChild )
	{
		//Sys_Printf ("\n\nNo external front end present.\n" );
		return;
	}

	Sys_Printf( "\n\nInitConProc:  Setting up external control.\n" );

	hfileBuffer			= hFile;
	heventParentSend	= heventParent;
	heventChildSend		= heventChild;

	// So we'll know when to go away.
	heventDone = CreateEvent (NULL, FALSE, FALSE, NULL);
	if (!heventDone)
	{
		Sys_Printf ("InitConProc:  Couldn't create heventDone\n");
		return;
	}

	if (!_beginthreadex (NULL, 0, RequestProc, NULL, 0, &threadAddr))
	{
		CloseHandle (heventDone);
		Sys_Printf ("InitConProc:  Couldn't create third party thread\n");
		return;
	}

	// save off the input/output handles.
	hStdout	= GetStdHandle (STD_OUTPUT_HANDLE);
	hStdin	= GetStdHandle (STD_INPUT_HANDLE);

	if ( CheckParm( "-conheight", &p ) && p )
	{
		WantHeight = atoi( p );
	}

	// Force 80 character width, at least 25 character height
	SetConsoleCXCY( hStdout, 80, WantHeight );
}
Beispiel #18
0
int main (int argc, char **argv)
{
	char	filename[128];
	int		handle;
	wadinfo_t	wad;
	lumpinfo_t	*lumps, *lump_p;
	int		i,j;
	char	name[9];
	uint32_t	datasize, wadsize, infosize;
	char	*lzss;


	printf ("SPITWAD "VERSION" by John Carmack, copyright (c) 1992 Id Software\n");

	if (CheckParm ("?") || (argc != 2 && argc != 4))
	{
		printf ("SPITWAD filename<.wad> [start end]\n");
		exit (1);
	}

	strcpy (filename, argv[1]);
	DefaultExtension (filename, ".wad");

	handle = SafeOpenRead (filename);
	wadsize = filelength(handle);
	datasize = 0;

	SafeRead (handle, &wad, sizeof(wad));

	if (strncmp(wad.identification,"IWAD",4) && strncmp(wad.identification,"PWAD",4))
		Error ("Wad file %s doesn't have IWAD or PWAD id\n",filename);

	wad.numlumps = LittleLong(wad.numlumps);
	wad.infotableofs = LittleLong(wad.infotableofs);

	infosize = wad.numlumps*sizeof(lumpinfo_t);
	lumps = lump_p = SafeMalloc(infosize);
	lseek (handle, wad.infotableofs, SEEK_SET);
	SafeRead (handle, lumps, infosize);
	infosize += sizeof(wadinfo_t);

	printf ("\n");
	printf ("WAD file    : %s\n",filename);
	printf ("numlumps    : %u\n",wad.numlumps);
	printf ("infotableofs: %u\n",wad.infotableofs);
	printf ("\n");
	printf ("lump name       size  filepos    0xsize 0xfpos\n");
	printf ("---- -------- ------ --------    ------ ------\n");

	name[8] = 0;

	for (i=0 ; i<wad.numlumps ; i++, lump_p++)
	{
		datasize += LittleLong (lump_p->size);
		strncpy (name,lump_p->name,8);
		for (j=7 ; j>=0 ; j--)
			if (!name[j])
				name[j] = ' ';
			else
				break;
		if (name[0] & 0x80)
		{
			lzss = "(lzss)";
			name[0] &= 0x7f;
		}
		else lzss = "";
		printf ("%4i %s %6i %8i    %6x %6x %s\n", i, name
		, LittleLong(lump_p->size), LittleLong(lump_p->filepos)
		, LittleLong(lump_p->size), LittleLong(lump_p->filepos),
		lzss );
	}

	printf ("\n");
	printf ("File size:%9i\n", wadsize);
	printf ("Data size:%9i\n", datasize);
	printf ("Info size:%9i\n", infosize);
	printf ("Wasted   :%9i\n", wadsize-(datasize+infosize));

	return 0;
}
Beispiel #19
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;
}
Beispiel #20
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);
}