/* ================= Cmd_Skinsize Set a skin size other than the default ================= */ void Cmd_Skinsize (void) { GetScriptToken (false); g_fixedwidth = atoi(token); GetScriptToken (false); g_fixedheight = atoi(token); }
/* ================= Cmd_Origin ================= */ void Cmd_Origin( void ){ // rotate points into frame of reference so model points down the // positive x axis GetScriptToken( false ); adjust[1] = -atof( token ); GetScriptToken( false ); adjust[0] = atof( token ); GetScriptToken( false ); adjust[2] = -atof( token ); }
void QFile_ReadMaterialTypes(char* filename) { int i; FILE *f; if (materialtypes != defaultmaterialtypes) { if (materialtypes) free(materialtypes); materialtypes = (materialtype_t*)malloc(256 * sizeof(materialtype_t)); } f = fopen (filename, "rb"); if (!f) { materialtypes = defaultmaterialtypes; return; } fclose (f); LoadScriptFile(filename); i = 0; do { GetScriptToken (true); if (endofscript) { break; } if (strcmp(sof_token, "material") != 0) { while (ScriptTokenAvailable()) { GetScriptToken(false); } } else { GetScriptToken(false); materialtypes[i].name = (char*)malloc(strlen(sof_token) + 1); strcpy(materialtypes[i].name, sof_token); GetScriptToken (false); materialtypes[i].value = atoi(sof_token); } } while (i++ < 255); materialtypes[i].name = NULL; materialtypes[i].value = 0; }
/* =============== Cmd_Cd =============== */ void Cmd_Cd (void) { char temp[256]; FinishModel (); ClearModel (); GetScriptToken (false); // this is a silly mess... sprintf (cdpartial, "models/%s", token); sprintf (cdarchive, "%smodels/%s", gamedir+strlen(qdir), token); sprintf (cddir, "%s%s", gamedir, cdpartial); // Since we also changed directories on the output side (for mirror) make sure the outputdir is set properly too. sprintf(temp, "%s%s", g_outputDir, cdpartial); strcpy(g_outputDir, temp); // if -only was specified and this cd doesn't match, // skip the model (you only need to match leading chars, // so you could regrab all monsters with -only monsters) if (!g_only[0]) return; if (strncmp(token, g_only, strlen(g_only))) { g_skipmodel = true; printf ("skipping %s\n", cdpartial); } }
int main(int argc, char *argv[]) { ScriptTokenInfo *token_info; token_info = AcquireScriptTokenInfo( (argc>1) ? argv[1] : "-" ); if (token_info == (ScriptTokenInfo *) NULL) { printf("Script Open Failure : %s\n", strerror(errno)); return(1); } while (1) { if( GetScriptToken(token_info) == MagickFalse ) break; if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) { token_info->token[INITAL_TOKEN_LENGTH-4] = '.'; token_info->token[INITAL_TOKEN_LENGTH-3] = '.'; token_info->token[INITAL_TOKEN_LENGTH-2] = '.'; token_info->token[INITAL_TOKEN_LENGTH-1] = '\0'; } printf("l=%d, c=%d, stat=%d, len=%d, token=\"%s\"\n", token_info->token_line, token_info->token_column, token_info->status, token_info->length, token_info->token); } switch( token_info->status ) { case TokenStatusOK: break; case TokenStatusEOF: printf("EOF Found\n"); break; case TokenStatusBadQuotes: /* Ensure last token has a sane length for error report */ if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) { token_info->token[INITAL_TOKEN_LENGTH-4] = '.'; token_info->token[INITAL_TOKEN_LENGTH-3] = '.'; token_info->token[INITAL_TOKEN_LENGTH-2] = '.'; token_info->token[INITAL_TOKEN_LENGTH-1] = '\0'; } printf("Bad Quotes l=%d, c=%d token=\"%s\"\n", token_info->token_line,token_info->token_column, token_info->token); break; case TokenStatusMemoryFailed: /* token is invalid */ printf("Out of Memory l=%d, c=%d\n", token_info->token_line,token_info->token_column); break; case TokenStatusBinary: /* token is invalid */ printf("Binary Char at l=%d, c=%d\n", token_info->curr_line,token_info->curr_column); break; } /* Clean up */ token_info = DestroyScriptTokenInfo(token_info); return(0); }
/* ================= Cmd_ScaleUp ================= */ void Cmd_ScaleUp (void) { GetScriptToken (false); scale_up = atof (token); if (g_skipmodel || g_release || g_archive) return; printf ("Scale up: %f\n", scale_up); }
/* =============== Cmd_picdir =============== */ void Cmd_Picdir( void ){ char filename[1024]; GetScriptToken( false ); strcpy( pic_prefix, token ); // create the directory if needed sprintf( filename, "%sPics", g_outputDir ); Q_mkdir( filename ); sprintf( filename, "%sPics/%s", g_outputDir, pic_prefix ); Q_mkdir( filename ); }
void Cmd_TextureMix() { miptex32_t *qtex32; char filename[1024]; int size; InitVars(); GetScriptToken (false); strcpy(root, token); RemoveExt(root); RemoveLeading(root); strcpy(filename, ExpandPathAndArchive(token)); if (SetVars(filename)) { // Create combined texture percent = ((TotalArea() * 100) / (out.w * out.h)); printf("Total area consumed : %d%%\n", percent); printf("Texture resolution : %dx%d pixels.\n", xcharsize, ycharsize); CreateMain(); // Save image as m32 sprintf (filename, "%spics/misc/%s.m32", gamedir, out.name); qtex32 = CreateMip32((unsigned *)outpixels, out.w, out.h, &size, false); qtex32->contents = 0; qtex32->value = 0; qtex32->scale_x = 1.0; qtex32->scale_y = 1.0; sprintf (qtex32->name, "misc/%s", out.name); printf ("\n\nwriting %s\n", filename); SaveFile (filename, (byte *)qtex32, size); free (qtex32); // Save out script file sprintf (filename, "%spics/misc/%s.fnt", gamedir, outscript); printf("Writing %s as script file\n", filename); if (!SaveScript(filename)) { printf("Unable to save output script.\n"); } } printf("Everythings groovy.\n"); Cleanup(); }
/* =============== Cmd_Frame =============== */ void Cmd_Frame( void ){ while ( ScriptTokenAvailable() ) { GetScriptToken( false ); if ( g_skipmodel ) { continue; } if ( g_release || g_archive ) { model.num_frames = 1; // don't skip the writeout continue; } H_printf( "#define FRAME_%-16s\t%i\n", token, model.num_frames ); GrabFrame( token ); } }
/* ================= Cmd_Cluster ================= */ void Cmd_Cluster(){ char file1[1024]; GetScriptToken( false ); printf( "---------------------\n" ); sprintf( file1, "%s/%s", cdpartial, token ); printf( "%s\n", file1 ); ExpandPathAndArchive( file1 ); sprintf( file1, "%s/%s", cddir, token ); LoadClusters( file1, (int **)&clusters, (int *)&num_verts, jointed ); new_num_verts[0] = num_verts[0]; clustered = 1; }
/* =============== Cmd_Maps Only relevent for release and pak files. Releases the .bsp files for the maps, and scans all of the files to build a list of all textures used, which are then released. =============== */ void Cmd_Maps (void) { char map[1024]; int i; while (ScriptTokenAvailable ()) { GetScriptToken (false); sprintf (map, "maps/%s.bsp", token); ReleaseFile (map); if (!g_release) continue; // get all the texture references sprintf (map, "%smaps/%s.bsp", gamedir, token); LoadBSPFileTexinfo (map); for (i=0 ; i<numtexinfo ; i++) ReleaseTexture (texinfo[i].texture); } }
qboolean EndOfScript (qboolean crossline) { if (!crossline) Error ("Line %i is incomplete\n",sof_scriptline); if (!strcmp (script->filename, "memory buffer")) { endofscript = true; return false; } free (script->buffer); if (script == scriptstack+1) { endofscript = true; return false; } script--; sof_scriptline = script->line; printf ("returning to %s\n", script->filename); return GetScriptToken (crossline); }
/* ============== GetScriptToken ============== */ qboolean GetScriptToken (qboolean crossline) { char *token_p; if (tokenready) // is a sof_token allready waiting? { tokenready = false; return true; } if (script->script_p >= script->end_p) return EndOfScript (crossline); // // skip space // skipspace: while (*script->script_p <= 32) { if (script->script_p >= script->end_p) return EndOfScript (crossline); if (*script->script_p++ == '\n') { if (!crossline) Error ("Line %i is incomplete\n",sof_scriptline); sof_scriptline = script->line++; } } if (script->script_p >= script->end_p) return EndOfScript (crossline); // ; # // comments if (*script->script_p == ';' || *script->script_p == '#' || ( script->script_p[0] == '/' && script->script_p[1] == '/') ) { if (!crossline) Error ("Line %i is incomplete\n",sof_scriptline); while (*script->script_p++ != '\n') if (script->script_p >= script->end_p) return EndOfScript (crossline); goto skipspace; } // /* */ comments if (script->script_p[0] == '/' && script->script_p[1] == '*') { if (!crossline) Error ("Line %i is incomplete\n",sof_scriptline); script->script_p+=2; while (script->script_p[0] != '*' && script->script_p[1] != '/') { script->script_p++; if (script->script_p >= script->end_p) return EndOfScript (crossline); } script->script_p += 2; goto skipspace; } // // copy sof_token // token_p = sof_token; if (*script->script_p == '"') { // quoted sof_token script->script_p++; while (*script->script_p != '"') { *token_p++ = *script->script_p++; if (script->script_p == script->end_p) break; if (token_p == &sof_token[MAXTOKEN]) Error ("Token too large on line %i\n",sof_scriptline); } script->script_p++; } else // regular sof_token while ( *script->script_p > 32 && *script->script_p != ';') { *token_p++ = *script->script_p++; if (script->script_p == script->end_p) break; if (token_p == &sof_token[MAXTOKEN]) Error ("Token too large on line %i\n",sof_scriptline); } *token_p = 0; if (!strcmp (sof_token, "$include")) { GetScriptToken (false); AddScriptToStack (sof_token); return GetScriptToken (crossline); } return true; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + P r o c e s s S c r i p t O p t i o n s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ProcessScriptOptions() reads options and processes options as they are % found in the given file, or pipeline. The filename to open and read % options is given as the 'index' argument of the argument array given. % % Other arguments following index may be read by special script options % as settings (strings), images, or as operations to be processed in various % ways. How they are treated is up to the script being processed. % % Note that a script not 'return' to the command line processing, nor can % they call (and return from) other scripts. At least not at this time. % % There are no 'ProcessOptionFlags' control flags at this time. % % The format of the ProcessScriptOptions method is: % % void ProcessScriptOptions(MagickCLI *cli_wand,int argc,char **argv, % int index) % % A description of each parameter follows: % % o cli_wand: the main CLI Wand to use. % % o argc: the number of elements in the argument vector. % % o argv: A text array containing the command line arguments. % % o index: offset for argc to CLI argumnet count % */ WandExport void ProcessScriptOptions(MagickCLI *cli_wand,int argc,char **argv, int index) { ScriptTokenInfo *token_info; CommandOptionFlags option_type; int count; char *option, *arg1, *arg2; assert(argc>index); /* at least one argument - script name */ assert(argv != (char **)NULL); assert(argv[index] != (char *)NULL); assert(argv[argc-1] != (char *)NULL); assert(cli_wand != (MagickCLI *) NULL); assert(cli_wand->signature == WandSignature); if (cli_wand->wand.debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name); /* open file script or stream, and set up tokenizer */ token_info = AcquireScriptTokenInfo(argv[index]); if (token_info == (ScriptTokenInfo *) NULL) { CLIWandExceptionFile(OptionFatalError,"UnableToOpenScript",argv[index]); return; } /* define the error location string for use in exceptions order of localtion format escapes: filename, line, column */ cli_wand->location="in \"%s\" at line %u,column %u"; if ( LocaleCompare("-", argv[index]) == 0 ) cli_wand->filename="stdin"; else cli_wand->filename=argv[index]; /* Process Options from Script */ option = arg1 = arg2 = (char*)NULL; while (1) { /* Get a option */ { MagickBooleanType status = GetScriptToken(token_info); cli_wand->line=token_info->token_line; cli_wand->column=token_info->token_column; if( IfMagickFalse(status) ) break; /* error or end of options */ } /* save option details */ CloneString(&option,token_info->token); { /* get option type and argument count */ const OptionInfo *option_info = GetCommandOptionInfo(option); count=option_info->type; option_type=(CommandOptionFlags) option_info->flags; #if 0 (void) FormatLocaleFile(stderr, "Script: %u,%u: \"%s\" matched \"%s\"\n", cli_wand->line, cli_wand->line, option, option_info->mnemonic ); #endif } /* handle a undefined option - image read? */ if ( option_type == UndefinedOptionFlag || (option_type & NonMagickOptionFlag) != 0 ) { #if MagickCommandDebug >= 3 (void) FormatLocaleFile(stderr, "Script %u,%u Non-Option: \"%s\"\n", cli_wand->line, cli_wand->line, option); #endif if ( IfMagickFalse(IsCommandOption(option))) { /* non-option -- treat as a image read */ CLISpecialOperator(cli_wand,"-read",option); goto next_token; } if ( LocaleCompare(option,"-script") == 0 ) { option_type=SpecialOptionFlag; count=1; /* fall thru - collect one argument */ } else { CLIWandExceptionBreak(OptionFatalError,"UnrecognizedOption",option); goto next_token; } } if ( count >= 1 ) { if( IfMagickFalse(GetScriptToken(token_info)) ) CLIWandException(OptionFatalError,"MissingArgument",option); CloneString(&arg1,token_info->token); } else CloneString(&arg1,(char *)NULL); if ( count >= 2 ) { if( IfMagickFalse(GetScriptToken(token_info)) ) CLIWandExceptionBreak(OptionFatalError,"MissingArgument",option); CloneString(&arg2,token_info->token); } else CloneString(&arg2,(char *)NULL); #if MagickCommandDebug >= 3 (void) FormatLocaleFile(stderr, "Script %u,%u Option: \"%s\" Count: %d Flags: %04x Args: \"%s\" \"%s\"\n", cli_wand->line,cli_wand->line,option,count,option_type,arg1,arg2); #endif if ( (option_type & GenesisOptionFlag) != 0 ) { /* Genesis Options have no place in a magick script */ CLIWandExceptionBreak(OptionError,"InvalidUseOfOption",option); goto next_token; } if ( (option_type & DeprecateOptionFlag) != 0 ) { CLIWandException(OptionWarning,"DeprecatedOption",option); if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse ) break; /* fall through - do the depreciated option */ } if (((option_type & ImageRequiredFlags) != 0 ) && ( cli_wand->wand.images == (Image *)NULL ) ) { CLIWandException(OptionError,"NoImagesFound",option); goto next_token; } /* handle special script-argument options here */ //either continue processing command line // or making use of the command line options. //CLICommandOptions(cli_wand,count+1,argv, MagickScriptArgsFlags); /* Process Option from file */ if ( (option_type & SpecialOptionFlag) != 0 ) { if ( LocaleCompare(option,"-exit") == 0 ) { break; /* forced end of script */ } else if ( LocaleCompare(option,"-script") == 0 ) { /* FUTURE: call new script from this script */ CLIWandExceptionBreak(OptionError,"InvalidUseOfOption",option); goto next_token; } /* handle any other special operators now */ CLISpecialOperator(cli_wand,option,arg1); } if ( (option_type & SettingOptionFlags) != 0 ) { CLISettingOptionInfo(cli_wand, option, arg1, arg2); // FUTURE: Sync Specific Settings into Image Properities (not global) } if ( cli_wand->wand.images != (Image *)NULL ) SyncImagesSettings(cli_wand->wand.image_info,cli_wand->wand.images, cli_wand->wand.exception); if ( (option_type & SimpleOperatorOptionFlag) != 0) CLISimpleOperatorImages(cli_wand, option, arg1, arg2); if ( (option_type & ListOperatorOptionFlag) != 0 ) CLIListOperatorImages(cli_wand, option, arg1, arg2); next_token: #if MagickCommandDebug >= 9 OutputOptions(cli_wand->wand.image_info); if ( cli_wand->wand.images != (Image *)NULL ) { OutputArtifacts(cli_wand->wand.images); OutputProperties(cli_wand->wand.images,cli_wand->wand.exception); } #endif if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse ) break; } #if MagickCommandDebug >= 3 (void) FormatLocaleFile(stderr, "Script End: %d\n", token_info->status); #endif switch( token_info->status ) { case TokenStatusOK: case TokenStatusEOF: if (cli_wand->image_list_stack != (Stack *)NULL) CLIWandException(OptionError,"UnbalancedParenthesis", "(eof)"); else if (cli_wand->image_info_stack != (Stack *)NULL) CLIWandException(OptionError,"UnbalancedBraces", "(eof)"); break; case TokenStatusBadQuotes: /* Ensure last token has a sane length for error report */ if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) { token_info->token[INITAL_TOKEN_LENGTH-4] = '.'; token_info->token[INITAL_TOKEN_LENGTH-3] = '.'; token_info->token[INITAL_TOKEN_LENGTH-2] = '.'; token_info->token[INITAL_TOKEN_LENGTH-1] = '\0'; } CLIWandException(OptionFatalError,"ScriptUnbalancedQuotes", token_info->token); break; case TokenStatusMemoryFailed: CLIWandException(OptionFatalError,"ScriptTokenMemoryFailed",""); break; case TokenStatusBinary: CLIWandException(OptionFatalError,"ScriptIsBinary",""); break; } /* Clean up */ token_info = DestroyScriptTokenInfo(token_info); CloneString(&option,(char *)NULL); CloneString(&arg1,(char *)NULL); CloneString(&arg2,(char *)NULL); return; }
/* ================= Cmd_Modelname Gives a different name/location for the file, instead of the cddir ================= */ void Cmd_Modelname (void) { GetScriptToken (false); strcpy (modelname, token); }
/* =============== Cmd_File This is only used to cause a file to be copied during a release build (default.cfg, maps, etc) =============== */ void Cmd_File (void) { GetScriptToken (false); ReleaseFile (token); }
/* =============== Cmd_Dir This is only used to cause a directory to be copied during a release build (sounds, etc) =============== */ void Cmd_Dir (void) { GetScriptToken (false); PackDirectory_r (token); }
/* =============== Cmd_Skin Skins aren't actually stored in the file, only a reference is saved out to the header file. =============== */ void Cmd_Skin (void) { byte *palette; byte *pixels; int width, height; byte *cropped; int y; char name[1024], savename[1024]; GetScriptToken (false); if (model.num_skins == MAX_MD2SKINS) Error ("model.num_skins == MAX_MD2SKINS"); if (g_skipmodel) return; #if 1 sprintf (name, "%s/%s.pcx", cddir, token); sprintf (savename, "%s/!%s.pcx", g_outputDir, token); sprintf (g_skins[model.num_skins], "%s/!%s.pcx", cdpartial, token); #else sprintf (name, "%s/%s.lbm", cdarchive, token); strcpy (name, ExpandPathAndArchive( name ) ); // sprintf (name, "%s/%s.lbm", cddir, token); if (ScriptTokenAvailable()) { GetScriptToken (false); sprintf (g_skins[model.num_skins], "%s.pcx", token); sprintf (savename, "%s%s.pcx", g_outputDir, g_skins[model.num_skins]); } else { sprintf (savename, "%s/%s.pcx", g_outputDir, token); sprintf (g_skins[model.num_skins], "%s/%s.pcx", cdpartial, token); } #endif model.num_skins++; if (g_skipmodel || g_release || g_archive) return; // load the image printf ("loading %s\n", name); Load256Image (name, &pixels, &palette, &width, &height); // RemapZero (pixels, palette, width, height); // crop it to the proper size cropped = (byte *) SafeMalloc (model.skinwidth*model.skinheight, "Cmd_Skin"); for (y=0 ; y<model.skinheight ; y++) { memcpy (cropped+y*model.skinwidth, pixels+y*width, model.skinwidth); } // save off the new image printf ("saving %s\n", savename); CreatePath (savename); WritePCXfile (savename, cropped, model.skinwidth, model.skinheight, palette); free (pixels); free (palette); free (cropped); }
/* =============== ParseScript =============== */ void ParseScript (void) { while (1) { do { // look for a line starting with a $ command GetScriptToken (true); if (endofscript) return; if (token[0] == '$') break; while (ScriptTokenAvailable()) GetScriptToken (false); } while (1); // // model commands // if (!strcmp (token, "$modelname")) MODELCMD_Modelname (MODEL_MD2); else if (!strcmp (token, "$cd")) MODELCMD_Cd (MODEL_MD2); else if (!strcmp (token, "$origin")) MODELCMD_Origin (MODEL_MD2); else if (!strcmp (token, "$cluster")) MODELCMD_Cluster (MODEL_MD2); else if (!strcmp (token, "$base")) MODELCMD_Base (MODEL_MD2); else if (!strcmp (token, "$scale")) MODELCMD_ScaleUp (MODEL_MD2); else if (!strcmp (token, "$frame")) MODELCMD_Frame (MODEL_MD2); else if (!strcmp (token, "$skin")) MODELCMD_Skin (MODEL_MD2); else if (!strcmp (token, "$skinsize")) MODELCMD_Skinsize (MODEL_MD2); // // flexible model commands // else if (!strcmp (token, "$fm_modelname")) MODELCMD_Modelname (MODEL_FM); else if (!strcmp (token, "$fm_base")) MODELCMD_Base (MODEL_FM); else if (!strcmp (token, "$fm_basest")) MODELCMD_BaseST (MODEL_FM); else if (!strcmp (token, "$fm_cd")) MODELCMD_Cd (MODEL_FM); else if (!strcmp (token, "$fm_origin")) MODELCMD_Origin (MODEL_FM); else if (!strcmp (token, "$fm_cluster")) MODELCMD_Cluster (MODEL_FM); else if (!strcmp (token, "$fm_skeleton")) MODELCMD_Skeleton (MODEL_FM); else if (!strcmp (token, "$fm_scale")) MODELCMD_ScaleUp (MODEL_FM); else if (!strcmp (token, "$fm_frame")) MODELCMD_Frame (MODEL_FM); else if (!strcmp (token, "$fm_skeletal_frame")) // left in for compadibility with qdt already using fm_skeletal_frame MODELCMD_Frame (MODEL_FM); else if (!strcmp (token, "$fm_skin")) MODELCMD_Skin (MODEL_FM); else if (!strcmp (token, "$fm_skinsize")) MODELCMD_Skinsize (MODEL_FM); else if (!strcmp (token, "$fm_begin_group")) MODELCMD_BeginGroup(MODEL_FM); else if (!strcmp (token, "$fm_end_group")) MODELCMD_EndGroup(MODEL_FM); else if (!strcmp (token, "$fm_referenced")) MODELCMD_Referenced(MODEL_FM); else if (!strcmp (token, "$fm_node_order")) MODELCMD_NodeOrder(MODEL_FM); // // sprite commands // else if (!strcmp (token, "$spritename")) Cmd_SpriteName (); else if (!strcmp (token, "$sprdir")) Cmd_Sprdir (); else if (!strcmp (token, "$load")) Cmd_Load (); else if (!strcmp (token, "$spriteframe")) Cmd_SpriteFrame (); // // image commands // else if (!strcmpi (token, "$grab")) Cmd_Grab (); else if (!strcmpi (token, "$raw")) Cmd_Raw (); else if (!strcmpi (token, "$colormap")) Cmd_Colormap (); else if (!strcmpi (token, "$mippal")) Cmd_Mippal (); else if (!strcmpi (token, "$mipdir")) Cmd_Mipdir (); else if (!strcmpi (token, "$mip")) Cmd_Mip (); else if (!strcmp (token, "$environment")) Cmd_Environment (); // // pics // else if (!strcmp (token, "$picdir")) Cmd_Picdir (); else if (!strcmp (token, "$pic")) Cmd_Pic (); // // book // else if (!strcmp (token, "$bookdir")) Cmd_Bookdir (); else if (!strcmp (token, "$book")) Cmd_Book (); // // tmix // else if (!strcmp (token, "$texturemix")) Cmd_TextureMix (); // // video // else if (!strcmp (token, "$video")) Cmd_Video (); // // misc // else if (!strcmp (token, "$file")) Cmd_File (); else if (!strcmp (token, "$dir")) Cmd_Dir (); else if (!strcmp (token, "$maps")) Cmd_Maps (); else if (!strcmp (token, "$alphalight")) Cmd_Alphalight (); else if (!strcmp (token, "$inverse16table" )) Cmd_Inverse16Table(); else Error ("bad command %s\n", token); } }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + P r o c e s s S c r i p t O p t i o n s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ProcessScriptOptions() reads options and processes options as they are % found in the given file, or pipeline. The filename to open and read % options is given as the 'index' argument of the argument array given. % % Other arguments following index may be read by special script options % as settings (strings), images, or as operations to be processed in various % ways. How they are treated is up to the script being processed. % % Note that a script not 'return' to the command line processing, nor can % they call (and return from) other scripts. At least not at this time. % % There are no 'ProcessOptionFlags' control flags at this time. % % The format of the ProcessScriptOptions method is: % % void ProcessScriptOptions(MagickCLI *cli_wand,const char *filename, % int argc,char **argv,int index) % % A description of each parameter follows: % % o cli_wand: the main CLI Wand to use. % % o filename: the filename of script to process % % o argc: the number of elements in the argument vector. (optional) % % o argv: A text array containing the command line arguments. (optional) % % o index: offset of next argment in argv (script arguments) (optional) % */ WandExport void ProcessScriptOptions(MagickCLI *cli_wand,const char *filename, int argc,char **argv,int index) { ScriptTokenInfo *token_info; CommandOptionFlags option_type; int count; char *option, *arg1, *arg2; assert(filename != (char *) NULL ); /* at least one argument - script name */ assert(cli_wand != (MagickCLI *) NULL); assert(cli_wand->signature == MagickWandSignature); if (cli_wand->wand.debug != MagickFalse) (void) LogMagickEvent(CommandEvent,GetMagickModule(), "Processing script \"%s\"", filename); /* open file script or stream, and set up tokenizer */ token_info = AcquireScriptTokenInfo(filename); if (token_info == (ScriptTokenInfo *) NULL) { CLIWandExceptionFile(OptionFatalError,"UnableToOpenScript",filename); return; } /* define the error location string for use in exceptions order of localtion format escapes: filename, line, column */ cli_wand->location="in \"%s\" at line %u,column %u"; if ( LocaleCompare("-", filename) == 0 ) cli_wand->filename="stdin"; else cli_wand->filename=filename; /* Process Options from Script */ option = arg1 = arg2 = (char*) NULL; DisableMSCWarning(4127) while (1) { RestoreMSCWarning { MagickBooleanType status = GetScriptToken(token_info); cli_wand->line=token_info->token_line; cli_wand->column=token_info->token_column; if (status == MagickFalse) break; /* error or end of options */ } do { /* use break to loop to exception handler and loop */ /* save option details */ CloneString(&option,token_info->token); /* get option, its argument count, and option type */ cli_wand->command = GetCommandOptionInfo(option); count=cli_wand->command->type; option_type=(CommandOptionFlags) cli_wand->command->flags; #if 0 (void) FormatLocaleFile(stderr, "Script: %u,%u: \"%s\" matched \"%s\"\n", cli_wand->line, cli_wand->line, option, cli_wand->command->mnemonic ); #endif /* handle a undefined option - image read - always for "magick-script" */ if ( option_type == UndefinedOptionFlag || (option_type & NonMagickOptionFlag) != 0 ) { #if MagickCommandDebug >= 3 (void) FormatLocaleFile(stderr, "Script %u,%u Non-Option: \"%s\"\n", cli_wand->line, cli_wand->line, option); #endif if (IsCommandOption(option) == MagickFalse) { /* non-option -- treat as a image read */ cli_wand->command=(const OptionInfo *) NULL; CLIOption(cli_wand,"-read",option); break; /* next option */ } CLIWandException(OptionFatalError,"UnrecognizedOption",option); break; /* next option */ } if ( count >= 1 ) { if (GetScriptToken(token_info) == MagickFalse) CLIWandException(OptionFatalError,"MissingArgument",option); CloneString(&arg1,token_info->token); } else CloneString(&arg1,(char *) NULL); if ( count >= 2 ) { if (GetScriptToken(token_info) == MagickFalse) CLIWandExceptionBreak(OptionFatalError,"MissingArgument",option); CloneString(&arg2,token_info->token); } else CloneString(&arg2,(char *) NULL); /* Process Options */ #if MagickCommandDebug >= 3 (void) FormatLocaleFile(stderr, "Script %u,%u Option: \"%s\" Count: %d Flags: %04x Args: \"%s\" \"%s\"\n", cli_wand->line,cli_wand->line,option,count,option_type,arg1,arg2); #endif /* Hard Deprecated Options, no code to execute - error */ if ( (option_type & DeprecateOptionFlag) != 0 ) { CLIWandException(OptionError,"DeprecatedOptionNoCode",option); break; /* next option */ } /* MagickCommandGenesis() options have no place in a magick script */ if ( (option_type & GenesisOptionFlag) != 0 ) { CLIWandException(OptionError,"InvalidUseOfOption",option); break; /* next option */ } /* handle any special 'script' options */ if ( (option_type & SpecialOptionFlag) != 0 ) { if ( LocaleCompare(option,"-exit") == 0 ) { goto loop_exit; /* break out of loop - return from script */ } if ( LocaleCompare(option,"-script") == 0 ) { /* FUTURE: call new script from this script - error for now */ CLIWandException(OptionError,"InvalidUseOfOption",option); break; /* next option */ } /* FUTURE: handle special script-argument options here */ /* handle any other special operators now */ CLIWandException(OptionError,"InvalidUseOfOption",option); break; /* next option */ } /* Process non-specific Option */ CLIOption(cli_wand, option, arg1, arg2); (void) fflush(stdout); (void) fflush(stderr); DisableMSCWarning(4127) } while (0); /* break block to next option */ RestoreMSCWarning #if MagickCommandDebug >= 5 fprintf(stderr, "Script Image Count = %ld\n", GetImageListLength(cli_wand->wand.images) ); #endif if (CLICatchException(cli_wand, MagickFalse) != MagickFalse) break; /* exit loop */ } /* Loop exit - check for some tokenization error */ loop_exit: #if MagickCommandDebug >= 3 (void) FormatLocaleFile(stderr, "Script End: %d\n", token_info->status); #endif switch( token_info->status ) { case TokenStatusOK: case TokenStatusEOF: if (cli_wand->image_list_stack != (Stack *) NULL) CLIWandException(OptionError,"UnbalancedParenthesis", "(eof)"); else if (cli_wand->image_info_stack != (Stack *) NULL) CLIWandException(OptionError,"UnbalancedBraces", "(eof)"); break; case TokenStatusBadQuotes: /* Ensure last token has a sane length for error report */ if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) { token_info->token[INITAL_TOKEN_LENGTH-4] = '.'; token_info->token[INITAL_TOKEN_LENGTH-3] = '.'; token_info->token[INITAL_TOKEN_LENGTH-2] = '.'; token_info->token[INITAL_TOKEN_LENGTH-1] = '\0'; } CLIWandException(OptionFatalError,"ScriptUnbalancedQuotes", token_info->token); break; case TokenStatusMemoryFailed: CLIWandException(OptionFatalError,"ScriptTokenMemoryFailed",""); break; case TokenStatusBinary: CLIWandException(OptionFatalError,"ScriptIsBinary",""); break; } (void) fflush(stdout); (void) fflush(stderr); if (cli_wand->wand.debug != MagickFalse) (void) LogMagickEvent(CommandEvent,GetMagickModule(), "Script End \"%s\"", filename); /* Clean up */ token_info = DestroyScriptTokenInfo(token_info); CloneString(&option,(char *) NULL); CloneString(&arg1,(char *) NULL); CloneString(&arg2,(char *) NULL); return; }
void Cmd_Pic( void ){ int xl,yl,xh,yh,w,h; byte *dest, *source; int flags, value, contents; char lumpname[128]; char animname[128]; byte buffer[256 * 256]; unsigned bufferl[256 * 256]; char filename[1024]; unsigned *destl, *sourcel; int linedelta, x, y; int size; miptex_t *qtex; miptex32_t *qtex32; float scale_x, scale_y; GetScriptToken( false ); strcpy( lumpname, token ); GetScriptToken( false ); xl = atoi( token ); GetScriptToken( false ); yl = atoi( token ); GetScriptToken( false ); w = atoi( token ); GetScriptToken( false ); h = atoi( token ); total_x += w; total_y += h; total_textures++; if ( ( w & 7 ) || ( h & 7 ) ) { Error( "line %i: miptex sizes must be multiples of 8", scriptline ); } flags = 0; contents = 0; value = 0; animname[0] = 0; scale_x = scale_y = 0.5; if ( TrueColorImage ) { sprintf( filename, "%spics/%s/%s.m32", g_outputDir, pic_prefix, lumpname ); if ( g_release ) { return; // textures are only released by $maps } xh = xl + w; yh = yl + h; if ( xl >= longimagewidth || xh > longimagewidth || yl >= longimageheight || yh > longimageheight ) { Error( "line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,longimagewidth,longimageheight ); } sourcel = longimage + ( yl * longimagewidth ) + xl; destl = bufferl; linedelta = ( longimagewidth - w ); for ( y = yl ; y < yh ; y++ ) { for ( x = xl ; x < xh ; x++ ) { *destl++ = *sourcel++; // RGBA } sourcel += linedelta; } qtex32 = CreateMip32( bufferl, w, h, &size, false ); qtex32->flags |= LittleLong( flags ); qtex32->contents = contents; qtex32->value = value; qtex32->scale_x = scale_x; qtex32->scale_y = scale_y; sprintf( qtex32->name, "%s/%s", pic_prefix, lumpname ); if ( animname[0] ) { sprintf( qtex32->animname, "%s/%s", pic_prefix, animname ); } // // write it out // printf( "writing %s\n", filename ); SaveFile( filename, (byte *)qtex32, size ); free( qtex32 ); } else { sprintf( filename, "%spics/%s/%s.m8", g_outputDir, pic_prefix, lumpname ); if ( g_release ) { return; // textures are only released by $maps } xh = xl + w; yh = yl + h; if ( xl >= byteimagewidth || xh > byteimagewidth || yl >= byteimageheight || yh > byteimageheight ) { Error( "line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,byteimagewidth,byteimageheight ); } source = byteimage + yl * byteimagewidth + xl; dest = buffer; linedelta = byteimagewidth - w; for ( y = yl ; y < yh ; y++ ) { for ( x = xl ; x < xh ; x++ ) { *dest++ = *source++; } source += linedelta; } qtex = CreateMip( buffer, w, h, lbmpalette, &size, false ); qtex->flags = flags; qtex->contents = contents; qtex->value = value; sprintf( qtex->name, "%s/%s", pic_prefix, lumpname ); if ( animname[0] ) { sprintf( qtex->animname, "%s/%s", pic_prefix, animname ); } // // write it out // printf( "writing %s\n", filename ); SaveFile( filename, (byte *)qtex, size ); free( qtex ); } }
/* ================= Cmd_Base ================= */ void Cmd_Base (void) { vec3_t base_xyz[MAX_VERTS]; triangle_t *ptri; int i, j, k; #if 1 #else int time1; #endif char file1[1024]; char file2[1024]; GetScriptToken (false); if (g_skipmodel || g_release || g_archive) return; printf ("---------------------\n"); #if 1 sprintf (file1, "%s/%s", cdpartial, token); printf ("%s ", file1); ExpandPathAndArchive (file1); sprintf (file1, "%s/%s", cddir, token); #else sprintf (file1, "%s/%s.%s", cdarchive, token, trifileext); printf ("%s\n", file1); ExpandPathAndArchive (file1); sprintf (file1, "%s/%s.%s", cddir, token, trifileext); time1 = FileTime (file1); if (time1 == -1) Error ("%s doesn't exist", file1); #endif // // load the base triangles // if (do3ds) Load3DSTriangleList (file1, &ptri, &model.num_tris, NULL, NULL); else LoadTriangleList (file1, &ptri, &model.num_tris, NULL, NULL); GetScriptToken (false); sprintf (file2, "%s/%s.pcx", cddir, token); // sprintf (trans_file, "%s/!%s_a.pcx", cddir, token); printf ("skin: %s\n", file2); Load256Image (file2, &BasePixels, &BasePalette, &BaseWidth, &BaseHeight); if (BaseWidth != SKINPAGE_WIDTH || BaseHeight != SKINPAGE_HEIGHT) { if (g_allow_newskin) { ScaleWidth = BaseWidth; ScaleHeight = BaseHeight; } else { Error("Invalid skin page size: (%d,%d) should be (%d,%d)", BaseWidth,BaseHeight,SKINPAGE_WIDTH,SKINPAGE_HEIGHT); } } else { ScaleWidth = (float)ExtractNumber(BasePixels, ENCODED_WIDTH_X, ENCODED_WIDTH_Y); ScaleHeight = (float)ExtractNumber(BasePixels, ENCODED_HEIGHT_X, ENCODED_HEIGHT_Y); } // // get the ST values // BuildST (ptri, model.num_tris,false); // // run through all the base triangles, storing each unique vertex in the // base vertex list and setting the indirect triangles to point to the base // vertices // for (i=0 ; i<model.num_tris ; i++) { for (j=0 ; j<3 ; j++) { // get the xyz index for (k=0 ; k<model.num_xyz ; k++) if (VectorCompare (ptri[i].verts[j], base_xyz[k])) break; // this vertex is already in the base vertex list if (k == model.num_xyz) { // new index VectorCopy (ptri[i].verts[j], base_xyz[model.num_xyz]); if(clustered) ReplaceClusterIndex(k, ptri[i].indicies[j], (int **)&clusters, (IntListNode_t **)&vertLists, (int *)&num_verts, (int *)&new_num_verts); model.num_xyz++; } triangles[i].index_xyz[j] = k; // get the st index for (k=0 ; k<model.num_st ; k++) if (triangle_st[i][j][0] == base_st[k].s && triangle_st[i][j][1] == base_st[k].t) break; // this vertex is already in the base vertex list if (k == model.num_st) { // new index base_st[model.num_st].s = triangle_st[i][j][0]; base_st[model.num_st].t = triangle_st[i][j][1]; model.num_st++; } triangles[i].index_st[j] = k; } } // build triangle strips / fans BuildGlCmds (); }