delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/12/21:47:46

From: "Joshua Cannon Butcher" <lchandar AT mindspring DOT com>
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
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.71.1008.3"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#a0a0a4>
<P><FONT color=3D#000000 face=3DArial size=3D2>Before I write anything I =
am using=20
RHIDE on Windows 95.</FONT>&nbsp;</P>
<P><FONT color=3D#000000 face=3DArial size=3D2>I am writing a command =
line DOS utility=20
and use a FOR command for several tasks.&nbsp; While the for command is=20
executing, I am using a printf statement to update progress.&nbsp; This =
code was=20
taken directly from a similar utility I wrote with Borland C++.&nbsp; =
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.&nbsp; =
Why?&nbsp;=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.&nbsp;&nbsp;</FONT>
<P><FONT color=3D#000000 face=3DArial size=3D2>Also, how do I stop my =
EXE file from=20
automatically expanding wild card file masks on the command line?</FONT>
<P><FONT color=3D#000000 face=3DArial size=3D2>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?</FONT>
<P><FONT color=3D#000000 face=3DArial size=3D2>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.</FONT>
<P><FONT color=3D#000000 face=3DArial size=3D2>Example:&nbsp; (The BOLD =
portion of the=20
code does not display until all of this is finished.</FONT>
<P><FONT face=3D"" size=3D1>int EncryptFile(char *Source, char =
*Dest)<BR>{<BR><BR>=20
if (FileExists(Dest))<BR> {<BR>&nbsp; _chmod(Dest,1,FF_ARCH);<BR>&nbsp;=20
remove(Dest);<BR> }<BR> long FileSize, BytesEncrypted, =
Bytes2Encrypt;<BR><BR>=20
DTA files;<BR><BR> if ((FindFirst(Source,AttrMask,&amp;files)))<BR> =
{<BR>&nbsp;=20
<STRONG>printf(&quot;(%s)&quot;,LSpace(&quot;0&quot;,12));<BR></STRONG>&n=
bsp;=20
cFailedFiles++;<BR>&nbsp; <STRONG>printf(&quot;, =
fail&quot;);<BR></STRONG>&nbsp;=20
return -1;<BR> }<BR><BR> FileSize =3D files.Size;<BR><BR>=20
<STRONG>printf(&quot;(%s)&quot;,LSpace(sepr(files.Size),16));<BR></STRONG=
><BR>=20
BytesEncrypted =3D 0;<BR><BR><BR> FILE *SourceHandle, =
*DestHandle;<BR><BR>=20
SourceHandle =3D fopen(Source,&quot;rb&quot;);<BR> if (SourceHandle =
=3D=3D NULL)<BR>=20
{<BR>&nbsp; <STRONG>printf(&quot;, fail&quot;);<BR></STRONG>&nbsp;=20
cFailedFiles++;<BR>&nbsp; cFailedBytes+=3D files.Size;<BR>&nbsp; return =
errno;<BR>=20
}<BR><BR> DestHandle =3D fopen(Dest,&quot;wb&quot;);<BR> if (DestHandle =
=3D=3D=20
NULL)<BR> {<BR><STRONG>&nbsp; printf(&quot;, =
fail&quot;);<BR></STRONG>&nbsp;=20
fclose(SourceHandle);<BR>&nbsp; cFailedFiles++;<BR>&nbsp; =
cFailedBytes+=3D=20
files.Size;<BR>&nbsp; return errno;<BR> }<BR> if (FileSize)<BR> =
{<BR>&nbsp; for=20
(; ;)<BR>&nbsp; {<BR><STRONG>&nbsp;&nbsp;&nbsp;=20
printf(&quot;.&quot;);<BR>&nbsp;&nbsp;=20
//printf(&quot;%c\b&quot;,Cool[CurCool++]);<BR></STRONG>&nbsp;&nbsp; if=20
(CurCool=3D=3D8)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; =
CurCool=3D0;<BR>&nbsp;&nbsp;=20
}<BR>&nbsp;&nbsp; BytesEncrypted +=3D (long) X_SIZE;<BR>&nbsp;&nbsp; if=20
(BytesEncrypted &gt; FileSize)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;=20
BytesEncrypted -=3D (long) X_SIZE;<BR>&nbsp;&nbsp;&nbsp; Bytes2Encrypt =
=3D=20
FileSize-BytesEncrypted;<BR>&nbsp;&nbsp;&nbsp; BytesEncrypted =3D =
BytesEncrypted=20
+=3D Bytes2Encrypt;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; =
else<BR>&nbsp;&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp; Bytes2Encrypt =3D (long)X_SIZE;<BR>&nbsp;&nbsp;=20
}<BR><BR>&nbsp;&nbsp; unsigned int BytesProcessed=3D0;<BR>&nbsp;&nbsp;=20
BytesProcessed =3D fread(FileBuffer,(unsigned=20
int)Bytes2Encrypt,1,SourceHandle);<BR>&nbsp;&nbsp; if (BytesProcessed=20
!=3D1)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; <STRONG>printf(&quot;=20
\b&quot;);<BR>&nbsp;&nbsp;&nbsp; printf(&quot;,=20
fail&quot;);<BR></STRONG>&nbsp;&nbsp;&nbsp;=20
fclose(SourceHandle);<BR>&nbsp;&nbsp;&nbsp;=20
fclose(DestHandle);<BR>&nbsp;&nbsp;&nbsp; =
cFailedFiles++;<BR>&nbsp;&nbsp;&nbsp;=20
cFailedBytes+=3D files.Size;<BR>&nbsp;&nbsp;&nbsp; return =
errno;<BR>&nbsp;&nbsp;=20
}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
encryptX(FileBuffer,xPassword,(unsigned =
int)Bytes2Encrypt);<BR>&nbsp;&nbsp;=20
BytesProcessed=3Dfwrite(FileBuffer,(unsigned=20
int)Bytes2Encrypt,1,DestHandle);<BR>&nbsp;&nbsp; if (BytesProcessed=20
!=3D1)<BR>&nbsp;&nbsp; {<STRONG><BR>&nbsp;&nbsp;&nbsp; printf(&quot;=20
\b&quot;);<BR>&nbsp;&nbsp;&nbsp; printf(&quot;,=20
fail&quot;);<BR></STRONG>&nbsp;&nbsp;&nbsp;=20
fclose(SourceHandle);<BR>&nbsp;&nbsp;&nbsp;=20
fclose(DestHandle);<BR>&nbsp;&nbsp;&nbsp; =
cFailedFiles++;<BR>&nbsp;&nbsp;&nbsp;=20
cFailedBytes+=3D files.Size;<BR>&nbsp;&nbsp;&nbsp; return =
errno;<BR>&nbsp;&nbsp;=20
}<BR><BR>&nbsp;&nbsp; if (Bytes2Encrypt !=3D X_SIZE)<BR>&nbsp;&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; if=20
(BytesEncrypted =3D=3D FileSize)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; =

