home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / SpecHost / Host.c < prev    next >
C/C++ Source or Header  |  1995-06-13  |  54KB  |  2,554 lines

  1. /*
  2. **    SpecialHost for PasTeX
  3. **
  4. **    Copyright © by Olaf Barthel & Georg Heßmann
  5. */
  6.  
  7. /*
  8. ** Host.c
  9. **
  10. ** latest revision: 13 Jun 1995, by Giuseppe Ghibò.
  11. */
  12.  
  13. #include "Global.h"
  14.  
  15. #include "SpecialHost_rev.h"
  16.  
  17. #define TEMPLATE    "TRANSFER/K,RENDER/K,BASEDEPI/K/N,INVERT/S,USESCREEN/S,NOGUI/S"
  18.  
  19. enum    {    ARG_TRANSFER,ARG_RENDER,ARG_BASEDPI,ARG_INVERT,ARG_USESCREEN,ARG_NOGUI,
  20.         ARGCOUNT
  21.     };
  22.  
  23. STATIC VOID __saveds ChildFunc(VOID);
  24. STATIC VOID __regargs Init_Transfer_Render(LONG *, LONG *, int draw_modus); /* (ghi) to fix problem with config file */
  25.  
  26. struct EnvVarPath *texconfig_var; /* for TEXCONFIG env var */
  27. struct EnvVarPath *psheaders_var; /* for DVIPSHEADERS env var */
  28.  
  29. LONG __saveds
  30. Main(VOID)
  31. {
  32.     LONG             Result = RETURN_FAIL;
  33.     BOOL             NeedStack;
  34.     struct WBStartup    *WBenchMsg;
  35.  
  36.     SysBase = *(struct ExecBase **)4;
  37.  
  38.     Father = (struct Process *)SysBase -> ThisTask;
  39.  
  40.     if(Father -> pr_CLI)
  41.     {
  42.         NeedStack = (((struct CommandLineInterface *)BADDR(Father -> pr_CLI)) -> cli_DefaultStack < 8192);
  43.  
  44.         WBenchMsg = NULL;
  45.     }
  46.     else
  47.     {
  48.         WaitPort(&Father -> pr_MsgPort);
  49.  
  50.         WBenchMsg = (struct WBStartup *)GetMsg(&Father -> pr_MsgPort);
  51.  
  52.         NeedStack = ((LONG)SysBase -> ThisTask -> tc_SPUpper - (LONG)SysBase -> ThisTask -> tc_SPLower < 32768);
  53.     }
  54.  
  55.     if(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",37))
  56.     {
  57.         if(UtilityBase = OpenLibrary("utility.library",37))
  58.         {
  59.             BPTR    OldDir,
  60.                 Stream        = NULL,
  61.                 OldCOS        = NULL;
  62.             APTR    OldConsoleTask    = NULL;
  63.  
  64.             if(WBenchMsg)
  65.                 OldDir = CurrentDir(WBenchMsg -> sm_ArgList[0] . wa_Lock);
  66.  
  67.             texconfig_var = Alloc_EnvVarPath("TEXCONFIG", EVP_BUFSIZE);
  68.             psheaders_var = Alloc_EnvVarPath("DVIPSHEADERS", EVP_BUFSIZE);
  69.             Init_EnvVarPath(texconfig_var, "TeX:config", ENVPATH_DEFSTR);
  70.             Init_EnvVarPath(psheaders_var, "TeX:ps,POST:", ENVPATH_DEFSTR | ENVPATH_APPEND_PATH);
  71.  
  72.             ReadConfig(&Configuration);
  73.  
  74.             if(Father -> pr_CLI)
  75.             {
  76.                 struct RDArgs    *ArgsPtr;
  77.                 STRPTR         Arg[ARGCOUNT];
  78.                 LONG         TransferMode,    // = CYID_Transfer_Memory,
  79.                          RenderMode,    // = CYID_Render_None,
  80.                          ID;
  81.  
  82.                 Init_Transfer_Render(&TransferMode, &RenderMode, Configuration . draw_modus); /* (ghi) TransferMode and RenderMode are initialized to the value read from the Config file */
  83.  
  84.                 memset(Arg,0,sizeof(Arg));
  85.  
  86.                 if(ArgsPtr = ReadArgs(TEMPLATE,(LONG *)Arg,NULL))
  87.                 {
  88.                     if(Arg[ARG_TRANSFER])
  89.                     {
  90.                         if((ID = GetMapCode(TransferTable,Arg[ARG_TRANSFER])) != -1)
  91.                             TransferMode = ID;
  92.                     }
  93.  
  94.                     if(Arg[ARG_RENDER])
  95.                     {
  96.                         if((ID = GetMapCode(RenderTable,Arg[ARG_RENDER])) != -1)
  97.                             RenderMode = ID;
  98.                     }
  99.  
  100.                     if(Arg[ARG_BASEDPI])
  101.                     {
  102.                         if((ID = *(LONG *)Arg[ARG_BASEDPI]) > 0)
  103.                             Configuration . base_dpi = ID;
  104.                     }
  105.  
  106.                     if(Arg[ARG_INVERT])
  107.                         Configuration . invert_bmap = TRUE;
  108.  
  109.                     if(Arg[ARG_USESCREEN])
  110.                         Configuration . use_pubscr = TRUE;
  111.  
  112.                     if(Arg[ARG_NOGUI])
  113.                         UseGUI = FALSE;
  114.  
  115.                     ChangeDrawMode(TransferMode,RenderMode,FALSE);
  116.  
  117.                     FreeArgs(ArgsPtr);
  118.                 }
  119.             }
  120.             else
  121.             {
  122.                 if(IconBase = OpenLibrary("icon.library",37))
  123.                 {
  124.                     struct DiskObject *Icon;
  125.  
  126.                     if(Icon = GetDiskObject(WBenchMsg -> sm_ArgList[0] . wa_Name))
  127.                     {
  128.                         STRPTR    Data;
  129.                         LONG    TransferMode,    // = CYID_Transfer_Memory,
  130.                             RenderMode,    // = CYID_Render_None,
  131.                             ID;
  132.  
  133.                         Init_Transfer_Render(&TransferMode, &RenderMode, Configuration . draw_modus); /* (ghi) TransferMode and RenderMode are initialized to the value read from the Config file */
  134.  
  135.                         if(Data = FindToolType(Icon -> do_ToolTypes,"TRANSFER"))
  136.                         {
  137.                             if((ID = GetMapCode(TransferTable,Data)) != -1)
  138.                                 TransferMode = ID;
  139.                         }
  140.  
  141.                         if(Data = FindToolType(Icon -> do_ToolTypes,"RENDER"))
  142.                         {
  143.                             if((ID = GetMapCode(RenderTable,Data)) != -1)
  144.                                 RenderMode = ID;
  145.                         }
  146.  
  147.                         if(Data = FindToolType(Icon -> do_ToolTypes,"BASEDPI"))
  148.                         {
  149.                             if(StrToLong(Data,&ID) > 0)
  150.                             {
  151.                                 if(ID > 0)
  152.                                     Configuration . base_dpi = ID;
  153.                             }
  154.                         }
  155.  
  156.                         if(FindToolType(Icon -> do_ToolTypes,"INVERT"))
  157.                             Configuration . invert_bmap = TRUE;
  158.  
  159.                         if(FindToolType(Icon -> do_ToolTypes,"USESCREEN"))
  160.                             Configuration . use_pubscr = TRUE;
  161.  
  162.                         if(FindToolType(Icon -> do_ToolTypes,"NOGUI"))
  163.                             UseGUI = FALSE;
  164.  
  165.                         ChangeDrawMode(TransferMode,RenderMode,FALSE);
  166.  
  167.                         FreeDiskObject(Icon);
  168.                     }
  169.  
  170.                     CloseLibrary(IconBase);
  171.                 }
  172.  
  173.                 if(!UseGUI)
  174.                 {
  175.                     if(Configuration . use_pubscr)
  176.                         Stream = Open("CON:20/20/400/80/SpecialHost/SCREENShowDVI-PubScr",MODE_NEWFILE);
  177.                     else
  178.                         Stream = Open("CON:20/20/400/80/SpecialHost",MODE_NEWFILE);
  179.  
  180.                     if(Stream)
  181.                     {
  182.                         struct FileHandle *Handle = (struct FileHandle *)BADDR(Stream);
  183.  
  184.                         OldConsoleTask = Father -> pr_ConsoleTask;
  185.  
  186.                         Father -> pr_ConsoleTask = (APTR)Handle -> fh_Type;
  187.  
  188.                         OldCOS = Father -> pr_COS;
  189.  
  190.                         if(!(Father -> pr_COS = Open("*",MODE_NEWFILE)))
  191.                         {
  192.                             Father -> pr_COS        = OldCOS;
  193.                             Father -> pr_ConsoleTask    = OldConsoleTask;
  194.  
  195.                             Close(Stream);
  196.  
  197.                             Stream = NULL;
  198.  
  199.                             UseGUI = TRUE;
  200.                         }
  201.                     }
  202.                     else
  203.                         UseGUI = TRUE;
  204.                 }
  205.             }
  206.  
  207.             if(NeedStack)
  208.             {
  209.                 Forbid();
  210.  
  211.                 SetSignal(0,SIGF_SINGLE);
  212.  
  213.                 if(CreateNewProcTags(
  214.                     NP_CommandName,    "SpecialHost Child",
  215.                     NP_Name,    "SpecialHost Child Process",
  216.                     NP_Output,    Father -> pr_COS,
  217.                     NP_CloseOutput,    FALSE,
  218.                     NP_StackSize,    32768,
  219.                     NP_Entry,    ChildFunc,
  220.                     NP_Cli,        (WBenchMsg == NULL),
  221.                 TAG_DONE))
  222.                 {
  223.                     ULONG Signals;
  224.  
  225.                     Result = RETURN_OK;
  226.  
  227.                     Wait(SIGF_SINGLE);
  228.  
  229.                     while(1)
  230.                     {
  231.                         Signals = Wait(SIGF_SINGLE | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_E);
  232.  
  233.                         if(Signals & SIGF_SINGLE)
  234.                             break;
  235.                         else
  236.                             Signal(ThisProcess,Signals);
  237.                     }
  238.                 }
  239.  
  240.                 Permit();
  241.             }
  242.             else
  243.             {
  244.                 HandleInput();
  245.  
  246.                 Result = RETURN_OK;
  247.             }
  248.  
  249.             if(Stream)
  250.             {
  251.                 BPTR NewCOS = Father -> pr_COS;
  252.  
  253.                 Father -> pr_COS        = OldCOS;
  254.                 Father -> pr_ConsoleTask    = OldConsoleTask;
  255.  
  256.                 Close(Stream);
  257.                 Close(NewCOS);
  258.             }
  259.  
  260.             Free_EnvVarPath(texconfig_var);
  261.             Free_EnvVarPath(psheaders_var);
  262.  
  263.             if(WBenchMsg)
  264.                 CurrentDir(OldDir);
  265.  
  266.             CloseLibrary(UtilityBase);
  267.         }
  268.  
  269.         CloseLibrary(DOSBase);
  270.     }
  271.  
  272.     if(WBenchMsg)
  273.     {
  274.         Forbid();
  275.  
  276.         ReplyMsg(&WBenchMsg -> sm_Message);
  277.     }
  278.     else
  279.         return(Result);
  280. }
  281.  
  282. int _FPERR;
  283. void _CXFERR(int code) {}
  284.  
  285. STATIC VOID __saveds
  286. ChildFunc()
  287. {
  288.     Signal(Father,SIGF_SINGLE);
  289.  
  290.     HandleInput();
  291.  
  292.     Forbid();
  293.  
  294.     Signal(Father,SIGF_SINGLE);
  295. }
  296.  
  297. BOOL __regargs
  298. BuildName(STRPTR LocalBuffer,BPTR Home,STRPTR Source,LONG ResX,LONG ResY,ULONG CRC,LONG *Error)
  299. {
  300.     UBYTE    NewDir[40];
  301.     STRPTR    Index;
  302.     BOOL    Success = FALSE;
  303.  
  304.     *Error = 0;
  305.  
  306.     strcpy(LocalBuffer,Source);
  307.  
  308.     if(FilePart(LocalBuffer) == LocalBuffer)
  309.     {
  310.         if(Home == (BPTR)~0)
  311.             LocalBuffer[0] = 0;
  312.         else
  313.         {
  314.             if(!NameFromLock(Home,LocalBuffer,MAX_FILENAME_LEN))
  315.             {
  316.                 *Error = IoErr();
  317.  
  318.                 return(FALSE);
  319.             }
  320.         }
  321.     }
  322.     else
  323.     {
  324.         Index = PathPart(LocalBuffer);
  325.  
  326.         *Index = 0;
  327.     }
  328.  
  329.     sprintf(NewDir,"SpecialHost_%dx%d",ResX,ResY);
  330.  
  331.     if(AddPart(LocalBuffer,NewDir,MAX_FILENAME_LEN))
  332.     {
  333.         BPTR FileLock;
  334.  
  335.         if(FileLock = Lock(LocalBuffer,ACCESS_READ))
  336.         {
  337.             struct FileInfoBlock *FileInfo;
  338.  
  339.             if(FileInfo = (struct FileInfoBlock *)AllocDosObjectTags(DOS_FIB,TAG_DONE))
  340.             {
  341.                 if(Examine(FileLock,FileInfo))
  342.                 {
  343.                     if(FileInfo -> fib_DirEntryType > 0)
  344.                         Success = TRUE;
  345.                     else
  346.                         *Error = ERROR_OBJECT_WRONG_TYPE;
  347.                 }
  348.                 else
  349.                     *Error = IoErr();
  350.  
  351.                 FreeDosObject(DOS_FIB,FileInfo);
  352.  
  353.                 UnLock(FileLock); /* (ghi) fixed */
  354.             }
  355.             else
  356.                 *Error = IoErr();
  357.         }
  358.         else
  359.         {
  360.             LONG LocalError = IoErr();
  361.  
  362.             if(LocalError == ERROR_OBJECT_NOT_FOUND)
  363.             {
  364.                 if(FileLock = CreateDir(LocalBuffer))
  365.                 {
  366.                     Success = TRUE;
  367.  
  368.                     UnLock(FileLock);
  369.                 }
  370.                 else
  371.                     *Error = IoErr();
  372.             }
  373.             else
  374.                 *Error = LocalError;
  375.         }
  376.     }
  377.     else
  378.         *Error = IoErr();
  379.  
  380.     if(Success)
  381.     {        /* (ghi) save the CRC number within the filename */
  382.         UBYTE Source2[32];
  383.  
  384.         sprintf(Source2,"%.20s_%1s%08lx",FilePart(Source),(Configuration . invert_bmap ? "I" : "N"), CRC);
  385.         
  386.         if(!AddPart(LocalBuffer,Source2,MAX_FILENAME_LEN))
  387.         {
  388.             *Error = IoErr();
  389.  
  390.             Success = FALSE;
  391.         }
  392.     }
  393.  
  394.     return(Success);
  395. }
  396.  
  397. VOID __regargs
  398. SetSleep(BOOL Mode)
  399. {
  400.     if(AP_Application)
  401.     {
  402.         if(Mode)
  403.         {
  404.             struct Window *Window;
  405.  
  406.             Forbid();
  407.  
  408.             if(get(WI_Main,MUIA_Window_Window,&Window))
  409.                 ThisProcess -> pr_WindowPtr = Window;
  410.  
  411.             Permit();
  412.  
  413.             set(AP_Application,MUIA_Application_Sleep,TRUE);
  414.         }
  415.         else
  416.         {
  417.             ThisProcess -> pr_WindowPtr = OldPtr;
  418.  
  419.             set(AP_Application,MUIA_Application_Sleep,FALSE);
  420.         }
  421.     }
  422. }
  423.  
  424. /*
  425. BPTR __regargs
  426. OpenConfigFile(STRPTR Name,LONG Mode)
  427. {
  428.     UBYTE    Env[MAX_FILENAME_LEN],
  429.         Path[MAX_FILENAME_LEN];
  430.     STRPTR    Index;
  431.     LONG    Len;
  432.     BPTR    File;
  433.  
  434.     if(GetVar("TEXCONFIG",Env,MAX_FILENAME_LEN,NULL) < 1)
  435.         strcpy(Env,"TeX:config");
  436.  
  437.     Index = strtok(Env,",;");
  438.  
  439.     do
  440.     {
  441.         strcpy(Path,Index);
  442.  
  443.         Len = strlen(Path);
  444.  
  445.         if(Path[Len - 1] != ':' && Path[Len - 1] != '/')
  446.         {
  447.             Path[Len]    = '/';
  448.             Path[Len + 1]    = 0;
  449.         }
  450.  
  451.         if(!strcmp(Path,"./"))
  452.             Path[0] = 0;
  453.  
  454.         strcat(Path,Name);
  455.  
  456.         if(File = Open(Path,Mode))
  457.             return(File);
  458.     }
  459.     while(Index = strtok(NULL,",;"));
  460.  
  461.     return(NULL);
  462. }
  463. */
  464.  
  465. BOOL __regargs
  466. ReadConfig(struct config_struct *ConfigPtr)
  467. {
  468.     BPTR File;
  469.     BOOL Result = FALSE;
  470.  
  471.     if (File = EVP_Open("SpecialHost.config", texconfig_var, NULL, NULL, MODE_OLDFILE))
  472.     {
  473.         struct config_struct Config;
  474.  
  475.         if(Read(File,&Config,sizeof(struct config_struct)) == sizeof(struct config_struct))
  476.         {
  477.             if(Config . magic == CONFIG_FILE_MAGIC && Config . version <= CONFIG_FILE_VERSION)
  478.             {
  479.                 if(Config . use_pubscr != ConfigPtr -> use_pubscr)
  480.                     Result = TRUE;
  481.  
  482.                 CopyMem(&Config,ConfigPtr,sizeof(struct config_struct));
  483.             }
  484.             else
  485.                 PrintLine("\33bConfiguration file format is too old.\33n");
  486.         }
  487.         else
  488.             PrintLine("\33bError reading configuration file.\33n");
  489.  
  490.         Close(File);
  491.     }
  492.     else
  493.         PrintLine("\33bFailed to open configuration file.\33n");
  494.  
  495.     return(Result);
  496. }
  497.  
  498. VOID __regargs
  499. SaveConfig(struct config_struct *ConfigPtr)
  500. {
  501.     BPTR File;
  502.  
  503.     if(File = EVP_Open("SpecialHost.config",texconfig_var, NULL, NULL, MODE_NEWFILE))
  504.     {
  505.         if(Write(File,ConfigPtr,sizeof(struct config_struct)) != sizeof(struct config_struct))
  506.             PrintLine("\33bError writing configuration file.\33n");
  507.  
  508.         Close(File);
  509.     }
  510.     else
  511.         PrintLine("\33bFailed to open configuration file.\33n");
  512. }
  513.  
  514. VOID
  515. ChangeDrawMode(LONG Transfer,LONG Render,BOOL GetThem)
  516. {
  517.     if(GetThem)
  518.     {
  519.         if(!CY_Transfer || !CY_Render)
  520.             return;
  521.         else
  522.         {
  523.             get(CY_Transfer,MUIA_Cycle_Active,&Transfer);
  524.             get(CY_Render,    MUIA_Cycle_Active,&Render);
  525.         }
  526.     }
  527.  
  528.     switch(Transfer)
  529.     {
  530.         case CYID_Transfer_Memory:
  531.  
  532.             switch(Render)
  533.             {
  534.                 case CYID_Render_None:
  535.  
  536.                     Configuration . draw_modus = DRAW_IN_MEM;
  537.                     break;
  538.  
  539.                 case CYID_Render_Frame:
  540.  
  541.                     Configuration . draw_modus = DRAW_IN_MEM_B;
  542.                     break;
  543.  
  544.                 case CYID_Render_Clear:
  545.  
  546.                     Configuration . draw_modus = DRAW_RECT;
  547.                     break;
  548.             }
  549.  
  550.             break;
  551.  
  552.         case CYID_Transfer_Disk:
  553.  
  554.             switch(Render)
  555.             {
  556.                 case CYID_Render_None:
  557.  
  558.                     Configuration . draw_modus = DRAW_FILE;
  559.                     break;
  560.  
  561.                 case CYID_Render_Frame:
  562.  
  563.                     Configuration . draw_modus = DRAW_FILE_B;
  564.                     break;
  565.  
  566.                 case CYID_Render_Clear:
  567.  
  568.                     Configuration . draw_modus = DRAW_BORDER;
  569.                     break;
  570.             }
  571.  
  572.             break;
  573.  
  574.         case CYID_Transfer_None:
  575.  
  576.             switch(Render)
  577.             {
  578.                 case CYID_Render_None:
  579.  
  580.                     Configuration . draw_modus = DRAW_RECT;
  581.                     break;
  582.  
  583.                 case CYID_Render_Frame:
  584.  
  585.                     Configuration . draw_modus = DRAW_BORDER;
  586.                     break;
  587.  
  588.                 case CYID_Render_Clear:
  589.  
  590.                     Configuration . draw_modus = DRAW_RECT;
  591.                     break;
  592.             }
  593.  
  594.             break;
  595.     }
  596. }
  597.  
  598. VOID __inline
  599. LibraryCleanup(struct Library **Library)
  600. {
  601.     if(*Library)
  602.     {
  603.         CloseLibrary(*Library);
  604.  
  605.         *Library = NULL;
  606.     }
  607. }
  608.  
  609. BOOL
  610. OpenGUI()
  611. {
  612.     STRPTR Version = VERSTAG;
  613.  
  614.     AP_Application = ApplicationObject,
  615.         MUIA_Application_Title,        "SpecialHost",
  616.         MUIA_Application_Version,    Version + 1,
  617.         MUIA_Application_Copyright,    "Copyright © 1993-1994 by Olaf `Olsen' Barthel & Georg Heßmann",
  618.         MUIA_Application_Author,    "Olaf `Olsen' Barthel & Georg Heßmann",
  619.         MUIA_Application_Description,    "PasTeX special extension processor",
  620.         MUIA_Application_Base,        "SPECIALHOST",
  621.         MUIA_Application_Menu,        MenuTemplate,
  622.  
  623.         SubWindow,
  624.             WI_Main = WindowObject,
  625.                 MUIA_Window_Title,    "SpecialHost",
  626.                 MUIA_Window_ID,        MAKE_ID('M','A','I','N'),
  627.                 WindowContents,        VGroup,
  628.  
  629.                     Child,    HGroup,
  630.                         Child,    ColGroup(2),GroupFrameT("Image"),
  631.                             Child,    KeyLabel1("Transfer",'t'),    Child,    CY_Transfer    = KeyCycle(CYA_Transfer,'t'),
  632.                             Child,    KeyLabel1("Rendering",'r'),    Child,    CY_Render    = KeyCycle(CYA_Render,'r'),
  633.                             Child,    KeyLabel1("Invert",'i'),    Child,    HGroup,
  634.                                                     Child,    CM_Invert    = KeyCheckMark(FALSE,'i'),
  635.                                                     Child,    HSpace(FALSE),
  636.                                                     End,
  637.                             Child,    KeyLabel2("Base DPI",'b'),    Child,    ST_BaseDPI = StringObject,
  638.                                                             StringFrame,
  639.                                                             MUIA_String_Integer,    100,
  640.                                                             MUIA_String_Accept,    "1234567890",
  641.                                                             MUIA_String_MaxLen,    5,
  642.                                                             MUIA_ControlChar,    'b',
  643.                                                     End,
  644.                             End,
  645.                         End,
  646.  
  647.                     Child,    HGroup,
  648.                         GroupFrameT("Messages"),
  649.                         Child,    LV_Messages = ListviewObject,
  650.                             MUIA_Listview_Input,    FALSE,
  651.                             MUIA_Listview_List,    ListObject,
  652.                                             ReadListFrame,
  653.                                         End,
  654.                             End,
  655.                         End,
  656.  
  657.                     Child,    VGroup,GroupFrame,
  658.                         Child,    GA_Gauge = GaugeObject,
  659.                             GaugeFrame,
  660.                             MUIA_Gauge_Horiz,    TRUE,
  661.                             MUIA_Weight,        0,
  662.                             End,
  663.                         Child,    RectangleObject,
  664.                             MUIA_Weight,        0,
  665.                             End,
  666.                         Child,    ScaleObject,
  667.                             End,
  668.                         End,
  669.                     Child,    HGroup,
  670.                         MUIA_Group_SameSize, TRUE,
  671.                         Child,    BT_Jump        = KeyButton("Jump to ShowDVI",'j'),
  672.                         Child,    BT_Show        = KeyButton("ShowDVI to front",'f'),
  673.                         Child,    BT_Clear    = KeyButton("Clear",'c'),
  674.                         End,
  675.                 End,
  676.             End,
  677.     End;
  678.  
  679.     if(AP_Application)
  680.     {
  681.         struct ListEntry    *Entry = (struct ListEntry *)MessageList . lh_Head;
  682.         struct Window        *Window;
  683.  
  684.         DoMethod(WI_Main,    MUIM_Notify,MUIA_Window_CloseRequest,    TRUE,        AP_Application,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  685.         DoMethod(CY_Transfer,    MUIM_Notify,MUIA_Cycle_Active,        MUIV_EveryTime,    AP_Application,2,MUIM_Application_ReturnID,GAD_TRANSFER);
  686.         DoMethod(CY_Render,    MUIM_Notify,MUIA_Cycle_Active,        MUIV_EveryTime,    AP_Application,2,MUIM_Application_ReturnID,GAD_RENDER);
  687.         DoMethod(CM_Invert,    MUIM_Notify,MUIA_Selected,        MUIV_EveryTime,    AP_Application,2,MUIM_Application_ReturnID,GAD_INVERT);
  688.         DoMethod(ST_BaseDPI,    MUIM_Notify,MUIA_String_Contents,    MUIV_EveryTime,    AP_Application,2,MUIM_Application_ReturnID,GAD_BASEDPI);
  689.         DoMethod(BT_Jump,    MUIM_Notify,MUIA_Pressed,FALSE,                AP_Application,2,MUIM_Application_ReturnID,GAD_JUMP);
  690.         DoMethod(BT_Show,    MUIM_Notify,MUIA_Pressed,FALSE,                AP_Application,2,MUIM_Application_ReturnID,GAD_SHOW);
  691.         DoMethod(BT_Clear,    MUIM_Notify,MUIA_Pressed,FALSE,                AP_Application,2,MUIM_Application_ReturnID,GAD_CLEAR);
  692.  
  693.         DoMethod(WI_Main,    MUIM_Window_SetCycleChain,CY_Transfer,CY_Render,CM_Invert,ST_BaseDPI,LV_Messages,BT_Jump,BT_Show,BT_Clear,NULL);
  694.  
  695.         while(Entry -> MinNode . mln_Succ)
  696.         {
  697.             DoMethod(LV_Messages,MUIM_List_Insert,&Entry -> Title,1,MUIV_List_Insert_Bottom);
  698.  
  699.             Entry = (struct ListEntry *)Entry -> MinNode . mln_Succ;
  700.         }
  701.  
  702.         set(LV_Messages,MUIA_List_Active,MUIV_List_Active_Bottom);
  703.  
  704.         switch(Configuration . draw_modus)
  705.         {
  706.             case DRAW_IN_MEM:
  707.  
  708.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Memory);
  709.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_None);
  710.                 break;
  711.  
  712.             case DRAW_FILE:
  713.  
  714.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Disk);
  715.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_None);
  716.                 break;
  717.  
  718.             case DRAW_IN_MEM_B:
  719.  
  720.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Memory);
  721.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  722.                 break;
  723.  
  724.             case DRAW_FILE_B:
  725.  
  726.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Disk);
  727.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  728.                 break;
  729.  
  730.             case DRAW_BORDER:
  731.  
  732.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_None);
  733.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  734.                 break;
  735.  
  736.             case DRAW_RECT:
  737.  
  738.                 set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_None);
  739.                 set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Clear);
  740.                 break;
  741.         }
  742.  
  743.         set(CM_Invert,MUIA_Selected,Configuration . invert_bmap);
  744.  
  745.         InvertChanged = TRUE;
  746.  
  747.         set(ST_BaseDPI,MUIA_String_Integer,Configuration . base_dpi);
  748.  
  749.         if(PubScreen)
  750.         {
  751.             UnlockPubScreen(NULL,PubScreen);
  752.  
  753.             PubScreen = NULL;
  754.         }
  755.  
  756.         if(Configuration . use_pubscr)
  757.         {
  758.             if(PubScreen = LockPubScreen("ShowDVI-PubScr"))
  759.             {
  760.                 set(WI_Main,MUIA_Window_Screen,PubScreen);
  761.  
  762.                 set(BT_Jump,MUIA_Disabled,TRUE);
  763.             }
  764.             else
  765.                 Configuration . use_pubscr = FALSE;
  766.         }
  767.  
  768.         set(WI_Main,MUIA_Window_Open,TRUE);
  769.  
  770.         Forbid();
  771.  
  772.         if(get(WI_Main,MUIA_Window_Window,&Window))
  773.         {
  774.             if(Window)
  775.             {
  776.                 struct MenuItem *Item;
  777.  
  778.                 if(Item = ItemAddress(Window -> MenuStrip,FULLMENUNUM(0,3,NOSUB)))
  779.                 {
  780.                     if(Configuration . use_pubscr)
  781.                         Item -> Flags |= CHECKED;
  782.                     else
  783.                         Item -> Flags &= ~CHECKED;
  784.                 }
  785.  
  786.                 Permit();
  787.  
  788.                 return(TRUE);
  789.             }
  790.         }
  791.  
  792.         Permit();
  793.  
  794.         if(PubScreen)
  795.         {
  796.             UnlockPubScreen(NULL,PubScreen);
  797.  
  798.             PubScreen = NULL;
  799.         }
  800.  
  801.         DisposeObject(AP_Application);
  802.  
  803.         AP_Application = NULL;
  804.     }
  805.  
  806.     return(FALSE);
  807. }
  808.  
  809. VOID
  810. CloseAll()
  811. {
  812.     if(ThisProcess)
  813.         ThisProcess -> pr_WindowPtr = OldPtr;
  814.  
  815.     if(MainPort)
  816.     {
  817.         struct special_msg *Message;
  818.  
  819.         RemPort(MainPort);
  820.  
  821.         while(Message = (struct special_msg *)GetMsg(MainPort))
  822.         {
  823.             Message -> action    = AC_REPLY_UNKNOWN;
  824.             Message -> ret        = 0;
  825.  
  826.             ReplyMsg((struct Message *)Message);
  827.         }
  828.  
  829.         DeleteMsgPort(MainPort);
  830.     }
  831.  
  832.     if(Pool)
  833.         LibDeletePool(Pool);
  834.  
  835.     LibraryCleanup(&MUIMasterBase);
  836.     LibraryCleanup(&DataTypesBase);
  837. /*
  838.     LibraryCleanup(&MathBase);
  839.     LibraryCleanup(&MathTransBase);
  840. */
  841.     LibraryCleanup(&MathIeeeDoubBasBase);
  842.     LibraryCleanup(&MathIeeeDoubTransBase);
  843.  
  844.     LibraryCleanup(&AslBase);
  845.     LibraryCleanup(&IFFParseBase);
  846.     LibraryCleanup(&GadToolsBase);
  847.     LibraryCleanup(&GfxBase);
  848.     LibraryCleanup(&IntuitionBase);
  849. }
  850.  
  851. BOOL
  852. OpenAll()
  853. {
  854.     ThisProcess = (struct Process *)SysBase -> ThisTask;
  855.  
  856.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)))
  857.     {
  858.         ShowError(ERR_NO_INTUITION,NULL,FALSE);
  859.  
  860.         return(FALSE);
  861.     }
  862.  
  863.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37)))
  864.     {
  865.         ShowError(ERR_NO_GRAPHICS,NULL,FALSE);
  866.  
  867.         return(FALSE);
  868.     }
  869.  
  870.     if(!(GadToolsBase = OpenLibrary("gadtools.library",37)))
  871.     {
  872.         ShowError(ERR_NO_GADTOOLS,NULL,FALSE);
  873.  
  874.         return(FALSE);
  875.     }
  876.  
  877.     if(!(IFFParseBase = OpenLibrary("iffparse.library",37)))
  878.     {
  879.         ShowError(ERR_NO_IFFPARSE,NULL,FALSE);
  880.  
  881.         return(FALSE);
  882.     }
  883.  
  884.     if(!(AslBase = OpenLibrary("asl.library",37)))
  885.     {
  886.         ShowError(ERR_NO_ASL,NULL,FALSE);
  887.  
  888.         return(FALSE);
  889.     }
  890.  
  891. /*    if(!(MathBase = OpenLibrary("mathffp.library",0)))*/
  892.  
  893.     if(!(MathIeeeDoubBasBase = OpenLibrary("mathieeedoubbas.library",0)))
  894.     {
  895.         ShowError(ERR_NO_MATHFFP,NULL,FALSE);
  896.  
  897.         return(FALSE);
  898.     }
  899.  
  900. /*    if(!(MathTransBase = OpenLibrary("mathtrans.library",0)))*/
  901.  
  902.     if(!(MathIeeeDoubTransBase = OpenLibrary("mathieeedoubtrans.library",0)))
  903.     {
  904.         ShowError(ERR_NO_MATHTRANS,NULL,FALSE);
  905.  
  906.         return(FALSE);
  907.     }
  908.  
  909.     if(UseGUI)
  910.     {
  911.         if(!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  912.         {
  913.             ShowError(ERR_NO_MUI,NULL,FALSE);
  914.  
  915.             return(FALSE);
  916.         }
  917.     }
  918.  
  919.     DataTypesBase = OpenLibrary("datatypes.library",39);
  920.  
  921.     if(!(Pool = LibCreatePool(MEMF_ANY | MEMF_PUBLIC,8192,8192)))
  922.     {
  923.         ShowError(ERR_NO_POOL,NULL,FALSE);
  924.  
  925.         return(FALSE);
  926.     }
  927.  
  928.     Forbid();
  929.  
  930.     if(FindPort(SPECIAL_PORT))
  931.     {
  932.         ShowError(ERR_ALREADY_RUNNING,NULL,FALSE);
  933.  
  934.         Permit();
  935.  
  936.         return(FALSE);
  937.     }
  938.  
  939.     if(!(MainPort = CreateMsgPort()))
  940.     {
  941.         ShowError(ERR_NO_PORT,NULL,FALSE);
  942.  
  943.         Permit();
  944.  
  945.         return(FALSE);
  946.     }
  947.  
  948.     MainPort -> mp_Node . ln_Name = SPECIAL_PORT;
  949.  
  950.     AddPort(MainPort);
  951.  
  952.     Permit();
  953.  
  954.     if(GfxBase -> ChipRevBits0 & GFXF_BIG_BLITS)
  955.     {
  956.         WriteLine    = LargeWriteLine;
  957.         ReadLine    = LargeReadLine;
  958.     }
  959.     else
  960.     {
  961.         WriteLine    = SmallWriteLine;
  962.         ReadLine    = SmallReadLine;
  963.     }
  964.  
  965.     NewList(&MessageList);
  966.  
  967.     OldPtr = ThisProcess -> pr_WindowPtr;
  968.  
  969.     return(TRUE);
  970. }
  971.  
  972. VOID __stdargs
  973. PrintLine(STRPTR Format,...)
  974. {
  975.     if(ThisProcess)
  976.     {
  977.         STATIC UBYTE __far    LineBuffer[512];
  978.         va_list            VarArgs;
  979.  
  980.         va_start(VarArgs,Format);
  981.  
  982.         vsprintf(LineBuffer,Format,VarArgs);
  983.  
  984.         if(AP_Application)
  985.         {
  986.             struct ListEntry *Entry;
  987.  
  988.             if(Entry = (struct ListEntry *)AllocVecPooled(sizeof(struct ListEntry) + strlen(LineBuffer) + 1,MEMF_ANY))
  989.             {
  990.                 Entry -> Title = (STRPTR)(Entry + 1);
  991.  
  992.                 strcpy(Entry -> Title,LineBuffer);
  993.  
  994.                 AddTail(&MessageList,(struct Node *)Entry);
  995.  
  996.                 DoMethod(LV_Messages,MUIM_List_Insert,&Entry -> Title,1,MUIV_List_Insert_Bottom);
  997.  
  998.                 set(LV_Messages,MUIA_List_Active,MUIV_List_Active_Bottom);
  999.             }
  1000.         }
  1001.         else
  1002.         {
  1003.             if(ThisProcess -> pr_CLI)
  1004.             {
  1005.                 STRPTR    From    = LineBuffer,
  1006.                     To    = LineBuffer;
  1007.                 LONG    i;
  1008.  
  1009.                 for(i = 0 ; i < strlen(LineBuffer) ; i++)
  1010.                 {
  1011.                     if(LineBuffer[i] == '\33')
  1012.                         To += 2;
  1013.                     else
  1014.                         *From++ = *To++;
  1015.                 }
  1016.  
  1017.                 *To = 0;
  1018.  
  1019.                 FPrintf(ThisProcess -> pr_COS,"%s\n",LineBuffer);
  1020.             }
  1021.         }
  1022.  
  1023.         va_end(VarArgs);
  1024.     }
  1025. }
  1026.  
  1027.  
  1028. VOID __regargs
  1029. GetNewSize(struct special_map *SpecialMap, struct parse_result *Result, LONG *NewWidth, LONG *NewHeight, LONG DPI_X, LONG DPI_Y)
  1030. {
  1031.     float width, height, mag;
  1032.  
  1033.     width    = (float)SpecialMap -> width  * Result -> hres / DPI_X;
  1034.     height    = (float)SpecialMap -> height * Result -> vres / DPI_Y;
  1035.     mag    = (float)Result -> DVI_mag/1000.0;
  1036.  
  1037.     if(Result -> hsize != 0.0)
  1038.         width  = Result -> hsize * Result -> hres;
  1039.  
  1040.     if(Result -> vsize != 0.0)
  1041.         height = Result -> vsize * Result -> vres;
  1042.  
  1043.     if(Result -> scale > 0.0)
  1044.     {
  1045.         width  *= Result -> scale;
  1046.         height *= Result -> scale;
  1047.     }
  1048.     else
  1049.     {
  1050.         if(Result -> hscale > 0.0)
  1051.             width *= Result -> hscale;
  1052.  
  1053.         if(Result -> vscale > 0.0)
  1054.             height *= Result -> vscale;
  1055.     }
  1056.  
  1057.     *NewWidth  = (LONG) (width  * mag + 0.5); /* (ghi) we round only once */
  1058.     *NewHeight = (LONG) (height * mag + 0.5);
  1059.  
  1060. }
  1061.  
  1062. struct BitMap * __regargs
  1063. ProcessImage(struct special_msg *Message)
  1064. {
  1065.     STATIC struct special_map    SpecialMap;
  1066.     STATIC struct config_struct    ConfigBackup;
  1067.  
  1068.     UBYTE            LocalBuffer[256];
  1069.     struct parse_result    Result;
  1070.     struct BitMap        *BitMap = NULL;
  1071.     LONG            Width, Height, Sum1, Sum2, Error;
  1072.     STRPTR            String = Message -> special_string;
  1073.     BPTR            NewDir = NULL, OldDir = NULL, Home;
  1074.  
  1075.     LONG            DVI_mag;
  1076.     STATIC UBYTE        DVI_fname[256] = { '\0' };
  1077.     STATIC struct DateStamp DVI_date = {0L, 0L, 0L};
  1078.     STATIC LONG        DVI_page;
  1079.  
  1080.     BOOL            DVI_filechanged = FALSE,
  1081.                 DVI_datechanged = FALSE,
  1082.                 DVI_pagechanged = FALSE;
  1083.  
  1084.     if (Message -> msg . mn_Length >= 56)
  1085.         DVI_mag = Message -> DVImagnification; /* (ghi) support for global DVI magnification */
  1086.     else
  1087.         DVI_mag = 1000L; /* default magnification = no magnification */
  1088.  
  1089.     if (Message -> msg . mn_Length >= 60)
  1090.     {
  1091.         if (Message -> DVIfilename != NULL)
  1092.         {
  1093.             if (Stricmp(DVI_fname, Message -> DVIfilename))
  1094.             {
  1095.                 strcpy(DVI_fname, Message -> DVIfilename);
  1096.                 memcpy(&DVI_date, Message -> DVIfiledate, sizeof(struct DateStamp));
  1097.                 DVI_filechanged = TRUE;
  1098.             }
  1099.         }
  1100.  
  1101.         if (!Message -> DVIfiledate)
  1102.         {
  1103.             if (!CompareDates(&DVI_date, Message -> DVIfiledate))
  1104.             {
  1105.                 memcpy(&DVI_date, Message -> DVIfiledate, sizeof(struct DateStamp));
  1106.                 DVI_datechanged = TRUE;
  1107.             }
  1108.         }
  1109.  
  1110.         if (DVI_page != Message -> DVIcurphypage)
  1111.         {
  1112.             DVI_page = Message -> DVIcurphypage;
  1113.             DVI_pagechanged = TRUE;
  1114.         }
  1115.     }
  1116.  
  1117.     if (DVI_pagechanged || DVI_filechanged || DVI_datechanged)
  1118.         Init_Extra_Transf();
  1119.  
  1120.     if (DVI_filechanged)
  1121.         Init_PSHeaders();
  1122.  
  1123.     if(Message -> msg . mn_Length >= 52 && TypeOfMem(BADDR(Message -> DVIdirLock)))
  1124.     {
  1125.         OldDir = CurrentDir(Message -> DVIdirLock);
  1126.  
  1127.         Home = Message -> DVIdirLock;
  1128.     }
  1129.     else
  1130.     {
  1131.         Home = (BPTR)~0;
  1132.  
  1133.         if(GetVar("TEXPICTPATH",LocalBuffer,256,NULL) > 0)
  1134.         {
  1135.             if(NewDir = Lock(LocalBuffer,ACCESS_READ))
  1136.             {
  1137.                 OldDir = CurrentDir(NewDir);
  1138.  
  1139.                 Home = NewDir;
  1140.             }
  1141.         }
  1142.     }
  1143.  
  1144.     PrintLine("Command string received (%d × %d DPI),",Message -> hresolution,Message -> vresolution);
  1145.     PrintLine("\"%s\"",Message -> special_string);
  1146.  
  1147.     memset(&Result,0,sizeof(struct parse_result));
  1148.     memset(&SpecialMap,0,sizeof(struct special_map));
  1149.     memcpy(&ConfigBackup,&Configuration,sizeof(struct config_struct));
  1150.  
  1151.     Result . hres        = Message -> hresolution;
  1152.     Result . vres        = Message -> vresolution;
  1153.     Result . mode        = BandW;
  1154.     Result . invert        = Configuration . invert_bmap;
  1155.     Result . base_dpi    = Configuration . base_dpi;
  1156.     Result . DVI_mag    = DVI_mag;
  1157.  
  1158.     if (Message -> dmap) /* (ghi) get current point */
  1159.     {
  1160.         Result . current_x   = Message -> dmap -> x;
  1161.         Result . current_y   = Message -> dmap -> y;
  1162.         Result . page_width  = Message -> dmap -> page_width;
  1163.         Result . page_height = Message -> dmap -> page_height;
  1164.     }
  1165.     else
  1166.     {
  1167.         Result . current_x   = 0L;
  1168.         Result . current_y   = 0L;
  1169.         Result . page_width  = 8 * Message -> hresolution;
  1170.         Result . page_height = 11 * Message -> vresolution;
  1171.     }
  1172.  
  1173.     strcpy(Result . psinit_file,"init.ps");
  1174.  
  1175.     get(CY_Transfer,MUIA_Cycle_Active,&Result . transfer);
  1176.     get(CY_Render,MUIA_Cycle_Active,&Result . rendering);
  1177.  
  1178.     Sum2 = 0;
  1179.  
  1180.     Sum1 = DoCRC(String,strlen(String));
  1181.  
  1182.     if(!ParseSpecial(Message -> special_string, &Result))
  1183.     {
  1184.         Message -> ret = 5;
  1185.  
  1186.         PrintLine("Done.");
  1187.         PrintLine("");
  1188.  
  1189.         ShowProgress(0);
  1190.  
  1191.         if(OldDir)
  1192.             CurrentDir(OldDir);
  1193.  
  1194.         if(NewDir)
  1195.             UnLock(NewDir);
  1196.  
  1197.         return(NULL);
  1198.     }
  1199.  
  1200.     if (psfig_status == PSFIG_END)
  1201.     {
  1202.         UBYTE TmpString[256];
  1203.  
  1204.         if (Extra_Transf)
  1205.         {
  1206.             sprintf(TmpString,"[%g %g %g %g] %ld %ld %ld %ld %ld %ld startTexFig %s%g rotate endTexFig",
  1207.                 Extra_Transf -> CTM . a,
  1208.                 Extra_Transf -> CTM . b,
  1209.                 Extra_Transf -> CTM . c,
  1210.                 Extra_Transf -> CTM . d,
  1211.                 psfig_data . width, psfig_data . height,
  1212.                 psfig_data . llx, psfig_data . lly, psfig_data . urx, psfig_data . ury,
  1213.                 (psfig_data . clip ? "doclip " : ""),
  1214.                 psfig_data . angle);
  1215.         }
  1216.         else
  1217.         {
  1218.             sprintf(TmpString,"%ld %ld %ld %ld %ld %ld startTexFig %s%g rotate endTexFig",
  1219.                 psfig_data . width, psfig_data . height,
  1220.                 psfig_data . llx, psfig_data . lly, psfig_data . urx, psfig_data . ury,
  1221.                 (psfig_data . clip ? "doclip " : ""),
  1222.                 psfig_data . angle);
  1223.         }
  1224.  
  1225.         Sum1 = DoCRC(TmpString,strlen(TmpString));
  1226.     }
  1227.  
  1228.     if (Extra_Transf && psfig_status == PSFIG_OFF)
  1229.     {
  1230.         UBYTE TmpString[256];
  1231.  
  1232.         sprintf(TmpString,"%s [%g %g %g %g]", String,
  1233.             Extra_Transf -> CTM . a,
  1234.             Extra_Transf -> CTM . b,
  1235.             Extra_Transf -> CTM . c,
  1236.             Extra_Transf -> CTM . d);
  1237.  
  1238.         Sum1 = DoCRC(TmpString, strlen(TmpString));
  1239.         }
  1240.  
  1241.     Configuration . invert_bmap    = Result . invert;
  1242.     Configuration . base_dpi    = Result . base_dpi;
  1243.  
  1244.     ChangeDrawMode(Result . transfer,Result . rendering,FALSE);
  1245.  
  1246.     SpecialMap . hoffset    = (LONG)((float)Message -> hresolution * Result . hoffset * Result . DVI_mag / 1000.0 + 0.5);
  1247.     SpecialMap . voffset    = (LONG)((float)Message -> vresolution * Result . voffset * Result . DVI_mag / 1000.0 + 0.5);
  1248.  
  1249.     Message -> ret    = 0;
  1250.     Message -> bmap    = &SpecialMap;
  1251.  
  1252.     SpecialMap . loc . map    = NULL;
  1253.     SpecialMap . where_is    = LOC_NONE;
  1254.  
  1255.     if(Result . iffile[0])
  1256.     {
  1257.         if(Configuration . draw_modus == DRAW_BORDER || Configuration . draw_modus == DRAW_RECT)
  1258.         {
  1259.             if(GetImageSize(Result . iffile,&Width,&Height,&Error))
  1260.             {
  1261.                 LONG NewWidth,NewHeight,DPI_X = Configuration . base_dpi,DPI_Y = Configuration . base_dpi;
  1262.  
  1263.                 SpecialMap . width    = Width;
  1264.                 SpecialMap . height    = Height;
  1265.  
  1266.                 if(Configuration . draw_modus == DRAW_BORDER)
  1267.                     SpecialMap . where_is = LOC_BORDER;
  1268.                 else
  1269.                     SpecialMap . where_is = LOC_RECTANGLE;
  1270.  
  1271.                 GetImageDPI(Result . iffile,&DPI_X,&DPI_Y,NULL);
  1272.  
  1273.                 GetNewSize(&SpecialMap, &Result, &NewWidth, &NewHeight, DPI_X, DPI_Y);
  1274.  
  1275.                 SpecialMap . width    = NewWidth;
  1276.                 SpecialMap . height    = NewHeight;
  1277.             }
  1278.             else
  1279.             {
  1280.                 STRPTR Result = ShowError(Error,NULL,TRUE);
  1281.  
  1282.                 if(Result)
  1283.                     PrintLine("\33bCannot determine picture size: %s.\33n",Result);
  1284.                 else
  1285.                     PrintLine("\33bCannot determine picture size.\33n");
  1286.  
  1287.                 Message -> ret = 5;
  1288.             }
  1289.         }
  1290.         else
  1291.         {
  1292.             UBYTE             FileName[MAX_FILENAME_LEN];
  1293.             struct GreyImage    *Image;
  1294.             LONG             i;
  1295.  
  1296.             if(Configuration . draw_modus == DRAW_FILE || Configuration . draw_modus == DRAW_FILE_B)
  1297.             {
  1298.                 LONG    DateResult;
  1299.                 BPTR    File;
  1300.                 LONG    Error;
  1301.  
  1302.                 if(!BuildName(FileName,Home,Result . iffile,Result . hres,Result . vres,Sum1,&Error))
  1303.                 {
  1304.                     STRPTR Result = ShowError(Error,NULL,TRUE);
  1305.  
  1306.                     if(Result)
  1307.                         PrintLine("\33bCannot store converted image: %s.\33n",Result);
  1308.                     else
  1309.                         PrintLine("\33bCannot store converted image.\33n");
  1310.  
  1311.                     Message -> ret = 5;
  1312.  
  1313.                     memcpy(&Configuration,&ConfigBackup,sizeof(struct config_struct));
  1314.  
  1315.                     if(OldDir)
  1316.                         CurrentDir(OldDir);
  1317.  
  1318.                     if(NewDir)
  1319.                         UnLock(NewDir);
  1320.  
  1321.                     return(NULL);
  1322.                 }
  1323.  
  1324.                 Sum2 = Sum1 + 1;
  1325.  
  1326.                 if(File = Open(FileName,MODE_OLDFILE))
  1327.                 {
  1328.                     LONG Magic[2];
  1329.  
  1330.                     if(Read(File,Magic,sizeof(Magic)))
  1331.                     {
  1332.                         if(Magic[0] == MAGIC_WORD)
  1333.                             Sum2 = Magic[1];
  1334.                     }
  1335.  
  1336.                     Close(File);
  1337.                 }
  1338.  
  1339.                 DateResult = FileDateCheck(Result . iffile,FileName,&Error);
  1340.  
  1341.                 if(Error || DateResult < 0) /* (ghi) fixed */
  1342.                     Sum2 = Sum1 + 1;
  1343.  
  1344.                 if(Sum1 == Sum2)
  1345.                 {
  1346.                     STATIC UBYTE BitMapFileName[MAX_FILENAME_LEN];
  1347.  
  1348.                     if(Configuration . draw_modus == DRAW_FILE)
  1349.                         SpecialMap . where_is = LOC_FILE;
  1350.                     else
  1351.                         SpecialMap . where_is = LOC_FILE_BORDER;
  1352.  
  1353.                     strcpy(BitMapFileName,FileName);
  1354.  
  1355.                     SpecialMap . loc . filename = BitMapFileName;
  1356.  
  1357.                     PrintLine("Done.");
  1358.                     PrintLine("");
  1359.  
  1360.                     memcpy(&Configuration,&ConfigBackup,sizeof(struct config_struct));
  1361.  
  1362.                     if(OldDir)
  1363.                         CurrentDir(OldDir);
  1364.  
  1365.                     if(NewDir)
  1366.                         UnLock(NewDir);
  1367.  
  1368.                     return(NULL);
  1369.                 }
  1370.             }
  1371.  
  1372.             InvertChanged = FALSE;
  1373.  
  1374.             for(i = 0 ; i < 256 ; i++)
  1375.                 Filter[i] = i;
  1376.  
  1377.             BrightnessFilter(Filter,Result . bright);
  1378.             ContrastFilter(Filter,Result . contrast);
  1379.             GammaFilter(Filter,Result . gamma);
  1380.  
  1381.             if(Result . red < 1 && Result . green < 1 && Result . blue < 1)
  1382.             {
  1383.                 LONG R,G,B,Delta1,Delta2;
  1384.  
  1385.                 for(i = 0 ; i < 256 ; i++)
  1386.                 {
  1387.                     R = (i * 65536 * 299) / 1000;
  1388.                     G = (i * 65536 * 587) / 1000;
  1389.                     B = (i * 65536 * 114) / 1000;
  1390.  
  1391.                     Delta1 = i * 65536 - (R + G + B);
  1392.                     Delta2 = Delta1 / 2;
  1393.  
  1394.                     LumR[i] = R + Delta2;
  1395.                     LumG[i] = G + Delta1 - 2 * Delta2;
  1396.                     LumB[i] = B + Delta2;
  1397.                 }
  1398.             }
  1399.             else
  1400.             {
  1401.                 LONG R,G,B;
  1402.  
  1403.                 R = Result . red;
  1404.                 G = Result . green;
  1405.                 B = Result . blue;
  1406.  
  1407.                 while(R + G + B > 100)
  1408.                 {
  1409.                     if(G > 33 && R + G + B > 100)
  1410.                         G--;
  1411.  
  1412.                     if(R > 33 && R + G + B > 100)
  1413.                         R--;
  1414.  
  1415.                     if(B > 33 && R + G + B > 100)
  1416.                         B--;
  1417.                 }
  1418.  
  1419.                 for(i = 0 ; i < 256 ; i++)
  1420.                 {
  1421.                     LumR[i] = ((i * 65536) * R) / 100;
  1422.                     LumG[i] = ((i * 65536) * G) / 100;
  1423.                     LumB[i] = ((i * 65536) * B) / 100;
  1424.                 }
  1425.             }
  1426.  
  1427.             PrintLine("Loading picture from \"%s\"...",Result . iffile);
  1428.  
  1429.             if(Image = ReadImage(Result . iffile,Result . patch_colours,&Error))
  1430.             {
  1431.                 LONG NewWidth,NewHeight,DPI_X = Configuration . base_dpi,DPI_Y = Configuration . base_dpi;
  1432.  
  1433.                 Error = 0;
  1434.  
  1435.                 SpecialMap . width    = Image -> Width;
  1436.                 SpecialMap . height    = Image -> Height;
  1437.  
  1438.                 GetImageDPI(Result . iffile,&DPI_X,&DPI_Y,NULL);
  1439.  
  1440.                 GetNewSize(&SpecialMap, &Result, &NewWidth, &NewHeight, DPI_X, DPI_Y);
  1441.  
  1442.                 if(NewWidth > 32768 || NewHeight > 32768)
  1443.                     Error = ERR_TOO_LARGE;
  1444.                 else
  1445.                 {
  1446.                     PrintLine("Processing picture (size %d × %d)...",NewWidth,NewHeight);
  1447.  
  1448.                     SetMaxProgress(NewHeight - 1);
  1449.  
  1450.                     switch(Result . mode)
  1451.                     {
  1452.                         case BandW:
  1453.  
  1454.                             Error = ScaleImage(&BitMap,Image,NewWidth,NewHeight);
  1455.                             break;
  1456.  
  1457.                         case FS:
  1458.  
  1459.                             Error = DitherImage_FS(&BitMap,Image,NewWidth,NewHeight);
  1460.                             break;
  1461.  
  1462.                         case Burkes:
  1463.  
  1464.                             Error = DitherImage_Burkes(&BitMap,Image,NewWidth,NewHeight);
  1465.                             break;
  1466.  
  1467.                         case Sierra:
  1468.  
  1469.                             Error = DitherImage_Sierra(&BitMap,Image,NewWidth,NewHeight);
  1470.                             break;
  1471.  
  1472.                         case JJN:
  1473.  
  1474.                             Error = DitherImage_JJN(&BitMap,Image,NewWidth,NewHeight);
  1475.                             break;
  1476.  
  1477.                         case StevensonArce:
  1478.  
  1479.                             Error = DitherImage_Stevenson_Arce(&BitMap,Image,NewWidth,NewHeight);
  1480.                             break;
  1481.  
  1482.                         case Stucki:
  1483.  
  1484.                             Error = DitherImage_Stucki(&BitMap,Image,NewWidth,NewHeight);
  1485.                             break;
  1486.  
  1487.                         case BlueNoise:
  1488.  
  1489.                             Error = DitherImage_BlueNoise(&BitMap,Image,NewWidth,NewHeight,Result . threshold);
  1490.                             break;
  1491.  
  1492.                         case Ordered:
  1493.  
  1494.                             Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedVanilla);
  1495.                             break;
  1496.  
  1497.                         case Halftone:
  1498.  
  1499.                             switch(Result . dither_opt)
  1500.                             {
  1501.                                 case 4:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedHalftone4);
  1502.                                     break;
  1503.  
  1504.                                 case 8:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedHalftone8);
  1505.                                     break;
  1506.  
  1507.                                 default:Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedHalftone);
  1508.                                     break;
  1509.                             }
  1510.  
  1511.                             break;
  1512.  
  1513.                         case RandomNoise:
  1514.  
  1515.                             Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,NULL);
  1516.                             break;
  1517.  
  1518.                         case BckBrick:
  1519.  
  1520.                             switch(Result . dither_opt)
  1521.                             {
  1522.                                 case 4:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedBckBrick4);
  1523.                                     break;
  1524.  
  1525.                                 case 8:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedBckBrick8);
  1526.                                     break;
  1527.  
  1528.                                 default:Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedBckBrick);
  1529.                                     break;
  1530.                             }
  1531.  
  1532.                             break;
  1533.  
  1534.                         case FwdBrick:
  1535.  
  1536.                             switch(Result . dither_opt)
  1537.                             {
  1538.                                 case 4:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedFwdBrick4);
  1539.                                     break;
  1540.  
  1541.                                 case 8:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedFwdBrick8);
  1542.                                     break;
  1543.  
  1544.                                 default:Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedFwdBrick);
  1545.                                     break;
  1546.                             }
  1547.  
  1548.                             break;
  1549.  
  1550.                         case Hexagon:
  1551.  
  1552.                             Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedHexagonalCluster);
  1553.                             break;
  1554.  
  1555.                         case SpiralDot:
  1556.  
  1557.                             switch(Result . dither_opt)
  1558.                             {
  1559.                                 case 4:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedSpiralDot4);
  1560.                                     break;
  1561.  
  1562.                                 case 8:    Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedSpiralDot8);
  1563.                                     break;
  1564.  
  1565.                                 default:Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedSpiralDot);
  1566.                                     break;
  1567.                             }
  1568.  
  1569.                             break;
  1570.  
  1571.                         case Horizontal:
  1572.  
  1573.                             Error = DitherImage_Matrix(&BitMap,Image,NewWidth,NewHeight,OrderedHorizontal);
  1574.                             break;
  1575.                     }
  1576.  
  1577.                     if(!BitMap)
  1578.                         Error = ERR_NO_MEM;
  1579.                 }
  1580.  
  1581.                 if(BitMap)
  1582.                 {
  1583.                     if(Configuration . draw_modus == DRAW_IN_MEM_B || Configuration . draw_modus == DRAW_FILE_B)
  1584.                         SpecialMap . where_is = LOC_BITMAP_BORDER;
  1585.                     else
  1586.                         SpecialMap . where_is = LOC_BITMAP;
  1587.  
  1588.                     SpecialMap . width    = NewWidth;
  1589.                     SpecialMap . height    = NewHeight;
  1590.                     SpecialMap . loc . map    = (ULONG *)BitMap -> Planes[0];
  1591.  
  1592.                     if(Configuration . invert_bmap)
  1593.                         BltBitMap(BitMap,0,0,BitMap,0,0,NewWidth,NewHeight,0x50,1,NULL);
  1594.  
  1595.                     if(Configuration . draw_modus == DRAW_FILE || Configuration . draw_modus == DRAW_FILE_B)
  1596.                     {
  1597.                         struct AsyncFile *File;
  1598.  
  1599.                         PrintLine("Saving picture...");
  1600.  
  1601.                         Error = 0;
  1602.  
  1603.                         if(File = OpenAsync(FileName,MODE_WRITE,2 * 16384))
  1604.                         {
  1605.                             ULONG Magic[4];
  1606.  
  1607.                             Magic[0] = MAGIC_WORD;
  1608.                             Magic[1] = Sum1;
  1609.                             Magic[2] = SpecialMap . width;
  1610.                             Magic[3] = SpecialMap . height;
  1611.  
  1612.                             if(WriteAsync(File,Magic,sizeof(Magic)) == sizeof(Magic))
  1613.                             {
  1614.                                 PLANEPTR    Plane = BitMap -> Planes[0];
  1615.                                 LONG        i;
  1616.  
  1617.                                 SetMaxProgress(BitMap -> Rows - 1);
  1618.  
  1619.                                 for(i = 0 ; i < BitMap -> Rows ; i++)
  1620.                                 {
  1621.                                     if(WriteAsync(File,Plane,BitMap -> BytesPerRow) != BitMap -> BytesPerRow)
  1622.                                     {
  1623.                                         Error = IoErr();
  1624.  
  1625.                                         break;
  1626.                                     }
  1627.                                     else
  1628.                                     {
  1629.                                         Plane += BitMap -> BytesPerRow;
  1630.  
  1631.                                         ShowProgress(i);
  1632.                                     }
  1633.                                 }
  1634.                             }
  1635.                             else
  1636.                                 Error = IoErr();
  1637.  
  1638.                             CloseAsync(File);
  1639.                         }
  1640.                         else
  1641.                             Error = IoErr();
  1642.  
  1643.                         if(Error)
  1644.                         {
  1645.                             STRPTR Result = ShowError(Error,NULL,TRUE); /* (ghi) fixed */
  1646.  
  1647.                             if(Result)
  1648.                                 PrintLine("\33bError saving picture: %s.\33n",Result);
  1649.                             else
  1650.                                 PrintLine("\33bError saving picture.\33n");
  1651.  
  1652.                             DeleteFile(FileName);
  1653.                         }
  1654.                         else
  1655.                             AddProtection(FileName,FIBF_EXECUTE);
  1656.                     }
  1657.  
  1658.                 }
  1659.  
  1660.                 if(!BitMap)
  1661.                 {
  1662.                     if(Error)
  1663.                     {
  1664.                         STRPTR Result = ShowError(Error,NULL,TRUE);
  1665.  
  1666.                         if(Result)
  1667.                             PrintLine("\33b%s.\33n",Result);
  1668.                     }
  1669.  
  1670.                     Message -> ret = 5;
  1671.                 }
  1672.  
  1673.                 DeleteImage(Image);
  1674.             }
  1675.             else
  1676.             {
  1677.                 STRPTR Result = ShowError(Error,NULL,TRUE);
  1678.  
  1679.                 if(Result)
  1680.                     PrintLine("\33bError loading picture: %s.\33n",Result);
  1681.                 else
  1682.                     PrintLine("\33bError loading picture.\33n");
  1683.  
  1684.                 Message -> ret = 5;
  1685.             }
  1686.         }
  1687.     }
  1688.  
  1689.     if(Result . psfile[0]) /* (ghi) fixed; `psfile' instead of `iffile' */
  1690.     {
  1691.         LONG PS_hoff, PS_voff;
  1692.         PSGetSizeDot(&Result, &SpecialMap . width, &SpecialMap . height, &PS_hoff, &PS_voff, &SpecialMap . hoffset, &SpecialMap . voffset); /* (ghi) */
  1693.  
  1694.         if(Configuration . draw_modus == DRAW_BORDER || Configuration . draw_modus == DRAW_RECT)
  1695.         {
  1696.             if(Configuration . draw_modus == DRAW_BORDER)
  1697.                 SpecialMap . where_is = LOC_BORDER;
  1698.             else
  1699.                 SpecialMap . where_is = LOC_RECTANGLE;
  1700.         }
  1701.         else
  1702.         {
  1703.             UBYTE FileName[MAX_FILENAME_LEN];
  1704.  
  1705.             if(Configuration . draw_modus == DRAW_FILE || Configuration . draw_modus == DRAW_FILE_B)
  1706.             {
  1707.                 LONG    DateResult;
  1708.                 BPTR    File;
  1709.                 LONG    Error;
  1710.  
  1711.                 if(!BuildName(FileName,Home,Result . psfile,Result . hres,Result . vres,Sum1,&Error))
  1712.                 {
  1713.                     STRPTR Result = ShowError(Error,NULL,TRUE);
  1714.  
  1715.                     if(Result)
  1716.                         PrintLine("\33bCannot store converted image: %s.\33n",Result);
  1717.                     else
  1718.                         PrintLine("\33bCannot store converted image.\33n");
  1719.  
  1720.                     Message -> ret = 5;
  1721.  
  1722.                     memcpy(&Configuration,&ConfigBackup,sizeof(struct config_struct));
  1723.  
  1724.                     if(OldDir)
  1725.                         CurrentDir(OldDir);
  1726.  
  1727.                     if(NewDir)
  1728.                         UnLock(NewDir);
  1729.  
  1730.                     return(NULL);
  1731.                 }
  1732.  
  1733.                 Sum2 = Sum1 + 1;
  1734.  
  1735.                 if(File = Open(FileName,MODE_OLDFILE))
  1736.                 {
  1737.                     LONG Magic[2];
  1738.  
  1739.                     if(Read(File,Magic,sizeof(Magic)))
  1740.                     {
  1741.                         if(Magic[0] == MAGIC_WORD)
  1742.                             Sum2 = Magic[1];
  1743.                     }
  1744.  
  1745.                     Close(File);
  1746.                 }
  1747.  
  1748.                 DateResult = FileDateCheck(Result . psfile,FileName,&Error);
  1749.  
  1750.                 if(Error || DateResult < 0) /* (ghi) fixed */
  1751.                     Sum2 = Sum1 + 1;
  1752.  
  1753.                 if(Sum1 == Sum2)
  1754.                 {
  1755.                     STATIC UBYTE BitMapFileName[MAX_FILENAME_LEN];
  1756.  
  1757.                     if(Configuration . draw_modus == DRAW_FILE)
  1758.                         SpecialMap . where_is = LOC_FILE;
  1759.                     else
  1760.                         SpecialMap . where_is = LOC_FILE_BORDER;
  1761.  
  1762.                     strcpy(BitMapFileName,FileName);
  1763.  
  1764.                     SpecialMap . loc . filename = BitMapFileName;
  1765.  
  1766.                     if (psfig_status == PSFIG_END)
  1767.                         psfig_status = PSFIG_OFF; /* re-init psfig_status */
  1768.  
  1769.                     PrintLine("Done.");
  1770.                     PrintLine("");
  1771.  
  1772.                     memcpy(&Configuration,&ConfigBackup,sizeof(struct config_struct));
  1773.  
  1774.                     if(OldDir)
  1775.                         CurrentDir(OldDir);
  1776.  
  1777.                     if(NewDir)
  1778.                         UnLock(NewDir);
  1779.  
  1780.                     return(NULL);
  1781.                 }
  1782.             }
  1783.  
  1784.             InvertChanged = FALSE;
  1785.  
  1786.             if(BitMap = ProcessPostscript(Message,&SpecialMap,&Result,&Error))
  1787.             {
  1788.                 if(Configuration . draw_modus == DRAW_IN_MEM_B || Configuration . draw_modus == DRAW_FILE_B)
  1789.                     SpecialMap . where_is = LOC_BITMAP_BORDER;
  1790.                 else
  1791.                     SpecialMap . where_is = LOC_BITMAP;
  1792.  
  1793.                 SpecialMap . loc . map = (ULONG *)BitMap -> Planes[0];
  1794.  
  1795.                 if(Configuration . invert_bmap)
  1796.                     InvertBitMap(BitMap,SpecialMap . width,SpecialMap . height);
  1797.  
  1798.                 if(Configuration . draw_modus == DRAW_FILE || Configuration . draw_modus == DRAW_FILE_B)
  1799.                 {
  1800.                     struct AsyncFile *File;
  1801.  
  1802.                     PrintLine("Saving picture...");
  1803.  
  1804.                     Error = 0;
  1805.  
  1806.                     if(File = OpenAsync(FileName,MODE_WRITE,2 * 16384))
  1807.                     {
  1808.                         ULONG Magic[4];
  1809.  
  1810.                         Magic[0] = MAGIC_WORD;
  1811.                         Magic[1] = Sum1;
  1812.                         Magic[2] = SpecialMap . width;
  1813.                         Magic[3] = SpecialMap . height;
  1814.  
  1815.                         if(WriteAsync(File,Magic,sizeof(Magic)) == sizeof(Magic))
  1816.                         {
  1817.                             PLANEPTR    Plane = BitMap -> Planes[0];
  1818.                             LONG        i;
  1819.  
  1820.                             SetMaxProgress(BitMap -> Rows - 1);
  1821.  
  1822.                             for(i = 0 ; i < BitMap -> Rows ; i++)
  1823.                             {
  1824.                                 if(WriteAsync(File,Plane,BitMap -> BytesPerRow) != BitMap -> BytesPerRow)
  1825.                                 {
  1826.                                     Error = IoErr();
  1827.  
  1828.                                     break;
  1829.                                 }
  1830.                                 else
  1831.                                 {
  1832.                                     Plane += BitMap -> BytesPerRow;
  1833.  
  1834.                                     ShowProgress(i);
  1835.                                 }
  1836.                             }
  1837.                         }
  1838.                         else
  1839.                             Error = IoErr();
  1840.  
  1841.                         CloseAsync(File);
  1842.                     }
  1843.                     else
  1844.                         Error = IoErr();
  1845.  
  1846.                     if(Error)
  1847.                     {
  1848.                         STRPTR Result = ShowError(Error,NULL,TRUE); /* (ghi) fixed */
  1849.  
  1850.                         if(Result)
  1851.                             PrintLine("\33bError saving picture: %s.\33n",Result);
  1852.                         else
  1853.                             PrintLine("\33bError saving picture.\33n");
  1854.  
  1855.                         DeleteFile(FileName);
  1856.                     }
  1857.                     else
  1858.                         AddProtection(FileName,FIBF_EXECUTE);
  1859.                 }
  1860.  
  1861.             }
  1862.             else
  1863.             {
  1864.                 if(Error)
  1865.                 {
  1866.                     STRPTR Result = ShowError(Error,NULL,TRUE);
  1867.  
  1868.                     if(Result)
  1869.                         PrintLine("\33b%s.\33n",Result);
  1870.                 }
  1871.  
  1872.                 Message -> ret = 5;
  1873.             }
  1874.         }
  1875.     }
  1876.  
  1877.     memcpy(&Configuration,&ConfigBackup,sizeof(struct config_struct));
  1878.  
  1879.     PrintLine("Done.");
  1880.     PrintLine("");
  1881.  
  1882.     ShowProgress(0);
  1883.  
  1884.     if(OldDir)
  1885.         CurrentDir(OldDir);
  1886.  
  1887.     if(NewDir)
  1888.         UnLock(NewDir);
  1889.  
  1890.     return(BitMap);
  1891. }
  1892.  
  1893. VOID __saveds
  1894. HandleInput()
  1895. {
  1896.     if(OpenAll())
  1897.     {
  1898.         if(UseGUI)
  1899.         {
  1900.             if(OpenGUI())
  1901.             {
  1902.                 BOOL    Done = FALSE;
  1903.                 ULONG    SignalMask,Signals;
  1904.                 LONG    Value;
  1905.  
  1906.                 SignalMask = Signals = NULL;
  1907.  
  1908.                 do
  1909.                 {
  1910.                     if(Signals & SIGBREAKF_CTRL_C)
  1911.                         Done = TRUE;
  1912.  
  1913.                     switch(DoMethod(AP_Application,MUIM_Application_Input,&SignalMask))
  1914.                     {
  1915.                         case MEN_QUIT:
  1916.                         case MUIV_Application_ReturnID_Quit:
  1917.  
  1918.                             Done = TRUE;
  1919.                             break;
  1920.  
  1921.                         case GAD_TRANSFER:
  1922.  
  1923.                             ChangeDrawMode(0,0,TRUE);
  1924.                             break;
  1925.  
  1926.                         case GAD_RENDER:
  1927.  
  1928.                             ChangeDrawMode(0,0,TRUE);
  1929.                             break;
  1930.  
  1931.                         case GAD_INVERT:
  1932.  
  1933.                             get(CM_Invert,MUIA_Selected,&Value);
  1934.  
  1935.                             Configuration . invert_bmap = Value;
  1936.  
  1937.                             InvertChanged = TRUE;
  1938.  
  1939.                             break;
  1940.  
  1941.                         case GAD_BASEDPI:
  1942.  
  1943.                             get(ST_BaseDPI,MUIA_String_Integer,&Value);
  1944.  
  1945.                             if(!Value)
  1946.                                 set(ST_BaseDPI,MUIA_String_Integer,Configuration . base_dpi);
  1947.                             else
  1948.                                 Configuration . base_dpi = Value;
  1949.  
  1950.                             break;
  1951.  
  1952.                         case GAD_JUMP:
  1953.  
  1954.                             Configuration . use_pubscr = TRUE;
  1955.  
  1956.                             SignalMask = NULL;
  1957.  
  1958.                             ThisProcess -> pr_WindowPtr = OldPtr;
  1959.  
  1960.                             MUI_DisposeObject(AP_Application);
  1961.  
  1962.                             AP_Application = NULL;
  1963.  
  1964.                             if(PubScreen)
  1965.                             {
  1966.                                 UnlockPubScreen(NULL,PubScreen);
  1967.  
  1968.                                 PubScreen = NULL;
  1969.                             }
  1970.  
  1971.                             if(!OpenGUI())
  1972.                             {
  1973.                                 ShowError(ERR_NO_GUI,NULL,FALSE);
  1974.  
  1975.                                 Done = TRUE;
  1976.                             }
  1977.                             else
  1978.                                 DoMethod(WI_Main,MUIM_Window_ScreenToFront,NULL);
  1979.  
  1980.                             break;
  1981.  
  1982.                         case GAD_SHOW:
  1983.  
  1984.                             {
  1985.                                 struct Process *ShowDVI;
  1986.  
  1987.                                 Forbid();
  1988.  
  1989.                                 if(ShowDVI = (struct Process *)FindTask("ShowDVI-Task"))
  1990.                                 {
  1991.                                     Signal(ShowDVI,SIGBREAKF_CTRL_E);
  1992.  
  1993.                                     Permit();
  1994.                                 }
  1995.                                 else
  1996.                                 {
  1997.                                     Permit();
  1998.  
  1999.                                     PrintLine("ShowDVI is not currently running.");
  2000.                                 }
  2001.                             }
  2002.  
  2003.                             break;
  2004.  
  2005.                         case GAD_CLEAR:
  2006.  
  2007.                             DoMethod(LV_Messages,MUIM_List_Clear,0);
  2008.  
  2009.                             ClearList(&MessageList);
  2010.  
  2011.                             break;
  2012.  
  2013.                         case MEN_ABOUT:
  2014.  
  2015.                             MUI_Request(AP_Application,WI_Main,0,NULL,"Ok",
  2016.                                 "\33c\33\70"
  2017.                                 VERS
  2018.                                 "\33\62\n\n"
  2019.                                 "Last compiled "
  2020.                                 DATE
  2021.                                 "\n"
  2022.                                 "Copyright © 1993-1994 by Olaf `Olsen' Barthel & Georg Heßmann\n"
  2023.                                 "Improvements to PostScript support by Giuseppe Ghibò\n\n"
  2024.                                 "This is a MUI-Application.\n"
  2025.                                 "MUI is copyrighted by Stefan Stuntz.");
  2026.  
  2027.                             break;
  2028.  
  2029.                         case MEN_OPEN:
  2030.  
  2031.                             SetSleep(TRUE);
  2032.  
  2033.                             if(ReadConfig(&Configuration))
  2034.                             {
  2035.                                 SignalMask = NULL;
  2036.  
  2037.                                 ThisProcess -> pr_WindowPtr = OldPtr;
  2038.  
  2039.                                 MUI_DisposeObject(AP_Application);
  2040.  
  2041.                                 AP_Application = NULL;
  2042.  
  2043.                                 if(PubScreen)
  2044.                                 {
  2045.                                     UnlockPubScreen(NULL,PubScreen);
  2046.  
  2047.                                     PubScreen = NULL;
  2048.                                 }
  2049.  
  2050.                                 if(!OpenGUI())
  2051.                                 {
  2052.                                     ShowError(ERR_NO_GUI,NULL,FALSE);
  2053.  
  2054.                                     Done = TRUE;
  2055.                                 }
  2056.                                 else
  2057.                                     DoMethod(WI_Main,MUIM_Window_ScreenToFront,NULL);
  2058.                             }
  2059.                             else
  2060.                             {
  2061.                                 SetSleep(FALSE);
  2062.  
  2063.                                 switch(Configuration . draw_modus)
  2064.                                 {
  2065.                                     case DRAW_IN_MEM:
  2066.  
  2067.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Memory);
  2068.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_None);
  2069.                                         break;
  2070.  
  2071.                                     case DRAW_FILE:
  2072.  
  2073.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Disk);
  2074.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_None);
  2075.                                         break;
  2076.  
  2077.                                     case DRAW_IN_MEM_B:
  2078.  
  2079.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Memory);
  2080.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  2081.                                         break;
  2082.  
  2083.                                     case DRAW_FILE_B:
  2084.  
  2085.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_Disk);
  2086.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  2087.                                         break;
  2088.  
  2089.                                     case DRAW_BORDER:
  2090.  
  2091.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_None);
  2092.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Frame);
  2093.                                         break;
  2094.  
  2095.                                     case DRAW_RECT:
  2096.  
  2097.                                         set(CY_Transfer,    MUIA_Cycle_Active,CYID_Transfer_None);
  2098.                                         set(CY_Render,        MUIA_Cycle_Active,CYID_Render_Clear);
  2099.                                         break;
  2100.                                 }
  2101.  
  2102.                                 set(CM_Invert,MUIA_Selected,Configuration . invert_bmap);
  2103.  
  2104.                                 InvertChanged = TRUE;
  2105.  
  2106.                                 set(ST_BaseDPI,MUIA_String_Integer,Configuration . base_dpi);
  2107.                             }
  2108.  
  2109.                             break;
  2110.  
  2111.                         case MEN_SAVE:
  2112.  
  2113.                             SetSleep(TRUE);
  2114.  
  2115.                             SaveConfig(&Configuration);
  2116.  
  2117.                             SetSleep(FALSE);
  2118.  
  2119.                             break;
  2120.  
  2121.                         case MEN_PUBSCREEN:
  2122.  
  2123.                             {
  2124.                                 struct Window    *Window;
  2125.                                 BOOL         Reopen = FALSE;
  2126.  
  2127.                                 if(get(WI_Main,MUIA_Window_Window,&Window))
  2128.                                 {
  2129.                                     if(Window)
  2130.                                     {
  2131.                                         struct MenuItem *Item;
  2132.  
  2133.                                         if(Item = ItemAddress(Window -> MenuStrip,FULLMENUNUM(0,3,NOSUB)))
  2134.                                         {
  2135.                                             if(Item -> Flags & CHECKED)
  2136.                                             {
  2137.                                                 if(!Configuration . use_pubscr)
  2138.                                                     Reopen = Configuration . use_pubscr = TRUE;
  2139.                                             }
  2140.                                             else
  2141.                                             {
  2142.                                                 if(Configuration . use_pubscr)
  2143.                                                 {
  2144.                                                     Reopen                = TRUE;
  2145.                                                     Configuration . use_pubscr    = FALSE;
  2146.                                                 }
  2147.                                             }
  2148.                                         }
  2149.                                     }
  2150.                                 }
  2151.  
  2152.                                 if(Reopen)
  2153.                                 {
  2154.                                     SignalMask = NULL;
  2155.  
  2156.                                     ThisProcess -> pr_WindowPtr = OldPtr;
  2157.  
  2158.                                     MUI_DisposeObject(AP_Application);
  2159.  
  2160.                                     AP_Application = NULL;
  2161.  
  2162.                                     if(PubScreen)
  2163.                                     {
  2164.                                         UnlockPubScreen(NULL,PubScreen);
  2165.  
  2166.                                         PubScreen = NULL;
  2167.                                     }
  2168.  
  2169.                                     if(!OpenGUI())
  2170.                                     {
  2171.                                         ShowError(ERR_NO_GUI,NULL,FALSE);
  2172.  
  2173.                                         Done = TRUE;
  2174.                                     }
  2175.                                     else
  2176.                                         DoMethod(WI_Main,MUIM_Window_ScreenToFront,NULL);
  2177.                                 }
  2178.                             }
  2179.  
  2180.                             break;
  2181.                     }
  2182.  
  2183.                     if(!Done)
  2184.                     {
  2185.                         if(Signals & SIGBREAKF_CTRL_E)
  2186.                         {
  2187.                             Signals = NULL;
  2188.  
  2189.                             Configuration . use_pubscr = FALSE;
  2190.  
  2191.                             SignalMask = NULL;
  2192.  
  2193.                             ThisProcess -> pr_WindowPtr = OldPtr;
  2194.  
  2195.                             MUI_DisposeObject(AP_Application);
  2196.  
  2197.                             AP_Application = NULL;
  2198.  
  2199.                             if(PubScreen)
  2200.                             {
  2201.                                 UnlockPubScreen(NULL,PubScreen);
  2202.  
  2203.                                 PubScreen = NULL;
  2204.                             }
  2205.  
  2206.                             if(!OpenGUI())
  2207.                             {
  2208.                                 ShowError(ERR_NO_GUI,NULL,FALSE);
  2209.  
  2210.                                 Done = TRUE;
  2211.                             }
  2212.                             else
  2213.                                 DoMethod(WI_Main,MUIM_Window_ScreenToFront,NULL);
  2214.                         }
  2215.  
  2216.                         if(Signals & PORTMASK(MainPort))
  2217.                         {
  2218.                             struct special_msg    *Message;
  2219.                             struct BitMap        *BitMap;
  2220.  
  2221.                             while(Message = (struct special_msg *)GetMsg(MainPort))
  2222.                             {
  2223.                                 switch(Message -> action)
  2224.                                 {
  2225.                                     case AC_SEND_SPECIAL:
  2226.  
  2227.                                         SetSleep(TRUE);
  2228.  
  2229.                                         BitMap = ProcessImage(Message);
  2230.  
  2231.                                         Message -> action = AC_REPLY_SPECIAL;
  2232.  
  2233.                                         ReplyMsg((struct Message *)Message);
  2234.  
  2235.                                         WaitPort(MainPort);
  2236.  
  2237.                                         Message = (struct special_msg *)GetMsg(MainPort);
  2238.  
  2239.                                         if(Message -> action != AC_OK_BITMAP)
  2240.                                             PrintLine("\33bExpected AC_OK_BITMAP but found %d!\33n",Message -> action);
  2241.  
  2242.                                         Message -> action    = AC_REPLY_BITMAP;
  2243.                                         Message -> ret        = 0;
  2244.  
  2245.                                         ReplyMsg((struct Message *)Message);
  2246.  
  2247.                                         if(BitMap)
  2248.                                             DeleteBitMap(BitMap);
  2249.  
  2250.                                         SetSleep(FALSE);
  2251.  
  2252.                                         break;
  2253.  
  2254.                                     case AC_SEND_TPIC:
  2255.  
  2256.                                         SetSleep(TRUE);
  2257.  
  2258.                                         work_with_tpic(Message -> tpic,Message -> dmap,Message -> hresolution,Message -> vresolution);
  2259.  
  2260.                                         Message -> action    = AC_REPLY_TPIC;
  2261.                                         Message -> ret        = 0;
  2262.  
  2263.                                         ReplyMsg((struct Message *)Message);
  2264.  
  2265.                                         SetSleep(FALSE);
  2266.  
  2267.                                         break;
  2268.  
  2269.                                     default:
  2270.  
  2271.                                         PrintLine("\33bUnknown action Nº%d.\33n",Message -> action);
  2272.  
  2273.                                         Message -> action    = AC_REPLY_UNKNOWN;
  2274.                                         Message -> ret        = 0;
  2275.  
  2276.                                         ReplyMsg((struct Message *)Message);
  2277.  
  2278.                                         break;
  2279.                                 }
  2280.                             }
  2281.                         }
  2282.  
  2283.                         if(!Done)
  2284.                         {
  2285.                             if(SignalMask)
  2286.                                 Signals = Wait(SignalMask | PORTMASK(MainPort) | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_E);
  2287.                             else
  2288.                                 Signals = CheckSignal(PORTMASK(MainPort) | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_E);
  2289.                         }
  2290.                     }
  2291.                 }
  2292.                 while(!Done);
  2293.  
  2294.                 ThisProcess -> pr_WindowPtr = OldPtr;
  2295.  
  2296.                 MUI_DisposeObject(AP_Application);
  2297.  
  2298.                 AP_Application = NULL;
  2299.  
  2300.                 if(PubScreen)
  2301.                 {
  2302.                     UnlockPubScreen(NULL,PubScreen);
  2303.  
  2304.                     PubScreen = NULL;
  2305.                 }
  2306.             }
  2307.             else
  2308.                 ShowError(ERR_NO_GUI,NULL,FALSE);
  2309.         }
  2310.         else
  2311.         {
  2312.             ULONG Signals;
  2313.  
  2314.             FOREVER
  2315.             {
  2316.                 Signals = Wait(PORTMASK(MainPort) | SIGBREAKF_CTRL_C);
  2317.  
  2318.                 if(Signals & SIGBREAKF_CTRL_C)
  2319.                     break;
  2320.                 else
  2321.                 {
  2322.                     if(Signals & PORTMASK(MainPort))
  2323.                     {
  2324.                         struct special_msg    *Message;
  2325.                         struct BitMap        *BitMap;
  2326.  
  2327.                         while(Message = (struct special_msg *)GetMsg(MainPort))
  2328.                         {
  2329.                             switch(Message -> action)
  2330.                             {
  2331.                                 case AC_SEND_SPECIAL:
  2332.  
  2333.                                     BitMap = ProcessImage(Message);
  2334.  
  2335.                                     Message -> action = AC_REPLY_SPECIAL;
  2336.  
  2337.                                     ReplyMsg((struct Message *)Message);
  2338.  
  2339.                                     WaitPort(MainPort);
  2340.  
  2341.                                     Message = (struct special_msg *)GetMsg(MainPort);
  2342.  
  2343.                                     if(Message -> action != AC_OK_BITMAP)
  2344.                                         PrintLine("\33bExpected AC_OK_BITMAP but found %d!\33n",Message -> action);
  2345.  
  2346.                                     Message -> action    = AC_REPLY_BITMAP;
  2347.                                     Message -> ret        = 0;
  2348.  
  2349.                                     ReplyMsg((struct Message *)Message);
  2350.  
  2351.                                     if(BitMap)
  2352.                                         DeleteBitMap(BitMap);
  2353.  
  2354.                                     break;
  2355.  
  2356.                                 case AC_SEND_TPIC:
  2357.  
  2358.                                     work_with_tpic(Message -> tpic,Message -> dmap,Message -> hresolution,Message -> vresolution);
  2359.  
  2360.                                     Message -> action    = AC_REPLY_TPIC;
  2361.                                     Message -> ret        = 0;
  2362.  
  2363.                                     ReplyMsg((struct Message *)Message);
  2364.  
  2365.                                     break;
  2366.  
  2367.                                 default:
  2368.  
  2369.                                     PrintLine("\33bUnknown action Nº%d.\33n",Message -> action);
  2370.  
  2371.                                     Message -> action    = AC_REPLY_UNKNOWN;
  2372.                                     Message -> ret        = 0;
  2373.  
  2374.                                     ReplyMsg((struct Message *)Message);
  2375.  
  2376.                                     break;
  2377.                             }
  2378.                         }
  2379.                     }
  2380.                 }
  2381.             }
  2382.         }
  2383.     }
  2384.  
  2385.     CloseAll();
  2386. }
  2387.  
  2388. #pragma libcall GfxBase WritePixelLine8 306 9A210806
  2389. #pragma libcall GfxBase ReadPixelLine8 300 9a210806
  2390.  
  2391. VOID __regargs
  2392. SmallWriteLine(struct RastPort *RPort,LONG Line,LONG Width,UBYTE *Buffer,struct RastPort *Temp)
  2393. {
  2394.     if(Width > 1008)
  2395.     {
  2396.         LONG    Size    = 1008,
  2397.             Offset    = 0;
  2398.  
  2399.         do
  2400.         {
  2401.             WritePixelLine8(RPort,Offset,Line,Size,Buffer,Temp);
  2402.  
  2403.             Buffer    += Size;
  2404.             Offset    += Size;
  2405.             Width    -= Size;
  2406.  
  2407.             if(Width > 1008)
  2408.                 Size = 1008;
  2409.             else
  2410.                 Size = Width;
  2411.         }
  2412.         while(Width);
  2413.     }
  2414.     else
  2415.         WritePixelLine8(RPort,0,Line,Width,Buffer,Temp);
  2416. }
  2417.  
  2418. VOID __regargs
  2419. SmallReadLine(struct RastPort *RPort,LONG Line,LONG Width,UBYTE *Buffer,struct RastPort *Temp)
  2420. {
  2421.     if(Width > 1008)
  2422.     {
  2423.         LONG    Size    = 1008,
  2424.             Offset    = 0;
  2425.  
  2426.         do
  2427.         {
  2428.             ReadPixelLine8(RPort,Offset,Line,Size,Buffer,Temp);
  2429.  
  2430.             Buffer    += Size;
  2431.             Offset    += Size;
  2432.             Width    -= Size;
  2433.  
  2434.             if(Width > 1008)
  2435.                 Size = 1008;
  2436.             else
  2437.                 Size = Width;
  2438.         }
  2439.         while(Width);
  2440.     }
  2441.     else
  2442.         ReadPixelLine8(RPort,0,Line,Width,Buffer,Temp);
  2443. }
  2444.  
  2445. VOID __regargs
  2446. LargeWriteLine(struct RastPort *RPort,LONG Line,LONG Width,UBYTE *Buffer,struct RastPort *Temp)
  2447. {
  2448.     if(Width > 32752)
  2449.     {
  2450.         LONG    Size    = 32752,
  2451.             Offset    = 0;
  2452.  
  2453.         do
  2454.         {
  2455.             WritePixelLine8(RPort,Offset,Line,Size,Buffer,Temp);
  2456.  
  2457.             Buffer    += Size;
  2458.             Offset    += Size;
  2459.             Width    -= Size;
  2460.  
  2461.             if(Width > 32752)
  2462.                 Size = 32752;
  2463.             else
  2464.                 Size = Width;
  2465.         }
  2466.         while(Width);
  2467.     }
  2468.     else
  2469.         WritePixelLine8(RPort,0,Line,Width,Buffer,Temp);
  2470. }
  2471.  
  2472. VOID __regargs
  2473. LargeReadLine(struct RastPort *RPort,LONG Line,LONG Width,UBYTE *Buffer,struct RastPort *Temp)
  2474. {
  2475.     if(Width > 32752)
  2476.     {
  2477.         LONG    Size    = 32752,
  2478.             Offset    = 0;
  2479.  
  2480.         do
  2481.         {
  2482.             ReadPixelLine8(RPort,Offset,Line,Size,Buffer,Temp);
  2483.  
  2484.             Buffer    += Size;
  2485.             Offset    += Size;
  2486.             Width    -= Size;
  2487.  
  2488.             if(Width > 32752)
  2489.                 Size = 32752;
  2490.             else
  2491.                 Size = Width;
  2492.         }
  2493.         while(Width);
  2494.     }
  2495.     else
  2496.         ReadPixelLine8(RPort,0,Line,Width,Buffer,Temp);
  2497. }
  2498.  
  2499. /* (ghi) Init_Transfer_Render(): given the draw_modus returns Transfer and
  2500.    Render, i.e. performs the reverse operation of the function
  2501.    ChangeDrawMode() */
  2502.  
  2503. STATIC VOID __regargs
  2504. Init_Transfer_Render(LONG *Transfer, LONG *Render, int draw_modus)
  2505. {
  2506.     switch (draw_modus)
  2507.     {
  2508.  
  2509.         case DRAW_IN_MEM:
  2510.  
  2511.             *Transfer = CYID_Transfer_Memory;
  2512.             *Render = CYID_Render_None;
  2513.             break;
  2514.  
  2515.         case DRAW_IN_MEM_B:
  2516.  
  2517.             *Transfer = CYID_Transfer_Memory;
  2518.             *Render = CYID_Render_Frame;
  2519.             break;
  2520.  
  2521.         case DRAW_FILE:
  2522.  
  2523.             *Transfer = CYID_Transfer_Disk;
  2524.             *Render = CYID_Render_None;
  2525.             break;
  2526.  
  2527.         case DRAW_FILE_B:
  2528.  
  2529.             *Transfer = CYID_Transfer_Disk;
  2530.             *Render = CYID_Render_Frame;
  2531.             break;
  2532.  
  2533.         case DRAW_BORDER:
  2534.  
  2535.             *Transfer = CYID_Transfer_None;
  2536.             *Render = CYID_Render_Frame;
  2537.             break;
  2538.  
  2539.         case DRAW_RECT:
  2540.  
  2541.             *Transfer = CYID_Transfer_None;
  2542.             *Render = CYID_Render_Clear;
  2543.             break;
  2544.  
  2545.         default:
  2546.  
  2547.             *Transfer = CYID_Transfer_Memory;
  2548.             *Render = CYID_Render_None;
  2549.             break;
  2550.  
  2551.     }
  2552.  
  2553. }
  2554.