From: "Joshua Cannon Butcher" Newsgroups: comp.os.msdos.djgpp Subject: Please Help: Printf problem argv[] issues. LFN? Date: Fri, 12 Sep 1997 20:44:05 -0400 Organization: MindSpring Enterprises Lines: 348 Message-ID: <5vcnai$s2q@camel3.mindspring.com> NNTP-Posting-Host: user-2k7i8oi.dialup.mindspring.com Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0003_01BCBFBC.9C567580" To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk This is a multi-part message in MIME format. ------=_NextPart_000_0003_01BCBFBC.9C567580 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Before I write anything I am using RHIDE on Windows 95. I am writing a command line DOS utility and use a FOR command for = several tasks. While the for command is executing, I am using a printf = statement to update progress. This code was taken directly from a = similar utility I wrote with Borland C++. the printf in the for command = DOS NOT update on the screen until the for command is finished = executing, and all the progress shows up at once. Why? Also, if I use = GetCh() in CONIO.H and use printf to print a statement before the = GetCh(), it does not show the statement (prompt for input ifyou will) = until after the key is pressed. =20 Also, how do I stop my EXE file from automatically expanding wild card = file masks on the command line? And, is there a switch i can use to compile my program to automatically = look at LFN rather than having to set LFN=3Dy? As seen below I call the doEncrypt() function, and it in turn calls = EncryptFile, none of the printf() statements put output to the screen = until after the doEncrypt has finished printing. Example: (The BOLD portion of the code does not display until all of = this is finished. int EncryptFile(char *Source, char *Dest) { if (FileExists(Dest)) { _chmod(Dest,1,FF_ARCH); remove(Dest); } long FileSize, BytesEncrypted, Bytes2Encrypt; DTA files; if ((FindFirst(Source,AttrMask,&files))) { printf("(%s)",LSpace("0",12)); cFailedFiles++; printf(", fail"); return -1; } FileSize =3D files.Size; printf("(%s)",LSpace(sepr(files.Size),16)); BytesEncrypted =3D 0; FILE *SourceHandle, *DestHandle; SourceHandle =3D fopen(Source,"rb"); if (SourceHandle =3D=3D NULL) { printf(", fail"); cFailedFiles++; cFailedBytes+=3D files.Size; return errno; } DestHandle =3D fopen(Dest,"wb"); if (DestHandle =3D=3D NULL) { printf(", fail"); fclose(SourceHandle); cFailedFiles++; cFailedBytes+=3D files.Size; return errno; } if (FileSize) { for (; ;) { printf("."); //printf("%c\b",Cool[CurCool++]); if (CurCool=3D=3D8) { CurCool=3D0; } BytesEncrypted +=3D (long) X_SIZE; if (BytesEncrypted > FileSize) { BytesEncrypted -=3D (long) X_SIZE; Bytes2Encrypt =3D FileSize-BytesEncrypted; BytesEncrypted =3D BytesEncrypted +=3D Bytes2Encrypt; } else { Bytes2Encrypt =3D (long)X_SIZE; } unsigned int BytesProcessed=3D0; BytesProcessed =3D fread(FileBuffer,(unsigned = int)Bytes2Encrypt,1,SourceHandle); if (BytesProcessed !=3D1) { printf(" \b"); printf(", fail"); fclose(SourceHandle); fclose(DestHandle); cFailedFiles++; cFailedBytes+=3D files.Size; return errno; } encryptX(FileBuffer,xPassword,(unsigned int)Bytes2Encrypt); BytesProcessed=3Dfwrite(FileBuffer,(unsigned = int)Bytes2Encrypt,1,DestHandle); if (BytesProcessed !=3D1) { printf(" \b"); printf(", fail"); fclose(SourceHandle); fclose(DestHandle); cFailedFiles++; cFailedBytes+=3D files.Size; return errno; } if (Bytes2Encrypt !=3D X_SIZE) { break; } if (BytesEncrypted =3D=3D FileSize) { break; } } } SyncTimes(files.Time,files.Date,DestHandle); fclose(SourceHandle); fclose(DestHandle); _chmod(Dest,1,files.Attr); printf(" \b"); printf(", pass"); return 0; } int doEncrypt(DTA files, char *source, char *dest) { if (IsDir(source)) return; FileNameStruct SourceFn; ParseFileName(source,&SourceFn); /* if (dSearch) { int Compd =3D fDateComp(files.Date,sDate); switch (dSearchMode) { case GreaterSearch: if (Compd =3D=3D 1) return 1; break; case LesserSearch: if (Compd =3D=3D -1) return 1; break; case EqualSearch: if (Compd) return 1; break; default: return 1; } } if (tSearch) { int Compd =3D fTimeComp(files.Time,sTime); switch (tSearchMode) { case GreaterSearch: if (Compd =3D=3D 1) return 1; break; case LesserSearch: if (Compd =3D=3D -1) return 1; break; case EqualSearch: if (Compd) return 1; break; default: return 1; } }*/ printf("\n %s",RSpace(files.Name,40)); sprintf(dest,"%s%sQENC.TMP",SourceFn.Drive,SourceFn.Path); EncryptFile(source,dest); remove(source); rename(dest,source); FilesEncrypted++; BytesEncrypted+=3D files.Size; } ------=_NextPart_000_0003_01BCBFBC.9C567580 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Before I write anything I = am using=20 RHIDE on Windows 95. 

I am writing a command = line DOS utility=20 and use a FOR command for several tasks.  While the for command is=20 executing, I am using a printf statement to update progress.  This = code was=20 taken directly from a similar utility I wrote with Borland C++.  = the printf=20 in the for command DOS NOT update on the screen until the for command is = finished executing, and all the progress shows up at once.  = Why? =20 Also, if I use GetCh() in CONIO.H and use printf to print a statement = before the=20 GetCh(), it does not show the statement (prompt for input ifyou will) = until=20 after the key is pressed.  

