libsrc/spanf2.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: spanf2.cxx,v $
00032  * Revision 1.11  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.10  2004/09/04 16:02:18  jrush
00037  * Added Doxygen headers before each and every function definition.
00038  *
00039  * Revision 1.9  2002/05/28 04:22:29  jrush
00040  * Adjusted source files to comply with GPL licensing.
00041  *
00042  * Revision 1.8  2002/05/28 02:52:23  jrush
00043  * Made static any functions and global variables private to this source file
00044  * and commented out any unused functions.
00045  *
00046  * Revision 1.7  2002/04/12 11:56:43  jrush
00047  * Reorganized include file layout, renamed xanadu.h to udanax.h and
00048  * typecontext/typecrumcontext to C++ class Context/CrumContext.
00049  *
00050  * Revision 1.6  2002/04/10 18:01:54  jrush
00051  * Renamed class typeisa to IStreamAddr.
00052  *
00053  * Revision 1.5  2002/04/06 20:42:50  jrush
00054  * Switch from sess->alloc() style to new(sess) Object parameterized allocator.
00055  *
00056  * Revision 1.4  2002/04/06 19:51:30  jrush
00057  * Renamed TRUE/FALSE constant use to the C++ standard of true/false.
00058  *
00059  * Revision 1.3  2002/04/06 17:05:57  jrush
00060  * Switched from referring to 'task' for a client connection to 'session',
00061  * and converted the typetask typedef/struct into a Session C++ class.
00062  *
00063  * Revision 1.2  2002/02/14 09:27:43  jrush
00064  * Cleaned up source:
00065  *
00066  * 1. ran thru the indent tool to achieve a standard look,
00067  * 2. added structured comments at top for use with DOxygen reporting
00068  *    as well as CVS keywords,
00069  * 3. fixed compiler warnings re ambiguous assign/compares,
00070  *    needed casts and unused/uninitialized variables,
00071  * 4. fixed funcs that didn't specify a return type,
00072  * 5. centralized prototypes in protos.h, removing incomplete ones,
00073  * 6. cleaned up use of bool/BOOLEAN type to suit C++ type,
00074  * 7. fixed initializer nesting in tumbler constants,
00075  * 8. renamed vars that conflict with C++ keywords (new, this),
00076  * 9. fixed global/extern confusion re some global vars.
00077  *
00078  */
00079 
00080 #include "udanax.h"
00081 
00089     bool
00090 isinlinklist(
00091     typelinkset  linkset,
00092     IStreamAddr *linkisaptr)
00093 {
00094     for (; linkset; linkset = linkset->next) {
00095         if (tumblereq(&linkset->address, linkisaptr))
00096             return true;
00097     }
00098     return false;
00099 }
00100 
00108     static typelink *
00109 makelinkitem(
00110     Session     *sess,          
00111     IStreamAddr *linkisa)
00112 {
00113 #ifndef DISTRIBUTION
00114     footumbler("makelinkitem", linkisa);
00115 #endif
00116 
00117     typelink *link = new(sess) typelink;
00118     movetumbler(linkisa, &link->address);
00119     link->itemid = LINKID;
00120     link->next   = NULL;
00121     return link;
00122 }
00123 
00131     void
00132 onlinklist(
00133     Session     *sess,          
00134     typelinkset *linksetptr,
00135     IStreamAddr *linkisaptr)
00136 {
00137     typelink *linkset, *temp, *nextlink;
00138 
00139     linkset = makelinkitem(sess, linkisaptr);
00140 
00141     if (*linksetptr == NULL) {
00142         *linksetptr = linkset;
00143         return;
00144     }
00145 
00146     for (temp = *linksetptr; (nextlink = temp->next) != 0; temp = nextlink) {
00147         if (tumblereq(&temp->address, linkisaptr))
00148             return;
00149     }
00150 
00151     temp->next = linkset;
00152 }
00153 
00161     void
00162 intersectlinksets(
00163     Session     *sess,          
00164     typelinkset  linkset1,
00165     typelinkset  linkset2,
00166     typelinkset  linkset3,
00167     typelinkset *linkset4ptr)
00168 {
00169     typelinkset linkset4;
00170     typelinkset temp1 = NULL;
00171     typelinkset temp2;
00172     typelinkset temp3;
00173     bool olddebug = debug;
00174 
00175 #ifndef DISTRIBUTION
00176     if (debug) {
00177         L("\nINTERSECTLINKSETS\n");
00178         fooitemset("", (typeitem *) linkset1);
00179         fooitemset("", (typeitem *) linkset2);
00180         L("inter linkset1 = %x, linkset2 = %x, linkset3 = %x\n", (int) linkset1, (int) linkset2, (int) linkset3);
00181     }
00182 #endif
00183 
00184 /* If only one linkset is non-null, then just use it */
00185     if (linkset1 && !linkset2 && !linkset3)
00186         *linkset4ptr = linkset1;
00187     else if (!linkset1 && linkset2 && !linkset3)
00188         *linkset4ptr = linkset2;
00189     else if (!linkset1 && !linkset2 && linkset3)
00190         *linkset4ptr = linkset3;
00191     else
00192         *linkset4ptr = NULL;
00193 
00194     if (*linkset4ptr) {
00195 #ifndef DISTRIBUTION
00196         if (debug) {
00197             L("*linkset4ptr = %x\n", (int) *linkset4ptr);
00198         }
00199 #endif
00200         debug = olddebug;
00201         return;
00202     }
00203 
00204 /* At least two linksets aren't null */
00205 /* If only two are, put them in temp1 and linkset2 */
00206     if (linkset1)
00207         temp1 = linkset1;
00208     if (linkset1 && !linkset2 && linkset3) {
00209         linkset2 = linkset3;
00210         linkset3 = NULL;
00211     } else if (!linkset1 && linkset2 && linkset3) {
00212         temp1 = linkset3;
00213         linkset3 = NULL;
00214     }
00215 
00216 #ifndef DISTRIBUTION
00217     if (debug) {
00218         L("temp1 = %x, linkset2 = %x, linkset3 = %x\n", (int) temp1, (int) linkset2, (int) linkset3);
00219     }
00220 #endif
00221 
00222     if (!linkset3) {
00223         for (; temp1; temp1 = temp1->next) {
00224             for (temp2 = linkset2; temp2; temp2 = temp2->next) {
00225                 if (tumblereq(&temp1->address, &temp2->address)) {
00226                     linkset4 = makelinkitem(sess, &temp1->address);
00227                     *linkset4ptr = linkset4;
00228                     linkset4ptr = &linkset4->next;
00229                 }
00230             }
00231         }
00232     } else {
00233         for (; temp1; temp1 = temp1->next) {
00234             for (temp2 = linkset2; temp2; temp2 = temp2->next) {
00235                 for (temp3 = linkset3; temp3; temp3 = temp3->next) {
00236                     if (tumblereq(&temp1->address, &temp2->address)
00237                         && tumblereq(&temp2->address, &temp3->address)) {
00238                         linkset4 = makelinkitem(sess, &temp1->address);
00239                         *linkset4ptr = linkset4;
00240                         linkset4ptr = &linkset4->next;
00241                     }
00242                 }
00243             }
00244         }
00245     }
00246     debug = olddebug;
00247 }

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