824N/A/*
824N/A * main.c
824N/A *
824N/A * (c) Copyright 1988-1994 Adobe Systems Incorporated.
824N/A * All rights reserved.
824N/A *
824N/A * Permission to use, copy, modify, distribute, and sublicense this software
824N/A * and its documentation for any purpose and without fee is hereby granted,
824N/A * provided that the above copyright notices appear in all copies and that
824N/A * both those copyright notices and this permission notice appear in
824N/A * supporting documentation and that the name of Adobe Systems Incorporated
824N/A * not be used in advertising or publicity pertaining to distribution of the
824N/A * software without specific, written prior permission. No trademark license
824N/A * to use the Adobe trademarks is hereby granted. If the Adobe trademark
824N/A * "Display PostScript"(tm) is used to describe this software, its
824N/A * functionality or for any other purpose, such use shall be limited to a
824N/A * statement that this software works in conjunction with the Display
824N/A * PostScript system. Proper trademark attribution to reflect Adobe's
824N/A * ownership of the trademark shall be given whenever any such reference to
824N/A * the Display PostScript system is made.
824N/A *
824N/A * ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
824N/A * ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
824N/A * ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
824N/A * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
824N/A * NON- INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE
824N/A * TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
824N/A * DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
824N/A * NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
824N/A * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT
824N/A * PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
824N/A *
824N/A * Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
824N/A * Incorporated which may be registered in certain jurisdictions
824N/A *
824N/A * Author: Adobe Systems Incorporated
824N/A */
824N/A/* $XFree86: xc/config/pswrap/main.c,v 1.4 2000/06/07 19:50:47 tsi Exp $ */
824N/A
824N/A#include <stdio.h>
824N/A
824N/A#ifdef XENVIRONMENT
824N/A#include <X11/Xos.h>
824N/A#else
824N/A#include <string.h>
824N/A#endif
824N/A
824N/A#define SLASH '/'
824N/A#include <ctype.h>
824N/A#include <stdlib.h>
824N/A#include "pswpriv.h"
824N/A
824N/A#define MIN_MAXSTRING 80 /* min allowable value of maxstring */
824N/A
824N/A/* global data */
824N/Achar *prog; /* program name */
824N/Achar *special_h = NULL; /* -f option */
824N/Achar *hfile = NULL; /* name of -h file */
824N/Achar *ofile = NULL; /* name of -o file */
824N/Achar *ifile = NULL; /* name of input file */
824N/Aint gotInFile = 0; /* got an explicit input file name */
824N/Aint doANSI = 0; /* got -a (ansi) flag for -h file */
824N/Aint pad = 0; /* got -p (padding) flag */
824N/Aboolean noUserNames = false; /* got -n (don't use usernames) flag */
824N/Aint reentrant = 0; /* automatic vars for generated BOS */
824N/Aint bigFile = 0; /* got -b flag => call free */
824N/AFILE *header; /* stream for -h file output */
824N/Achar headid[200]; /* id for header file #include */
824N/Aint maxstring = 2000; /* -s max string length to scan */
824N/Achar *string_temp; /* string buffer of above size */
824N/Aint outlineno = 1; /* output line number */
824N/Aint nWraps = 0; /* total number of wraps */
824N/A#ifdef __MACH__
824N/Achar *shlibInclude = NULL; /* special file to be #included at top of */
824N/A /* file. Used only when building shlibs */
824N/A#endif /* __MACH__ */
824N/A
824N/Astatic void Usage(void)
824N/A{
824N/A fprintf(stderr,"Usage: pswrap [options] [input-file]\n");
824N/A fprintf(stderr," -a produce ANSI C procedure prototypes\n");
824N/A fprintf(stderr," -b process a big file\n");
824N/A fprintf(stderr," -f filename include special header\n");
824N/A fprintf(stderr," -h filename specify header filename\n");
824N/A fprintf(stderr," -o filename specify output C filename\n");
824N/A fprintf(stderr," -r make wraps re-entrant\n");
824N/A fprintf(stderr," -s length set maximum string length\n");
824N/A exit(1);
824N/A}
824N/A
824N/Astatic void ScanArgs(int argc, char *argv[])
824N/A{
824N/A char *slash; /* index of last / in hfile */
824N/A char *c; /* pointer into headid for conversion */
824N/A int i = 0;
824N/A
824N/A prog = argv[i++];
824N/A slash = rindex(prog,SLASH);
824N/A if (slash)
824N/A prog = slash + 1;
824N/A while (i < argc) {
824N/A if (*argv[i] != '-') {
824N/A if (ifile != NULL) {
824N/A fprintf(stderr, "%s: Only one input file can be specified.\n", prog);
824N/A Usage();
824N/A } else {
824N/A ifile = argv[i];
824N/A }
824N/A } else {
824N/A switch (*(argv[i]+1)) {
824N/A case 'a':
824N/A doANSI++;
824N/A reentrant++;
824N/A break;
824N/A case 'b':
824N/A bigFile++;
824N/A break;
824N/A#ifdef PSWDEBUG
824N/A case 'd':
824N/A lexdebug++;
824N/A break;
824N/A#endif /* PSWDEBUG */
824N/A case 'f':
824N/A special_h = argv[++i];
824N/A break;
824N/A case 'h':
824N/A hfile = argv[++i];
824N/A slash = rindex(hfile,SLASH);
824N/A strcpy(headid, slash ? slash+1 : hfile);
824N/A for (c = headid; *c != '\0'; c++) {
824N/A if (*c == '.') *c = '_';
824N/A else if (isascii(*c) && islower(*c)) *c = toupper(*c);
824N/A }
824N/A break;
824N/A case 'o':
824N/A ofile = argv[++i];
824N/A break;
824N/A case 'r':
824N/A reentrant++;
824N/A break;
824N/A case 's':
824N/A if ((maxstring = atoi(argv[++i])) < MIN_MAXSTRING) {
824N/A fprintf(stderr,"%s: -s %d is the minimum\n", prog, MIN_MAXSTRING);
824N/A maxstring = MIN_MAXSTRING;
824N/A }
824N/A break;
824N/A case 'w':
824N/A break;
824N/A#ifdef __MACH__
824N/A case 'S':
824N/A shlibInclude = argv[++i];
824N/A break;
824N/A#endif /* __MACH__ */
824N/A case 'n':
824N/A noUserNames = true;
824N/A break;
824N/A case 'p':
824N/A pad++;
824N/A break;
824N/A default:
824N/A fprintf(stderr, "%s: bad option '-%c'\n", prog, *(argv[i]+1));
824N/A Usage();
824N/A break;
824N/A } /* switch */
824N/A } /* else */
824N/A i++;
824N/A } /* while */
824N/A} /* ScanArgs */
824N/A
824N/Aint main(int argc, char *argv[])
824N/A{
824N/A int retval; /* return from yyparse */
824N/A
824N/A ScanArgs(argc, argv);
824N/A
824N/A if (ifile == NULL)
824N/A ifile = "stdin";
824N/A else {
824N/A gotInFile = 1;
824N/A if (freopen(ifile,"r",stdin) == NULL) {
824N/A fprintf(stderr, "%s: can't open %s for input\n", prog, ifile);
824N/A exit(1);
824N/A }
824N/A }
824N/A if ((string_temp = (char *) malloc((unsigned) (maxstring+1))) == 0) {
824N/A fprintf(stderr, "%s: can't allocate %d char string; try a smaller -s value\n", prog, maxstring);
824N/A exit(1);
824N/A }
824N/A if (ofile == NULL)
824N/A ofile = "stdout";
824N/A else {
824N/A#ifdef __MACH__
824N/A (void)unlink(ofile);
824N/A#endif /* __MACH__ */
824N/A if (freopen(ofile,"w",stdout) == NULL) {
824N/A fprintf(stderr, "%s: can't open %s for output\n", prog, ofile);
824N/A exit(1);
824N/A }
824N/A }
824N/A InitOFile();
824N/A
824N/A if (hfile != NULL) {
824N/A#ifdef __MACH__
824N/A (void)unlink(hfile);
824N/A#endif /* __MACH__ */
824N/A if ((header = fopen(hfile,"w")) == NULL) {
824N/A fprintf(stderr, "%s: can't open %s for output\n", prog, hfile);
824N/A exit(1);
824N/A }
824N/A }
824N/A if (header != NULL) InitHFile();
824N/A
824N/A InitWellKnownPSNames();
824N/A
824N/A if ((retval = yyparse()) != 0)
824N/A fprintf(stderr,"%s: error in parsing %s\n",prog,ifile);
824N/A else if (errorCount != 0) {
824N/A fprintf(stderr,"%s: errors were encountered\n",prog);
824N/A retval = errorCount;
824N/A }
824N/A
824N/A if (hfile != NULL) FinishHFile();
824N/A
824N/A exit (retval);
824N/A}