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> </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. 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. </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: (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> _chmod(Dest,1,FF_ARCH);<BR> =20
remove(Dest);<BR> }<BR> long FileSize, BytesEncrypted, =
Bytes2Encrypt;<BR><BR>=20
DTA files;<BR><BR> if ((FindFirst(Source,AttrMask,&files)))<BR> =
{<BR> =20
<STRONG>printf("(%s)",LSpace("0",12));<BR></STRONG>&n=
bsp;=20
cFailedFiles++;<BR> <STRONG>printf(", =
fail");<BR></STRONG> =20
return -1;<BR> }<BR><BR> FileSize =3D files.Size;<BR><BR>=20
<STRONG>printf("(%s)",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,"rb");<BR> if (SourceHandle =
=3D=3D NULL)<BR>=20
{<BR> <STRONG>printf(", fail");<BR></STRONG> =20
cFailedFiles++;<BR> cFailedBytes+=3D files.Size;<BR> return =
errno;<BR>=20
}<BR><BR> DestHandle =3D fopen(Dest,"wb");<BR> if (DestHandle =
=3D=3D=20
NULL)<BR> {<BR><STRONG> printf(", =
fail");<BR></STRONG> =20
fclose(SourceHandle);<BR> cFailedFiles++;<BR> =
cFailedBytes+=3D=20
files.Size;<BR> return errno;<BR> }<BR> if (FileSize)<BR> =
{<BR> for=20
(; ;)<BR> {<BR><STRONG> =20
printf(".");<BR> =20
//printf("%c\b",Cool[CurCool++]);<BR></STRONG> if=20
(CurCool=3D=3D8)<BR> {<BR> =
CurCool=3D0;<BR> =20
}<BR> BytesEncrypted +=3D (long) X_SIZE;<BR> if=20
(BytesEncrypted > FileSize)<BR> {<BR> =20
BytesEncrypted -=3D (long) X_SIZE;<BR> Bytes2Encrypt =
=3D=20
FileSize-BytesEncrypted;<BR> BytesEncrypted =3D =
BytesEncrypted=20
+=3D Bytes2Encrypt;<BR> }<BR> =
else<BR> =20
{<BR> Bytes2Encrypt =3D (long)X_SIZE;<BR> =20
}<BR><BR> unsigned int BytesProcessed=3D0;<BR> =20
BytesProcessed =3D fread(FileBuffer,(unsigned=20
int)Bytes2Encrypt,1,SourceHandle);<BR> if (BytesProcessed=20
!=3D1)<BR> {<BR> <STRONG>printf("=20
\b");<BR> printf(",=20
fail");<BR></STRONG> =20
fclose(SourceHandle);<BR> =20
fclose(DestHandle);<BR> =
cFailedFiles++;<BR> =20
cFailedBytes+=3D files.Size;<BR> return =
errno;<BR> =20
}<BR> =20
encryptX(FileBuffer,xPassword,(unsigned =
int)Bytes2Encrypt);<BR> =20
BytesProcessed=3Dfwrite(FileBuffer,(unsigned=20
int)Bytes2Encrypt,1,DestHandle);<BR> if (BytesProcessed=20
!=3D1)<BR> {<STRONG><BR> printf("=20
\b");<BR> printf(",=20
fail");<BR></STRONG> =20
fclose(SourceHandle);<BR> =20
fclose(DestHandle);<BR> =
cFailedFiles++;<BR> =20
cFailedBytes+=3D files.Size;<BR> return =
errno;<BR> =20
}<BR><BR> if (Bytes2Encrypt !=3D X_SIZE)<BR> =20
{<BR> break;<BR> }<BR> if=20
(BytesEncrypted =3D=3D FileSize)<BR> {<BR> =
break;<BR> }<BR> }<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("=20
\b");<BR> printf(", pass");<BR></STRONG> return=20
0;<BR>}<BR><BR>int doEncrypt(DTA files, char *source, char=20
*dest)<BR>{<BR> if (IsDir(source)) return;<BR> =20
FileNameStruct SourceFn;<BR> =20
ParseFileName(source,&SourceFn);<BR>/* if (dSearch)<BR> {<BR> =
int=20
Compd =3D fDateComp(files.Date,sDate);<BR><BR> switch=20
(dSearchMode)<BR> {<BR> case GreaterSearch: if =
(Compd =3D=3D=20
1) return 1; break;<BR> case LesserSearch: if (Compd =
=3D=3D -1)=20
return 1; break;<BR> case EqualSearch: if (Compd) =
return 1;=20
break;<BR> default: return 1;<BR> }<BR> }<BR> if =
(tSearch)<BR>=20
{<BR> int Compd =3D fTimeComp(files.Time,sTime);<BR><BR> =
switch=20
(tSearchMode)<BR> {<BR> case GreaterSearch: if =
(Compd =3D=3D=20
1) return 1; break;<BR> case LesserSearch: if (Compd =
=3D=3D -1)=20
return 1; break;<BR> case EqualSearch: if (Compd) =
return 1;=20
break;<BR> default: return 1;<BR> }<BR> }*/<BR>=20
<STRONG>printf("\n =20
%s",RSpace(files.Name,40));<BR></STRONG> =20
sprintf(dest,"%s%sQENC.TMP",SourceFn.Drive,SourceFn.Path);<BR> =
EncryptFile(source,dest);<BR> =
remove(source);<BR> =20
rename(dest,source);<BR> FilesEncrypted++;<BR> BytesEncrypted+=3D=20
files.Size;<BR>}<BR></FONT></BODY></HTML>
------=_NextPart_000_0003_01BCBFBC.9C567580--
- Raw text -