125 lines
2.5 KiB
C
125 lines
2.5 KiB
C
/***
|
|
*
|
|
* Copyright (C) 2002 The Wastes Project, All Rights Reserved.
|
|
*
|
|
* This product contains software technology from Valve Software, LLC,
|
|
* Copyright © 1996-2001, Valve LLC, All rights reserved.
|
|
*
|
|
* Use, distribution, and modification of this source code and/or resulting
|
|
* object code is restricted to non-commercial enhancements to products from
|
|
* The Wastes Project. All other use, distribution, or modification is prohibited
|
|
* without written permission from The Wastes Project.
|
|
*
|
|
***/
|
|
//
|
|
// program entry, scripting parser
|
|
//
|
|
#include <ctype.h>
|
|
#include <malloc.h>
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "../../common/mathlib.h"
|
|
#include "../../common/const.h"
|
|
#include "../../common/twm.h"
|
|
#include "studiotwm.h"
|
|
|
|
#define VERSION_NUM "1.0"
|
|
|
|
int g_errCount = 0;
|
|
|
|
char g_szTexturePath[MAX_STRLEN];
|
|
float g_flScale = 1;
|
|
|
|
void ParseLine(char *line)
|
|
{
|
|
char *token = strtok(line," ");
|
|
|
|
if(token != NULL)
|
|
{
|
|
// parse the opening token
|
|
// TODO: triflip ?
|
|
if(strcmp("$texturepath",token) == 0)
|
|
{
|
|
char *param1 = strtok(NULL," ");
|
|
|
|
strcpy(g_szTexturePath,param1);
|
|
}
|
|
else if(strcmp("$convertsmd",token) == 0)
|
|
{
|
|
char *param1 = strtok(NULL," ");
|
|
char *param2 = strtok(NULL," ");
|
|
|
|
SMD_ConvertToTWM(param1,param2);
|
|
}
|
|
else if(strcmp("$scale",token) == 0)
|
|
{
|
|
char *param1 = strtok(NULL," ");
|
|
|
|
sscanf(param1,"%f",&g_flScale);
|
|
}
|
|
else
|
|
{
|
|
fprintf(stderr,"ERROR: invalid token %s\n",token);
|
|
g_errCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void RunScript(char *filename)
|
|
{
|
|
FILE *pFile = fopen(filename,"r");
|
|
|
|
if(pFile == NULL)
|
|
{
|
|
fprintf(stderr,"ERROR: Unable to load %s\n",filename);
|
|
g_errCount++;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
// Begin the parsing operation
|
|
char current_line[MAX_STRLEN];
|
|
memset(current_line,0,sizeof(char)*MAX_STRLEN);
|
|
|
|
while(fgets(current_line,MAX_STRLEN,pFile) != NULL)
|
|
{
|
|
// strip comments first
|
|
char *comment = strstr(current_line,"//");
|
|
if(comment != NULL)
|
|
comment[0] = '\0';
|
|
|
|
// strip newline
|
|
comment = strchr(current_line,'\n');
|
|
if(comment != NULL)
|
|
comment[0] = '\0';
|
|
|
|
ParseLine(current_line);
|
|
}
|
|
}
|
|
|
|
fclose(pFile);
|
|
}
|
|
|
|
int main(int argc,char **argv)
|
|
{
|
|
// No options put in, print help
|
|
if(argc <= 1)
|
|
{
|
|
printf("usage: studiotwm script1 script2...\n");
|
|
}
|
|
else
|
|
{
|
|
int arg_count;
|
|
|
|
printf("studiotwm version %s\n",VERSION_NUM);
|
|
|
|
// Start at 1 to bypass the path arg
|
|
for(arg_count = 1;arg_count < argc;arg_count++)
|
|
RunScript(argv[arg_count]);
|
|
|
|
printf("%i errors\n",g_errCount);
|
|
}
|
|
|
|
return 0;
|
|
} |