projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix code to read from pipes to request only what it needs
[unix-history]
/
usr
/
src
/
usr.bin
/
pascal
/
px
/
int.c
diff --git
a/usr/src/usr.bin/pascal/px/int.c
b/usr/src/usr.bin/pascal/px/int.c
index
072e166
..
28e959b
100644
(file)
--- a/
usr/src/usr.bin/pascal/px/int.c
+++ b/
usr/src/usr.bin/pascal/px/int.c
@@
-24,11
+24,10
@@
main(ac,av)
{
register char *objprog, *file;
{
register char *objprog, *file;
- register long bytesread, block;
+ register long bytesread, b
ytestoread, b
lock;
register FILE *prog;
struct pxhdr pxhd;
# define pipe 3
register FILE *prog;
struct pxhdr pxhd;
# define pipe 3
-# define pipesize 4096
/*
* Initialize everything
/*
* Initialize everything
@@
-40,88
+39,73
@@
main(ac,av)
/*
* Determine how PX was invoked, and how to process the program
*/
/*
* Determine how PX was invoked, and how to process the program
*/
- if (_argv[0][0] == '-' && _argv[0][1] == 'o')
- {
+ if (_argv[0][0] == '-' && _argv[0][1] == 'o') {
file = &_argv[0][2];
_mode = PIX;
file = &_argv[0][2];
_mode = PIX;
- }
- else if (_argc <= 1)
- {
+ } else if (_argc <= 1) {
file = "obj";
_mode = PX;
file = "obj";
_mode = PX;
- }
- else if (_argv[1][0] != '-')
- {
+ } else if (_argv[1][0] != '-') {
file = _argv[1];
_mode = PX;
file = _argv[1];
_mode = PX;
- }
- else if (_argv[1][1] == 0)
- {
+ } else if (_argv[1][1] == 0) {
file = _argv[0];
_mode = PIPE;
_argc -= 1;
_argv[1] = _argv[0];
_argv = &_argv[1];
file = _argv[0];
_mode = PIPE;
_argc -= 1;
_argv[1] = _argv[0];
_argv = &_argv[1];
- }
- else
- {
+ } else {
fputs("Improper specification of object file to PX\n",stderr);
exit(1);
fputs("Improper specification of object file to PX\n",stderr);
exit(1);
-
}
+ }
\f
/*
* Process program header information
*/
\f
/*
* Process program header information
*/
- if (_mode == PIPE)
+ if (_mode == PIPE)
{
read(pipe,&pxhd,sizeof(struct pxhdr));
read(pipe,&pxhd,sizeof(struct pxhdr));
- else
- {
+ } else {
prog = fopen(file,"r");
prog = fopen(file,"r");
- if (prog == NULL)
- {
+ if (prog == NULL) {
perror(file);
exit(1);
perror(file);
exit(1);
-
}
+ }
fseek(prog,(long)(HEADER_BYTES-sizeof(struct pxhdr)),0);
fread(&pxhd,sizeof(struct pxhdr),1,prog);
fseek(prog,(long)(HEADER_BYTES-sizeof(struct pxhdr)),0);
fread(&pxhd,sizeof(struct pxhdr),1,prog);
- }
- if (pxhd.maketime < createtime)
- {
+ }
+ if (pxhd.maketime < createtime) {
fprintf(stderr,"%s is obsolete and must be recompiled\n",file);
exit(1);
fprintf(stderr,"%s is obsolete and must be recompiled\n",file);
exit(1);
- }
- if (pxhd.magicnum != MAGICNUM)
- {
+ }
+ if (pxhd.magicnum != MAGICNUM) {
fprintf(stderr,"%s is not a Pascal interpreter file\n",file);
exit(1);
fprintf(stderr,"%s is not a Pascal interpreter file\n",file);
exit(1);
-
}
+ }
\f
/*
* Load program into memory
*/
objprog = malloc((int)pxhd.objsize);
\f
/*
* Load program into memory
*/
objprog = malloc((int)pxhd.objsize);
- if (_mode == PIPE)
- {
+ if (_mode == PIPE)
{
+ bytestoread = pxhd.objsize;
bytesread = 0;
bytesread = 0;
- do
- {
- block = read(pipe,(int)(objprog+bytesread),pipesize);
- bytesread += block;
+ do {
+ block = read(pipe,(int)(objprog+bytesread),bytestoread);
+ if (block > 0) {
+ bytesread += block;
+ bytestoread -= block;
}
}
- while (block);
- }
- else
- {
+ } while (block > 0);
+ } else {
bytesread = fread(objprog,1,(int)pxhd.objsize,prog);
fclose(prog);
if (_mode == PIX)
unlink(file);
bytesread = fread(objprog,1,(int)pxhd.objsize,prog);
fclose(prog);
if (_mode == PIX)
unlink(file);
- }
- if (bytesread != pxhd.objsize)
- {
+ }
+ if (bytesread != pxhd.objsize) {
fprintf(stderr,"Read error occurred while loading %s\n",file);
exit(1);
fprintf(stderr,"Read error occurred while loading %s\n",file);
exit(1);
-
}
+ }
if (_mode == PIX)
fputs("Execution begins...\n",stderr);
/*
if (_mode == PIX)
fputs("Execution begins...\n",stderr);
/*