/* Pro136D.c */
/* Automatic generation of a pair of All fileNames[] = {}
	  Header file for DATE-TIME stamp erase AND 'diff' in C.     */
/* Read  'DIR.TXT'                           */
/*    This 'DIR.TXT' must be make Win95, Win98 or later.
	  Check there is a full name of directory at Column 45.
	  This one doesn't work if I make 'DIR-01.TXT' in Win3.1 .   */
/* Write 'HEADER.TXT' and
		 'OUT-HEAD.TXT'                         */
/* This C program is a variation of 'Pro136C.c' which automatically
	  generate DOS-Batch program after it captures Directory names.  */
/*
 *		   10        20        30        40        50
 * 1...5....0....5....0....5....0....5....0....5....0
 * KMAIL          <DIR>        04-27-04  1:07a KMAIL.003
 * TO-CD          <DIR>        04-29-04  6:13p TO-CD.005
 * Therefore, directory name Magic Number for memory is '44'.
 */

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

char inline [256];
char id [128];

extern char *firstwd (char *to, char *from);   /* Recycling Object 'firstwd()' */
extern char *first8orLess (char *to, char *from);    /* Modified Recycling Object */
/* OR */
// extern char *firstwd (char *, char *);


void main(void){
   FILE *infp1, *infp2, *outfp1, *outfp2;
   infp1=fopen("DIR.txt", "r");
   outfp1=fopen("HEADER.TXT", "w");

   printf("This makes header files for '4Eraser.exe' and '5Diff.exe'. They are, \n\n");
   printf("     'HEADER.TXT'   and \n");
   printf("     'OUT-HEAD.TXT'\n\n");
   printf("If they are not created, check if 'DIR.TXT' is in this temporary \n");
   printf("directory.\n");

   /* Here I eat first SEVEN lines, just lightly viewing, and eating. */
   /* The following FIVE lines are just beening eaten, because */
   /* When IF-loop is true (Continue); When IF-loop isn't true (Continue) */
   /* Thus, they are merely decorative effects. */
   fgets(inline, 256, infp1); if(strncmp(inline, "\n", 1)==0);
   fgets(inline, 256, infp1); if(strncmp(inline, " Volume in", 10)==0);
   fgets(inline, 256, infp1); if(strncmp(inline, " Volume Serial", 14)==0);
   fgets(inline, 256, infp1); if(strncmp(inline, " Directory of", 13)==0);
   fgets(inline, 256, infp1); if(strncmp(inline, "\n", 1)==0);
   /* The ROOT or SUB-FOLDER "DIR.TXT" Switch. */
   fgets(inline, 256, infp1); if(strncmp(inline, ". ", 2)==0)  /* ROOT: This one is the actual first inline data (or in ELSE-loop as I indicated) */
	  {
									   /* This is in the IF-loop of ".", ZIP's SUB-DIRECTORY "Dir.Txt" */
		  fgets(inline, 256, infp1);   /* Eat one more line of ".." */
		  fgets(inline, 256, infp1);   /* SUB-FOLDER:  This line is actual the first data line in IF-true loop, SUB-FOLDER case */
	  }else{                           /* ELSE implies NOT ".", likely ZIP's ROOT "Dir.Txt", so the before IF-loop's inline is still active. */
		  ;
	  }
   /* Now, DO the process immidiately since the first inline data is   */
   /* alread in the Pointer infp1.                                     */
   /* The following three lines are for the first data inline          */
   firstwd(id, &inline[44]);
   fprintf (outfp1, "     %s     \n", id);


   while(fgets(inline, 256, infp1)!=NULL){
		 if(strncmp(inline, "      ", 6)==0)break;      /* To deal the last two incoming lines */
		 firstwd(id, &inline[44]);
		 fprintf (outfp1, "     %s     \n", id);
   }
   fclose (infp1);
   fclose (outfp1);

/* ========  ANOTHER SET FOR OUTPUT FILE ============= */

   infp2=fopen("DIR.txt", "r");
   outfp2=fopen("OUT-Head.TXT", "w");

   /* Here I eat first SEVEN lines, recognizing. */
   fgets(inline, 256, infp1); if(strncmp(inline, "\n", 1)==0);
   fgets(inline, 256, infp1); if(strncmp(inline, " Volume in", 10)==0);
   fgets(inline, 256, infp1); if(strncmp(inline, " Volume Serial", 14)==0);
   fgets(inline, 256, infp1); if(strncmp(inline, " Directory of", 13)==0);
   fgets(inline, 256, infp1); if(strncmp(inline, "\n", 1)==0);
   /* The ROOT or SUB-FOLDER "DIR.TXT" Switch. */
   fgets(inline, 256, infp1); if(strncmp(inline, ". ", 2)==0)  /* ROOT: This one is the actual first inline data (or in ELSE-loop as I indicated) */
	  {
									   /* This is in the IF-loop of ".", ZIP's SUB-DIRECTORY "Dir.Txt" */
		  fgets(inline, 256, infp1);   /* Eat one more line of ".." */
		  fgets(inline, 256, infp1);   /* SUB-FOLDER:  This line is actual the first data line in IF-true loop, SUB-FOLDER case */
	  }else{                           /* ELSE implies NOT ".", likely ZIP's ROOT "Dir.Txt", so the before IF-loop's inline is still active. */
		  ;
	  }
   /* Now, DO the process immidiately since the first inline data is   */
   /* alread in the Pointer infp1.                                     */
   /* The following three lines are for the first data inline          */
   first8orLess(id, &inline[44]);
   fprintf (outfp2, "     %s     \n", id);


   while(fgets(inline, 256, infp2)!=NULL){
		 if(strncmp(inline, "      ", 6)==0)break;      /* To deal the last two incoming lines */
		 first8orLess(id, &inline[44]);
		 fprintf (outfp2, "     %s     \n", id);
   }
   fclose (infp2);
   fclose (outfp2);
}