/* Pro142B.c */
/* Pre_Adjust for PC_Dual, to Adjust Folders.    */
/*     This finds the Folder name change, even         */
/*     the change is just Upper-Lower case.            */
/*     Read   dir-zip.txt (ZIP_FLASH)                  */
/*     Read   dir-sdw.txt (SDW)                        */
/*     Write  RESULT.TXT                               */

/* This is case-sensitive.
 *       E:\>           dir /b /on >  A:\ dir-zip.txt (ZIP_FLASH)
 *       C:\1TO-CD\..\> dir /b /on >  A:\ dir-sdw.txt (SDW)
 *     in which, "/b"  is for Brief Directory name only.
 *               "/on" is for Alphabetical order.
 */


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

char oldLine01[1024];
char newLines[1024];


int main(void)
{
   char strPause[16];
   int i, j, iFlag;
   FILE *fp01, *fp02, *outfp;
   i=j=iFlag=0;

   fp01=fopen("dir-zip.txt", "r");
   outfp=fopen("result.txt", "w");

   printf("\n");
   printf("This \"0_ADJUST.EXE\" finds difference of folders (directories)\n");
   printf("It is convenient to run before running Dual scan program (1,2,3,4).\n");
   printf("Please use with \"SAMPLE-[12].TXT\" with your customization.\n\n");
   printf("    Read   dir-zip.txt (ZIP_FLASH)\n");
   printf("    Read   dir-sdw.txt (SDW)\n");
   printf("    Write  RESULT.TXT\n\n");
   printf("Type any character key and [ENTER] to close this message: ");
   scanf("%s", &strPause);


/* 1st While-Loop ======================================== */
   while(fgets(oldLine01, 1024, fp01)!=NULL)   /* Old-File Scrolling, but one by one, so to imagine that I named oldLine01 */
   {
		 fp02=fopen("dir-sdw.txt", "r");        /* ReFresh fp02-Pointer to the beginning each time */
/* 2nd While-Loop ========================================= */
		 while(fgets(newLines, 1024, fp02)!=NULL)     /* New-File Scrolling, all lines, so I named newLines */
		 {
			if(strcmp(oldLine01, newLines)==0)
			{
			   fprintf(outfp, "I found the same one in sdwFile:  %s", oldLine01);
			   iFlag=1;        /* Found */
			   break;         /* No more scanning for this oldLine03 */
			}else
			   j++;       /* This 2nd While-Loop ran Repeatedly for each oldLine03 */
		 }
		 if(iFlag==0){
			   fprintf(outfp, "I didn't find the same one in sdwFile:  %s", oldLine01);
		 }
		 iFlag=0;    /* reset to Not-found yet */
		 fclose(fp02);
		 i++;

/* END of 2nd While-Loop, back to 1st While-Loop ============= */
   }
   fprintf(outfp, "\nLine-number of zipFild is about %d.", i);
   fprintf(outfp, "\nRepeatedly Scanned Line-number of sdwFile is about %d.", j);
   fclose(fp01);
   fclose(fp02);
   fclose(outfp);
   return (0);
}