home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / the25.zip / thesrc251.zip / util.c < prev    next >
C/C++ Source or Header  |  1998-07-28  |  79KB  |  2,577 lines

  1. /***********************************************************************/
  2. /* UTIL.C - Utility routines                                           */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1997 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                 Email:             M.Hessling@qut.edu.au
  33.  * PO Box 203                    Phone:                    +617 3802 0800
  34.  * Bellara                       http://www.gu.edu.au/gext/the/markh.html
  35.  * QLD 4507                      **** Maintainer PDCurses & REXX/SQL ****
  36.  * Australia                     ************* Author of THE ************
  37.  */
  38.  
  39. /*
  40. $Id: util.c 2.1 1995/06/24 16:31:38 MH Rel MH $
  41. */
  42.  
  43. #include <the.h>
  44. #include <proto.h>
  45.  
  46. /*--------------------------- common data -----------------------------*/
  47.  static CHARTYPE *rcvry[MAX_RECV];
  48.  static LENGTHTYPE rcvry_len[MAX_RECV];
  49.  static short add_rcvry=(-1);
  50.  static short retr_rcvry=(-1);
  51.  static short num_rcvry=0;
  52.  
  53. #ifdef USE_EXTCURSES
  54.  chtype color_pair[COLOR_PAIRS];
  55.  static chtype fore_color[8];
  56.  static chtype back_color[8];
  57. #endif
  58.  
  59. /*man***************************************************************************
  60. NAME
  61.      memreveq - search buffer reversed for character
  62.  
  63. SYNOPSIS
  64.      short memreveq(buffer,chr,max_length)
  65.      CHARTYPE *buffer;
  66.      CHARTYPE ch;
  67.      short max_length;
  68.  
  69. DESCRIPTION
  70.      The memreveq function searches the buffer from the right for the
  71.      first character equal to the supplied character.
  72.  
  73. RETURN VALUE
  74.      If successful, returns the position of first matching character
  75.      or (-1) if unsuccessful.
  76.  
  77. SEE ALSO
  78.      strzreveq, memrevne
  79. *******************************************************************************/
  80. #ifdef HAVE_PROTO
  81. short memreveq(CHARTYPE *buffer,CHARTYPE ch,short max_len)
  82. #else
  83. short memreveq(buffer,ch,max_len)
  84. CHARTYPE *buffer,ch;
  85. short max_len;
  86. #endif
  87. /***********************************************************************/
  88. {
  89. /*--------------------------- local data ------------------------------*/
  90.  register short len=max_len;
  91. /*--------------------------- processing ------------------------------*/
  92.  for (--len; len>=0 && buffer[len]!=ch; len--);
  93.  return(len);
  94. }
  95. /*man***************************************************************************
  96. NAME
  97.      memrevne - search buffer reversed for NOT character
  98.  
  99. SYNOPSIS
  100.      short memrevne(buffer,known_char,max_len)
  101.      CHARTYPE *buffer;
  102.      CHARTYPE known_char;
  103.      short max_len;
  104.  
  105. DESCRIPTION
  106.      The memrevne function searches the buffer from the right for first
  107.      character NOT equal to the supplied character.
  108.  
  109. RETURN VALUE
  110.      If successful, returns the position of first NON-matching character
  111.      or (-1) if unsuccessful.
  112.  
  113. SEE ALSO
  114.      strzrevne, strzne
  115. *******************************************************************************/
  116. #ifdef HAVE_PROTO
  117. short memrevne(CHARTYPE *buffer,CHARTYPE known_char,short max_len)
  118. #else
  119. short memrevne(buffer,known_char,max_len)
  120. CHARTYPE *buffer;
  121. CHARTYPE known_char;
  122. short max_len;
  123. #endif
  124. {
  125. /*--------------------------- local data ------------------------------*/
  126.  register short len=max_len;
  127. /*--------------------------- processing ------------------------------*/
  128.  for (--len; len>=0 && buffer[len]==known_char; len--);
  129.  return(len);
  130. }
  131. /*man***************************************************************************
  132. NAME
  133.      meminschr - insert character into buffer
  134.  
  135. SYNOPSIS
  136.      CHARTYPE *meminschr(buffer,chr,location,max_length,curr_length)
  137.      CHARTYPE *buffer;
  138.      CHARTYPE chr;
  139.      short location,max_length,curr_length;
  140.  
  141. DESCRIPTION
  142.      The meminschr inserts the supplied 'chr' into the buffer 'buffer'
  143.      before the 'location' specified. 'location' is an offset (0 based)
  144.      from the start of 'buffer'.
  145.      The 'buffer' will not be allowed to have more than 'max_length'
  146.      characters, so if the insertion of the character causes the
  147.      'max_length' to be exceeded, the last character of 'buffer' will
  148.      be lost.
  149.  
  150. RETURN VALUE
  151.      A pointer to the same 'buffer' as was supplied.
  152.  
  153. SEE ALSO
  154.     meminsstr, memdeln
  155.  
  156. *******************************************************************************/
  157. #ifdef HAVE_PROTO
  158. CHARTYPE *meminschr(CHARTYPE *buffer,CHARTYPE chr,short location,
  159.                 short max_length,short curr_length)
  160. #else
  161. CHARTYPE *meminschr(buffer,chr,location,max_length,curr_length)
  162. CHARTYPE *buffer;
  163. CHARTYPE chr;
  164. short location,max_length,curr_length;
  165. #endif
  166. {
  167. /*--------------------------- local data ------------------------------*/
  168.  register short i=0;
  169. /*--------------------------- processing ------------------------------*/
  170.  for (i=curr_length;i > location;i--)
  171.      if (i < max_length)
  172.        buffer[i] = buffer[i-1];
  173.  if (location < max_length)
  174.     buffer[location] = chr;
  175.  return(buffer);
  176. }
  177. /*man***************************************************************************
  178. NAME
  179.      meminsmem - insert memory into buffer
  180.  
  181. SYNOPSIS
  182.      #include "the.h"
  183.  
  184.      CHARTYPE *meminsmem(buffer,str,len,location,max_length,curr_length)
  185.      CHARTYPE *buffer;
  186.      CHARTYPE *str;
  187.      short len,location,max_length,curr_length;
  188.  
  189. DESCRIPTION
  190.      The meminsmem function inserts the supplied 'str' into the buffer 'buffer'
  191.      before the 'location' specified. 'location' is an offset (0 based)
  192.      from the start of 'buffer'.
  193.      The 'buffer' will not be allowed to have more than 'max_length'
  194.      characters, so if the insertion of the string causes the
  195.      'max_length' to be exceeded, the last character(s) of 'buffer' will
  196.      be lost.
  197.  
  198. RETURN VALUE
  199.      A pointer to the same 'buffer' as was supplied.
  200.  
  201. SEE ALSO
  202.     meminschr
  203.  
  204. *******************************************************************************/
  205. #ifdef HAVE_PROTO
  206. CHARTYPE *meminsmem(CHARTYPE *buffer,CHARTYPE *str,short len,short location,
  207.                 short max_length,short curr_length)
  208. #else
  209. CHARTYPE *meminsmem(buffer,str,len,location,max_length,curr_length)
  210. CHARTYPE *buffer,*str;
  211. short len,location,max_length,curr_length;
  212. #endif
  213. {
  214. /*--------------------------- local data ------------------------------*/
  215.  register short i=0;
  216. /*--------------------------- processing ------------------------------*/
  217.  for (i=curr_length;i > location;i--)
  218.      if (i+len-1 < max_length)
  219.        buffer[i+len-1] = buffer[i-1];
  220.  for (i=0;i<len;i++)
  221.      if (location+i < max_length)
  222.        buffer[location+i] = str[i];
  223.  return(buffer);
  224. }
  225. /*man***************************************************************************
  226. NAME
  227.      memdeln - delete a number of character(s) from buffer
  228.  
  229. SYNOPSIS
  230.      CHARTYPE *memdeln(buffer,location,curr_length,num_chars)
  231.      CHARTYPE *buffer;
  232.      short location,curr_length,num_chars;
  233.  
  234. DESCRIPTION
  235.      The memdeln deletes the supplied number of characters from the
  236.      buffer starting at the 'location' specified. 'location' is an offset (0 based)
  237.      from the start of 'buffer'.
  238.      For each character deleted, what was the last character in buffer;
  239.      based on 'curr_length' will be replaced with a space.
  240.  
  241. RETURN VALUE
  242.      A pointer to the same 'buffer' as was supplied.
  243.  
  244. SEE ALSO
  245.     meminschr, strdelchr
  246.  
  247. *******************************************************************************/
  248. #ifdef HAVE_PROTO
  249. CHARTYPE *memdeln(CHARTYPE *buffer,short location,short curr_length,short num_chars)
  250. #else
  251. CHARTYPE *memdeln(buffer,location,curr_length,num_chars)
  252. CHARTYPE *buffer;
  253. short location,curr_length,num_chars;
  254. #endif
  255. {
  256. /*--------------------------- local data ------------------------------*/
  257.  register short i=0;
  258. /*--------------------------- processing ------------------------------*/
  259.  for (i=location;i <curr_length;i++)
  260.      if (i+num_chars >= curr_length)
  261.         buffer[i] = ' ';
  262.       else
  263.         buffer[i] = buffer[i+num_chars];
  264.  return(buffer);
  265. }
  266. /*man***************************************************************************
  267. NAME
  268.      strdelchr - delete all supplied character from buffer
  269.  
  270. SYNOPSIS
  271.      CHARTYPE *memdeln(buffer,chr)
  272.      CHARTYPE *buffer;
  273.      CHARTYPE chr;
  274.  
  275. DESCRIPTION
  276.      The memdeln deletes all occurrences of chr from the ASCIIZ buffer.
  277.  
  278. RETURN VALUE
  279.      A pointer to the same 'buffer' as was supplied.
  280.  
  281. SEE ALSO
  282.     meminschr, memdeln
  283.  
  284. *******************************************************************************/
  285. #ifdef HAVE_PROTO
  286. CHARTYPE *strdelchr(CHARTYPE *buffer,CHARTYPE chr)
  287. #else
  288. CHARTYPE *strdelchr(buffer,chr)
  289. CHARTYPE *buffer;
  290. CHARTYPE chr;
  291. #endif
  292. {
  293. /*--------------------------- local data ------------------------------*/
  294.  register int i=0,j=0;
  295.  int len=strlen((DEFCHAR *)buffer);
  296. /*--------------------------- processing ------------------------------*/
  297.  for(i=0;i<len;i++)
  298.    {
  299.     if (buffer[i] != chr)
  300.        buffer[j++] = buffer[i];
  301.    }
  302.  buffer[j] = (CHARTYPE)'\0';
  303.  return(buffer);
  304. }
  305. /*man***************************************************************************
  306. NAME
  307.      memrmdup - remove duplicate, contiguous characters
  308.  
  309. SYNOPSIS
  310.      CHARTYPE *memrmdup(buf,len,chr)
  311.      CHARTYPE *buf;
  312.      short *len;
  313.      CHARTYPE ch;
  314.  
  315. DESCRIPTION
  316.      The memrmdup function removes all duplicate, contiguous characters
  317.      from the supplied buffer.
  318.      eg. memrmdup("abc$$$def$$ghi$",15,'$')
  319.      will return pointer to buf equal to "abc$def$ghi$" and new length
  320.      in len.
  321.  
  322. RETURN VALUE
  323.      Returns the new buf.
  324. *******************************************************************************/
  325. #ifdef HAVE_PROTO
  326. CHARTYPE *memrmdup(CHARTYPE *buf,short *len,CHARTYPE ch)
  327. #else
  328. CHARTYPE *memrmdup(buf,len,ch)
  329. CHARTYPE *buf;
  330. short *len;
  331. CHARTYPE ch;
  332. #endif
  333. {
  334. /*--------------------------- local data ------------------------------*/
  335.  register short i=0,num_dups=0,newlen=*len;
  336.  CHARTYPE *src=buf,*dst=buf;
  337.  bool dup=FALSE;
  338. /*--------------------------- processing ------------------------------*/
  339.  for (; i<newlen; i++,src++)
  340.    {
  341.     if (*src == ch)
  342.       {
  343.        if (dup)
  344.          {
  345.           num_dups++;
  346.           continue;
  347.          }
  348.        else
  349.          {
  350.           dup = TRUE;
  351.          }
  352.       }
  353.     else
  354.        dup = FALSE;
  355.     *dst++ = *src;
  356.    }
  357.  *len = newlen-num_dups;
  358.  return(buf);
  359. }
  360. /*man***************************************************************************
  361. NAME
  362.      strrmdup - remove duplicate, contiguous characters
  363.  
  364. SYNOPSIS
  365.      CHARTYPE *strrmdup(buf,chr)
  366.      CHARTYPE *buf;
  367.      CHARTYPE ch;
  368.  
  369. DESCRIPTION
  370.      The strrmdup function removes all duplicate, contiguous characters
  371.      from the supplied string.
  372.      eg. strrmdup("abc$$$def$$ghi$",'$')
  373.      will return pointer to buf equal to "abc$def$ghi$".
  374.  
  375. RETURN VALUE
  376.      Returns the new buf.
  377. *******************************************************************************/
  378. #ifdef HAVE_PROTO
  379. CHARTYPE *strrmdup(CHARTYPE *buf,CHARTYPE ch)
  380. #else
  381. CHARTYPE *strrmdup(buf,ch)
  382. CHARTYPE *buf;
  383. CHARTYPE ch;
  384. #endif
  385. {
  386. /*--------------------------- local data ------------------------------*/
  387.  register short i=0,num_dups=0,newlen=strlen((DEFCHAR*)buf);
  388.  CHARTYPE *src=buf,*dst=buf;
  389.  bool dup=FALSE;
  390. /*--------------------------- processing ------------------------------*/
  391.  for (; i<newlen; i++,src++)
  392.    {
  393.     if (*src == ch)
  394.       {
  395.        if (dup)
  396.          {
  397.           num_dups++;
  398.           continue;
  399.          }
  400.        else
  401.          {
  402.           dup = TRUE;
  403.          }
  404.       }
  405.     else
  406.        dup = FALSE;
  407.     *dst++ = *src;
  408.    }
  409.  *dst = '\0';
  410.  return(buf);
  411. }
  412. /*man***************************************************************************
  413. NAME
  414.      strzne - search string for NOT character
  415.  
  416. SYNOPSIS
  417.      short strzne(str,chr)
  418.      CHARTYPE *str;
  419.      CHARTYPE ch;
  420.  
  421. DESCRIPTION
  422.      The strzne function searches the string from the left for the first
  423.      character NOT equal to the supplied character.
  424.  
  425. RETURN VALUE
  426.      If successful, returns the position of first NON-matching character
  427.      or (-1) if unsuccessful.
  428.  
  429. SEE ALSO
  430.      strzrevne, memrevne
  431. *******************************************************************************/
  432. #ifdef HAVE_PROTO
  433. short strzne(CHARTYPE *str,CHARTYPE ch)
  434. #else
  435. short strzne(str,ch)
  436. CHARTYPE *str;
  437. CHARTYPE ch;
  438. #endif
  439. {
  440. /*--------------------------- local data ------------------------------*/
  441.  register short len=0;
  442.  register short  i = 0;
  443. /*--------------------------- processing ------------------------------*/
  444.  len = strlen((DEFCHAR *)str);
  445.  for (; i<len && str[i]==ch; i++);
  446.  if (i>=len)
  447.     i = (-1);
  448.  return(i);
  449. }
  450. /*man***************************************************************************
  451. NAME
  452.      my_strdup - equivalent to strdup
  453.  
  454. SYNOPSIS
  455.      CHARTYPE *my_strdup(str)
  456.      CHARTYPE *str;
  457.  
  458. DESCRIPTION
  459.      The my_strdup function duplicates the supplied string.
  460.  
  461. RETURN VALUE
  462.      If successful, returns a pointer to the copy of the supplied string
  463.      or NULL if unsuccessful.
  464. *******************************************************************************/
  465. #ifdef HAVE_PROTO
  466. CHARTYPE *my_strdup(CHARTYPE *str)
  467. #else
  468. CHARTYPE *my_strdup(str)
  469. CHARTYPE *str;
  470. #endif
  471. {
  472. /*--------------------------- local data ------------------------------*/
  473.  register short len=0;
  474.  CHARTYPE *tmp=NULL;
  475. /*--------------------------- processing ------------------------------*/
  476.  len = strlen((DEFCHAR *)str);
  477.  if ((tmp = (CHARTYPE *)(*the_malloc)((len+1)*sizeof(CHARTYPE))) == (CHARTYPE *)NULL)
  478.     return((CHARTYPE *)NULL);
  479.  strcpy((DEFCHAR *)tmp,(DEFCHAR *)str);
  480.  return(tmp);
  481. }
  482. /*man***************************************************************************
  483. NAME
  484.      memne - search buffer for NOT character
  485.  
  486. SYNOPSIS
  487.      #include "the.h"
  488.  
  489.      short memne(buffer,chr,length)
  490.      CHARTYPE *buffer;
  491.      CHARTYPE chr;
  492.      short length;
  493.  
  494. DESCRIPTION
  495.      The memne function searches the buffer from the left for the first
  496.      character NOT equal to the supplied character.
  497.  
  498. RETURN VALUE
  499.      If successful, returns the position of first NON-matching character
  500.      or (-1) if unsuccessful.
  501.  
  502. SEE ALSO
  503.      strzrevne, memrevne, strzne
  504. *******************************************************************************/
  505. #ifdef HAVE_PROTO
  506. short memne(CHARTYPE *buffer,CHARTYPE chr,short length)
  507. #else
  508. short memne(buffer,chr,length)
  509. CHARTYPE *buffer;
  510. CHARTYPE chr;
  511. short length;
  512. #endif
  513. {
  514. /*--------------------------- local data ------------------------------*/
  515.  register short  i = 0;
  516. /*--------------------------- processing ------------------------------*/
  517.  for (; i<length && buffer[i]==chr; i++);
  518.  if (i>=length)
  519.     i = (-1);
  520.  return(i);
  521. }
  522. /*man***************************************************************************
  523. NAME
  524.      strzrevne - search string reversed for NOT character
  525.  
  526. SYNOPSIS
  527.      #include "the.h"
  528.  
  529.      short strzrevne(str,chr)
  530.      CHARTYPE *str;
  531.      CHARTYPE ch;
  532.  
  533. DESCRIPTION
  534.      The strzrevne function searches the string from the right for the
  535.      first character NOT equal to the supplied character.
  536.  
  537. RETURN VALUE
  538.      If successful, returns the position of first NON-matching character
  539.      or (-1) if unsuccessful.
  540.  
  541. SEE ALSO
  542.      strzne, memrevne
  543. *******************************************************************************/
  544. #ifdef HAVE_PROTO
  545. short strzrevne(CHARTYPE *str,CHARTYPE ch)
  546. #else
  547. short strzrevne(str,ch)
  548. CHARTYPE *str;
  549. CHARTYPE ch;
  550. #endif
  551. {
  552. /*--------------------------- local data ------------------------------*/
  553.  register short len=0;
  554. /*--------------------------- processing ------------------------------*/
  555.  len = strlen((DEFCHAR *)str);
  556.  for (--len; len>=0 && str[len]==ch; len--);
  557.  return(len);
  558. }
  559. /*man***************************************************************************
  560. NAME
  561.      strzreveq - search string reversed for character
  562.  
  563. SYNOPSIS
  564.      short strzreveq(str,chr)
  565.      CHARTYPE *str;
  566.      CHARTYPE ch;
  567.  
  568. DESCRIPTION
  569.      The strzreveq function searches the string from the right for the
  570.      first character equal to the supplied character.
  571.  
  572. RETURN VALUE
  573.      If successful, returns the position of first matching character
  574.      or (-1) if unsuccessful.
  575.  
  576. SEE ALSO
  577.      strzrevne
  578. *******************************************************************************/
  579. #ifdef HAVE_PROTO
  580. short strzreveq(CHARTYPE *str,CHARTYPE ch)
  581. #else
  582. short strzreveq(str,ch)
  583. CHARTYPE *str,ch;
  584. #endif
  585. /***********************************************************************/
  586. {
  587. /*--------------------------- local data ------------------------------*/
  588.  register short len=0;
  589. /*--------------------------- processing ------------------------------*/
  590.  len = strlen((DEFCHAR *)str);
  591.  for (--len; len>=0 && str[len]!=ch; len--);
  592.  return(len);
  593. }
  594. /*man***************************************************************************
  595. NAME
  596.      strtrunc - truncate leading and trailing spaces from string
  597.  
  598. SYNOPSIS
  599.      #include "the.h"
  600.  
  601.      CHARTYPE *strtrunc(string)
  602.      CHARTYPE *string;
  603.  
  604. DESCRIPTION
  605.      The strtrunc function truncates all leading and trailing spaces 
  606.      from the supplied string.
  607.  
  608. RETURN VALUE
  609.      A pointer to the original string, now truncated.
  610.  
  611. SEE ALSO
  612.  
  613. *******************************************************************************/
  614. #ifdef HAVE_PROTO
  615. CHARTYPE *strtrunc(CHARTYPE *string)
  616. #else
  617. CHARTYPE *strtrunc(string)
  618. CHARTYPE *string;
  619. #endif
  620. {
  621. /*--------------------------- local data ------------------------------*/
  622. /*--------------------------- processing ------------------------------*/
  623.  return(MyStrip(string,STRIP_BOTH,' '));
  624. }
  625. /*man***************************************************************************
  626. NAME
  627.      MyStrip - truncate leading and/or trailing spaces from string
  628.  
  629. SYNOPSIS
  630.      #include "the.h"
  631.  
  632.      CHARTYPE *MyStrip(string,option,ch)
  633.      CHARTYPE *string;
  634.      char option;
  635.      char ch;
  636.  
  637. DESCRIPTION
  638.      The MyStrip function truncates all leading and/or trailing ch
  639.      from the supplied string.
  640.      The value of the "option" argument can be one of:
  641.         STRIP_LEADING
  642.         STRIP_TRAILING
  643.         STRIP_BOTH
  644.         STRIP_ALL
  645.         STRIP_NONE
  646.      These are defined elsewhere with the values:
  647.         STRIP_LEADING    1
  648.         STRIP_TRAILING   2
  649.         STRIP_BOTH       STRIP_LEADING|STRIP_TRAILING
  650.         STRIP_ALL        STRIP_LEADING|STRIP_TRAILING|4
  651.         STRIP_NONE       0
  652.  
  653. RETURN VALUE
  654.      A pointer to the original string, now truncated.
  655.  
  656. SEE ALSO
  657.  
  658. *******************************************************************************/
  659. #ifdef HAVE_PROTO
  660. CHARTYPE *MyStrip(CHARTYPE *string,char option,char ch)
  661. #else
  662. CHARTYPE *MyStrip(string,option,ch)
  663. CHARTYPE *string;
  664. char option,ch;
  665. #endif
  666. {
  667. /*--------------------------- local data ------------------------------*/
  668.  register short i=0;
  669.  short pos=0;
  670. /*--------------------------- processing ------------------------------*/
  671.  if (strlen((DEFCHAR *)string) == 0)
  672.     return(string);
  673.  if (option & STRIP_TRAILING)
  674.    {
  675.     pos = strzrevne(string,ch);
  676.     if (pos == (-1))
  677.        *(string) = '\0';
  678.     else
  679.        *(string+pos+1) = '\0';
  680.    }
  681.  if (option & STRIP_LEADING)
  682.    {
  683.     pos = strzne(string,ch);
  684.     if (pos == (-1))
  685.        *(string) = '\0';
  686.     else
  687.       {
  688. /*       for (i=0;*(string+i)!='\0';i++) */
  689.        for (i=0;*(string+i+pos)!='\0';i++) /* fixed by FGC */
  690.           *(string+i) = *(string+i+pos);
  691.        *(string+i) = '\0';
  692.       }
  693.    }
  694.  if (option == STRIP_ALL)
  695.     string = strdelchr(string,' ');
  696.  return(string);
  697. }
  698. /*man***************************************************************************
  699. NAME
  700.      memfind - finds a needle in a haystack respecting case and arbitrary
  701.                characters if set.
  702.  
  703. SYNOPSIS
  704.      short memfind(haystack,needle,hay_len,nee_len,case_ignore,arbsts,arb)
  705.      CHARTYPE *haystack;                            string to be searched
  706.      CHARTYPE *needle;        string to search for - may contain arbchars
  707.      short hay_len;                                    length of haystack
  708.      short nee_len;                                      length of needle
  709.      bool case_ignore;                      TRUE if search to ignore case
  710.      bool arbsts;          TRUE if need to check for arbitrary characters
  711.      CHARTYPE single                       the single arbitrary character
  712.      CHARTYPE multiple                   the multiple arbitrary character
  713.  
  714. DESCRIPTION
  715.      The memfind function locates a needle in a haystack. Both the needle
  716.      and haystack may contain null characters. If case_ignore is TRUE,
  717.      then upper and lower case characters are treated equal. If arbsts
  718.      is ON, any arbitrary character, specified by arb, in needle, will
  719.      match ANY character in the haystack.
  720.  
  721. RETURN VALUE
  722.      The first occurrence (0 based) of needle in haystack, or (-1) if
  723.      the needle does not appear in the haystack.
  724. *******************************************************************************/
  725. #ifdef HAVE_PROTO
  726. short memfind(CHARTYPE *haystack,CHARTYPE *needle,short hay_len,short nee_len,
  727.             bool case_ignore,bool arbsts,CHARTYPE arb_single,CHARTYPE arb_multiple)
  728. #else
  729. short memfind(haystack,needle,hay_len,nee_len,case_ignore,arbsts,arb_single,arb_multiple)
  730. CHARTYPE *haystack;
  731. CHARTYPE *needle;
  732. short hay_len;
  733. short nee_len;
  734. bool case_ignore;
  735. bool arbsts;
  736. CHARTYPE arb_single;
  737. CHARTYPE arb_multiple;
  738. #endif
  739. /*--------------------------- local data ------------------------------*/
  740. {
  741.  register CHARTYPE c1=0,c2=0;
  742.  register CHARTYPE *buf1=NULL,*buf2=NULL;
  743.  register short i=0,j=0;
  744.  short matches=0;
  745.  CHARTYPE *new_needle=needle;
  746.  bool need_free=FALSE;
  747. /*--------------------------- processing ------------------------------*/
  748. /*---------------------------------------------------------------------*/
  749. /* Strip any duplicate, contiguous occurrences of arb_multiple if      */
  750. /* we are handling arbchars.                                           */
  751. /*---------------------------------------------------------------------*/
  752.  if (arbsts
  753.  &&  strzeq(needle,arb_multiple) != (-1))
  754.    {
  755.     if ((new_needle = (CHARTYPE *)my_strdup(needle)) == NULL)
  756.       {
  757.        display_error(30,(CHARTYPE *)"",FALSE);
  758.        return(-1);
  759.       }
  760.     need_free = TRUE;
  761.     memrmdup(new_needle,&nee_len,arb_multiple);
  762.    }
  763.  
  764.  for (i=0;i<(hay_len-nee_len+1);i++)
  765.     {
  766.      buf1 = haystack+i;
  767.      buf2 = new_needle;
  768.      matches=0;
  769.      for (j=0;j<nee_len;j++)
  770.         {
  771.          if (case_ignore)
  772.            {
  773.             if (isupper(*buf1))
  774.                c1 = tolower(*buf1);
  775.             else
  776.                c1 = *buf1;
  777.             if (isupper(*buf2))
  778.                c2 = tolower(*buf2);
  779.             else
  780.                c2 = *buf2;
  781.            }
  782.          else
  783.            {
  784.             c1 = *buf1;
  785.             c2 = *buf2;
  786.            }
  787.          if (arbsts)
  788.            {
  789. /* Next lines added by R.BOSSUT */
  790.             if (c2 == arb_multiple)
  791.               {
  792.                short new_hay_len = hay_len-(buf1-haystack);
  793.                short new_nee_len = nee_len-(buf2+1-new_needle);
  794.  
  795.                if (memfind(buf1,buf2+1,new_hay_len,new_nee_len,
  796.                                  case_ignore,arbsts,arb_single,arb_multiple) == (-1))
  797.                   break;
  798.                else
  799.                  {
  800.                   if (need_free) 
  801.                      (*the_free)(new_needle);
  802.                   return(i);
  803.                  }
  804.               }
  805.             else
  806.               {
  807. /* Up to here... */
  808.                if (c1 != c2 && c2 != arb_single)
  809.                   break;
  810.                else
  811.                   matches++;
  812.               }
  813. /* Next lines added by R.BOSSUT */
  814.            }
  815. /* Up to here... */
  816.          else
  817.            {
  818.             if (c1 != c2)
  819.                break;
  820.             else
  821.                matches++;
  822.            }
  823.          ++buf1;
  824.          ++buf2;
  825.         }
  826.      if (matches == nee_len)
  827.        {
  828.         if (need_free) 
  829.            (*the_free)(new_needle);
  830.         return(i);
  831.        }
  832.     }
  833.  if (need_free) 
  834.     (*the_free)(new_needle);
  835.  return(-1);
  836. }
  837. /***********************************************************************/
  838. #ifdef HAVE_PROTO
  839. short memcmpi(CHARTYPE *buf1,CHARTYPE *buf2,short len)
  840. #else
  841. short memcmpi(buf1,buf2,len)
  842. CHARTYPE *buf1,*buf2;
  843. short len;
  844. #endif
  845. /***********************************************************************/
  846. /* Function  : Compares two memory buffers for equality;               */
  847. /*             case insensitive. Same as memicmp() Microsoft C.        */
  848. /* Parameters: buf1     - first buffer                                 */
  849. /*             buf2     - second buffer                                */
  850. /*             len      - number of characters to compare.             */
  851. /* Return    : <0 if buf1 < buf2,                                      */
  852. /*             =0 if buf1 = buf2,                                      */
  853. /*             >0 if buf1 > buf2,                                      */
  854. /***********************************************************************/
  855. {
  856. /*--------------------------- local data ------------------------------*/
  857.  register short i=0;
  858.  CHARTYPE c1,c2;
  859. /*--------------------------- processing ------------------------------*/
  860.  for(i=0;i<len;i++)
  861.    {
  862.     if (isupper(*buf1))
  863.        c1 = tolower(*buf1);
  864.     else
  865.        c1 = *buf1;
  866.     if (isupper(*buf2))
  867.        c2 = tolower(*buf2);
  868.     else
  869.        c2 = *buf2;
  870.     if (c1 != c2)
  871.        return(c1-c2);
  872.     ++buf1;
  873.     ++buf2;
  874.    }
  875.  return(0);
  876. }
  877. /***********************************************************************/
  878. #ifdef HAVE_PROTO
  879. CHARTYPE *make_upper(CHARTYPE *str)
  880. #else
  881. CHARTYPE *make_upper(str)
  882. CHARTYPE *str;
  883. #endif
  884. /***********************************************************************/
  885. /* Function  : Makes the supplied string uppercase.                    */
  886. /*             Equivalent to strupr() on some platforms.      .        */
  887. /* Parameters: str      - string to uppercase                          */
  888. /* Return    : str uppercased                                          */
  889. /***********************************************************************/
  890. {
  891. /*--------------------------- local data ------------------------------*/
  892.  CHARTYPE *save_str=str;
  893. /*--------------------------- processing ------------------------------*/
  894.  while(*str)
  895.    {
  896.     if (islower(*str))
  897.        *str = toupper(*str);
  898.     ++str;
  899.    }
  900.  return(save_str);
  901. }
  902. /*man***************************************************************************
  903. NAME
  904.      equal - determine if strings are equal up to specified length
  905.  
  906. SYNOPSIS
  907.      unsigned short equal(con,str,min_len)
  908.      CHARTYPE *con,*str;
  909.      short min_len;
  910.  
  911. DESCRIPTION
  912.      The equal function determines if a two strings are equal, irrespective
  913.      of case, up to the length of the second string. The length of the
  914.      second string must be greater than or equal to the specified minimum
  915.      length for the strings to be considered equal.
  916.  
  917. RETURN VALUE
  918.      If 'equal' TRUE else FALSE.
  919. *******************************************************************************/
  920. #ifdef HAVE_PROTO
  921. unsigned short equal(CHARTYPE *con,CHARTYPE *str,short min_len)
  922. #else
  923. unsigned short equal(con,str,min_len)
  924. CHARTYPE *con,*str;
  925. short min_len;
  926. #endif
  927. {
  928. /*--------------------------- local data ------------------------------*/
  929. /*--------------------------- processing ------------------------------*/
  930. #ifdef TRACE
  931.  trace_function("util.c:    equal");
  932. #endif
  933.  if (min_len == 0)
  934.    {
  935. #ifdef TRACE
  936.     trace_return();
  937. #endif
  938.     return(FALSE);
  939.    }
  940.  if (memfind(con,str,min(strlen((DEFCHAR *)str),strlen((DEFCHAR *)con)),
  941.      min(strlen((DEFCHAR *)str),strlen((DEFCHAR *)con)),TRUE,FALSE,'\0','\0') == 0
  942.  &&  strlen((DEFCHAR *)str) >= min_len
  943.  &&  strlen((DEFCHAR *)con) >= strlen((DEFCHAR *)str))
  944.    {
  945. #ifdef TRACE
  946.     trace_return();
  947. #endif
  948.     return(TRUE);
  949.    }
  950. #ifdef TRACE
  951.  trace_return();
  952. #endif
  953.  return(FALSE);
  954. }
  955. /***********************************************************************/
  956. #ifdef HAVE_PROTO
  957. short valid_integer(CHARTYPE *str)
  958. #else
  959. short valid_integer(str)
  960. CHARTYPE *str;
  961. #endif
  962. /***********************************************************************/
  963. /* Function  : Checks that string contains only 0-9,- or +.            */
  964. /* Parameters: *str     - string to be checked                         */
  965. /* Return    : TRUE or FALSE                                           */
  966. /***********************************************************************/
  967. {
  968. /*--------------------------- local data ------------------------------*/
  969.  register short i=0;
  970.  short num_signs=0;
  971. /*--------------------------- processing ------------------------------*/
  972. #ifdef TRACE
  973.  trace_function("util.c:    valid_integer");
  974. #endif
  975.  for (i=0; i<strlen((DEFCHAR *)str); i++)
  976.     {
  977.      if (*(str+i) == '-' || *(str+i) == '+')
  978.         num_signs++;
  979.      else
  980.         if (!isdigit(*(str+i)))
  981.           {
  982. #ifdef TRACE
  983.            trace_return();
  984. #endif
  985.            return(FALSE);
  986.           }
  987.     }
  988.  if (num_signs > 1)
  989.    {
  990. #ifdef TRACE
  991.     trace_return();
  992. #endif
  993.     return(FALSE);
  994.    }
  995. #ifdef TRACE
  996.  trace_return();
  997. #endif
  998.  return(TRUE);
  999. }
  1000. /***********************************************************************/
  1001. #ifdef HAVE_PROTO
  1002. short valid_positive_integer(CHARTYPE *str)
  1003. #else
  1004. short valid_positive_integer(str)
  1005. CHARTYPE *str;
  1006. #endif
  1007. /***********************************************************************/
  1008. /* Function  : Checks that string contains only 0-9, or +.             */
  1009. /* Parameters: *str     - string to be checked                         */
  1010. /* Return    : TRUE or FALSE                                           */
  1011. /***********************************************************************/
  1012. {
  1013. /*--------------------------- local data ------------------------------*/
  1014.  register short i=0;
  1015.  short num_signs=0;
  1016. /*--------------------------- processing ------------------------------*/
  1017. #ifdef TRACE
  1018.  trace_function("util.c:    valid_positive_integer");
  1019. #endif
  1020.  for (i=0; i<strlen((DEFCHAR *)str); i++)
  1021.     {
  1022.      if (*(str+i) == '+')
  1023.         num_signs++;
  1024.      else
  1025.         if (!isdigit(*(str+i)))
  1026.           {
  1027. #ifdef TRACE
  1028.            trace_return();
  1029. #endif
  1030.            return(FALSE);
  1031.           }
  1032.     }
  1033.  if (num_signs > 1)
  1034.    {
  1035. #ifdef TRACE
  1036.     trace_return();
  1037. #endif
  1038.     return(FALSE);
  1039.    }
  1040. #ifdef TRACE
  1041.  trace_return();
  1042. #endif
  1043.  return(TRUE);
  1044. }
  1045. /***********************************************************************/
  1046. #ifdef HAVE_PROTO
  1047. short strzeq(CHARTYPE *str,CHARTYPE ch)
  1048. #else
  1049. short strzeq(str,ch)
  1050. CHARTYPE *str;
  1051. CHARTYPE ch;
  1052. #endif
  1053. /***********************************************************************/
  1054. /* Function  : Locate in ASCIIZ string, character                      */
  1055. /* Parameters: *str     - string to be searched                        */
  1056. /*             ch       - character to be searched for                 */
  1057. /* Return    : position in string of character - (-1) if not found     */
  1058. /***********************************************************************/
  1059. {
  1060. /*--------------------------- local data ------------------------------*/
  1061.  register short len=0;
  1062.  register short  i = 0;
  1063. /*--------------------------- processing ------------------------------*/
  1064.  len = strlen((DEFCHAR *)str);
  1065.  for (; i<len && str[i]!=ch; i++);
  1066.  if (i>=len)
  1067.     i = (-1);
  1068.  return(i);
  1069. }
  1070.  
  1071. /***********************************************************************/
  1072. #ifdef HAVE_PROTO
  1073. CHARTYPE *strtrans(CHARTYPE *str,CHARTYPE oldch,CHARTYPE newch)
  1074. #else
  1075. CHARTYPE *strtrans(str,oldch,newch)
  1076. CHARTYPE *str;
  1077. CHARTYPE oldch,newch;
  1078. #endif
  1079. /***********************************************************************/
  1080. /* Function  : Translate all occurrences of oldch to newch in str      */
  1081. /* Parameters: *str     - string to be amendedd                        */
  1082. /*             oldch    - character to be replaced                     */
  1083. /*             newch    - character to replace oldch                   */
  1084. /* Return    : same string but with characters translated              */
  1085. /***********************************************************************/
  1086. {
  1087. /*--------------------------- local data ------------------------------*/
  1088.  register short  i=0;
  1089. /*--------------------------- processing ------------------------------*/
  1090.  for (i=0;i<strlen((DEFCHAR *)str); i++)
  1091.    {
  1092.     if (*(str+i) == oldch)
  1093.        *(str+i) = newch;
  1094.    }
  1095.  return(str);
  1096. }
  1097. /***********************************************************************/
  1098. #ifdef HAVE_PROTO
  1099. LINE *add_line(LINE *first,LINE *curr,CHARTYPE *line,
  1100.                LENGTHTYPE len,SELECTTYPE select,bool new_flag)
  1101. #else
  1102. LINE *add_line(first,curr,line,len,select,new_flag)
  1103. LINE *first;
  1104. LINE *curr;
  1105. CHARTYPE *line;
  1106. LENGTHTYPE len;
  1107. SELECTTYPE select;
  1108. bool new_flag;
  1109. #endif
  1110. /***********************************************************************/
  1111. /* Adds a member of the linked list for the specified file containing  */
  1112. /* the line contents and length.                                       */
  1113. /* PARAMETERS:                                                         */
  1114. /* first      - pointer to first line for the file                     */
  1115. /* curr       - pointer to current line for the file                   */
  1116. /* line       - contents of line to be added                           */
  1117. /* len        - length of line to be added                             */
  1118. /* select     - select level of new line                               */
  1119. /* RETURN:    - pointer to current item in linked list or NULL if error*/
  1120. /***********************************************************************/
  1121. {
  1122. /*-------------------------- external data ----------------------------*/
  1123.  extern LINE *curr_line;
  1124.  extern LINE *next_line;
  1125. /*--------------------------- local data ------------------------------*/
  1126. /*--------------------------- processing ------------------------------*/
  1127. #ifdef TRACE
  1128.  trace_function("util.c:    add_line");
  1129. #endif
  1130.  next_line = lll_add(first,curr,sizeof(LINE));
  1131.  if (next_line == NULL)
  1132.    {
  1133. #ifdef TRACE
  1134.     trace_return();
  1135. #endif
  1136.     return(NULL);
  1137.    }
  1138.  curr_line = next_line;
  1139.  
  1140.  curr_line->line = (CHARTYPE *)(*the_malloc)((len+1)*sizeof(CHARTYPE));
  1141.  if (curr_line->line == NULL)
  1142.    {
  1143. #ifdef TRACE
  1144.     trace_return();
  1145. #endif
  1146.     return(NULL);
  1147.    }
  1148.  memcpy(curr_line->line,line,len);
  1149.  *(curr_line->line+len) = '\0'; /* for functions that expect ASCIIZ string */
  1150.  curr_line->length = len;
  1151.  curr_line->select = select;
  1152.  curr_line->pre = NULL;
  1153.  curr_line->name = NULL;
  1154.  curr_line->new_flag = new_flag;
  1155.  curr_line->changed_flag = FALSE;
  1156.  curr_line->tag_flag = FALSE;
  1157. #ifdef TRACE
  1158.  trace_return();
  1159. #endif
  1160.  return(curr_line);
  1161. }
  1162. /***********************************************************************/
  1163. #ifdef HAVE_PROTO
  1164. LINE *append_line(LINE *curr,CHARTYPE *line,LENGTHTYPE len)
  1165. #else
  1166. LINE *append_line(curr,line,len)
  1167. LINE *curr;
  1168. CHARTYPE *line;
  1169. LENGTHTYPE len;
  1170. #endif
  1171. /***********************************************************************/
  1172. {
  1173. /*-------------------------- external data ----------------------------*/
  1174. /*--------------------------- local data ------------------------------*/
  1175. /*--------------------------- processing ------------------------------*/
  1176. #ifdef TRACE
  1177.  trace_function("util.c:    append_line");
  1178. #endif
  1179.  curr->line = (CHARTYPE *)(*the_realloc)(curr->line,(curr->length+len+1)*sizeof(CHARTYPE));
  1180.  if (curr->line == NULL)
  1181.    {
  1182. #ifdef TRACE
  1183.     trace_return();
  1184. #endif
  1185.     return(NULL);
  1186.    }
  1187.  memcpy(curr->line+curr->length,line,len);
  1188.  curr->length += len;
  1189.  *(curr->line+curr->length) = '\0'; /* for functions that expect ASCIIZ string */
  1190. #ifdef TRACE
  1191.  trace_return();
  1192. #endif
  1193.  return(curr);
  1194. }
  1195. /***********************************************************************/
  1196. #ifdef HAVE_PROTO
  1197. LINE *delete_line(LINE *first,LINE *curr,short direction)
  1198. #else
  1199. LINE *delete_line(first,curr,direction)
  1200. LINE *first,*curr;
  1201. short direction;
  1202. #endif
  1203. /***********************************************************************/
  1204. /* Deletes a member of the linked list for the specified file.         */
  1205. /* PARAMETERS:                                                         */
  1206. /* first      - pointer to first line for the file                     */
  1207. /* curr       - pointer to current line for the file                   */
  1208. /* direction  - direction in which to delete.                          */
  1209. /* RETURN:    - pointer to current item in linked list or NULL if error*/
  1210. /***********************************************************************/
  1211. {
  1212. /*--------------------------- local data ------------------------------*/
  1213. /*--------------------------- processing ------------------------------*/
  1214. #ifdef TRACE
  1215.  trace_function("util.c:    delete_line");
  1216. #endif
  1217.  if (curr->name != (CHARTYPE *)NULL)
  1218.     (*the_free)(curr->name);
  1219.  (*the_free)(curr->line);
  1220.  curr = lll_del(&first,NULL,curr,direction);
  1221. #ifdef TRACE
  1222.  trace_return();
  1223. #endif
  1224.  return(curr);
  1225. }
  1226.  
  1227. /***********************************************************************/
  1228. #ifdef HAVE_PROTO
  1229. void put_string(WINDOW *win,short row,short col,CHARTYPE *string,short len)
  1230. #else
  1231. void put_string(win,row,col,string,len)
  1232. WINDOW *win;
  1233. short row,col;
  1234. CHARTYPE *string;
  1235. short len;
  1236. #endif
  1237. /***********************************************************************/
  1238. {
  1239. /*------------------------- external data -----------------------------*/
  1240.  extern chtype etmode_table[256];
  1241. /*--------------------------- local data ------------------------------*/
  1242.  register short i=0;
  1243. /*--------------------------- processing ------------------------------*/
  1244. #ifdef TRACE
  1245.  trace_function("util.c:    put_string");
  1246. #endif
  1247.  wmove(win,row,col);
  1248.  for (i=0;i<len;i++)
  1249.    {
  1250.     waddch(win,etmode_table[*(string+i)]);
  1251.    }
  1252. #ifdef TRACE
  1253.  trace_return();
  1254. #endif
  1255.  return;
  1256. }
  1257. /***********************************************************************/
  1258. #ifdef HAVE_PROTO
  1259. void put_char(WINDOW *win,chtype ch,CHARTYPE add_ins)
  1260. #else
  1261. void put_char(win,ch,add_ins)
  1262. WINDOW *win;
  1263. chtype ch;
  1264. CHARTYPE add_ins;
  1265. #endif
  1266. /***********************************************************************/
  1267. {
  1268. /*------------------------- external data -----------------------------*/
  1269.  extern chtype etmode_table[256];
  1270.  extern bool   etmode_flag[256];
  1271. /*--------------------------- local data ------------------------------*/
  1272.  chtype chr_attr=0,chr=0;
  1273.  chtype attr=0L;
  1274. /*--------------------------- processing ------------------------------*/
  1275. #ifdef TRACE
  1276.  trace_function("util.c:    put_char");
  1277. #endif
  1278.  chr_attr = ch;
  1279.  chr = chr_attr & A_CHARTEXT;
  1280.  if (etmode_flag[chr])  /* etmode character has attributes, use them */
  1281.     chr_attr = etmode_table[chr];
  1282.  else
  1283.    {
  1284.     attr = chr_attr & A_ATTRIBUTES;
  1285.     chr_attr = etmode_table[chr] | attr;
  1286.    }
  1287.  
  1288.  if (add_ins == ADDCHAR)
  1289.     waddch(win,chr_attr);
  1290.  else
  1291.     winsch(win,chr_attr);
  1292. #ifdef TRACE
  1293.  trace_return();
  1294. #endif
  1295.  return;
  1296. }
  1297. /***********************************************************************/
  1298. #ifdef HAVE_PROTO
  1299. short set_up_windows(short scrn)
  1300. #else
  1301. short set_up_windows(scrn)
  1302. short scrn;
  1303. #endif
  1304. /***********************************************************************/
  1305. {
  1306. /*-------------------------- external data ----------------------------*/
  1307.  extern bool curses_started;
  1308.  extern CHARTYPE display_screens;
  1309.  extern bool horizontal;
  1310.  extern WINDOW *divider;
  1311.  extern WINDOW *statarea;
  1312.  extern short prefix_width;
  1313.  extern short prefix_gap;
  1314. /*--------------------------- local data ------------------------------*/
  1315.  register short i=0;
  1316.  short y=0,x=0;
  1317.  FILE_DETAILS fp;
  1318.  short my_prefix_width=0;
  1319.  short my_prefix_gap=0;
  1320. /*--------------------------- processing ------------------------------*/
  1321. #ifdef TRACE
  1322.  trace_function("util.c:    set_up_windows");
  1323. #endif
  1324. /*---------------------------------------------------------------------*/
  1325. /* If curses has not started exit gracefully...                        */
  1326. /*---------------------------------------------------------------------*/
  1327.  if (!curses_started)
  1328.    {
  1329. #ifdef TRACE
  1330.     trace_return();
  1331. #endif
  1332.     return(RC_OK);
  1333.    }
  1334. /*---------------------------------------------------------------------*/
  1335. /* Allocate space for a file descriptor colour attributes...           */
  1336. /*---------------------------------------------------------------------*/
  1337.  if ((fp.attr = (COLOUR_ATTR *)(*the_malloc)(ATTR_MAX*sizeof(COLOUR_ATTR))) == NULL)
  1338.    {
  1339.     display_error(30,(CHARTYPE *)"",FALSE);
  1340. #ifdef TRACE
  1341.     trace_return();
  1342. #endif
  1343.     return(RC_OUT_OF_MEMORY);
  1344.    }
  1345.  if (screen[scrn].screen_view)
  1346.    {
  1347.     memcpy(fp.attr,screen[scrn].screen_view->file_for_view->attr,ATTR_MAX*sizeof(COLOUR_ATTR));
  1348.     memcpy(fp.attr+ATTR_DIVIDER,CURRENT_FILE->attr+ATTR_DIVIDER,sizeof(COLOUR_ATTR));
  1349.     my_prefix_width = screen[scrn].screen_view->prefix_width;
  1350.    }
  1351.  else
  1352.    {
  1353.     set_up_default_colours(&fp,(COLOUR_ATTR *)NULL,ATTR_MAX);
  1354.     my_prefix_width = prefix_width;
  1355.    }
  1356. /*---------------------------------------------------------------------*/
  1357. /* Save the position of the cursor in each window, and then delete the */
  1358. /* window. Recreate each window, that has a valid size and move the    */
  1359. /* cursor back to the position it had in each window.                  */
  1360. /*---------------------------------------------------------------------*/
  1361.  for (i=0;i<VIEW_WINDOWS;i++)
  1362.    {
  1363.     y = x = 0;
  1364.     if (screen[scrn].win[i] != (WINDOW *)NULL)
  1365.       {
  1366.        getyx(screen[scrn].win[i],y,x);
  1367.        delwin(screen[scrn].win[i]);
  1368.        screen[scrn].win[i] = (WINDOW *)NULL;
  1369.       }
  1370.     if (screen[scrn].rows[i] != 0
  1371.     &&  screen[scrn].cols[i] != 0)
  1372.       {
  1373.        screen[scrn].win[i] = newwin(screen[scrn].rows[i],screen[scrn].cols[i],
  1374.                                  screen[scrn].start_row[i],screen[scrn].start_col[i]);
  1375.        if (screen[scrn].win[i] == (WINDOW *)NULL)
  1376.          {
  1377.           display_error(30,(CHARTYPE *)"creating window",FALSE);
  1378. #ifdef TRACE
  1379.           trace_return();
  1380. #endif
  1381.           return(RC_OUT_OF_MEMORY);
  1382.          }
  1383. #if !defined(PDCURSES)
  1384.        touchwin(screen[scrn].win[i]);
  1385. #endif
  1386.        wmove(screen[scrn].win[i],y,x);
  1387.       }
  1388.     }
  1389.  wattrset(screen[scrn].win[WINDOW_FILEAREA],set_colour(fp.attr+ATTR_FILEAREA));
  1390.  
  1391.  create_statusline_window();
  1392.  
  1393.  if (screen[scrn].win[WINDOW_ARROW] != (WINDOW *)NULL)
  1394.    {
  1395.     wattrset(screen[scrn].win[WINDOW_ARROW],set_colour(fp.attr+ATTR_ARROW));
  1396.     for (i=0;i<my_prefix_width-2;i++)
  1397.         mvwaddch(screen[scrn].win[WINDOW_ARROW],0,i,'=');
  1398.     mvwaddstr(screen[scrn].win[WINDOW_ARROW],0,my_prefix_width-2,"> ");
  1399.     wnoutrefresh(screen[scrn].win[WINDOW_ARROW]);
  1400.    }
  1401.  
  1402.  if (screen[scrn].win[WINDOW_IDLINE] != (WINDOW *)NULL)
  1403.    {
  1404.     wattrset(screen[scrn].win[WINDOW_IDLINE],set_colour(fp.attr+ATTR_IDLINE));
  1405.     wmove(screen[scrn].win[WINDOW_IDLINE],0,0);
  1406.     my_wclrtoeol(screen[scrn].win[WINDOW_IDLINE]);
  1407.    }
  1408.  
  1409.  if (screen[scrn].win[WINDOW_PREFIX] != (WINDOW *)NULL)
  1410.     wattrset(screen[scrn].win[WINDOW_PREFIX],set_colour(fp.attr+ATTR_PENDING));
  1411.  
  1412.  if (screen[scrn].win[WINDOW_GAP] != (WINDOW *)NULL)
  1413.     wattrset(screen[scrn].win[WINDOW_GAP],set_colour(fp.attr+ATTR_GAP));
  1414.  
  1415.  if (screen[scrn].win[WINDOW_COMMAND] != (WINDOW *)NULL)
  1416.    {
  1417.     wattrset(screen[scrn].win[WINDOW_COMMAND],set_colour(fp.attr+ATTR_CMDLINE));
  1418.     wmove(screen[scrn].win[WINDOW_COMMAND],0,0);
  1419.     my_wclrtoeol(screen[scrn].win[WINDOW_COMMAND]);
  1420.     wnoutrefresh(screen[scrn].win[WINDOW_COMMAND]);
  1421.     wmove(screen[scrn].win[WINDOW_COMMAND],0,0);
  1422.    }
  1423. /*---------------------------------------------------------------------*/
  1424. /* Set up divider window...                                            */
  1425. /*---------------------------------------------------------------------*/
  1426.  if (display_screens > 1
  1427.  &&  !horizontal)
  1428.    {
  1429.     if (divider != (WINDOW *)NULL)
  1430.        delwin(divider);
  1431.     divider = newwin(screen[1].screen_rows,2,screen[1].screen_start_row,
  1432.                      screen[1].screen_start_col-2);
  1433.     if (divider == (WINDOW *)NULL)
  1434.       {
  1435.        display_error(30,(CHARTYPE *)"creating window",FALSE);
  1436. #ifdef TRACE
  1437.        trace_return();
  1438. #endif
  1439.        return(RC_OUT_OF_MEMORY);
  1440.       }
  1441.  
  1442. #if 0
  1443. # if defined(A_ALTCHARSET) && !defined(USE_NCURSES)
  1444.     wattrset(divider,A_ALTCHARSET|set_colour(fp.attr+ATTR_DIVIDER));
  1445. # else
  1446.     wattrset(divider,set_colour(fp.attr+ATTR_DIVIDER));
  1447. # endif
  1448. #else
  1449.     wattrset(divider,set_colour(fp.attr+ATTR_DIVIDER));
  1450. #endif
  1451.  
  1452.     draw_divider();
  1453.    }
  1454. /*---------------------------------------------------------------------*/
  1455. /* Free up  space for a file descriptor colour attributes...           */
  1456. /*---------------------------------------------------------------------*/
  1457.  (*the_free)(fp.attr);
  1458. #ifdef TRACE
  1459.  trace_return();
  1460. #endif
  1461.  return(RC_OK);
  1462. }
  1463. /***********************************************************************/
  1464. #ifdef HAVE_PROTO
  1465. short draw_divider(void)
  1466. #else
  1467. short draw_divider()
  1468. #endif
  1469. /***********************************************************************/
  1470. {
  1471. /*-------------------------- external data ----------------------------*/
  1472.  extern WINDOW *divider;
  1473. /*--------------------------- local data ------------------------------*/
  1474. #ifndef HAVE_WVLINE
  1475.  register int i=0;
  1476. #endif
  1477. /*--------------------------- processing ------------------------------*/
  1478. #ifdef TRACE
  1479.  trace_function("util.c:    draw_divider");
  1480. #endif
  1481.  
  1482. #ifdef HAVE_WVLINE
  1483.  wmove(divider,0,0);
  1484.  wvline(divider,0,screen[1].screen_rows);
  1485.  wmove(divider,0,1);
  1486.  wvline(divider,0,screen[1].screen_rows);
  1487. #else
  1488.  for (i=0;i<screen[1].screen_rows;i++)
  1489.    {
  1490.     wmove(divider,i,0);
  1491.     waddch(divider,'|');
  1492.     waddch(divider,'|');
  1493.    }
  1494. #endif
  1495. #ifdef TRACE
  1496.  trace_return();
  1497. #endif
  1498.  return(RC_OK);
  1499. }
  1500. /***********************************************************************/
  1501. #ifdef HAVE_PROTO
  1502. short create_statusline_window(void)
  1503. #else
  1504. short create_statusline_window()
  1505. #endif
  1506. /***********************************************************************/
  1507. {
  1508. /*-------------------------- external data ----------------------------*/
  1509.  extern bool curses_started;
  1510.  extern ROWTYPE STATUSLINEx;
  1511.  extern WINDOW *statarea;
  1512.  extern short terminal_lines;
  1513. /*--------------------------- local data ------------------------------*/
  1514.  COLOUR_ATTR attr;
  1515. /*--------------------------- processing ------------------------------*/
  1516. #ifdef TRACE
  1517.  trace_function("util.c:    create_statusline_window");
  1518. #endif
  1519.  if (!curses_started)
  1520.    {
  1521. #ifdef TRACE
  1522.     trace_return();
  1523. #endif
  1524.     return(RC_OK);
  1525.    }
  1526.  if (CURRENT_VIEW == NULL
  1527.  ||  CURRENT_FILE == NULL)
  1528.     set_up_default_colours((FILE_DETAILS *)NULL,&attr,ATTR_STATAREA);
  1529.  else
  1530.     memcpy(&attr,CURRENT_FILE->attr+ATTR_STATAREA,sizeof(COLOUR_ATTR));
  1531.  if (statarea != (WINDOW *)NULL)
  1532.    {
  1533.     delwin(statarea);
  1534.     statarea = (WINDOW *)NULL;
  1535.    }
  1536.  switch(STATUSLINEx)
  1537.    {
  1538.     case 'B':
  1539.          statarea = newwin(1,COLS,terminal_lines-1,0);
  1540.          wattrset(statarea,set_colour(&attr));
  1541.          clear_statarea();
  1542.          break;
  1543.     case 'T':
  1544.          statarea = newwin(1,COLS,0,0);
  1545.          wattrset(statarea,set_colour(&attr));
  1546.          clear_statarea();
  1547.          break;
  1548.     default:
  1549.          break;
  1550.    }
  1551. #ifdef TRACE
  1552.  trace_return();
  1553. #endif
  1554.  return(RC_OK);
  1555. }
  1556. /***********************************************************************/
  1557. #ifdef HAVE_PROTO
  1558. void pre_process_line(VIEW_DETAILS *the_view,LINETYPE line_number,LINE *known_curr)
  1559. #else
  1560. void pre_process_line(the_view,line_number,known_curr)
  1561. VIEW_DETAILS *the_view;
  1562. LINETYPE line_number;
  1563. LINE *known_curr;
  1564. #endif
  1565. /***********************************************************************/
  1566. {
  1567. /*-------------------------- external data ----------------------------*/
  1568.  extern unsigned short pre_rec_len;
  1569.  extern CHARTYPE *pre_rec;
  1570.  extern LENGTHTYPE rec_len;
  1571.  extern CHARTYPE *rec;
  1572. /*--------------------------- local data ------------------------------*/
  1573.  LINE *curr=known_curr;
  1574. /*--------------------------- processing ------------------------------*/
  1575. #ifdef TRACE
  1576.  trace_function("util.c:    pre_process_line");
  1577. #endif
  1578. /*---------------------------------------------------------------------*/
  1579. /* If we haven't been passed a valid LINE*, go and get one for the     */
  1580. /* supplied line_number.                                               */
  1581. /*---------------------------------------------------------------------*/
  1582.  if (curr == (LINE *)NULL)
  1583.     curr = lll_find(the_view->file_for_view->first_line,the_view->file_for_view->last_line,
  1584.                  line_number,the_view->file_for_view->number_lines);
  1585.  memset(rec,' ',max_line_length);
  1586.  memcpy(rec,curr->line,curr->length);
  1587.  rec_len = curr->length;
  1588. /*---------------------------------------------------------------------*/
  1589. /* Now set up the prefix command from the linked list...               */
  1590. /*---------------------------------------------------------------------*/
  1591.  if (curr->pre == NULL)
  1592.    {
  1593.     memset(pre_rec,' ',MAX_PREFIX_WIDTH);
  1594.     pre_rec_len = 0;
  1595.    }
  1596.  else
  1597.    {
  1598.     memset(pre_rec,' ',MAX_PREFIX_WIDTH);
  1599.     strcpy((DEFCHAR *)pre_rec,(DEFCHAR *)curr->pre->ppc_command);
  1600.     pre_rec_len = strlen((DEFCHAR *)pre_rec);
  1601.     pre_rec[pre_rec_len] = ' ';
  1602.     pre_rec[MAX_PREFIX_WIDTH] = '\0';
  1603.    }
  1604. #ifdef TRACE
  1605.  trace_return();
  1606. #endif
  1607.  return;
  1608. }
  1609. /***********************************************************************/
  1610. #ifdef HAVE_PROTO
  1611. short post_process_line(VIEW_DETAILS *the_view,LINETYPE line_number,LINE *known_curr,bool set_alt)
  1612. #else
  1613. short post_process_line(the_view,line_number,known_curr,set_alt)
  1614. VIEW_DETAILS *the_view;
  1615. LINETYPE line_number;
  1616. LINE *known_curr;
  1617. bool set_alt;
  1618. #endif
  1619. /***********************************************************************/
  1620. {
  1621. /*------------------------- external data -----------------------------*/
  1622.  extern bool prefix_changed;
  1623.  extern CHARTYPE *rec;
  1624.  extern LENGTHTYPE rec_len;
  1625. /*--------------------------- local data ------------------------------*/
  1626.  LINE *curr=known_curr;
  1627.  short rc=RC_OK;
  1628. /*--------------------------- processing ------------------------------*/
  1629. #ifdef TRACE
  1630.  trace_function("util.c:    post_process_line");
  1631. #endif
  1632. /*---------------------------------------------------------------------*/
  1633. /* If there are no lines in the file associated with the view, exit... */
  1634. /*---------------------------------------------------------------------*/
  1635.  if (the_view->file_for_view->first_line == NULL)
  1636.    {
  1637. #ifdef TRACE
  1638.     trace_return();
  1639. #endif
  1640.     return(RC_OK);
  1641.    }
  1642. /*---------------------------------------------------------------------*/
  1643. /* If we haven't been passed a valid LINE*, go and get one for the     */
  1644. /* supplied line_number.                                               */
  1645. /*---------------------------------------------------------------------*/
  1646.  if (curr == (LINE *)NULL)
  1647.     curr = lll_find(the_view->file_for_view->first_line,the_view->file_for_view->last_line,
  1648.                  line_number,the_view->file_for_view->number_lines);
  1649. /*---------------------------------------------------------------------*/
  1650. /* First copy the pending prefix command to the linked list.           */
  1651. /* Only do it if the prefix command has a value or there is already a  */
  1652. /* pending prefix command for that line.                               */
  1653. /*---------------------------------------------------------------------*/
  1654.  if (prefix_changed)
  1655.     add_prefix_command(curr,line_number,FALSE);
  1656. /*---------------------------------------------------------------------*/
  1657. /* If the line hasn't changed, return.                                 */
  1658. /*---------------------------------------------------------------------*/
  1659.  if (rec_len == curr->length && (memcmp(rec,curr->line,curr->length) == 0))
  1660.    {
  1661. #ifdef TRACE
  1662.     trace_return();
  1663. #endif
  1664.     return(RC_NO_LINES_CHANGED);
  1665.    }
  1666. /*---------------------------------------------------------------------*/
  1667. /* If it has set the changed_flag.                                     */
  1668. /*---------------------------------------------------------------------*/
  1669.  curr->changed_flag = TRUE;
  1670. /*---------------------------------------------------------------------*/
  1671. /* Increment the alteration counters, if requested to do so...         */
  1672. /*---------------------------------------------------------------------*/
  1673.  if (set_alt)
  1674.     increment_alt(the_view->file_for_view);
  1675. /*---------------------------------------------------------------------*/
  1676. /* Add the old line contents to the line recovery list.                */
  1677. /*---------------------------------------------------------------------*/
  1678.  if (the_view->file_for_view->undoing)
  1679.     add_to_recovery_list(curr->line,curr->length);
  1680. /*---------------------------------------------------------------------*/
  1681. /* Realloc the dynamic memory for the line if the line is now longer.  */
  1682. /*---------------------------------------------------------------------*/
  1683.  if (rec_len > curr->length)
  1684.    {
  1685.     curr->line = (CHARTYPE *)(*the_realloc)((void *)curr->line,(rec_len+1)*sizeof(CHARTYPE));
  1686.     if (curr->line == NULL)
  1687.       {
  1688.        display_error(30,(CHARTYPE *)"",FALSE);
  1689. #ifdef TRACE
  1690.        trace_return();
  1691. #endif
  1692.        return(RC_OUT_OF_MEMORY);
  1693.       }
  1694.    }
  1695. /*---------------------------------------------------------------------*/
  1696. /* Copy the contents of rec into the line.                             */
  1697. /*---------------------------------------------------------------------*/
  1698.  memcpy(curr->line,rec,rec_len);
  1699.  curr->length = rec_len;
  1700.  *(curr->line+rec_len) = '\0';
  1701. #ifdef TRACE
  1702.  trace_return();
  1703. #endif
  1704.  return(rc);
  1705. }
  1706. /***********************************************************************/
  1707. #ifdef HAVE_PROTO
  1708. bool blank_field(CHARTYPE *field)
  1709. #else
  1710. bool blank_field(field)
  1711. CHARTYPE *field;
  1712. #endif
  1713. /***********************************************************************/
  1714. {
  1715. /*--------------------------- local data ------------------------------*/
  1716. /*--------------------------- processing ------------------------------*/
  1717. #ifdef TRACE
  1718.  trace_function("util.c:    blank_field");
  1719. #endif
  1720.  if (strzne(field,' ') == (-1))
  1721.    {
  1722. #ifdef TRACE
  1723.     trace_return();
  1724. #endif
  1725.     return(TRUE);                /* field is NULL or just contains spaces */
  1726.    }
  1727. #ifdef TRACE
  1728.  trace_return();
  1729. #endif
  1730.  return(FALSE);
  1731. }
  1732. /***********************************************************************/
  1733. #ifdef HAVE_PROTO
  1734. void adjust_marked_lines(bool insert_line,LINETYPE base_line,LINETYPE num_lines)
  1735. #else
  1736. void adjust_marked_lines(insert_line,base_line,num_lines)
  1737. bool insert_line;
  1738. LINETYPE base_line;
  1739. LINETYPE num_lines;
  1740. #endif
  1741. /***********************************************************************/
  1742. {
  1743. /*---------------------------------------------------------------------*/
  1744. /* When lines are deleted, the base line is the first line in the file */
  1745. /* irrespective of the direction that the delete is done.              */
  1746. /*---------------------------------------------------------------------*/
  1747. /*-------------------------- external data ----------------------------*/
  1748.  extern VIEW_DETAILS *vd_mark;
  1749. /*--------------------------- local data ------------------------------*/
  1750. /*--------------------------- processing ------------------------------*/
  1751. #ifdef TRACE
  1752.  trace_function("util.c:    adjust_marked_lines");
  1753. #endif
  1754. /*---------------------------------------------------------------------*/
  1755. /* If there are no marked lines in the current view, return.           */
  1756. /*---------------------------------------------------------------------*/
  1757.  if (MARK_VIEW != CURRENT_VIEW)
  1758.    {
  1759. #ifdef TRACE
  1760.     trace_return();
  1761. #endif
  1762.     return;
  1763.    }
  1764.  switch(insert_line)
  1765.    {
  1766.     case TRUE:/* INSERT */
  1767.          if (base_line < CURRENT_VIEW->mark_start_line)
  1768.            {
  1769.             CURRENT_VIEW->mark_start_line += num_lines;
  1770.             CURRENT_VIEW->mark_end_line += num_lines;
  1771.             break;
  1772.            }
  1773.          if (base_line >= CURRENT_VIEW->mark_start_line
  1774.          &&  base_line < CURRENT_VIEW->mark_end_line)
  1775.            {
  1776.             CURRENT_VIEW->mark_end_line += num_lines;
  1777.             break;
  1778.            }
  1779.          break;
  1780.     case FALSE:  /* DELETE */
  1781.          if (base_line <= CURRENT_VIEW->mark_start_line
  1782.          &&  base_line+num_lines-1L >= CURRENT_VIEW->mark_end_line)
  1783.            {
  1784.             CURRENT_VIEW->marked_line = FALSE;
  1785.             MARK_VIEW = (VIEW_DETAILS *)NULL;
  1786.             break;
  1787.            }
  1788.          if (base_line+num_lines-1L < CURRENT_VIEW->mark_start_line)
  1789.            {
  1790.             CURRENT_VIEW->mark_start_line -= num_lines;
  1791.             CURRENT_VIEW->mark_end_line -= num_lines;
  1792.             break;
  1793.            }
  1794.          if (base_line > CURRENT_VIEW->mark_end_line)
  1795.            {
  1796.             break;
  1797.            }
  1798.          if (base_line+num_lines-1L > CURRENT_VIEW->mark_end_line)
  1799.            {
  1800.             CURRENT_VIEW->mark_end_line = base_line - 1L;
  1801.             break;
  1802.            }
  1803.          if (base_line < CURRENT_VIEW->mark_start_line)
  1804.            {
  1805.             CURRENT_VIEW->mark_start_line = base_line;
  1806.             CURRENT_VIEW->mark_end_line = base_line +
  1807.                                          (CURRENT_VIEW->mark_end_line -
  1808.                                           (base_line + num_lines));
  1809.             break;
  1810.            }
  1811.          CURRENT_VIEW->mark_end_line -= num_lines;
  1812.          break;
  1813.    }
  1814. #ifdef TRACE
  1815.  trace_return();
  1816. #endif
  1817.  return;
  1818. }
  1819. /***********************************************************************/
  1820. #ifdef HAVE_PROTO
  1821. void adjust_pending_prefix(VIEW_DETAILS *view,bool insert_line,LINETYPE base_line,LINETYPE num_lines)
  1822. #else
  1823. void adjust_pending_prefix(view,insert_line,base_line,num_lines)
  1824. VIEW_DETAILS *view;
  1825. bool insert_line;
  1826. LINETYPE base_line;
  1827. LINETYPE num_lines;
  1828. #endif
  1829. /***********************************************************************/
  1830. {
  1831. /*---------------------------------------------------------------------*/
  1832. /* When lines are deleted, the base line is the first line in the file */
  1833. /* irrespective of the direction that the delete is done.              */
  1834. /*---------------------------------------------------------------------*/
  1835. /*--------------------------- local data ------------------------------*/
  1836.  PPC *curr_ppc=NULL;
  1837. /*--------------------------- processing ------------------------------*/
  1838. #ifdef TRACE
  1839.  trace_function("util.c:    adjust_pending_prefix");
  1840. #endif
  1841. /*---------------------------------------------------------------------*/
  1842. /* If there are no pending prefix commands in the view, return.        */
  1843. /*---------------------------------------------------------------------*/
  1844.  if (view->file_for_view->first_ppc == NULL)
  1845.    {
  1846. #ifdef TRACE
  1847.     trace_return();
  1848. #endif
  1849.     return;
  1850.    }
  1851.  curr_ppc = view->file_for_view->first_ppc;
  1852.  while (curr_ppc != NULL)
  1853.    {
  1854.     switch(insert_line)
  1855.       {
  1856.        case TRUE:/* INSERT */
  1857.             if (base_line < curr_ppc->ppc_line_number)
  1858.               {
  1859.                curr_ppc->ppc_line_number += num_lines;
  1860.                break;
  1861.               }
  1862.             break;
  1863.        case FALSE:  /* DELETE */
  1864.             if (base_line+num_lines-1L < curr_ppc->ppc_line_number)
  1865.               {
  1866.                curr_ppc->ppc_line_number -= num_lines;
  1867.                break;
  1868.               }
  1869.             if (base_line > curr_ppc->ppc_line_number)
  1870.                break;
  1871. #if OLD_CLEAR
  1872.             (void)delete_pending_prefix_command(curr_ppc,view->file_for_view,(LINE *)NULL);
  1873. #else
  1874.             clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  1875. #endif
  1876.             break;
  1877.       }
  1878.     curr_ppc = curr_ppc->next;
  1879.    }
  1880. #ifdef TRACE
  1881.  trace_return();
  1882. #endif
  1883.  return;
  1884. }
  1885. /***********************************************************************/
  1886. #ifdef HAVE_PROTO
  1887. CHARTYPE case_translate(CHARTYPE key)
  1888. #else
  1889. CHARTYPE case_translate(key)
  1890. CHARTYPE key;
  1891. #endif
  1892. /***********************************************************************/
  1893. {
  1894. /*-------------------------- external data ----------------------------*/
  1895. /*--------------------------- local data ------------------------------*/
  1896. /*--------------------------- processing ------------------------------*/
  1897. #ifdef TRACE
  1898.  trace_function("util.c:    case_translate");
  1899. #endif
  1900.  if (CURRENT_VIEW->case_enter == CASE_UPPER
  1901.  && islower(key))
  1902.    {
  1903. #ifdef TRACE
  1904.     trace_return();
  1905. #endif
  1906.     return(toupper(key));
  1907.    }
  1908.  if (CURRENT_VIEW->case_enter == CASE_LOWER
  1909.  && isupper(key))
  1910.    {
  1911. #ifdef TRACE
  1912.     trace_return();
  1913. #endif
  1914.     return(tolower(key));
  1915.    }
  1916. #ifdef TRACE
  1917.  trace_return();
  1918. #endif
  1919.  return(key);
  1920. }
  1921. /***********************************************************************/
  1922. #ifdef HAVE_PROTO
  1923. void add_to_recovery_list(CHARTYPE *line,LENGTHTYPE len)
  1924. #else
  1925. void add_to_recovery_list(line,len)
  1926. CHARTYPE *line;
  1927. LENGTHTYPE len;
  1928. #endif
  1929. /***********************************************************************/
  1930. {
  1931. /*-------------------------- external data ----------------------------*/
  1932.  extern bool batch_only;
  1933. /*--------------------------- local data ------------------------------*/
  1934.  register short i=0;
  1935. /*--------------------------- processing ------------------------------*/
  1936. #ifdef TRACE
  1937.  trace_function("util.c:    add_to_recovery_list");
  1938. #endif
  1939. /*---------------------------------------------------------------------*/
  1940. /* Ignore if running in batch.                                         */
  1941. /*---------------------------------------------------------------------*/
  1942.  if (batch_only)
  1943.    {
  1944. #ifdef TRACE
  1945.     trace_return();
  1946. #endif
  1947.     return;
  1948.    }
  1949. /*---------------------------------------------------------------------*/
  1950. /* First time through, set line array to NULL,  to indicated unused.   */
  1951. /* This setup MUST occur before the freeing up code.                   */
  1952. /*---------------------------------------------------------------------*/
  1953.  if (add_rcvry == (-1))
  1954.    {
  1955.     for (i=0;i<MAX_RECV;i++)
  1956.        rcvry[i] = NULL;
  1957.     add_rcvry = 0;               /* set to point to next available slot */
  1958.    }
  1959. /*---------------------------------------------------------------------*/
  1960. /* Now we are here, lets add to the array.                             */
  1961. /*---------------------------------------------------------------------*/
  1962.  if (rcvry[add_rcvry] == NULL)  /* haven't malloced yet */
  1963.    {
  1964.     if ((rcvry[add_rcvry] = (CHARTYPE *)(*the_malloc)((len+1)*sizeof(CHARTYPE))) == NULL)
  1965.       {
  1966.        display_error(30,(CHARTYPE *)"",FALSE);
  1967. #ifdef TRACE
  1968.        trace_return();
  1969. #endif
  1970.        return;
  1971.       }
  1972.    }
  1973.  else
  1974.    {
  1975.     if ((rcvry[add_rcvry] = (CHARTYPE *)(*the_realloc)(rcvry[add_rcvry],(len+1)*sizeof(CHARTYPE))) == NULL)
  1976.       {
  1977.        display_error(30,(CHARTYPE *)"",FALSE);
  1978. #ifdef TRACE
  1979.        trace_return();
  1980. #endif
  1981.        return;
  1982.       }
  1983.    }
  1984.  memcpy(rcvry[add_rcvry],line,len);
  1985.  rcvry_len[add_rcvry] = len;
  1986.  retr_rcvry = add_rcvry;
  1987.  add_rcvry = (++add_rcvry >= MAX_RECV) ? 0 : add_rcvry;
  1988.  num_rcvry = (++num_rcvry > MAX_RECV) ? MAX_RECV : num_rcvry;
  1989.  
  1990. #ifdef TRACE
  1991.  trace_return();
  1992. #endif
  1993.  return;
  1994. }
  1995. /***********************************************************************/
  1996. #ifdef HAVE_PROTO
  1997. void get_from_recovery_list(short num)
  1998. #else
  1999. void get_from_recovery_list(num)
  2000. short num;
  2001. #endif
  2002. /***********************************************************************/
  2003. {
  2004. /*-------------------------- external data ----------------------------*/
  2005.  extern CHARTYPE *temp_cmd;
  2006. /*--------------------------- local data ------------------------------*/
  2007.  register short i=0;
  2008.  short num_retr = min(num,num_rcvry);
  2009. /*--------------------------- processing ------------------------------*/
  2010. #ifdef TRACE
  2011.  trace_function("util.c:    get_from_recovery_list");
  2012. #endif
  2013. /*---------------------------------------------------------------------*/
  2014. /* Return error if nothing to recover.                                 */
  2015. /*---------------------------------------------------------------------*/
  2016.  if (retr_rcvry == (-1))
  2017.    {
  2018.     display_error(0,(CHARTYPE *)"0 line(s) recovered",TRUE);
  2019. #ifdef TRACE
  2020.     trace_return();
  2021. #endif
  2022.     return;
  2023.    }
  2024. /*---------------------------------------------------------------------*/
  2025. /* Retrieve each allocated recovery line and put back into the body.   */
  2026. /*---------------------------------------------------------------------*/
  2027.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  2028.  for (i=0;i<num_retr;i++)
  2029.    {
  2030.     if (rcvry[retr_rcvry] != NULL)
  2031.       {
  2032.        insert_new_line(rcvry[retr_rcvry],rcvry_len[retr_rcvry],1L,get_true_line(TRUE),TRUE,FALSE,FALSE,CURRENT_VIEW->display_low,TRUE,FALSE);
  2033.        retr_rcvry = (--retr_rcvry < 0) ? num_rcvry-1 : retr_rcvry;
  2034.       }
  2035.    }
  2036. /*---------------------------------------------------------------------*/
  2037. /* If one or more lines were retrieved, increment the alteration counts*/
  2038. /*---------------------------------------------------------------------*/
  2039.  if (num_retr)
  2040.     increment_alt(CURRENT_FILE);
  2041.  
  2042.  sprintf((DEFCHAR *)temp_cmd,"%d line(s) recovered",num_retr);
  2043.  display_error(0,temp_cmd,TRUE);
  2044. #ifdef TRACE
  2045.  trace_return();
  2046. #endif
  2047.  return;
  2048. }
  2049. /***********************************************************************/
  2050. #ifdef HAVE_PROTO
  2051. void free_recovery_list(void)
  2052. #else
  2053. void free_recovery_list()
  2054. #endif
  2055. /***********************************************************************/
  2056. {
  2057. /*--------------------------- local data ------------------------------*/
  2058.  register short i=0;
  2059. /*--------------------------- processing ------------------------------*/
  2060. #ifdef TRACE
  2061.  trace_function("util.c:    free_recovery_list");
  2062. #endif
  2063.  for (i=0;i<MAX_RECV;i++)
  2064.    {
  2065.     if (rcvry[i] != NULL)
  2066.       {
  2067.        (*the_free)(rcvry[i]);
  2068.        rcvry[i] = NULL;
  2069.       }
  2070.    }
  2071.  add_rcvry  = (-1);
  2072.  retr_rcvry = (-1);
  2073.  num_rcvry  = 0;
  2074. #ifdef TRACE
  2075.  trace_return();
  2076. #endif
  2077.  return;
  2078. }
  2079.  
  2080. #if THIS_APPEARS_TO_NOT_BE_USED
  2081. /***********************************************************************/
  2082. #ifdef HAVE_PROTO
  2083. WINDOW *adjust_window(WINDOW *win,short tr,short tc,short lines,short cols)
  2084. #else
  2085. WINDOW *adjust_window(win,tr,tc,lines,cols)
  2086. WINDOW *win;
  2087. short tr;
  2088. short tc;
  2089. short lines;
  2090. short cols;
  2091. #endif
  2092. /***********************************************************************/
  2093. {
  2094. /*--------------------------- local data ------------------------------*/
  2095.  WINDOW *neww=NULL;
  2096.  short begy=0,begx=0,maxy=0,maxx=0,y=0,x=0;
  2097.  short rc=RC_OK;
  2098. /*--------------------------- processing ------------------------------*/
  2099. #ifdef TRACE
  2100.  trace_function("util.c:    adjust_window");
  2101. #endif
  2102. /*---------------------------------------------------------------------*/
  2103. /* Get existing details about the current window.                      */
  2104. /*---------------------------------------------------------------------*/
  2105.  getbegyx(win,begy,begx);
  2106.  getmaxyx(win,maxy,maxx);
  2107.  if (maxy == lines && maxx == cols)  /* same size */
  2108.    {
  2109.     if (begy == tr && begx == tc)   /* same position */
  2110.       {
  2111. #ifdef TRACE
  2112.        trace_return();
  2113. #endif
  2114.        return(win); /* nothing to do, return same window */
  2115.       }
  2116.     else /* need to move window */
  2117.       {
  2118.        rc = mvwin(win,tr,tc);
  2119. #ifdef TRACE
  2120.        trace_return();
  2121. #endif
  2122.        return(win);
  2123.       }
  2124.    }
  2125. /*---------------------------------------------------------------------*/
  2126. /* To get here the window needs to be resized.                         */
  2127. /*---------------------------------------------------------------------*/
  2128.  getyx(win,y,x);
  2129.  delwin(win);
  2130.  neww = newwin(lines,cols,tr,tc);
  2131.  if (neww != (WINDOW *)NULL)
  2132.     wmove(neww,y,x);
  2133. #ifdef TRACE
  2134.  trace_return();
  2135. #endif
  2136.  return(neww);
  2137. }
  2138. #endif
  2139.  
  2140. /***********************************************************************/
  2141. #ifdef HAVE_PROTO
  2142. void draw_cursor(bool visible)
  2143. #else
  2144. void draw_cursor(visible)
  2145. bool visible;
  2146. #endif
  2147. /***********************************************************************/
  2148. {
  2149. /*-------------------------- external data ----------------------------*/
  2150.  extern bool INSERTMODEx;
  2151. /*--------------------------- local data ------------------------------*/
  2152. /*--------------------------- processing ------------------------------*/
  2153. #ifdef TRACE
  2154.  trace_function("util.c:    draw_cursor");
  2155. #endif
  2156.  
  2157. #if 0
  2158.  
  2159. #ifdef HAVE_CURS_SET
  2160.  if (visible)
  2161.    {
  2162.     if (INSERTMODEx)
  2163. #if defined(USE_NCURSES) || defined(CURSOR_DISAPPEARS)
  2164.        curs_set(1);   /* underline cursor - until ncurses bug fixed */
  2165. #else
  2166.        curs_set(2);   /* block cursor */
  2167. #endif
  2168.     else
  2169.        curs_set(1);   /* underline cursor */
  2170.    }
  2171.  else
  2172.     curs_set(0);      /* cursor off */
  2173. #endif
  2174.  
  2175. #else
  2176.  
  2177. #ifdef HAVE_CURS_SET
  2178.  if (visible)
  2179.    {
  2180.     if (INSERTMODEx)
  2181.       {
  2182.        curs_set(1);   /* First set to displayed... */
  2183.        curs_set(2);   /* ...then try to make it more visible */
  2184.       }
  2185.     else
  2186.        curs_set(1);   /* underline cursor */
  2187.    }
  2188.  else
  2189.     curs_set(0);      /* cursor off */
  2190. #endif
  2191.  
  2192. #endif
  2193.  
  2194. #ifdef TRACE
  2195.  trace_return();
  2196. #endif
  2197.  return;
  2198. }
  2199. /***********************************************************************/
  2200. #ifdef HAVE_PROTO
  2201. short my_wclrtoeol(WINDOW *win)
  2202. #else
  2203. short my_wclrtoeol(win)
  2204. WINDOW *win;
  2205. #endif
  2206. /***********************************************************************/
  2207. {
  2208. /*--------------------------- local data ------------------------------*/
  2209.  register short i=0;
  2210.  short x=0,y=0,maxx=0,maxy=0;
  2211. /*--------------------------- processing ------------------------------*/
  2212. #ifdef TRACE
  2213.  trace_function("util.c:    my_wclrtoeol");
  2214. #endif
  2215. #if defined(USE_NCURSES_IGNORED)
  2216.  /*
  2217.   * This extra code here to get around an ncurses bug that
  2218.   * does not overwrite existing characters displayed when a
  2219.   * clrtoeol() is called.
  2220.   * Try COMPAT X#PREFIX OFF#PREFIX ON
  2221.   */
  2222.  if (win != (WINDOW *)NULL)
  2223.    {
  2224.     getyx(win,y,x);
  2225.     getmaxyx(win,maxy,maxx);
  2226.     for (i=x;i<maxx;i++)
  2227.        waddch(win,'@');
  2228.     wmove(win,y,x);
  2229.    }
  2230. #endif
  2231.  if (win != (WINDOW *)NULL)
  2232.    {
  2233.     getyx(win,y,x);
  2234.     getmaxyx(win,maxy,maxx);
  2235.     for (i=x;i<maxx;i++)
  2236.        waddch(win,' ');
  2237.     wmove(win,y,x);
  2238.    }
  2239. #ifdef TRACE
  2240.  trace_return();
  2241. #endif
  2242.  return(0);
  2243. }
  2244. /***********************************************************************/
  2245. #ifdef HAVE_PROTO
  2246. short my_wdelch(WINDOW *win)
  2247. #else
  2248. short my_wdelch(win)
  2249. WINDOW *win;
  2250. #endif
  2251. /***********************************************************************/
  2252. {
  2253. /*--------------------------- local data ------------------------------*/
  2254.  short x=0,y=0,maxx=0,maxy=0;
  2255. /*--------------------------- processing ------------------------------*/
  2256. #ifdef TRACE
  2257.  trace_function("util.c:    my_wdelch");
  2258. #endif
  2259.  
  2260.  getyx(win,y,x);
  2261.  getmaxyx(win,maxy,maxx);
  2262.  wdelch(win);
  2263.  mvwaddch(win,y,maxx-1,' ');
  2264.  wmove(win,y,x);
  2265.  
  2266. #ifdef TRACE
  2267.  trace_return();
  2268. #endif
  2269.  return(0);
  2270. }
  2271. /***********************************************************************/
  2272. #ifdef HAVE_PROTO
  2273. short get_word(CHARTYPE *string,LENGTHTYPE length,LENGTHTYPE curr_pos,
  2274.                LENGTHTYPE *first_col,LENGTHTYPE *last_col)
  2275. #else
  2276. short get_word(string,length,curr_pos,first_col,last_col)
  2277. CHARTYPE *string;
  2278. LENGTHTYPE length,curr_pos;
  2279. LENGTHTYPE *first_col,*last_col;
  2280. #endif
  2281. /***********************************************************************/
  2282. {
  2283. #define FIRST_BLANK      0
  2284. #define SECOND_BLANK     1
  2285. #define FIRST_WORD       2
  2286. #define SECOND_WORD      3
  2287. #define THE_ALPHANUM     4
  2288. #define THE_NOT_ALPHANUM 5
  2289. /*--------------------------- local data ------------------------------*/
  2290.  short state=0,cursor_off=0;
  2291.  short num_cols=0;
  2292.  register short i=0;
  2293. /*--------------------------- processing ------------------------------*/
  2294. #ifdef TRACE
  2295.  trace_function("util.c:    get_word");
  2296. #endif
  2297. /*---------------------------------------------------------------------*/
  2298. /* If we are after the last column of the line, then just ignore the   */
  2299. /* command and leave the cursor where it is.                           */
  2300. /*---------------------------------------------------------------------*/
  2301.  if (curr_pos >= length)
  2302.    {
  2303. #ifdef TRACE
  2304.     trace_return();
  2305. #endif
  2306.     return(0);
  2307.    }
  2308. /*---------------------------------------------------------------------*/
  2309. /* Determine the end   of the next word, or go to the end of the line  */
  2310. /* if already at or past beginning of last word.                       */
  2311. /*---------------------------------------------------------------------*/
  2312.  if (CURRENT_VIEW->word == 'N')
  2313.    {
  2314.     cursor_off = num_cols = 0;
  2315.     if (*(string+curr_pos) == ' ')
  2316.        state = FIRST_BLANK;
  2317.     else
  2318.       {
  2319.        state = FIRST_WORD;
  2320.        for (i=curr_pos;;i--)
  2321.          {
  2322.           if (*(string+i) == ' '
  2323.           ||  i == -1)
  2324.             {
  2325.              cursor_off++;
  2326.              break;
  2327.             }
  2328.           cursor_off--;
  2329.          }
  2330.       }
  2331.     for (i=curr_pos+cursor_off;i<length;i++)
  2332.       {
  2333.        switch(state)
  2334.           {
  2335.            case FIRST_BLANK:
  2336.                 if (*(string+i) != ' ')
  2337.                    state = FIRST_WORD;
  2338.                 break;
  2339.            case FIRST_WORD:
  2340.                 if (*(string+i) == ' ')
  2341.                    state = SECOND_BLANK;
  2342.                 break;
  2343.            case SECOND_BLANK:
  2344.                 if (*(string+i) != ' ')
  2345.                    state = SECOND_WORD;
  2346.                 break;
  2347.           }
  2348.        if (state == SECOND_WORD)
  2349.           break;
  2350.        num_cols++;
  2351.       }
  2352.     *first_col = curr_pos + cursor_off;
  2353.     *last_col = *first_col + num_cols - 1;
  2354.    }
  2355.  else
  2356.    {
  2357.     if (isalpha(*(string+curr_pos))
  2358.     ||  isdigit(*(string+curr_pos))
  2359.     ||  *(string+curr_pos) == '_'
  2360.     ||  *(string+curr_pos) > 128)
  2361.        state = THE_ALPHANUM;
  2362.     else
  2363.        state = THE_NOT_ALPHANUM;
  2364.     /*
  2365.      * From the current position look forward for the first
  2366.      * character that is NOT in the current group...
  2367.      */
  2368.     for (i=curr_pos;i<length;i++)
  2369.       {
  2370.        if (state == THE_ALPHANUM)
  2371.          {
  2372.           if (isalpha(*(string+i))
  2373.           ||  isdigit(*(string+i))
  2374.           ||  *(string+i) == '_'
  2375.           ||  *(string+i) > 128)
  2376.              ;
  2377.           else
  2378.              break;
  2379.          }
  2380.        else
  2381.          {
  2382.           if (isalpha(*(string+i))
  2383.           ||  isdigit(*(string+i))
  2384.           ||  *(string+i) == '_'
  2385.           ||  *(string+i) > 128)
  2386.              break;
  2387.          }
  2388.       }
  2389.     *last_col = i-1;
  2390.     /*
  2391.      * From the current position look backwards for the first
  2392.      * character that is NOT in the current group...
  2393.      */
  2394.     for (i=curr_pos;i>(-1);i--)
  2395.       {
  2396.        if (state == THE_ALPHANUM)
  2397.          {
  2398.           if (isalpha(*(string+i))
  2399.           ||  isdigit(*(string+i))
  2400.           ||  *(string+i) == '_'
  2401.           ||  *(string+i) > 128)
  2402.              ;
  2403.           else
  2404.              break;
  2405.          }
  2406.        else
  2407.          {
  2408.           if (isalpha(*(string+i))
  2409.           ||  isdigit(*(string+i))
  2410.           ||  *(string+i) == '_'
  2411.           ||  *(string+i) > 128)
  2412.              break;
  2413.          }
  2414.       }
  2415.     *first_col = i+1;
  2416.    }
  2417. #ifdef TRACE
  2418.  trace_return();
  2419. #endif
  2420.  return(1);
  2421. }
  2422. /***********************************************************************/
  2423. #ifdef HAVE_PROTO
  2424. short my_wmove(WINDOW *win,short scridx,short winidx,short y,short x)
  2425. #else
  2426. short my_wmove(win,scridx,winidx,y,x)
  2427. WINDOW *win;
  2428. short scridx,winidx,y,x;
  2429. #endif
  2430. /***********************************************************************/
  2431. {
  2432. /*-------------------------- external data ----------------------------*/
  2433.  extern bool curses_started;
  2434. /*--------------------------- local data ------------------------------*/
  2435.  short rc=RC_OK;
  2436. /*--------------------------- processing ------------------------------*/
  2437. #ifdef TRACE
  2438.  trace_function("util.c:    my_wmove");
  2439. #endif
  2440. /*---------------------------------------------------------------------*/
  2441. /* If the scridx or winidx are -1, do not try to save the x/y position.*/
  2442. /*---------------------------------------------------------------------*/
  2443.  if (scridx != (-1)
  2444.  &&  winidx != (-1))
  2445.    {
  2446.     screen[scridx].screen_view->x[winidx] = x;
  2447.     screen[scridx].screen_view->y[winidx] = y;
  2448.    }
  2449.  if (curses_started)
  2450.     wmove(win,y,x);
  2451. #ifdef TRACE
  2452.  trace_return();
  2453. #endif
  2454.  return(rc);
  2455. }
  2456. /***********************************************************************/
  2457. #ifdef HAVE_PROTO
  2458. short get_row_for_tof_eof(short row,CHARTYPE scridx)
  2459. #else
  2460. short get_row_for_tof_eof(row,scridx)
  2461. short row;
  2462. CHARTYPE scridx;
  2463. #endif
  2464. /***********************************************************************/
  2465. {
  2466. /*-------------------------- external data ----------------------------*/
  2467. /*--------------------------- local data ------------------------------*/
  2468. /*--------------------------- processing ------------------------------*/
  2469. #ifdef TRACE
  2470.  trace_function("util.c:    get_row_for_tof_eof");
  2471. #endif
  2472.  if (screen[scridx].sl[row].line_type == LINE_OUT_OF_BOUNDS_ABOVE)
  2473.    {
  2474.     for(;screen[scridx].sl[row].line_type != LINE_TOF;row++)
  2475. /*    for(;screen[scridx].sl[row].line_type != LINE_TOF_EOF;row++) MH12 */
  2476.        ;
  2477.    }
  2478.  if (screen[scridx].sl[row].line_type == LINE_OUT_OF_BOUNDS_BELOW)
  2479.    {
  2480. /*    for(;screen[scridx].sl[row].line_type != LINE_TOF_EOF;row--) MH12 */
  2481.     for(;screen[scridx].sl[row].line_type != LINE_EOF;row--)
  2482.        ;
  2483.    }
  2484. #ifdef TRACE
  2485.  trace_return();
  2486. #endif
  2487.  return(row);
  2488. }
  2489. #ifndef HAVE_DOUPDATE
  2490. /***********************************************************************/
  2491. #ifdef HAVE_PROTO
  2492. int doupdate(void)
  2493. #else
  2494. int doupdate()
  2495. #endif
  2496. /***********************************************************************/
  2497. {
  2498. /*-------------------------- external data ----------------------------*/
  2499. /*--------------------------- local data ------------------------------*/
  2500.  unsigned short y=0,x=0;
  2501. /*--------------------------- processing ------------------------------*/
  2502. #ifdef TRACE
  2503.  trace_function("util.c:    doupdate");
  2504. #endif
  2505.  getyx(CURRENT_WINDOW,y,x);
  2506.  refresh();
  2507.  wmove(CURRENT_WINDOW,y,x);
  2508.  wrefresh(CURRENT_WINDOW);
  2509. #ifdef TRACE
  2510.  trace_return();
  2511. #endif
  2512.  return(0);
  2513. }
  2514. #endif
  2515.  
  2516. #ifdef USE_EXTCURSES
  2517. /***********************************************************************/
  2518. #ifdef HAVE_PROTO
  2519. int has_colors(void)
  2520. #else
  2521. int has_colors()
  2522. #endif
  2523. /***********************************************************************/
  2524. {
  2525. /*--------------------------- local data ------------------------------*/
  2526. /*--------------------------- processing ------------------------------*/
  2527.  return(TRUE);
  2528. }
  2529. /***********************************************************************/
  2530. #ifdef HAVE_PROTO
  2531. int start_color(void)
  2532. #else
  2533. int start_color()
  2534. #endif
  2535. /***********************************************************************/
  2536. {
  2537. /*--------------------------- local data ------------------------------*/
  2538.  register int i=0;
  2539. /*--------------------------- processing ------------------------------*/
  2540.  for (i=0;i<COLOR_PAIRS;i++)
  2541.    color_pair[i] = NORMAL;
  2542.  fore_color[COLOR_BLACK  ] = F_BLACK  ;
  2543.  fore_color[COLOR_BLUE   ] = F_BLUE   ;
  2544.  fore_color[COLOR_GREEN  ] = F_GREEN  ;
  2545.  fore_color[COLOR_CYAN   ] = F_CYAN   ;
  2546.  fore_color[COLOR_RED    ] = F_RED    ;
  2547.  fore_color[COLOR_MAGENTA] = F_MAGENTA;
  2548.  fore_color[COLOR_YELLOW ] = F_BROWN  ;
  2549.  fore_color[COLOR_WHITE  ] = F_WHITE  ;
  2550.  back_color[COLOR_BLACK  ] = B_BLACK  ;
  2551.  back_color[COLOR_BLUE   ] = B_BLUE   ;
  2552.  back_color[COLOR_GREEN  ] = B_GREEN  ;
  2553.  back_color[COLOR_CYAN   ] = B_CYAN   ;
  2554.  back_color[COLOR_RED    ] = B_RED    ;
  2555.  back_color[COLOR_MAGENTA] = B_MAGENTA;
  2556.  back_color[COLOR_YELLOW ] = B_BROWN  ;
  2557.  back_color[COLOR_WHITE  ] = B_WHITE  ;
  2558.  return(0);
  2559. }
  2560. /***********************************************************************/
  2561. #ifdef HAVE_PROTO
  2562. int init_pair(int pairnum,chtype fore,chtype back)
  2563. #else
  2564. int init_pair(pairnum,fore,back)
  2565. int pairnum;
  2566. chtype fore,back;
  2567. #endif
  2568. /***********************************************************************/
  2569. {
  2570. /*--------------------------- local data ------------------------------*/
  2571.  register int i=0;
  2572. /*--------------------------- processing ------------------------------*/
  2573.  color_pair[pairnum] = fore_color[fore] | back_color[back];
  2574.  return(0);
  2575. }
  2576. #endif
  2577.