Also, how do I stop my = EXE file from=20 automatically expanding wild card file masks on the command line?

And, is there a switch i = can use to=20 compile my program to automatically look at LFN rather than having to = set=20 LFN=3Dy?

As seen below I call the = doEncrypt()=20 function, and it in turn calls EncryptFile, none of the printf() = statements put=20 output to the screen until after the doEncrypt has finished = printing.

Example:  (The BOLD = portion of the=20 code does not display until all of this is finished.

int EncryptFile(char *Source, char = *Dest)
{

=20 if (FileExists(Dest))
{
  _chmod(Dest,1,FF_ARCH);
 =20 remove(Dest);
}
long FileSize, BytesEncrypted, = Bytes2Encrypt;

=20 DTA files;

if ((FindFirst(Source,AttrMask,&files)))
= {
 =20 printf("(%s)",LSpace("0",12));
&n= bsp;=20 cFailedFiles++;
  printf(", = fail");
 =20 return -1;
}

FileSize =3D files.Size;

=20 printf("(%s)",LSpace(sepr(files.Size),16));

=20 BytesEncrypted =3D 0;


FILE *SourceHandle, = *DestHandle;

=20 SourceHandle =3D fopen(Source,"rb");
if (SourceHandle = =3D=3D NULL)
=20 {
  printf(", fail");
 =20 cFailedFiles++;
  cFailedBytes+=3D files.Size;
  return = errno;
=20 }

DestHandle =3D fopen(Dest,"wb");
if (DestHandle = =3D=3D=20 NULL)
{
  printf(", = fail");
 =20 fclose(SourceHandle);
  cFailedFiles++;
  = cFailedBytes+=3D=20 files.Size;
  return errno;
}
if (FileSize)
= {
  for=20 (; ;)
  {
   =20 printf(".");
  =20 //printf("%c\b",Cool[CurCool++]);
   if=20 (CurCool=3D=3D8)
   {
    = CurCool=3D0;
  =20 }
   BytesEncrypted +=3D (long) X_SIZE;
   if=20 (BytesEncrypted > FileSize)
   {
   =20 BytesEncrypted -=3D (long) X_SIZE;
    Bytes2Encrypt = =3D=20 FileSize-BytesEncrypted;
    BytesEncrypted =3D = BytesEncrypted=20 +=3D Bytes2Encrypt;
   }
   = else
  =20 {
    Bytes2Encrypt =3D (long)X_SIZE;
  =20 }

   unsigned int BytesProcessed=3D0;
  =20 BytesProcessed =3D fread(FileBuffer,(unsigned=20 int)Bytes2Encrypt,1,SourceHandle);
   if (BytesProcessed=20 !=3D1)
   {
    printf("=20 \b");
    printf(",=20 fail");
   =20 fclose(SourceHandle);
   =20 fclose(DestHandle);
    = cFailedFiles++;
   =20 cFailedBytes+=3D files.Size;
    return = errno;
  =20 }
        =20 encryptX(FileBuffer,xPassword,(unsigned = int)Bytes2Encrypt);
  =20 BytesProcessed=3Dfwrite(FileBuffer,(unsigned=20 int)Bytes2Encrypt,1,DestHandle);
   if (BytesProcessed=20 !=3D1)
   {
    printf("=20 \b");
    printf(",=20 fail");
   =20 fclose(SourceHandle);
   =20 fclose(DestHandle);
    = cFailedFiles++;
   =20 cFailedBytes+=3D files.Size;
    return = errno;
  =20 }

   if (Bytes2Encrypt !=3D X_SIZE)
  =20 {
    break;
   }
   if=20 (BytesEncrypted =3D=3D FileSize)
   {
    = break;
   }
  }
}
=20 SyncTimes(files.Time,files.Date,DestHandle);
= fclose(SourceHandle);
=20 fclose(DestHandle);
_chmod(Dest,1,files.Attr);
= printf("=20 \b");
printf(", pass");
return=20 0;
}

int doEncrypt(DTA files, char *source, char=20 *dest)
{
   if (IsDir(source)) return;
  =20 FileNameStruct SourceFn;
  =20 ParseFileName(source,&SourceFn);
/* if (dSearch)
{
  = int=20 Compd =3D fDateComp(files.Date,sDate);

  switch=20 (dSearchMode)
  {
   case GreaterSearch:  if = (Compd =3D=3D=20 1) return 1; break;
   case LesserSearch:  if (Compd = =3D=3D -1)=20 return 1; break;
   case EqualSearch:  if (Compd) = return 1;=20 break;
   default: return 1;
  }
}
if = (tSearch)
=20 {
  int Compd =3D fTimeComp(files.Time,sTime);

  = switch=20 (tSearchMode)
  {
   case GreaterSearch:  if = (Compd =3D=3D=20 1) return 1; break;
   case LesserSearch:  if (Compd = =3D=3D -1)=20 return 1; break;
   case EqualSearch:  if (Compd) = return 1;=20 break;
   default: return 1;
  }
}*/
=20 printf("\n   =20 %s",RSpace(files.Name,40));
  =20 sprintf(dest,"%s%sQENC.TMP",SourceFn.Drive,SourceFn.Path);
= EncryptFile(source,dest);
   = remove(source);
  =20 rename(dest,source);
FilesEncrypted++;
BytesEncrypted+=3D=20 files.Size;
}
------=_NextPart_000_0003_01BCBFBC.9C567580--