home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / ace / c / message.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-04  |  5.6 KB  |  326 lines

  1. /*
  2. ** ACE Message Ports.
  3. ** Copyright (C) 1998 David Benn
  4. ** 
  5. ** This program is free software; you can redistribute it and/or
  6. ** modify it under the terms of the GNU General Public License
  7. ** as published by the Free Software Foundation; either version 2
  8. ** of the License, or (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program; if not, write to the Free Software
  17. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18. **
  19. ** Author: David J Benn
  20. **   Date: 15th February 1994,
  21. **       22nd August 1994,
  22. **       1st September 1994
  23. */
  24.  
  25. #include "acedef.h"
  26.  
  27. /* locals */
  28. static     char    *frame_ptr[] = { "(a4)","(a5)" };
  29.  
  30. /* externals */
  31. extern    int    sym;
  32. extern    int    typ;
  33. extern    int    obj;
  34. extern    int    lev;
  35. extern    char    id[MAXIDSIZE];
  36. extern    SYM    *curr_item;
  37.  
  38. /* functions */
  39. void    message_open()
  40. {
  41. /* 
  42. ** MESSAGE OPEN [#]channel,port-name,mode
  43. */
  44. int    mtype;
  45.  
  46.     insymbol();
  47.  
  48.     if (sym == hash) insymbol();
  49.  
  50.     mtype = expr();
  51.  
  52.     if (mtype == stringtype)
  53.         _error(4);
  54.     else
  55.     {
  56.         /* channel */
  57.         if (make_integer(mtype) == shorttype) make_long();
  58.         
  59.         if (sym != comma) 
  60.             _error(16);
  61.         else
  62.         {
  63.             /* port-name */
  64.             insymbol();
  65.             if (expr() != stringtype)
  66.                 _error(4);
  67.             else
  68.             {
  69.                 if (sym != comma)
  70.                     _error(16);
  71.                 else
  72.                 {
  73.                     /* mode (r,R,w,W) */
  74.                     insymbol();
  75.                     if (expr() != stringtype)
  76.                         _error(4);
  77.                     else
  78.                     {
  79.                       /* call function */
  80.                       gen("jsr","_MessageOpen","  ");
  81.                       gen("add.l","#12","sp");
  82.                       enter_XREF("_MessageOpen");
  83.                     }                
  84.                 }
  85.             }
  86.         } 
  87.             
  88.     }
  89. }
  90.  
  91. void    message_read()
  92. {
  93. /* 
  94. ** MESSAGE READ [#]channel,message-string
  95. */
  96. int    mtype;
  97. SYM    *storage;
  98. char    addrbuf[40];
  99.  
  100.     insymbol();
  101.  
  102.     if (sym == hash) insymbol();
  103.  
  104.     mtype = expr();
  105.  
  106.     if (mtype == stringtype)
  107.         _error(4);
  108.     else
  109.     {
  110.         /* channel */
  111.         if (make_integer(mtype) == shorttype) make_long();
  112.         
  113.         if (sym != comma) 
  114.             _error(16);
  115.         else
  116.         {
  117.               /*
  118.             ** Message string. 
  119.             */
  120.               insymbol();                        
  121.               if (sym == ident && obj == variable)
  122.               {
  123.                    /* 
  124.                 ** If string variable/array doesn't exist, 
  125.                 ** create a simple variable.
  126.                 */
  127.                    if (!exist(id,variable) && !exist(id,array)) 
  128.                    {
  129.                         /* 
  130.                     ** Allocate a simple string variable.
  131.                     */
  132.                         enter(id,typ,obj,0);
  133.                         enter_DATA("_nullstring:","dc.b 0");
  134.                         gen("pea","_nullstring","  ");
  135.                         assign_to_string_variable(curr_item,
  136.                                   MAXSTRLEN);
  137.                    }
  138.  
  139.                    storage = curr_item;
  140.  
  141.                    /* 
  142.                 ** Is it a string variable or array? 
  143.                 */
  144.                    if (storage->type != stringtype) _error(4);
  145.                    else    
  146.                    {
  147.                         /* 
  148.                     ** Get address of string pointed to 
  149.                     ** by variable/array element.
  150.                     */
  151.                         itoa(-1*storage->address,addrbuf,10);
  152.                         strcat(addrbuf,frame_ptr[lev]);
  153.  
  154.                         /*
  155.                     ** Pass string address to function 
  156.                     ** (on stack).
  157.                     */
  158.                         if (storage->object == array)
  159.                         {
  160.                              point_to_array(storage,addrbuf);
  161.                              gen("move.l",addrbuf,"d0");
  162.                              gen("add.l","d7","d0");
  163.                              gen("move.l","d0","-(sp)");
  164.                         }
  165.                          else
  166.                                gen("move.l",addrbuf,"-(sp)");
  167.  
  168.                         insymbol();
  169.  
  170.                     /* call function */
  171.                     gen("jsr","_MessageRead","  ");
  172.                     gen("addq","#8","sp");
  173.                     enter_XREF("_MessageRead");
  174.                 }
  175.             }
  176.             else
  177.                 _error(19);  /* variable or array expected */
  178.         }   
  179.             
  180.     }
  181. }
  182.  
  183. void    message_write()
  184. {
  185. /* 
  186. ** MESSAGE WRITE [#]channel,message-string
  187. */
  188. int    mtype;
  189.  
  190.     insymbol();
  191.  
  192.     if (sym == hash) insymbol();
  193.  
  194.     mtype = expr();
  195.  
  196.     if (mtype == stringtype)
  197.         _error(4);
  198.     else
  199.     {
  200.         /* channel */
  201.         if (make_integer(mtype) == shorttype) make_long();
  202.         
  203.         if (sym != comma) 
  204.             _error(16);
  205.         else
  206.         {
  207.             /* message-string */
  208.             insymbol();
  209.             if (expr() != stringtype)
  210.                 _error(4);
  211.             else
  212.             {
  213.                 /* call function */
  214.                 gen("jsr","_MessageWrite","  ");
  215.                 gen("addq","#8","sp");
  216.                 enter_XREF("_MessageWrite");
  217.             }
  218.         } 
  219.             
  220.     }
  221. }
  222.  
  223. void    message_wait()
  224. {
  225. /* 
  226. ** MESSAGE WAIT [#]channel
  227. */
  228. int    mtype;
  229.  
  230.     insymbol();
  231.  
  232.     if (sym == hash) insymbol();
  233.  
  234.     mtype = expr();
  235.  
  236.     if (mtype == stringtype)
  237.         _error(4);
  238.     else
  239.     {
  240.         /* channel */
  241.         if (make_integer(mtype) == shorttype) make_long();
  242.  
  243.         /* call function */
  244.         gen("jsr","_MessageWait","  ");
  245.         gen("addq","#4","sp");
  246.         enter_XREF("_MessageWait");
  247.     }
  248. }
  249.  
  250. void    message_clear()
  251. {
  252. /* 
  253. ** MESSAGE CLEAR [#]channel
  254. */
  255. int    mtype;
  256.  
  257.     insymbol();
  258.  
  259.     if (sym == hash) insymbol();
  260.  
  261.     mtype = expr();
  262.  
  263.     if (mtype == stringtype)
  264.         _error(4);
  265.     else
  266.     {
  267.         /* channel */
  268.         if (make_integer(mtype) == shorttype) make_long();
  269.  
  270.         /* call function */
  271.         gen("jsr","_MessageClear","  ");
  272.         gen("addq","#4","sp");
  273.         enter_XREF("_MessageClear");
  274.     }
  275. }
  276.  
  277. void    message_close()
  278. {
  279. /* 
  280. ** MESSAGE CLOSE [#]channel
  281. */
  282. int    mtype;
  283.  
  284.     insymbol();
  285.  
  286.     if (sym == hash) insymbol();
  287.  
  288.     mtype = expr();
  289.  
  290.     if (mtype == stringtype)
  291.         _error(4);
  292.     else
  293.     {
  294.         /* channel */
  295.         if (make_integer(mtype) == shorttype) make_long();
  296.  
  297.         /* call function */
  298.         gen("jsr","_MessageClose","  ");
  299.         gen("addq","#4","sp");
  300.         enter_XREF("_MessageClose");
  301.     }
  302. }
  303.  
  304. void    message()
  305. {
  306. /* 
  307. ** MESSAGE OPEN|CLOSE|READ|WRITE|WAIT|CLEAR
  308. */
  309.  
  310.     insymbol();
  311.  
  312.     switch(sym)
  313.     {
  314.         case opensym    : message_open(); break;
  315.         case closesym    : message_close(); break;
  316.  
  317.         case readsym    : message_read(); break;
  318.         case writesym    : message_write(); break;
  319.  
  320.         case waitsym    : message_wait(); break;
  321.         case clearsym    : message_clear(); break;
  322.  
  323.         default        : _error(77); break;    
  324.     }    
  325. }
  326.