break;<BR>&nbsp;&nbsp; }<BR>&nbsp; }<BR> }<BR>=20
SyncTimes(files.Time,files.Date,DestHandle);<BR> =
fclose(SourceHandle);<BR>=20
fclose(DestHandle);<BR> _chmod(Dest,1,files.Attr);<BR> =
<STRONG>printf(&quot;=20
\b&quot;);<BR> printf(&quot;, pass&quot;);<BR></STRONG> return=20
0;<BR>}<BR><BR>int doEncrypt(DTA files, char *source, char=20
*dest)<BR>{<BR>&nbsp;&nbsp; if (IsDir(source)) return;<BR>&nbsp;&nbsp;=20
FileNameStruct SourceFn;<BR>&nbsp;&nbsp;=20
ParseFileName(source,&amp;SourceFn);<BR>/* if (dSearch)<BR> {<BR>&nbsp; =
int=20
Compd =3D fDateComp(files.Date,sDate);<BR><BR>&nbsp; switch=20
(dSearchMode)<BR>&nbsp; {<BR>&nbsp;&nbsp; case GreaterSearch:&nbsp; if =
(Compd =3D=3D=20
1) return 1; break;<BR>&nbsp;&nbsp; case LesserSearch:&nbsp; if (Compd =
=3D=3D -1)=20
return 1; break;<BR>&nbsp;&nbsp; case EqualSearch:&nbsp; if (Compd) =
return 1;=20
break;<BR>&nbsp;&nbsp; default: return 1;<BR>&nbsp; }<BR> }<BR> if =
(tSearch)<BR>=20
{<BR>&nbsp; int Compd =3D fTimeComp(files.Time,sTime);<BR><BR>&nbsp; =
switch=20
(tSearchMode)<BR>&nbsp; {<BR>&nbsp;&nbsp; case GreaterSearch:&nbsp; if =
(Compd =3D=3D=20
1) return 1; break;<BR>&nbsp;&nbsp; case LesserSearch:&nbsp; if (Compd =
=3D=3D -1)=20
return 1; break;<BR>&nbsp;&nbsp; case EqualSearch:&nbsp; if (Compd) =
return 1;=20
break;<BR>&nbsp;&nbsp; default: return 1;<BR>&nbsp; }<BR> }*/<BR>=20
<STRONG>printf(&quot;\n&nbsp;&nbsp;&nbsp;=20
%s&quot;,RSpace(files.Name,40));<BR></STRONG>&nbsp;&nbsp;=20
sprintf(dest,&quot;%s%sQENC.TMP&quot;,SourceFn.Drive,SourceFn.Path);<BR> =

EncryptFile(source,dest);<BR>&nbsp;&nbsp; =
remove(source);<BR>&nbsp;&nbsp;=20
rename(dest,source);<BR> FilesEncrypted++;<BR> BytesEncrypted+=3D=20
files.Size;<BR>}<BR></FONT></BODY></HTML>

------=_NextPart_000_0003_01BCBFBC.9C567580--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019