home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / wp_dtp / ispell.lha / amiga.c next >
C/C++ Source or Header  |  1990-12-29  |  5KB  |  237 lines

  1. /*
  2.  *  Deal w/ amiga console screen stuff (and other missing stuff - LJR).
  3.  *
  4.  *                    -- luis soltero, 5/12/88 --
  5.  *
  6.  *  Total rework by Loren J. Rittle, 12/28/90
  7.  *
  8.  *  Now when ISpell is run in interactive mode, all screen
  9.  *  I/O is directed at the CLI window ISpell is started in 
  10.  *  if possible.  If started by WorkBench then, of course,
  11.  *  a window is opened for screen I/O.
  12.  *
  13.  *  Note: None of the screen I/O routines are called if ISpell
  14.  *  is run in ARexx server mode.
  15.  */
  16.  
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <stdarg.h>
  20. #include <string.h>
  21. #include <fcntl.h>
  22. #include <signal.h>
  23. #include <exec/types.h>
  24. #include <exec/exec.h>
  25. #include <libraries/dos.h>
  26. #include <libraries/dosextens.h>
  27. #include <intuition/intuition.h>
  28. #include <proto/all.h>
  29. #include "version.h"
  30. #include "ispell.h"
  31.  
  32. BPTR tty;
  33.  
  34. struct colortype
  35. {
  36.   char *style;
  37.   char *frw;
  38.   char *bak;
  39. } colors[] =
  40. {
  41. #define WHITE_ON_BLACK    0
  42.   {"0", "31", "42"},
  43. #define WHITE_ON_BLUE    1
  44.   {"0", "31", "40"},
  45. #define BLACK_ON_WHITE    2
  46.   {"0", "32", "41"},
  47. #define BLUE_ON_WHITE    3
  48.   {"0", "30", "41"},
  49. #define ORANGE_ON_BLUE    4
  50.   {"0", "33", "40"},
  51. #define BLUE_ON_ORANGE  5
  52.   {"0", "30", "43"}
  53. };
  54.  
  55. #define SETCOLORS(x)    (setcolors(colors[x].style, colors[x].frw, colors[x].bak))
  56.  
  57. void setcolors (char *style, char *fg, char *bg)
  58. {
  59.   char buf[16];
  60.  
  61.   sprintf (buf, "\x9b%s\x3b%s\x3b%s\x6d", style, fg, bg);
  62.   Write (tty, buf, strlen(buf));
  63. }
  64.  
  65. void printcon (char *fmt,...)
  66. {
  67.   char buf[256];
  68.   va_list ap;
  69.  
  70.   va_start (ap, fmt);
  71.   vsprintf (buf, fmt, ap);
  72.   va_end (ap);
  73.   Write (tty, buf, strlen(buf));
  74. }
  75.  
  76. void putccon (char ch)
  77. {
  78.   char c = ch;
  79.  
  80.   Write (tty, &c, 1);
  81. }
  82.  
  83. int getccon (void)
  84. {
  85.   unsigned char ch;
  86.  
  87.   Read(tty, &ch,1L);
  88.   return ((int)ch);
  89. }
  90.  
  91. #undef GLOBAL
  92. /* my version of BADDR() has no problems with casting */
  93. #undef  BADDR
  94. #define BADDR(x)        ((APTR)((long)x << 2))
  95. #define MKBADDR(x)      ((BPTR)((long)x >> 2))
  96.  
  97. /* This subroutine does the work of turning the current console to raw  */
  98. /* Pass a zero to turn it to cooked mode, any other value to turn it    */
  99. /* to raw mode.                                                         */
  100. long rawmode (int flag)
  101. {
  102.   long myargs[8];
  103.   struct Process *proc;
  104.  
  105.   myargs[0] = flag ? DOSTRUE : DOSFALSE;
  106.  
  107.   proc = (struct Process *) FindTask (0L);
  108.   return (sendpkt ((struct MsgPort *) proc->pr_ConsoleTask,
  109.            ACTION_SCREEN_MODE, myargs, 1));
  110. }
  111.  
  112. LONG sendpkt (struct MsgPort *pid, LONG action, LONG args[], LONG nargs)
  113. {
  114.   struct MsgPort *replyport;
  115.   struct StandardPacket *packet;
  116.  
  117.   LONG count, *pargs, res1;
  118.  
  119.   replyport = (struct MsgPort *) CreatePort (NULL, 0);
  120.   if (!replyport)
  121.     return (NULL);
  122.  
  123.   packet = (struct StandardPacket *)
  124.     AllocMem ((long) sizeof (struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR);
  125.   if (!packet)
  126.     {
  127.       DeletePort (replyport);
  128.       return (NULL);
  129.     }
  130.   packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt);
  131.   packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
  132.   packet->sp_Pkt.dp_Port = replyport;
  133.   packet->sp_Pkt.dp_Type = action;
  134.  
  135.   /* copy the args into the packet */
  136.   pargs = &(packet->sp_Pkt.dp_Arg1);    /* address of first argument */
  137.   for (count = 0; count < nargs; count++)
  138.     pargs[count] = args[count];
  139.  
  140.   PutMsg (pid, (struct Message *) packet);    /* send packet */
  141.  
  142.   WaitPort (replyport);
  143.   GetMsg (replyport);
  144.  
  145.   res1 = packet->sp_Pkt.dp_Res1;
  146.  
  147.   FreeMem ((char *) packet, (long) sizeof (struct StandardPacket));
  148.   DeletePort (replyport);
  149.  
  150.   return (res1);
  151. }
  152.  
  153. /* open a console window for ISpell */
  154. void terminit (void)
  155. {
  156.   tty = Open("*", MODE_OLDFILE);
  157.   rawmode(1);
  158.   li = 23;
  159.   co = 77;
  160. }
  161.  
  162. void done (void)
  163. {
  164.   remove (tempfile);
  165.   Close(tty);
  166.   rawmode(0);
  167.   exit (0);
  168. }
  169.  
  170. /* clear the screen */
  171. void erase (void)
  172. {
  173.   Write (tty, "\x0c", 1);
  174. }
  175.  
  176. /* move to row, col */
  177. void move (int row, int col)
  178. {
  179.   char buf[16];
  180.  
  181.   sprintf (buf, "\x9b%d\x3b%d\x48", row, col);
  182.   Write (tty, buf, strlen(buf));
  183. }
  184.  
  185. /* do stand out mode */
  186. void inverse (void)
  187. {
  188.   SETCOLORS (BLUE_ON_WHITE);
  189. }
  190.  
  191. /* do stand end mode */
  192. void normal (void)
  193. {
  194.   SETCOLORS (WHITE_ON_BLUE);
  195. }
  196.  
  197. /* do a back space */
  198. void backup (void)
  199. {
  200.   putccon ('\b');
  201. }
  202.  
  203. /* not implemented on the amiga */
  204. void onstop (int signo)
  205. {
  206. }
  207.  
  208. void stop (void)
  209. {
  210. }
  211.  
  212. /*
  213.  * i really do not understand why sleep is used in Ispell. Here is a null
  214.  * function used soley to keep ispell happy.
  215.  */
  216. /* i do.  fixed.  -tgr */
  217. void sleep (int n)
  218. {
  219.   if (n > 0)
  220.     Delay (50L * n);
  221. }
  222.  
  223. /*
  224.  * This function is broken in SAS/C v5.10 - LJR 
  225.  * Thanks to Matt Dillon, as this was lifted from DICE. 
  226.  */
  227. char *tmpnam(char *buf)
  228. {
  229.     static char Buf[32];
  230.     static long i;
  231.  
  232.     if (buf == NULL)
  233.     buf = Buf;
  234.     sprintf(buf, "T:%08lx-%ld", FindTask(NULL), i++);
  235.     return(buf);
  236. }
  237.