home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / driver / util / globals.c < prev    next >
C/C++ Source or Header  |  1994-08-03  |  22KB  |  972 lines

  1. /*
  2. **    This file generated by localize 2.9 (AmigaDOS 2.1) from util/globals.c
  3. */
  4. /*****************************************************************************/
  5. /*    globals.c                                     */
  6. /*****************************************************************************/
  7.  
  8.  
  9. #include "defines.h"
  10.  
  11. #include <stdio.h>
  12. #include <time.h>
  13. #include <ctype.h>
  14.  
  15. #include "globals.h"
  16. #include "flmt.h"
  17. #include "new_font.h"
  18.  
  19. #ifdef ANSI
  20. #  include <string.h>
  21. #  include <stdlib.h>
  22. #  include <stdarg.h>
  23. #endif
  24.  
  25.  
  26. #ifdef AZTEC_C
  27. #  include <functions.h>
  28. #endif
  29.  
  30. #ifdef DEBUG
  31. # ifdef ATARI
  32. #  ifdef DISPLAY
  33. #   include "bitmap.i"
  34. #  endif
  35. #  include <tos.h>
  36. # endif
  37. #endif
  38.  
  39. #include "ver_code.h"        /* codierte Strings */
  40. #include "crypt.h"        /* Codierfunktionen */
  41.  
  42. #include "globals.i"
  43. #include "new_font.i"
  44. #include "dvihand.i"
  45.  
  46. extern int background;        /* def. in amscreen.c / amprint.c */
  47. extern struct ExecBase        *SysBase;
  48.  
  49. #include <exec/exec.h>
  50. #include <libraries/locale.h>
  51. #include <clib/exec_protos.h>
  52. #include <pragmas/exec_pragmas.h>
  53.  
  54. #ifdef DISPLAY
  55. #  include "amscreen.i"
  56. #  include "am_requ.i"
  57. #else
  58. #  include "muiprint.i"
  59. #  ifndef FLIB
  60. #    include <exec/types.h>
  61. #    include <devices/printer.h>    /* wg. amprint.h */
  62. #    include <exec/exec.h>
  63. #    include "amprint.h"
  64. #    include "amprhelp.i"
  65. #    include "dviprint.i"
  66. #  endif
  67. #endif
  68. #include <clib/alib_protos.h>
  69. #include <clib/dos_protos.h>
  70. #include <pragmas/dos_pragmas.h>
  71. #include <pragmas/exec_pragmas.h>
  72.  
  73.  
  74.  
  75. #define MAXLINE        150    /* size of maxline buffer    */
  76.  
  77.  
  78.  
  79. /*
  80.  * Fuer die locale-Library:
  81.  *
  82.  * Hier duerfen *nur* die MSG_#? Nummern eingebunden werden!
  83.  * Achtung:
  84.  * Es muss/sollte 'multiple-include' erlaubt sein!
  85.  */
  86. #include "local.i"
  87.  
  88. #undef  CATCOMP_ARRAY
  89. #undef  CATCOMP_BLOCK
  90. #undef  CATCOMP_STRINGS
  91. #define CATCOMP_NUMBERS
  92. #include "localstr.h"
  93.  
  94.  
  95.  
  96.  
  97.  
  98. /* lokale Funktionen */
  99. static void TimeString        Args((char *s));
  100. static int  DoOut        Args((char *buf, char *fmt, va_list args, int log, int message));
  101. static void DoMessage        Args((char *ptr));
  102. static void DoLogging        Args((char *ptr));
  103.  
  104.  
  105.  
  106. #ifdef AMIGA
  107.   extern int Enable_Abort;
  108. #endif /* AMIGA */
  109.  
  110. extern long g_authors;    /* print author names? Defined in the main-progs */
  111.  
  112. static char *mo_arr[12] = {"January","February","March","April","May","June",
  113.             "July","August","September",
  114.             "October","November","December"};
  115.  
  116. static char maxline[MAXLINE];    /* für Message() Warning() Logging() Fatal() */
  117. static int user_aborted;    /* Wurde wegen ^C abgebrochen ? */
  118.  
  119.  
  120. #ifdef ATARI
  121. void beep(void)
  122. {
  123.   return;
  124. }
  125. #endif
  126.  
  127.  
  128.  
  129.  
  130. /*
  131.  ************************************************************************
  132.  *    alloc mem, if no mem available release chars            *
  133.  ************************************************************************
  134.  */
  135.  
  136. #undef MALLOC_DEBUG        // checke jedes malloc/free
  137.  
  138.  
  139. #if defined(MALLOC_DEBUG)
  140.   FILE * MallocDebFile = NULL;
  141.   struct MemDebList {
  142.     struct MemDebList * Next;
  143.     void * Pointer;
  144.   };
  145.   struct MemDebList * MDLst = NULL;
  146. #endif    // MALLOC_DEBUG
  147.  
  148.  
  149. void * xmalloc(unsigned bytes)
  150. {
  151.   void * ret;
  152.   int bytes_to_alloc;
  153.  
  154. #if defined(MALLOC_DEBUG)
  155.   bytes_to_alloc = bytes + 4 + 2 * 16;
  156. #else
  157.   bytes_to_alloc = bytes;
  158. #endif    // MALLOC_DEBUG
  159.   
  160.   ret = malloc(bytes_to_alloc);
  161.   if (ret == NULL) {
  162.     release_mem();
  163.     ret = malloc(bytes_to_alloc);
  164.     if (ret == NULL) {
  165.       Fatal(10,MSG_NOT_ENOUGH_MEM_BYTES, bytes);        /* no memory */
  166.     }
  167.   }
  168.   
  169.   if (ret != NULL) {
  170.     (void)memset(ret, 0, bytes_to_alloc);            /* clear the mem */
  171.   }
  172.   
  173. #if defined(MALLOC_DEBUG)
  174.   {
  175.     long * tmp = (long *)ret;
  176.     tmp[0] = bytes_to_alloc;
  177.     tmp[1] = 0xA1B2C3D4;
  178.     tmp[2] = 0xA1B2C3D4;
  179.     tmp[3] = 0xA1B2C3D4;
  180.     tmp[4] = 0xA1B2C3D4;
  181.     
  182.     tmp = (long *)(((char *)ret + 4 + 16) + bytes);
  183.     tmp[0] = 0xA1B2C3D4;
  184.     tmp[1] = 0xA1B2C3D4;
  185.     tmp[2] = 0xA1B2C3D4;
  186.     tmp[3] = 0xA1B2C3D4;
  187.   }
  188.   
  189.   {
  190.     struct MemDebList * new;
  191.     new = malloc(sizeof(struct MemDebList));
  192.     if (new) {
  193.       new->Next = MDLst;
  194.       new->Pointer = ret;
  195.       MDLst = new;
  196.     }
  197.   }
  198.  
  199.   if (MallocDebFile == NULL) {
  200. #if defined(DISPLAY)
  201.     MallocDebFile = fopen("ram:ShowDVI.MDeb", "w");
  202. #else
  203.     MallocDebFile = fopen("ram:DVIprint.MDeb", "w");
  204. #endif
  205.   }
  206.   if (MallocDebFile != NULL) {
  207.     fprintf(MallocDebFile, "malloc %6ld bytes (%6ld) at 0x%x (0x%x)\n", 
  208.         bytes, bytes_to_alloc, (void *)((char *)ret + 4 + 16), ret);
  209.   }
  210.  
  211.   return (void *)((char *)ret + 4 + 16);
  212. #else
  213.   return ret;
  214. #endif    // MALLOC_DEBUG
  215. }
  216.  
  217.  
  218.  
  219. /*
  220.  ************************************************************************
  221.  *    free mem                            *
  222.  ************************************************************************
  223.  */
  224.  
  225. #if defined(MALLOC_DEBUG)
  226.  
  227. /*
  228.  * Wenn kein MALLOC_DEBUG definiert ist, dann wird in globals.h xfree
  229.  * als Macro definiert.
  230.  */
  231.  
  232. void xfree(void * poi)
  233. {
  234.   int i;
  235.   long * tmp = (long *)poi - 5;        // size + 4 check
  236.   struct MemDebList * s, *prev;
  237.  
  238.   if (MallocDebFile != NULL) {
  239.     long * ttt = (long *)((char *)tmp + tmp[0]-16);
  240.  
  241.     s = MDLst;
  242.     prev = NULL;
  243.     while (s && s->Pointer != tmp) {
  244.       prev = s;
  245.       s = s->Next;
  246.     }
  247.     if (!s) {
  248.       fprintf(MallocDebFile, "** error: Don't find entry in mem-list for 0x%x\n", tmp);
  249.     }
  250.     else {
  251.       if (prev) {
  252.         prev->Next = s->Next;
  253.       }
  254.       else {
  255.         MDLst = s->Next;
  256.       }
  257.  
  258.       fprintf(MallocDebFile, "free   %6ld bytes (%6ld) at 0x%x (0x%x)\n", 
  259.         tmp[0]-4-2*16, tmp[0], poi, (char *)poi-4-16);
  260.       for (i = 1; i<5; i++) {
  261.         if (tmp[i] != 0xA1B2C3D4) {
  262.           fprintf(MallocDebFile, "** error: Overwrite prev long #%ld with 0x%x\n", i, tmp[i]);
  263.           fflush(MallocDebFile);
  264.           fprintf(stderr, "** error: Overwrite prev long #%ld with 0x%x\n", i, tmp[i]);
  265.         }
  266.       }
  267.       for (i = 0; i<4; i++) {
  268.         if (ttt[i] != 0xA1B2C3D4) {
  269.           fprintf(MallocDebFile, "** error: Overwrite last long #%ld with 0x%x\n", i+1, ttt[i]);
  270.           fflush(MallocDebFile);
  271.           fprintf(stderr, "** error: Overwrite last long #%ld with 0x%x\n", i+1, ttt[i]);
  272.         }
  273.       }
  274.     }
  275.   }
  276.  
  277.  (void)memset(tmp, 37, tmp[0]);            /* clear the freed mem */
  278.   
  279.   free(tmp);
  280. }
  281.  
  282. void xfree_all()
  283. {
  284.   while (MDLst) {
  285.     xfree((char *)MDLst->Pointer + 4 + 16);
  286.   }
  287. }
  288. #endif
  289.  
  290.  
  291. /*-->TimeString*/
  292. /**********************************************************************/
  293. /*************************  TimeString  *******************************/
  294. /**********************************************************************/
  295. static void TimeString(char *s)
  296. {
  297.   time_t clock = 0L;
  298.   struct tm *tmptr;
  299.  
  300.   clock = time((long *)0L);
  301.   tmptr = localtime(&clock);
  302.  
  303.   if (tmptr == NULL) {
  304.     s[0] = '\0';
  305.   }
  306.   else {
  307.     sprintf(s,"\t%2d:%02d, %2d %s %4d", tmptr->tm_hour, tmptr->tm_min,
  308.         tmptr->tm_mday, 
  309.         GetLocString(tmptr->tm_mon+MON_1, mo_arr[tmptr->tm_mon]), 
  310.         tmptr->tm_year+1900);
  311.   }
  312. }
  313.  
  314.  
  315. /* print additional copyright text */
  316. #if defined(BETACOPYRIGHT)
  317. void PrintBetaCopy(void)
  318. {
  319.   ENCODE2(COPYRIGHT, m_string);
  320.   WarningStr(m_string);
  321. }
  322. #endif
  323.  
  324.  
  325.  
  326. /*-->GetCopy*/
  327. /**********************************************************************/
  328. /***************************  GetCopy  ********************************/
  329. /**********************************************************************/
  330. char *GetCopy(void)
  331. {
  332.   char s1[30], s2[30], s3[70], s4[30];
  333.  
  334.   ENCODE(PROGRAMTITLE,s1);
  335.   ENCODE(VERSION,s2);
  336.   ENCODE(PROGRAMKENNUNG,s3);
  337.   ENCODE(VERSION_FORMAT_STRING,s4);
  338.  
  339.   /*    slight misuse of maxline...    */
  340.  
  341.   sprintf(maxline,s4,s1,s2,COMPILER-CR_OFFSET,s3);
  342.  
  343.   return (maxline);
  344. }
  345.  
  346.  
  347. /*-->PrintAuthors*/
  348. /**********************************************************************/
  349. /***************************  PrintAuthors  ***************************/
  350. /**********************************************************************/
  351. void PrintAuthors(void)
  352. {
  353. #ifdef DISPLAY
  354.   char s1[50], s4[20], s[30];
  355. #else
  356.   char s1[50], s3[40], s4[20], s[30];
  357. #endif
  358.  
  359.   ENCODE(AUTHOR1,s1);
  360.   //ENCODE(AUTHOR2,s2);
  361.   ENCODE(AUTHOR_TITLE,s4);
  362.  
  363. #ifdef DISPLAY
  364.   ENCODE(AUTHOR_S_FORMAT,s);
  365.   LoggingStr(s,s4,s1);
  366. #else
  367.   ENCODE(AUTHOR3,s3);
  368.   ENCODE(AUTHOR_D_FORMAT,s);
  369.   LoggingStr(s,s4,s1,s3);
  370. #endif
  371.  
  372. #if defined(BETACOPYRIGHT)
  373.   PrintBetaCopy();
  374. #endif
  375. }
  376.  
  377.  
  378.  
  379. /*-->AbortRun*/
  380. /**********************************************************************/
  381. /***************************  AbortRun  *******************************/
  382. /**********************************************************************/
  383. void AbortRun(int code)
  384. {
  385.   static int InAbortRun = FALSE;
  386.  
  387.   // don't do a endless loop!
  388.   if (InAbortRun) exit(code);
  389.   InAbortRun = TRUE;
  390.   
  391. #ifndef DISPLAY
  392.   if (do_accounting && is_printer_started > 0) {
  393.     /* Speichere Accounting-File */
  394.     FILE *fp;
  395.     long t;
  396.     char user[20], host[60];
  397.     char *ptr;
  398.  
  399.     sprintf(m_string, "Account.%s", o_printer_name);
  400.     fp = OpenConfigFile(m_string, MODE_APPEND);
  401.     if (fp != NULL) {
  402.       ptr = getenv("USERNAME");
  403.       if (ptr != NULL) {
  404.         strncpy(user, ptr, 19);
  405.       }
  406.       else {
  407.         strcpy(user, "user");
  408.       }
  409.       ptr = getenv("HOSTNAME");
  410.       if (ptr != NULL) {
  411.         strncpy(host, ptr, 59);
  412.       }
  413.       else {
  414.         strcpy(host, "host");
  415.       }
  416.       time(&t);
  417.       sprintf(m_string, "%s : %s : %s", user, host, ctime(&t));
  418.       m_string[strlen(m_string)-1] = '\0';    /* weg mit dem \n */
  419.       sprintf(maxline, "%s : %d\n", m_string, nr_printed_pages);
  420.       fputs(maxline, fp);
  421.       fclose(fp);
  422.     }
  423.   }
  424. #endif
  425. #ifdef ATARI
  426.    if ((code != -1) || is_gem_installed)
  427.     {
  428.      close_all();
  429.     }
  430.    else
  431.     code = 1;
  432. # ifdef DISPLAY
  433.    if (!is_gem_installed)
  434.     {
  435.      fprintf(stderr,"\033E\033e");
  436.      }
  437. # endif
  438. #else
  439. #  ifdef AMIGA
  440.        Enable_Abort = 0;    /* don't come in my way */
  441. #    ifdef DISPLAY
  442.        close_all_bild();
  443. #    else             /* DISPLAY */
  444.      /* prnzero(); wird schon in in BREAK Func gemacht   */
  445.          ClosePrinterDevice();
  446.          /* CloseARP(); */    /* wird nicht mehr benoetigt */
  447. #    endif            /* DISPLAY */
  448. #  endif            /* AMIGA */
  449. #endif                 /* ATARI */
  450.  
  451.    DebugStats = 0L;    /* don't flush at every line anymore */
  452.  
  453.    if (g_authors == 1) {
  454.       PrintAuthors();
  455.    }
  456.  
  457.  
  458. #ifdef DISPLAY
  459.    if (code != 0) {
  460.      Logging(MSG_PROGRAM_END_ERR, code);
  461.    }
  462.    else {
  463.      if (Stats) write_font_def_file();
  464.      Logging((user_aborted) ? MSG_USER_ABORT : MSG_PROGRAM_END_OK);
  465.    }
  466. #else
  467.    if (code != 0) {
  468.      Warning(MSG_PROGRAM_END_ERR, code);
  469.    }
  470.    else {
  471.      if (Stats) write_font_def_file();
  472.      Warning((user_aborted) ? MSG_USER_ABORT : MSG_DVIP_PRINT_FINISHED);
  473.    }
  474. #endif
  475.  
  476. #ifdef AMIGA
  477.    if (task_priority != old_task_priority) {
  478.      (void)SetTaskPri(FindTask(NULL), old_task_priority);
  479.    }
  480. #endif
  481.  
  482. #if defined(MALLOC_DEBUG)
  483.    xfree_all();
  484. #endif
  485.  
  486. #ifndef DISPLAY
  487.   MUIfree();        /* Oberflaeche (IMMER!!) schliessen, direkt vor dem Prg.Ende */
  488. #endif
  489.  
  490.    exit(code);        /* everything is closed and freed for us */
  491. }
  492.  
  493.  
  494.  
  495. /*-->Fatal*/
  496. /**********************************************************************/
  497. /***************************  Fatal  **********************************/
  498. /**********************************************************************/
  499.  
  500. void __stdargs Fatal(int ret, int msg, ...)
  501. {
  502.   va_list argptr;
  503.  
  504.   va_start(argptr, msg);
  505.   /* sprintf() should return the number of chars output */
  506.   vsprintf(&maxline[sprintf(maxline,GetTeXString(MSG_FATAL))], GetTeXString(msg), argptr);
  507.   va_end(argptr);
  508.  
  509.   DoLogging(maxline);
  510.  
  511. #if defined(DISPLAY)
  512.   FatalMessage(ret, &(maxline[0])+8);
  513. #else
  514.   if (usegui) MUIFatal(maxline);
  515.   else DoMessage(maxline);
  516. #endif
  517.  
  518.   if (g_logging == 1 && NULL != g_logfp) {
  519.     Message(MSG_LOG_FILE_CREATED,g_Logname);
  520.   }
  521.   AbortRun(ret);
  522. }
  523.  
  524. void __stdargs FatalStr(int ret, char *format,...)
  525. {
  526.   va_list argptr;
  527.  
  528.   va_start(argptr, format);
  529.   /* sprintf() should return the number of chars output */
  530.   vsprintf(&maxline[sprintf(maxline,GetTeXString(MSG_FATAL))], format, argptr);
  531.   va_end(argptr);
  532.  
  533.   DoLogging(maxline);
  534.  
  535. #if defined(DISPLAY)
  536.   FatalMessage(ret, &(maxline[0])+8);
  537. #else
  538.    if (usegui) MUIShowMessWin();
  539.   DoMessage(maxline + strlen(GetTeXString(MSG_FATAL)));
  540. #endif
  541.  
  542.   if (g_logging == 1 && NULL != g_logfp) {
  543.     Message(MSG_LOG_FILE_CREATED,g_Logname);
  544.   }
  545.   AbortRun(ret);
  546. }
  547.  
  548.  
  549.  
  550. /*-->Logging*/
  551. /**********************************************************************/
  552. /*****************************  Logging  ******************************/
  553. /**********************************************************************/
  554. /* nur ins Logfile */
  555.  
  556. void __stdargs Logging(int msg, ...)
  557. {
  558.   va_list argptr;
  559.  
  560.   va_start(argptr, msg);
  561.   DoOut(maxline, GetTeXString(msg), argptr, TRUE, FALSE);
  562.   va_end(argptr);
  563. }
  564.  
  565. void __stdargs LoggingStr(char *fmt,...)        /* issue a message to the logfile */
  566. {
  567.   va_list argptr;
  568.  
  569.   va_start(argptr, fmt);
  570.   DoOut(maxline, fmt, argptr, TRUE, FALSE);
  571.   va_end(argptr);
  572. }
  573.  
  574.  
  575.  
  576. /*-->Message*/
  577. /**********************************************************************/
  578. /*****************************  Message  ******************************/
  579. /**********************************************************************/
  580. /* nur auf den Bildschirm */
  581.  
  582. void __stdargs Message(int msg, ...)
  583. {
  584.   va_list argptr;
  585.  
  586.   va_start(argptr, msg);
  587.   DoOut(maxline, GetTeXString(msg), argptr, FALSE, TRUE);
  588.   va_end(argptr);
  589. }
  590.  
  591. void __stdargs MessageStr(char *fmt,...)          /* issue a message */
  592. {
  593.   va_list argptr;
  594.  
  595.   if (fmt) {   
  596.     va_start(argptr, fmt);
  597.     DoOut(maxline, fmt, argptr, FALSE, TRUE);
  598.     va_end(argptr);
  599.   }
  600.   else {
  601.     DoOut(maxline, GetCopy(), argptr, FALSE, TRUE);
  602.   }
  603. }
  604.  
  605.  
  606.  
  607. /*-->Warning*/
  608. /**********************************************************************/
  609. /*****************************  Warning  ******************************/
  610. /**********************************************************************/
  611. /* sowohl ins Logfile als auch an den Bildschirm */
  612.  
  613. void __stdargs Warning(int msg, ...)
  614. {
  615.   va_list argptr;
  616.  
  617. #if defined(AMIGA) && defined(DISPLAY)
  618.   beep();
  619. #endif
  620.  
  621.   va_start(argptr, msg);
  622.   DoOut(maxline, GetTeXString(msg), argptr, TRUE, TRUE);
  623.   va_end(argptr);
  624. }
  625.  
  626. void __stdargs WarningStr(char *fmt,...)      /* issue a warning */
  627. {
  628.   va_list argptr;
  629.  
  630. #if defined(DISPLAY)
  631.   beep();
  632. #else
  633.    if (usegui) MUIShowMessWin();
  634. #endif
  635.  
  636.   if (fmt) {
  637.     va_start(argptr, fmt);
  638.     DoOut(maxline, fmt, argptr, TRUE, TRUE);
  639.     va_end(argptr);
  640.   }
  641.   else {
  642.     DoOut(maxline, GetCopy(), argptr, TRUE, TRUE);
  643.   }
  644. }
  645.  
  646.  
  647.  
  648. /*************************************************************************/
  649. /*******    Fatal, Warning, Logging, Message support functions    **/
  650. /*************************************************************************/
  651. static int DoOut(char *buf, char *fmt, va_list args, int log, int message)
  652. {
  653.   char *ptr;
  654.   int length = 0;    /* we could check for overflows    */
  655.  
  656.   if (fmt == NULL) {
  657.     ptr = GetCopy();
  658.     if (message) DoMessage(ptr);
  659.     if (log) {
  660.       char time[30];
  661.       TimeString(time);
  662.       strcat(ptr, time);
  663.       strcat(ptr, "\n");
  664.     }
  665.   }
  666.   else {
  667.     ptr = buf;
  668.     length = vsprintf(ptr, fmt, args);
  669.     if (length >= MAXLINE) Fatal(20, MSG_LINE_BUFFER_OVERFLOW,length);
  670. #if defined(AMIGA) && defined(DISPLAY)
  671.     /* es wird etwas ungleich 'copyright' ausgegeben */
  672.     if (message) AddTimeRequest();    /* aus amscreen.c */
  673. #endif
  674.     if (message) DoMessage(ptr);
  675.   }
  676.   if (log) DoLogging(ptr);
  677.   return length;
  678. }
  679.  
  680.  
  681.  
  682. static void DoLogging(char *ptr)
  683. {
  684.   if (g_logging == 0) {
  685.     if (NULL == g_logfp) {
  686.       g_logfp = fopen(g_Logname,"w");
  687.     }
  688.     g_logging = (NULL == g_logfp) ? -1 : 1 ;
  689.   }
  690.  
  691.   if (g_logging == 1 && g_logfp) {
  692.  
  693.     fputs(ptr, g_logfp);
  694.     fputs("\n",g_logfp);
  695.  
  696. #ifdef AMIGA
  697.     if (DebugStats) {
  698.       fclose(g_logfp);    /* Kampf dem 'empty' log (aber nur mit -S) */
  699.       g_logfp = fopen(g_Logname,"a");
  700.       if (g_logfp == NULL) {
  701.         g_logging = -1;
  702.       }
  703.     }
  704. #else
  705.     fflush(g_logfp);
  706. #endif
  707.   }
  708. }
  709.  
  710.  
  711.  
  712. static void DoMessage(char *ptr)
  713. {
  714. #ifdef DISPLAY
  715.  
  716.     /* die naechsten zwei Ausgaben auf stderr sollten die einzigen im */
  717.     /* gesamten ShowDVI sein!!!    (und keine Ausgabe auf stdout)      */
  718.  
  719.     if (!write_screen(ptr)) {        /* ShowDVI */
  720.       fprintf(stderr, "%s\n", ptr);
  721. #if 0
  722.       if (!background) {
  723.         printf("%s\n",ptr);            /* nix screen */
  724.       }
  725. #endif
  726.     }
  727.  
  728. #else
  729.  
  730.     if (usegui) MUIMessage(ptr);
  731.     else if (!background) printf("%s\n",ptr);            /* DVIprint */
  732.  
  733. #endif    /* DISPLAY */
  734. }
  735.  
  736.  
  737.  
  738. /*========================================================================*/
  739.  
  740.  
  741. #ifdef AMIGA
  742.  
  743.  
  744. /*-->_abort*/
  745. /**********************************************************************/
  746. /***************************  _abort  *********************************/
  747. /**********************************************************************/
  748. void _abort(void)
  749. {
  750.   (void)CXBRK();
  751. }
  752.  
  753.  
  754. /*
  755.  * Neue SAS/c 6.0 Break-Funktion
  756.  */
  757. int _CXBRK(void)
  758. {
  759.   return CXBRK();
  760. }
  761.  
  762.  
  763. /**********************************************************************/
  764. /************************  free_resources  ****************************/
  765. /**********************************************************************/
  766. int CXBRK(void)        /* overwrite standard Lattice-function */
  767. {
  768. #ifdef DISPLAY
  769.   if (Enable_Abort) {
  770.     if (can_i_exit()) {    /* is a other window on the screen */
  771.       Enable_Abort = 0;    /* no recursive break */
  772.       Message(MSG_BREAK);
  773.       user_aborted = 1;
  774.       AbortRun(0);
  775.       return -1;    /* not reached (exit) */
  776.     }
  777.     else {
  778.       return 0;        /* no exit */
  779.     }
  780.   }
  781.   else {
  782.     return 0;        /* no exit */
  783.   }
  784. #else /* DISPLAY */
  785.   if (Enable_Abort) {
  786.     Enable_Abort = 0;    /* no recursive break */
  787.     Message( is_printer_started    ? MSG_BREAK_IO : MSG_BREAK);
  788.     prnzero();
  789.     user_aborted = 1;
  790.     AbortRun(0);
  791.     return -1;    /* not reached (exit) */
  792.   }
  793.   else {
  794.     return 0;        /* no exit */
  795.   }
  796. #endif /* DISPLAY */
  797. }
  798.  
  799.  
  800.  
  801. /********************************/
  802. /*  ARexx Port to call Metafont */
  803. /********************************/
  804.  
  805.  
  806. static int PutRexxMsg(struct MsgPort *mp, long action, STRPTR arg0,
  807.                 struct RexxMsg *arg1, char *extension);
  808.  
  809.  
  810. int call_mf(char *fntname, long fontmag, long hres, long vres,
  811.         long driver_type, char *pkname, char *pkdir)
  812. {
  813.   char com[256], *tmp;
  814.   int ret = FALSE, result = 20;
  815.  
  816.   tmp = getenv("CALLMF");
  817.  
  818.   if (tmp != NULL) {
  819.  
  820. #if defined(HARDDEB)
  821.     printf("ENV:CALLMF len %d & last char %x.\n",strlen(tmp),tmp[strlen(tmp)-1]);
  822. #endif
  823.     /* Ein Aufruf:
  824.        "callmf cmr10 120 100 100 show|print 100/cmr10.100pk tex:preview"
  825.     */
  826.  
  827.     sprintf(com,"\'%s %s %ld %ld %ld %s %s %s\'", tmp, fntname, fontmag, hres, vres,
  828.         (driver_type == 0) ? "show" : "print" , pkname, pkdir);
  829.     Logging(MSG_CALL_MF, com);
  830.     if (!call_rexx(com, &result)) {
  831. #ifndef DISPLAY
  832.       MessageStr("%s :",com);
  833. #endif
  834.       Warning(MSG_AREXX_COMM_START_FAILED);
  835.     }
  836.     else {
  837.       if(!(ret = (result == 0))) {
  838.         Warning(MSG_AREXX_COMM_FAILED, com, result);
  839.       }
  840.     }
  841.   }
  842.  
  843.   return ret;
  844. }
  845.  
  846. #include <exec/types.h>
  847. #include <libraries/dos.h>
  848. #include <clib/exec_protos.h>
  849. #include <clib/dos_protos.h>
  850. #include <string.h>
  851. #include <dos.h>
  852.  
  853. #include <rexx/rxslib.h>
  854. #include <rexx/errors.h>
  855.  
  856. STRPTR        CreateArgstring(STRPTR, long);
  857. void        DeleteArgstring(STRPTR);
  858. struct RexxMsg    *CreateRexxMsg(struct MsgPort *, STRPTR, STRPTR);
  859. void        DeleteRexxMsg(struct RexxMsg *);
  860.  
  861. #pragma libcall RexxSysBase CreateArgstring 7e 0802
  862. #pragma libcall RexxSysBase DeleteArgstring 84 801
  863. #pragma libcall RexxSysBase CreateRexxMsg   90 09803
  864. #pragma libcall RexxSysBase DeleteRexxMsg   96 801
  865.  
  866. #define PORTNAME    "Call-MF"
  867. #define RXEXTENS    "rexx"
  868.  
  869. #ifndef DISPLAY
  870.   struct RxsLib *RexxSysBase = NULL;
  871. #else
  872.   extern struct RxsLib *RexxSysBase;
  873. #endif
  874.  
  875. static int PutRexxMsg(struct MsgPort *mp, long action, STRPTR arg0,
  876.         struct RexxMsg *arg1, char *extension)
  877. {
  878.   struct RexxMsg *rm;
  879.   struct MsgPort *rp;
  880.  
  881.   if ((rm = CreateRexxMsg(mp, extension, mp->mp_Node.ln_Name)) != NULL) {
  882.     rm->rm_Action  = action;
  883.     rm->rm_Args[0] = arg0;
  884.     rm->rm_Args[1] = (STRPTR)arg1;
  885. /*    rm->rm_Stdin   = Output(); */
  886. /*    rm->rm_Stdout  = Output(); */
  887.     Forbid();
  888.     if ((rp = FindPort(RXSDIR)) != NULL) {
  889.       PutMsg(rp, (struct Message *)rm);
  890.     }
  891.     Permit();
  892.     if (rp == NULL) {
  893.       DeleteRexxMsg(rm);
  894.     }
  895.   }
  896.   return rm != NULL && rp != NULL;
  897. }
  898.  
  899.  
  900. int call_rexx(char *str, int *result)
  901. {
  902.   char *arg;
  903.   struct MsgPort *mp;
  904.   struct RexxMsg *rm, *rm2;
  905.   int ret = FALSE;
  906.   int pend;
  907.   int base_open;
  908.   char *portname, *extension;
  909.   
  910.   portname  = PORTNAME;
  911.   extension = RXEXTENS;
  912.  
  913.   base_open = (RexxSysBase != NULL);
  914.  
  915.   if ((!base_open) &&
  916.       (RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME, 0 /*RXSVERS*/)) == NULL) {
  917.     Fatal(10, MSG_CANT_OPEN, RXSNAME);
  918.   }
  919.   else {
  920.     Forbid();
  921.     if (FindPort(portname) == NULL) {
  922.       mp = CreatePort(portname, 0);
  923.       Permit();
  924.       if (mp != NULL) {
  925.         if ((arg = CreateArgstring(str, strlen(str))) != NULL) {
  926.           if (PutRexxMsg(mp, RXCOMM | RXFF_STRING, arg, NULL, extension)) {
  927.  
  928.             for (pend = 1; pend != 0; ) {
  929.               if (WaitPort(mp) != NULL) {
  930.                 while ((rm = (struct RexxMsg *)GetMsg(mp)) != NULL) {
  931.                   if (rm->rm_Node.mn_Node.ln_Type == NT_REPLYMSG) {
  932.                     ret = TRUE;
  933.                     *result = rm->rm_Result1;
  934.                     if ((rm2 = (struct RexxMsg *)rm->rm_Args[1]) != NULL) {
  935.                       rm2->rm_Result1 = rm->rm_Result1;
  936.                       rm2->rm_Result2 = 0;
  937.                       ReplyMsg((struct Message *)rm2);
  938.                     }
  939.                     DeleteRexxMsg(rm);
  940.                     pend--;
  941.                   }
  942.                   else {
  943.                     rm->rm_Result2 = 0;
  944.                     if (PutRexxMsg(mp, rm->rm_Action, rm->rm_Args[0], rm, extension)) {
  945.                       pend++;
  946.                     }
  947.                     else {
  948.                       rm->rm_Result1 = RC_FATAL;
  949.                       ReplyMsg((struct Message *)rm);
  950.                     }
  951.                   }
  952.                 }
  953.               }
  954.             }        /* for */
  955.           }
  956.           DeleteArgstring(arg);
  957.         }
  958.         DeletePort(mp);
  959.       }
  960.     }            /* Find port */
  961.     else {
  962.       Permit();
  963.     }
  964.     if (!base_open) {
  965.       CloseLibrary((struct Library *)RexxSysBase);
  966.     }
  967.   }
  968.   return ret;
  969. }
  970.  
  971. #endif /* AMIGA */
  972.