This is orcad.c in view mode; [Download] [Up]
#include "incl.h"
extern FILE *fpo, *fpi;
extern char buffer[];
extern int inlinecount, outlinecount, NoOrcadFrame;
extern double llx, lly, urx, ury;
extern double scx, scy;
orcad ()
{
double x, y, lx, by, rx, uy;
long newpath_fpi, newpath_fpo;
char str[MAXWORD+1];
char str1[MAXWORD+1];
int i, n, translateflag, rotateflag;
/*
** Do some initialization.
*/
lx = 1e4;
by = 1e4;
rx = 0.0;
uy = 0.0;
translateflag = 0;
rotateflag = 0;
/*
** Get the x- and y picture limits in inches.
*/
for (fgets (buffer, MAXBUF, fpi); (!(feof (fpi)));
fgets (buffer, MAXBUF, fpi)) {
n = sscanf (buffer, "%lf%*s%lf%*s%s", &x, &y, str);
if (n == 3 && (strcmp (MOVETO, str) == 0
|| strcmp (LINETO, str) == 0)) {
if (x < lx) lx = x;
else if (x > rx) rx = x;
if (y < by) by = y;
else if (y > uy) uy = y;
}
}
rewind (fpi);
/*
** Compute BoundingBox values in point units.
*/
llx = lx * 72;
lly = by * 72;
urx = rx * 72;
ury = uy * 72;
scx = 1.0;
scy = 1.0;
/*
** Adjust BoundingBox and scale values depending on width (-w)
** height (-h) and space (-s) options.
*/
if (adj_bbox (urx - llx) == EXIT_FAILURE) return (EXIT_FAILURE);
/*
** Replace first line
*/
fgets (buffer, MAXBUF, fpi);
inlinecount++;
fprintf (fpo, "%s", FIRSTLINE);
fprintf (fpo, "%s %d %d %d %d\n",
PPBOUNDINGBOXC, (int)llx, (int)lly, (int)urx, (int)ury);
fprintf (fpo, "%s: 0 1\n", PPPAGES);
fprintf (fpo, "%s\n", PPENDCOMMENTS);
/*
** Insert next statement for use with program ``dvialw''
*/
fprintf (fpo, "%s", DVIALW_BEGIN);
outlinecount += 5;
for (fgets (buffer, MAXBUF, fpi); (!(feof (fpi)));
fgets (buffer, MAXBUF, fpi)) {
inlinecount++;
/*
** When the `translate' and `rotate' statements are commented out
** write a `scale' statement with the above computed scale factors
** to the output file.
*/
if (translateflag && rotateflag) {
fprintf (fpo, "%.3lf %.3lf %s\n", scx, scy, SCALE);
fprintf (fpo, "%s", buffer);
outlinecount += 2;
break;
}
/*
** The `translate' and `rotate' statements put the picture
** in landscape mode so comment them out.
*/
else if ((n = sscanf (buffer, "%*lf%*s%*lf%*s%s", str)) == 1 &&
(strcmp (TRANSLATE, str)) == 0) {
fprintf (fpo, "%s%s", PPP, buffer);
outlinecount++;
translateflag = TRUE;
}
else if ((n = sscanf (buffer, "%*lf%s", str)) == 1 &&
(strcmp (ROTATE, str)) == 0) {
fprintf (fpo, "%s%s", PPP, buffer);
outlinecount++;
rotateflag = TRUE;
}
else fprintf (fpo, "%s", buffer);
outlinecount++;
}
for (fgets (buffer, MAXBUF, fpi); (!(feof (fpi)));
fgets (buffer, MAXBUF, fpi)) {
inlinecount++;
str1[0] = '\0';
n = sscanf (buffer, "%s", str1);
/*
** When the -f option has been given, no Orcad frame is wanted
** around the picture, so comment out the associated statements.
*/
if (NoOrcadFrame) {
if (n == 1 && (strcmp (NEWPATH, str1) == 0)) {
newpath_fpi = ftell (fpi) - strlen (buffer);
newpath_fpo = ftell (fpo);
}
n = sscanf (buffer, "%lf%*s%lf%*s%s", &x, &y, str);
if (n == 3 && (strcmp (MOVETO, str) == 0) &&
(x == lx || x == rx)) {
if (fseek (fpi, newpath_fpi, SEEK_SET)) {
fprintf (stderr, "\norcad.c: fseek error on input file\n\n");
return (EXIT_FAILURE);
}
if (fseek (fpo, newpath_fpo, SEEK_SET)) {
fprintf (stderr, "\norcad.c: fseek error on output file\n\n");
return (EXIT_FAILURE);
}
do {
fgets (buffer, MAXBUF, fpi);
inlinecount++;
fprintf (fpo, "%s%s", PPP, buffer);
outlinecount++;
sscanf (buffer, "%s", str);
} while (strcmp (STROKE, str) != 0);
}
else if ((strcmp (SHOWPAGE, str1)) == 0) {
/*
** Insert next statement for use with program ``dvialw''
*/
fprintf (fpo, "%s", DVIALW_END);
fprintf (fpo, "%s", buffer);
outlinecount += 2;
}
else {
fprintf (fpo, "%s", buffer);
outlinecount++;
}
}
else if ((strcmp (SHOWPAGE, str1)) == 0) {
/*
** Insert next statement for use with program ``dvialw''
*/
fprintf (fpo, "%s", DVIALW_END);
fprintf (fpo, "%s", buffer);
outlinecount += 2;
}
else {
fprintf (fpo, "%s", buffer);
outlinecount++;
}
}
if (!translateflag) {
fprintf (stderr, "\n*** Didn't find translate statement.\n\n");
return (EXIT_FAILURE);
}
if (!rotateflag) {
fprintf (stderr, "\n*** Didn't find rotate statement.\n\n");
return (EXIT_FAILURE);
}
return (EXIT_SUCCESS);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.