home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / SpecHost / Parse.c < prev    next >
C/C++ Source or Header  |  1994-10-07  |  23KB  |  1,068 lines

  1. /*
  2. **    SpecialHost for PasTeX
  3. **
  4. **    Copyright © by Olaf Barthel & Georg Heßmann
  5. */
  6.  
  7. /*
  8. ** Parse.c
  9. **
  10. ** latest revision: 7 Oct 1994, by Giuseppe Ghibò
  11. */
  12.  
  13. #include "Global.h"
  14.  
  15. STATIC VOID __regargs Parse_PSLit(STRPTR SpecialString, struct parse_result *Result);
  16. BOOL __regargs Add_Extra_Transf(int transformation, float arg_x, float arg_y);
  17. BOOL __regargs Del_Extra_Transf(int transformation);
  18. VOID __regargs Init_Extra_Transf(VOID);
  19.  
  20. LONG    psfig_status = PSFIG_OFF;
  21. STATIC    BYTE psfig_name[MAX_FILENAME_LEN] = { '\0' };
  22. struct    psfig_data psfig_data;
  23.  
  24. enum    {    ARG_IFFFILE,ARG_PSFILE,ARG_HSIZE,ARG_VSIZE,ARG_HOFFSET,
  25.         ARG_VOFFSET,ARG_SCALE,ARG_HSCALE,ARG_VSCALE,ARG_ANGLE,ARG_CLIP,ARG_MODE,
  26.         ARG_BRIGHT,ARG_CONTRAST,ARG_GAMMA,ARG_RED,ARG_GREEN,ARG_BLUE,
  27.         ARG_TRANSFER,ARG_RENDERING,ARG_INVERT,ARG_BASEDPI,ARG_THRESHOLD,
  28.         ARG_PATCHCOLOURS,ARG_LLX,ARG_LLY,ARG_URX,ARG_URY,ARG_RWI,ARG_RHI,
  29.         ARG_DITHEROPT,ARG_PSINITSTRING,ARG_PSINITFILE,ARG_HEADER,ARG_PSLIT,
  30. //              ARG_PSLITQUOTE,
  31.         ARGCOUNT
  32.     };
  33.  
  34. #define TEMPLATE "IMAGE=IFFFILE/K,PSFILE/K,HSIZE/K,VSIZE/K,HOFFSET/K,VOFFSET/K,SCALE=/K,HSCALE/K,VSCALE/K,ANGLE/K,CLIP/S,MODE/K,BRIGHT/K,CONTRAST/K,GAMMA/K,RED/K,GREEN/K,BLUE/K,TRANSFER/K,RENDER/K,INVERT/K,BASEDPI/K,THRESHOLD/K,PATCH=PATCHCOLOURS/S,LLX/K,LLY/K,URX/K,URY/K,RWI/K,RHI/K,DITHEROPT/K/N,PSINITSTRING/K,PSINITFILE/K,HEADER=PROLOG/K,PS:=PS::/F"
  35.  
  36. STATIC BOOL __regargs
  37. GetDimension(STRPTR Argument, float *Storage, float Unit, LONG DVI_mag)
  38. {
  39.     UBYTE LocalBuffer[40];
  40.     LONG Len;
  41.     float mag = (float)DVI_mag / 1000.0;
  42.  
  43.     memcpy(LocalBuffer,Argument,39);
  44.  
  45.     LocalBuffer[39] = 0;
  46.  
  47.     Len = strlen(LocalBuffer);
  48.  
  49.     while(Len > 0 && LocalBuffer[Len - 1] == ' ')
  50.         Len--; /* remove trailing spaces */
  51.  
  52.     LocalBuffer[Len] = 0;
  53.  
  54.     if(Len > 2) /* if(Len > 2 && isalpha(LocalBuffer[Len-1])) */
  55.     {
  56.         STATIC struct { STRPTR Name; float Unit; } UnitTable[] =
  57.         {
  58.             "pt",    72.27,
  59.             "pc",    6.0225,     /* 72.27/12.0 */
  60.             "in",    1.0,
  61.             "bp",    72.0,
  62.             "cm",    2.54,
  63.             "mm",    25.4,
  64.             "dd",    67.5415105, /* 72.27*1157.0/1238.0 */
  65.             "cc",    5.6284592,  /* 72.27*1157.0/1238.0/12.0 */
  66.                         "sp",   4736286.72  /* 72.27 * 65536.0 */
  67.         };
  68.  
  69.         LONG i;
  70.  
  71.         for(i = 0 ; i < 9 ; i++)
  72.         {
  73.             if(!Stricmp(&LocalBuffer[Len - 2],UnitTable[i] . Name))
  74.             {
  75.                 Unit = UnitTable[i] . Unit;
  76.  
  77.                 if (Len > 6)
  78.                 {
  79.                     if (!strncmp(&LocalBuffer[Len - 6], "true", 4))
  80.                     {
  81.                         Unit *= mag;
  82.                         LocalBuffer[Len - 6] = 0;
  83.                     }
  84.                 }
  85.                 else
  86.                     LocalBuffer[Len - 2] = 0;
  87.  
  88.                 break;
  89.             }
  90.         }
  91.     }
  92.  
  93.     *Storage = atof(LocalBuffer);
  94.  
  95.     switch(_FPERR)
  96.     {
  97.         case 0:
  98.  
  99.             *Storage /= Unit;
  100.  
  101.             return(TRUE);
  102.  
  103.         case _FPEUND:
  104.  
  105.             PrintLine("\33bFloating point underflow \"%s\".\33n",Argument);
  106.             return(FALSE);
  107.  
  108.         case _FPEOVF:
  109.  
  110.             PrintLine("\33bFloating point overflow \"%s\".\33n",Argument);
  111.             return(FALSE);
  112.  
  113.         case _FPEZDV:
  114.  
  115.             PrintLine("\33bDivision by zero \"%s\".\33n",Argument);
  116.             return(FALSE);
  117.  
  118.         case _FPENAN:
  119.  
  120.             PrintLine("\33bInvalid operation \"%s\".\33n",Argument);
  121.             return(FALSE);
  122.  
  123.         case _FPECOM:
  124.  
  125.             PrintLine("\33bFloating point value not comparable \"%s\".\33n",Argument);
  126.             return(FALSE);
  127.     }
  128. }
  129.  
  130. STATIC BOOL __regargs
  131. GetScale(STRPTR Argument,float *Storage, float Unit)
  132. {
  133.     *Storage = atof(Argument);
  134.  
  135.     switch(_FPERR)
  136.     {
  137.         case 0:
  138.  
  139.             if(*Storage <= 0.0)
  140.             {
  141.                 PrintLine("\33bIllegal scale value \"%s\".\33n",Argument);
  142.  
  143.                 return(FALSE);
  144.             }
  145.             else
  146.             {
  147.                 *Storage /= Unit;
  148.  
  149.                 return(TRUE);
  150.             }
  151.  
  152.         case _FPEUND:
  153.  
  154.             PrintLine("\33bFloating point underflow \"%s\".\33n",Argument);
  155.             return(FALSE);
  156.  
  157.         case _FPEOVF:
  158.  
  159.             PrintLine("\33bFloating point overflow \"%s\".\33n",Argument);
  160.             return(FALSE);
  161.  
  162.         case _FPEZDV:
  163.  
  164.             PrintLine("\33bDivision by zero \"%s\".\33n",Argument);
  165.             return(FALSE);
  166.  
  167.         case _FPENAN:
  168.  
  169.             PrintLine("\33bInvalid operation \"%s\".\33n",Argument);
  170.             return(FALSE);
  171.  
  172.         case _FPECOM:
  173.  
  174.             PrintLine("\33bFloating point value not comparable \"%s\".\33n",Argument);
  175.             return(FALSE);
  176.     }
  177. }
  178.  
  179. STATIC BOOL __regargs
  180. GetInteger(STRPTR Argument,LONG *Storage,LONG Min,LONG Max)
  181. {
  182.     if(StrToLong(Argument,Storage) < 1)
  183.     {
  184.         PrintLine("\33bIllegal value \"%s\".\33n",Argument);
  185.  
  186.         return(FALSE);
  187.     }
  188.     else
  189.     {
  190.         if(Min != Max)
  191.         {
  192.             if(*Storage < Min)
  193.                 *Storage = Min;
  194.             else
  195.             {
  196.                 if(*Storage > Max)
  197.                     *Storage = Max;
  198.             }
  199.         }
  200.  
  201.         return(TRUE);
  202.     }
  203. }
  204.  
  205. BOOL
  206. ParseSpecial(STRPTR OldString,struct parse_result *Result)
  207. {
  208.     STRPTR NewString;
  209.     LONG Len = strlen(OldString);
  210.     BOOL Success = FALSE;
  211.  
  212.     if(NewString = (STRPTR)AllocVecPooled(Len + 2,MEMF_ANY))
  213.     {
  214.         STRPTR Args[ARGCOUNT];
  215.         struct RDArgs *ArgsPtr;
  216.  
  217.         memset(Args,0,sizeof(Args));
  218.  
  219.         while(*OldString == ' ')
  220.             OldString++;
  221.  
  222.         strcpy(NewString,OldString);
  223.  
  224.         Len = strlen(NewString);
  225.  
  226.         while(Len > 0 && NewString[Len - 1] == ' ')
  227.             Len--;
  228.  
  229.         NewString[Len] = '\n';
  230.         NewString[Len + 1] = 0;
  231.  
  232.         if(ArgsPtr = (struct RDArgs *)AllocDosObjectTags(DOS_RDARGS,TAG_DONE))
  233.         {
  234.                 /* Don't prompt for input! */
  235.     
  236.             ArgsPtr -> RDA_Flags |= RDAF_NOPROMPT;
  237.     
  238.                 /* Set up for local parsing. */
  239.     
  240.             ArgsPtr -> RDA_Source . CS_Buffer    = NewString;
  241.             ArgsPtr -> RDA_Source . CS_Length    = Len + 1;
  242.             ArgsPtr -> RDA_Source . CS_CurChr    = 0;
  243.     
  244.                 /* Read the arguments. */
  245.     
  246.             if(ReadArgs(TEMPLATE,(LONG *)Args,ArgsPtr))
  247.             {
  248.                 BOOL    PostScript;
  249.                 float    Unit;
  250.                 float    ScaleUnit;
  251.  
  252.                 if(Args[ARG_PATCHCOLOURS])
  253.                     Result -> patch_colours = TRUE;
  254.  
  255.                 if(Args[ARG_DITHEROPT])
  256.                     Result -> dither_opt = *(LONG *)Args[ARG_DITHEROPT];
  257.  
  258.                 if(Args[ARG_PSINITSTRING])
  259.                     strcpy(Result -> psinit_string,Args[ARG_PSINITSTRING]);
  260.  
  261.                 if(Args[ARG_PSINITFILE])
  262.                     strcpy(Result -> psinit_file,Args[ARG_PSINITFILE]);
  263.  
  264.                 if(Args[ARG_IFFFILE] && Args[ARG_PSFILE])
  265.                     PrintLine("\33bYou can either use \"IFFFILE=...\" or \"PSFILE=...\" but not both.\33n");
  266.                 else
  267.                 {
  268.                     Success = TRUE;
  269.  
  270.                     if(Args[ARG_IFFFILE])
  271.                     {
  272.                         strcpy(Result -> iffile,Args[ARG_IFFFILE]);
  273.  
  274.                         Unit = 1.0;    // `small points'
  275.  
  276.                         ScaleUnit = 1.0;
  277.  
  278.                         PostScript = FALSE;
  279.                     }
  280.  
  281.                     if(Args[ARG_PSFILE])
  282.                     {
  283.                         strcpy(Result -> psfile,Args[ARG_PSFILE]);
  284.  
  285.                         Unit = 72.0;    // `big points'
  286.  
  287.                         ScaleUnit = 100.0; // percentage unit
  288.  
  289.                         PostScript = TRUE;
  290.                     }
  291.                 }
  292.  
  293.                 if(Args[ARG_HEADER])
  294.                     Add_PSHeaderName(Args[ARG_HEADER]);
  295.  
  296.                 if(Args[ARG_PSLIT])
  297.                 {
  298.                     Parse_PSLit(Args[ARG_PSLIT], Result);
  299.                 }
  300.  
  301.                 if(Args[ARG_HSIZE])
  302.                 {
  303.                     if(Success = GetDimension(Args[ARG_HSIZE], &Result -> hsize, Unit, Result -> DVI_mag))
  304.                         Result -> gotcontrol |= GOT_HSIZE;
  305.                 }
  306.  
  307.                 if(Args[ARG_VSIZE] && Success)
  308.                 {
  309.                     if(Success = GetDimension(Args[ARG_VSIZE], &Result -> vsize, Unit, Result -> DVI_mag))
  310.                         Result -> gotcontrol |= GOT_VSIZE;
  311.                 }
  312.  
  313.                 if(Args[ARG_HOFFSET] && Success)
  314.                 {
  315.                     if(Success = GetDimension(Args[ARG_HOFFSET], &Result -> hoffset, Unit, Result -> DVI_mag))
  316.                         Result -> gotcontrol |= GOT_HOFFSET;
  317.                 }
  318.  
  319.                 if(Args[ARG_VOFFSET] && Success)
  320.                 {
  321.                     if(Success = GetDimension(Args[ARG_VOFFSET], &Result -> voffset, Unit, Result -> DVI_mag))
  322.                         Result -> gotcontrol |= GOT_VOFFSET;
  323.                 }
  324.  
  325.                 if(Args[ARG_SCALE] && Success)
  326.                 {
  327.                     if(Success = GetScale(Args[ARG_SCALE],&Result -> scale, 1.0f))
  328.                         Result -> gotcontrol |= GOT_SCALE;
  329.                 }
  330.  
  331.                 if(Args[ARG_HSCALE] && Success)
  332.                 {
  333.                     if (Success = GetScale(Args[ARG_HSCALE],&Result -> hscale,ScaleUnit))
  334.                         Result -> gotcontrol |= GOT_HSCALE;
  335.                 }
  336.  
  337.                 if(Args[ARG_VSCALE] && Success)
  338.                 {
  339.                     if(Success = GetScale(Args[ARG_VSCALE],&Result -> vscale,ScaleUnit))
  340.                         Result -> gotcontrol |= GOT_VSCALE;
  341.                 }
  342.  
  343.                 if(Args[ARG_MODE] && Success)
  344.                 {
  345.                     STATIC struct { STRPTR Name; LONG Mode; } ModeTable[] =
  346.                     {
  347.                         "bw",        BandW,
  348.                         "gray",        FS,
  349.                         "fs",        FS,
  350.                         "burkes",    Burkes,
  351.                         "sierra",    Sierra,
  352.                         "jarvis",    JJN,
  353.                         "jjn",        JJN,
  354.                         "whitenoise",    RandomNoise,
  355.                         "bluenoise",    BlueNoise,
  356.                         "stucki",    Stucki,
  357.                         "ordered",    Ordered,
  358.                         "halftone",    Halftone,
  359.                         "random",    RandomNoise,
  360.                         "bckbrick",    BckBrick,
  361.                         "fwdbrick",    FwdBrick,
  362.                         "hexagon",    Hexagon,
  363.                         "spiraldot",    SpiralDot,
  364.                         "horizontal",    Horizontal,
  365.                         "stevenson",    StevensonArce,
  366.                         "sa",        StevensonArce
  367.                     };
  368.  
  369.                     LONG i;
  370.  
  371.                     Success = FALSE;
  372.  
  373.                     for(i = 0 ; i < 20 ; i++)
  374.                     {
  375.                         if(!Stricmp(Args[ARG_MODE],ModeTable[i] . Name))
  376.                         {
  377.                             Result -> mode = ModeTable[i] . Mode;
  378.  
  379.                             Success = TRUE;
  380.  
  381.                             break;
  382.                         }
  383.                     }
  384.  
  385.                     if(!Success)
  386.                         PrintLine("\33bUnknown shading mode \"%s\".\33n",Args[ARG_MODE]);
  387.                 }
  388.  
  389.                 if(Args[ARG_LLX] && Success)
  390.                 {
  391.                     if(Success = GetDimension(Args[ARG_LLX], &Result -> llx, Unit, Result -> DVI_mag))
  392.                             Result -> gotcontrol |= GOT_LLX;
  393.                 }
  394.  
  395.                 if(Args[ARG_LLY] && Success)
  396.                 {
  397.                     if(Success = GetDimension(Args[ARG_LLY], &Result -> lly, Unit, Result -> DVI_mag))
  398.                         Result -> gotcontrol |= GOT_LLY;
  399.                 }
  400.  
  401.                 if(Args[ARG_URX] && Success)
  402.                 {
  403.                     if(Success = GetDimension(Args[ARG_URX], &Result -> urx, Unit, Result -> DVI_mag))
  404.                         Result -> gotcontrol |= GOT_URX;
  405.                 }
  406.  
  407.                 if(Args[ARG_URY] && Success)
  408.                 {
  409.                     if(Success = GetDimension(Args[ARG_URY], &Result -> ury, Unit, Result -> DVI_mag))
  410.                         Result -> gotcontrol |= GOT_URY;
  411.                 }
  412.  
  413.                 if(Args[ARG_RWI] && Success)
  414.                 {
  415.                     if(Success = GetDimension(Args[ARG_RWI], &Result -> rwi, Unit, Result -> DVI_mag))
  416.                         Result -> gotcontrol |= GOT_RWI;
  417.                 }
  418.  
  419.                 if(Args[ARG_RHI] && Success)
  420.                 {
  421.                     if(Success = GetDimension(Args[ARG_RHI], &Result -> rhi, Unit, Result -> DVI_mag))
  422.                         Result -> gotcontrol |= GOT_RHI;
  423.                 }
  424.  
  425.                 if (PostScript && Args[ARG_ANGLE])
  426.                 {
  427.                     if(Success = GetDimension(Args[ARG_ANGLE], &Result -> angle, 1.0f, 1000L))
  428.                         Result -> gotcontrol |= GOT_ANGLE;
  429.                 }
  430.  
  431.                 if (PostScript && Args[ARG_CLIP])
  432.                         Result -> gotcontrol |= GOT_CLIP;
  433.  
  434.                 if(Args[ARG_BRIGHT] && Success)
  435.                     Success = GetInteger(Args[ARG_BRIGHT],&Result -> bright,-100,100);
  436.  
  437.                 if(Args[ARG_CONTRAST] && Success)
  438.                     Success = GetInteger(Args[ARG_CONTRAST],&Result -> contrast,-100,100);
  439.  
  440.                 if(Args[ARG_GAMMA] && Success)
  441.                     Success = GetInteger(Args[ARG_GAMMA],&Result -> gamma,-100,100);
  442.  
  443.                 if(Args[ARG_RED] && Success)
  444.                     Success = GetInteger(Args[ARG_RED],&Result -> red,0,100);
  445.  
  446.                 if(Args[ARG_GREEN] && Success)
  447.                     Success = GetInteger(Args[ARG_GREEN],&Result -> green,0,100);
  448.  
  449.                 if(Args[ARG_BLUE] && Success)
  450.                     Success = GetInteger(Args[ARG_BLUE],&Result -> blue,0,100);
  451.  
  452.                 if(Args[ARG_BASEDPI] && Success)
  453.                     Success = GetInteger(Args[ARG_BASEDPI],&Result -> base_dpi,0,1000000);
  454.  
  455.                 if(Args[ARG_THRESHOLD] && Success)
  456.                     Success = GetInteger(Args[ARG_THRESHOLD],&Result -> threshold,0,100);
  457.  
  458.                 if(Args[ARG_TRANSFER] && Success)
  459.                 {
  460.                     STATIC struct { STRPTR Name; LONG Mode; } TransferTable[] =
  461.                     {
  462.                         "memory",    CYID_Transfer_Memory,
  463.                         "file",        CYID_Transfer_Disk,
  464.                         "none",        CYID_Transfer_None
  465.                     };
  466.  
  467.                     LONG i;
  468.  
  469.                     Success = FALSE;
  470.  
  471.                     for(i = 0 ; i < 3 ; i++)
  472.                     {
  473.                         if(!Stricmp(Args[ARG_TRANSFER],TransferTable[i] . Name))
  474.                         {
  475.                             Result -> transfer = TransferTable[i] . Mode;
  476.  
  477.                             Success = TRUE;
  478.  
  479.                             break;
  480.                         }
  481.                     }
  482.  
  483.                     if(!Success)
  484.                         PrintLine("\33bUnknown transfer mode \"%s\".\33n",Args[ARG_TRANSFER]);
  485.                 }
  486.  
  487.                 if(Args[ARG_RENDERING] && Success)
  488.                 {
  489.                     STATIC struct { STRPTR Name; LONG Mode; } RenderTable[] =
  490.                     {
  491.                         "plain",    CYID_Render_None,
  492.                         "frame",    CYID_Render_Frame,
  493.                         "clear",    CYID_Render_Clear
  494.                     };
  495.  
  496.                     LONG i;
  497.  
  498.                     Success = FALSE;
  499.  
  500.                     for(i = 0 ; i < 3 ; i++)
  501.                     {
  502.                         if(!Stricmp(Args[ARG_RENDERING],RenderTable[i] . Name))
  503.                         {
  504.                             Result -> rendering = RenderTable[i] . Mode;
  505.  
  506.                             Success = TRUE;
  507.  
  508.                             break;
  509.                         }
  510.                     }
  511.  
  512.                     if(!Success)
  513.                         PrintLine("\33bUnknown render mode \"%s\".\33n",Args[ARG_RENDERING]);
  514.                 }
  515.  
  516.                 if(Args[ARG_INVERT] && Success)
  517.                 {
  518.                     STATIC struct { STRPTR Name; LONG Mode; } InvertTable[] =
  519.                     {
  520.                         "on",        TRUE,
  521.                         "yes",        TRUE,
  522.                         "true",        TRUE,
  523.                         "1",        TRUE,
  524.                         "off",        FALSE,
  525.                         "no",        FALSE,
  526.                         "false",    FALSE,
  527.                         "0",        FALSE
  528.                     };
  529.  
  530.                     LONG i;
  531.  
  532.                     Success = FALSE;
  533.  
  534.                     for(i = 0 ; i < 8 ; i++)
  535.                     {
  536.                         if(!Stricmp(Args[ARG_INVERT],InvertTable[i] . Name))
  537.                         {
  538.                             Result -> invert = InvertTable[i] . Mode;
  539.  
  540.                             Success = TRUE;
  541.  
  542.                             break;
  543.                         }
  544.                     }
  545.  
  546.                     if(!Success)
  547.                         PrintLine("\33bUnknown invert mode \"%s\".\33n",Args[ARG_INVERT]);
  548.                 }
  549.  
  550.                 FreeArgs(ArgsPtr);
  551.             }
  552.             else
  553.             {
  554.                 UBYTE LocalBuffer[256];
  555.  
  556.                 Fault(IoErr(),"",LocalBuffer,256);
  557.  
  558.                 PrintLine("\33bParsing error: %s\33n",LocalBuffer + 2);
  559.             }
  560.  
  561.             FreeDosObject(DOS_RDARGS,ArgsPtr);
  562.         }
  563.  
  564.         FreeVecPooled(NewString);
  565.     }
  566.  
  567.     return(Success);
  568. }
  569.  
  570. /* (ghi) Parse_PSLit(): parse psfig specials and a small set of literal
  571.    PostScript specials. */
  572. STATIC VOID __regargs
  573. Parse_PSLit(STRPTR SpecialString, struct parse_result *Result)
  574. {
  575.     BOOL Success = TRUE;
  576.     STRPTR String, Buffer, *array;
  577.     STATIC float new_xpos = 0.0, new_ypos = 0.0;
  578.  
  579.     if (!(String = AllocVecPooled(strlen(SpecialString)+1L, MEMF_ANY)))
  580.         return;
  581.  
  582.     if (!(Buffer = AllocVecPooled(8192L, MEMF_ANY)))
  583.     {
  584.         FreeVecPooled(String);
  585.         return;
  586.     }
  587.  
  588.     if (!Extra_Transf)
  589.     {
  590.         ET_CurrentPoint_x = (float) Result -> current_x / Result -> hres;
  591.         ET_CurrentPoint_y = (float) Result -> current_y / Result -> vres;
  592.         new_xpos = new_ypos = 0.0;
  593.     }
  594.     else
  595.     {
  596.         new_xpos = (float) Result -> current_x / Result -> hres - ET_CurrentPoint_x;
  597.         new_ypos = - (float) Result -> current_y / Result -> vres + ET_CurrentPoint_y;
  598.     }
  599.  
  600.     strcpy(String, SpecialString);
  601.     array = StrToArray(String, " ", Buffer, 8192L);
  602.     FreeVecPooled(String);
  603.  
  604.     if (!strcmp(array[0],"gsave"))
  605.     {
  606.         float angle = 0.0;
  607.         int i;
  608.         STATIC STRPTR RotTable[] =
  609.         {
  610.             "gsave",
  611.             "currentpoint",
  612.             "currentpoint",
  613.             "translate",
  614.             "*",
  615.             "neg",
  616.             "rotate",
  617.             "neg",
  618.             "exch",
  619.             "neg",
  620.             "exch",
  621.             "translate"
  622.         };
  623.  
  624.         for (i = 1; i < 12; i++)
  625.         {
  626.             if (array[i])
  627.             {
  628.                 if (!strcmp(RotTable[i],"*"))
  629.                 {
  630.                     angle = atof(array[i]);
  631.                     Success = TRUE;
  632.                 }
  633.                 else
  634.                 {
  635.                     if (strcmp(array[i],RotTable[i]) != 0)
  636.                     {
  637.                         PrintLine("\33bps: gsave ... Syntax Error, unknown keyword \"%s\"!\33n",array[i]);
  638.                         Success = FALSE;
  639.                         break;
  640.                     }
  641.                 }
  642.             }
  643.             else
  644.             {
  645.                 PrintLine("\33bps: gsave ... not enough arguments, needed 12 found %ld!\33n",i);
  646.                 Success = FALSE;
  647.                 break;
  648.             }
  649.         }
  650.         if (Success)
  651.         {
  652.             if (!Add_Extra_Transf(TR_TRANSLATION, new_xpos, new_ypos) ||
  653.                 !Add_Extra_Transf(TR_ROTATION, RAD(angle), 0.0f) ||
  654.                 !Add_Extra_Transf(TR_TRANSLATION, (float)-new_xpos, (float)-new_ypos))
  655.             {
  656.                 PrintLine("\33bps: gsave ... can't execute extra rotation!\33n");
  657.                 Success = FALSE;
  658.             }
  659.             else
  660.             {
  661.                 PrintLine("Added extra rotation.");
  662.             }
  663.         }
  664.     }
  665.     else if (!strcmp(array[0],"currentpoint"))
  666.     {
  667.         int count = 0;
  668.  
  669.         while (array[count])
  670.             count++; /* count arguments */
  671.  
  672.         if (count > 15)
  673.         {
  674.             PrintLine("\33bps: currentpoint... Too many arguments!\33n");
  675.             Success = FALSE;
  676.         }
  677.         else if (count == 3)
  678.         {
  679.             if (!strcmp(array[1],"grestore") && !strcmp(array[2],"moveto"))
  680.             {
  681.                 if (!Del_Extra_Transf(TR_TRANSLATION) ||
  682.                     !Del_Extra_Transf(TR_ROTATION) ||
  683.                     !Del_Extra_Transf(TR_TRANSLATION))
  684.                 {
  685.                     PrintLine("\33bps: currentpoint grestore moveto, doesn't match last transformation!\33n");
  686.                     PrintLine("\33bExtra Transformation Matrix re-initialized.\33n");
  687.                     Init_Extra_Transf();
  688.                     Success = FALSE;
  689.                 }
  690.                 else
  691.                 {
  692.                     PrintLine("Removed extra rotation.");
  693.                     Success = TRUE;
  694.                 }
  695.             }
  696.             else
  697.             {
  698.                 PrintLine("\33bps: currentpoint %s %s, Unknown keywords.\33n",array[1],array[2]);
  699.                 Success = FALSE;
  700.             }
  701.  
  702.         }
  703.         else if (count == 11)
  704.         {
  705.             float xscale = 0.0, yscale = 0.0;
  706.             int i;
  707.             STATIC STRPTR ScaleTable[] =
  708.             {
  709.                 "currentpoint",
  710.                 "currentpoint",
  711.                 "translate",
  712.                 "*x",
  713.                 "*y",
  714.                 "scale",
  715.                 "neg",
  716.                 "exch",
  717.                 "neg",
  718.                 "exch",
  719.                 "translate"
  720.             };
  721.  
  722.             for (i = 0; i < count; i++)
  723.             {
  724.                 if (!strcmp(ScaleTable[i],"*x"))
  725.                 {
  726.                     xscale = atof(array[i]);
  727.                     Success = TRUE;
  728.                 }
  729.                 else if (!strcmp(ScaleTable[i],"*y"))
  730.                 {
  731.                     yscale = atof(array[i]);
  732.                     Success = TRUE;
  733.                 }
  734.                 else
  735.                 {
  736.                     if (strcmp(array[i],ScaleTable[i]) != 0)
  737.                     {
  738.                         PrintLine("\33bps: %s ... Syntax Error, unknown keyword \"%s\"!\33n",array[0],array[i]);
  739.                         Success = FALSE;
  740.                         break;
  741.                     }
  742.                 }
  743.             }
  744.             if (Success)
  745.             {
  746.                 if (!Add_Extra_Transf(TR_TRANSLATION, new_xpos, new_ypos) ||
  747.                     !Add_Extra_Transf(TR_SCALING, xscale, yscale) ||
  748.                     !Add_Extra_Transf(TR_TRANSLATION, (float)-new_xpos, (float)-new_ypos))
  749.                 {
  750.                     PrintLine("\33bps: %s ... can't execute extra scaling!\33n",array[0]);
  751.                     Success = FALSE;
  752.                 }
  753.                 else
  754.                 {
  755.                     PrintLine("Added extra scaling.");
  756.                 }
  757.             }
  758.         }
  759.         else if (count == 15)
  760.         {
  761.             float xunscale = 0.0, yunscale = 0.0;
  762.             int i;
  763.             STATIC STRPTR UnScaleTable[] =
  764.             {
  765.                 "currentpoint",
  766.                 "currentpoint",
  767.                 "translate",
  768.                 "1",
  769.                 "*x",
  770.                 "div",
  771.                 "1",
  772.                 "*y",
  773.                 "div",
  774.                 "scale",
  775.                 "neg",
  776.                 "exch",
  777.                 "neg",
  778.                 "exch",
  779.                 "translate"
  780.             };
  781.  
  782.             for (i = 0; i < count; i++)
  783.             {
  784.                 if (!strcmp(UnScaleTable[i],"*x"))
  785.                 {
  786.                     xunscale = atof(array[i]);
  787.                     Success = TRUE;
  788.                 }
  789.                 else if (!strcmp(UnScaleTable[i],"*y"))
  790.                 {
  791.                     yunscale = atof(array[i]);
  792.                     Success = TRUE;
  793.                 }
  794.                 else
  795.                 {
  796.                     if (strcmp(array[i],UnScaleTable[i]) != 0)
  797.                     {
  798.                         PrintLine("\33bps: %s ... Syntax Error, unknown keyword \"%s\"!\33n",array[0],array[i]);
  799.                         Success = FALSE;
  800.                         break;
  801.                     }
  802.                 }
  803.             }
  804.             if (Success)
  805.             {
  806.                 if (!Del_Extra_Transf(TR_TRANSLATION) ||
  807.                     !Del_Extra_Transf(TR_SCALING) ||
  808.                     !Del_Extra_Transf(TR_TRANSLATION))
  809.                 {
  810.                     PrintLine("\33bps: currentpoint ..., doesn't match last transformation!\33n");
  811.                     PrintLine("\33bExtra Transformation Matrix re-initialized.\33n");
  812.                     Init_Extra_Transf();
  813.                     Success = FALSE;
  814.                 }
  815.                 else
  816.                 {
  817.                     PrintLine("Removed extra scaling.");
  818.                 }
  819.             }
  820.         }
  821.         else
  822.         {
  823.             PrintLine("\33bps: %s, Literal PostScript Special: Syntax Unknown!\33n",array[0]);
  824.             Success = FALSE;
  825.         }
  826.     }
  827.     else if (!Stricmp(array[0],"ps::[begin]"))
  828.     {
  829.         int i;
  830.         LONG value[6];
  831.  
  832.         for (i = 1 ; i < 7; i++) {
  833.             if (array[i])
  834.             {
  835.                 if (StrToLong(array[i],&value[i-1]) < 1)
  836.                 {
  837.                     PrintLine("\33bps::[begin] Syntax Unknown: Illegal value \"%s\".\33n",array[i]);
  838.                     Success = FALSE;
  839.                     break;
  840.                 }
  841.             }
  842.             else
  843.             {
  844.                 PrintLine("\33bps::[begin] Syntax Unknown: needed 6 argument, found %ld. \33n",i+1);
  845.                 Success = FALSE;
  846.                 break;
  847.             }
  848.         }
  849.  
  850.         if (Success && array[7])
  851.         {
  852.             if (!strcmp(array[7],"startTexFig"))
  853.             {
  854.                 psfig_status = PSFIG_BEGIN;
  855.                 psfig_data . width  = value[0];
  856.                 psfig_data . height = value[1];
  857.                 psfig_data . llx    = value[2];
  858.                 psfig_data . lly    = value[3];
  859.                 psfig_data . urx    = value[4];
  860.                 psfig_data . ury    = value[5];
  861.                 psfig_data . angle  = 0.0;
  862.                 psfig_data . clip   = FALSE;
  863.  
  864.                 FreeVecPooled(Buffer);
  865.                 return;
  866.             }
  867.             else
  868.             {
  869.                 psfig_status = PSFIG_OFF;            
  870.                 PrintLine("\33bps::[begin] Needed \"startTeXFig\" keyword; psfig special aborted!\33n");
  871.                 Success = FALSE;
  872.  
  873.                 FreeVecPooled(Buffer);
  874.                 return;
  875.             }
  876.         }
  877.         else
  878.         {
  879.             psfig_status = PSFIG_OFF;
  880.             PrintLine("\33bps::[begin] Syntax Unknown: psfig special aborted!\33n");
  881.             Success = FALSE;
  882.         }
  883.     }
  884.     else if (psfig_status == PSFIG_BEGIN)
  885.     {
  886.         if (array[0])
  887.         {
  888.             if (!Stricmp(array[0],"plotfile"))
  889.             {
  890.                 if (!array[1])
  891.                 {
  892.                     PrintLine("\33bps: plotfile, you must specify a filename!\33n");
  893.                 }
  894.                 else
  895.                 {
  896.                     strcpy(psfig_name,array[1]);
  897.                     psfig_status = PSFIG_WAIT; /* now wait for ps::[end] */
  898.                 }
  899.             }
  900.             else if (!strcmp(array[0],"doclip"))
  901.             {
  902.                 psfig_data . clip = TRUE;
  903.             }
  904.             else if (!strcmp(array[1],"rotate"))
  905.             {
  906.                 psfig_data . angle += atof(array[0]);
  907.             }
  908.             else
  909.                 PrintLine("\33bps: Literal PostScript ignored.\33n");
  910.         }
  911.     }
  912.     else if (psfig_status == PSFIG_WAIT)
  913.     {
  914.         if (!Stricmp(array[0],"ps::[end]"))
  915.         {
  916.             if (!array[1])
  917.             {
  918.                 PrintLine("\33bps::[end] Argument expected, psfig special aborted!\33n");
  919.                 psfig_status = PSFIG_OFF;
  920.             }
  921.             else
  922.             {
  923.                 if (!strcmp(array[1],"endTexFig"))
  924.                 {
  925.                     psfig_status = PSFIG_END;
  926.                     strcpy(Result -> psfile, psfig_name);
  927.                 }
  928.                 else
  929.                 {
  930.                     PrintLine("\33bps::[end] \"endTexFig\" expected, psfig special aborted!\33n");
  931.                     psfig_status = PSFIG_OFF;
  932.                 }
  933.             }
  934.         }
  935.     }
  936.     else
  937.     {
  938.         PrintLine("\33b%s: Literal PostScript ignored.\33n",array[0]);
  939.     }
  940.  
  941.     FreeVecPooled(Buffer);
  942. }
  943.  
  944. /* (ghi) StrToArray() converts a string into an array of strings. strings are
  945.    drawed in the Buffer. */
  946. STRPTR __regargs *StrToArray(STRPTR String, STRPTR BrkStr, UBYTE *Buffer, LONG Size)
  947. {
  948.     STRPTR *p = (STRPTR *)Buffer, q = Buffer + Size, s;
  949.     LONG i = 0L;
  950.  
  951.     s = strtok(String, BrkStr);
  952.  
  953.     do
  954.     {
  955.         q -= (strlen(s) + 1L);
  956.  
  957.         if (&p[i] > (STRPTR *)(q - 2 * sizeof(STRPTR)))
  958.         {
  959.             p[i] = NULL;
  960.             break;
  961.         }
  962.         else
  963.         {
  964.             p[i] = q;
  965.             strcpy(p[i++], s);
  966.         }
  967.         
  968.     }
  969.     while (s = strtok(NULL, BrkStr));
  970.  
  971.     p[i] = NULL;
  972.     return p;
  973. }
  974.  
  975. /* (ghi) Add the transformation to the global list Extra_Transf. */
  976. BOOL __regargs
  977. Add_Extra_Transf(int transformation, float arg_x, float arg_y)
  978. {
  979.     if (Extra_Transf == NULL)
  980.     {
  981.         if (Extra_Transf = AllocVecPooled(sizeof(struct extra_transf), MEMF_ANY))
  982.         {
  983.             Extra_Transf -> prev = Extra_Transf -> next = NULL;
  984.             Init_CTM(&Extra_Transf -> CTM);
  985.         }
  986.         else
  987.             return (FALSE);
  988.     }
  989.     else
  990.     {
  991.         while (Extra_Transf -> next)
  992.             Extra_Transf = Extra_Transf -> next;
  993.  
  994.         if (Extra_Transf -> next = AllocVecPooled(sizeof(struct extra_transf), MEMF_ANY))
  995.         {
  996.             Extra_Transf -> next -> prev = Extra_Transf;
  997.             Extra_Transf = Extra_Transf -> next;
  998.             Extra_Transf -> next = NULL;
  999.             Copy_CTM(&Extra_Transf -> CTM, &Extra_Transf -> prev -> CTM);
  1000.         }
  1001.         else
  1002.             return (FALSE);
  1003.     }
  1004.  
  1005.     Extra_Transf -> type_of_transf = transformation;
  1006.     CTM_Transf(&Extra_Transf -> CTM, arg_x, arg_y, transformation);
  1007.  
  1008.     return (TRUE);
  1009. }
  1010.  
  1011. /* (ghi) we try to match transformation, otherwise return FALSE */
  1012. BOOL __regargs
  1013. Del_Extra_Transf(int transformation)
  1014. {
  1015.     if (!Extra_Transf)
  1016.         return(FALSE);
  1017.  
  1018.     while (Extra_Transf -> next)
  1019.         Extra_Transf = Extra_Transf -> next;
  1020.  
  1021.     if (Extra_Transf -> type_of_transf != transformation)
  1022.         return (FALSE);
  1023.     else
  1024.     {
  1025.         struct extra_transf *p = Extra_Transf;
  1026.  
  1027.         if (p -> prev)
  1028.         {
  1029.             p -> prev -> next = NULL;
  1030.             Extra_Transf = p -> prev;
  1031.             FreeVecPooled(p);
  1032.         }
  1033.         else
  1034.         {
  1035.             FreeVecPooled(p);
  1036.             Extra_Transf = NULL;
  1037.         }
  1038.  
  1039.         return(TRUE);
  1040.     }
  1041.  
  1042. }
  1043.  
  1044. VOID __regargs Init_Extra_Transf(VOID)
  1045. {
  1046.     struct extra_transf *p;
  1047.  
  1048.     ET_CurrentPoint_x = ET_CurrentPoint_y = 0.0f;
  1049.  
  1050.     if (!Extra_Transf)
  1051.         return;
  1052.  
  1053.     while (Extra_Transf -> next)
  1054.         Extra_Transf = Extra_Transf -> next;
  1055.  
  1056.     while ((p = Extra_Transf) && p -> prev)
  1057.     {
  1058.         Extra_Transf = p -> prev;
  1059.         FreeVecPooled(p);
  1060.     }
  1061.  
  1062.     if (Extra_Transf)
  1063.     {
  1064.         FreeVecPooled(Extra_Transf);
  1065.         Extra_Transf = NULL;
  1066.     }
  1067. }
  1068.