This is main.c in view mode; [Download] [Up]
#include "incl.h" FILE *fpo, *fpi; char *word1, *word2, *optarg; char buffer[MAXBUF+1], newbuf[MAXBUF+1], buf[MAXBUF+1]; char ifile[MAXBUF+1], ofile[MAXBUF+1]; int inlinecount, outlinecount; int PSpicePS, GemPS, OrcadPS, DrawPerfectPS, GnuPlotPS, PrintGlPS, MathcadPS; int InputFile, OutputFile, DateTempLine; int Height, Width, Vspace, NoOrcadFrame; int pagesOK, boundingboxOK, boundingboxOPTION; int atend, EndComments, EndProlog; int userdictFOUND, initclipFOUND, landscapeFOUND; int quit(); long CurrentPos, BboxPos, ScalePos; double llx, lly, urx, ury, height, width, defaultwidth; double xfac, yfac, scx, scy; double top_space, bottom_space, mm2pt=2.8453; #define USAGE {fprintf(stderr,"\nUsage:\n%s [-P -G -O -D -T -H -M] [-d] [-f] [-h#] [-w#] [-b#,#,#,#] [-s#,#] [-oOutputfile] inputfile\n\n", PROG_NAME); exit (EXIT_FAILURE);} main (argc, argv) char *argv[]; int argc; { int ret_code, c, errflag = 0; char *cp, *opt_str = "PGODTHMdfh;w;b;s;o;"; /* ** Intercept termination signals. */ signal (SIGINT, quit); initarg(argc - 1, argv + 1); while ((c = getarg(opt_str)) != 0) { switch (c) { case 'P': if (GemPS || OrcadPS || DrawPerfectPS || GnuPlotPS || PrintGlPS) errflag++; else PSpicePS = TRUE; break; case 'G': if (PSpicePS || OrcadPS || DrawPerfectPS || GnuPlotPS || PrintGlPS) errflag++; else GemPS = TRUE; break; case 'O': if (PSpicePS || GemPS || DrawPerfectPS || GnuPlotPS || PrintGlPS) errflag++; else OrcadPS = TRUE; break; case 'D': if (PSpicePS || OrcadPS || GemPS || GnuPlotPS || PrintGlPS) errflag++; else DrawPerfectPS = TRUE; break; case 'T': if (PSpicePS || OrcadPS || GemPS || DrawPerfectPS || PrintGlPS) errflag++; else GnuPlotPS = TRUE; break; case 'H': if (PSpicePS || OrcadPS || GemPS || DrawPerfectPS || GnuPlotPS) errflag++; else PrintGlPS = TRUE; break; case 'M': if (PSpicePS || OrcadPS || GemPS || DrawPerfectPS || GnuPlotPS || PrintGlPS) errflag++; else MathcadPS = TRUE; break; case -1: if (strcmp (optarg, "?") == 0) { help (); exit (EXIT_FAILURE); } strcpy (ifile, optarg); cp = strchr (ifile, '.'); if (cp == NULL) { strcat (ifile, ".ps"); } if (((fpi = fopen (ifile, "r")) == NULL)) { fprintf (stderr, "\n*** Cannot open file '%s' for reading.\n\n", ifile); exit (EXIT_FAILURE); } InputFile = TRUE; break; case 'w': if (optarg == NULL) { fprintf (stderr, "\n*** There must be a width(mm) right after the -w option.\n\n"); exit (EXIT_FAILURE); } width = atof (optarg); if (width > MAX_WIDTH) { fprintf (stderr, "\n*** Invalid option value (width > %d).\n\n", MAX_WIDTH); exit (EXIT_FAILURE); } Width = TRUE; break; case 'h': if (optarg == NULL) { fprintf (stderr, "\n*** There must be a height(mm) right after the -h option.\n\n"); exit (EXIT_FAILURE); } height = atof (optarg); if (height > MAX_HEIGHT) { fprintf (stderr, "\n*** Invalid option value (height > %d).\n\n", MAX_HEIGHT); exit (EXIT_FAILURE); } Height = TRUE; break; case 'b': if (optarg == NULL) { fprintf (stderr, "\n*** Boundingbox values must be right after the -b option.\n\n"); exit (EXIT_FAILURE); } llx = strtod (optarg, &cp); lly = strtod (cp+1, &cp); urx = strtod (cp+1, &cp); ury = strtod (cp+1, &cp); if (urx == 0.0 || ury == 0.0) { fprintf (stderr, "\n*** Error in -b option.\n\n"); USAGE; } boundingboxOPTION = TRUE; break; case 's': if (optarg == NULL) { fprintf (stderr, "\n*** There must be a spacevalue(mm) right after the -s option.\n\n"); exit (EXIT_FAILURE); } top_space = strtod (optarg, &cp); bottom_space = strtod (cp+1, &cp); if ((strcmp (cp+1, cp)) == 0) { fprintf (stderr, "\n*** Error in -s option.\n\n"); USAGE; } Vspace = TRUE; break; case 'd': DateTempLine = TRUE; break; case 'f': NoOrcadFrame = TRUE; break; case 'o': if (optarg == NULL) { fprintf (stderr, "\n*** Outputfile name must be right after the -o option.\n\n"); exit (EXIT_FAILURE); } strcpy (ofile, optarg); OutputFile = TRUE; break; case '?': case '-': USAGE; break; } if (errflag) { fprintf (stderr, "\n*** Options -P -G -O -D -T -H -M are mutually exclusive.\n\n"); exit (EXIT_FAILURE); } } if (argc == 1) { help (); exit (EXIT_FAILURE); } if (DateTempLine && !PSpicePS) { fprintf (stderr, "\n*** Option -d only valid with -P option.\n\n"); exit (EXIT_FAILURE); } if (NoOrcadFrame && !OrcadPS) { fprintf (stderr, "\n*** Option -f only valid with -O option.\n\n"); exit (EXIT_FAILURE); } if (GemPS && (!boundingboxOPTION)) { fprintf (stderr, "\n*** With Gem -b option is required.\n\n"); exit (EXIT_FAILURE); } if (DrawPerfectPS && (!boundingboxOPTION)) { fprintf (stderr, "\n*** With DrawPerfect -b option is required.\n\n"); exit (EXIT_FAILURE); } if (MathcadPS && (!boundingboxOPTION)) { fprintf (stderr, "\n*** With Mathcad -b option is required.\n\n"); exit (EXIT_FAILURE); } if (!InputFile) { fprintf (stderr, "\n*** No input file specified.\n\n"); exit (EXIT_FAILURE); } if (!OutputFile) { strcpy (ofile, ifile); cp = strchr (ofile, '.'); if (cp != NULL) *cp = '\0'; if ((strcmp ((cp + 1), EPS)) == 0) { fprintf (stderr, "\n*** Input file may not have extension 'eps'.\n\n"); exit (EXIT_FAILURE); } strcat (ofile, DEPS); } if (((fpo = fopen (ofile, "w")) == NULL)) { fprintf (stderr, "\n*** Cannot open file '%s' for writing.\n\n", ofile); exit (EXIT_FAILURE); } defaultwidth = MAX_WIDTH * mm2pt; width *= mm2pt; height *= mm2pt; top_space *= mm2pt; bottom_space *= mm2pt; llx *= mm2pt; lly *= mm2pt; urx *= mm2pt; ury *= mm2pt; if (PSpicePS) ret_code = pspice (); else if (GemPS) ret_code = gem (); else if (OrcadPS) ret_code = orcad (); else if (DrawPerfectPS) ret_code = dperfect (); else if (GnuPlotPS) ret_code = gnuplot (); else if (PrintGlPS) ret_code = printgl (); else if (MathcadPS) ret_code = mathcad (); else ret_code = parse (); exit (ret_code); } quit (code) int code; { /* ** This routine will be called when certain ** signals are caught. Do the cleanup before ** exiting. */ fprintf (stderr, "\n>>> Caught a signal %d. Goodbye.\n\n", code); exit (-1); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.