home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d191 / ispell.lha / ISpell / src.zoo / amiga.c next >
C/C++ Source or Header  |  1989-02-22  |  9KB  |  453 lines

  1. /* -*- Mode:Text -*- */
  2. /*
  3.  * Deal w/ amiga console screen stuff.
  4.  *
  5.  *                     -- luis soltero, 5/12/88 --
  6.  *
  7.  *
  8.  */
  9. #include <stdio.h>
  10. #include <fcntl.h>
  11. #include "ispell.h"
  12.  
  13. #define FONT_HEIGHT    9
  14.  
  15. /*------------------------------------------------------------------------
  16.  * amiga console suport routines
  17.  */
  18.  
  19. #include <exec/types.h>
  20. #include <exec/exec.h>
  21. #include <intuition/intuition.h>
  22. #include <graphics/gfx.h>
  23. #include <libraries/dos.h>
  24. #include <libraries/dosextens.h>
  25.  
  26. /* console colors */
  27. #define WHITE_ON_BLACK    0
  28. #define WHITE_ON_BLUE    1
  29. #define BLACK_ON_WHITE    2
  30. #define BLUE_ON_WHITE    3
  31. #define ORANGE_ON_BLUE    4
  32.  
  33. #define SETCOLORS(k,x)    (setcolors(k, colors[x].style, colors[x].frw, colors[x].bak))
  34.  
  35. struct Window *scr_w = NULL;
  36. struct IOStdReq *scr_rq = NULL, _scr_rq;
  37.  
  38. struct colortype {
  39.     char *style;
  40.     char *frw;
  41.     char *bak;
  42. } colors[5] = {
  43.     {"0", "31", "42"},        /* white on black */
  44.     {"0", "31", "40"},        /* white on blue  */
  45.     {"0", "32", "41"},        /* black on white */
  46.     {"0", "30", "41"},        /* blue on white  */
  47.     {"0", "33", "40"}        /* orange_on_blue */
  48. };
  49.  
  50. insert_line(rq)
  51. struct IOStdReq *rq;
  52. {
  53.      printc(rq,"%c%c",0x9b, 0x4c);
  54. }
  55.  
  56. scroll_up(rq, nl)
  57. struct IOStdReq *rq;
  58. int nl;
  59. {
  60.     char buf[10];
  61.     sprintf(buf,"%d",(short)nl);
  62.     printc(rq,"%c%s%c",0x9b, buf, 0x53);
  63. }
  64.  
  65. scroll_down(rq, nl)
  66. struct IOStdReq *rq;
  67. int nl;
  68. {
  69.     char buf[10];
  70.     sprintf(buf,"%d",(short)nl);
  71.     printc(rq,"%c%s%c",0x9b, buf, 0x54);
  72. }
  73.  
  74. cursor_off(rq)
  75. struct IOStdReq *rq;
  76. {
  77.      printc(rq,"%c%c%c%c",0x9b,0x30,0x20,0x70);
  78. }
  79.  
  80. cursor_on(rq)
  81. struct IOStdReq *rq;
  82. {
  83.     printf(rq,"%c%c%c",0x9b,0x20,0x70);
  84. }
  85.  
  86. beep(rq)
  87. struct IOStdReq *rq;
  88. {
  89.     printc(rq,"%c",0x7);
  90. }
  91.  
  92. con_set_line(rq,offset,len)
  93. struct IOStdReq *rq;
  94. int offset,        /* in raster col, dist from left of win */
  95.     len;        /* number of chars                */
  96. {
  97.     char buf[10];
  98.     sprintf(buf,"%d",(short)offset);
  99.     printc(rq,"%c%s%c",0x9b,buf,0x78);
  100.  
  101.     sprintf(buf,"%d",(short)len);
  102.     printc(rq,"%c%s%c",0x9b,buf,0x75);
  103. }
  104.  
  105. con_set_pagelen(rq)
  106. struct IOStdReq *rq;
  107. {
  108.     printc(rq,"%c%c",0x9b,0x74);
  109. }
  110.  
  111. Open_Console(rq,win)
  112.   struct IOStdReq     *rq;
  113.   struct Window        *win;
  114. {
  115.     rq->io_Data = (APTR) win;
  116.     rq->io_Length = sizeof(*win);
  117.     if (OpenDevice("console.device",0,rq,0))
  118.       return(FALSE);    /* could not get device */      
  119.     return(TRUE);    /* device opened successfully */
  120. }
  121.  
  122. GotoXY(rq,x,y)
  123.   struct IOStdReq    *rq;
  124.   ULONG            x,y;
  125. {
  126.     char buf[10];
  127.     sprintf(buf,"%c%d%c%d%c",0x9b,y,0x3b,x,0x48);
  128.     putcon(rq,buf);
  129. }
  130.  
  131. ClrScr(rq)
  132.   struct IOStdReq    *rq;
  133. {
  134.     char buf[10];
  135.     sprintf(buf,"%c",0x0c);
  136.     putcon(rq,buf);
  137. }
  138.  
  139. setcolors(rq,style,fg,bg)
  140. struct IOStdReq *rq;
  141. char *style, *fg, *bg;
  142. {
  143.     char buf[10];
  144.     sprintf(buf,"%c%s%c%s%c%s%c",0x9b,style,0x3b,fg,0x3b,bg,0x6d);
  145.     putcon(rq,buf);
  146. }
  147.  
  148. putcon(rq,str)
  149. struct IOStdReq *rq;
  150. char *str;
  151. {
  152.     /* in case the console has not been initialized */
  153.     if ( rq == NULL ) {
  154.         fprintf(stderr,"%s",str);
  155.     return;
  156.     }
  157.     rq->io_Command = CMD_WRITE;
  158.     rq->io_Data = (APTR) str;
  159.     rq->io_Length = -1;    
  160.     DoIO(rq);    
  161. }
  162.  
  163. printc(rq,fmt,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
  164. struct  IOStdReq    *rq;
  165. ULONG      fmt,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12;
  166. {
  167.     char    pbuff[256];
  168.     sprintf(pbuff,fmt,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12);
  169.     putcon(rq,pbuff);
  170. }
  171.  
  172. struct NewWindow NewWin = {
  173.     0, 0,        /* left, top edge    */
  174.     0, 0,        /* width, hight      */
  175.     0, 1,        /* detail, block pen */
  176.     CLOSEWINDOW   | NEWSIZE,      /* IDCMP flags */
  177.     SMART_REFRESH | ACTIVATE    | /* flags       */
  178.     WINDOWCLOSE   | WINDOWDRAG  | 
  179.     WINDOWSIZING  | WINDOWDEPTH | 
  180.     GIMMEZEROZERO,
  181.     NULL, NULL,        /* gadget, check mark    */
  182.     NULL,        /* title             */
  183.     NULL, NULL,        /* screen, bitmap        */
  184.     200, 15,        /* min width, min height */
  185.     640, 200,        /* max width, max height */
  186.     WBENCHSCREEN    /* type             */
  187. };
  188.  
  189. Make_Window(w_ptr, title, x0, y0, x1, y1)
  190.   struct    Window    **w_ptr;
  191.   UBYTE        *title;
  192.   int        x0,y0,x1,y1;    /* upper left & lower right corners */
  193.  
  194. {
  195.     struct  Window         *OpenWindow();
  196.     
  197.     /* define the window in Amiga Intuition terms */
  198.  
  199.     NewWin.LeftEdge = x0;
  200.     NewWin.TopEdge = y0;
  201.     NewWin.Width = (x1 - x0);
  202.     NewWin.Height = (y1 - y0);
  203.     NewWin.Title = title;
  204.  
  205.     if ((*w_ptr = OpenWindow(&NewWin)) == NULL)
  206.       return(FALSE);    /* problem... return false */
  207.  
  208.     return(TRUE);    /* window opened okay... return true */
  209.  
  210. }    /* Make_Window() */
  211.  
  212. struct IntuitionBase *IntuitionBase;
  213.  
  214. /* open a 25x80 nondescript win to scroll text in */
  215. init_win(ApplWin, applname, ApplIOrq)
  216. struct Window   **ApplWin;
  217. char *applname;
  218. struct IOStdReq *ApplIOrq;
  219. {
  220.     struct IntuitionBase *OpenLibrary();
  221.         struct GfxBase *gfb;
  222.  
  223.     IntuitionBase = OpenLibrary("intuition.library",LIBRARY_VERSION);
  224.     if (IntuitionBase == NULL)
  225.       exit(FALSE);
  226.  
  227.     gfb = (struct GfxBase *)OpenLibrary("graphics.library",LIBRARY_VERSION);
  228.     if (gfb == NULL)
  229.       exit(FALSE);
  230.  
  231.     if (!(Make_Window(ApplWin,applname,0L,0L,640L,200L)))
  232.       exit (FALSE);
  233.       
  234.     ModifyIDCMP((*ApplWin), CLOSEWINDOW | NEWSIZE | ACTIVEWINDOW | 
  235.                  VANILLAKEY  | MENUPICK);
  236.     
  237.     if (! Open_Console(ApplIOrq,(*ApplWin) )){
  238.        CloseWindow((*ApplWin));
  239.        exit(FALSE);
  240.      }
  241.         con_set_line(ApplIOrq,0,130);
  242.     SETCOLORS(ApplIOrq,WHITE_ON_BLACK);
  243. }
  244.  
  245. /* terminate win opened by init_win() */
  246. close_win(ApplWin, ApplIOrq)
  247. struct Window   *ApplWin;
  248. struct IOStdReq *ApplIOrq;
  249. {
  250.     CloseWindow(ApplWin);
  251.     CloseDevice(ApplIOrq);
  252. }
  253.  
  254. /* get input from user and tokenize it */ 
  255. getevent(ApplWin) 
  256. struct Window *ApplWin;
  257. {
  258.     struct IntuiMessage *mess, *GetMsg();
  259.     int retval = -1;
  260.  
  261.     /* wait for an intuition event */
  262.     while( !(mess = GetMsg(ApplWin->UserPort)) )
  263.         Wait(1 << ApplWin->UserPort->mp_SigBit);
  264.  
  265.     switch(mess->Class) {
  266.     case CLOSEWINDOW:
  267.         retval = 'q';
  268.         break;
  269.     case VANILLAKEY: 
  270.         retval = mess->Code;
  271.         break;
  272.     case NEWSIZE : 
  273.         con_set_pagelen(scr_rq);
  274.         co = (mess->IDCMPWindow->Width  - 13)/FONT_HEIGHT -1;
  275.         li = (mess->IDCMPWindow->Height - 13)/FONT_HEIGHT -1;
  276.         retval = 0x0c;
  277.             SETCOLORS(scr_rq, WHITE_ON_BLACK);        
  278.         break;
  279.     case MENUPICK:
  280.     case ACTIVEWINDOW:
  281.     default:
  282.         break;
  283.     }
  284.     ReplyMsg(mess);
  285.     return(retval);
  286. }
  287.  
  288. /*
  289.  * end of amiga console support.
  290.  *-----------------------------------------------------------------------*/
  291.  
  292.  
  293. /*-------------------------------------------------------------------------
  294.  * terminal handling entry points
  295.  */
  296.  
  297. #include <sgtty.h>
  298. #include <signal.h>
  299.  
  300. printcon(fmt,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
  301. ULONG      fmt,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12;
  302. {
  303.     char    pbuff[256];
  304.     sprintf(pbuff,fmt,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12);
  305.     putcon(scr_rq, pbuff);
  306. }
  307.  
  308. putccon(ch)
  309. char ch;
  310. {
  311.     printc(scr_rq,"%c", ch);
  312. }
  313.  
  314. getccon()
  315. {
  316.     int ch;
  317.  
  318.     while ( (ch=getevent(scr_w)) == -1 )
  319.         ;
  320.     if ( ch == '\b' || ch == 0x7f )
  321.         erasechar = ch;
  322.     return( ch );
  323. }
  324.  
  325. #include "version.h"
  326.  
  327. /* open a console window for spell */
  328. terminit ()
  329. {
  330.     erasechar = '\b';
  331.     scr_rq = &_scr_rq;
  332.     init_win(&scr_w, Version_ID+strlen("@(#) "), scr_rq);
  333.     li = 23;
  334.     co = 77;
  335. }
  336.  
  337. done ()
  338. {
  339.     unlink(tempfile);
  340.     close_win(scr_w, scr_rq);
  341.     exit(0);
  342. }
  343.  
  344. /* clear the screen */
  345. erase ()
  346. {
  347.     ClrScr(scr_rq);
  348. }
  349.  
  350. /* move to row, col */
  351. move (row, col)
  352. {
  353.     GotoXY(scr_rq, col, row);
  354. }
  355.  
  356. /* do stand out mode */
  357. inverse ()
  358. {
  359.     SETCOLORS(scr_rq, ORANGE_ON_BLUE); 
  360. }
  361.  
  362. /* do stand end mode */
  363. normal ()
  364. {
  365.     SETCOLORS(scr_rq, WHITE_ON_BLACK);
  366. }
  367.  
  368. /* do a back space */
  369. backup ()
  370. {
  371.     putch((int)'\b');
  372. }
  373.  
  374. putch (c)
  375. {
  376.     printc (scr_rq,"%c", c);
  377. }
  378.  
  379. /* not implemented on the amiga */
  380. onstop(signo) {}
  381. stop () {}
  382.  
  383. #define CLI    "NewCli"
  384. #define CLINAME "\"con:20/30/600/100/ISpell Cli\""
  385.  
  386. shellescape (buf)
  387. char *buf;
  388. {
  389.     fexecl(CLI,CLI,CLINAME,0);
  390. }
  391.  
  392. /*
  393.  * end of terminal control entry points
  394.  *-----------------------------------------------------------------------*/
  395.  
  396. /*-----------------------------------------------------------------------
  397.  * misc missing and broken stuff.
  398.  *
  399.  */
  400.  
  401. /* the manx access routine is broken, here is a brain damaged one
  402.    that works for this applications. */
  403. access(name)
  404. char *name;
  405. {
  406.     int in = open(name, O_RDWR);
  407.     if ( in == -1 ) 
  408.         return( -1 );
  409.     close (in);
  410.     return(0);
  411. }
  412.  
  413. /* i really do not understant why sleep is used in i spell. Here is
  414.    a null function used soley to keep ispell happy. */
  415. /* i do.  fixed.  -tgr */
  416. sleep(n) int n; {
  417.    if (n > 0)
  418.       Delay(50L * n) ;
  419. }
  420.  
  421. link(from, to)
  422. char *from, *to;
  423. {
  424.     FILE *f, *t;
  425.     int  ch;
  426.     if ( (f=fopen(from,"r")) == NULL )
  427.         return(-1);
  428.     if ( (t=fopen(to,"w")) == NULL ) {
  429.         fclose(f);
  430.     return(-1);
  431.     }
  432.     while((ch=getc(f)) != EOF )
  433.     putc(ch, t);
  434.     fclose(f);
  435.     fclose(t);
  436. }
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.