version 1.28, 2009/10/27 23:59:41 |
version 1.29, 2010/08/17 21:37:11 |
|
|
int ips; |
int ips; |
int ops; |
int ops; |
int cps; |
int cps; |
char *obuf; |
char *obuf = NULL; |
char *lbuf; |
char *lbuf; |
char *nbuf; |
char *nbuf; |
char *hbuf; |
char *hbuf = NULL; |
char *ohbuf; |
char *ohbuf; |
FILE *inf; |
FILE *inf; |
char *fname; |
char *fname; |
int mor; |
int mor; |
|
int error = 1; |
|
|
if (nmwd) |
if (nmwd) |
num = nmwd + 1; |
num = nmwd + 1; |
|
|
/* |
/* |
* allocate line buffer |
* allocate line buffer |
*/ |
*/ |
if ((obuf = malloc((unsigned)LBUF + off)) == NULL) { |
if ((obuf = malloc((unsigned)(LBUF + off)*sizeof(char))) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
|
|
/* |
/* |
* allocate header buffer |
* allocate header buffer |
*/ |
*/ |
if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) { |
if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
|
|
ohbuf = hbuf + offst; |
ohbuf = hbuf + offst; |
nbuf = obuf + offst; |
nbuf = obuf + offst; |
|
|
if (cnt >= 0) { |
if (cnt >= 0) { |
if (!lrgln) |
if (!lrgln) |
if (!linecnt && prhead(hbuf, fname, ++pagecnt)) |
if (!linecnt && prhead(hbuf, fname, ++pagecnt)) |
return(1); |
goto out; |
|
|
/* |
/* |
* start new line or continue a long one |
* start new line or continue a long one |
|
|
if (num) |
if (num) |
addnum(nbuf, num, ++lncnt); |
addnum(nbuf, num, ++lncnt); |
if (otln(obuf,cnt+off, &ips, &ops, mor)) |
if (otln(obuf,cnt+off, &ips, &ops, mor)) |
return(1); |
goto out; |
} else |
} else |
if (otln(lbuf, cnt, &ips, &ops, mor)) |
if (otln(lbuf, cnt, &ips, &ops, mor)) |
return(1); |
goto out; |
|
|
/* |
/* |
* if line bigger than buffer, get more |
* if line bigger than buffer, get more |
|
|
* fill to end of page |
* fill to end of page |
*/ |
*/ |
if (prtail(lines - linecnt, lrgln)) |
if (prtail(lines - linecnt, lrgln)) |
return(1); |
goto out; |
|
|
/* |
/* |
* unless END continue |
* unless END continue |
|
|
/* |
/* |
* If we didn't process all the files, return error |
* If we didn't process all the files, return error |
*/ |
*/ |
if (eoptind < argc) |
if (eoptind < argc) { |
return(1); |
goto out; |
else |
} else { |
return(0); |
error = 0; |
|
goto out; |
|
} |
|
|
|
oomem: |
|
mfail(); |
|
out: |
|
free(obuf); |
|
free(hbuf); |
|
if (inf != NULL && inf != stdin) |
|
(void)fclose(inf); |
|
return error; |
} |
} |
|
|
/* |
/* |
|
|
vertcol(int argc, char *argv[]) |
vertcol(int argc, char *argv[]) |
{ |
{ |
char *ptbf; |
char *ptbf; |
char **lstdat; |
char **lstdat = NULL; |
int i; |
int i; |
int j; |
int j; |
int pln; |
int pln; |
int *indy; |
int *indy = NULL; |
int cnt; |
int cnt; |
int rc; |
int rc; |
int cvc; |
int cvc; |
int *lindy; |
int *lindy = NULL; |
int lncnt; |
int lncnt; |
int stp; |
int stp; |
int pagecnt; |
int pagecnt; |
int col = colwd + 1; |
int col = colwd + 1; |
int mxlen = pgwd + offst + 1; |
int mxlen = pgwd + offst + 1; |
int mclcnt = clcnt - 1; |
int mclcnt = clcnt - 1; |
struct vcol *vc; |
struct vcol *vc = NULL; |
int mvc; |
int mvc; |
int tvc; |
int tvc; |
int cw = nmwd + 1; |
int cw = nmwd + 1; |
int fullcol; |
int fullcol; |
char *buf; |
char *buf = NULL; |
char *hbuf; |
char *hbuf = NULL; |
char *ohbuf; |
char *ohbuf; |
char *fname; |
char *fname; |
FILE *inf; |
FILE *inf = NULL; |
int ips = 0; |
int ips = 0; |
int cps = 0; |
int cps = 0; |
int ops = 0; |
int ops = 0; |
int mor = 0; |
int mor = 0; |
|
int error = 1; |
|
|
/* |
/* |
* allocate page buffer |
* allocate page buffer |
*/ |
*/ |
if ((buf = calloc((unsigned)lines, mxlen)) == NULL) { |
if ((buf = calloc((unsigned)lines, mxlen)) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
|
|
/* |
/* |
* allocate page header |
* allocate page header |
*/ |
*/ |
if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) { |
if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
|
|
ohbuf = hbuf + offst; |
ohbuf = hbuf + offst; |
if (offst) |
if (offst) |
|
|
* col pointers when no headers |
* col pointers when no headers |
*/ |
*/ |
mvc = lines * clcnt; |
mvc = lines * clcnt; |
if ((vc=(struct vcol *)calloc((unsigned)mvc, sizeof(struct vcol))) == NULL) { |
if ((vc=(struct vcol *)calloc((unsigned)mvc, sizeof(struct vcol))) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
|
|
/* |
/* |
* pointer into page where last data per line is located |
* pointer into page where last data per line is located |
*/ |
*/ |
if ((lstdat = (char **)calloc((unsigned)lines, sizeof(char *))) == NULL){ |
if ((lstdat = (char **)calloc((unsigned)lines, sizeof(char *))) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
|
|
/* |
/* |
* fast index lookups to locate start of lines |
* fast index lookups to locate start of lines |
*/ |
*/ |
if ((indy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL) { |
if ((indy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL) |
mfail(); |
goto oomem; |
return(1); |
if ((lindy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL) |
} |
goto oomem; |
if ((lindy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL) { |
|
mfail(); |
|
return(1); |
|
} |
|
|
|
if (nmwd) |
if (nmwd) |
fullcol = col + cw; |
fullcol = col + cw; |
|
|
*/ |
*/ |
if (vc[0].cnt >= 0) { |
if (vc[0].cnt >= 0) { |
if (prhead(hbuf, fname, ++pagecnt)) |
if (prhead(hbuf, fname, ++pagecnt)) |
return(1); |
goto out; |
|
|
/* |
/* |
* check to see if "last" page needs to be reordered |
* check to see if "last" page needs to be reordered |
|
|
ips = 0; |
ips = 0; |
ops = 0; |
ops = 0; |
if (offst && otln(buf,offst,&ips,&ops,1)) |
if (offst && otln(buf,offst,&ips,&ops,1)) |
return(1); |
goto out; |
tvc = i; |
tvc = i; |
|
|
for (j = 0; j < clcnt; ++j) { |
for (j = 0; j < clcnt; ++j) { |
|
|
cnt = fullcol; |
cnt = fullcol; |
|
|
if (otln(vc[tvc].pt, cnt, &ips, &ops, 1)) |
if (otln(vc[tvc].pt, cnt, &ips, &ops, 1)) |
return(1); |
goto out; |
tvc += pln; |
tvc += pln; |
if (tvc > cvc) |
if (tvc > cvc) |
break; |
break; |
|
|
* terminate line |
* terminate line |
*/ |
*/ |
if (otln(buf, 0, &ips, &ops, 0)) |
if (otln(buf, 0, &ips, &ops, 0)) |
return(1); |
goto out; |
} |
} |
|
|
} else { |
} else { |
|
|
ips = 0; |
ips = 0; |
ops = 0; |
ops = 0; |
if (otln(ptbf, j, &ips, &ops, 0)) |
if (otln(ptbf, j, &ips, &ops, 0)) |
return(1); |
goto out; |
} |
} |
} |
} |
} |
} |
|
|
* pad to end of page |
* pad to end of page |
*/ |
*/ |
if (prtail((lines - pln), 0)) |
if (prtail((lines - pln), 0)) |
return(1); |
goto out; |
|
|
/* |
/* |
* if FORM continue |
* if FORM continue |
|
|
(void)fclose(inf); |
(void)fclose(inf); |
} |
} |
|
|
if (eoptind < argc) |
if (eoptind < argc){ |
return(1); |
goto out; |
else |
} else { |
return(0); |
error = 0; |
|
goto out; |
|
} |
|
|
|
oomem: |
|
mfail(); |
|
out: |
|
free(buf); |
|
free(hbuf); |
|
free(vc); |
|
free(lstdat); |
|
free(lindy); |
|
if (inf != NULL && inf != stdin) |
|
(void)fclose(inf); |
|
return error; |
|
|
} |
} |
|
|
/* |
/* |
|
|
int rc; |
int rc; |
int lncnt; |
int lncnt; |
int pagecnt; |
int pagecnt; |
char *buf; |
char *buf = NULL; |
char *hbuf; |
char *hbuf = NULL; |
char *ohbuf; |
char *ohbuf; |
char *fname; |
char *fname; |
FILE *inf; |
FILE *inf = NULL; |
int cps = 0; |
int cps = 0; |
int mor = 0; |
int mor = 0; |
int ips = 0; |
int ips = 0; |
int ops = 0; |
int ops = 0; |
|
int error = 1; |
|
|
if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL) { |
if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
|
|
/* |
/* |
* page header |
* page header |
*/ |
*/ |
if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) { |
if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
|
|
ohbuf = hbuf + offst; |
ohbuf = hbuf + offst; |
if (offst) { |
if (offst) { |
|
|
rc = inln(inf,ptbf,colwd,&cnt,&cps,1, &mor); |
rc = inln(inf,ptbf,colwd,&cnt,&cps,1, &mor); |
if (cnt >= 0) { |
if (cnt >= 0) { |
if (!i && !j && prhead(hbuf, fname, ++pagecnt)) |
if (!i && !j && prhead(hbuf, fname, ++pagecnt)) |
return(1); |
goto out; |
|
|
ptbf += cnt; |
ptbf += cnt; |
lstdat = ptbf; |
lstdat = ptbf; |
|
|
*/ |
*/ |
if (j) { |
if (j) { |
if (otln(buf, lstdat-buf, &ips, &ops, 0)) |
if (otln(buf, lstdat-buf, &ips, &ops, 0)) |
return(1); |
goto out; |
} |
} |
|
|
if (rc != NORMAL) |
if (rc != NORMAL) |
|
|
if (inf != stdin) |
if (inf != stdin) |
(void)fclose(inf); |
(void)fclose(inf); |
} |
} |
if (eoptind < argc) |
if (eoptind < argc){ |
return(1); |
goto out; |
return(0); |
} else { |
|
error = 0; |
|
goto out; |
|
} |
|
|
|
oomem: |
|
mfail(); |
|
out: |
|
free(buf); |
|
free(hbuf); |
|
if (inf != NULL && inf != stdin) |
|
(void)fclose(inf); |
|
return error; |
} |
} |
|
|
struct ferrlist { |
struct ferrlist { |
|
|
int cnt; |
int cnt; |
char *lstdat; |
char *lstdat; |
int i; |
int i; |
FILE **fbuf; |
FILE **fbuf = NULL; |
int actf; |
int actf; |
int lncnt; |
int lncnt; |
int col; |
int col; |
int pagecnt; |
int pagecnt; |
int fproc; |
int fproc; |
char *buf; |
char *buf = NULL; |
char *hbuf; |
char *hbuf = NULL; |
char *ohbuf; |
char *ohbuf; |
char *fname; |
char *fname; |
int ips = 0; |
int ips = 0; |
int cps = 0; |
int cps = 0; |
int ops = 0; |
int ops = 0; |
int mor = 0; |
int mor = 0; |
|
int error = 1; |
|
|
/* |
/* |
* array of FILE *, one for each operand |
* array of FILE *, one for each operand |
*/ |
*/ |
if ((fbuf = (FILE **)calloc((unsigned)clcnt, sizeof(FILE *))) == NULL) { |
if ((fbuf = (FILE **)calloc((unsigned)clcnt, sizeof(FILE *))) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
|
|
/* |
/* |
* array of int *, one for each operand |
* array of int *, one for each operand |
*/ |
*/ |
if ((rc = (int *)calloc((unsigned)clcnt, sizeof(int))) == NULL) { |
if ((rc = (int *)calloc((unsigned)clcnt, sizeof(int))) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
|
|
/* |
/* |
* page header |
* page header |
*/ |
*/ |
if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) { |
if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
ohbuf = hbuf + offst; |
ohbuf = hbuf + offst; |
|
|
/* |
/* |
|
|
if (j) |
if (j) |
clcnt = j; |
clcnt = j; |
else |
else |
return(1); |
goto out; |
|
|
/* |
/* |
* calculate page boundaries based on open file count |
* calculate page boundaries based on open file count |
|
|
} |
} |
if (colwd < 1) { |
if (colwd < 1) { |
ferrout("pr: page width too small for %d columns\n", clcnt); |
ferrout("pr: page width too small for %d columns\n", clcnt); |
return(1); |
goto out; |
} |
} |
col = colwd + 1; |
col = colwd + 1; |
|
|
/* |
/* |
* line buffer |
* line buffer |
*/ |
*/ |
if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL) { |
if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL) |
mfail(); |
goto oomem; |
return(1); |
|
} |
|
if (offst) { |
if (offst) { |
(void)memset(buf, (int)' ', offst); |
(void)memset(buf, (int)' ', offst); |
(void)memset(hbuf, (int)' ', offst); |
(void)memset(hbuf, (int)' ', offst); |
|
|
*/ |
*/ |
if (fproc != 0) { |
if (fproc != 0) { |
if (!i && prhead(hbuf, fname, ++pagecnt)) |
if (!i && prhead(hbuf, fname, ++pagecnt)) |
return(1); |
goto out; |
|
|
/* |
/* |
* output line |
* output line |
*/ |
*/ |
if (otln(buf, lstdat-buf, &ips, &ops, 0)) |
if (otln(buf, lstdat-buf, &ips, &ops, 0)) |
return(1); |
goto out; |
} else |
} else |
break; |
break; |
} |
} |
|
|
if (actf <= 0) |
if (actf <= 0) |
break; |
break; |
} |
} |
if (eoptind < argc) |
if (eoptind < argc){ |
return(1); |
goto out; |
return(0); |
} else { |
|
error = 0; |
|
goto out; |
|
} |
|
|
|
oomem: |
|
mfail(); |
|
out: |
|
if (fbuf) { |
|
for (j = 0; j < clcnt; j++) { |
|
if (fbuf[j] && fbuf[j] != stdin) |
|
(void)fclose(fbuf[j]); |
|
} |
|
free(fbuf); |
|
} |
|
free(hbuf); |
|
free(buf); |
|
return error; |
} |
} |
|
|
/* |
/* |