home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / larp145.lha / LARP / LMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-20  |  6.0 KB  |  292 lines

  1. /* LMain.c - main c file for LARP */
  2.  
  3. #include "defs.h"
  4.  
  5. char *RexxHostName = "LARP";
  6. UBYTE count = 0;        /* num messages in buffer */
  7. char *Buf;            /* Buffer */
  8. char PubName[32] = {0};        /* the name of the pubscreen */
  9. char FontName[32] = {0};    /* the name of the font */
  10. UBYTE status = 0;
  11. UBYTE dirt = 0;            /* No dirt */
  12. UWORD MAXBUF = 60;
  13.  
  14. void main(int ac, char *av[])
  15. {
  16.     int done=0;
  17.     ULONG class;
  18.     UWORD code;
  19.     LONG mask;
  20.     struct IntuiMessage *imsg;
  21.     if(ac > 0)
  22.         status = CLI;
  23.     if(status == CLI && ac > 1)
  24.     {
  25.         for(done = 1; done < ac; ++done)
  26.         {
  27.             if((strcmp(av[done], "PUBSCREEN"))==NULL)
  28.             {
  29.                 if(ac > done)
  30.                 {
  31.                     if(strlen(av[done + 1]) < 32)
  32.                     {
  33.                         strcpy(&PubName[0], av[done + 1]);
  34.                         LARP_pubscreen = &PubName[0];
  35.                     }
  36.                 }
  37.             }
  38.             if((strcmp(av[done], "QUIET"))==NULL)
  39.                 status = CLI|QUIET;
  40.             if((strcmp(av[done], "HISTORY"))==NULL)
  41.             {
  42.                 if(ac > done)
  43.                 {
  44.                     MAXBUF = atoi(av[done + 1]);
  45.                     if(MAXBUF > 1000||MAXBUF<1)
  46.                         MAXBUF = 60; /* There's got to be some sense */
  47.                 }
  48.             }
  49.             if((strcmp(av[done], "FONTSIZE"))==NULL)
  50.             {
  51.                 if(ac > done)
  52.                 {
  53.                     topazattr.ta_YSize = atoi(av[done + 1]);
  54.                     if(topazattr.ta_YSize > 100||topazattr.ta_YSize < 5)
  55.                         topazattr.ta_YSize = 8;
  56.                 }
  57.             }
  58.             if((strcmp(av[done], "FONTNAME"))==NULL)
  59.             {
  60.                 if(ac > done)
  61.                 {
  62.                     if(strlen(av[done + 1]) < 32)
  63.                     {
  64.                         strcpy(&FontName[0], av[done + 1]);
  65.                         topazattr.ta_Name = (STRPTR)&FontName[0];
  66.                     }
  67.                 }
  68.             }
  69.         }
  70.         done = 0;
  71.     }
  72.     
  73.     if(RexxSysBase == NULL)
  74.     {
  75.         puts("Unable to open rexxsyslib.library !");
  76.         exit(20);
  77.     }
  78.     if (OpenLibs()==0)
  79.     {
  80.         Buf = AllocMem(MAXBUF*80l, MEMF_PUBLIC|MEMF_CLEAR);
  81.         if(Buf == NULL)
  82.         {
  83.             puts("Cannot allocate memory.");
  84.             CloseLibs();
  85.             exit(20);
  86.         }
  87.         if (OpenWindowWin0()==0)
  88.         {
  89.             while(done==0)
  90.             {
  91.                 mask = Wait((1l<<RexxSigBit)|(1L << Win0->UserPort->mp_SigBit));
  92.                 if(mask & (1l<<RexxSigBit))
  93.                 {
  94.                     ProcessRexxCommands(NULL);
  95.                     DrawMessages(Win0, Buf, count);
  96.                 }
  97.                 else
  98.                 {
  99.                     imsg=GT_GetIMsg(Win0->UserPort);
  100.                     while (imsg != NULL )
  101.                     {
  102.                         class=imsg->Class;
  103.                         code=imsg->Code;
  104.                         GT_ReplyIMsg(imsg);
  105.                         done = ProcessWindowWin0(class, code, imsg);
  106.                         imsg=GT_GetIMsg(Win0->UserPort);
  107.                     }
  108.                 }
  109.             }
  110.             CloseWindowWin0();
  111.         }
  112.         else
  113.         {
  114.             puts("Cannot open window.");
  115.         }
  116.         FreeMem(Buf, MAXBUF*80l);
  117.         CloseLibs();
  118.     }
  119.     else
  120.     {
  121.         puts("Cannot open libraries.\n");
  122.         exit(20);
  123.     }
  124. }
  125.  
  126. long DoRexxCommand(msg, port, arg0, pres)
  127. void *msg;
  128. struct MsgPort *port;
  129. char *arg0;
  130. char **pres;
  131. {
  132.     int rc;
  133.     LONG x, y, n;
  134.     if(strncmp(arg0, "PUTS", 4) == 0)
  135.     {
  136.         *pres = "succ!";
  137.         rc = 0;
  138.         UpdateMessages(arg0 + 5);
  139.         return(rc);
  140.     }
  141.     if(strncmp(arg0, "SIZE", 4) == 0)
  142.     {
  143.         n = sscanf(arg0 + 5, "%d %d", &x, &y);
  144.         SizeWindow(Win0, x - Win0->Width, y - Win0->Height );
  145.         *pres = "succ!";
  146.         rc = 0;
  147.         return(rc);
  148.     }
  149.     if(strncmp(arg0, "PLACE", 5) == 0)
  150.     {
  151.         n = sscanf(arg0 + 6, "%d %d", &x, &y);
  152.         MoveWindow(Win0, x - Win0->LeftEdge, y - Win0->TopEdge );
  153.         *pres = "succ!";
  154.         rc = 0;
  155.         return(rc);
  156.     }
  157.     rc = 5;
  158.     *pres = "fail!";
  159.     return(rc);
  160. }
  161.  
  162. void DrawMessages(struct Window *win, char *buff, UBYTE count)
  163. {
  164.     short i, howmany, start, fontsize = win->RPort->Font->tf_YSize;
  165.     UWORD offx = win->BorderLeft, length, rowchar;
  166.     UWORD offy = win->BorderTop;
  167.     int linechar = (win->Height - 3 - fontsize - offy) / fontsize;
  168.     if(linechar<1||linechar > 1000)
  169.         return();
  170.     if(rowchar>80)
  171.         rowchar = 80;
  172.     if(dirt!=0)
  173.     {
  174.         SetAPen(win->RPort, 0);
  175.         RectFill(win->RPort, offx+8, offy + 5, win->Width-offx-21, win->Height-win->BorderBottom-5);
  176.     }
  177.     SetAPen(win->RPort, 1);
  178.     start = count - linechar;
  179.     if(start<0)
  180.         start = 0;
  181.     for(i = 0; i<count; i++)
  182.     {
  183.         howmany = strlen(buff + ((i+start) * 80));
  184.         if(howmany>79)
  185.             howmany = 79;
  186.         for(rowchar = 1; rowchar <= howmany; rowchar++)
  187.         {
  188.             length = TextLength(win->RPort, (STRPTR)buff + ((i+start) * 80), rowchar);
  189.             if(length > win->Width-28-offx-offx)
  190.             {
  191.                 howmany = rowchar - 1;
  192.                 break;
  193.             }
  194.         }
  195.         Move(win->RPort, offx + 8, offy + 3 + fontsize + (i * fontsize));
  196.         Text(win->RPort, buff + ((i + start) * 80), howmany);
  197.         if(i == linechar)
  198.             break;
  199.     }
  200.     dirt = 1; /* There are chars in the display */
  201. }
  202.  
  203. void UpdateMessages(char *line)
  204. {
  205.     int howmany = strlen(line);
  206.     if(howmany>78)
  207.         howmany = 78;
  208.     count++;
  209.     if(count>MAXBUF)
  210.     {
  211.         count = MAXBUF;
  212.         memmove(Buf, Buf + 80, (MAXBUF-1)*80);
  213.         memcpy(Buf + ((MAXBUF-1)*80), line, howmany+1);
  214.     }
  215.     else
  216.     {
  217.         memcpy(Buf+((count-1)*80), line, howmany+1);
  218.     }
  219. }
  220.  
  221. int ProcessWindowWin0( LONG Class, UWORD Code, APTR IAddress )
  222. {
  223.     int returncode = 0;
  224.     switch ( Class )
  225.     {
  226.     case IDCMP_CLOSEWINDOW:
  227.         returncode = 1;
  228.         break;
  229.     case IDCMP_NEWSIZE:
  230.         RendWindowWin0(Win0);
  231.         dirt = 0;
  232.         DrawMessages(Win0, Buf, count);
  233.         break;
  234.     }
  235.     return(returncode);
  236. }
  237.  
  238. void wbmain(struct WBStartup *wbstartup)
  239. {
  240.     struct DiskObject *dobj;    /* Really didn't had the motivation to get   */
  241.     struct WBArg *wbarg;        /* into this - so I looked at the Libraries  */
  242.     char **toolarray;        /* - and copied it - well modified it quite a*/
  243.     char *s;            /* bit actually */
  244.     status = WB;            /* because wbmain calls main and main has to */
  245.     wbarg = wbstartup->sm_ArgList;    /* know that it has been called by wbmain    */
  246.     dobj = GetDiskObject(wbarg->wa_Name);
  247.     if(dobj != NULL)
  248.     {
  249.         toolarray = (char**)dobj->do_ToolTypes;
  250.         s = (char *)FindToolType(toolarray, "PUBSCREEN");
  251.         if(s != NULL)
  252.         {
  253.             if(strlen(s) < 32)
  254.             {
  255.                 strcpy(&PubName[0], s);
  256.                 LARP_pubscreen = &PubName[0];
  257.             }
  258.         }
  259.         s = (char *)FindToolType(toolarray, "QUIET");
  260.         if(s != NULL)
  261.         {
  262.             if((strcmp(s, "TRUE")) == NULL)
  263.                 status = WB | QUIET;
  264.         }
  265.         s = (char *)FindToolType(toolarray, "HISTORY");
  266.         if(s != NULL)
  267.         {
  268.             MAXBUF = atoi(s);
  269.             if(MAXBUF > 1000||MAXBUF < 1)
  270.                 MAXBUF = 60;
  271.         }
  272.         s = (char *)FindToolType(toolarray, "FONTNAME");
  273.         if(s != NULL)
  274.         {
  275.             if(strlen(s) < 32)
  276.             {
  277.                 strcpy(&FontName[0], s);
  278.                 topazattr.ta_Name = (STRPTR)&FontName[0];
  279.             }
  280.         }
  281.         s = (char *)FindToolType(toolarray, "FONTSIZE");
  282.         if(s != NULL)
  283.         {
  284.             topazattr.ta_YSize = atoi(s);
  285.             if(topazattr.ta_YSize > 100||topazattr.ta_YSize < 5)
  286.                 topazattr.ta_YSize = 8;
  287.         }
  288.         FreeDiskObject(dobj);
  289.     }    
  290.     main(NULL, NULL);
  291. }
  292.