home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / programs / amiga / mma2ltx / mma2ltx.c < prev    next >
C/C++ Source or Header  |  1994-09-01  |  31KB  |  816 lines

  1. /************************************************************************\
  2. *                                                                        *
  3. *   mma2ltc.c - Copyright (C) 1994 by Giuseppe Ghibo`                    *
  4. *                                                                        *
  5. *   version 1.2 - 16 July 1994                                           *
  6. *                                                                        *
  7. \************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <errno.h>
  13. #include <math.h>
  14. #include <time.h>
  15. #include <ctype.h>
  16.  
  17. typedef int bool;
  18. #ifndef TRUE
  19. #define TRUE 1
  20. #endif
  21. #ifndef FALSE
  22. #define FALSE 0
  23. #endif
  24.  
  25. #ifndef min
  26. #define min(a,b) (a<b ? a : b)
  27. #endif
  28. #ifndef max
  29. #define max(a,b) (a>b ? a : b)
  30. #endif
  31.  
  32. struct pnts {
  33.     float gx,gy,tx,ty;
  34. };
  35.  
  36. struct scaletrasl {
  37.     float Ax,Ay,Bx,By;
  38. };
  39.  
  40. struct cw {
  41.     float ctx,wtx,cgx,wgx,cty,wty,cgy,wgy;
  42. };
  43.  
  44. struct TeXunits {
  45.     float convfactor;
  46.     char *strunit;
  47. };
  48.  
  49. struct TeXunits TeXtable[] = {
  50.   {72.0/25.4,"mm"},                     /* mm to bp */
  51.   {72.0/2.54,"cm"},                     /* cm to bp */
  52.   {72.0/72.27,"pt"},                    /* pt to bp */
  53.   {1.0,"bp"},                           /* bp to bp */
  54.   {72.0/72.27*12.0,"pc"},               /* pc to bp */
  55.   {72.0,"in"},                          /* in to bp */
  56.   {1238.0/1157.0*72.0/72.27,"dd"},      /* dd to bp */
  57.   {1238.0/1157.0*12.0*72.0/72.27,"cc"}, /* cc to bp */
  58.   {72.0/72.27/65536.0,"sp"},            /* sp to bp */
  59.   {1.0,""}
  60. };
  61.  
  62. /* Prototypes */
  63. void Mlprun(float,float,struct cw *);
  64. void Mlp(float,float,struct scaletrasl *);
  65. void Mlp1(float,float,float,float,float,float,float *,float *,bool *);
  66. float strtobp(char *);
  67. float bptounit(char *);
  68. void stripext(char *,char *);
  69. char *strtolwr(char *);
  70.  
  71. #define NMAX 1000
  72. #define NMAXFILEIN 20 /* maximun number of files to process */
  73. #define TMPLEN 512
  74. #define PROLOG "texmma22.pro"
  75. #define OPTSWITCH1 '-'
  76. #define OPTSWITCH2 '/'
  77.  
  78. int np=0;
  79. struct pnts *p;
  80. char tmpbuf1[TMPLEN],tmpbuf2[TMPLEN];
  81. char texfname[256];
  82. bool Mnodistort = TRUE;              /* keep the aspect ratio ? */
  83.  
  84. /* This is the Mathematica v2.2 prologue file */
  85. char *prologue[] = {
  86. "/Mlmarg 0 def /Mrmarg 0 def /Mbmarg 0 def /Mtmarg 0 def /Mtransform{}\n",
  87. "bind def /Mfixwid true def /Mfixdash false def /Mrot 0 def /Mpstart{\n",
  88. "MathPictureStart}bind def /Mpend{MathPictureEnd}bind def /Mscale{0 1 0 1\n",
  89. "5 -1 roll MathScale}bind def /ISOLatin1Encoding dup where{pop pop}{[\n",
  90. "/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef\n",
  91. "/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef\n",
  92. "/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef\n",
  93. "/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef\n",
  94. "/space /exclam /quotedbl /numbersign /dollar /percent /ampersand\n",
  95. "/quoteright /parenleft /parenright /asterisk /plus /comma /minus /period\n",
  96. "/slash /zero /one /two /three /four /five /six /seven /eight /nine\n",
  97. "/colon /semicolon /less /equal /greater /question /at /A /B /C /D /E /F\n",
  98. "/G /H /I /J /K /L /M /N /O /P /Q /R /S /T /U /V /W /X /Y /Z /bracketleft\n",
  99. "/backslash /bracketright /asciicircum /underscore /quoteleft /a /b /c /d\n",
  100. "/e /f /g /h /i /j /k /l /m /n /o /p /q /r /s /t /u /v /w /x /y /z\n",
  101. "/braceleft /bar /braceright /asciitilde /.notdef /.notdef /.notdef\n",
  102. "/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef\n",
  103. "/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /dotlessi /grave\n",
  104. "/acute /circumflex /tilde /macron /breve /dotaccent /dieresis /.notdef\n",
  105. "/ring /cedilla /.notdef /hungarumlaut /ogonek /caron /space /exclamdown\n",
  106. "/cent /sterling /currency /yen /brokenbar /section /dieresis /copyright\n",
  107. "/ordfeminine /guillemotleft /logicalnot /hyphen /registered /macron\n",
  108. "/degree /plusminus /twosuperior /threesuperior /acute /mu /paragraph\n",
  109. "/periodcentered /cedilla /onesuperior /ordmasculine /guillemotright\n",
  110. "/onequarter /onehalf /threequarters /questiondown /Agrave /Aacute\n",
  111. "/Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute\n",
  112. "/Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth\n",
  113. "/Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply\n",
  114. "/Oslash /Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn\n",
  115. "/germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae\n",
  116. "/ccedilla /egrave /eacute /ecircumflex /edieresis /igrave /iacute\n",
  117. "/icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex\n",
  118. "/otilde /odieresis /divide /oslash /ugrave /uacute /ucircumflex\n",
  119. "/udieresis /yacute /thorn /ydieresis]def}ifelse /MFontDict 50 dict def\n",
  120. "/MStrCat{exch dup length 2 index length add string dup 3 1 roll copy\n",
  121. "length exch dup 4 2 roll exch putinterval}def /MCreateEncoding{1 index\n",
  122. "255 string cvs(-)MStrCat 1 index MStrCat cvn exch(Encoding)MStrCat cvn\n",
  123. "dup where{exch get}{pop StandardEncoding}ifelse 3 1 roll dup MFontDict\n",
  124. "exch known not{1 index findfont dup length dict begin{1 index /FID ne{\n",
  125. "def}{pop pop}ifelse}forall /Encoding 3 index def currentdict end 1 index\n",
  126. "exch definefont pop MFontDict 1 index null put}if exch pop exch pop}def\n",
  127. "/ISOLatin1{(ISOLatin1)MCreateEncoding}def /ISO8859{(ISOLatin1)\n",
  128. "MCreateEncoding}def /Mcopyfont{dup maxlength dict exch{1 index /FID eq{\n",
  129. "pop pop}{2 index 3 1 roll put}ifelse}forall}def /Plain /Courier findfont\n",
  130. "Mcopyfont definefont pop /Bold /Courier-Bold findfont Mcopyfont\n",
  131. "definefont pop /Italic /Courier-Oblique findfont Mcopyfont definefont\n",
  132. "pop /MathPictureStart{gsave Mtransform Mlmarg Mbmarg translate Mwidth\n",
  133. "Mlmarg Mrmarg add sub /Mwidth exch def Mheight Mbmarg Mtmarg add sub\n",
  134. "/Mheight exch def /Mtmatrix matrix currentmatrix def /Mgmatrix matrix\n",
  135. "currentmatrix def}bind def /MathPictureEnd{grestore}bind def /MFill{0 0\n",
  136. "moveto Mwidth 0 lineto Mwidth Mheight lineto 0 Mheight lineto fill}bind\n",
  137. "def /MPlotRegion{3 index Mwidth mul 2 index Mheight mul translate exch\n",
  138. "sub Mheight mul /Mheight exch def exch sub Mwidth mul /Mwidth exch def}\n",
  139. "bind def /MathSubStart{Momatrix Mgmatrix Mtmatrix Mwidth Mheight 7 -2\n",
  140. "roll moveto Mtmatrix setmatrix currentpoint Mgmatrix setmatrix 9 -2 roll\n",
  141. "moveto Mtmatrix setmatrix currentpoint 2 copy translate /Mtmatrix matrix\n",
  142. "currentmatrix def 3 -1 roll exch sub /Mheight exch def sub /Mwidth exch\n",
  143. "def}bind def /MathSubEnd{/Mheight exch def /Mwidth exch def /Mtmatrix\n",
  144. "exch def dup setmatrix /Mgmatrix exch def /Momatrix exch def}bind def\n",
  145. "/Mdot{moveto 0 0 rlineto stroke}bind def /Mtetra{moveto lineto lineto\n",
  146. "lineto fill}bind def /Metetra{moveto lineto lineto lineto closepath\n",
  147. "gsave fill grestore 0 setgray stroke}bind def /Mistroke{flattenpath 0 0\n",
  148. "0{4 2 roll pop pop}{4 -1 roll 2 index sub dup mul 4 -1 roll 2 index sub\n",
  149. "dup mul add sqrt 4 -1 roll add 3 1 roll}{stop}{stop}pathforall pop pop\n",
  150. "currentpoint stroke moveto currentdash 3 -1 roll add setdash}bind def\n",
  151. "/Mfstroke{stroke currentdash pop 0 setdash}bind def /Mrotsboxa{gsave dup\n",
  152. "/Mrot exch def Mrotcheck Mtmatrix dup setmatrix 7 1 roll 4 index 4 index\n",
  153. "translate rotate 3 index -1 mul 3 index -1 mul translate /Mtmatrix\n",
  154. "matrix currentmatrix def grestore Msboxa 3 -1 roll /Mtmatrix exch def\n",
  155. "/Mrot 0 def}bind def /Msboxa{newpath 5 -1 roll Mvboxa pop Mboxout 6 -1\n",
  156. "roll 5 -1 roll 4 -1 roll Msboxa1 5 -3 roll Msboxa1 Mboxrot[7 -2 roll 2\n",
  157. "copy[3 1 roll 10 -1 roll 9 -1 roll]6 1 roll 5 -2 roll]}bind def /Msboxa1\n",
  158. "{sub 2 div dup 2 index 1 add mul 3 -1 roll -1 add 3 -1 roll mul}bind def\n",
  159. "/Mvboxa{Mfixwid{Mvboxa1}{dup Mwidthcal 0 exch{add}forall exch Mvboxa1 4\n",
  160. "index 7 -1 roll add 4 -1 roll pop 3 1 roll}ifelse}bind def /Mvboxa1{\n",
  161. "gsave newpath[true 3 -1 roll{Mbbox 5 -1 roll{0 5 1 roll}{7 -1 roll exch\n",
  162. "sub(m)stringwidth pop .3 mul sub 7 1 roll 6 -1 roll 4 -1 roll