From 871d3b3da6c84be394963d1f5a41de12bfc5a2bc Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 20 Sep 2008 21:48:37 +0000 Subject: Remove bits from heretic/m_misc.c that are in common; change V_ScreenShot to take a format string describing the format of the filename for the screen shot file. Subversion-branch: /branches/raven-branch Subversion-revision: 1255 --- src/heretic/m_misc.c | 331 +-------------------------------------------------- 1 file changed, 1 insertion(+), 330 deletions(-) (limited to 'src/heretic/m_misc.c') diff --git a/src/heretic/m_misc.c b/src/heretic/m_misc.c index fe969f4c..64ad555f 100644 --- a/src/heretic/m_misc.c +++ b/src/heretic/m_misc.c @@ -33,11 +33,9 @@ #include "doomdef.h" #include "i_swap.h" #include "i_video.h" +#include "m_argv.h" #include "s_sound.h" -int myargc; -char **myargv; - //--------------------------------------------------------------------------- // // FUNC M_ValidEpisodeMap @@ -88,33 +86,6 @@ boolean M_ValidEpisodeMap(int episode, int map) return true; } -/* -================= -= -= M_CheckParm -= -= Checks for the given parameter in the program's command line arguments -= -= Returns the argument number (1 to argc-1) or 0 if not present -= -================= -*/ - -int M_CheckParm(char *check) -{ - int i; - - for (i = 1; i < myargc; i++) - { - if (!strcasecmp(check, myargv[i])) - return i; - } - - return 0; -} - - - /* =============== = @@ -185,151 +156,6 @@ void M_AddToBox(fixed_t * box, fixed_t x, fixed_t y) box[BOXTOP] = y; } - - -/* -================== -= -= M_WriteFile -= -================== -*/ - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -boolean M_WriteFile(char const *name, void *source, int length) -{ - int handle, count; - - handle = open(name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); - if (handle == -1) - return false; - count = write(handle, source, length); - close(handle); - - if (count < length) - return false; - - return true; -} - - -/* -================== -= -= M_ReadFile -= -================== -*/ - -int M_ReadFile(char const *name, byte ** buffer) -{ - int handle, count, length; - struct stat fileinfo; - byte *buf; - - handle = open(name, O_RDONLY | O_BINARY, 0666); - if (handle == -1) - I_Error("Couldn't read file %s", name); - if (fstat(handle, &fileinfo) == -1) - I_Error("Couldn't read file %s", name); - length = fileinfo.st_size; - buf = Z_Malloc(length, PU_STATIC, NULL); - count = read(handle, buf, length); - close(handle); - - if (count < length) - I_Error("Couldn't read file %s", name); - - *buffer = buf; - return length; -} - -//--------------------------------------------------------------------------- -// -// PROC M_FindResponseFile -// -//--------------------------------------------------------------------------- - -#define MAXARGVS 100 - -void M_FindResponseFile(void) -{ - int i; - - for (i = 1; i < myargc; i++) - { - if (myargv[i][0] == '@') - { - FILE *handle; - int size; - int k; - int index; - int indexinfile; - char *infile; - char *file; - char *moreargs[20]; - char *firstargv; - - // READ THE RESPONSE FILE INTO MEMORY - handle = fopen(&myargv[i][1], "rb"); - if (!handle) - { - printf("\nNo such response file!"); - exit(1); - } - printf("Found response file %s!\n", &myargv[i][1]); - fseek(handle, 0, SEEK_END); - size = ftell(handle); - fseek(handle, 0, SEEK_SET); - file = malloc(size); - fread(file, size, 1, handle); - fclose(handle); - - // KEEP ALL CMDLINE ARGS FOLLOWING @RESPONSEFILE ARG - for (index = 0, k = i + 1; k < myargc; k++) - moreargs[index++] = myargv[k]; - - firstargv = myargv[0]; - myargv = malloc(sizeof(char *) * MAXARGVS); - memset(myargv, 0, sizeof(char *) * MAXARGVS); - myargv[0] = firstargv; - - infile = file; - indexinfile = k = 0; - indexinfile++; // SKIP PAST ARGV[0] (KEEP IT) - do - { - myargv[indexinfile++] = infile + k; - while (k < size && - ((*(infile + k) >= ' ' + 1) && (*(infile + k) <= 'z'))) - k++; - *(infile + k) = 0; - while (k < size && - ((*(infile + k) <= ' ') || (*(infile + k) > 'z'))) - k++; - } - while (k < size); - - for (k = 0; k < index; k++) - myargv[indexinfile++] = moreargs[k]; - myargc = indexinfile; - // DISPLAY ARGS - if (M_CheckParm("-debug")) - { - printf("%d command-line args:\n", myargc); - for (k = 1; k < myargc; k++) - { - printf("%s\n", myargv[k]); - } - } - break; - } - } -} - //--------------------------------------------------------------------------- // // PROC M_ForceUppercase @@ -661,158 +487,3 @@ void M_LoadDefaults(void) #endif } - -/* -============================================================================== - - SCREEN SHOTS - -============================================================================== -*/ - - -typedef struct -{ - char manufacturer; - char version; - char encoding; - char bits_per_pixel; - unsigned short xmin, ymin, xmax, ymax; - unsigned short hres, vres; - unsigned char palette[48]; - char reserved; - char color_planes; - unsigned short bytes_per_line; - unsigned short palette_type; - char filler[58]; - unsigned char data; // unbounded -} pcx_t; - -/* -============== -= -= WritePCXfile -= -============== -*/ - -void WritePCXfile(char *filename, byte * data, int width, int height, - byte * palette) -{ - int i, length; - pcx_t *pcx; - byte *pack; - - pcx = Z_Malloc(width * height * 2 + 1000, PU_STATIC, NULL); - - pcx->manufacturer = 0x0a; // PCX id - pcx->version = 5; // 256 color - pcx->encoding = 1; // uncompressed - pcx->bits_per_pixel = 8; // 256 color - pcx->xmin = 0; - pcx->ymin = 0; - pcx->xmax = SHORT(width - 1); - pcx->ymax = SHORT(height - 1); - pcx->hres = SHORT(width); - pcx->vres = SHORT(height); - memset(pcx->palette, 0, sizeof(pcx->palette)); - pcx->color_planes = 1; // chunky image - pcx->bytes_per_line = SHORT(width); - pcx->palette_type = SHORT(2); // not a grey scale - memset(pcx->filler, 0, sizeof(pcx->filler)); - -// -// pack the image -// - pack = &pcx->data; - - for (i = 0; i < width * height; i++) - if ((*data & 0xc0) != 0xc0) - *pack++ = *data++; - else - { - *pack++ = 0xc1; - *pack++ = *data++; - } - -// -// write the palette -// - *pack++ = 0x0c; // palette ID byte - for (i = 0; i < 768; i++) - *pack++ = *palette++; - -// -// write output file -// - length = pack - (byte *) pcx; - M_WriteFile(filename, pcx, length); - - Z_Free(pcx); -} - - -//============================================================================== - -/* -================== -= -= M_ScreenShot -= -================== -*/ - -void M_ScreenShot(void) -{ - int i; - byte *linear; - char lbmname[12]; - byte *pal; - -#ifdef _WATCOMC_ - extern byte *pcscreen; -#endif -// -// munge planar buffer to linear -// -#ifdef _WATCOMC_ - linear = pcscreen; -#else - linear = I_VideoBuffer; -#endif -// -// find a file name to save it to -// - strcpy(lbmname, "HRTIC00.pcx"); - - for (i = 0; i <= 99; i++) - { - lbmname[5] = i / 10 + '0'; - lbmname[6] = i % 10 + '0'; - if (access(lbmname, 0) == -1) - break; // file doesn't exist - } - if (i == 100) - I_Error("M_ScreenShot: Couldn't create a PCX"); - -// -// save the pcx file -// -#ifdef __WATCOMC__ - pal = (byte *) Z_Malloc(768, PU_STATIC, NULL); - outp(0x3c7, 0); - for (i = 0; i < 768; i++) - { - *(pal + i) = inp(0x3c9) << 2; - } -#else - pal = (byte *) W_CacheLumpName("PLAYPAL", PU_CACHE); -#endif - - WritePCXfile(lbmname, linear, SCREENWIDTH, SCREENHEIGHT, pal); - - players[consoleplayer].message = "SCREEN SHOT"; -#ifdef __WATCOMC__ - Z_Free(pal); -#endif -} -- cgit v1.2.3