Source code for /engineering/rendsite/test/source/2XTILE/XCOMBINE.COriginal file XCOMBINE.C
   1 /*
   2 
   3 	XTile Combine Files utility
   4 
   5 	COPYRIGHT (C) 1993 Erich P  Gatejen
   6 
   7 */
   8 #include<stdlib.h>
   9 #include<stdio.h>
  10 #include<ctype.h>
  11 #include<string.h>
  12 
  13 
  14 /* ------ Globals -------------- */
  15    FILE *OutFile;
  16    FILE *ScriptFile;
  17    FILE *ReportFile;
  18 
  19    unsigned long  Start = 0;
  20    char	Buffer[81];	/* Script line buffer */
  21    char DefaultExt[81];
  22 
  23 
  24    void  DoFile(void);
  25 
  26 /* ------ Functions ------------ */
  27 void  DoFile( ) {
  28 
  29    FILE  *InFile;
  30    char   Name[81];	/* Extra room for errors */
  31    int	  Step = 0;
  32    long   Size;
  33    unsigned char	Byte;
  34    int    EXTFlag	=	0;
  35 
  36 
  37   /* Move name into Name buffer, up until whitespace */
  38   while ( !isspace(Buffer[Step]) ) {
  39 
  40      Name[Step] = Buffer[Step];
  41      if ( Name[Step] == '.' ) EXTFlag = 1; /* Set extension present flag */
  42      ++Step;
  43   }
  44 
  45   /* Pad NULL */
  46   Name[Step] = NULL;
  47 
  48   /* Add the default extension if none provided */
  49   if ( !EXTFlag ) strcat( Name, DefaultExt );
  50 
  51 
  52   /* Open the file */
  53    if ( (InFile = fopen( Name, "rb" )) == NULL ) {
  54       puts("\n\rCannot open file : ");
  55       puts(Name);
  56       puts(" in script!  Combine aborted.\n\rCombine file is corrupt!\n\r");
  57       fputs("!!!!!Combine corrupted!!!!!", ReportFile );
  58       exit(1);
  59    };
  60 
  61   /* Put report data */
  62   fprintf(ReportFile, "Item %12s starts at : %08li.\n", Name, Start );
  63 
  64   /* Copy Data */
  65 
  66   fread ( &Byte, sizeof( unsigned char ), 1, InFile );
  67   while ( !feof( InFile ) ) {
  68 
  69      fwrite( &Byte, sizeof( unsigned char ), 1, OutFile );
  70      ++Start;
  71      fread ( &Byte, sizeof( unsigned char ), 1, InFile );
  72   }
  73   fclose( InFile );
  74 
  75 }
  76 
  77 
  78 /* ------ Main ----------------- */
  79 void  main( int argn, char* argc[] ) {
  80 
  81    if ( argn == 1 ) {
  82 
  83      puts("\n\r...  XCOMBINE tool for the XTILE Graphics System  ...");
  84      puts    ("...       Copyright (C) Erich P Gatejen 1993      ...");
  85      puts("- Arguments : ");
  86      puts("  (1) Name of the script file.");
  87      puts("  (2) Name of the combine and report file.");
  88      puts("  (3) [Optional] Default extension (without this, it is .PIX). \n");
  89      exit(0);
  90    }
  91 
  92    /* is there right number of arg */
  93    if ( (argn != 3)&&(argn != 3)) {
  94       puts("\n\rBad number of arguments! -- !Program terminated\n\r");
  95       return;
  96    };
  97 
  98    /* Set Default extension.  If none is supplied it is ".PIX" */
  99    if ( argn == 3 ) strcpy( DefaultExt, ".PIX");
 100    else strcpy( DefaultExt, argc[3]);
 101 
 102 
 103   /* -------  Open script and output files ------ */
 104 
 105   /* Build script file name and open */
 106    strcpy( Buffer, argc[2] );
 107    strcat( Buffer, ".SCR"  );
 108    if ( (ScriptFile = fopen( Buffer, "rt" )) == NULL ) {
 109       puts("\n\rCannot open script file! -- !Program terminated\n\n\r");
 110       return;
 111    };
 112 
 113   /* Build report file name and open */
 114    strcpy( Buffer, argc[1] );
 115    strcat( Buffer, ".RPT"  );
 116    if ( (ReportFile = fopen( Buffer, "wt" )) == NULL ) {
 117       puts("\n\rCannot open report file! -- !Program terminated\n\n\r");
 118       return;
 119    };
 120 
 121    strcpy( Buffer, argc[1] );
 122    strcat( Buffer, ".CMB"  );
 123    if ( (OutFile = fopen( Buffer, "wb" )) == NULL ) {
 124       puts("\n\rCannot open combine file! -- !Program terminated\n\n\r");
 125       return;
 126    };
 127 
 128 
 129   /* -------  Process script file ----------- */
 130 
 131   /* Put header on report file */
 132    fputs( "---- Combine Report ------\n\r", ReportFile);
 133    fputs( " For combine file : ", ReportFile );
 134    fputs( Buffer, ReportFile );
 135    fputs( "\n\r", ReportFile );
 136 
 137   /* While not eof get script lines and process */
 138    while( !feof(ScriptFile) ) {
 139 
 140      fgets( Buffer, 81, ScriptFile );
 141 
 142      /* It may be a comment line(ignore), if not, process it */
 143      if ( (Buffer[0] != '/') && (!isspace(Buffer[0])) ) DoFile();
 144 
 145   } /* end while */
 146 
 147   /* ------  Clean up ----------------------- */
 148 
 149   /* Put report file tail */
 150   fputs("\n\r  Total file size : ", ReportFile );
 151   fprintf(ReportFile, "%08li. \n\r\n", Start );
 152 
 153   /* Close all files */
 154   fcloseall();
 155 
 156   /* Report combine done! */
 157   puts("....Combine done.  !!Successful!!\n");
 158 
 159 }