root/tags/5.4.pre05/wxis_src/hlfill.c

Revision 1, 3.9 kB (checked in by heitor.barbieri, 4 years ago)

Criação do svn para Cisis.

Line 
1/* ---------------------------------------------------------------- HLFILL.C */
2
3/* /////////////////////////////////////////////////////////////////////////
4
5   [ Version 1.0 ]
6   01.Dez.1998 - High light text filler.
7
8   ///////////////////////////////////////////////////////////////////////// */
9
10/* ---------------------------------------------------------- C HEADER FILES */
11#include <string.h>
12/* ------------------------------------------------------------ HEADER FILES */
13#include "../cisis.h"
14#include "easyfc.h"
15#include "easyci.h"
16#include "hlfill.h"
17
18/* ================================================================= hl_find */
19long hl_find(char *comp,                /* compare text */
20             char *key,                 /* find key */
21             BOOLEAN truncate)          /* truncate flag */
22{
23/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
24        1. Set key size
25   2. Loop all characters
26   3. Find key
27   4. Check "word" separator
28   5. Return character position where the key was found
29   6. Return key not found indicator
30
31   1.0 - 01.Dez.1998
32>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
33   unsigned char *p;    /* auxiliary loop pointer */
34   long pos;         /* position in the string */
35   long findsize;    /* size of the find key */
36
37        /* 1 */
38   findsize = strlen(key);
39
40        /* 2 */
41   for (p = comp,pos = 0L; *p; p++,pos++) {
42
43                /* 3 */
44      if (*p != *key) continue;
45      if (strncmp(p,key,findsize) != 0) continue;
46
47                /* 4 */
48      if (pos)
49         if (isiswctab[*(p-1)]) continue;
50      if (!truncate)
51         if (*(p+findsize))
52            if (isiswctab[*(p+findsize)]) continue;
53
54                /* 5 */
55      return pos;
56
57   } /* for */
58
59        /* 6 */
60   return -1L;
61}
62/* ================================================================== hl_put */
63char *hl_put(char *origb,   /* original text */
64             char *key,     /* find key */
65             char *pfx,     /* prefix text */
66             char *sfx,     /* suffix text */
67             char *copyb)   /* destination text */
68{
69/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
70        1. Original text upper case copy
71   2. Texts size
72   3. Check truncate character
73   4. Scan all occurrences of the key
74   5. Find the key
75   6. Check if the key was found
76   7. Inserts prefix and suffix in the destination text
77   8. Inserts the remainding text
78   9. Garbage collector
79   10. Return destination text pointer
80
81   1.0 - 01.Dez.1998
82>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
83   unsigned char *upperb;               /* upper case of original text */
84   unsigned char *findkey;              /* find key */
85   unsigned char *p;                    /* upper case of original text loop pointer */
86   unsigned char *c;                    /* destination text loop pointer */
87   unsigned char *o;                                    /* original text loop pointer */
88   long lenkey;         /* size of the find key */
89   long lenpfx;         /* size of the prefix key */
90   long lensfx;         /* size of the suffix key */
91   long offset;         /* offset of characters from the beginning of the scan */
92   BOOLEAN truncate;            /* key truncate flag */
93
94        /* 1 */
95   upperb = eci_uctab(strdup(origb));
96   findkey = strdup(key);
97
98        /* 2 */
99   lenkey = strlen(findkey);
100   lenpfx = strlen(pfx);
101   lensfx = strlen(sfx);
102
103        /* 3 */
104   if (*(findkey+lenkey-1) != '$') truncate = FALSE;
105   else {
106      truncate = TRUE;
107      lenkey--;
108      *(findkey+lenkey) = '\0';
109   }
110
111        /* 4 */
112   for (p = upperb,c = copyb,o = origb; *p; p += offset+lenkey) {
113
114                /* 5 */
115      offset = hl_find(p,findkey,truncate);
116
117                /* 6 */
118      if (offset < 0) break;
119
120                /* 7 */
121      strncpy(c,o,offset);  c += offset; o += offset;
122      strcpy (c,pfx);       c += lenpfx;
123      strncpy(c,o,lenkey);  c += lenkey; o += lenkey;
124      strcpy (c,sfx);       c += lensfx;
125
126   } /* for */
127
128        /* 8 */
129   strcpy(c,o);
130
131        /* 9 */
132   efc_free(upperb);
133   efc_free(findkey);
134
135        /* 10 */
136   return copyb;
137}
Note: See TracBrowser for help on using the browser.