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

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

Criação do svn para Cisis.

Line 
1/* ----------------------------------------------------------------- CITPV.C */
2
3/* /////////////////////////////////////////////////////////////////////////
4
5   17.Jun.1997 - Adapted from PREVTRM.CPP and PREVTRM.HPP sources (HEITOR).
6
7   ///////////////////////////////////////////////////////////////////////// */
8
9/* -------------------------------------------------------------- C includes */
10#include <string.h>
11/* ---------------------------------------------------------------- includes */
12#include "../cisis.h"
13#define CIENV   0
14#if CIENV
15#include "globdef.h"
16#include "cienv.h"
17#else
18#include "easyfc.h"
19#include "easyci.h"
20#endif
21#include "citpv.h"
22
23/* ................................................. Previous Term functions */
24void IniPreviousTerm(prvtrm)
25STRUCT_PREVTERM *prvtrm;
26{
27 memset(prvtrm,0x00,sizeof(prvtrm));
28 PT_CharLimits (prvtrm);
29}
30
31void PT_CharLimits (prvtrm)
32STRUCT_PREVTERM *prvtrm;
33{
34 int Count = 0;
35 while ((Count < 32) && (isiswctab[Count] == 0)) /* Vai ate o caracter de espaco */
36  Count++;
37 prvtrm->PT_FirstChar = Count;
38
39 Count = 255;
40 while ((Count > prvtrm->PT_FirstChar) && (isiswctab[Count] == 0))
41  Count--;
42 prvtrm->PT_LastChar = Count;
43}
44
45void PT_Search(prvtrm)
46STRUCT_PREVTERM *prvtrm;
47{
48 /* Realiza busca horizontal do termo previo.
49    *** Vai-se cortando a palavra no meio ate' que a chave encontrada
50    *** por xterm seja diferente da chave inicial, a partir dai'
51    *** parte-se para a busca vertical.
52 */
53
54 unsigned char Ch;
55 unsigned char BCh;
56 unsigned char ECh;
57 unsigned char MCh;
58 size_t CLen;
59
60 prvtrm->PT_Begin = prvtrm->PT_WorkKey + (int)prvtrm->PT_DifPosition;
61 prvtrm->PT_End   = prvtrm->PT_WorkKey + strlen(prvtrm->PT_WorkKey) - 1;
62
63 while (prvtrm->PT_Begin < prvtrm->PT_End)
64 {
65  prvtrm->PT_Middle = prvtrm->PT_Begin + (prvtrm->PT_End - prvtrm->PT_Begin)/2;
66
67  if (prvtrm->PT_Begin == prvtrm->PT_End - 1)
68   prvtrm->PT_Middle = prvtrm->PT_End;
69
70  Ch = *prvtrm->PT_Middle;
71  *prvtrm->PT_Middle = '\0';
72
73  term (prvtrm->PT_iTrm, (UCHR*)prvtrm->PT_Trmp->trmdbxp->dbxname,
74     (UCHR*)prvtrm->PT_WorkKey);
75
76  if (strcmp ((char*)prvtrm->PT_Trmp->trmkey, (char*)prvtrm->PT_Key))
77  {
78   *prvtrm->PT_Middle = Ch;
79    prvtrm->PT_Begin  = prvtrm->PT_Middle;
80  }
81  else
82   prvtrm->PT_End = prvtrm->PT_Middle - 1;
83 }
84
85 /* Testa se ja' chegou ao termo previo. */
86 strcpy ((char*)prvtrm->PT_AuxWorkKey, (char*)prvtrm->PT_Trmp->trmkey);
87 nxterm (prvtrm->PT_iTrm);
88 /* RPIVA: Acrescentei o teste do fim do invertido */
89 if (prvtrm->PT_Trmp->trmrc != RCEOF &&
90  strcmp ((char*)prvtrm->PT_Trmp->trmkey, (char*)prvtrm->PT_Key) == 0)
91 {
92  strcpy ((char*)prvtrm->PT_WorkKey, (char*)prvtrm->PT_AuxWorkKey);
93  return;
94 }
95
96 CLen = strlen ((char*)prvtrm->PT_WorkKey);
97
98 while (CLen <= LE2)
99 {
100  BCh = prvtrm->PT_FirstChar;
101  ECh = prvtrm->PT_LastChar;
102
103  while (BCh < ECh)
104  {
105   MCh = BCh + (ECh - BCh) / 2;
106
107   if (BCh == ECh - 1)
108   MCh = ECh;
109
110   prvtrm->PT_WorkKey[CLen - 1] = MCh;
111
112   term (prvtrm->PT_iTrm, (UCHR*)prvtrm->PT_Trmp->trmdbxp->dbxname,
113      (UCHR*)prvtrm->PT_WorkKey);
114
115   if (strcmp ((char*)prvtrm->PT_Trmp->trmkey, (char*)prvtrm->PT_Key) < 0)
116    BCh = MCh;
117   else
118    ECh = MCh - 1;
119  }
120
121  prvtrm->PT_WorkKey[CLen - 1] = BCh;
122  prvtrm->PT_WorkKey[++CLen] = '\0';
123
124  term (prvtrm->PT_iTrm, (UCHR*)prvtrm->PT_Trmp->trmdbxp->dbxname,
125     (UCHR*)prvtrm->PT_WorkKey);
126  strcpy ((char*)prvtrm->PT_AuxWorkKey, (char*)prvtrm->PT_Trmp->trmkey);
127  nxterm (prvtrm->PT_iTrm);
128
129  if (strcmp ((char*)prvtrm->PT_Trmp->trmkey, (char*)prvtrm->PT_Key) == 0)
130  {
131   strcpy ((char*)prvtrm->PT_WorkKey, (char*)prvtrm->PT_AuxWorkKey);
132   return;
133  }
134 }
135}
136
137long PT_FindPreviousKey(prvtrm,limit,itrm,previous)
138STRUCT_PREVTERM *prvtrm;
139UCHAR           *limit;
140long             itrm;
141UCHAR           *previous;
142{
143 if (!limit || !vtrmp[itrm] || (*(VTRMkey(itrm)) == '\0'))
144 {
145  strcpy ((char*)previous, "");
146  return 0;
147 }
148
149 prvtrm->PT_Trmp = vtrmp[itrm];
150 prvtrm->PT_iTrm = itrm;
151
152 strncpy ((char*)prvtrm->PT_Limit, (char*)limit, LE2);
153 prvtrm->PT_Limit [LE2] = '\0';
154 /* GetIsisUctab (prvtrm->PT_Limit, prvtrm->PT_Limit); */
155#if CIENV
156 env_strtab(prvtrm->PT_Limit);
157#else
158 eci_uctab(prvtrm->PT_Limit);
159#endif
160
161 strcpy ((char*)prvtrm->PT_Key, (char*)prvtrm->PT_Trmp->trmkey);
162 strcpy ((char*)prvtrm->PT_WorkKey, (char*)prvtrm->PT_Key);
163
164 /* Verifica se limite inferior e' menor que a chave atual. */
165 if (strcmp ((char*)prvtrm->PT_Limit, (char*)prvtrm->PT_Key) >= 0)
166 {
167  strcpy ((char*)previous, "");
168  return 0;
169 }
170
171 /* Verifica se existe um termo previo. */
172 term (itrm, (UCHR *)VTDBname(itrm), prvtrm->PT_Limit);
173 if (!strcmp ((char*)prvtrm->PT_Trmp->trmkey, (char*)prvtrm->PT_Key))
174 {
175  strcpy ((char*)previous, "");
176  return 0;
177 }
178
179 /* Encontra a posicao de inicio das diferencas entre a chave e o limite. */
180 prvtrm->PT_DifPosition = 0;
181 while ((prvtrm->PT_Limit[(int)prvtrm->PT_DifPosition]!= '\0') &&
182   (prvtrm->PT_Limit[(int)prvtrm->PT_DifPosition] == prvtrm->PT_Key[(int)prvtrm->PT_DifPosition]))
183  prvtrm->PT_DifPosition++;
184
185
186 /* Efetivamente encontra o termo previo. */
187 PT_Search (prvtrm);
188
189 strcpy ((char*)previous, (char*)prvtrm->PT_WorkKey);
190
191 return 1;
192}
193/* ............................................................ TermPrevious */
194long TermPrevious(prvtrm,itrm,prefix,key)
195STRUCT_PREVTERM *prvtrm;
196long   itrm;
197UCHAR *prefix;
198UCHAR *key;
199{
200   if (!PT_FindPreviousKey(prvtrm,prefix,itrm,key)) return -1L;
201   term(itrm,VTDBname(itrm),key);
202   return VTRMxytotp(itrm);
203}
Note: See TracBrowser for help on using the browser.