/* 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, 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);
   fgets(inline, 256, infp1); if(strncmp(inline, ". ", 2)==0);
   fgets(inline, 256, infp1); if(strncmp(inline, "..", 2)==0);

   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);
   fgets(inline, 256, infp1); if(strncmp(inline, ". ", 2)==0);
   fgets(inline, 256, infp1); if(strncmp(inline, "..", 2)==0);

   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);
}