home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / wp_dtp / xdme1821.lha / XDME / subs.c < prev    next >
C/C++ Source or Header  |  1993-04-04  |  17KB  |  862 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     subs.c
  5.  
  6.     DESCRIPTION
  7.     General subroutines.
  8.  
  9.     NOTES
  10.  
  11.     BUGS
  12.  
  13.     TODO
  14.  
  15.     EXAMPLES
  16.  
  17.     SEE ALSO
  18.  
  19.     INDEX
  20.  
  21.     HISTORY
  22.     16. Jan 1993    ada created
  23.  
  24. ******************************************************************************/
  25.  
  26. /**************************************
  27.         Includes
  28. **************************************/
  29. #include "defs.h"
  30. #include <clib/macros.h>
  31. #include <graphics/display.h>
  32. #define MYDEBUG     0
  33. #include "debug.h"
  34.  
  35.  
  36. /**************************************
  37.         Globale Variable
  38. **************************************/
  39. Prototype void      makemygadget      (struct Gadget *);
  40. Prototype int      firstns      (char *);
  41. Prototype int      lastns      (char *);
  42. Prototype int      wordlen      (char *);
  43. Prototype BOOL      getpathto      (BPTR, char *, char *);
  44. Prototype LINE      allocline      (long);
  45. Prototype int      detab       (char *, char *, int);
  46. Prototype int      xefgets      (FILE *, char *, int);
  47. Prototype ED    * finded      (char *, int);
  48. Prototype void      mountrequest      (int);
  49. Prototype FONT    * GetFont      (char *, short);
  50. Prototype void      freeline      (LINE);
  51. Prototype void      movetocursor      (void);
  52. Prototype int      extend      (ED *, int);
  53. Prototype int      makeroom      (int);
  54. Prototype void      freelist      (LINE *, int);
  55. Prototype long      lineflags      (int);
  56. Prototype void      scroll_display  (short, short, Column, Line, Column, Line);
  57. Prototype char    * skip_whitespace (char *);
  58. Prototype char      is_number      (char *);
  59. Prototype char    * getnextcomline  (FILE *, int *);
  60. Prototype char    * fname       (char *);
  61. Prototype BOOL      switch_ed      (ED *);
  62. Prototype void      do_makecursorvisible (void);
  63. Prototype void      MakeRectVisible (WIN *, USHORT, USHORT, USHORT, USHORT);
  64. Prototype LINE      GETLINE      (ED *, Line);
  65. Prototype void      SETLINE      (ED *, LINE, Line);
  66. Prototype int      LENGTH      (LINE);
  67. Prototype UBYTE * GETCONTENTS      (LINE);
  68. Prototype BOOL      SETCONTENTS      (LINE, UBYTE *);
  69. Prototype int      LINELEN      (ED *, Line);
  70.  
  71. /* Assembler */
  72. Prototype void swapmem (void *, void *, ULONG);
  73.  
  74.  
  75. /**************************************
  76.       Interne Defines & Strukturen
  77. **************************************/
  78. typedef struct FileInfoBlock FIB;
  79.  
  80.  
  81. /**************************************
  82.         Interne Variable
  83. **************************************/
  84.  
  85.  
  86. /**************************************
  87.        Interne Prototypes
  88. **************************************/
  89.  
  90.  
  91. /*
  92.  *  Create XDME's text icon.
  93.  */
  94.  
  95. void makemygadget (struct Gadget *gad)
  96. {
  97.     const static unsigned short ga[] =
  98.     {
  99.      /* Plane 0 */
  100.      0x0000,0x0000,0x0000,0x0400,0x0000,0x0000,0x0000,0x0C00,
  101.      0x0000,0x0000,0x0000,0x0C00,0x0FFF,0xFFFF,0xFFFF,0x8C00,
  102.      0x0C00,0x0000,0x0000,0x0C00,0x0C1F,0xFFFF,0xFFE0,0x0C00,
  103.      0x0C17,0xFFFF,0xFFA0,0x0C00,0x0C1E,0x08BF,0xFFE0,0x0C00,
  104.      0x0C17,0xFFFF,0xFFA0,0x0C00,0x0C1F,0x25FF,0xFFE0,0x0C00,
  105.      0x0C17,0xFFFF,0xFFA0,0x0C00,0x0C1F,0x0BFF,0xFFE0,0x0C00,
  106.      0x0C17,0xFFFF,0xFFA0,0x0C00,0x0C1E,0x1FFF,0xFFE0,0x0C00,
  107.      0x0C16,0xFFFF,0xFFA0,0x0C00,0x0C1E,0x7FFF,0xFFE0,0x0C00,
  108.      0x0C17,0xFFFF,0xFFA0,0x0C00,0x0800,0x0000,0x0000,0x0C00,
  109.      0x0000,0x0000,0x0000,0x0C00,0x007B,0xFF9E,0x7FF8,0x0C00,
  110.      0x0031,0x98CE,0x7318,0x0C00,0x001B,0x186F,0xF318,0x0C00,
  111.      0x001B,0x186F,0xF360,0x0C00,0x000E,0x186D,0xB3E0,0x0C00,
  112.      0x001B,0x186D,0xB360,0x0C00,0x001B,0x186C,0x3318,0x0C00,
  113.      0x0031,0x98CC,0x3318,0x0C00,0x007B,0xFF9E,0x7FF8,0x0C00,
  114.      0x0000,0x0000,0x0000,0x0C00,0x7FFF,0xFFFF,0xFFFF,0xFC00,
  115.      /* Plane 1 */
  116.      0xFFFF,0xFFFF,0xFFFF,0xF800,0xD555,0x5555,0x5555,0x5000,
  117.      0xD555,0x5555,0x5555,0x5000,0xD000,0x0000,0x0000,0x5000,
  118.      0xD000,0x0000,0x0000,0xD000,0xD000,0x0000,0x0000,0xD000,
  119.      0xD003,0xFFFF,0xFF00,0xD000,0xD003,0xFFFF,0xFF00,0xD000,
  120.      0xD003,0xFFFF,0xFF00,0xD000,0xD003,0xFFFF,0xFF00,0xD000,
  121.      0xD003,0xFFFF,0xFF00,0xD000,0xD003,0xFFFF,0xFF00,0xD000,
  122.      0xD003,0xFFFF,0xFF00,0xD000,0xD003,0xFFFF,0xFF00,0xD000,
  123.      0xD003,0xFFFF,0xFF00,0xD000,0xD003,0xFFFF,0xFF00,0xD000,
  124.      0xD003,0xFFFF,0xFF00,0xD000,0xD7FF,0xFFFF,0xFFFF,0xD000,
  125.      0xD555,0x5555,0x5555,0x5000,0xD504,0x0041,0x0005,0x5000,
  126.      0xD544,0x4511,0x0445,0x5000,0xD544,0x4510,0x0445,0x5000,
  127.      0xD544,0x4510,0x0415,0x5000,0xD551,0x4510,0x4415,0x5000,
  128.      0xD544,0x4510,0x4415,0x5000,0xD544,0x4511,0x4445,0x5000,
  129.      0xD544,0x4511,0x4445,0x5000,0xD504,0x0041,0x0005,0x5000,
  130.      0xD555,0x5555,0x5555,0x5000,0x8000,0x0000,0x0000,0x0000
  131.     };
  132.     const static struct Image image =
  133.     {
  134.      0, 0, 54, 30, 2, (unsigned short *)ga, 3, 0, NULL
  135.     };
  136.  
  137.     clrmem (gad, sizeof(struct Gadget));
  138.  
  139.     gad->Width          = 54;
  140.     gad->Height       = 31; /* Blank line between Image and Text ! */
  141.     gad->Flags          = GADGIMAGE|GADGHCOMP;
  142.     gad->GadgetType   = BOOLGADGET;
  143.     gad->Activation   = RELVERIFY|GADGIMMEDIATE;
  144.     gad->GadgetRender = (APTR)ℑ
  145. } /* makemygadget */
  146.  
  147.  
  148. /*
  149.  * return index of first non space.  Returns 0 if no spaces found.
  150.  */
  151.  
  152. int firstns (char * str)
  153. {
  154.     short i;
  155.  
  156.     for (i = 0; str[i] && str[i] == ' '; i ++);
  157.  
  158.     if (str[i] == 0)
  159.     i = 0;
  160.  
  161.     return (i);
  162. } /* firstns */
  163.  
  164.  
  165. /*
  166.  *  Return index of last non-space, 0 if no spaces.
  167.  */
  168.  
  169. int lastns (char * str)
  170. {
  171.     short i;
  172.  
  173.     /* get last char of string (i might be -1 after that !).
  174.        now walk left until a char != ' ' is found or i == 0. */
  175.     for (i = strlen(str) - 1; i > 0 && str[i] == ' '; i --);
  176.  
  177.     if (i < 0)  /* string empty */
  178.     i = 0;
  179.  
  180.     return (i);
  181. } /* lastns */
  182.  
  183.  
  184. /*
  185.  *  Return length of word under cursor
  186.  */
  187.  
  188. int wordlen (char * str)
  189. {
  190.     short i;
  191.  
  192.     for (i = 0; *str && *str != ' '; ++i, ++str);
  193.  
  194.     return(i);
  195. } /* wordlen */
  196.  
  197.  
  198. /*
  199.  *  Backtracks the program lock, 0 on failure, 1 on success.
  200.  *  The filename is appended to the lock, if it exists.
  201.  */
  202.  
  203. BOOL getpathto (BPTR lock, char * filename, char * buf)
  204. {
  205.     if (!NameFromLock (lock, buf, PATHSIZE))
  206.     return (FALSE);
  207.  
  208.     if (filename)
  209.     AddPart (buf, filename, PATHSIZE);
  210.  
  211.     return (TRUE);
  212. } /* getpathto */
  213.  
  214.  
  215. /*
  216.  *  Allocation routines and other shortcuts
  217.  */
  218.  
  219. static LINE empty_line;
  220.  
  221. __autoinit void init_empty_line (void)
  222. {
  223.     if (empty_line.text = AllocateArray (1,1))
  224.     WriteElements (empty_line, "", 0, 1);
  225. }
  226.  
  227.  
  228. LINE allocline (long size)
  229. {
  230.     LINE line;
  231.  
  232.     if (size <= 1)
  233.     return (empty_line);     /* no more tiny empty blocks */
  234.  
  235.     if (!(line.text = AllocateArray (1, size)) )
  236.     return (NULL);
  237.  
  238.     return (line);
  239. } /* allocline */
  240.  
  241.  
  242. void freeline (LINE line)
  243. {
  244.     if (line && line != empty_line)
  245.     FreeArray (line.text);
  246. } /* freeline */
  247.  
  248.  
  249. /*
  250.  *  Remove tabs in a buffer
  251.  */
  252.  
  253. int detab (char * ibuf, char * obuf, int maxlen)
  254. {
  255.     short i, j;
  256.  
  257.     maxlen -= 1;
  258.  
  259.     for (i = j = 0; ibuf[i] && j < maxlen; ++i)
  260.     {
  261.     if (ibuf[i] == 9)
  262.     {
  263.         do
  264.         {
  265.         obuf[j++] = ' ';
  266.         } while ((j & 7) && j < maxlen);
  267.     } else
  268.     {
  269.         obuf[j++] = ibuf[i];
  270.     }
  271.     }
  272.  
  273.     if (j && obuf[j-1] == '\n')
  274.     --j;
  275.  
  276.     while (j && obuf[j-1] == ' ')
  277.     --j;
  278.  
  279.     obuf[j] = 0;
  280.  
  281.     return (j);
  282. } /* detab */
  283.  
  284.  
  285. int xefgets (FILE * fi, char * buf, int max)
  286. {
  287.     char ebuf[MAXLINELEN];
  288.  
  289.     if (fgets (ebuf, max, fi))
  290.     return (detab (ebuf, buf, max));
  291.  
  292.     return (-1);
  293. } /* xefgets */
  294.  
  295.  
  296. ED * finded (char * str, int doff)
  297.  
  298. {
  299.     ED *ed;
  300.  
  301.     for (ed = (ED *)GetHead(&DBase); ed; ed=(ED *)GetSucc((struct Node *)ed))
  302.     {
  303.     if (strlen (ed->name) >= doff && stricmp (str, ed->name+doff) == 0)
  304.         return (ed);
  305.     }
  306.  
  307.     return (NULL);
  308. } /* finded */
  309.  
  310.  
  311. void mountrequest (int bool)
  312. {
  313.     static APTR     original_pr_WindowPtr = NULL;
  314.     register PROC * proc;
  315.  
  316.     proc = (PROC *)FindTask (0);
  317.  
  318.     if (!bool && proc->pr_WindowPtr != (APTR)-1)
  319.     {
  320.     original_pr_WindowPtr = proc->pr_WindowPtr;
  321.     proc->pr_WindowPtr    = (APTR)-1;
  322.     }
  323.  
  324.     if (bool && proc->pr_WindowPtr == (APTR)-1)
  325.     proc->pr_WindowPtr = original_pr_WindowPtr;
  326. } /* mountrequest */
  327.  
  328.  
  329. /*
  330.  *  GETFONT()
  331.  *
  332.  *  This function properly searches resident and disk fonts for the
  333.  *  font.
  334.  */
  335.  
  336. struct Library * DiskfontBase;
  337.  
  338. FONT * GetFont (char * name, short size)
  339. {
  340.     FONT * font1;
  341.     TA       Ta;
  342.     USHORT pos;
  343.  
  344.     strcpy (tmp_buffer, name);
  345.     pos = strlen (tmp_buffer);
  346.  
  347.     if (pos < 6 || (pos > 5 && stricmp (tmp_buffer + pos - 5, ".font")))
  348.     strcpy (tmp_buffer + pos, ".font");
  349.  
  350.     Ta.ta_Name    = (UBYTE *)tmp_buffer;
  351.     Ta.ta_YSize = size;
  352.     Ta.ta_Style = 0;
  353.     Ta.ta_Flags = 0;
  354.  
  355.     font1 = OpenFont (&Ta);
  356.  
  357.     if (!font1 || font1->tf_YSize != Ta.ta_YSize)
  358.     {
  359.     FONT * font2;
  360.  
  361.     if (DiskfontBase = OpenLibrary ("diskfont.library", 0L))
  362.     {
  363.         if (font2 = OpenDiskFont (&Ta))
  364.         {
  365.         if (font1)
  366.             CloseFont (font1);
  367.  
  368.         font1 = font2;
  369.  
  370.         CloseLibrary (DiskfontBase);
  371.         }
  372.     }
  373.     } /* if !font1 || Wrong_Font_Size */
  374.  
  375.     return (font1);
  376. } /* GetFont */
  377.  
  378.  
  379. void movetocursor (void)
  380. {
  381.     Move (Ep->win->RPort, COLT(Ep->column - Ep->topcolumn),
  382.       ROWT(Ep->line - Ep->topline));
  383. } /* movetocursor */
  384.  
  385.  
  386. int extend (ED * ep, int lines)
  387. {
  388.     long   extra = ep->maxlines - ep->lines;
  389.     LINE * list;
  390.  
  391.     if (lines > extra)
  392.     {
  393.     lines += ep->lines;
  394.  
  395.     if (list = (LINE *)alloclptr(lines))
  396.     {
  397.         bmovl (ep->list, list, ep->lines);
  398.         FreeMem (ep->list, sizeof(LINE) * ep->maxlines);
  399.  
  400.         ep->maxlines = lines;
  401.         ep->list     = list;
  402.  
  403.         return (1);
  404.     }
  405.  
  406.     nomemory ();
  407.     return (0);
  408.     }
  409.  
  410.     return (1);
  411. } /* extend */
  412.  
  413.  
  414. int makeroom (int n)
  415. {
  416.     ED * ep = Ep;
  417.  
  418.     if (ep->lines >= ep->maxlines)
  419.     return (extend (ep, n));
  420.  
  421.     return (1);
  422. } /* makeroom */
  423.  
  424.  
  425. void freelist (LINE * list, int n)
  426. {
  427.     while (n)
  428.     {
  429.     freeline (list[0]);
  430.     list ++;
  431.     n --;
  432.     }
  433. } /* freelist */
  434.  
  435.  
  436. void do_undo (void)
  437. {
  438.     text_load ();
  439.     text_redisplaycurrline ();
  440. } /* do_undo */
  441.  
  442.  
  443. long lineflags (int line)
  444. {
  445.     long flags;
  446.  
  447.     if (line < Ep->topline)
  448.     flags = LINE_ABOVE;
  449.     else if (line < Ep->topline + Lines)
  450.     flags = LINE_VISIBLE;
  451.     else
  452.     flags = LINE_BELOW;
  453.  
  454.     return (flags);
  455. } /* lineflags */
  456.  
  457.  
  458. void scroll_display (short dx, short dy, Column lc, Line tl, Column rc, Line bl)
  459. {
  460.     USHORT width, height;
  461.     Line lines, rest;
  462.     USHORT x1, y1, x2, y2, t;
  463.     Line bottom;
  464.     Column right;
  465.     RP * rp;
  466.  
  467.     /* don't do anything if we are not allowed */
  468.     if (Ep->iconmode || Nsu || (!dx && !dy)) return;
  469.  
  470.     /* clip coords */
  471.     if (tl < Ep->topline)
  472.     tl = Ep->topline;
  473.  
  474.     if (bl >= Ep->topline+Lines)
  475.     bl = Ep->topline + Lines - 1;
  476.  
  477.     if (lc < Ep->topcolumn)
  478.     lc = Ep->topcolumn;
  479.  
  480.     if (rc >= Ep->topcolumn+Columns)
  481.     rc = Ep->topcolumn + Columns - 1;
  482.  
  483.     /* check if area is visible */
  484.     if (bl < tl || rc < lc) return;
  485.  
  486.     /* is there something below the text */
  487.     if (bl > Ep->lines)
  488.     {
  489.     bottom = bl - Ep->lines + 1;
  490.     } else
  491.     {
  492.     bottom = 0;
  493.     }
  494.  
  495.     /* is there something to the right */
  496.     if (rc > MAXLINELEN)
  497.     {
  498.     right = rc - MAXLINELEN + 1;
  499.     } else
  500.     {
  501.     right = 0;
  502.     }
  503.  
  504.     /* get size of real text */
  505.     width  = rc - lc + 1 - right;
  506.     height = bl - tl + 1 - bottom;
  507.  
  508.     if (dx)
  509.     {
  510.     lines = ABS(dx);    /* number of columns to draw */
  511.  
  512.     if (lines >= width)
  513.          rest = 0;
  514.     else rest = width - lines;
  515.  
  516.     dx *= Xsize;
  517.     } else
  518.     {
  519.     lines = ABS(dy);    /* number of lines to draw */
  520.  
  521.     /* if the number of new lines is bigger than the height of the
  522.        remaining text, we have to erase the empty lines. Otherwise
  523.        we store the first line of the area that is to update in rest. */
  524.  
  525.     if (lines >= height)
  526.          rest = 0;
  527.     else rest = height - lines;
  528.  
  529.     dy *= Ysize;
  530.     }
  531.  
  532.     x1 = lc - Ep->topcolumn;
  533.     x2 = rc - Ep->topcolumn;
  534.     y1 = tl - Ep->topline;
  535.     y2 = bl - Ep->topline;
  536.  
  537.     t = y1;
  538.  
  539.     x1 = COL(x1);
  540.     x2 = COL(x2+1)-1;
  541.     y1 = ROW(y1);
  542.     y2 = ROW(y2+1)-1;
  543.  
  544.     rp = Ep->win->RPort;
  545.  
  546. #ifdef MYDEBUG
  547.     D(bug("scroll_display: rest %ld  height %ld  lines %ld  t %ld (%ld,%ld)-(%ld,%ld)\n",
  548.       rest, height, lines, t, x1, y1, x2, y2));
  549. #endif
  550.  
  551.     SetWrMsk (rp, -1);
  552.     SetBPen (rp, TEXT_BPEN);
  553.  
  554.     if (rest)
  555.     {
  556.     ScrollRaster (rp, dx, dy, x1, y1, x2, y2);
  557.  
  558.     if (dx)
  559.     {
  560.         Line   line;
  561.         Column col;
  562.  
  563.         line = tl;
  564.         col  = lc;
  565.  
  566.         if (dx > 0)
  567.         col += rest;
  568.  
  569.         redraw_block (TRUE, line, col, line + height, col + lines - 1);
  570.     } else
  571.     {
  572.         if (dy < 0)
  573.         {
  574.         text_displayseg (t, lines);
  575.         } else
  576.         {
  577.         text_displayseg (t+rest, lines);
  578.         }
  579.     }
  580.     } else
  581.     {
  582.     SetAPen (rp, TEXT_BPEN);
  583.     RectFill (rp, x1, y1, x2, y2);
  584.  
  585.     text_displayseg (t, height);
  586.     }
  587. } /* scroll_display */
  588.  
  589.  
  590. char * skip_whitespace (char * ptr)
  591. {
  592.     while (isspace (*ptr)) ptr ++;
  593.  
  594.     return (ptr);
  595. } /* skip_whitespace */
  596.  
  597.  
  598. /*
  599.  *  IS_NUMBER
  600.  *  tests if a string represents a valid number, i.e.
  601.  *  if there are only numbers in it ( what about spaces around,
  602.  *  and + before a number, do they disturb atol??? )
  603.  */
  604.  
  605. char is_number (char * str)           /* represents a string a number? */
  606. {
  607.     while (*str==' ')           /* ignore leading spaces */
  608.     {
  609.     str++;
  610.     } /* while */
  611.  
  612.     if ((*str=='-')||(*str=='+'))  /* dont worry about +/- */
  613.     {
  614.     str++;
  615.     } /* if */
  616.  
  617.     while (isdigit(*str))     /* if there are only numbers in str: ok */
  618.     {
  619.     str++;
  620.     } /* while */
  621.  
  622.     while (*str==' ')          /* ignore ending spaces */
  623.     {
  624.     str++;
  625.     } /* while */
  626.  
  627.     return (!*str);
  628. } /* is_number */
  629.  
  630.  
  631. char * getnextcomline (FILE* fi, int * lineno)
  632. {
  633.     /* skipps comments and emptylines */
  634.     char* buf;
  635.     char* ptr;
  636.     do
  637.     {
  638.     if (lineno)
  639.     {
  640.         (*lineno)++; /* Welches hat Priortaet?? */
  641.     } /* if */
  642.  
  643.     buf = tmp_buffer;
  644.     if ((xefgets(fi, tmp_buffer, LINE_LENGTH))<0)
  645.     /* buf = fgets(tmp_buffer, LINE_LENGTH, fi); */
  646.     if (!buf)
  647.     {
  648.         error ("%s:\nUnexpected End Of File Encountered", av[0]);
  649.         return(NULL);
  650.     } /* if */
  651.     buf[255] = 0; /* marker for eol */
  652.     while (*buf<33 && *buf)
  653.     {
  654.         buf++;
  655.     } /* while */
  656.     } while (buf[0] == 0 || buf[0] == '#');
  657.     for (ptr = buf; *ptr;ptr++)
  658.     {
  659.     if (*ptr == 10)
  660.     {
  661.         *ptr = 0;
  662.     } /* if */
  663.     } /* for */
  664.     return(buf);
  665. } /* getnextcomline */
  666.  
  667.  
  668. /*
  669.  *  fname
  670.  *
  671.  *  instead of a macro: sets a ptr to the filename of a full path&filename
  672.  *  (returniert einen Zeiger auf den namensteil eines pfades)
  673.  *
  674.  * SHOULD BE PUT INTO SUBS.C
  675.  */
  676.  
  677. char * fname (char * fullpath)
  678. {
  679.     return (FilePart (fullpath));
  680. } /* fname */
  681.  
  682.  
  683. BOOL switch_ed (ED * newed)
  684. {
  685.     BOOL success;
  686.  
  687.     if (newed)
  688.     {
  689.     if (Ep)
  690.         text_sync ();
  691.  
  692.     Ep = newed;
  693.  
  694.     text_load ();
  695.  
  696.     if (!Ep->iconmode)
  697.     {
  698.         set_window_params ();
  699.         window_title ();
  700.     }
  701.  
  702.     text_cursor (1);
  703.  
  704.     success = TRUE;
  705.     } else
  706.     success = FALSE;
  707.  
  708.     return (success);
  709. } /* switch_ed */
  710.  
  711.  
  712. void do_makecursorvisible (void)
  713. {
  714.     if ((Ep->win->Flags & WFLG_WINDOWACTIVE) && !Ep->iconmode)
  715.     {
  716.     USHORT x1 = COL(Ep->column - Ep->topcolumn) + Ep->win->LeftEdge;
  717.     USHORT y1 = ROW(Ep->line   - Ep->topline)   + Ep->win->TopEdge;
  718.     USHORT x2, y2;
  719.  
  720.     x2 = x1 + (Xsize << 2) + Xsize;
  721.     y2 = y1 + (Ysize << 2) + Ysize;
  722.  
  723.     if (x1 < (Xsize << 2))
  724.         x1 = 0;
  725.     else
  726.         x1 -= Xsize << 2;
  727.  
  728.     if (y1 < (Ysize << 2))
  729.         y1 = 0;
  730.     else
  731.         y1 -= Ysize << 2;
  732.  
  733.     MakeRectVisible (Ep->win, x1, y1, x2, y2);
  734.     }
  735. } /* do_makecursorvisible */
  736.  
  737.  
  738. void MakeRectVisible (WIN * win, USHORT minx, USHORT miny, USHORT maxx,
  739.                                    USHORT maxy)
  740. {
  741.     struct DimensionInfo diminfo;
  742.     struct Screen      * screen        = win->WScreen;
  743.     ULONG         Width, Height;
  744.     WORD         dx, dy;
  745.  
  746.     GetDisplayInfoData (NULL,
  747.             (UBYTE *)&diminfo,
  748.             sizeof(diminfo),
  749.             DTAG_DIMS,
  750.             GetVPModeID (&screen->ViewPort)
  751.     );
  752.  
  753.     Width  = diminfo.TxtOScan.MaxX - diminfo.TxtOScan.MinX;
  754.     Height = diminfo.TxtOScan.MaxY - diminfo.TxtOScan.MinY;
  755.  
  756.     if (Width > screen->Width)
  757.     Width = screen->Width;
  758.  
  759.     if (Height > screen->Height)
  760.     Height = screen->Height;
  761.  
  762.     if (minx < win->LeftEdge)
  763.     minx = win->LeftEdge;
  764.  
  765.     if (miny < win->TopEdge)
  766.     miny = win->TopEdge;
  767.  
  768.     if (maxx > win->LeftEdge + win->Width)
  769.     maxx = win->LeftEdge + win->Width;
  770.  
  771.     if (maxy > win->TopEdge + win->Height)
  772.     maxy = win->TopEdge + win->Height;
  773.  
  774.     dx = (Width - screen->LeftEdge) - maxx + 1;
  775.  
  776.     if (dx > 0)
  777.     {
  778.     dx = minx + screen->LeftEdge;
  779.  
  780.     if (dx > 0)
  781.         dx = 0;
  782.     else
  783.         dx = -dx;
  784.     }
  785.  
  786.     dy = (Height - screen->TopEdge) - maxy + 1;
  787.  
  788.     if (dy > 0)
  789.     {
  790.     dy = miny + screen->TopEdge;
  791.  
  792.     if (dy >= 0)
  793.         dy = 0;
  794.     else
  795.         dy = -dy;
  796.     }
  797.  
  798.     MoveScreen (screen, dx, dy);
  799. } /* MakeRectVisible */
  800.  
  801.  
  802. LINE GETLINE (ED * ep, Line nr)
  803. {
  804.     LINE line;
  805.  
  806.     ReadElements (ep->linearray, &line, nr, 1);
  807.  
  808.     return (line);
  809. } /* GETLINE */
  810.  
  811.  
  812. void SETLINE (ED * ep, LINE line, Line nr)
  813. {
  814.     WriteElements (ep->linearray, &line, nr, 1);
  815. } /* SETLINE */
  816.  
  817.  
  818. int LENGTH (LINE line)
  819. {
  820.     return (SizeofArray (line.text));
  821. } /* LENGTH */
  822.  
  823.  
  824. UBYTE * GETCONTENTS (LINE line)
  825. {
  826.     return (AddressOfElement (line.text, 0));
  827. } /* GETCONTENTS */
  828.  
  829.  
  830. BOOL SETCONTENTS (LINE line, UBYTE * new_contents)
  831. {
  832.     /* Empty old array */
  833.     SetArrayTags (line.text, AR_NumElements, 0);
  834.  
  835.     return (WriteElements (line.text, new_contents, 0, ~1));
  836. } /* SETCONTENTS */
  837.  
  838.  
  839. int Clen (void)
  840. {
  841.     int     len = SizeofArray (Current.text);
  842.     UBYTE * ptr;
  843.  
  844.     ptr = AddressOfElement (Current.text, len);
  845. } /* Clen */
  846.  
  847.  
  848. int LINELEN (ED * ep, Line nr)
  849. {
  850.     if (nr == ep->line)
  851.     {
  852.     return (Clen ());
  853.     }
  854.  
  855.     return (LENGTH (GETLINE(ep,nr)));
  856. } /* LINELEN */
  857.  
  858.  
  859. /******************************************************************************
  860. *****  ENDE subs.c
  861. ******************************************************************************/
  862.