/
Crimson2/alias/
Crimson2/area.tmp/
Crimson2/area.tmp/AnomalySpaceDock/
Crimson2/area.tmp/AnomalyStation/
Crimson2/area.tmp/AntHill/
Crimson2/area.tmp/ArcticTerrarium/
Crimson2/area.tmp/BuilderCity/
Crimson2/area.tmp/Dungeon/
Crimson2/area.tmp/MiningDock/
Crimson2/area.tmp/PipeSystem/
Crimson2/area.tmp/RattArea/
Crimson2/area.tmp/RobotFactory/
Crimson2/area.tmp/SilverDale/
Crimson2/area.tmp/StarshipFearless/
Crimson2/area.tmp/StationConduits/
Crimson2/area.tmp/TerrariumAlpha/
Crimson2/area.tmp/TerrariumBeta/
Crimson2/area.tmp/TestArea/
Crimson2/area.tmp/Void/
Crimson2/area/
Crimson2/area/AnomalySpaceDock/
Crimson2/area/AnomalyStation/
Crimson2/area/MiningDock/
Crimson2/area/PipeSystem/
Crimson2/area/SilverDale/
Crimson2/area/StationConduits/
Crimson2/area/Void/
Crimson2/board/
Crimson2/clone/
Crimson2/lib/
Crimson2/mole/
Crimson2/mole/mole_src/HELP/
Crimson2/player/
Crimson2/util/
Crimson2/wldedit/
Crimson2/wldedit/res/
#define NULL  0
#define FALSE  0
#define TRUE  1

/* Use mallocs rather than a static sized buffer of 32k */
#define USE_MALLOC

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>


void main (int argc, char *argv[]) {

  long size = 0, carvedSize = 32768, i;
  FILE *theFile;                         
#ifdef USE_MALLOC
  unsigned char *buffer;
#else
  unsigned char buffer[32768];
#endif
  unsigned char c = 0;
  char name[15];

  /* setup stuff */
#ifdef USE_MALLOC
  buffer = (char *) malloc(carvedSize);
  if (!buffer) { printf("(initial malloc) Out of memory.. argh!\n"); exit(1); }
#endif
  if (argc < 3) {
    printf("Usage: strip <infile> <outfile>\n");
    exit(1);
  }


  /* read in the file */
  printf("Opening the file %s\n", argv[1]);
  if (!(theFile = fopen(argv[1], "rb"))) {
    printf("Error opening file\n");
    fclose(theFile);
    exit(1);
  }

  while (!feof(theFile)) {
    c = fgetc(theFile);
    if (feof(theFile))
      break;
    if (c > 127) c-=128;
    if ( ((c > 26) && (c < 127)) || c==9 ) {
      if (size >= carvedSize) {
#ifdef USE_MALLOC
        carvedSize *= 2;
        buffer = realloc(buffer, carvedSize);
        if (!buffer) { printf("(realloc) Out of memory.. argh!\n"); exit(1); }
#else
      printf("Out of memory.. argh!\n");
      exit(1);
#endif
      }
      buffer[size] = c;
      size++;
    }
  }

  /* make sure file isnt empty */
  if (size == 0) {
    printf("Empty input file!\n");
    fclose(theFile);
    exit(1);
  }
  fclose(theFile);


  /* write out the new file */
  printf("Opening the file %s\n", argv[2]);
  if (!(theFile = fopen(argv[2], "wb"))) {
    printf("Error opening file\n");
    fclose(theFile);
    exit(1);
  }
  for (i = 0; i<size; i++)
    fprintf(theFile, "%c", buffer[i]);
  printf("Wrote the file.\n");
  fclose(theFile);
#ifdef USE_MALLOC
  free(buffer);
#endif
}