Beispiel #1
0
int Compile(unsigned char* string, int len, unsigned char *fileName, wchar_t *fileNameW) {
	Token *tokens;
	int numTokens;
	int numErrors = Tokenize(string, len, tokens, numTokens, fileNameW);
	if (numErrors) {
		CleanupTokens(tokens, numTokens);
		return 0;
	}
/*	Token test[100];
	test[0].type = ONE;
	test[1].type = PLUS;
	test[2].type = ONE;
	test[3].type = DOLLAR;
//	TreeNode *t = ParseScript(test, 4);
//*/
	ParseTree *tree = ParseScript(tokens, numTokens);
	if (!tree) {
		return 0;
	}
	TempCode * tempCode = GenTempCode(tree);
	CleanupTree(tree);
	if (!tempCode) {
		return 0;
	}
	if (!GenCode(tempCode, string, len, fileName)) {
		return 0;
	}
	return 1;
}
unsigned int optimize(PanoramaData& pano,
                      const char * userScript)
{
    char * script = 0;
    unsigned int retval = 0;

    if (userScript == 0) {
        std::ostringstream scriptbuf;
        UIntSet allImg;
        fill_set(allImg,0, unsigned(pano.getNrOfImages()-1));
        pano.printPanoramaScript(scriptbuf, pano.getOptimizeVector(), pano.getOptions(), allImg, true);
        script = strdup(scriptbuf.str().c_str());
    } else {
        script = const_cast<char *>(userScript);
    }

    OptInfo		opt;
	AlignInfo	ainf;

    if (ParseScript( script, &ainf ) == 0)
	{
		if( CheckParams( &ainf ) == 0 )
		{
			ainf.fcn	= fcnPano;
			
			SetGlobalPtr( &ainf ); 
			
			opt.numVars 		= ainf.numParam;
			opt.numData 		= ainf.numPts;
			opt.SetVarsToX		= SetLMParams;
			opt.SetXToVars		= SetAlignParams;
			opt.fcn			= ainf.fcn;
			*opt.message		= 0;

			RunLMOptimizer( &opt );
			ainf.data		= opt.message;
            // get results from align info.
#ifdef DEBUG_WRITE_OPTIM_OUTPUT
            fullPath path;
            StringtoFullPath(&path, DEBUG_WRITE_OPTIM_OUTPUT_FILE );

		    ainf.data		= opt.message;
            WriteResults( script, &path, &ainf, distSquared, 0);
#endif
            pano.updateVariables( GetAlignInfoVariables(ainf) );
            pano.updateCtrlPointErrors( GetAlignInfoCtrlPoints(ainf) );
		} else {
            std::cerr << "Bad params" << std::endl;
            retval = 2;
        }
		DisposeAlignInfo( &ainf );
    } else {
        std::cerr << "Bad params" << std::endl;
        retval = 1;
    }
    if (! userScript) {
        free(script);
    }
    return retval;
}
int main(int argc,char *argv[])
{
	aPrefs		aP;

	char*		script;
	OptInfo		opt;
	AlignInfo	ainf;

	fullPath	infile;
	//fullPath	outfile;

	//	

	SetAdjustDefaults(&aP);

	if(argc != 2)
	{
		printf(PT_OPTIMIZER_VERSION);
		printf("Usage: %s /path/to/script.txt\n", argv[0]);
		exit(1);
	}

	StringtoFullPath(&infile, argv[1]);

	script = LoadScript( &infile );
	if( script != NULL )
	{
		if (ParseScript( script, &ainf ) == 0)
		{
			if( CheckParams( &ainf ) == 0 )
			{
				ainf.fcn	= fcnPano;
				
				SetGlobalPtr( &ainf ); 
				
				opt.numVars 		= ainf.numParam;
				opt.numData 		= ainf.numPts;
				opt.SetVarsToX		= SetLMParams;
				opt.SetXToVars		= SetAlignParams;
				opt.fcn			= ainf.fcn;
				*opt.message		= 0;

				RunLMOptimizer( &opt );
				ainf.data		= opt.message;
				WriteResults( script, &infile, &ainf, distSquared, 0);
				exit(0);
			}
      //TODO: if optCreatePano is 1 then should call stitcher  OR  the option removed
      //if (ainf.sP.optCreatePano == 1)
      //{
      //   Stitch();
      //}
			DisposeAlignInfo( &ainf );
		}
		free( script );
	}
	exit(1);
}
int asCParser::ParseScript(asCScriptCode *script)
{
	Reset();

	this->script = script;

	scriptNode = ParseScript();

	if( errorWhileParsing )
		return -1;

	return 0;
}
Beispiel #5
0
void CFX_CTTGSUBTable::ParseScriptList(FT_Bytes raw, struct TScriptList* rec) {
  int i;
  FT_Bytes sp = raw;
  rec->ScriptCount = GetUInt16(sp);
  if (rec->ScriptCount <= 0) {
    return;
  }
  rec->ScriptRecord = new struct TScriptRecord[rec->ScriptCount];
  for (i = 0; i < rec->ScriptCount; i++) {
    rec->ScriptRecord[i].ScriptTag = GetUInt32(sp);
    TT_uint16_t offset = GetUInt16(sp);
    ParseScript(&raw[offset], &rec->ScriptRecord[i].Script);
  }
}
Beispiel #6
0
static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& strInput)
{
    // separate VALUE:SCRIPT[:FLAGS]
    std::vector<std::string> vStrInputParts;
    boost::split(vStrInputParts, strInput, boost::is_any_of(":"));
    if (vStrInputParts.size() < 2)
        throw std::runtime_error("TX output missing separator");

    // Extract and validate VALUE
    CAmount value = ExtractAndValidateValue(vStrInputParts[0]);

    // extract and validate script
    std::string strScript = vStrInputParts[1];
    CScript scriptPubKey = ParseScript(strScript);

    // Extract FLAGS
    bool bSegWit = false;
    bool bScriptHash = false;
    if (vStrInputParts.size() == 3) {
        std::string flags = vStrInputParts.back();
        bSegWit = (flags.find('W') != std::string::npos);
        bScriptHash = (flags.find('S') != std::string::npos);
    }

    if (scriptPubKey.size() > MAX_SCRIPT_SIZE) {
        throw std::runtime_error(strprintf(
                    "script exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_SIZE));
    }

    if (bSegWit) {
        scriptPubKey = GetScriptForWitness(scriptPubKey);
    }
    if (bScriptHash) {
        if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
            throw std::runtime_error(strprintf(
                        "redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
        }
        scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
    }

    // construct TxOut, append to transaction output list
    CTxOut txout(value, scriptPubKey);
    tx.vout.push_back(txout);
}
void calcCtrlPointErrors (PanoramaData& pano) 
{
    if(pano.getNrOfImages()>0 && pano.getNrOfCtrlPoints()>0)
    {
        char * p=setlocale(LC_ALL,NULL);
#ifndef ANDROID
        char * oldlocale=strdup(p);
#else
	char * oldlocale="";
#endif
        setlocale(LC_ALL,"C");
        UIntSet allImg;
        std::ostringstream scriptbuf;
        fill_set(allImg,0, unsigned(pano.getNrOfImages()-1));
        //create temporary non-empty optimize vector
        OptimizeVector optVec;
        std::set<std::string> opt;
        opt.insert("y");
        for(unsigned int i=0;i<pano.getNrOfImages();i++)
        {
            optVec.push_back(opt);
        };
        pano.printPanoramaScript(scriptbuf, optVec, 
                pano.getOptions(), allImg, true);

        char * script = 0;
        script = strdup(scriptbuf.str().c_str());
        AlignInfo ainf;
        if (ParseScript( script, &ainf ) == 0)
        {
            if( CheckParams( &ainf ) == 0 )
            {
                ainf.fcn = fcnPano;
                SetGlobalPtr( &ainf ); 
                pano.updateCtrlPointErrors( GetAlignInfoCtrlPoints(ainf) );
            }
        }
        setlocale(LC_ALL,oldlocale);
        free(oldlocale);
    };
}
Beispiel #8
0
void
DoScript(StandardFileReply *reply)
{
	short			result;
	FILE *			stream;
	ScriptCmd *		scriptCmds;
	
	result     = noErr;
	stream     = nil;
	scriptCmds = nil;
	
	//if ( result == noErr )
		{
		stream = OpenScript( reply );
		if ( stream == nil )
			{
			result = -1;
			}
		}
	if ( result == noErr )
		{
		scriptCmds = ParseScript( stream );
		if ( scriptCmds == nil )
			{
			result = -1;
			}
		}
	if ( result == noErr )
		{
		ExecuteScript( scriptCmds );
		}
	
	if ( scriptCmds )
		{
		DisposeScript( scriptCmds );
		}
	if ( stream )
		{
		fclose( stream );
		}
}
Beispiel #9
0
/*
=================
ProcessLumpyScript

Loads a script file, then grabs everything from it
=================
*/
void ProcessLumpyScript (char *basename)
{
	char            script[256];

	printf ("qlumpy script: %s\n",basename);
	
//
// create default destination directory
//
	strcpy (destfile, ExpandPath(basename));
	StripExtension (destfile);
	strcat (destfile,".wad");		// unless the script overrides, save in cwd

//
// save in a wadfile by default
//
	savesingle = false;
	grabbed = 0;
	outputcreated = false;
	
	
//
// read in the script file
//
	strcpy (script, basename);
	DefaultExtension (script, ".ls");
	LoadScriptFile (script);
	
	strcpy (basepath, basename);
	
	ParseScript ();				// execute load / grab commands
	
	if (!savesingle)
	{
		WriteWad (do16bit);				// write out the wad directory
		printf ("%i lumps grabbed in a wad file\n",grabbed);
	}
	else
		printf ("%i lumps written seperately\n",grabbed);
}
Beispiel #10
0
static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& strInput)
{
    // separate VALUE:SCRIPT in string
    size_t pos = strInput.find(':');
    if ((pos == std::string::npos) ||
        (pos == 0))
        throw std::runtime_error("TX output missing separator");

    // extract and validate VALUE
    std::string strValue = strInput.substr(0, pos);
    CAmount value;
    if (!ParseMoney(strValue, value))
        throw std::runtime_error("invalid TX output value");

    // extract and validate script
    std::string strScript = strInput.substr(pos + 1, std::string::npos);
    CScript scriptPubKey = ParseScript(strScript); // throws on err

    // construct TxOut, append to transaction output list
    CTxOut txout(value, scriptPubKey);
    tx.vout.push_back(txout);
}
Beispiel #11
0
void CEnvironment::Load( DFile& FileToLoad_ )
{
	if( !FileToLoad_.IsReadable() ) return;

	// Load to buffer
	//vector<char> aBuffer;
	//aBuffer.resize( FileToLoad_.GetSize()+1 );
	//appMemzero( &aBuffer[0], sizeof(char)*aBuffer.size() );
	//FileToLoad_.Read( &aBuffer[0], sizeof(char)*FileToLoad_.GetSize() );
	dword dwBufSize = FileToLoad_.GetSize()+1;
	char *szBuffer = new char[dwBufSize];
	appMemzero( szBuffer, sizeof(char)*dwBufSize );
	FileToLoad_.Read( szBuffer, sizeof(char)*FileToLoad_.GetSize() );

	//if( aBuffer.size()<2 ) { return; } // too small

	// parsing
	CVarBlockParser Parser( szBuffer );
	const CVarBlockParser::_VariableBlock *pBlock = &Parser.Root();

	ParseScript( pBlock );

	SAFE_DELETE_ARRAY( szBuffer );
}
static int panoMenderImageFileNamesReadFromScript(fullPath **ptrImageFileNames, fullPath *scriptFileName)
{
    char *script;
    AlignInfo alignInfo;
    int counter;
    int i;

    // We don't have any images yet. We read the Script and load them from it.
    if (ptDebug) {
	fprintf(stderr, "Loading script [%s]\n", scriptFileName->name);
    }
	
    script = LoadScript(scriptFileName);
    
    if (script == NULL) {
	PrintError("Could not load script [%s]", scriptFileName->name);
	return -1;
    }
    
    // parse input script and set up an array of input file names
    if (ParseScript(script, &alignInfo) != 0) {
	// print error
	
	PrintError("Panorama script parsing error");
	return 0;
    }
    
    // The parser of panotools is really broken. To retrieve each
    // input filename it reads the file,
    // finds the first filename, then removes it, and writes the rest of the file again
    // This is done recursively 
    
    counter = alignInfo.numIm;
    
    if (counter != 0) {
	
	// Try to find filenames in input section
	if (ptDebug) {
	    fprintf(stderr, "Found %d images in script file in INPUT section\n", counter);
	}
	// Allocate their space
	if ((*ptrImageFileNames = malloc(512 * counter)) == NULL) {
	    PrintError("Not enough memory");
	    exit(1);
	}
	
	//Iterate over input images and populate input filename array
	for (i = 0; i < counter; i ++) {
	    //If the image filenames don't appear to have any path information, then 
	    //prepend the path to the script (if any) that was specified on the 
	    //command line (Note: this was the only behavior in the original 
	    //PTStitcher.  It has been moved into this conditional block because
	    //the script path could get prepended to an already fully qualified
	    //filename...not very useful.
	    if (ptDebug) {
		fprintf(stderr, "Processing image [%s] from 'i' line %d\n", alignInfo.im[i].name, i);
	    }

	    panoMenderSetFileName(&((*ptrImageFileNames)[i]), alignInfo.im[i].name, scriptFileName);
	    
	    if (ptDebug) {
		fprintf(stderr, "Reading image filename [%s] from 'i' line %d\n", (*ptrImageFileNames)[i].name, i);
	    }
	    
	    
	}
	DisposeAlignInfo(&alignInfo);
    }	
    if (counter == 0) {
	// Sometimes the names of the images are not in the 'o' line, then assume they are
	// in the 'i' line.
	
	
	// create a temporary copy we can overwrite
	fullPath scriptPathName;
	
	counter = numLines(script, 'o');
	
	if (counter == 0) {
	    PrintError("No images found input file script file (there are no 'o' lines nor 'i' lines");
	    exit(1);
	}
	// Allocate their space
	if ((*ptrImageFileNames = malloc(512 * counter)) == NULL) {
	    PrintError("Not enough memory");
	    exit(1);
	}
	
	
	panoMenderDuplicateScriptFile(scriptFileName->name, script, &scriptPathName);
	
	for (i = 0; i < counter; i++) {
	    aPrefs* preferences;
	    if ( (preferences = readAdjustLine(&scriptPathName)) == NULL) {
		PrintError("No 'i' line for image number %d", i);
		exit(1);
	    }
	    
	    if (ptDebug) {
		fprintf(stderr, "Processing image [%s] from 'o' line %d\n", preferences->im.name, i);
	    }

	    panoMenderSetFileName(&((*ptrImageFileNames)[i]), preferences->im.name, scriptFileName);
	    
	    if (ptDebug) {
		fprintf(stderr, "Reading image filename [%s] from 'i' line %d\n",
			(*ptrImageFileNames)[i].name, i);
	    }
	    if (preferences->td != NULL)
		free(preferences->td);
	    
	    if (preferences->ts != NULL)
		free(preferences->ts);
	    
	    free(preferences);
	    
	} // end of for (i = 0; i < counter; i++) {
	free(script); 
	
	remove(scriptPathName.name);
	
    }
    return counter;
}
Beispiel #13
0
/*
==============
main
==============
*/
int main (int argc, char **argv)
{
	static	int		i;		// VC4.2 compiler bug if auto...
	char	path[1024];

  // using GtkRadiant's versioning next to Id's versioning
  printf ("Q3Data      - (c) 1999 Id Software Inc.\n");
  printf ("GtkRadiant  - v" RADIANT_VERSION " " __DATE__ "\n");

	ExpandWildcards (&argc, &argv);

	for (i=1 ; i<argc ; i++)
	{
		if (!strcmp(argv[i], "-archive"))
		{
			archive = qtrue;
			strcpy (archivedir, argv[i+1]);
			printf ("Archiving source to: %s\n", archivedir);
			i++;
		}
		else if (!strcmp(argv[i], "-release"))
		{
			g_release = qtrue;
			strcpy (g_releasedir, argv[i+1]);
			printf ("Copy output to: %s\n", g_releasedir);
			i++;
		}
		else if ( !strcmp( argv[i], "-nostrips" ) )
		{
			g_stripify = qfalse;
			printf( "Not optimizing for strips\n" );
		}
		else if ( !strcmp( argv[i], "-writedir" ) )
		{
			strcpy( writedir, argv[i+1] );
			printf( "Write output to: %s\n", writedir );
			i++;
		}
		else if ( !strcmp( argv[i], "-verbose" ) )
		{
			g_verbose = qtrue;
		}
		else if ( !strcmp( argv[i], "-dump" ) )
		{
			printf( "Dumping contents of: '%s'\n", argv[i+1] );
			if ( strstr( argv[i+1], ".md3" ) )
			{
				MD3_Dump( argv[i+1] );
			}
			else
			{
				Error( "Do not know how to dump the contents of '%s'\n", argv[i+1] );
			}
			i++;
		}
		else if ( !strcmp( argv[i], "-3dsconvert" ) )
		{
      // NOTE TTimo this is broken, tried on a sample .3ds
      // what happens .. it calls the Convert3DStoMD3,
      // which calls the scriptlib function in non initialized state .. and crashes
			printf( "Converting %s.3DS to %s.MD3\n", argv[i+1], argv[i+1] );
			SetQdirFromPath( argv[i+1] );
      vfsInitDirectory( gamedir );
			Convert3DStoMD3( argv[i+1] );
			i++;
		}
		else if (!strcmp(argv[i], "-only"))
		{
			strcpy (g_only, argv[i+1]);
			printf ("Only grabbing %s\n", g_only);
			i++;
		}
		else if (!strcmp(argv[i], "-gamedir"))
		{
			strcpy(gamedir, argv[i+1]);
			i++;
		}
		else if (argv[i][0] == '-')
			Error ("Unknown option \"%s\"", argv[i]);
		else
			break;
	}

	if (i == argc)
		Error ("usage: q3data [-archive <directory>] [-dump <file.md3>] [-release <directory>] [-only <model>] [-3dsconvert <file.3ds>] [-verbose] [file.qdt]");

	for ( ; i<argc ; i++)
	{
		printf ("--------------- %s ---------------\n", argv[i]);
		// load the script
		strcpy (path, argv[i]);
		DefaultExtension (path, ".qdt");
		if(!gamedir[0])
			SetQdirFromPath (path);
    // NOTE TTimo
    // q3data went through a partial conversion to use the vfs
    // it was never actually tested before 1.1.1
    // the code is still mostly using direct file access calls
    vfsInitDirectory( gamedir );
		LoadScriptFile (ExpandArg(path), -1);
		
		//
		// parse it
		//
		ParseScript ();

		// write out the last model
		FinishModel ( TYPE_UNKNOWN );
	}

	return 0;
}
Beispiel #14
0
/*
==============
main
==============
*/
int main (int argc, char **argv)
{
	static	int		i;		// VC4.2 compiler bug if auto...
	char	path[1024];

	ExpandWildcards (&argc, &argv);

	for (i=1 ; i<argc ; i++)
	{
		if (!strcmp(argv[i], "-archive"))
		{
			// -archive f:/quake2/release/dump_11_30
			archive = true;
			strcpy (archivedir, argv[i+1]);
			printf ("Archiving source to: %s\n", archivedir);
			i++;
		}
		else if (!strcmp(argv[i], "-release"))
		{
			g_release = true;
			strcpy (g_releasedir, argv[i+1]);
			printf ("Copy output to: %s\n", g_releasedir);
			i++;
		}
		else if (!strcmp(argv[i], "-compress"))
		{
			g_compress_pak = true;
			printf ("Compressing pakfile\n");
		}
		else if (!strcmp(argv[i], "-pak"))
		{
			g_release = true;
			g_pak = true;
			printf ("Building pakfile: %s\n", argv[i+1]);
			BeginPak (argv[i+1]);
			i++;
		}
		else if (!strcmp(argv[i], "-only"))
		{
			strcpy (g_only, argv[i+1]);
			printf ("Only grabbing %s\n", g_only);
			i++;
		}
		else if (!strcmp(argv[i], "-3ds"))
		{
			do3ds = true;
			printf ("loading .3ds files\n");
		}
		else if (argv[i][0] == '-')
			Error ("Unknown option \"%s\"", argv[i]);
		else
			break;
	}

	if (i >= argc)
		Error ("usage: qgrab [-archive <directory>] [-release <directory>] [-only <model>] [-3ds] file.qgr");

	if (do3ds)
		trifileext = ext_3ds;
	else
		trifileext = ext_tri;

	for ( ; i<argc ; i++)
	{
		printf ("--------------- %s ---------------\n", argv[i]);
		// load the script
		strcpy (path, argv[i]);
		DefaultExtension (path, ".qdt");
		SetQdirFromPath (path);
		LoadScriptFile (ExpandArg(path));
		
		//
		// parse it
		//
		ParseScript ();

		// write out the last model
		FinishModel ();
		FinishSprite ();
	}

	if (g_pak)
		FinishPak ();

	return 0;
}
int main(int argc, char **argv)
{
	unsigned char *buffer = NULL, *output = NULL;
	int strtablesize = 0, pos = 0;
	
	if(argc!=3)
	{
		printf("usage: %s inscript outfile\n",argv[0]);
		return 0;
	}
	
	infile = fopen(argv[1],"r");
	if(!infile)
	{
		printf("Could not open %s\n",argv[1]);
		return -1;
	}
	
	setlocale(LC_ALL, "Japanese");
	
	ParseScript();
	
	outfile = fopen(argv[2],"wb");
	
	strtablesize = scrhead.strtable.size;
	scrhead.headersize = sizeof(scrhead);
	scrhead.strtable.offset = scrhead.headersize+scrhead.strindex.size*sizeof(Entry);
	scrhead.bytecode.offset = scrhead.strtable.offset+scrhead.strtable.size;
	scrhead.bytecode.size = bytestack.size;
	scrhead.strindex.offset = scrhead.headersize;
	scrhead.strtable.size = scrhead.strindex.size;
	scrhead.labels.offset = scrhead.bytecode.offset+scrhead.bytecode.size;
	scrhead.markers.offset = scrhead.labels.offset+scrhead.labels.size*4;
	scrhead.unk3.offset = scrhead.unk4.offset = scrhead.unk5.offset = scrhead.unk6.offset = scrhead.markers.offset+scrhead.markers.size*4;
	scrhead.unk7.offset = scrhead.unk8.offset = scrhead.unk9.offset = scrhead.unk10.offset = scrhead.markers.offset+scrhead.markers.size*4;
	scrhead.unk11.offset = scrhead.markers.offset+scrhead.markers.size*4;
	scrhead.unk12.offset = scrhead.markers.offset+scrhead.markers.size*4;
	scrhead.unk13.offset = scrhead.unk12.offset+scrhead.unk12.size*4;
	
	buffer = (unsigned char*)calloc(scrhead.unk13.offset+scrhead.unk13.size*4,sizeof(unsigned char));
	
	/*
	fwrite(&scrhead,1,sizeof(scrhead),outfile);
	fwrite(strindex,sizeof(Entry),scrhead.strindex.size,outfile);
	fwrite(strtable,1,strtablesize,outfile);
	fwrite(bytestack.stack,1,scrhead.bytecode.size,outfile);
	fwrite(labelstack.stack,4,scrhead.labels.size,outfile);
	fwrite(&markerstack,4,scrhead.markers.size,outfile);
	fwrite(unk12stack,4,scrhead.unk12.size,outfile);
	fwrite(unk13stack,4,scrhead.unk13.size,outfile);
	*/
	
	memcpy(buffer+pos,&scrhead,sizeof(scrhead));	pos += sizeof(scrhead);
	memcpy(buffer+pos,strindex,sizeof(Entry)*scrhead.strindex.size);	pos += sizeof(Entry)*scrhead.strindex.size;
	memcpy(buffer+pos,strtable,strtablesize);	pos += strtablesize;
	memcpy(buffer+pos,bytestack.stack,scrhead.bytecode.size);	pos += scrhead.bytecode.size;
	memcpy(buffer+pos,labelstack.stack,4*scrhead.labels.size);	pos += 4*scrhead.labels.size;
	memcpy(buffer+pos,&markerstack,4*scrhead.markers.size); pos += 4*scrhead.markers.size;
	memcpy(buffer+pos,unk12stack,4*scrhead.unk12.size);	pos += 4*scrhead.unk12.size;
	memcpy(buffer+pos,unk13stack,4*scrhead.unk13.size);	pos += 4*scrhead.unk13.size;
	
	//output = CompressData(buffer,pos,&pos);
	//fwrite(output,1,pos,outfile);
	fwrite(buffer,1,pos,outfile);
	
	free(buffer);
	free(output);
	fclose(infile);
	fclose(outfile);
	
	return 0;
}
Beispiel #16
0
/*
==============
main
==============
*/
int main (int argc, char **argv)
{
	int			i;
	char		path[1024];
	char		*basedir;
	double		starttime, endtime;

	printf ("Qdata Plus : "__TIME__" "__DATE__"\n");

	starttime = I_FloatTime();
	basedir = NULL;

	TK_Init();
	ExpandWildcards (&argc, &argv);

	for (i=1 ; i<argc ; i++)
	{
		if (!strcmp(argv[i], "-archive"))
		{
			// -archive f:/quake2/release/dump_11_30
			archive = true;
			strcpy (archivedir, argv[i+1]);
			printf ("Archiving source to: %s\n", archivedir);
			i++;
		}
		else if (!strcmp(argv[i], "-release"))
		{
			g_release = true;
			strcpy (g_releasedir, argv[i+1]);
			printf ("Copy output to: %s\n", g_releasedir);
			i++;
		}
		else if (!strcmp(argv[i], "-base"))
		{
			i++;
			basedir = argv[i];
		}
		else if (!strcmp(argv[i], "-compress"))
		{
			g_compress_pak = true;
			printf ("Compressing pakfile\n");
		}
		else if (!strcmp(argv[i], "-pak"))
		{
			g_release = true;
			g_pak = true;
			printf ("Building pakfile: %s\n", argv[i+1]);
			BeginPak (argv[i+1]);
			i++;
		}
		else if (!strcmp(argv[i], "-only"))
		{
			strcpy (g_only, argv[i+1]);
			printf ("Only grabbing %s\n", g_only);
			i++;
		}
		else if (!strcmpi(argv[i], "-keypress"))
		{
			g_dokeypress = true;
		}
		else if (!strcmp(argv[i], "-3ds"))
		{
			do3ds = true;
			printf ("loading .3ds files\n");
		}
		else if (!strcmp(argv[i], "-materialfile"))
		{
			strcpy(g_materialFile, argv[i+1]);
			printf("Setting material file to %s\n", g_materialFile);
			i++;
		}
/*		else if (!strcmpi(argv[i], "-newgen"))
		{
			if (i < argc-4)
			{
				printf("run new triangle grouping routine here\n");
				NewGen(argv[i+1],argv[i+2],atoi(argv[i+3]),atoi(argv[i+4]));
			}
			else
			{
				printf("qdata -newskin <base.hrc> <skin.pcx> width height\n");
			}
			return 0;
		}
*/		else if (!strcmpi(argv[i], "-genskin"))
		{
			i++;
			if (i < argc-3)
			{
				GenSkin(argv[i],argv[i+1],atol(argv[i+2]),atol(argv[i+3]));
			}
			else
			{
				printf("qdata -genskin <base.hrc> <skin.pcx> <desired width> <desired height>\n");
			}
			return 0;
			
		}
		else if (!strcmpi(argv[i], "-noopts"))
		{
			g_no_opimizations = true;
			printf("not performing optimizations\n");
		}
		else if (!strcmpi(argv[i], "-md2"))
		{
			g_forcemodel = MODEL_MD2;
		}
		else if (!strcmpi(argv[i], "-fm"))
		{
			g_forcemodel = MODEL_FM;
		}
		else if (!strcmpi(argv[i], "-verbose"))
		{
			g_verbose = true;
		}
		else if (!strcmpi(argv[i], "-oldskin"))
		{
			g_allow_newskin = false;
		}
		else if (!strcmpi(argv[i], "-ignoreUV"))
		{
			g_ignoreTriUV = true;
		}
		else if (!strcmpi(argv[i], "-publish"))
		{
			g_publishOutput = true;
		}
		else if (!strcmpi(argv[i], "-nomkdir"))
		{
			g_nomkdir = true;
		}
		else if (argv[i][0] == '-')
			Error ("Unknown option \"%s\"", argv[i]);
		else
			break;
	}

	if (i >= argc)
	{
		Error ("usage: qdata [-archive <directory>]\n"
			"             [-release <directory>]\n"
			"             [-base <directory>]\n"
			"             [-compress]\n"
			"             [-pak <file>]\n"
			"             [-only <model>]\n"
			"             [-keypress]\n"
			"             [-3ds]\n"
			"             [-materialfile <file>]\n"
			"             [-noopts]\n"
			"             [-md2]\n"
			"             [-fm]\n"
			"             [-verbose]\n"
			"             [-ignoreUV]\n"
			"             [-oldskin]\n"
			"             [-publish]\n"
			"             [-nomkdir]\n"
			"             file.qdt\n"
			"or\n"
			"       qdata -genskin <base.hrc> <skin.pcx> <desired width> <desired height>");
	}

	if (do3ds)
		trifileext = ext_3ds;
	else
		trifileext = ext_tri;

	for ( ; i<argc ; i++)
	{
		printf ("--------------- %s ---------------\n", argv[i]);
		// load the script
		strcpy (path, argv[i]);
		DefaultExtension (path, ".qdt");
		DefaultExtension(g_materialFile, ".mat");
		SetQdirFromPath (path);

		printf("workingdir='%s'\n", gamedir);
		if (basedir)
		{
			qdir[0] = 0;
			g_outputDir = basedir;
		}

		printf("outputdir='%s'\n", g_outputDir);

		QFile_ReadMaterialTypes(g_materialFile);
		LoadScriptFile (ExpandArg(path));
		
		//
		// parse it
		//
		ParseScript ();

		// write out the last model
		FinishModel ();
		FMFinishModel ();
		FinishSprite ();
	}

	if (total_textures)
	{
		printf("\n");
		printf("Total textures processed: %d\n",total_textures);
		printf("Average size: %d x %d\n",total_x / total_textures, total_y / total_textures);
	}

	if (g_pak)
		FinishPak ();

	endtime = I_FloatTime();
	printf("Time elapsed:  %f\n", endtime-starttime);
	
	if (g_dokeypress)
	{
		printf("Success! ... Hit a key: ");
		getchar();
	}

	return 0;
}