libsrc/spanf1.cxx

Go to the documentation of this file.
00001 /**********************************************************************
00002  * Copyright 2002 Jeff Rush <jrush@taupro.com>
00003  * Original Copyright 1979-2002 Udanax.com
00004  *
00005  * This file is part of the Udanax xanalogical storage system.
00006  *
00007  * Udanax is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * Udanax is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with Udanax; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  **********************************************************************/
00021 
00030 /* Modification History:
00031  * $Log: spanf1.cxx,v $
00032  * Revision 1.14  2004/09/11 13:59:21  jrush
00033  * Changed all fprintf's to stderr to use the Nana library L() macro.  Also
00034  * removed a 2-3 minor compiler warnings.
00035  *
00036  * Revision 1.13  2004/09/04 16:02:18  jrush
00037  * Added Doxygen headers before each and every function definition.
00038  *
00039  * Revision 1.12  2002/07/26 04:32:01  jrush
00040  * Replaced gerror() with assert()
00041  *
00042  * Revision 1.11  2002/05/28 04:22:29  jrush
00043  * Adjusted source files to comply with GPL licensing.
00044  *
00045  * Revision 1.10  2002/05/28 02:52:23  jrush
00046  * Made static any functions and global variables private to this source file
00047  * and commented out any unused functions.
00048  *
00049  * Revision 1.9  2002/04/12 11:56:43  jrush
00050  * Reorganized include file layout, renamed xanadu.h to udanax.h and
00051  * typecontext/typecrumcontext to C++ class Context/CrumContext.
00052  *
00053  * Revision 1.8  2002/04/10 18:01:54  jrush
00054  * Renamed class typeisa to IStreamAddr.
00055  *
00056  * Revision 1.7  2002/04/09 21:45:46  jrush
00057  * Renamed class 'tumbler' to 'Tumbler', for consistency with Python sources,
00058  * and changed typeisa from typedef to a subclass, in preparation for cleaning
00059  * up the type/class tree.
00060  *
00061  * Revision 1.6  2002/04/06 20:42:50  jrush
00062  * Switch from sess->alloc() style to new(sess) Object parameterized allocator.
00063  *
00064  * Revision 1.5  2002/04/06 19:51:30  jrush
00065  * Renamed TRUE/FALSE constant use to the C++ standard of true/false.
00066  *
00067  * Revision 1.4  2002/04/06 17:05:57  jrush
00068  * Switched from referring to 'task' for a client connection to 'session',
00069  * and converted the typetask typedef/struct into a Session C++ class.
00070  *
00071  * Revision 1.3  2002/04/06 15:01:17  jrush
00072  * Changed INT to just 'int'.
00073  *
00074  * Revision 1.2  2002/02/14 09:27:43  jrush
00075  * Cleaned up source:
00076  *
00077  * 1. ran thru the indent tool to achieve a standard look,
00078  * 2. added structured comments at top for use with DOxygen reporting
00079  *    as well as CVS keywords,
00080  * 3. fixed compiler warnings re ambiguous assign/compares,
00081  *    needed casts and unused/uninitialized variables,
00082  * 4. fixed funcs that didn't specify a return type,
00083  * 5. centralized prototypes in protos.h, removing incomplete ones,
00084  * 6. cleaned up use of bool/BOOLEAN type to suit C++ type,
00085  * 7. fixed initializer nesting in tumbler constants,
00086  * 8. renamed vars that conflict with C++ keywords (new, this),
00087  * 9. fixed global/extern confusion re some global vars.
00088  *
00089  */
00090 
00091 #include <memory.h>
00092 #include "udanax.h"
00093 
00101     bool
00102 insertspanf(
00103     Session       *sess,          
00104     typespanf      spanfptr,
00105     IStreamAddr   *isaptr,
00106     typesporglset  sporglset,
00107     int            spantype)
00108 {
00109     typedsp crumorigin;
00110     typewid crumwidth;
00111     Tumbler lstream, lwidth;
00112     type2dbottomcruminfo linfo; /* zzz 2dinfo ? fix ? 5/27/84 ----- */
00113 
00114     prefixtumbler(isaptr, spantype, &crumorigin.dsas[ORGLRANGE]);
00115     tumblerclear(&crumwidth.dsas[ORGLRANGE]);
00116     clear(&linfo, sizeof(linfo));
00117     for (; sporglset; sporglset = (typesporglset) ((typeitemheader *) sporglset)->next) {
00118         if (((typeitemheader *) sporglset)->itemid == ISPANID) {
00119             movetumbler(&((typeispan *) sporglset)->stream, &lstream);
00120             movetumbler(&((typeispan *) sporglset)->width, &lwidth);
00121             movetumbler(isaptr, &linfo.homedoc);
00122         } else if (((typeitemheader *) sporglset)->itemid == SPORGLID) {
00123             movetumbler(&((typesporgl *) sporglset)->sporglorigin, &lstream);
00124             movetumbler(&((typesporgl *) sporglset)->sporglwidth, &lwidth);
00125             movetumbler(&((typesporgl *) sporglset)->sporgladdress, &linfo.homedoc);
00126         } else if (((typeitemheader *) sporglset)->itemid == TEXTID) {
00127             movetumbler(isaptr, &lstream);
00128 
00129 /* create lwidth out of sporglset->length */
00130             tumblerclear(&lwidth);
00131             lwidth.mantissa[1] = ((typetext *) sporglset)->length;
00132             tumblerjustify(&lwidth);
00133 
00134             movetumbler(isaptr, &linfo.homedoc);
00135         } else
00136             assert(0); // insertspanf - bad itemid
00137 
00138         movetumbler(&lstream, &crumorigin.dsas[SPANRANGE]);
00139         movetumbler(&lwidth, &crumwidth.dsas[SPANRANGE]);
00140         insertnd(sess, (typecuc *) spanfptr, &crumorigin, &crumwidth, &linfo, SPANRANGE);
00141     }
00142     return true;
00143 }
00144 
00152     bool
00153 findlinksfromtothreesp(
00154     Session     *sess,          
00155     typespanf    spanfptr,
00156     typespecset  fromvspecset,
00157     typespecset  tovspecset,
00158     typespecset  threevspecset,
00159     typeispan   *orglrange,
00160     typelinkset *linksetptr)
00161 {
00162     typesporglset fromsporglset;
00163     typesporglset tosporglset;
00164     typesporglset threesporglset;
00165     typelinkset fromlinkset;
00166     typelinkset tolinkset;
00167     typelinkset threelinkset;
00168     bool olddebug = debug;
00169 
00170 #ifndef DISTRIBUTION
00171     if (debug) {
00172         L("findlinksfromtothreesp fromset = %x, toset = %x, threeset = %x\n", (int) fromvspecset, (int) tovspecset,
00173                 (int) threevspecset);
00174     }
00175 #endif
00176 
00177     fromlinkset = tolinkset = threelinkset = NULL;
00178 
00179     if (fromvspecset)
00180         specset2sporglset(sess, fromvspecset, &fromsporglset, NOBERTREQUIRED);
00181 
00182     if (tovspecset)
00183         specset2sporglset(sess, tovspecset, &tosporglset, NOBERTREQUIRED);
00184 
00185     if (threevspecset)
00186         specset2sporglset(sess, threevspecset, &threesporglset, NOBERTREQUIRED);
00187 
00188     if (fromvspecset) {
00189         sporglset2linkset(sess, (typecuc *) spanfptr, fromsporglset, &fromlinkset, orglrange, LINKFROMSPAN);
00190         if (!fromlinkset) {
00191             *linksetptr = NULL;
00192             debug = olddebug;
00193             return true;
00194         }
00195     }
00196 
00197     if (tovspecset) {
00198         sporglset2linkset(sess, (typecuc *) spanfptr, tosporglset, &tolinkset, orglrange, LINKTOSPAN);
00199         if (!tolinkset) {
00200             *linksetptr = NULL;
00201             debug = olddebug;
00202             return true;
00203         }
00204     }
00205 
00206     if (threevspecset) {
00207         sporglset2linkset(sess, (typecuc *) spanfptr, threesporglset, &threelinkset, orglrange, LINKTHREESPAN);
00208         if (!threelinkset) {
00209             *linksetptr = NULL;
00210             debug = olddebug;
00211             return true;
00212         }
00213     }
00214 
00215     intersectlinksets(sess, fromlinkset, tolinkset, threelinkset, linksetptr);
00216     debug = olddebug;
00217     return true;
00218 }
00219 
00227     bool
00228 findnumoflinksfromtothreesp(
00229     Session     *sess,          
00230     typespanf    spanfptr,
00231     typespecset  fromvspecset,
00232     typespecset  tovspecset,
00233     typespecset  threevspecset,
00234     typeispan   *orglrange,
00235     int         *numptr)
00236 {
00237     typelinkset linkset;
00238     int n;
00239 
00240     if (!findlinksfromtothreesp(sess, spanfptr, fromvspecset, tovspecset, threevspecset, orglrange, &linkset))
00241         return (false);
00242 
00243     for (n = 0; linkset; linkset = linkset->next, ++n)
00244         ;
00245 
00246     *numptr = n;
00247     return true;
00248 }
00249 
00257     bool
00258 findnextnlinksfromtothreesp(
00259     Session      *sess,          
00260     typespecset   fromvspecset,
00261     typespecset   tovspecset,
00262     typespecset   threevspecset,
00263     typeispan    *orglrangeptr,
00264     IStreamAddr  *lastlinkisaptr,
00265     typelinkset  *nextlinksetptr,
00266     int          *nptr)
00267 {
00268     int n;
00269     typelinkset linkset;
00270 
00271     n = 0;
00272     *nextlinksetptr = NULL;
00273 
00274     if (!findlinksfromtothreesp(sess, spanf, fromvspecset, tovspecset, threevspecset, orglrangeptr, &linkset))
00275         return false;
00276 
00277     if (iszerotumbler(lastlinkisaptr)) {
00278         *nextlinksetptr = linkset;
00279     } else {
00280         for (; linkset; linkset = linkset->next) {
00281             if (tumblereq(&linkset->address, lastlinkisaptr)) {
00282                 *nextlinksetptr = linkset->next;
00283                 break;
00284             }
00285         }
00286     }
00287 
00288     if (!linkset) {
00289         *nextlinksetptr = NULL;
00290         *nptr = 0;
00291         return true;
00292     }
00293 
00294     for (linkset = *nextlinksetptr; linkset; linkset = linkset->next) {
00295         if (++n >= *nptr) {
00296             linkset->next = NULL;
00297             break;
00298         }
00299     }
00300     *nptr = n;
00301     return true;
00302 }
00303 
00311     bool
00312 finddocscontainingsp(
00313     Session     *sess,          
00314     typespanset  ispanset,
00315     typelinkset *addresssetptr)
00316 {
00317     Tumbler docid;
00318     Context *context, *c;
00319     typelinkset *headptr;
00320     typelink document;
00321     typespan docspace;
00322 
00323 #ifndef DISTRIBUTION
00324     if (debug) {
00325         L("\nFINDDOCSCONTAININGsp\n");
00326         fooitemset("", (typeitem *) ispanset);
00327     }
00328 #endif
00329 
00330     headptr = addresssetptr;
00331     *addresssetptr = NULL;
00332     clear(&docspace, sizeof(typespan));
00333     tumblerincrement(&docspace.stream, 0, DOCISPAN, &docspace.stream);
00334     tumblerincrement(&docspace.width, 0, 1, &docspace.width);
00335 
00336     for (; ispanset; ispanset = ispanset->next) {
00337         context = retrieverestricted((typecuc *) spanf, &docspace, ORGLRANGE, ispanset, SPANRANGE, (IStreamAddr *) NULL);
00338 
00339         for (c = context; c; c = (Context *) c->nextcontext) {
00340             movetumbler(&c->totaloffset.dsas[ORGLRANGE], &docid);
00341             beheadtumbler(&docid, &document.address);
00342             if (isinlinklist(*headptr, &document.address))
00343                 continue;
00344 
00345             document.itemid = LINKID;
00346             document.next = NULL;
00347             addresssetptr = (typelinkset *) onitemlist(sess, (typeitem *) & document, (typeitemset *) addresssetptr);
00348         }
00349         contextfree(context);
00350     }
00351 
00352 #ifndef DISTRIBUTION
00353     if (debug)
00354         fooitemset("", (typeitem *) *headptr);
00355 #endif
00356 
00357     return true;
00358 }
00359 
00367     static bool
00368 retrievesporglsetinrange(
00369     Session       *sess,          
00370     typesporglset  sporglptr,
00371     typespan      *whichspace,
00372     typesporglset *sporglsetptr)
00373 {
00374     Context *context, *c, *tmp;
00375     typesporgl *sporglset;
00376 
00377     for (; sporglptr; sporglptr = (typesporglset) sporglptr->xxxxsporgl.next) {
00378         context = retrieverestricted((typecuc *) spanf, (typespan *) sporglptr, SPANRANGE, whichspace, ORGLRANGE, (IStreamAddr *) NULL
00379         /* kluge to make links show thru to version &sporglptr->sporgladdress */ );
00380 
00381         /* dumpcontextlist(context); */
00382         for (c = context; c;) {
00383             sporglset = new(sess) typesporgl;
00384             contextintosporgl((type2dcontext *) c, (Tumbler *) NULL, sporglset, SPANRANGE);
00385             *sporglsetptr = (typesporglset) sporglset;
00386             sporglsetptr = (typesporglset *) & sporglset->next;
00387 
00388             tmp = (Context *) c->nextcontext;
00389 
00390             /*
00391              * if (c->contexttype == GRAN)
00392              *     --contextnum;
00393              * else
00394              *     --c2dontextnum;
00395              * efree((char*)c);
00396              */
00397 
00398             c = tmp;
00399         }
00400         contextfree(context);
00401     }
00402     return true;
00403 }
00404 
00412     bool
00413 retrieveendsetsfromspanf(
00414     Session     *sess,          
00415     typespecset  specset,
00416     typespecset *fromsetptr,
00417     typespecset *tosetptr,
00418     typespecset *threesetptr)
00419 {
00420     typespan fromspace, tospace, threespace;
00421     typesporglset sporglset;
00422     typesporglset fromsporglset;
00423     typesporglset tosporglset;
00424     typesporglset threesporglset;
00425     bool bang(), retrievesporglsetinrange(), linksporglset2specset();
00426     bool temp;
00427 
00428 #ifndef DISTRIBUTION
00429     if (debug) {
00430         L("retrieveendsetsfromspanf\n");
00431         fooitemset("", (typeitem *) specset);
00432     }
00433 #endif
00434 
00435     clear(&fromspace, sizeof(typespan));
00436     clear(&tospace, sizeof(typespan));
00437     clear(&threespace, sizeof(typespan));
00438 
00439     fromspace.stream.mantissa[0] = LINKFROMSPAN;
00440     fromspace.width.mantissa[0] = 1;
00441 
00442     tospace.stream.mantissa[0] = LINKTOSPAN;
00443     tospace.width.mantissa[0] = 1;
00444 
00445     threespace.stream.mantissa[0] = LINKTHREESPAN;
00446     threespace.width.mantissa[0] = 1;
00447 
00448     fromsporglset = tosporglset = threesporglset = NULL;
00449 
00450     if (!(specset2sporglset(sess, specset, &sporglset, NOBERTREQUIRED)
00451           && retrievesporglsetinrange(sess, sporglset, &fromspace, &fromsporglset)
00452           && linksporglset2specset(sess, &((typevspec *) specset)->docisa, fromsporglset, fromsetptr, NOBERTREQUIRED)
00453           && retrievesporglsetinrange(sess, sporglset, &tospace, &tosporglset)
00454           && linksporglset2specset(sess, &((typevspec *) specset)->docisa, tosporglset, tosetptr, NOBERTREQUIRED))) {
00455         return false;
00456     }
00457     if (threesetptr) {
00458         temp = (retrievesporglsetinrange(sess, sporglset, &threespace, &threesporglset)
00459                 && linksporglset2specset(sess, &((typevspec *) specset)->docisa, threesporglset, threesetptr,
00460                                          NOBERTREQUIRED));
00461         return temp;
00462     }
00463     return true;
00464 }

Generated on Sun Aug 21 04:18:14 2005 for Udanax-Green by doxygen1.3.4