Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!husc6!sri-unix!hplabs!felix!macintosh From: macintosh@felix.UUCP Newsgroups: mod.mac.sources Subject: Unix program for MacDraw->Imagen (3 of 3) Message-ID: <2352@felix.UUCP> Date: Fri, 27-Feb-87 05:42:27 EST Article-I.D.: felix.2352 Posted: Fri Feb 27 05:42:27 1987 Date-Received: Sun, 1-Mar-87 10:06:49 EST References: <2347@felix.UUCP> <2349@felix.UUCP> Sender: news@felix.UUCP Reply-To: macintosh@felix.UUCP (The Moderator) Organization: FileNet Corp., Costa Mesa, Ca. Lines: 327 Approved: bytebug@felix.UUCP (Roger L. Long) This is part 3 of 3 of "drawimp", a program that runs on Unix to convert MacDraw files into Impress commands for printing on Imagen laser printers. Allan Weber USC Signal and Image Processing Institute (213) 743-5519 Arpa: Weber%Brand@USC-Oberon.ARPA UUCP: ...sdcrdcf!usc-oberon!brand!weber --- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # README.SPCL # special.c # PicMacros.tex # This archive created: Mon Feb 2 11:06:56 1987 export PATH; PATH=/bin:$PATH if test -f 'README.SPCL' then echo shar: will not over-write existing file "'README.SPCL'" else cat << \SHAR_EOF > 'README.SPCL' Instruction for using putting MacDraw files in LaTeX documents The following files are needed to use the TeX/LaTeX option of drawimp. special.c - Handles the \special command for including files with Impress commands in the output stream. PicMacros.tex - TeX and LaTeX macros You must be using the "imagen1" dvi-to-impress driver in order to make this stuff work. This was the driver that came with the TeX distribution tape we purchased. There may be others that could be made to work also. Imagen1 handles \special's with a routine that reads the data and ignores it. Special.c has a new routine for handling the \special command and needs to be linked in with the rest of imagen1.c First, go into your copy of imagen1.c and find the routine "DoSpecial". Delete or comment out the DoSpecial in imagen1.c so the one in special.c will be used instead. Compile imagen1.c and special.c, link them together with whatever else is needed, and move imagen1 to where it will be found by the shell scripts that drive the Imagen printer. The following assumes something like MacTerminal and macget have been used to upload the MacDraw files to Unix. Normally this leaves three files on Unix for each Mac file, with extensions .data, .info, and .rsrc. The .info and .rsrc files can be deleted. Move all the .data files to one place and do % drawimp -t *.data This will cause drawimp to process each MacDraw .data file into a separate file containing Impress commands with the same name except ending in .imp. If there are text objects in any of the pictures, it is important that all the MacDraw files be processed together in this way. If a new picture is added later, they should all be processed again or the fonts used in the pictures will get mixed up. In the LaTeX file, pictures are include with lines like \DrawPicture{500}{200}{filename} The first and second arguments are the width and height respectively of the box area to reserve for the picture. They are specified in the current units as set by \setlength{\unitlength}{0.01in} or something similar. The picture can be larger or smaller than this, but LaTeX will reserve space according to these parameters. The top-left corner of the active area of the picture will be placed on the page at the top-left corner of the reserved area. The picture does not have to be pushed to the top-left of the MacDraw document page in order for drawimp to find it. The DrawPicture macro will center the reserved picture area horizontally on the page. The third parameter is the file name of the picture file as processed by "drawimp -t". See the macro definition for more info. Send any comments or bug reports to "Weber%Brand@USC-ECL.ARPA" Allan Weber USC Signal and Image Processing Inst. PHE 306, MC-0272 L.A., CA 90089-0272 (213) 743-5519 SHAR_EOF fi # end of overwriting check if test -f 'special.c' then echo shar: will not over-write existing file "'special.c'" else cat << \SHAR_EOF > 'special.c' /* Routines for handling \special commands. Currently only supports inserting impress data from external files. Bitmap stuff is not complete. Allan Weber (Weber%Brand@USC-ECL.ARPA) - 9/12/86 */ /* #define DEBUG */ #include #include extern char *malloc(); extern int errno; extern int ImHH, ImVV, hh, vv; int S_bitmap(); int S_impress(); char *nb(); struct spec { char *name; int (*func)(); } spectbl[] = { "bitmap", S_bitmap, "impress", S_impress, "", NULL }; /* Perform a \special */ DoSpecial (len) int len; /* length of the \special string */ { struct spec *s; char *p; register char ch, *p1, *p2; if (ImHH != hh || ImVV != vv) /* flush out any pending moves */ ImSetPosition (hh, vv); p1 = p = malloc(len + 1); while (len--) /* read the special string */ *p1++ = getc(stdin); *p1 = '\0'; #ifdef DEBUG fprintf(stderr,"special: '%s'\n",p); #endif p1 = nb(p); /* skip leading blanks */ if (*p1 == '\0') /* if nothing left, return */ return; p2 = p1; while ((ch = *p2) != '\0' && !isspace(ch)) /* find end of 1st word */ p2++; if (ch != '\0') { /* more than one word? */ *p2++ = '\0'; /* mark end of first word */ p2 = nb(p2); /* point to start of rest of string */ } s = spectbl; while (s->func != NULL) { if (strcmp(p1,s->name) == 0) { (s->func)(p1,p2); return; } else s++; } free(p); } /* split - separate the words in string s, placing a '\0' after each one and setting the elements of tok to point to the beginning of each word. Only do this for up to max words. Return the number of words found. */ static split(s,tok,max) register char *s; char *tok[]; { int i, n; register char ch; n = 0; for (i = 0; i < max; i++) { s = nb(s); /* find word start */ if ((ch = *s) != '\0') { /* did we find one? */ tok[i] = s; n++; while ((ch = *s) != '\0' && !isspace(ch)) s++; /* find end of word */ if (ch != '\0') /* mark end of word */ *s++ = '\0'; } else tok[i] = NULL; } return(n); } char *nb(s) char *s; { register char ch; while ((ch = *s) != '\0' && isspace(ch)) s++; return(s); } /* --------------------------------------------------------------------- */ static S_bitmap(s1, s2) char *s1, *s2; { int i, n, fd; int rows, cols, wrows, wcols, wroff, wcoff; char *p, *word[7]; #ifdef DEBUG fprintf(stderr,"in bitmap: s1='%s', s2='%s'\n",s1,s2); #endif p = malloc(strlen(s2) + 1); strcpy(p,s2); n = split(p,word,7); #ifdef DEBUG fprintf(stderr, "split into %d words\n",n); for (i = 0; i < n; i++) fprintf(stderr,"%d: '%s'\n",i,word[i]); #endif #ifndef DEBUG if ((fd = open(word[0], 0)) == -1) { error (1, errno, "can't open %s", s2); } if (n < 7) /* no window offset */ word[6] = word[5] = "0"; if (n < 5) { /* full window */ word[3] = word[1]; word[4] = word[2]; } if (n < 3) { /* need at least the dimensions */ error(1, 0, "\"\\special bitmap\" not enough arguments"); free(p); return; } rows = atoi(word[1]); cols = atoi(word[2]); wrows = atoi(word[3]); wcols = atoi(word[4]); wroff = atoi(word[5]); wcoff = atoi(word[6]); close(fd); #endif free(p); } static S_impress(s1, s2) char *s1, *s2; { FILE *fp; int n, h, v, ch; char *p, *word[3]; #ifdef DEBUG fprintf(stderr,"in impress: s1='%s', s2='%s'\n",s1,s2); #endif #ifndef DEBUG p = malloc(strlen(s2) + 1); strcpy(p,s2); n = split(p,word,3); if ((fp = fopen(word[0], "r")) == NULL) { error (1, errno, "can't open %s", word[0]); } putchar(211); /* push */ if (n == 3) { /* absolute move specified */ if (sscanf(word[1],"%d", &h) == 1) { putchar(135); putchar((h >> 8) & 255); putchar(h & 255); } if (sscanf(word[2],"%d", &v) == 1) { putchar(137); putchar((v >> 8) & 255); putchar(v & 255); } } while ((ch = getc(fp)) != EOF || !feof(fp)) putchar(ch); putchar(212); /* pop */ fclose(fp); #endif } SHAR_EOF fi # end of overwriting check if test -f 'PicMacros.tex' then echo shar: will not over-write existing file "'PicMacros.tex'" else cat << \SHAR_EOF > 'PicMacros.tex' \def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax} \ifundefined{newcommand} % define DrawPicture for TeX \long\gdef\DrawPicture#1#2#3 {\centerline {\vbox to #1pt {\hbox to #2pt {\special{impress #3}} } } } \else % define DrawPicture for LaTeX % output some impress data at current location on page \newcommand{\Impress}[1] { \makebox(0,0){\special{impress #1}} } % put a picture on page (use for multiple pictures across page) \newcommand{\PutPicture}[3] { \begin{picture}(#1,#2) \put(0,#2){\Impress{#3}} \end{picture} } % put a centered picture on page (use for single picture across page) \newcommand{\DrawPicture}[3] { \begin{center} \PutPicture{#1}{#2}{#3} \end{center} } \fi SHAR_EOF fi # end of overwriting check # End of shell archive exit 0 ---