root/trunk/ciupdsplt.c

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

essage first commit

Line 
1
2
3/* Begin PROCXSPLIREC
4*/
5#if PROCXSPLIREC
6             if (strncmp(p,"split=",6) == 0 || strncmp(p,"split/clean=",12) == 0) {
7            char *xarea=NULL;
8            LONGX nbytes;
9            int trigrams=0;
10            char lasttrigchr1='\0';
11            char *q;
12            LONGX xtag;
13            char c1='\r';
14            char c2='\n';
15            int clean=0;
16            char tabsplit[256];
17            int b2a=0;
18            short int b2ashort;
19            LONGX b2along;
20            int letteroption=0;
21#define MAXNWORDS 4000
22            int sixwords=0;
23            char *vwordsp[MAXNWORDS];
24            short int vwordsn[MAXNWORDS];
25            short int vwordsx[MAXNWORDS+1];
26            char tabperiod[256];
27            LONGX sixwordsitrm=(-1);  /**/
28            char *sixwordsif=NULL;   /**/
29#if INCPRECX
30            TRMSTRU *trmp=NULL;      /**/
31#endif /* INCPRECX */
32
33            nbytes=MFRmfrl+BUFSIZ;
34            nbytes+=(MFRmfrl>BUFSIZ)?MFRmfrl:BUFSIZ; /* <== */
35
36            if (strncmp(p,"split/clean=",12) == 0) { clean=1; p+=12; }
37            else p+=6;
38            if (sscanf(p,"%"_LD_,&xtag) != 1) fatal("fldupdat/procx/Gsplit/tag");
39            while (isdigit(*p)) p++;
40            memset(tabperiod,0x00,sizeof(tabperiod));
41            memset(tabsplit,0x00,sizeof(tabsplit));
42            tabsplit[c1]=1;
43            tabsplit[c2]=1;
44            if (*p == '=') {
45                p++;
46                if (strncmp(p,"wtrig",5) == 0) {
47                  b2a=1;
48                  memset(tabsplit,0x00,sizeof(tabsplit));
49                  p+=5;
50                }
51                else
52                if (strncmp(p,"short",5) == 0) {
53                  b2a=sizeof(b2ashort);
54                  memset(tabsplit,0x00,sizeof(tabsplit));
55                  p+=5;
56                }
57                else
58                if (strncmp(p,"long",4) == 0) {
59                  b2a=sizeof(b2along);
60                  memset(tabsplit,0x00,sizeof(tabsplit));
61                  p+=4;
62                }
63                else
64                if (strncmp(p,"words",5) == 0) {
65                  int i;
66                  for (i=0; i<sizeof(tabsplit); i++) tabsplit[i]=1-isiswctab[i];
67                  p+=5;
68                }
69                else
70                if (strncmp(p,"6words",6) == 0
71#if INCPRECX
72                 || strncmp(p,"6words/if=",10) == 0
73#endif /* INCPRECX */
74                ) {
75                  int i;
76                  for (i=0; i<sizeof(tabsplit); i++) tabsplit[i]=1-isiswctab[i];
77                  p+=6;
78                  sixwords=1;
79                  tabperiod['.']=tabperiod[',']=tabperiod[';']=tabperiod[':']=1;
80#if INCPRECX
81                  if (strncmp(p,"/if=",4) == 0) {
82                    p+=4;
83                    sixwordsif=p; p+=strlen(p);
84                    sixwordsitrm=(-1);
85#if CICPP
86                    try { trmp=new TRMSTRU(cisisxp); }
87                    catch (BAD_ALLOC) { fatal("fldupdat/procx/Gsplit/next"); }
88#else /* CICPP */
89                    for (sixwordsitrm=maxntrm; sixwordsitrm--; ) {
90                      if (!vtrmp[sixwordsitrm]) /* ja' decrementado */
91                        break;
92                    }
93                    if (!sixwordsitrm) fatal("fldupdat/procx/Gsplit/next");
94#endif /* CICPP */
95                  }
96#endif /* INCPRECX */
97                }
98                else
99                if (strncmp(p,"letters",7) == 0 || strncmp(p,"letter1",7) == 0 || strncmp(p,"letterA",7) == 0) {
100                  int i;
101                  letteroption=(strncmp(p,"letter1",7) == 0) ? 1 : 0;
102                  letteroption=(strncmp(p,"letterA",7) == 0) ? 2 : letteroption;
103                  memset(tabsplit,0x01,sizeof(tabsplit));
104                  for (i=(int)'A'; i<=(int)'Z'; i++) tabsplit[i]=0;
105                  if (letteroption == 0) for (i=(int)'a'; i<=(int)'z'; i++) tabsplit[i]=0;
106                  if (letteroption == 1) for (i=(int)'a'; i<=(int)'z'; i++) tabsplit[i]=0;
107                  if (letteroption == 2) {
108                    //mx iso=\utl\charac\gansna.iso "pft=if v50.1>='A' and v50.1<='Z' then c21'tabsplit['f(val(v1),3,0)']=0; // 'v50/ fi" lw=0 now
109                    tabsplit[192]=0; // A grave
110                    tabsplit[193]=0; // A agudo
111                    tabsplit[194]=0; // A circu
112                    tabsplit[195]=0; // A til
113                    tabsplit[196]=0; // A trema
114                    tabsplit[197]=0; // A bola
115                    tabsplit[199]=0; // Cedilha
116                    tabsplit[200]=0; // E grave
117                    tabsplit[201]=0; // E agudo
118                    tabsplit[202]=0; // E circu
119                    tabsplit[203]=0; // E trema
120                    tabsplit[204]=0; // I grave
121                    tabsplit[205]=0; // I agudo
122                    tabsplit[206]=0; // I circu
123                    tabsplit[207]=0; // I trema
124                    tabsplit[209]=0; // N til
125                    tabsplit[210]=0; // O grave
126                    tabsplit[211]=0; // O agudo
127                    tabsplit[212]=0; // O circu
128                    tabsplit[213]=0; // O til
129                    tabsplit[214]=0; // O trema
130                    tabsplit[217]=0; // U grave
131                    tabsplit[218]=0; // U agudo
132                    tabsplit[219]=0; // U circu
133                    tabsplit[220]=0; // U trema
134                    tabsplit[221]=0; // Y agudo
135                  }
136                  p+=7;
137                }
138                else
139                if (strncmp(p,"numbers",7) == 0) {
140                  int i;
141                  memset(tabsplit,0x01,sizeof(tabsplit));
142                  for (i=(int)'0'; i<=(int)'9'; i++) tabsplit[i]=0;
143                  p+=7;
144                }
145                else
146                if (strncmp(p,"trigrams",8) == 0) {
147                  int i;
148                  memset(tabsplit,0x01,sizeof(tabsplit));
149                  for (i=(int)'A'; i<=(int)'Z'; i++) tabsplit[i]=0;
150                  for (i=(int)'a'; i<=(int)'z'; i++) tabsplit[i]=0;
151                  for (i=(int)'0'; i<=(int)'9'; i++) tabsplit[i]=0;
152                  p+=8; trigrams=1;
153                }
154                else {
155                  c1=c2= *p;
156                  if (*p) p++;
157                  memset(tabsplit,0x00,sizeof(tabsplit));
158                  tabsplit[c1]=1;
159                }
160            }
161            if (*p) fatal("fldupdat/procx/Gsplit");
162            if (trigrams || sixwords) {
163              //nbytes=(MFRmfrl+1)*(1+3+1+1+1+3)+BUFSIZ; /* k+1 * 10 */
164              //nbytes=(MFRmfrl+1)*(1+5+1+1+1+4)+BUFSIZ; /* k+1 * 13 */
165              FFI haddlen = 1/*H*/ + 5/*tag*/ + 1/* */ + 1/*4*/ + 1/* */; /* =9 */
166              FFI ntrigs = 0;
167              FFI K;
168              FFI totlenwords=0;
169/*...*/
170              for (xdir=0; xdir < MFRnvf; xdir++) {
171                if (DIRtag(xdir) == (UWORD)xtag || !xtag) {
172                    char *addp=NULL;
173                    FFI addlen=0;
174                    FFI left=DIRlen(xdir);
175                    FFI len=0;
176                    char *fldp,*fldq;
177                    unsigned char uc;
178                    fldp=fldq=FIELDP(xdir);
179                    while (left) {
180                      /* upper case */
181                      uc = isisuctab[(unsigned char)*fldq]; 
182                      if (tabsplit[uc]) {
183                        fldq++; left--;
184                        if (len) {
185                          addp=fldp; addlen=len;
186                        }
187                        fldp=fldq;
188                        len=0;
189                      }
190                      else {
191                        fldq++; len++; left--;
192                        if (left == 0) {
193                          addp=fldp; addlen=len;
194                        }
195                      }
196                      if (addp) {
197                        if (addlen) {
198                            K = addlen;
199                            ntrigs += 4 + (K+1);
200                              /* dna!  distinguished first trig in word */
201                              /* dna!  peso 2 */
202                              /* d#    distinguished first letter in word */
203                              /* d s   initial space initial letter */
204                              /* dna   every each 1- to 3-letter trig */
205                            totlenwords+=21*(K+1); /* 6+5+4+3+2+1 */
206                        }
207                        addp=NULL; addlen=0;
208                      }
209                    } /* end while left */
210                } /* end tag */
211              } /* end xdir */
212              if (trigrams) nbytes = ntrigs*(haddlen+4) + BUFSIZ;
213              else nbytes = haddlen + totlenwords + BUFSIZ;
214              //printf(" + + nbytes=%"_LD_"\n",nbytes);
215/*...*/
216            } /* end if trigrams */
217#if CICPP
218            try { xarea = (char *) new char [nbytes]; }
219            catch (BAD_ALLOC) { xarea = (char *)ALLONULL; }
220#else /* CICPP */
221            xarea=(char *)ALLOC((ALLOPARM)nbytes);
222#endif /* CICPP */
223            if (xarea == (char *)ALLONULL) fatal("fldupdat/procx/Gsplit/ALLOC");
224            q=xarea;
225            if (xtag)
226              sprintf(q,"D%"_LD_,xtag);
227            else
228              sprintf(q,"D*");
229            q+=strlen(q);
230            for (xdir=0; xdir < MFRnvf; xdir++) {
231                if (DIRtag(xdir) == (UWORD)xtag || !xtag) {
232                    char *addp=NULL;
233                    FFI addlen=0;
234                    FFI left=DIRlen(xdir);
235                    FFI len=0;
236                    char *fldp=FIELDP(xdir);
237                    char *fldq=fldp;
238                    int nwords=0;
239                    int followperiod=0;
240                    int newperiod=1;
241                    if (b2a == 1) {
242                     /*char b2awterm[4+1];*/
243                     float b2aweight;
244                     unsigned short int usi_w;
245                     int b2a=sizeof(usi_w);
246                     while (left) {
247                        if (left < b2a+1) fatal("fldupdat/procx/Gsplit/b2a/left/w");
248                        memcpy((void *)&usi_w,fldq,b2a);
249                        fldq+=b2a; left-=b2a;
250                        b2aweight=(float)usi_w/(float)USHRT_MAX;
251                        sprintf(q,"<%"_LD_" 0>",(LONGX)DIRtag(xdir)); q+=strlen(q);
252                        while (left) {
253                          *q = *fldq++; left--;
254                          if (*q) q++; else break;
255                        }
256                        sprintf(q,"^w%f</%"_LD_">",b2aweight,(LONGX)DIRtag(xdir));
257                        q+=strlen(q);
258                     }
259                    }
260                    else
261                    if (b2a) {
262                     if (left % b2a) fatal("fldupdat/procx/Gsplit/b2a/left");
263                     while (left) {
264                      if (b2a == sizeof(b2ashort)) {
265                        memcpy((void *)&b2ashort,fldq,b2a);
266                        sprintf(q,"A%"_LD_"/%d/",(LONGX)DIRtag(xdir),b2ashort);
267                      } else {
268                        memcpy((void *)&b2along,fldq,b2a);
269                        sprintf(q,"A%"_LD_"/%"_LD_"/",(LONGX)DIRtag(xdir),b2along);
270                      }
271                      q+=strlen(q); fldq+=b2a; left-=b2a;
272                     }
273                    }
274                    else { /* not b2a */
275                     while (left) {
276                      unsigned char uc;
277                      /* upper case */
278                      //uc = isisuctab[(unsigned char)*fldq];  //printf("uc=%c\n",uc);
279                      uc = (letteroption) ? (unsigned char)*fldq : isisuctab[(unsigned char)*fldq]; 
280                      if (tabsplit[uc]) {
281                        if (tabperiod[(unsigned char)*fldq]) followperiod=1;
282                        fldq++; left--;
283                        if (len) {
284                          addp=fldp; addlen=len;
285                        }
286                        fldp=fldq;
287                        len=0;
288                      }
289                      else {
290                        fldq++; len++; left--;
291                        if (left == 0) {
292                          addp=fldp; addlen=len;
293                        }
294                      }
295                      if (addp) {
296                        if (clean) {
297                          unsigned char *p;  /* AOT, 24/06/2005 */
298                          FFI left;
299                          while (addlen) {
300                              if ((unsigned char)addp[0] <= ' ') { addp++; addlen--; }
301                              else break;
302                          }
303                          while (addlen) {
304                              if ((unsigned char)addp[addlen-1] <= ' ') addlen--;
305                              else break;
306                          }
307                          for (left=addlen, p=(unsigned char *)addp; left--; p++) if (*p < ' ') *p=' ';
308                        }
309                        if (addlen) {
310                          if (trigrams) { /* trigrams */
311                            char trig[4+1];
312                            int tlen=3;
313                            char *up;
314                            int loop;
315                            /* upper case */
316                            for (up=addp, loop=addlen; loop--; up++) *up = isisuctab[(unsigned char)*up];
317                            /* clean: other ' ' to 'Z' */
318                            for (up=addp, loop=addlen; loop--; up++)
319                                if (*up < ' ' || *up > 'Z') *up = '@';
320                            if (addlen < 3) tlen=addlen;
321
322                            /* dna! */
323                            memcpy(trig,addp,tlen); trig[tlen++]='!';
324                            sprintf(q,"H%"_LD_" %"_LD_" ",(LONGX)DIRtag(xdir),(LONGX)tlen); q+=strlen(q);
325                            memcpy(q,trig,tlen); q+=tlen;
326                            /* dna! - peso 2 */
327                            sprintf(q,"H%"_LD_" %"_LD_" ",(LONGX)DIRtag(xdir),(LONGX)tlen); q+=strlen(q);
328                            memcpy(q,trig,tlen); q+=tlen;
329                            tlen--;
330
331                            /* d# */
332                            sprintf(q,"H%"_LD_" %"_LD_" ",(LONGX)DIRtag(xdir),(LONGX)2); q+=strlen(q);
333                            *q++ = trig[0];
334                            *q++ = '#';
335
336                            /* d s */
337                            if (lasttrigchr1) {
338                              sprintf(q,"H%"_LD_" %"_LD_" ",(LONGX)DIRtag(xdir),(LONGX)3); q+=strlen(q);
339                              *q++ = lasttrigchr1;
340                              *q++ = ' ';
341                              *q++ = trig[0];
342                            }
343                            lasttrigchr1=trig[0];
344
345                            /* dna */
346                            sprintf(q,"H%"_LD_" %"_LD_" ",(LONGX)DIRtag(xdir),(LONGX)tlen); q+=strlen(q);
347                            memcpy(q,trig,tlen); q+=tlen;
348                            while (addlen > 3) {
349                              addp++;
350                              sprintf(q,"H%"_LD_" %"_LD_" ",(LONGX)DIRtag(xdir),(LONGX)3); q+=strlen(q);
351                              memcpy(q,addp,3); q+=3;
352                              addlen--;
353                            }
354
355                          }
356                          else if (sixwords) { /* sixwords: store */
357                            vwordsp[nwords]=addp;
358                            vwordsn[nwords]=addlen;
359                            vwordsx[nwords]=newperiod; nwords++;
360                            newperiod=followperiod; followperiod=0;
361                          }
362                          else { /* words */
363                            if (letteroption) if (addlen) addlen=1;
364                            if (addlen) {
365                              sprintf(q,"H%"_LD_" %"_LD_" ",(LONGX)DIRtag(xdir),(LONGX)addlen); q+=strlen(q);
366                              memcpy(q,addp,addlen); q+=addlen;
367                            }
368                          }
369                        }
370                        addp=NULL; addlen=0;
371                      }
372                     } /* end while left */
373                    }  /* end b2a */
374                    if (sixwords) {  /* sixwords: output */
375/*
376000002|     5077|OF
377000004|     2860|AND
378000006|     2530|DE
379000011|     1493|THE
380000019|      971|IN
381000031|      626|DO
382000035|      587|DA
383000061|      344|LA
384000103|      236|ET
385000110|      216|Y
386000112|      215|ON
387*/
388                     int loop,loop2,loop3,n,i;
389                     FFI len=0;
390                     char *lenp;
391                     FFI oldlen; /**/
392                     char *oldq; /**/
393
394
395                     sprintf(q,"H%"_LD_" ",(LONGX)xtag); q+=strlen(q);
396                     sprintf(lenp=q,"123456789 "); q+=strlen(q);
397                     vwordsx[nwords]=1;
398                     for (loop=0; loop < nwords; loop++) {
399                      oldq=q; oldlen=len;
400                      memcpy(q,vwordsp[loop],n=vwordsn[loop]); q+=n; len+=n;
401                      if (sixwordsif) {
402#if INCPRECX
403                        *q='\0';
404#if CICPP
405                        trmp->xterm((unsigned char *)sixwordsif,(unsigned char *)oldq);
406#else /* CICPP */
407                        TERM(sixwordsitrm,(unsigned char *)sixwordsif,(unsigned char *)oldq);
408#endif /* CICPP */
409                        if (TRMrc==RCNORMAL) {
410                          *q++='\n'; len++;
411                        } else {
412                          q=oldq; len=oldlen;
413                        }
414#endif /* INCPRECX */
415                      } else {
416                        *q++='\n'; len++;
417                      }
418                      for (loop2=1; loop2 <= 5; loop2++) {
419                        if ((n=loop+loop2) == nwords) break;
420                        if (vwordsx[n]) break;
421                        oldq=q; oldlen=len;
422                        memcpy(q,vwordsp[loop],n=vwordsn[loop]); q+=n; len+=n;
423                        for (loop3=0; loop3 < loop2; loop3++ ) {
424                          *q++=' '; len++;
425                          i=loop+1+loop3;
426                          memcpy(q,vwordsp[i],n=vwordsn[i]); q+=n; len+=n;
427                        }
428                        if (sixwordsif) {
429#if INCPRECX
430                          *q='\0';
431#if CICPP
432                          trmp->xterm((unsigned char *)sixwordsif,(unsigned char *)oldq);
433#else /* CICPP */
434                          TERM(sixwordsitrm,(unsigned char *)sixwordsif,(unsigned char *)oldq);
435#endif /* CICPP */
436                          if (TRMrc==RCNORMAL) {
437                            *q++='\n'; len++;
438                          }
439                          else {
440                            q=oldq; len=oldlen;
441                          }
442#endif /* INCPRECX */
443                        } else {
444                          *q++='\n'; len++;
445                        }
446                      }
447                     }
448                     sprintf(lenp,"%9"_LD_,(LONGX)len); lenp[9]=' ';
449                    } /* end sixwords */
450                } /* end tag */
451            } /* end xdir */
452
453            *q='\0';
454
455             //printf(" + + nbytes=%"_LD_" x %d \n",nbytes,strlen(xarea));
456             
457#if CICPP
458     delete trmp;
459#else /* CICPP */
460     if (sixwordsitrm>=0L) if (vtrmp[sixwordsitrm]!=NULL) { /**/
461          FREE(vtrmp[sixwordsitrm]); vtrmp[sixwordsitrm]=NULL; ntrms--;
462     }
463#endif /* CICPP */
464#if CICPP
465        if (recp->xfldupdat(xarea)) fatal(errp);
466        delete xarea;
467#else /* CICPP */
468        if (fldupdat(irec,xarea)) fatal(errp);
469        if (xarea) FREE(xarea);
470#endif /* CICPP */
471
472        return NULL; //isgdump=1;
473
474        }
475        else
476#endif /* PROCXSPLIREC */
477/* End PROCXSPLIREC
478*/
Note: See TracBrowser for help on using the browser.