home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / text / tex / pastex / source / driver / util / amiga / special.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-30  |  6.4 KB  |  299 lines

  1. /*
  2. **    This file generated by localize 2.9 (AmigaDOS 2.1) from special.c
  3. */
  4. /* special.c */
  5.  
  6. #include "defines.h"
  7.  
  8. #include <sprof.h>
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <exec/types.h>
  14. #include <exec/exec.h>
  15. #include <exec/ports.h>
  16. #include <dos/dos.h>
  17. #include <dos/dostags.h>
  18. #include <intuition/intuition.h>
  19.  
  20. #include "globals.h"
  21. #include "special.h"
  22. #include "bitmap.h"
  23.  
  24. #include "globals.i"
  25. #include "amscreen.i"
  26.  
  27. #include <clib/alib_protos.h>
  28. #include <clib/exec_protos.h>
  29. #include <clib/dos_protos.h>
  30.  
  31. extern struct ExecBase *SysBase;
  32. extern struct DOSBase *DOSBase;
  33. #include <pragmas/exec_pragmas.h>
  34. #include <pragmas/dos_pragmas.h>
  35.  
  36.  
  37.  
  38. /*
  39.  * Fuer die locale-Library:
  40.  *
  41.  * Hier duerfen *nur* die MSG_#? Nummern eingebunden werden!
  42.  * Achtung:
  43.  * Es muss/sollte 'multiple-include' erlaubt sein!
  44.  */
  45. #include "local.i"
  46.  
  47. #undef  CATCOMP_ARRAY
  48. #undef  CATCOMP_BLOCK
  49. #undef  CATCOMP_STRINGS
  50. #define CATCOMP_NUMBERS
  51. #include "localstr.h"
  52.  
  53.  
  54.  
  55. extern long  hh;                        /* current h on device */
  56. extern long  vv;                        /* current v on device */
  57. extern struct bitmap map;
  58. extern long upper_limit;
  59. extern long lower_limit;
  60. extern int  Pass, PassNo;
  61.  
  62.  
  63. static struct MsgPort *special_port, *reply_port;
  64. static struct special_msg message;
  65. static struct driver_map dmap;
  66.  
  67.  
  68.  
  69. static int  open_port(void);
  70. static void setup_dmap(struct driver_map *dmap);
  71.  
  72.  
  73.  
  74. struct special_map *send_special(char *sp_string)
  75. {
  76.   struct special_msg *reply_msg;
  77.   BPTR lck;
  78.  
  79.   if (open_port()) {    /* Fehler? */
  80.     return NULL;
  81.   }
  82.  
  83.   setup_dmap(&dmap);
  84.  
  85.   message.msg.mn_Node.ln_Type    = NT_MESSAGE;
  86.   message.msg.mn_ReplyPort    = reply_port;
  87.   message.msg.mn_Length        = sizeof(message);
  88.   message.action        = AC_SEND_SPECIAL;
  89.   message.ret            = 0;
  90.   message.special_string    = sp_string;
  91.   message.hresolution        = hconvresolution;
  92.   message.vresolution        = vconvresolution;
  93.   message.bmap            = NULL;
  94.   message.tpic            = NULL;
  95.   message.dmap            = &dmap;
  96.   
  97.   lck = Lock(filename, ACCESS_READ);
  98.   if (lck) {
  99.     message.DVIdirLock = ParentDir(lck);
  100.     UnLock(lck);
  101.   }
  102.   else message.DVIdirLock            = NULL;
  103.   
  104.   message.DVImagnification = mag;
  105.   message.DVIfilename      = filename;
  106.   message.DVIfiledate      = &dvidatestamp;
  107.   message.DVIcurphypage    = current_page_phy;
  108.   
  109.   Message(MSG_SPECIAL_WAIT_FOR_PICT);
  110.  
  111.   PutMsg(special_port,&(message.msg));
  112.  
  113.   PROFILE_OFF();
  114.   WaitPort(reply_port);
  115.   PROFILE_ON();
  116.  
  117.   reply_msg = (struct special_msg *)GetMsg(reply_port);
  118.   if (reply_msg->action != AC_REPLY_SPECIAL) {
  119.     Warning(MSG_SPECIAL_EXPT_REPLY_SPECIAL,reply_msg->action);
  120.     return NULL;
  121.   }
  122.   if (reply_msg->ret != 0) {
  123.     Warning(MSG_SPECIAL_RET_FROM_SPECIAL,reply_msg->ret);
  124.   }
  125.  
  126.   return reply_msg->bmap;
  127. }
  128.  
  129.  
  130. void send_tpic(struct tpic_msg *tp)
  131. {
  132.   struct special_msg *reply_msg;
  133.   BPTR lck;
  134.  
  135.   if (open_port()) {    /* Fehler? */
  136.     return;
  137.   }
  138.  
  139.   setup_dmap(&dmap);
  140.  
  141.   message.msg.mn_Node.ln_Type    = NT_MESSAGE;
  142.   message.msg.mn_ReplyPort    = reply_port;
  143.   message.msg.mn_Length        = sizeof(message);
  144.   message.action        = AC_SEND_TPIC;
  145.   message.ret            = 0;
  146.   message.special_string    = NULL;
  147.   message.hresolution        = hconvresolution;
  148.   message.vresolution        = vconvresolution;
  149.   message.bmap            = NULL;
  150.   message.tpic            = tp;
  151.   message.dmap            = &dmap;
  152.  
  153.   lck = Lock(filename, ACCESS_READ);
  154.   if (lck) {
  155.     message.DVIdirLock = ParentDir(lck);
  156.     UnLock(lck);
  157.   }
  158.   else message.DVIdirLock            = NULL;
  159.  
  160.   PutMsg(special_port,&(message.msg));
  161.   
  162.   PROFILE_OFF();
  163.   WaitPort(reply_port);
  164.   PROFILE_ON();
  165.  
  166.   reply_msg = (struct special_msg *)GetMsg(reply_port);
  167.   if (reply_msg->action != AC_REPLY_TPIC) {
  168.     Warning(MSG_SPECIAL_EXPT_REPLY_TPIC,reply_msg->action);
  169.     return;
  170.   }
  171.   if (reply_msg->ret != 0) {
  172.     Warning(MSG_SPECIAL_RET_FROM_SPECIAL,reply_msg->ret);
  173.   }
  174.  
  175.   DeletePort(reply_port);
  176.   
  177.   special_port = NULL;
  178.   reply_port   = NULL;
  179. }
  180.  
  181.  
  182. void special_ok(void)
  183. {
  184.   struct special_msg *reply_msg;
  185.  
  186.   if (special_port == NULL || reply_port == NULL) {
  187.     special_port = NULL;
  188.     reply_port = NULL;
  189.     return;
  190.   }
  191.  
  192.   setup_dmap(&dmap);
  193.  
  194.   message.msg.mn_Node.ln_Type    = NT_MESSAGE;
  195.   message.msg.mn_ReplyPort    = reply_port;
  196.   message.msg.mn_Length        = sizeof(message);
  197.   message.action        = AC_OK_BITMAP;
  198.   message.ret            = 0;
  199.   message.tpic            = NULL;
  200.   message.dmap            = &dmap;
  201.   message.special_string    = NULL;
  202.   message.hresolution        = hconvresolution;
  203.   message.vresolution        = vconvresolution;
  204.  
  205.   PutMsg(special_port,&(message.msg));
  206.   
  207.   PROFILE_OFF();
  208.   WaitPort(reply_port);
  209.   PROFILE_ON();
  210.  
  211.   reply_msg = (struct special_msg *)GetMsg(reply_port);
  212.   if (reply_msg->action != AC_REPLY_BITMAP) {
  213.     Warning(MSG_SPECIAL_EXPT_REPLY_BITMAP,reply_msg->action);
  214.   }
  215.   else {
  216.     if (reply_msg->ret != 0) {
  217.       Warning(MSG_SPECIAL_RET_FROM_SPECIAL,reply_msg->ret);
  218.     }
  219.   }
  220.  
  221.   DeletePort(reply_port);
  222.  
  223.   special_port = NULL;
  224.   reply_port   = NULL;
  225.   
  226.   if (message.DVIdirLock) UnLock(message.DVIdirLock);
  227.   message.DVIdirLock = NULL;
  228.  
  229.   Message(MSG_SPECIAL_PICT_RECEIVED);
  230. }
  231.  
  232.  
  233.  
  234. static int open_port(void)
  235. {
  236.   special_port = NULL;
  237.   reply_port   = NULL;
  238.  
  239.   special_port = FindPort(SPECIAL_PORT);
  240.  
  241.   if (special_port == NULL && start_specialhost) {
  242.     int error;
  243.     int count = 0;
  244.     BPTR fh;
  245.     
  246.     fh = Open("nil:", MODE_NEWFILE);
  247.     
  248.     error = SystemTags("SpecialHost", SYS_Input, fh, SYS_Output, NULL, SYS_Asynch, TRUE, SYS_UserShell, TRUE, TAG_DONE);
  249.  
  250.     if (error) {
  251.       count = 6;
  252.       Close(fh);
  253.     }
  254.     
  255.     do {
  256.       special_port = FindPort(SPECIAL_PORT);
  257.       count++;
  258.       if (!special_port && count < 6) Delay(10);
  259.     } while (!special_port || count < 6);
  260.   }
  261.  
  262.   if (special_port == NULL) {
  263.     /* no special port */
  264.     Warning(MSG_SPECIAL_FOUND_NO_SPECIAL);
  265.     return TRUE;
  266.   }
  267.  
  268.   reply_port = CreatePort(SPECIAL_REPLY,0L);
  269.   if (reply_port == NULL) {
  270.     /* no reply port */
  271.     Warning(MSG_SPECIAL_CANT_CREATE_PORT);
  272.     return TRUE;
  273.   }
  274.   return FALSE;        /* kein Fehler */
  275. }
  276.  
  277.  
  278. static void setup_dmap(struct driver_map *dmap)
  279. {
  280. #ifdef OLD_NO_OFFSET_VARS
  281.   dmap->x         = hh + (long)hoffset;
  282.   dmap->y         = vv + (long)voffset;
  283. #else
  284.   dmap->x         = hh + OffsetBitmap_X;        // mit landscape usw.
  285.   dmap->y         = vv + OffsetBitmap_Y; 
  286. #endif
  287.   dmap->width         = map.width;
  288.   dmap->height         = map.height;
  289.   dmap->lower_limit     = lower_limit;
  290.   dmap->upper_limit     = upper_limit;
  291.   dmap->pixptr         = map.pixptr;
  292.   dmap->null_x         = (long)hoffset;
  293.   dmap->null_y         = (long)voffset;
  294.   dmap->page_width     = paper_width;
  295.   dmap->page_height     = paper_height;
  296.   dmap->pass         = Pass;
  297.   dmap->passes         = PassNo;
  298. }
  299.