home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / CreativeComputers.iso / shareware / text / dvi_3.62 / source / dvisrc.lha / dviamiga.c < prev    next >
C/C++ Source or Header  |  1994-02-16  |  58KB  |  2,001 lines

  1. /*
  2. ** Datei: DVIAMIGA.C
  3. ** Autor: Markus Zahn
  4. */
  5.  
  6. #include <ctype.h>
  7. #include <math.h>
  8. #include <setjmp.h>
  9. #include <stdarg.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <time.h>
  14.  
  15. #include <clib/alib_protos.h>
  16. #include <clib/asl_protos.h>
  17. #include <clib/dos_protos.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/icon_protos.h>
  22. #include <clib/intuition_protos.h>
  23. #include <clib/layers_protos.h>
  24. #include <pragmas/asl_pragmas.h>
  25. #include <pragmas/dos_pragmas.h>
  26. #include <pragmas/exec_pragmas.h>
  27. #include <pragmas/gadtools_pragmas.h>
  28. #include <pragmas/graphics_pragmas.h>
  29. #include <pragmas/icon_pragmas.h>
  30. #include <pragmas/intuition_pragmas.h>
  31. #include <pragmas/layers_pragmas.h>
  32. #include <proto/wb.h>
  33. #include <devices/printer.h>
  34. #include <exec/memory.h>
  35. #include <intuition/gadgetclass.h>
  36.  
  37. #include "dvimisc.h"
  38. #include "dvi.h"
  39. #include "dvidvi.h"
  40. #include "dviframe.h"
  41. #include "dvihdcp.h"
  42. #include "dvisplin.h"
  43. #include "dvidraw.h"
  44. #include "dviver.h"
  45. #include "dviamiga.h"
  46. #include "dvi_req.h"
  47.  
  48. #ifndef MIN
  49. #define MIN(a,b) ((a)<(b) ? (a):(b))
  50. #endif
  51. #ifndef MAX
  52. #define MAX(a,b) ((b)<(a) ? (a):(b))
  53. #endif
  54. #ifndef ABS
  55. #define ABS(a) ((a)>0 ? (a):-(a))
  56. #endif
  57. #define ON_OFF(a) ((a) ? "ON":"OFF")
  58.  
  59. #define BUFSIZE 1024 /* Groesse des Druckerpuffers */
  60.  
  61. /*
  62.  * Prototypen
  63.  */
  64. void about_dvi( void );
  65. void *chip_frame_alloc( long s );
  66. void chip_frame_free( void huge *p, long s );
  67. void close_all( void );
  68. void ClearBusyPointer( struct Window *window );
  69. void dir_setup( void );
  70. int dvi_filereq( void );
  71. void *fast_frame_alloc( long s );
  72. void fast_frame_free( void huge *p, long s );
  73. void get_dimen( char *string, double *dimen );
  74. void get_opts( char *argv[] );
  75. int goto_page( int nr );
  76. void halt( char *format, ... );
  77. void main_loop( void );
  78. void margins_setup( void );
  79. int open_all( void );
  80. int open_menu( void );
  81. int open_screen( void );
  82. int open_window( void );
  83. void out_newline( void );
  84. void out_string( char *s );
  85. void prbyte( int c );
  86. void print_pages( int start, int end, int step );
  87. void print_range( void );
  88. void printer_setup( void );
  89. int process_idcmp_messages( struct MsgPort *msgport, int *newpage, int *update );
  90. int process_wb_messages( struct MsgPort *app_menu_port );
  91. int request_integer( int *value, char *txt );
  92. int request_range( int *first, int *last, int *step );
  93. void SetBusyPointer( struct Window *window );
  94. int stop_key( void );
  95. void update_window( void );
  96. void write_opts( void );
  97.  
  98. /*
  99.  * Globale Variablen fⁿr Screen, Window, Libraries etc.
  100.  * Die LibraryBases werden vom SAS/C 6.50 automatisch initialisiert!
  101.  */
  102. extern struct Library *GfxBase, *IntuitionBase, *IconBase;
  103. extern struct Library *GadToolsBase, *AslBase, *LayersBase;
  104. extern struct Library *DOSBase;
  105. struct Screen *scr = NULL;
  106. struct Window *win = NULL, *sbm_win = NULL;
  107. struct BitMap *bmap = NULL;
  108. struct Menu *mnu = NULL;
  109. struct IOStdReq *prt_req;
  110. APTR vis = NULL;
  111. BPTR out_handle = MKBADDR( NULL );
  112. struct MsgPort *app_menu_port = NULL;
  113. struct AppMenuItem *app_menu_item = NULL;
  114. static struct NewMenu new_menu[] =
  115. {
  116.   NM_TITLE, (STRPTR)"Project", NULL, 0, 0, NULL,
  117.    NM_ITEM, (STRPTR)"Load DVI...", (STRPTR)"L", 0, 0, NULL,
  118.    NM_ITEM, (STRPTR)"Update DVI", (STRPTR)"U", NM_ITEMDISABLED, 0, NULL,
  119.    NM_ITEM, (STRPTR)"Save Options", (STRPTR)"S", 0, 0, NULL,
  120.    NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0, NULL,
  121.    NM_ITEM, (STRPTR)"About...", NULL, 0, 0, NULL,
  122.    NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0, NULL,
  123.    NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0, NULL,
  124.   NM_TITLE, (STRPTR)"Screen", NULL, NM_MENUDISABLED, 0, NULL,
  125.    NM_ITEM, (STRPTR)"Next Page", NULL, 0, 0, NULL,
  126.    NM_ITEM, (STRPTR)"Previous Page", NULL, 0, 0, NULL,
  127.    NM_ITEM, (STRPTR)"Goto Page...", (STRPTR)"G", 0, 0, NULL,
  128.    NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0, NULL,
  129.    NM_ITEM, (STRPTR)"Magnification...", (STRPTR)"M", 0, 0, NULL,
  130.   NM_TITLE, (STRPTR)"Printer", NULL, NM_MENUDISABLED, 0, NULL,
  131.    NM_ITEM, (STRPTR)"Print Range...", (STRPTR)"P", 0, 0, NULL,
  132.    NM_ITEM, (STRPTR)"Print Page", NULL, 0, 0, NULL,
  133.    NM_ITEM, (STRPTR)"Print Document", NULL, 0, 0, NULL,
  134.   NM_TITLE, (STRPTR)"Setup", NULL, 0, 0, NULL,
  135.    NM_ITEM, (STRPTR)"Directories...", NULL, 0, 0, NULL,
  136.    NM_ITEM, (STRPTR)"Margins...", NULL, 0, 0, NULL,
  137.    NM_ITEM, (STRPTR)"Options", NULL, 0, 0, NULL,
  138. #define FIRST_OPTIONS 22
  139.     NM_SUB, (STRPTR)"Eject", NULL, CHECKIT | MENUTOGGLE, 0, NULL,
  140.     NM_SUB, (STRPTR)"Landscape", NULL, CHECKIT | MENUTOGGLE, 0, NULL,
  141.     NM_SUB, (STRPTR)"Memory", NULL, CHECKIT | MENUTOGGLE, 0, NULL,
  142.     NM_SUB, (STRPTR)"Pictures", NULL, CHECKIT | MENUTOGGLE, 0, NULL,
  143.     NM_SUB, (STRPTR)"Separate", NULL, CHECKIT | MENUTOGGLE, 128, NULL,
  144.     NM_SUB, (STRPTR)"Showfonts", NULL, CHECKIT | MENUTOGGLE, 0, NULL,
  145.     NM_SUB, (STRPTR)"Singlesheet", NULL, CHECKIT | MENUTOGGLE, 0, NULL,
  146.     NM_SUB, (STRPTR)"Thinout", NULL, CHECKIT | MENUTOGGLE, 16, NULL,
  147.     NM_SUB, (STRPTR)"Tracechars", NULL, CHECKIT | MENUTOGGLE, 0, NULL,
  148.     NM_SUB, (STRPTR)"Tracemem", NULL, CHECKIT | MENUTOGGLE, 0, NULL,
  149.    NM_ITEM, (STRPTR)"Printer...", NULL, 0, 0, NULL,
  150.   NM_END, NULL, NULL, 0, 0, NULL
  151. };
  152. /* data for a busy pointer.
  153. ** this data must be in chip memory!!!
  154. */
  155. UWORD __chip waitPointer[] =
  156.     {
  157.     0x0000, 0x0000,     /* reserved, must be NULL */
  158.  
  159.     0x0400, 0x07C0,
  160.     0x0000, 0x07C0,
  161.     0x0100, 0x0380,
  162.     0x0000, 0x07E0,
  163.     0x07C0, 0x1FF8,
  164.     0x1FF0, 0x3FEC,
  165.     0x3FF8, 0x7FDE,
  166.     0x3FF8, 0x7FBE,
  167.     0x7FFC, 0xFF7F,
  168.     0x7EFC, 0xFFFF,
  169.     0x7FFC, 0xFFFF,
  170.     0x3FF8, 0x7FFE,
  171.     0x3FF8, 0x7FFE,
  172.     0x1FF0, 0x3FFC,
  173.     0x07C0, 0x1FF8,
  174.     0x0000, 0x07E0,
  175.  
  176.     0x0000, 0x0000,     /* reserved, must be NULL */
  177.     };
  178.  
  179. /*
  180.  * Globale Variablen
  181.  */
  182. static char buffer[BUFSIZE]; /* Druckerpuffer */
  183. static int count = 0;
  184. char scr_title[80], win_title[80];
  185. char opt_name[MAX_PATH_LEN];
  186. jmp_buf halt_jump;
  187. int bmp_width, bmp_height, act_page = 1;
  188. ami_options aop =
  189. {
  190.   0,    /* Magnification fⁿr Ausdruck */
  191.   0,    /* kein Redirect */
  192.   "",   /* Name der Redirection Datei */
  193.   0     /* Bitmapgroesse beim Ausdruck */
  194. };
  195. struct prt_def p_defs[] =
  196. {
  197.   180, 180, p6low, "p6low",
  198.   360, 360, p6high, "p6high",
  199.   360, 180, p6mid, "p6mid",
  200.   240, 216, fx80, "fx80",
  201.   300, 300, hplj, "hplj",
  202.   100, 100, hpljlow, "hpljlow",
  203.   300, 300, bj300, "bj300"
  204. };
  205.  
  206. /*
  207.  * Version String fⁿr die Abfrage durch 'version'
  208.  */
  209. char version[] = "\0$VER: DVI "DVI_VER" "__AMIGADATE__;
  210. char __near *__procname = "DVI "DVI_VER; /* Name des Hintergrundprozesses */
  211. long __near __stack = 8192; /* minimaler Stack f"ur dvi */
  212.  
  213. void *(*frame_alloc)( long );
  214. void (*frame_free)( void huge*, long );
  215.  
  216. void *fast_frame_alloc( long s )
  217. {
  218.   return( mem_alloc( s, "Frame-Buffer" ) );
  219. }
  220.  
  221. void fast_frame_free( void huge *p, long s )
  222. {
  223.   mem_free( p, s );
  224. }
  225.  
  226. void *chip_frame_alloc( long s )
  227. {
  228.   int plane, ok = TRUE;
  229.  
  230.   bmp_width = frame_width * 8;
  231.   bmp_height = frame_height + MAX_PINS;
  232.  
  233.   if( GfxBase->lib_Version >= 39 )
  234.     bmap = AllocBitMap( bmp_width,
  235.       bmp_height,
  236.       scr->RastPort.BitMap->Depth,
  237.       BMF_CLEAR,
  238.       NULL );
  239.   else
  240.   {
  241.     bmap = AllocMem( sizeof( struct BitMap ), MEMF_PUBLIC | MEMF_CLEAR );
  242.     if( bmap != NULL )
  243.     {
  244.       InitBitMap( bmap, scr->BitMap.Depth, bmp_width, bmp_height );
  245.  
  246.       for( plane = 0; plane < scr->BitMap.Depth; plane++ )
  247.       {
  248.         bmap->Planes[plane] = AllocRaster( bmp_width, bmp_height );
  249.         ok = ok && ( bmap->Planes[plane] != NULL );
  250.       }
  251.  
  252.       if( !ok )
  253.       {
  254.         for( plane = 0; plane < scr->BitMap.Depth; plane++ )
  255.           if( bmap->Planes[plane] != NULL )
  256.             FreeRaster( bmap->Planes[plane], bmp_width, bmp_height );
  257.         FreeMem( bmap, sizeof( struct BitMap ) );
  258.         bmap = NULL;
  259.         halt( "Error: Cannot allocate memory for Frame-Buffer" );
  260.             return( NULL );
  261.       }
  262.     }
  263.   }
  264.  
  265.   if( bmap == NULL )
  266.   {
  267.     halt( "Error: Cannot allocate memory for Frame-Buffer" );
  268.     return( NULL );
  269.   }
  270.  
  271.   /*
  272.    * Speicher da, alles ok, Bitmap initialisiert.
  273.    * Jetzt: SuperBitmap Window
  274.    */
  275.   if( sbm_win = OpenWindowTags( NULL, WA_Top, (ULONG)( scr->BarHeight + 1 ),
  276.       WA_Left, (ULONG)0, WA_Width, (ULONG)scr->Width,
  277.       WA_Height, (ULONG)( scr->Width, scr->Height - scr->BarHeight - 1 ),
  278.       WA_MaxHeight, (ULONG)scr->Height,
  279.       WA_MaxWidth, (ULONG)scr->Width,
  280.       WA_Title, (ULONG)scr_title,
  281.       WA_Flags, WFLG_ACTIVATE | WFLG_SUPER_BITMAP | WFLG_GIMMEZEROZERO |
  282.         WFLG_REPORTMOUSE | WFLG_NOCAREREFRESH,
  283.       WA_CloseGadget, (ULONG)TRUE,
  284.       WA_DepthGadget, (ULONG)TRUE,
  285.       WA_NewLookMenus, (ULONG)TRUE,
  286.       WA_IDCMP, IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_MENUPICK |
  287.         IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS,
  288.       WA_PubScreen, (ULONG)scr,
  289.       WA_SuperBitMap, bmap,
  290.       TAG_DONE ) )
  291.   {
  292.     SetRast( sbm_win->RPort, 0 );
  293.     SetMenuStrip( sbm_win, mnu );
  294.     GT_RefreshWindow( sbm_win, NULL );
  295.     return( bmap->Planes[0] );
  296.   }
  297.   else
  298.     chip_frame_free( bmap, s );
  299.   return( NULL );
  300. }
  301.  
  302. void chip_frame_free( void huge *p, long s )
  303. {
  304.   int plane;
  305.  
  306.   if( sbm_win != NULL )
  307.   {
  308.     CloseWindow( sbm_win );
  309.     sbm_win = NULL;
  310.   }
  311.  
  312.   if( bmap != NULL )
  313.   {
  314.     if( GfxBase->lib_Version >= 39 )
  315.       FreeBitMap( bmap );
  316.     else
  317.     {
  318.       for( plane = 0; plane < scr->BitMap.Depth; plane++ )
  319.         if( bmap->Planes[plane] != NULL )
  320.           FreeRaster( bmap->Planes[plane], bmp_width, bmp_height );
  321.       FreeMem( bmap, sizeof( struct BitMap ) );
  322.     }
  323.     bmap = NULL;
  324.   }
  325. }
  326.  
  327. void about_dvi( void )
  328. {
  329.   struct EasyStruct req =
  330.   {
  331.     sizeof( struct EasyStruct ),
  332.     0,
  333.     (UBYTE *)"About DVI",
  334.     (UBYTE *)"   DVI %s ⌐ 1994\n"
  335.              "½╗½╗½╗½╗½╗½╗½╗½╗½╗½╗\n"
  336.              "  Ingo Eichenseher\n"
  337.              "  Gerhard Wilhelms\n"
  338.              "    Markus Zahn\n"
  339.              "½╗½╗½╗½╗½╗½╗½╗½╗½╗½╗\n"
  340.              "Amiga Version ⌐ 1994\n"
  341.              "    Markus Zahn\n"
  342.              "Zahn@Uni-Augsburg.DE",
  343.     (UBYTE *)"OK"
  344.   };
  345.  
  346.   EasyRequest( win, &req, NULL, version_string );
  347. }
  348.  
  349. void close_all( void )
  350. {
  351.   if( app_menu_item != NULL )
  352.     RemoveAppMenuItem( app_menu_item );
  353.   if( app_menu_port != NULL )
  354.     DeleteMsgPort( app_menu_port );
  355.   if( mnu != NULL )
  356.   {
  357.     ClearMenuStrip( win );
  358.     FreeMenus( mnu );
  359.   }
  360.   if( BADDR( out_handle ) != NULL )
  361.     if( Close( out_handle ) )
  362.       win = NULL; /* Das mit CON: verbundene Fenster wird automatisch geschlossen */
  363.   if( win != NULL )
  364.     CloseWindow( win );
  365.   if( vis != NULL )
  366.     FreeVisualInfo( vis );
  367.   if( scr !=NULL )
  368.     CloseScreen( scr );
  369. }
  370.  
  371. void ClearBusyPointer( struct Window *window )
  372. {
  373.   if( window != NULL )
  374.   {
  375.     if( IntuitionBase->lib_Version >= 39 )
  376.       SetWindowPointer( window, TAG_DONE );
  377.     else
  378.       ClearPointer( window );
  379.   }
  380. }
  381.  
  382. void dir_setup( void )
  383. {
  384.   int end = FALSE, ok = FALSE;
  385.   struct IntuiMessage *imsg;
  386.   struct Gadget *gad;
  387.   struct StringInfo *str_info;
  388.   options op_save;
  389.   
  390.   memcpy( &op_save, &op, sizeof( options ) ); /* Options zwischenspeichern */
  391.  
  392.   if( OpenDirectoriesWindow() == 0 )
  393.   {
  394.     GT_SetGadgetAttrs( DirectoriesGadgets[GD_pk_path], DirectoriesWnd, NULL,
  395.       GTST_String, (ULONG)op.pk_path, TAG_DONE );
  396.     GT_SetGadgetAttrs( DirectoriesGadgets[GD_tfm_path], DirectoriesWnd, NULL,
  397.       GTST_String, (ULONG)op.tfm_path, TAG_DONE );
  398.     GT_SetGadgetAttrs( DirectoriesGadgets[GD_img_path], DirectoriesWnd, NULL,
  399.       GTST_String, (ULONG)op.img_path, TAG_DONE );
  400.     GT_SetGadgetAttrs( DirectoriesGadgets[GD_gr_path], DirectoriesWnd, NULL,
  401.       GTST_String, (ULONG)op.input_path, TAG_DONE );
  402.     GT_SetGadgetAttrs( DirectoriesGadgets[GD_vf_path], DirectoriesWnd, NULL,
  403.       GTST_String, (ULONG)op.vf_path, TAG_DONE );
  404.     GT_SetGadgetAttrs( DirectoriesGadgets[GD_call_mf], DirectoriesWnd, NULL,
  405.       GTST_String, (ULONG)op.pk_callmf, TAG_DONE );
  406.  
  407.     ActivateGadget( DirectoriesGadgets[GD_pk_path], DirectoriesWnd, NULL );
  408.  
  409.     while( !end )
  410.     {
  411.       WaitPort( DirectoriesWnd->UserPort );
  412.       while( imsg = GT_GetIMsg( DirectoriesWnd->UserPort ) )
  413.       {
  414.         gad = imsg->IAddress;
  415.  
  416.         switch( imsg->Class )
  417.         {
  418.           case CLOSEWINDOW:
  419.             end = TRUE;
  420.             ok = FALSE;
  421.             break;
  422.           case GADGETUP:
  423.             switch( gad->GadgetID )
  424.             {
  425.               case GD_dir_ok:
  426.                 end = TRUE;
  427.                 ok = TRUE;
  428.                 break;
  429.               case GD_dir_cancel:
  430.                 end = TRUE;
  431.                 ok = FALSE;
  432.                 break;
  433.               default:
  434.                 break;
  435.             }
  436.             break;
  437.           default:
  438.             break;
  439.         }
  440.         GT_ReplyIMsg( imsg );
  441.       }
  442.     }
  443.     str_info = DirectoriesGadgets[GD_pk_path]->SpecialInfo;
  444.     strcpy( op.pk_path, str_info->Buffer );
  445.     str_info = DirectoriesGadgets[GD_tfm_path]->SpecialInfo;
  446.     strcpy( op.tfm_path, str_info->Buffer );
  447.     str_info = DirectoriesGadgets[GD_img_path]->SpecialInfo;
  448.     strcpy( op.img_path, str_info->Buffer );
  449.     str_info = DirectoriesGadgets[GD_gr_path]->SpecialInfo;
  450.     strcpy( op.input_path, str_info->Buffer );
  451.     str_info = DirectoriesGadgets[GD_vf_path]->SpecialInfo;
  452.     strcpy( op.vf_path, str_info->Buffer );
  453.     str_info = DirectoriesGadgets[GD_call_mf]->SpecialInfo;
  454.     strcpy( op.pk_callmf, str_info->Buffer );
  455.  
  456.     CloseDirectoriesWindow();
  457.   }
  458.  
  459.   if( !ok )
  460.     memcpy( &op, &op_save, sizeof( options ) );
  461. }
  462.  
  463. int dvi_filereq( void )
  464. {
  465.   struct FileRequester *freq = NULL;
  466.   BPTR file_lock = NULL, dir_lock = NULL;
  467.   int file_exists = FALSE;
  468.  
  469.   if( freq = AllocFileRequest() )
  470.   {
  471.     if( AslRequestTags( freq, ASL_Hail, (ULONG)"Load DVI",
  472.         ASL_OKText, (ULONG)"Load",
  473.         ASL_Window, (ULONG)win,
  474.         ASL_Pattern, (ULONG)"#?.dvi",
  475.         TAG_DONE ) )
  476.     {
  477.       if( dir_lock = Lock( freq->rf_Dir, ACCESS_READ ) )
  478.       {
  479.         dir_lock = CurrentDir( dir_lock );
  480.         if( file_lock = Lock( freq->rf_File, ACCESS_READ ) )
  481.         {
  482.           UnLock( file_lock );
  483.  
  484.           strcpy( dvi_name, freq->rf_File );
  485.           file_exists = TRUE;
  486.  
  487.           dvi_clean();
  488.           act_page = 1;
  489.         }
  490.         else
  491.           dir_lock = CurrentDir( dir_lock );
  492.         UnLock( dir_lock );
  493.       }
  494.     }
  495.     FreeFileRequest( freq );
  496.   }
  497.   return( file_exists );
  498. }
  499.  
  500. void get_dimen( char *string, double *dimen )
  501. {
  502.   char *s=string, c;
  503.   double r;
  504.  
  505.   while( *s == ' ' )  /* Leerzeichen ueberlesen */
  506.     s++;
  507.   if( *s == '-' || *s == '+' )
  508.     s++;
  509.   while( isdigit( *s ) || *s == '.' )
  510.     s++;
  511.   if( s == string )
  512.   {
  513.     print( "%s - Illegal dimension", string );
  514.     return;
  515.   }
  516.   strlwr( s ), c = *s, *s = 0, r = atof( string ), *s = c;
  517.   while( *s == ' ' )  /* Leerzeichen ueberlesen */
  518.     s++;
  519.   if( r == 0.0 && *s == '\0' )
  520.     *dimen = 0.0;
  521.   else if( strcmp( s, "in" ) == 0 )
  522.     *dimen = r;
  523.   else if( strcmp( s, "cm" ) == 0 )
  524.     *dimen= r / 2.54;
  525.   else if( strcmp( s, "pt" ) == 0 )
  526.     *dimen= r / 72.27;
  527.   else if( strcmp( s, "pc" ) == 0 )
  528.     *dimen= r * 12.0 / 72.27;
  529.   else if( strcmp( s, "bp" ) == 0 )
  530.     *dimen= r / 72.0;
  531.   else if( strcmp( s, "mm" ) == 0 )
  532.     *dimen= r / 25.4;
  533.   else if( strcmp( s, "dd" ) == 0 )
  534.     *dimen= r * 1238.0 / 72.27;
  535.   else if( strcmp( s, "cc" ) == 0 )
  536.     *dimen= r * 12 * 1238.0 / 72.27;
  537.   else if( strcmp( s, "sp" ) == 0 )
  538.     *dimen= r / 72.27 / 65536.0;
  539.     else
  540.   {
  541.     print( "%s - Illegal dimension", string );
  542.     return;
  543.   }
  544. }
  545.  
  546. void get_opts( char *argv[] )
  547. {
  548.   int i;
  549.   long r;
  550.   double density;
  551.   char *str, *rhs, *toup;
  552.  
  553.   for( i = 0; argv[i] != NULL; i++ )
  554.   {
  555.     if( strchr( argv[i], '=' ) != NULL )
  556.     {
  557.       str = strtok( argv[i], "=" );
  558.       rhs = strtok( NULL, "=\n" );
  559.  
  560.       /* Zuerst mal Schl"usselworte in Gro"sbuchstaben! */
  561.       for( toup = str; *toup != '\0'; toup++ )
  562.         *toup = toupper( *toup );
  563.  
  564.       if( strcmp( str, "COPIES" ) == 0 )
  565.       {
  566.         if( ( r = atol( rhs ) ) > 0 )
  567.           op.copies = r;
  568.       }
  569.       else if( strcmp( str, "HRESOLUTION" ) == 0 )
  570.       {
  571.         if( ( r = atol( rhs ) ) > 0 )
  572.           op.hres = r;
  573.       }
  574.       else if( strcmp( str, "MAGNIFICATION" ) == 0 )
  575.       {
  576.         if( ( r = atol( rhs ) ) > 0 )
  577.           op.new_mag = r;
  578.       }
  579. /*
  580.       else if( strcmp( str, "MAXMEM" ) == 0 )
  581.       {
  582.         if( ( r = atol( rhs ) ) > 0 )
  583.           op.maxmem = r;
  584.       }
  585. */
  586.       else if( strcmp( str, "PATHMEM" ) == 0 )
  587.       {
  588.         if( ( r = atol( rhs ) ) > 0 )
  589.           op.pathmem = r;
  590.       }
  591.       else if( strcmp( str, "PIXMEM" ) == 0 )
  592.       {
  593.         if( ( r = atol( rhs ) ) > 0 )
  594.           op.pixmem = r;
  595.       }
  596.       else if( strcmp( str, "VRESOLUTION" ) == 0 )
  597.       {
  598.         if( ( r = atol( rhs ) ) > 0 )
  599.           op.vres = r;
  600.       }
  601.       else if( strcmp( str, "DENSITY" ) == 0 )
  602.       {
  603.         density = atof( rhs );
  604.         op.density = MIN( MAX( 0.0, density ), 1.0 );
  605.       }
  606.       else if( strcmp( str, "PATH" ) == 0 )
  607.         strcpy( op.dvi_path, rhs );
  608.       else if( strcmp( str, "PKPATH" ) == 0 )
  609.         strcpy( op.pk_path, rhs );
  610.       else if( strcmp( str, "TFMPATH" ) == 0 )
  611.         strcpy( op.tfm_path, rhs );
  612.       else if( strcmp( str, "IMGPATH" ) == 0 )
  613.         strcpy( op.img_path, rhs );
  614.       else if( strcmp( str, "GRPATH" ) == 0 )
  615.         strcpy( op.input_path, rhs );
  616.       else if( strcmp( str, "VFPATH" ) == 0 )
  617.         strcpy( op.vf_path, rhs );
  618.       else if( strcmp( str, "CALLMF" ) == 0 )
  619.         strcpy( op.pk_callmf, rhs );
  620.       else if( strcmp( str, "REDIRECT" ) == 0 )
  621.       {
  622.         strcpy( aop.redir_name, rhs );
  623.         aop.redirect = ( aop.redir_name[0] != '\0' );
  624.       }
  625.       else if( strcmp( str, "LOGFILE" ) == 0 )
  626.         catfe( op.log_name, rhs, "log" );
  627.       else if( strcmp( str, "WIDTH" ) == 0 )
  628.         get_dimen( rhs, &op.width );
  629.       else if( strcmp( str, "HEIGHT" ) == 0 )
  630.         get_dimen( rhs, &op.height );
  631.       else if( strcmp( str, "HOFFSET" ) == 0 )
  632.         get_dimen( rhs, &op.hoffset );
  633.       else if( strcmp( str, "VOFFSET" ) == 0 )
  634.         get_dimen( rhs, &op.voffset );
  635.       else if( strcmp( str, "HMARGIN" ) == 0 )
  636.         get_dimen( rhs, &op.hmargin );
  637.       else if( strcmp( str, "VMARGIN" ) == 0 )
  638.         get_dimen( rhs, &op.vmargin );
  639.       else if( strcmp( str, "HSPREAD" ) == 0 )
  640.         get_dimen( rhs, &op.hspread );
  641.       else if( strcmp( str, "VSPREAD" ) == 0 )
  642.         get_dimen( rhs, &op.vspread );
  643.       else
  644.       {
  645.         /*
  646.          * Bei den restlichen Angaben wird die rechte Seite in
  647.          * Gro"sbuchstaben erwartet.
  648.          */
  649.         if( rhs != NULL )
  650.         {
  651.           for( toup = rhs; *toup != '\0'; toup++ )
  652.             *toup = toupper( *toup );
  653.  
  654.           if( strcmp( str, "OUTPUT" ) == 0 )
  655.           {
  656.             if( strcmp( rhs, "P6LOW" ) == 0 )
  657.               op.shipno = P6LOW;
  658.             else if( strcmp( rhs, "P6HIGH" ) == 0 )
  659.               op.shipno = P6HIGH;
  660.             else if( strcmp( rhs, "P6MID" ) == 0 )
  661.               op.shipno = P6MID;
  662.             else if( strcmp( rhs, "FX80" ) == 0 )
  663.               op.shipno = FX80;
  664.             else if( strcmp( rhs, "HPLJ" ) == 0 )
  665.               op.shipno = HPLJ;
  666.             else if( strcmp( rhs, "HPLJLOW" ) == 0 )
  667.               op.shipno = HPLJLOW;
  668.             else if( strcmp( rhs, "BJ300" ) == 0 )
  669.               op.shipno = BJ300;
  670.             else
  671.               op.shipno = NO_PRINTER;
  672.           }
  673.           else if( strcmp( str, "EJECT" ) == 0 )
  674.           {
  675.             if( strcmp( rhs, "ON" ) == NULL )
  676.             {
  677.               op.formfeed = TRUE;
  678.               new_menu[FIRST_OPTIONS].nm_Flags |= CHECKED;
  679.             }
  680.           }
  681.           else if( strcmp( str, "LANDSCAPE" ) == 0 )
  682.           {
  683.             if( strcmp( rhs, "ON" ) == NULL )
  684.             {
  685.               op.landscape = TRUE;
  686.               new_menu[FIRST_OPTIONS+1].nm_Flags |= CHECKED;
  687.             }
  688.           }
  689.           else if( strcmp( str, "MEMORY" ) == 0 )
  690.           {
  691.             if( strcmp( rhs, "ON" ) == NULL )
  692.             {
  693.               op.dvimemory = TRUE;
  694.               new_menu[FIRST_OPTIONS+2].nm_Flags |= CHECKED;
  695.             }
  696.           }
  697.           else if( strcmp( str, "PICTURES" ) == 0 )
  698.           {
  699.             if( strcmp( rhs, "ON" ) == NULL )
  700.             {
  701.               op.show_img = TRUE;
  702.               new_menu[FIRST_OPTIONS+3].nm_Flags |= CHECKED;
  703.             }
  704.           }
  705.           else if( strcmp( str, "SEPARATE" ) == 0 )
  706.           {
  707.             if( strcmp( rhs, "ON" ) == NULL )
  708.             {
  709.               op.separate = TRUE;
  710.               new_menu[FIRST_OPTIONS+4].nm_Flags |= CHECKED;
  711.               op.thin_out = FALSE;
  712.               new_menu[FIRST_OPTIONS+7].nm_Flags &= ~CHECKED;
  713.             }
  714.           }
  715.           else if( strcmp( str, "SHOWFONTS" ) == 0 )
  716.           {
  717.             if( strcmp( rhs, "ON" ) == NULL )
  718.             {
  719.               op.showfonts = TRUE;
  720.               new_menu[FIRST_OPTIONS+5].nm_Flags |= CHECKED;
  721.             }
  722.           }
  723.           else if( strcmp( str, "SINGLESHEET" ) == 0 )
  724.           {
  725.             if( strcmp( rhs, "ON" ) == NULL )
  726.             {
  727.               op.singlesheet = TRUE;
  728.               new_menu[FIRST_OPTIONS+6].nm_Flags |= CHECKED;
  729.             }
  730.           }
  731.           else if( strcmp( str, "THINOUT" ) == 0 )
  732.           {
  733.             if( strcmp( rhs, "ON" ) == NULL )
  734.             {
  735.               op.thin_out = TRUE;
  736.               new_menu[FIRST_OPTIONS+7].nm_Flags |= CHECKED;
  737.               op.separate = FALSE;
  738.               new_menu[FIRST_OPTIONS+4].nm_Flags &= ~CHECKED;
  739.             }
  740.           }
  741.           else if( strcmp( str, "TRACECHARS" ) == 0 )
  742.           {
  743.             if( strcmp( rhs, "ON" ) == NULL )
  744.             {
  745.               op.tracechars = TRUE;
  746.               new_menu[FIRST_OPTIONS+8].nm_Flags |= CHECKED;
  747.             }
  748.           }
  749.           else if( strcmp( str, "TRACEMEM" ) == 0 )
  750.           {
  751.             if( strcmp( rhs, "ON" ) == NULL )
  752.             {
  753.               op.tracemem = TRUE;
  754.               new_menu[FIRST_OPTIONS+9].nm_Flags |= CHECKED;
  755.             }
  756.           }
  757.         }
  758.       }
  759.     }
  760.   }
  761. }
  762.  
  763. int goto_page( int nr )
  764. {
  765.   if( nr == act_page || !frame_valid )
  766.     return( FALSE );
  767.   else
  768.     if( ( nr > 0 ) && ( nr <= dvi_info.pages ) )
  769.       act_page = nr;
  770.   return( act_page == nr );
  771. }
  772.  
  773. void halt( char *format, ... )
  774. {
  775.   extern void vprint( char *, va_list );
  776.   va_list l;
  777.  
  778.   va_start( l, format );
  779.   vprint( format, l );
  780.   va_end( l );
  781.   dvi_clean();
  782.   longjmp( halt_jump, 1 );
  783. }
  784.  
  785. void main_loop( void )
  786. {
  787.   int quit = FALSE, update = FALSE, newpage = dvi_name[0];
  788.   ULONG signals, sig_mask;
  789.  
  790.   while( !quit )
  791.   {
  792.     if( newpage )
  793.     {
  794.       SetBusyPointer( win );
  795.       SetBusyPointer( sbm_win );
  796.       newpage = FALSE;
  797.  
  798.       if( !setjmp( halt_jump ) )
  799.       {
  800.         act_page = format_pages( act_page, act_page, 1 );
  801.         OnMenu( win, FULLMENUNUM( 0, 1, NOSUB ) ); /* Update DVI anschalten */
  802.         OnMenu( win, FULLMENUNUM( 1, NOITEM, NOSUB ) ); /* Screen Menu an */
  803.         OnMenu( win, FULLMENUNUM( 2, NOITEM, NOSUB ) ); /* Printer Menue an */
  804.         update = TRUE;
  805.       }
  806.       else
  807.       {
  808.         OffMenu( win, FULLMENUNUM( 0, 1, NOSUB ) ); /* Update DVI abschalten */
  809.         OffMenu( win, FULLMENUNUM( 1, NOITEM, NOSUB ) ); /* Screen Menu aus */
  810.         OffMenu( win, FULLMENUNUM( 2, NOITEM, NOSUB ) ); /* Printer Menue aus */
  811.         update = FALSE;
  812.       }
  813.  
  814.       ClearBusyPointer( win );
  815.       ClearBusyPointer( sbm_win );
  816.     }
  817.  
  818.     if( update && frame_valid )
  819.     {
  820.       sprintf( win_title, "DVI File: %s - [%d]", FilePart( (UBYTE *)dvi_name ),
  821.         act_page );
  822.       SetWindowTitles( sbm_win, (UBYTE *)win_title, (UBYTE *)~0 );
  823.       update_window();
  824.       update = FALSE;
  825.     }
  826.  
  827.     sig_mask = 1 << win->UserPort->mp_SigBit;
  828.     if( sbm_win != NULL )
  829.       sig_mask |= 1 << sbm_win->UserPort->mp_SigBit;
  830.     if( app_menu_port != NULL )
  831.       sig_mask |= 1 << app_menu_port->mp_SigBit;
  832.  
  833.     signals = Wait( sig_mask );
  834.  
  835.     if( signals & ( 1 << win->UserPort->mp_SigBit ) )
  836.       quit = process_idcmp_messages( win->UserPort, &newpage, &update );
  837.     if( sbm_win != NULL )
  838.       if( signals & ( 1 << sbm_win->UserPort->mp_SigBit ) )
  839.         quit = process_idcmp_messages( sbm_win->UserPort, &newpage, &update );
  840.     if( app_menu_port )
  841.       if( signals & ( 1 << app_menu_port->mp_SigBit ) )
  842.         newpage = process_wb_messages( app_menu_port );
  843.   }
  844. }
  845.  
  846. void margins_setup( void )
  847. {
  848.   int end = FALSE, ok = FALSE;
  849.   struct IntuiMessage *imsg;
  850.   struct Gadget *gad;
  851.   struct StringInfo *str_info;
  852.   options op_save;
  853.   char str[MAX_PATH_LEN];
  854.   
  855.   memcpy( &op_save, &op, sizeof( options ) ); /* Options zwischenspeichern */
  856.  
  857.   if( OpenMarginsWindow() == 0 )
  858.   {
  859.     sprintf( str, "%.6lf in", op.hoffset );
  860.     GT_SetGadgetAttrs( MarginsGadgets[GD_h_offset], MarginsWnd, NULL,
  861.       GTST_String, (ULONG)str, TAG_DONE );
  862.     sprintf( str, "%.6lf in", op.voffset );
  863.     GT_SetGadgetAttrs( MarginsGadgets[GD_v_offset], MarginsWnd, NULL,
  864.       GTST_String, (ULONG)str, TAG_DONE );
  865.     sprintf( str, "%.6lf in", op.hspread );
  866.     GT_SetGadgetAttrs( MarginsGadgets[GD_h_spread], MarginsWnd, NULL,
  867.       GTST_String, (ULONG)str, TAG_DONE );
  868.     sprintf( str, "%.6lf in", op.vspread );
  869.     GT_SetGadgetAttrs( MarginsGadgets[GD_v_spread], MarginsWnd, NULL,
  870.       GTST_String, (ULONG)str, TAG_DONE );
  871.     sprintf( str, "%.6lf in", op.hmargin );
  872.     GT_SetGadgetAttrs( MarginsGadgets[GD_h_margin], MarginsWnd, NULL,
  873.       GTST_String, (ULONG)str, TAG_DONE );
  874.     sprintf( str, "%.6lf in", op.vmargin );
  875.     GT_SetGadgetAttrs( MarginsGadgets[GD_v_margin], MarginsWnd, NULL,
  876.       GTST_String, (ULONG)str, TAG_DONE );
  877.     sprintf( str, "%.6lf in", op.width );
  878.     GT_SetGadgetAttrs( MarginsGadgets[GD_width], MarginsWnd, NULL,
  879.       GTST_String, (ULONG)str, TAG_DONE );
  880.     sprintf( str, "%.6lf in", op.height );
  881.     GT_SetGadgetAttrs( MarginsGadgets[GD_height], MarginsWnd, NULL,
  882.       GTST_String, (ULONG)str, TAG_DONE );
  883.  
  884.     ActivateGadget( MarginsGadgets[GD_h_offset], MarginsWnd, NULL );
  885.  
  886.     while( !end )
  887.     {
  888.       WaitPort( MarginsWnd->UserPort );
  889.       while( imsg = GT_GetIMsg( MarginsWnd->UserPort ) )
  890.       {
  891.         gad = imsg->IAddress;
  892.  
  893.         switch( imsg->Class )
  894.         {
  895.           case CLOSEWINDOW:
  896.             end = TRUE;
  897.             ok = FALSE;
  898.             break;
  899.           case GADGETUP:
  900.             switch( gad->GadgetID )
  901.             {
  902.               case GD_marg_ok:
  903.                 end = TRUE;
  904.                 ok = TRUE;
  905.                 break;
  906.               case GD_marg_cancel:
  907.                 end = TRUE;
  908.                 ok = FALSE;
  909.                 break;
  910.               default:
  911.                 break;
  912.             }
  913.             break;
  914.           default:
  915.             break;
  916.         }
  917.         GT_ReplyIMsg( imsg );
  918.       }
  919.     }
  920.     str_info = MarginsGadgets[GD_h_offset]->SpecialInfo;
  921.     get_dimen( str_info->Buffer, &op.hoffset );
  922.     str_info = MarginsGadgets[GD_v_offset]->SpecialInfo;
  923.     get_dimen( str_info->Buffer, &op.voffset );
  924.     str_info = MarginsGadgets[GD_h_spread]->SpecialInfo;
  925.     get_dimen( str_info->Buffer, &op.hspread );
  926.     str_info = MarginsGadgets[GD_v_spread]->SpecialInfo;
  927.     get_dimen( str_info->Buffer, &op.vspread );
  928.     str_info = MarginsGadgets[GD_h_margin]->SpecialInfo;
  929.     get_dimen( str_info->Buffer, &op.hmargin );
  930.     str_info = MarginsGadgets[GD_v_margin]->SpecialInfo;
  931.     get_dimen( str_info->Buffer, &op.vmargin );
  932.     str_info = MarginsGadgets[GD_width]->SpecialInfo;
  933.     get_dimen( str_info->Buffer, &op.width );
  934.     str_info = MarginsGadgets[GD_height]->SpecialInfo;
  935.     get_dimen( str_info->Buffer, &op.height );
  936.  
  937.     CloseMarginsWindow();
  938.   }
  939.  
  940.   if( !ok )
  941.     memcpy( &op, &op_save, sizeof( options ) );
  942. }
  943.  
  944. int open_all( void )
  945. {
  946.   char out_name[64];
  947.  
  948.   if( open_screen() )
  949.   {
  950.     if( open_window() )
  951.     {
  952.       sprintf( out_name, "CON://///WINDOW %x", win );
  953.       out_handle = Open( out_name, MODE_OLDFILE );
  954.  
  955.       if( BADDR( out_handle ) != NULL )
  956.       {
  957.         if( app_menu_port = CreateMsgPort() )
  958.         {
  959.           app_menu_item = AddAppMenuItem( 1, NULL, "DVI", app_menu_port, TAG_DONE );
  960.  
  961.           if( open_menu() )
  962.             return( TRUE );
  963.           else
  964.             print( "Unable to create menu!" );
  965.         }
  966.         else
  967.           print( "Unable to create message port!" );
  968.       }
  969.       else
  970.         print( "Unable to attach console to control window!" );
  971.     }
  972.     else
  973.       print( "Unable to open window!" );
  974.   }
  975.   else
  976.     print( "Unable to open screen!" );
  977.  
  978.   return( FALSE );
  979. }
  980.  
  981. int open_menu( void )
  982. {
  983.   if( mnu = CreateMenus( new_menu, GTMN_NewLookMenus, (ULONG)TRUE, TAG_DONE ) )
  984.   {
  985.     LayoutMenus( mnu, vis, GTMN_NewLookMenus, (ULONG)TRUE, TAG_DONE );
  986.     SetMenuStrip( win, mnu );
  987.     GT_RefreshWindow( win, NULL );
  988.   }
  989.   return( mnu != NULL );
  990. }
  991.  
  992. int open_screen( void )
  993. {
  994.   struct Screen *default_screen;
  995.   struct DrawInfo *draw_info;
  996.   UWORD pen = (UWORD)~0;
  997.  
  998.   if( default_screen = LockPubScreen( NULL ) )
  999.   {
  1000.     draw_info = GetScreenDrawInfo( default_screen );
  1001.  
  1002.     if( scr = OpenScreenTags( NULL,
  1003.         SA_Title, (ULONG)scr_title,
  1004.         SA_DisplayID, GetVPModeID( &(default_screen->ViewPort) ),
  1005.         SA_Depth, draw_info ? (ULONG)( draw_info->dri_Depth ) : (ULONG)DEPTH,
  1006.         SA_Pens, draw_info ? (ULONG)( draw_info->dri_Pens ) : (ULONG)&pen,
  1007.         TAG_DONE ) )
  1008.       vis = GetVisualInfo( scr, TAG_DONE );
  1009.  
  1010.     if( draw_info )
  1011.       FreeScreenDrawInfo( default_screen, draw_info );
  1012.     UnlockPubScreen( NULL, default_screen );
  1013.   }
  1014.   return( scr && vis );
  1015. }
  1016.  
  1017. int open_window( void )
  1018. {
  1019.   win = OpenWindowTags( NULL, WA_Top, (ULONG)( scr->BarHeight + 1 ),
  1020.     WA_Left, (ULONG)0, WA_Width, (ULONG)scr->Width,
  1021.     WA_Height, 130, /* analog zum Shellfenster */
  1022.     WA_MinHeight, (ULONG)50, /* analog zum Shellfenster */
  1023.     WA_MinWidth, (ULONG)490, /* analog zum Shellfenster */
  1024.     WA_MaxHeight, (ULONG)scr->Height,
  1025.     WA_MaxWidth, (ULONG)scr->Width,
  1026.     WA_Title, (ULONG)"Control",
  1027.     WA_Flags, WFLG_ACTIVATE | WFLG_NOCAREREFRESH | WFLG_SMART_REFRESH,
  1028.     WA_CloseGadget, (ULONG)TRUE,
  1029.     WA_DepthGadget, (ULONG)TRUE,
  1030.     WA_DragBar, (ULONG)TRUE,
  1031.     WA_SizeGadget, (ULONG)TRUE,
  1032.     WA_NewLookMenus, (ULONG)TRUE,
  1033.     WA_IDCMP, IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_MENUPICK |
  1034.         IDCMP_CLOSEWINDOW,
  1035.     WA_PubScreen, (ULONG)scr,
  1036.     TAG_DONE );
  1037.   return( win != NULL );
  1038. }
  1039.  
  1040. void out_newline( void )
  1041. {
  1042.   if( BADDR( out_handle ) != NULL )
  1043.     FPutC( out_handle, '\n' );
  1044.   else
  1045.     fputc( '\n', stdout );
  1046. }
  1047.  
  1048. void out_string( char *s )
  1049. {
  1050.   if( BADDR( out_handle ) != NULL )
  1051.   {
  1052.     FPuts( out_handle, s );
  1053.     Flush( out_handle );
  1054.   }
  1055.   else
  1056.   {
  1057.     fputs( s, stdout );
  1058.     fflush( stdout );
  1059.   }
  1060. }
  1061.  
  1062. void print_pages( int start, int end, int step )
  1063. {
  1064.   options op_save;
  1065.   ami_options aop_save;
  1066.   int old_valid = frame_valid;
  1067.   struct MsgPort *prt_port;
  1068.   
  1069.   memcpy( &op_save, &op, sizeof( options ) ); /* Options zwischenspeichern */
  1070.   memcpy( &aop_save, &aop, sizeof( ami_options ) );
  1071.  
  1072.   op.hres = p_defs[op.shipno].hres; /* Optionen an Drucker anpassen */
  1073.   op.vres = p_defs[op.shipno].vres;
  1074.   shipout = p_defs[op.shipno].shipout;
  1075.   op.pixmem = aop.pixmem; /* Wieviel Speicher f"ur die Bitmap? */
  1076.  
  1077.   if( shipout && frame_valid )
  1078.   {
  1079.     if( aop.redirect )
  1080.     {
  1081.       if( aop.redir_name[0] == '\0' )
  1082.         strcpy( op.redirect, "output.prt" );
  1083.       else
  1084.         strcpy( op.redirect, aop.redir_name );
  1085.  
  1086.       SetBusyPointer( win );
  1087.       SetBusyPointer( sbm_win );
  1088.       ClearMenuStrip( win ); /* Menues aus */
  1089.  
  1090.       dvi_clean();
  1091.       frame_alloc = fast_frame_alloc;
  1092.       frame_free = fast_frame_free;
  1093.  
  1094.       if( !setjmp( halt_jump ) )
  1095.         format_pages( start, end, step );
  1096.  
  1097.       ResetMenuStrip( win, mnu ); /* Menues an */
  1098.     }
  1099.     else
  1100.     {
  1101.       if( prt_port = CreateMsgPort() )
  1102.       {
  1103.         if( prt_req = (struct IOStdReq*)CreateIORequest( prt_port, sizeof( struct IOStdReq ) ) )
  1104.         {
  1105.           if( OpenDevice( "printer.device", 0, (struct IORequest*)prt_req, 0 ) == 0 )
  1106.           {
  1107.             SetBusyPointer( win );
  1108.             SetBusyPointer( sbm_win );
  1109.             ClearMenuStrip( win ); /* Menues aus */
  1110.  
  1111.             dvi_clean();
  1112.             frame_alloc = fast_frame_alloc;
  1113.             frame_free = fast_frame_free;
  1114.  
  1115.             if( !setjmp( halt_jump ) )
  1116.               format_pages( start, end, step );
  1117.  
  1118.             if( prt_req->io_Error == PDERR_NOERR )
  1119.             {
  1120.               prt_req->io_Command = PRD_RAWWRITE;
  1121.               prt_req->io_Data = buffer;
  1122.               prt_req->io_Length = count;
  1123.  
  1124.               DoIO( (struct IORequest*)prt_req ); /* Druckerpuffer leeren */
  1125.             }
  1126.             count = 0; /* Keine Daten mehr im Druckerpuffer */
  1127.  
  1128.             ResetMenuStrip( win, mnu ); /* Menues an */
  1129.             CloseDevice( (struct IORequest*)prt_req );
  1130.           }
  1131.           else
  1132.             print( "Unable to open printer device!" );
  1133.           DeleteIORequest( (struct IORequest*)prt_req );
  1134.         }
  1135.         else
  1136.           print( "Unable to create IORequest!" );
  1137.         DeleteMsgPort( prt_port );
  1138.       }
  1139.       else
  1140.         print( "Unable to open printer port!" );
  1141.     }
  1142.   }
  1143.  
  1144.   memcpy( &aop, &aop_save, sizeof( ami_options ) ); /* Options restaurieren */
  1145.   memcpy( &op, &op_save, sizeof( options ) );
  1146.  
  1147.   /* Dieser Teil entfΣllt bei SuperBitmap Window, shipout = NULL nach oben */
  1148.   if( shipout )
  1149.   {
  1150.     shipout = NULL;
  1151.     if( old_valid /* && !setjmp( halt_jump ) */ )
  1152.     {
  1153.       dvi_clean();
  1154.       frame_alloc = chip_frame_alloc;
  1155.       frame_free = chip_frame_free;
  1156.       format_pages( act_page, act_page, 1 );
  1157.     }
  1158.   }
  1159.   ClearBusyPointer( win );
  1160.   ClearBusyPointer( sbm_win );
  1161. }
  1162.  
  1163. void print_range( void )
  1164. {
  1165.   static int first = 1, last = 1, step = 1;
  1166.  
  1167.   if( request_range( &first, &last, &step ) )
  1168.     print_pages( first, last, step );
  1169. }
  1170.  
  1171. void prbyte( int c )
  1172. {
  1173.   if( red_fp == NULL || !aop.redirect )
  1174.   {
  1175.     if( count < BUFSIZE )
  1176.       buffer[count++] = c;
  1177.     else
  1178.     {
  1179.       prt_req->io_Command = PRD_RAWWRITE;
  1180.       prt_req->io_Data = buffer;
  1181.       prt_req->io_Length = BUFSIZE;
  1182.  
  1183.       DoIO( (struct IORequest*)prt_req );
  1184.  
  1185.       if( prt_req->io_Error == PDERR_CANCEL )
  1186.         halt( "printing aborted!" );
  1187.  
  1188.       count = 0;
  1189.       buffer[count++] = c;
  1190.     }
  1191.   }
  1192.   else
  1193.   {
  1194.     if( fputc( c, red_fp ) == EOF )
  1195.       halt( "writing to redirection file %s aborted!", op.redirect );
  1196.   }
  1197. }
  1198.  
  1199. void printer_setup( void )
  1200. {
  1201.   int end = FALSE, ok = FALSE;
  1202.   struct IntuiMessage *imsg;
  1203.   struct Gadget *gad;
  1204.   struct StringInfo *str_info;
  1205.   options op_save;
  1206.   ami_options aop_save;
  1207.   
  1208.   memcpy( &op_save, &op, sizeof( options ) ); /* Options zwischenspeichern */
  1209.   memcpy( &aop_save, &aop, sizeof( ami_options ) );
  1210.  
  1211.   if( OpenPrinter_SetupWindow() == 0 )
  1212.   {
  1213.     GT_SetGadgetAttrs( Printer_SetupGadgets[GD_printer], Printer_SetupWnd, NULL,
  1214.       GTMX_Active, (ULONG)( op.shipno + 1 ), TAG_DONE );
  1215.     GT_SetGadgetAttrs( Printer_SetupGadgets[GD_redirect], Printer_SetupWnd, NULL,
  1216.       GTMX_Active, (ULONG)( aop.redirect ), TAG_DONE );
  1217.     GT_SetGadgetAttrs( Printer_SetupGadgets[GD_redir_file], Printer_SetupWnd, NULL,
  1218.       GTST_String, (ULONG)( aop.redir_name ), GA_Disabled, !aop.redirect, TAG_DONE );
  1219.     GT_SetGadgetAttrs( Printer_SetupGadgets[GD_copies], Printer_SetupWnd, NULL,
  1220.       GTIN_Number, (ULONG)( op.copies ), TAG_DONE );
  1221.     GT_SetGadgetAttrs( Printer_SetupGadgets[GD_mag], Printer_SetupWnd, NULL,
  1222.       GTIN_Number, (ULONG)( aop.prt_mag ), TAG_DONE );
  1223.  
  1224.     ActivateGadget( Printer_SetupGadgets[GD_copies], Printer_SetupWnd, NULL );
  1225.  
  1226.     while( !end )
  1227.     {
  1228.       WaitPort( Printer_SetupWnd->UserPort );
  1229.       while( imsg = GT_GetIMsg( Printer_SetupWnd->UserPort ) )
  1230.       {
  1231.         gad = imsg->IAddress;
  1232.  
  1233.         switch( imsg->Class )
  1234.         {
  1235.           case CLOSEWINDOW:
  1236.             end = TRUE;
  1237.             ok = FALSE;
  1238.             break;
  1239.           case GADGETDOWN:
  1240.             switch( gad->GadgetID )
  1241.             {
  1242.               case GD_printer:
  1243.                 op.shipno = imsg->Code - 1;
  1244.                 break;
  1245.               case GD_redirect:
  1246.                 aop.redirect = imsg->Code;
  1247.                 GT_SetGadgetAttrs( Printer_SetupGadgets[GD_redir_file],
  1248.                   Printer_SetupWnd, NULL, GA_Disabled, !aop.redirect, TAG_DONE );
  1249.                 break;
  1250.               default:
  1251.                 break;
  1252.             }
  1253.             break;
  1254.           case GADGETUP:
  1255.             switch( gad->GadgetID )
  1256.             {
  1257.               case GD_psetup_ok:
  1258.                 end = TRUE;
  1259.                 ok = TRUE;
  1260.                 break;
  1261.               case GD_psetup_cancel:
  1262.                 end = TRUE;
  1263.                 ok = FALSE;
  1264.                 break;
  1265.               default:
  1266.                 break;
  1267.             }
  1268.             break;
  1269.           default:
  1270.             break;
  1271.         }
  1272.         GT_ReplyIMsg( imsg );
  1273.       }
  1274.     }
  1275.  
  1276.     str_info = Printer_SetupGadgets[GD_redir_file]->SpecialInfo;
  1277.     strcpy( aop.redir_name, (char *)str_info->Buffer );
  1278.  
  1279.     str_info = Printer_SetupGadgets[GD_copies]->SpecialInfo;
  1280.     op.copies = str_info->LongInt;
  1281.  
  1282.     str_info = Printer_SetupGadgets[GD_mag]->SpecialInfo;
  1283.     op.new_mag = str_info->LongInt;
  1284.  
  1285.     ClosePrinter_SetupWindow();
  1286.   }
  1287.  
  1288.   if( !ok )
  1289.   {
  1290.     memcpy( &aop, &aop_save, sizeof( ami_options ) ); /* Options restaurieren */
  1291.     memcpy( &op, &op_save, sizeof( options ) );
  1292.   }
  1293. }
  1294.  
  1295. int process_idcmp_messages( struct MsgPort *msgport, int *newpage, int *update )
  1296. {
  1297.   static int dx = 0, dy = 0;
  1298.   int gopage = 1, newmag = 0;
  1299.   struct IntuiMessage *imsg, cpy_msg;
  1300.   static ULONG micros = 0, seconds = 0;
  1301.  
  1302.   if( msgport != NULL )
  1303.     while( imsg = GT_GetIMsg( msgport ) )
  1304.     {
  1305.       cpy_msg = *imsg;
  1306.       GT_ReplyIMsg( imsg );
  1307.  
  1308.       switch( cpy_msg.Class )
  1309.       {
  1310.         case IDCMP_CLOSEWINDOW:
  1311.           return( TRUE );
  1312.           break;
  1313.         case IDCMP_VANILLAKEY:
  1314.           switch( cpy_msg.Code )
  1315.           {
  1316.             case '\x0D':
  1317.             case '+':
  1318.               *newpage = goto_page( act_page + 1 );
  1319.               break;
  1320.             case '\x08':
  1321.             case '-':
  1322.               *newpage = goto_page( act_page - 1 );
  1323.               break;
  1324.             default:
  1325. /*
  1326.               print( "VANILLAKEY: %d", cpy_msg.Code );
  1327. */
  1328.               break;
  1329.           }
  1330.           break;
  1331.         case IDCMP_RAWKEY:
  1332.           switch( cpy_msg.Code )
  1333.           {
  1334.             case CRSR_UP:
  1335.               dx = 0;
  1336.               if( sbm_win->RPort->Layer->Scroll_Y - PIX_UPDOWN >=  0 )
  1337.                 dy = -PIX_UPDOWN;
  1338.               else
  1339.                 dy = -sbm_win->RPort->Layer->Scroll_Y;
  1340.               break;
  1341.             case CRSR_DOWN:
  1342.               dx = 0;
  1343.               if( sbm_win->RPort->Layer->Scroll_Y + PIX_UPDOWN +
  1344.                   sbm_win->GZZHeight <= bmp_height )
  1345.                 dy = PIX_UPDOWN;
  1346.               else
  1347.                 dy = MAX( 0,
  1348.                   bmp_height - sbm_win->GZZHeight - sbm_win->RPort->Layer->Scroll_Y );
  1349.               break;
  1350.             case CRSR_RIGHT:
  1351.               dy = 0;
  1352.               if( sbm_win->RPort->Layer->Scroll_X + PIX_LEFTRIGHT +
  1353.                   sbm_win->GZZWidth <= bmp_width )
  1354.                 dx = PIX_LEFTRIGHT;
  1355.               else
  1356.                 dx = MAX( 0,
  1357.                   bmp_width - sbm_win->GZZWidth - sbm_win->RPort->Layer->Scroll_X );
  1358.               break;
  1359.             case CRSR_LEFT:
  1360.               dy = 0;
  1361.               if( sbm_win->RPort->Layer->Scroll_X - PIX_LEFTRIGHT >= 0 )
  1362.                 dx = -PIX_LEFTRIGHT;
  1363.               else
  1364.                 dx = -sbm_win->RPort->Layer->Scroll_X;
  1365.               break;
  1366.             default:
  1367.               dx = dy = 0;
  1368. /*
  1369.                 print( "RAWKEY: %d", cpy_msg.Code );
  1370. */
  1371.               break;
  1372.           }
  1373.           if( dx || dy )
  1374.           {
  1375.             ScrollLayer( 0, sbm_win->RPort->Layer, dx, dy );
  1376.             dx = dy = 0;
  1377.           }
  1378.           break;
  1379.         case IDCMP_MOUSEBUTTONS:
  1380.           switch( cpy_msg.Code )
  1381.           {
  1382.             case SELECTDOWN:
  1383.               if( DoubleClick( seconds, micros, cpy_msg.Seconds, cpy_msg.Micros ) )
  1384.                 *newpage = goto_page( act_page + 1 );
  1385.               seconds = cpy_msg.Seconds;
  1386.               micros = cpy_msg.Micros;
  1387.               ModifyIDCMP( sbm_win, sbm_win->IDCMPFlags | IDCMP_DELTAMOVE |
  1388.                 IDCMP_MOUSEMOVE );
  1389.               break;
  1390.             case SELECTUP:
  1391.               ModifyIDCMP( sbm_win, sbm_win->IDCMPFlags &
  1392.                 ~( IDCMP_DELTAMOVE ^ IDCMP_MOUSEMOVE ) );
  1393.               break;
  1394.             default:
  1395.               break;
  1396.           }
  1397.           break;
  1398.         case IDCMP_MOUSEMOVE:
  1399.           dx += cpy_msg.MouseX;
  1400.           dy += cpy_msg.MouseY;
  1401.           if( ABS( dx ) > PIX_LEFTRIGHT )
  1402.           {
  1403.             if( dx < 0 && sbm_win->RPort->Layer->Scroll_X - dx +
  1404.                 sbm_win->GZZWidth > bmp_width )
  1405.             {
  1406.               dx = -MAX( 0,
  1407.                 bmp_width - sbm_win->GZZWidth - sbm_win->RPort->Layer->Scroll_X );
  1408.             }
  1409.             else if( dx > 0 && sbm_win->RPort->Layer->Scroll_X - dx < 0 )
  1410.             {
  1411.               dx = sbm_win->RPort->Layer->Scroll_X;
  1412.             }
  1413.             if( dx )
  1414.             {
  1415.               ScrollLayer( 0, sbm_win->RPort->Layer, -dx, 0 );
  1416.               dx = 0;
  1417.             }
  1418.           }
  1419.           if( ABS( dy ) > PIX_UPDOWN )
  1420.           {
  1421.             if( dy < 0 && sbm_win->RPort->Layer->Scroll_Y - dy +
  1422.                 sbm_win->GZZHeight > bmp_height )
  1423.             {
  1424.               dy = -MAX( 0,
  1425.                 bmp_height - sbm_win->GZZHeight - sbm_win->RPort->Layer->Scroll_Y );
  1426.             }
  1427.             else if( dy > 0 && sbm_win->RPort->Layer->Scroll_Y - dy < 0 )
  1428.             {
  1429.               dy = sbm_win->RPort->Layer->Scroll_Y;
  1430.             }
  1431.             if( dy )
  1432.             {
  1433.               ScrollLayer( 0, sbm_win->RPort->Layer, 0, -dy );
  1434.               dy = 0;
  1435.             }
  1436.           }
  1437.           break;
  1438.         case IDCMP_MENUPICK:
  1439.           switch( MENUNUM( cpy_msg.Code ) )
  1440.           {
  1441.             case 0: /* Project Menu */
  1442.               switch( ITEMNUM( cpy_msg.Code ) )
  1443.               {
  1444.                 case 0: /* Load DVI */
  1445.                   *newpage = dvi_filereq();
  1446.                   return( FALSE );
  1447.                   break;
  1448.                 case 1: /* update DVI */
  1449.                   if( frame_valid )
  1450.                   {
  1451.                     *newpage = TRUE;
  1452.                     dvi_clean();
  1453.                     return( FALSE );
  1454.                   }
  1455.                   break;
  1456.                 case 2: /* Save Options */
  1457.                   write_opts();
  1458.                   break;
  1459.                 case 4: /* About */
  1460.                   about_dvi();
  1461.                   break;
  1462.                 case 6: /* Quit */
  1463.                   return( TRUE );
  1464.                   break;
  1465.                 default:
  1466.                   break;
  1467.               }
  1468.               break;
  1469.             case 1: /* Screen Menu */
  1470.               switch( ITEMNUM( cpy_msg.Code ) )
  1471.               {
  1472.                 case 0: /* Next Page */
  1473.                   *newpage = goto_page( act_page + 1 );
  1474.                   break;
  1475.                 case 1: /* Previous Page */
  1476.                   *newpage = goto_page( act_page - 1 );
  1477.                   break;
  1478.                 case 2: /* Goto Page */
  1479.                   if( request_integer( &gopage, "Goto Page" ) )
  1480.                     *newpage = goto_page( gopage );
  1481.                   break;
  1482.                 case 4: /* Magnification */
  1483.                   if( request_integer( &newmag, "Magnification" ) )
  1484.                   {
  1485.                     if( op.new_mag != newmag )
  1486.                     {
  1487.                       op.new_mag = newmag;
  1488.                       dvi_clean();
  1489.                       *newpage = TRUE;
  1490.                       return( FALSE );
  1491.                     }
  1492.                   }
  1493.                   break;
  1494.                 default:
  1495.                   break;
  1496.               }
  1497.               break;
  1498.             case 2: /* Printer Menu */
  1499.               switch( ITEMNUM( cpy_msg.Code ) )
  1500.               {
  1501.                 case 0: /* Print Range */
  1502.                   print_range();
  1503.                   break;
  1504.                 case 1: /* Print Page */
  1505.                   print_pages( act_page, act_page, 1 );
  1506.                   break;
  1507.                 case 2: /* Print Document */
  1508.                   print_pages( 1, dvi_info.pages, 1 );
  1509.                   break;
  1510.                 default:
  1511.                   break;
  1512.               }
  1513.               *update = TRUE;
  1514.               return( FALSE );
  1515.             case 3: /* Setup Menu */
  1516.               switch( ITEMNUM( cpy_msg.Code ) )
  1517.               {
  1518.                 case 0: /* Directories */
  1519.                   dir_setup();
  1520.                   break;
  1521.                 case 1: /* Margins */
  1522.                   margins_setup();
  1523.                   break;
  1524.                 case 2: /* Options */
  1525.                   switch( SUBNUM( cpy_msg.Code ) )
  1526.                   {
  1527.                     case 0: /* Eject */
  1528.                       op.formfeed = !op.formfeed;
  1529.                       break;
  1530.                     case 1: /* Landscape */
  1531.                       op.landscape = !op.landscape;
  1532.                       if( frame_valid )
  1533.                       {
  1534.                         *newpage = TRUE;
  1535.                         dvi_clean();
  1536.                         return( FALSE );
  1537.                       }
  1538.                       break;
  1539.                     case 2: /* Memory */
  1540.                       op.dvimemory = !op.dvimemory;
  1541.                       if( frame_valid )
  1542.                       {
  1543.                         *newpage = TRUE;
  1544.                         dvi_clean();
  1545.                         return( FALSE );
  1546.                       }
  1547.                       break;
  1548.                     case 3: /* Pictures */
  1549.                       op.show_img = !op.show_img;
  1550.                       break;
  1551.                     case 4: /* Separate */
  1552.                       op.separate = !op.separate;
  1553.                       if( op.separate )
  1554.                         op.thin_out = FALSE;
  1555.                       break;
  1556.                     case 5: /* Showfonts */
  1557.                       op.showfonts = !op.showfonts;
  1558.                       break;
  1559.                     case 6: /* Singlesheet */
  1560.                       op.singlesheet = !op.singlesheet;
  1561.                       break;
  1562.                     case 7: /* Thinout */
  1563.                       op.thin_out = !op.thin_out;
  1564.                       if( op.thin_out )
  1565.                         op.separate = FALSE;
  1566.                       break;
  1567.                     case 8: /* Tracechars */
  1568.                       op.tracechars = !op.tracechars;
  1569.                       if( frame_valid )
  1570.                       {
  1571.                         *newpage = TRUE;
  1572.                         dvi_clean();
  1573.                         return( FALSE );
  1574.                       }
  1575.                       break;
  1576.                     case 9: /* Tracemem */
  1577.                       op.tracemem = !op.tracemem;
  1578.                       if( frame_valid )
  1579.                       {
  1580.                         *newpage = TRUE;
  1581.                         dvi_clean();
  1582.                         return( FALSE );
  1583.                       }
  1584.                       break;
  1585.                     default:
  1586.                       break;
  1587.                   }
  1588.                   break;
  1589.                 case 3: /* Printer */
  1590.                   printer_setup();
  1591.                   break;
  1592.                 default:
  1593.                   break;
  1594.               }
  1595.             default:
  1596.               break;
  1597.           }
  1598.           break;
  1599.         default:
  1600.           break;
  1601.       }
  1602.     }
  1603.   return( FALSE );
  1604. }
  1605.  
  1606. int process_wb_messages( struct MsgPort *app_menu_port )
  1607. {
  1608.   struct AppMessage *app_message;
  1609.   BPTR dir_lock, file_lock;
  1610.   int newpage = FALSE;
  1611.  
  1612.   while( app_message = (struct AppMessage *)GetMsg( app_menu_port ) )
  1613.   {
  1614.     if( ( app_message->am_Type == 9 ) && ( app_message->am_ID == 1 ) &&
  1615.         ( app_message->am_NumArgs > 0 ) )
  1616.     {
  1617.       if( dir_lock = DupLock( app_message->am_ArgList->wa_Lock ) )
  1618.       {
  1619.         dir_lock = CurrentDir( dir_lock );
  1620.         if( file_lock = Lock( app_message->am_ArgList->wa_Name, ACCESS_READ ) )
  1621.         {
  1622.           UnLock( file_lock );
  1623.  
  1624.           strcpy( dvi_name, app_message->am_ArgList->wa_Name );
  1625.           ScreenToFront( scr );
  1626.           newpage = TRUE;
  1627.  
  1628.           dvi_clean();
  1629.           act_page = 1;
  1630.         }
  1631.         else
  1632.           dir_lock = CurrentDir( dir_lock );
  1633.         UnLock( dir_lock );
  1634.       }
  1635.     }
  1636.     ReplyMsg( (struct Message *)app_message );
  1637.   }
  1638.   return( newpage );
  1639. }
  1640.  
  1641. int request_integer( int *value, char *txt )
  1642. {
  1643.   struct IntuiMessage *imsg;
  1644.   struct Gadget *gad;
  1645.   struct StringInfo *str_info;
  1646.   int end = FALSE, ok = FALSE;
  1647.  
  1648.   if( OpenRequest_IntegerWindow() == 0 )
  1649.   {
  1650.     GT_SetGadgetAttrs( Request_IntegerGadgets[GD_reqint_txt], Request_IntegerWnd, NULL,
  1651.       GTTX_Text, (ULONG)txt, TAG_DONE );
  1652.     GT_SetGadgetAttrs( Request_IntegerGadgets[GD_reqint_int], Request_IntegerWnd, NULL,
  1653.       GTIN_Number, (ULONG)*value, TAG_DONE );
  1654.  
  1655.     SetWindowTitles( Request_IntegerWnd, (UBYTE *)txt, (UBYTE *)~0 );
  1656.     ActivateGadget( Request_IntegerGadgets[GD_reqint_int], Request_IntegerWnd, NULL );
  1657.  
  1658.     while( !end )
  1659.     {
  1660.       WaitPort( Request_IntegerWnd->UserPort );
  1661.       while( imsg = GT_GetIMsg( Request_IntegerWnd->UserPort ) )
  1662.       {
  1663.         gad = imsg->IAddress;
  1664.  
  1665.         switch( imsg->Class )
  1666.         {
  1667.           case CLOSEWINDOW:
  1668.             end = TRUE;
  1669.             ok = FALSE;
  1670.             break;
  1671.           case GADGETUP:
  1672.             switch( gad->GadgetID )
  1673.             {
  1674.               case GD_reqint_int:
  1675.               case GD_reqint_ok:
  1676.                 end = TRUE;
  1677.                 ok = TRUE;
  1678.                 break;
  1679.               case GD_reqint_cancel:
  1680.                 end = TRUE;
  1681.                 ok = FALSE;
  1682.                 break;
  1683.               default:
  1684.                 break;
  1685.             }
  1686.             break;
  1687.           default:
  1688.             break;
  1689.         }
  1690.         GT_ReplyIMsg( imsg );
  1691.       }
  1692.     }
  1693.     str_info = Request_IntegerGadgets[GD_reqint_int]->SpecialInfo;
  1694.     *value = str_info->LongInt;
  1695.  
  1696.     CloseRequest_IntegerWindow();
  1697.   }
  1698.  
  1699.   return( ok );
  1700. }
  1701.  
  1702. int request_range( int *first, int *last, int *step )
  1703. {
  1704.   int end = FALSE, print = FALSE;
  1705.   struct IntuiMessage *imsg;
  1706.   struct Gadget *gad;
  1707.   struct StringInfo *str_info;
  1708.  
  1709.   if( OpenSelect_RangeWindow() == 0 )
  1710.   {
  1711.     GT_SetGadgetAttrs( Select_RangeGadgets[GD_from], Select_RangeWnd, NULL,
  1712.       GTIN_Number, (ULONG)*first, TAG_DONE );
  1713.     GT_SetGadgetAttrs( Select_RangeGadgets[GD_to], Select_RangeWnd, NULL,
  1714.       GTIN_Number, (ULONG)*last, TAG_DONE );
  1715.     GT_SetGadgetAttrs( Select_RangeGadgets[GD_step], Select_RangeWnd, NULL,
  1716.       GTIN_Number, (ULONG)*step, TAG_DONE );
  1717.  
  1718.     ActivateGadget( Select_RangeGadgets[GD_from], Select_RangeWnd, NULL );
  1719.  
  1720.     while( !end )
  1721.     {
  1722.       WaitPort( Select_RangeWnd->UserPort );
  1723.       while( imsg = GT_GetIMsg( Select_RangeWnd->UserPort ) )
  1724.       {
  1725.         gad = imsg->IAddress;
  1726.  
  1727.         switch( imsg->Class )
  1728.         {
  1729.           case CLOSEWINDOW:
  1730.             end = TRUE;
  1731.             print = FALSE;
  1732.             break;
  1733.           case GADGETUP:
  1734.             switch( gad->GadgetID )
  1735.             {
  1736.               case GD_range_ok:
  1737.                 end = TRUE;
  1738.                 print = TRUE;
  1739.                 break;
  1740.               case GD_range_cancel:
  1741.                 end = TRUE;
  1742.                 print = FALSE;
  1743.                 break;
  1744.               default:
  1745.                 break;
  1746.             }
  1747.             break;
  1748.           default:
  1749.             break;
  1750.         }
  1751.         GT_ReplyIMsg( imsg );
  1752.       }
  1753.     }
  1754.     str_info = Select_RangeGadgets[GD_from]->SpecialInfo;
  1755.     *first = str_info->LongInt;
  1756.  
  1757.     str_info = Select_RangeGadgets[GD_to]->SpecialInfo;
  1758.     *last = str_info->LongInt;
  1759.  
  1760.     str_info = Select_RangeGadgets[GD_step]->SpecialInfo;
  1761.     *step = str_info->LongInt;
  1762.  
  1763.     CloseSelect_RangeWindow();
  1764.   }
  1765.  
  1766.   return( print );
  1767. }
  1768.  
  1769. void SetBusyPointer( struct Window *window )
  1770. {
  1771.   if( window != NULL )
  1772.   {
  1773.     if( IntuitionBase->lib_Version >= 39 )
  1774.       SetWindowPointer( window, WA_BusyPointer, (ULONG)TRUE, TAG_DONE );
  1775.     else
  1776.       SetPointer( window, waitPointer, 16, 16, -6, 0 );
  1777.   }
  1778. }
  1779.  
  1780. int stop_key( void )
  1781. {
  1782.     return( 0 );
  1783. }
  1784.  
  1785. int wait_for_sheet( void )
  1786. {
  1787.   struct EasyStruct req =
  1788.   {
  1789.     sizeof( struct EasyStruct ),
  1790.     0,
  1791.     (UBYTE *)"Paper Request",
  1792.     (UBYTE *)"Insert new sheet",
  1793.     (UBYTE *)"OK|Cancel"
  1794.   };
  1795.  
  1796.   prt_req->io_Command = PRD_RAWWRITE;
  1797.   prt_req->io_Data = buffer;
  1798.   prt_req->io_Length = count;
  1799.  
  1800.   DoIO( (struct IORequest*)prt_req ); /* Druckerpuffer leeren */
  1801.   count = 0;
  1802.  
  1803.   return( !EasyRequest( win, &req, NULL ) );
  1804. }
  1805.  
  1806. void update_window( void )
  1807. {
  1808.   if( frame_valid )
  1809.   {
  1810.       LockLayerRom( sbm_win->RPort->Layer );
  1811.       CopySBitMap( sbm_win->RPort->Layer );
  1812.       UnlockLayerRom( sbm_win->RPort->Layer );
  1813.   }
  1814. }
  1815.  
  1816. void write_opts( void )
  1817. {
  1818.   char opt_line[128];
  1819.   FILE *opt_file;
  1820.  
  1821.   opt_file = fopen( opt_name, "w" );
  1822.   if( opt_file != NULL )
  1823.   {
  1824.     print( "Writing %s", opt_name );
  1825.  
  1826.     sprintf( opt_line, "%sCOPIES=%d\n",       op.copies );
  1827.     fputs( opt_line, opt_file );
  1828.     sprintf( opt_line, "DENSITY=%lf\n",       op.density );
  1829.     fputs( opt_line, opt_file );
  1830.     sprintf( opt_line, "EJECT=%s\n",          ON_OFF( op.formfeed ) );
  1831.     fputs( opt_line, opt_file );
  1832.     sprintf( opt_line, "HEIGHT=%lf in\n",     op.height );
  1833.     fputs( opt_line, opt_file );
  1834.     sprintf( opt_line, "HMARGIN=%lf in\n",    op.hmargin );
  1835.     fputs( opt_line, opt_file );
  1836.     sprintf( opt_line, "HOFFSET=%lf in\n",    op.hoffset );
  1837.     fputs( opt_line, opt_file );
  1838.     sprintf( opt_line, "HRESOLUTION=%ld\n",   op.hres );
  1839.     fputs( opt_line, opt_file );
  1840.     sprintf( opt_line, "HSPREAD=%lf in\n",    op.hspread );
  1841.     fputs( opt_line, opt_file );
  1842.     sprintf( opt_line, "IMGPATH=%s\n",        op.img_path );
  1843.     fputs( opt_line, opt_file );
  1844.     sprintf( opt_line, "LANDSCAPE=%s\n",      ON_OFF( op.landscape ) );
  1845.     fputs( opt_line, opt_file );
  1846.     sprintf( opt_line, "LOGFILE=%s\n",        op.log_name );
  1847.     fputs( opt_line, opt_file );
  1848.     sprintf( opt_line, "MAGNIFICATION=%ld\n", op.new_mag );
  1849.     fputs( opt_line, opt_file );
  1850.     sprintf( opt_line, "MEMORY=%s\n",         ON_OFF( op.dvimemory ) );
  1851.     fputs( opt_line, opt_file );
  1852.     sprintf( opt_line, "OUTPUT=%s\n",         p_defs[op.shipno].name );
  1853.     fputs( opt_line, opt_file );
  1854.     sprintf( opt_line, "PATH=%s\n",           op.dvi_path );
  1855.     fputs( opt_line, opt_file );
  1856.     sprintf( opt_line, "PATHMEM=%ld\n",       op.pathmem );
  1857.     fputs( opt_line, opt_file );
  1858.     sprintf( opt_line, "PICTURES=%s\n",       ON_OFF( op.show_img ) );
  1859.     fputs( opt_line, opt_file );
  1860.     sprintf( opt_line, "PIXMEM=%ld\n",        op.pixmem );
  1861.     fputs( opt_line, opt_file );
  1862.     sprintf( opt_line, "PKPATH=%s\n",         op.pk_path );
  1863.     fputs( opt_line, opt_file );
  1864.     sprintf( opt_line, "REDIRECT=%s\n",       op.redirect );
  1865.     fputs( opt_line, opt_file );
  1866.     sprintf( opt_line, "SEPARATE=%s\n",       ON_OFF( op.separate ) );
  1867.     fputs( opt_line, opt_file );
  1868.     sprintf( opt_line, "SHOWFONTS=%s\n",      ON_OFF( op.showfonts ) );
  1869.     fputs( opt_line, opt_file );
  1870.     sprintf( opt_line, "SINGLESHEET=%s\n",    ON_OFF( op.singlesheet ) );
  1871.     fputs( opt_line, opt_file );
  1872.     sprintf( opt_line, "TFMPATH=%s\n",        op.tfm_path );
  1873.     fputs( opt_line, opt_file );
  1874.     sprintf( opt_line, "THINOUT=%s\n",        ON_OFF( op.thin_out ) );
  1875.     fputs( opt_line, opt_file );
  1876.     sprintf( opt_line, "TRACECHARS=%s\n",     ON_OFF( op.tracechars ) );
  1877.     fputs( opt_line, opt_file );
  1878.     sprintf( opt_line, "TRACEMEM=%s\n",       ON_OFF( op.tracemem ) );
  1879.     fputs( opt_line, opt_file );
  1880.     sprintf( opt_line, "VFPATH=%s\n",         op.vf_path );
  1881.     fputs( opt_line, opt_file );
  1882.     sprintf( opt_line, "VMARGIN=%lf in\n",    op.vmargin );
  1883.     fputs( opt_line, opt_file );
  1884.     sprintf( opt_line, "VOFFSET=%lf in\n",    op.voffset );
  1885.     fputs( opt_line, opt_file );
  1886.     sprintf( opt_line, "VRESOLUTION=%ld\n",   op.vres );
  1887.     fputs( opt_line, opt_file );
  1888.     sprintf( opt_line, "VSPREAD=%lf in\n",    op.vspread );
  1889.     fputs( opt_line, opt_file );
  1890.     sprintf( opt_line, "WIDTH=%lf in\n",      op.width );
  1891.     fputs( opt_line, opt_file );
  1892.     sprintf( opt_line, "CALLMF=%s\n",         op.pk_callmf );
  1893.     fputs( opt_line, opt_file );
  1894.  
  1895.     fclose( opt_file );
  1896.   }
  1897. }
  1898.  
  1899. int main( int argc, char *argv[] )
  1900. {
  1901.   BPTR old_dir = NULL, lock = NULL;
  1902.   struct Process *process = NULL;
  1903.   FILE *opt_file;
  1904.   char option[128], *opt[2], *opt_dir, ch;
  1905.   int i, wbstarted = FALSE;
  1906.   struct DiskObject *dobj;
  1907.  
  1908.   shipout = NULL; /* shipout Hahn von dvi abdrehen */
  1909.   opt[0] = option; opt[1] = NULL;
  1910.   process = (struct Process *)FindTask( NULL ); /* eigenen Prozess ermitteln */
  1911.  
  1912.   sprintf( scr_title, "This is DVI Version %s" , DVI_VER );
  1913.  
  1914.   frame_alloc = chip_frame_alloc;
  1915.   frame_free = chip_frame_free;
  1916.  
  1917.   if( argc == 0 ) /* Start von der Workbench? */
  1918.   {
  1919.     argc = _WBArgc; /* argc und argv entsprechend der */
  1920.     argv = _WBArgv; /* Workbench Argumente setzen */
  1921.     wbstarted = TRUE;
  1922.   }
  1923.  
  1924.   for( i = 1; i < argc; i++ )
  1925.   {
  1926.     if( strchr( argv[i], '=' ) == NULL )
  1927.       strcpy( dvi_name, argv[i] );
  1928.   }
  1929.  
  1930.   /*
  1931.    * Optionen verarbeiten:
  1932.    * 1. Optionsdatei
  1933.    * 2. Kommandozeilenoptionen / Tooltypes
  1934.    * 3. Tooltypes des Arguments auswerten ( bei WB Start )
  1935.    */
  1936.   opt_dir = getenv( "TEXCONFIG" );
  1937.   strcpy( opt_name, ( opt_dir != NULL ) ? opt_dir : "TeX:config" );
  1938.   AddPart( opt_name, "dvi.opt", MAX_PATH_LEN - 1 );
  1939.  
  1940.   /* Zuerst die Optionen aus der Optionsdatei einlesen */
  1941.   if( ( opt_file = fopen( opt_name, "r" ) ) != NULL )
  1942.   {
  1943.     while( fgets( option, 127, opt_file ) != NULL )
  1944.       get_opts( opt );
  1945.     fclose( opt_file );
  1946.   }
  1947.   /* Jetzt die in der Kommandozeile / in den Tooltypes angegebenen Optionen */
  1948.   get_opts( argv );
  1949.   /* Jetzt eventuell noch Tooltype Optionen des WB Arguments */
  1950.   if( wbstarted && ( dvi_name[0] != '\0' ) )
  1951.   {
  1952.     if( ( dobj = GetDiskObject( dvi_name ) ) != NULL )
  1953.     {
  1954.       get_opts( dobj->do_ToolTypes );
  1955.       FreeDiskObject( dobj );
  1956.     }
  1957.   }
  1958.  
  1959.   if( wbstarted )
  1960.   {
  1961.     if( dvi_name[0] != '\0' )
  1962.     {
  1963.       opt[0] = PathPart( dvi_name );
  1964.       ch = *opt[0];
  1965.       *opt[0] = '\0';
  1966.       lock = Lock( dvi_name, ACCESS_READ );
  1967.       *opt[0] = ch;
  1968.     }
  1969.     else
  1970.       lock = DupLock( process->pr_CurrentDir );
  1971.   }
  1972.   else
  1973.     lock = DupLock( process->pr_CurrentDir );
  1974.  
  1975.   if( BADDR( lock ) == NULL )
  1976.   {
  1977.     print( "Unable to create directory lock!" );
  1978.     return( RETURN_ERROR );
  1979.   }
  1980.  
  1981.   old_dir = CurrentDir( lock ); /* In das entsprechende Verzeichnis wechseln */
  1982.  
  1983.   if( gr_install() )
  1984.   {
  1985.     if( open_all() )
  1986.     {
  1987.       process->pr_WindowPtr = win; /* aktuelles Window fuer Systemrequester */
  1988.       main_loop();
  1989.       dvi_clean();
  1990.     }
  1991.     close_all();
  1992.   }
  1993.  
  1994.   gr_destall();
  1995.   mem_test();
  1996.  
  1997.   UnLock( CurrentDir( old_dir ) );
  1998.  
  1999.   return( 0 );
  2000. }
  2001.