#include #include #include #include #include void removechar (char *s, int c) { int i, l; l = strlen (s); if ((c >= l) || (c < 0)) return; for (i = c; i < l; i++) s[i] = s[i + 1]; } void removeallc (char *s, char c) { char *pos; while ((pos = strchr (s, c)) != 0) removechar (s, (long int) pos - (long int) s); } void normalizestr (char *s) { char *pos; while ((pos = strstr (s, "#~")) != 0) { removechar (s, (long int) pos - (long int) s); removechar (s, (long int) pos - (long int) s); } while (strchr (s, ' ') == s) removechar (s, 0); } void freadline(char *buff,FILE *f) { char c; while ((fread(&c,1,1,f)==1) && (c!='\n')) { *buff=c; buff++; } *buff=0; } int makePoDb(const char* sourceName,const char* outputName) { static bool open = false; int m=0,n=0,h=0; GDBM_FILE db; datum key,value; char *s,a[20000],b[2000],k[2000],v[2000]; int i,*np,nmax=0,co=-1,oldref[2000]; long int tim; FILE *mlf; bool nextIsFuzzy; bool isAMsgId=true; /* char keystring[1000],valuestring[1000]; */ /*Read headers, refnum end other info */ db = gdbm_open((char *)outputName,1024,GDBM_READER,0666,0); mlf = fopen(sourceName,"r"); if(strrchr(sourceName,'/')!=0) sourceName=strrchr(sourceName,'/')+1; if(!(db==0)) { printf("ciao\n"); key.dptr=a; strcpy(a,"__@REFNUM__"); key.dsize=strlen(a)+1; value = gdbm_fetch(db,key); np=(int*)value.dptr; nmax=*np; for(i=0;i",oldref[co],*re); if(oldref[r]==*re) { modif=true; // fprintf(stderr,"Yes\n"); *re=(nmax-1); } //else fprintf(stderr,"No\n"); } // fprintf(stderr,"qui\n"); if(!modif) md=nr; // fprintf(stderr,"modif %s\n",modif ? "true":"false"); } } } if(!exist) { int oldlen=(long int)os-(long int)oldvalue.dptr-4; memcpy(a+4,oldvalue.dptr+4,oldlen); // fprintf(stderr,"***!exist Old len is %d+4 1st str is %s\n",oldlen,a+4); v++; t=(int *)a; *t=v; // fprintf(stderr,"b=%s",b); strcpy(a+4+oldlen,b); re=(int *)(a+4+oldlen+strlen(b)+1); *re=1; re++; *re=nmax-1; //fprintf(stderr,"a+4=%s a+4+oldlen=%s",a+4,a+4+oldlen); value.dptr=a; value.dsize=oldlen+strlen(b)+1+4+8; gdbm_store(db,key,value,GDBM_REPLACE); n++; } else { if(!modif) { // fprintf(stderr,"grossa crisi %d\n",*md); // fprintf(stderr,"Old num of ref \n"); int oldlen1=(long int)(md)-(long int)(oldvalue.dptr)-4; int oldlen2=(long int)(os)-(long int)(md)-4; //-4 because nr memcpy(a+4,oldvalue.dptr+4,oldlen1); memcpy(a+4+oldlen1+8,oldvalue.dptr+4+oldlen1+4,oldlen2); re=(int *)(a+4+oldlen1); *re=(*md )+1; // *re++; re++; *re=nmax-1; t=(int *)a; *t=v; value.dptr=a; value.dsize=oldlen1+oldlen2+4+8; gdbm_store(db,key,value,GDBM_REPLACE); n++; } else //if (modif) { value.dptr=oldvalue.dptr; value.dsize=oldvalue.dsize; gdbm_store(db,key,value,GDBM_REPLACE); } } h++; } else { m++; } } } } } fclose(mlf); gdbm_close(db); open=false; printf("new Key in database %d\n old key found %d\n value added %d\n",m,h,n); return m+n; } main(int argc,char **argv) { int i; for(i=1;i