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