summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib')
-rw-r--r--Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/getopt.c124
-rw-r--r--Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/macintosh.h34
-rw-r--r--Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/unix-to-macintosh.c460
3 files changed, 618 insertions, 0 deletions
diff --git a/Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/getopt.c b/Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/getopt.c
new file mode 100644
index 00000000000..a0db51e2520
--- /dev/null
+++ b/Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/getopt.c
@@ -0,0 +1,124 @@
+/* getopt.c
+ * Modified slightly to port to Think C by AV 4.5.1993.
+ */
+
+/*
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getopt.c 4.13 (Berkeley) 2/23/91";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "getopt.h"
+
+/*
+ * get option letter from argument vector
+ */
+int opterr = 1, /* if error message should be printed */
+ optind = 1, /* index into parent argv vector */
+ optopt; /* character checked for validity */
+char *optarg; /* argument associated with option */
+
+#define BADCH (int)'?'
+#define EMSG ""
+
+int
+getopt(nargc, nargv, ostr)
+ int nargc;
+ char * const *nargv;
+ const char *ostr;
+{
+ static char *place = EMSG; /* option letter processing */
+ register char *oli; /* option letter list index */
+ char *p;
+ if (!*place) { /* update scanning pointer */
+ if (optind >= nargc || *(place = nargv[optind]) != '-') {
+ place = EMSG;
+ return(EOF);
+ }
+ if (place[1] && *++place == '-') { /* found "--" */
+ ++optind;
+ place = EMSG;
+ return(EOF);
+ }
+ } /* option letter okay? */
+ if ((optopt = (int)*place++) == (int)':' ||
+ !(oli = index(ostr, optopt))) {
+ /*
+ * if the user didn't specify '-' as an option,
+ * assume it means EOF.
+ */
+ if (optopt == (int)'-')
+ return(EOF);
+ if (!*place)
+ ++optind;
+ if (opterr) {
+ if (!(p = rindex(*nargv, '/')))
+ p = *nargv;
+ else
+ ++p;
+ (void)fprintf(stderr, "%s: illegal option -- %c\n",
+ p, optopt);
+ }
+ return(BADCH);
+ }
+ if (*++oli != ':') { /* don't need argument */
+ optarg = NULL;
+ if (!*place)
+ ++optind;
+ }
+ else { /* need an argument */
+ if (*place) /* no white space */
+ optarg = place;
+ else if (nargc <= ++optind) { /* no arg */
+ place = EMSG;
+ if (!(p = rindex(*nargv, '/')))
+ p = *nargv;
+ else
+ ++p;
+ if (opterr)
+ (void)fprintf(stderr,
+ "%s: option requires an argument -- %c\n",
+ p, optopt);
+ return(BADCH);
+ }
+ else /* white space */
+ optarg = nargv[optind];
+ place = EMSG;
+ ++optind;
+ }
+ return(optopt); /* dump back option letter */
+}
diff --git a/Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/macintosh.h b/Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/macintosh.h
new file mode 100644
index 00000000000..24843f507c7
--- /dev/null
+++ b/Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/macintosh.h
@@ -0,0 +1,34 @@
+/* macintosh.h 24.2.1996 Alex Viskovatoff
+ *
+ * Header file accompanying unix-to-macintosh.c.
+ *
+ * Written and copyright (c) 1996 by Alex Viskovatoff.
+ * Permission is granted to distribute and modify this file.
+ */
+
+
+#define PATHNAME_LENGTH 256
+
+#define isascii(c) (((unsigned) c) <= 0x7f)
+
+
+/* "DVI2ODVI" is equivalent to an arry of static unsigned long
+ initialized to {'DVI2', 'ODVI'} - Textures and OzTeX
+ type signatures of dvi files, respectively. */
+
+#define process_dvi_command_line(args) \
+ docommand(args,0L,2,(unsigned long*)"DVI2ODVI")
+
+int docommand(char ***,void*,int,unsigned long*);
+void set_creator(const unsigned char *outfilename);
+int getopt(int nargc, char * const *nargv, const char *ostr);
+char *get_home_dir(void);
+char *get_file_from_dialog(void);
+pascal unsigned char not_rtf_file_p(void *parms);
+
+
+/* The following are defined in getopt.c */
+
+#define index strchr
+#define rindex strrchr
+int getopt(int nargc, char * const *nargv, const char *ostr);
diff --git a/Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/unix-to-macintosh.c b/Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/unix-to-macintosh.c
new file mode 100644
index 00000000000..f29b0334256
--- /dev/null
+++ b/Build/source/texk/dvi2tty/dvi2tty-5.3.1/UNIXtoMacLib/unix-to-macintosh.c
@@ -0,0 +1,460 @@
+/* unix-to-macintosh.c 24.2.1996
+
+ * Macintosh THINK-C file system and user interface
+ * library for use by dvi2tty, disdvi, and rtf2LaTeX.
+ *
+ * Written and copyright (c) 1996 by Alex Viskovatoff
+ * (av@mixcom.com). Permission is granted to distribute
+ * and modify this file.
+ */
+
+#include <MacHeaders>
+#include <string.h>
+#include "macintosh.h"
+
+
+static char home_pathname_buf[PATHNAME_LENGTH];
+
+static char *make_pathname(char *q,long dir_id, int vol_num)
+{
+ CInfoPBRec directory;
+ Str31 dir_name;
+ int n;
+ directory.dirInfo.ioDrDirID = dir_id;
+ directory.dirInfo.ioVRefNum = vol_num;
+ directory.dirInfo.ioFDirIndex = -1;
+ directory.dirInfo.ioNamePtr = dir_name;
+ for (;;directory.dirInfo.ioDrDirID = directory.dirInfo.ioDrParID) {
+ *q-- = ':';
+ PBGetCatInfoSync(&directory);
+ for (n=*dir_name; n; n--) *q-- = (char) dir_name[n];
+ if (directory.dirInfo.ioDrDirID == 2) break;
+ }
+ return q+1;
+}
+
+char *get_home_dir()
+{
+ FCBPBRec home_dir;
+ Str31 dir_name;
+ Str31 apName;
+ int pathRefNum;
+ Handle apParam;
+ char *p = home_pathname_buf+PATHNAME_LENGTH-1;
+ GetAppParms(&apName,&pathRefNum,&apParam);
+ home_dir.ioRefNum = pathRefNum;
+ home_dir.ioFCBIndx = 0;
+ home_dir.ioNamePtr = dir_name;
+ PBGetFCBInfoSync(&home_dir);
+ *p-- = 0;
+ return make_pathname(p,home_dir.ioFCBParID,home_dir.ioFCBVRefNum);
+}
+
+pascal unsigned char not_rtf_file_p(void *parms)
+{
+ StringPtr name = ((IOParam*)parms)->ioNamePtr;
+ char *p, *q;
+ static char extension[] = ".rtf";
+ int i;
+ if (name[0] < 5) return TRUE;
+ for (i=4, p = (char*) name + name[0] - 3, q=extension; i; i--)
+ if (*p++ != *q++) return TRUE;
+ return FALSE;
+}
+
+void set_creator(const unsigned char *outfilename)
+{
+ FInfo finfo;
+ Str255 filename;
+ StringHandle h;
+ strcpy((char*)filename,(char*)outfilename);
+ CtoPstr(filename);
+ if (!GetFInfo(filename,0,&finfo)) {
+ finfo.fdCreator = *((OSType*)*(h=GetString(128)));
+ ReleaseResource(h);
+ SetFInfo(filename,0,&finfo);
+ }
+}
+
+
+
+/* The rest of file is a modification of the file ccomand.c (part of
+ * Think C 5.0), with the function ccommand renamed to "docommand",
+ * and changed to take three more arguments: a filter procedure to use
+ * when displaying files in the open input file dialog, the length of
+ * a list of signatures of file types that should be displayed in that
+ * dialog, and a pointer to this list. Furthermore, the file creator
+ * signature for the output file, which is of type 'TEXT', is now set
+ * by a call to the new function set_creator. The signature is stored
+ * as a string resource, and so can be modified by means of ResEdit.
+ * (In the distribution, the signature used is '*TEX', that of Textures.)
+ */
+
+
+/*
+ * ccommand.c
+ *
+ * Copyright (c) 1991 Symantec Corporation. All rights reserved.
+ *
+ * This routine should be called from "main" as follows:
+ *
+ * main(int argc, char **argv)
+ * {
+ * argc = ccommand(&argv);
+ * ...
+ *
+ * A dialog is presented allowing entry of command line arguments
+ * and redirection of stdin/stdout.
+ *
+ */
+
+#include <MacHeaders>
+
+#include "stdlib.h"
+#include "errno.h"
+#include "console.h"
+#include "ansi_private.h"
+
+#define NARGS 25
+
+static char *argv[NARGS+1];
+static char argbuf[256];
+
+static void create_dialog(void);
+static Handle ditem(int);
+static void radio(int, int, int);
+static pascal void drawRing(DialogPtr, short);
+
+static Point getWhere = { 90, 82 };
+static Point putWhere = { 106, 104 };
+
+static void setfile(char *, SFReply *);
+
+static void init_command_line(char *, char *);
+static int parse(char *, char *);
+
+enum {
+ cmdLine = 3,
+ inCon, inFile,
+ outCon, outFile, outEcho, outPrint,
+ okRing,
+ labelIn, labelOut, labelLine
+};
+
+static struct {
+ short count;
+ struct {
+ Handle h;
+ Rect box;
+ char kind;
+ } item[13];
+} itemList = { 12,
+
+ /* OK */
+ 0, { 176, 115, 196, 175 }, ctrlItem+btnCtrl,
+
+ /* Cancel */
+ 0, { 176, 225, 196, 285 }, ctrlItem+btnCtrl,
+
+ /* command line */
+ 0, { 141, 34, 157, 376 }, editText+itemDisable,
+
+ /* (stdin) console */
+ 0, { 34, 30, 50, 180 }, ctrlItem+radCtrl,
+
+ /* (stdin) file */
+ 0, { 54, 30, 70, 180 }, ctrlItem+radCtrl,
+
+ /* (stdout) console */
+ 0, { 34, 230, 50, 380 }, ctrlItem+radCtrl,
+
+ /* (stdout) file */
+ 0, { 54, 230, 70, 380 }, ctrlItem+radCtrl,
+
+ /* (stdout) console+file */
+ 0, { 74, 230, 90, 380 }, ctrlItem+radCtrl,
+
+ /* (stdout) console+printer */
+ 0, { 94, 230, 110, 380 }, ctrlItem+radCtrl,
+
+ /* ring around OK button */
+ (Handle) drawRing, { 172, 111, 200, 179 }, userItem+itemDisable,
+
+ /* "Standard Input:" */
+ 0, { 10, 20, 26, 170 }, statText+itemDisable,
+
+ /* "Standard Output:" */
+ 0, { 10, 220, 26, 370 }, statText+itemDisable,
+
+ /* "Command Line:" */
+ 0, { 114, 20, 130, 170 }, statText+itemDisable,
+};
+
+static DialogPtr dp;
+static Rect bounds = { 60, 51, 270, 461 };
+static int inChoice = inCon, outChoice = outCon;
+
+
+/*
+ * ccommand - process "command line"
+ *
+ */
+
+int
+docommand(char ***av, ProcPtr file_filter, int num_types, SFTypeList type_list)
+{
+ short i, argc;
+ SFReply input, output, scratch;
+ char buf[256];
+
+ /* present dialog */
+
+ cshow(stdin);
+ create_dialog();
+ init_command_line(buf, argbuf);
+ SetCtlValue(ditem(inCon), 1);
+ SetCtlValue(ditem(outCon), 1);
+ ShowWindow(dp);
+
+ /* engage in dialog */
+
+ do {
+ ModalDialog(0, &i);
+ switch (i) {
+ case cancel:
+ abort();
+ case inFile:
+ SFGetFile(getWhere, "", file_filter, num_types, type_list, NULL, &scratch);
+ if (!scratch.good)
+ break;
+ input = scratch;
+ /* ... */
+ case inCon:
+ radio(inChoice = i, inCon, 2);
+ break;
+ case outFile:
+ case outEcho:
+ SFPutFile(putWhere, "", "", NULL, &scratch);
+ if (!scratch.good)
+ break;
+ output = scratch;
+ /* ... */
+ case outCon:
+ case outPrint:
+ radio(outChoice = i, outCon, 4);
+ break;
+ }
+ } while (i != ok);
+
+ /* parse command line */
+
+ GetIText(ditem(cmdLine), argbuf);
+ sprintf(buf, "%#s", argbuf);
+ argc = parse(buf, argbuf);
+ *av = argv;
+ DisposDialog(dp);
+
+ /* redirect stdout */
+
+ if (outChoice == outPrint)
+ cecho2printer(stdout);
+ else if (outChoice != outCon) {
+ setfile((char *) scratch.fName, &output);
+ if (outChoice == outFile)
+ freopen((char *) scratch.fName, "w", stdout);
+ else cecho2file((char *) scratch.fName, 0, stdout);
+ set_creator(scratch.fName); /*** Added by av ***/
+ }
+
+ /* redirect stdin */
+
+ if (inChoice == inFile) {
+ setfile((char *) scratch.fName, &input);
+ freopen((char *) scratch.fName, "r", stdin);
+ }
+
+ /* done */
+
+ errno = 0;
+ return(argc);
+}
+
+
+/* ---------- dialog utilities ---------- */
+
+
+/*
+ * create_dialog - build dialog in memory
+ *
+ */
+
+static void
+create_dialog(void)
+{
+ Handle items;
+
+ asm {
+ lea itemList,a0
+ move.l #sizeof itemList,d0
+ _PtrToHand
+ move.l a0,items
+ }
+ dp = NewDialog(0, &bounds, "", 0, 1, (Ptr) -1, 0, 0, items);
+ SetCTitle(ditem(ok), "\pOK");
+ SetCTitle(ditem(cancel), "\pCancel");
+ SetCTitle(ditem(inCon), "\pconsole");
+ SetCTitle(ditem(inFile), "\pfile");
+ SetCTitle(ditem(outCon), "\pconsole");
+ SetCTitle(ditem(outFile), "\pfile");
+ SetCTitle(ditem(outEcho), "\pconsole+file");
+ SetCTitle(ditem(outPrint), "\pconsole+printer");
+ SetIText(ditem(labelIn), "\pStandard Input:");
+ SetIText(ditem(labelOut), "\pStandard Output:");
+ SetIText(ditem(labelLine), "\pCommand Line:");
+}
+
+
+/*
+ * ditem - return item handle
+ *
+ */
+
+static Handle
+ditem(int i)
+{
+ short kind;
+ Handle item;
+ Rect box;
+
+ GetDItem(dp, i, &kind, &item, &box);
+ return(item);
+}
+
+
+/*
+ * radio - adjust a cluster of radio buttons
+ *
+ */
+
+static void
+radio(int i, int j, int n)
+{
+ for (; n--; j++)
+ SetCtlValue(ditem(j), i == j);
+}
+
+
+/*
+ * drawRing - (user-item proc) draw ring around OK button
+ *
+ */
+
+static pascal void
+drawRing(DialogPtr dp, short i)
+{
+ PenNormal();
+ PenSize(3, 3);
+ FrameRoundRect(&itemList.item[okRing-1].box, 16, 16);
+ PenNormal();
+}
+
+
+/* ---------- file utilities ---------- */
+
+
+/*
+ * setfile - prepare to open file
+ *
+ */
+
+static void
+setfile(char *buf, SFReply *reply)
+{
+ IOParam pb;
+
+ pb.ioNamePtr = 0;
+ pb.ioVRefNum = reply->vRefNum;
+ PBSetVolSync(&pb);
+ sprintf(buf, "%#s", reply->fName);
+}
+
+
+/* ---------- string utilities ---------- */
+
+
+/*
+ * init_command_line - prepare initial command line
+ *
+ * The command line is preset to show the name of the program.
+ * The program name is quoted as necessary.
+ *
+ */
+
+static void
+init_command_line(char *buf1, char *buf2)
+{
+ register char *s, *t = buf2;
+ int c, space = 0, dquote = 0, squote = 0, quote = 0;
+
+ sprintf(s = buf1, "%#s", CurApName);
+ while (c = *s++) {
+ if (c == ' ')
+ space = 1;
+ else if (c == '"')
+ dquote = 1;
+ else if (c == '\'')
+ squote = 1;
+ }
+ if (space || dquote || squote)
+ *t++ = quote = dquote && !squote ? '\'' : '"';
+ for (s = buf1; c = *s++; *t++ = c) {
+ if (c == quote || c == '\\')
+ *t++ = '\\';
+ }
+ if (quote)
+ *t++ = quote;
+ *t++ = ' ';
+ *t++ = 0;
+ SetIText(ditem(cmdLine), __c2p(buf2, buf1));
+ SelIText(dp, cmdLine, 9999, 9999);
+}
+
+
+/*
+ * parse - divide command line into "words"
+ *
+ * Words are delimited by one or more spaces. Any characters within
+ * matching single (') or double (") quotes are taken literally. Any
+ * character preceded by a backslash (\) is taken literally.
+ *
+ */
+
+static int
+parse(char *s, char *t)
+{
+ int c, quote = 0, argc = 0;
+
+ while (c = *s++) {
+ if (c == ' ')
+ continue;
+ if (argc < NARGS)
+ argv[argc++] = t;
+ do {
+ if (c == '\\' && *s)
+ c = *s++;
+ else if (c == '"' || c == '\'') {
+ if (!quote) {
+ quote = c;
+ continue;
+ }
+ if (c == quote) {
+ quote = 0;
+ continue;
+ }
+ }
+ *t++ = c;
+ } while (*s && ((c = *s++) != ' ' || quote));
+ *t++ = 0;
+ }
+ return(argc);
+}