root/trunk/cidump.c

Revision 389, 9.1 kB (checked in by heitor.barbieri, 3 weeks ago)

essage first commit

Line 
1/**
2* Funcoes utilizadas pelo modulo ciupdxslt.c para transformacao XSLT.
3**/
4
5#if PROCXSLT
6
7struct TagOcc {
8    int tag;
9    int occ;
10    struct TagOcc *next;
11};
12
13typedef struct TagOcc OccLst;
14
15int getOcc(OccLst **top,
16           int tag) {
17    OccLst *current = NULL;
18
19    if (tag <= 0) {
20        fatal("cidump/getOcc/tag <= 0");
21    }
22    for (current = *top; current; current = current->next) {
23        if (current->tag == tag) {
24            current->occ++;
25            break;
26        }
27    }
28    if (current == NULL) {
29        current = (OccLst *)malloc(sizeof(OccLst));
30        if (current == NULL) {
31            fatal("cidump/getOcc/malloc");
32        }
33        current->tag = tag;
34        current->occ = 1;
35        current->next = *top;
36        *top = current;
37    }
38
39    return current->occ;
40}
41
42void deleteList(OccLst **top) {
43    OccLst *current = *top;
44    OccLst *next = NULL;
45
46    while(current) {
47        next = current->next;
48        free(current);
49        current = next;
50    }
51    *top = NULL;
52}
53
54char *dumpRecord1(RECSTRU *crecp,
55                  RECSTRU *recp,
56                  char *areap,
57                  char *area2p) {
58
59    if ((crecp != NULL) && (recp != NULL)  &&
60        (areap != NULL) && (area2p != NULL) && (MFRstatus == ACTIVE)) {
61
62        int xdir = 0;
63        int loop = 0;
64        int xocc = 0;
65        int xtag = 0;
66        FFI xlen = 0;
67        char stag = 0;
68        int socc = 0;
69        int spos = 0;
70        FFI slen = 0;
71        char *p = areap;
72        char *q = area2p;
73        char *cur = NULL;
74        char *f = NULL;
75        char *xxconvent[256];
76        RECSTRU *arecp = recp;
77        OccLst *ftop = NULL;
78        OccLst *stop = NULL;
79
80        *p = '\0';
81
82        /* chars to entities */
83        memset(xxconvent, 0x00, sizeof(xxconvent));
84        xxconvent['&']="&amp;";
85        xxconvent['<']="&lt;";
86        xxconvent['>']="&gt;";
87        xxconvent['"']="&quot;";
88        xxconvent['\'']="&#39;";
89        xxconvent['|']="%7C";
90
91        // registro de controle
92        recp = crecp;
93        sprintf(p, "<masterfile name=\"%s\" nxtmfn=\"%"_LD_"\" mftype=\"%d\" ewlock=\"%"_LD_"\">\n",
94                RDBname, MF0nxtmfn, MF0mftype, MF0mfcxx3);
95        p += strlen(p);
96        recp = arecp;
97
98        sprintf(p, "<record mfn=\"%"_LD_"\" nvf=\"%d\" base=\"%"_LD_"\" len=\"%"_LD_"\" status=\"%s\" rclock=\"%d\">\n",
99                MFRmfn, MFRnvf, (LONGX)MFRbase, (LONGX)MFRmfrl,
100                (MFRstatus == ACTIVE) ? "active" : "deleted", REClock);
101        p += strlen(p);
102
103        for (xdir = 0, loop = MFRnvf; loop--; xdir++) {
104            xtag = DIRtag(xdir);
105            xlen = DIRlen(xdir);
106            xocc = getOcc(&ftop, xtag);
107            stag = 0;
108            spos = 0;
109            stop = NULL;
110
111            sprintf(p, "<field iocc=\"%d\" tag=\"%u\" occ=\"%d\" len=\"%"_LD_"\">",
112                    xdir+1, xtag, xocc, (LONGX)xlen);
113            p += strlen(p);
114
115            cur = f = FIELDP(xdir);
116
117            for (; xlen--; cur++) {
118                if (*cur == '^') {
119                    if (stag > 0) {
120                        socc = getOcc(&stop, stag);
121                        slen = (int)((cur - f) - spos - 1);
122                        sprintf(p, "<subfield tag=\"%c\" occ=\"%d\" pos=\"%d\" len=\"%"_LD_"\">",
123                                stag, socc, spos, slen);
124                        p += strlen(p);
125                        area2p[slen] = 0;
126                        strcpy(p, area2p);
127                        p += strlen(p);
128                        strcpy(p, "</subfield>");
129                        p += strlen(p);
130                    }
131                    stag = *++cur;
132                    xlen--;
133                    spos = (int)(cur - f);
134                    q = area2p;
135                } else {
136                    if (stag > 0) {
137                        if (xxconvent[*cur]) {
138                            strcpy(q, xxconvent[*cur]);
139                            q += strlen(q);
140                        } else {
141                            *q++ = (*cur);
142                        }
143                    } else {
144                        if (xxconvent[*cur]) {
145                            strcpy(p,xxconvent[*cur]);
146                            p += strlen(p);
147                        } else {
148                            *p++ = (*cur);
149                        }
150                    }
151                }
152            }
153            if (stag > 0) {
154                socc = getOcc(&stop, stag);
155                slen = (int)((cur - f) - spos - 1);
156                sprintf(p, "<subfield tag=\"%c\" occ=\"%d\" pos=\"%d\" len=\"%"_LD_"\">",
157                        stag, socc, spos, slen);
158                p += strlen(p);
159                area2p[slen] = 0;
160                strcpy(p, area2p);
161                p += strlen(p);
162                strcpy(p, "</subfield>");
163                p += strlen(p);
164            }
165            sprintf(p, "</field>\n");
166            p += strlen(p);
167        }
168
169        strcpy(p,"</record>\n");
170        p += strlen(p);
171        strcpy(p, "</masterfile>");
172
173        deleteList(&stop);
174        deleteList(&ftop);
175    }
176
177    return areap;
178}
179
180char * dumpRecord2(RECSTRU *crecp,
181                   RECSTRU *recp,
182                   char *areap,
183                   char *area2p) {
184
185    if ((crecp != NULL) && (recp != NULL)  &&
186        (areap != NULL) && (area2p != NULL) && (MFRstatus == ACTIVE)) {
187
188        int xdir = 0;
189        int loop = 0;
190        int xocc = 0;
191        int xtag = 0;
192        FFI xlen = 0;
193        char stag = 0;
194        int socc = 0;
195        int spos = 0;
196        FFI slen = 0;
197        char *p = areap;
198        char *q = area2p;
199        char *cur = NULL;
200        char *f = NULL;
201        char *xxconvent[256];
202        RECSTRU *arecp = recp;
203        OccLst *ftop = NULL;
204        OccLst *stop = NULL;
205
206        *p = '\0';
207
208        /* chars to entities */
209        memset(xxconvent, 0x00, sizeof(xxconvent));
210        xxconvent['&']="&amp;";
211        xxconvent['<']="&lt;";
212        xxconvent['>']="&gt;";
213        xxconvent['"']="&quot;";
214        xxconvent['\'']="&#39;";
215        xxconvent['|']="%7C";
216
217        sprintf(p,"<isis>\n");
218        p += strlen(p);
219
220        // registro de controle
221        recp = crecp;
222        sprintf(p, "<item type=\"masterfile\" name=\"%s\" nxtmfn=\"%"_LD_"\" mftype=\"%d\" ewlock=\"%"_LD_"\"/>\n",
223                RDBname, MF0nxtmfn, MF0mftype, MF0mfcxx3);
224        p += strlen(p);
225        recp = arecp;
226
227        sprintf(p, "<item type=\"record\" mfn=\"%"_LD_"\" nvf=\"%d\" base=\"%"_LD_"\" len=\"%"_LD_"\" status=\"%s\" rclock=\"%d\"/>\n",
228                MFRmfn, MFRnvf, (LONGX)MFRbase, (LONGX)MFRmfrl,
229                (MFRstatus == ACTIVE) ? "active" : "deleted", REClock);
230        p += strlen(p);
231
232        for (xdir = 0, loop = MFRnvf; loop--; xdir++) {
233            xtag = DIRtag(xdir);
234            xlen = DIRlen(xdir);
235            xocc = getOcc(&ftop, xtag);
236            stag = 0;
237            spos = 0;
238            stop = NULL;
239
240            sprintf(p, "<item type=\"field\" iocc=\"%d\" tag=\"%u\" occ=\"%d\" len=\"%"_LD_"\">",
241                        xdir+1, xtag, xocc, (LONGX)xlen);
242            p += strlen(p);
243            cur = f = FIELDP(xdir);
244            for (; xlen--; cur++) {
245                if (*cur == '^') {
246                    if (stag > 0) {
247                        socc = getOcc(&stop, stag);
248                        slen = (int)((cur - f) - spos - 1);
249                        sprintf(p, "<item type=\"subfield\" tag=\"%d\" occ=\"%d\" dlm=\"%c\" socc=\"%d\" pos=\"%d\" len=\"%"_LD_"\">",
250                                xtag, xocc, stag, socc, spos, slen);
251                        p += strlen(p);
252                        area2p[slen] = 0;
253                        strcpy(p, area2p);
254                        p += strlen(p);
255                    }
256                    strcpy(p, "</item>\n");
257                    p += strlen(p);
258                    stag = *++cur;
259                    xlen--;
260                    spos = (int)(cur - f);
261                    q = area2p;
262                } else {
263                    if (stag > 0) {
264                        if (xxconvent[*cur]) {
265                            strcpy(q, xxconvent[*cur]);
266                            q += strlen(q);
267                        } else {
268                            *q++ = (*cur);
269                        }
270                    } else {
271                        if (xxconvent[*cur]) {
272                            strcpy(p,xxconvent[*cur]);
273                            p += strlen(p);
274                        } else {
275                            *p++ = (*cur);
276                        }
277                    }
278                }
279            }
280
281            if (stag > 0) {
282                socc = getOcc(&stop, stag);
283                slen = (int)((cur - f) - spos - 1);
284                sprintf(p, "<item type=\"subfield\" tag=\"%d\" occ=\"%d\" dlm=\"%c\" socc=\"%d\" pos=\"%d\" len=\"%"_LD_"\">",
285                                xtag, xocc, stag, socc, spos, slen);
286                p += strlen(p);
287                area2p[slen] = 0;
288                strcpy(p, area2p);
289                p += strlen(p);
290            }
291            strcpy(p, "</item>\n");
292            p += strlen(p);
293        }
294        strcpy(p,"</isis>");
295
296        deleteList(&stop);
297        deleteList(&ftop);
298    }
299
300    return areap;
301}
302
303#endif /* PROCXSLT */
Note: See TracBrowser for help on using the browser.