server/put.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: put.cxx,v $
00032  * Revision 1.14  2004/09/11 15:02:00  jrush
00033  * Fixed Doxygen tags on all Session parameter arguments.
00034  *
00035  * Revision 1.13  2004/09/04 16:02:18  jrush
00036  * Added Doxygen headers before each and every function definition.
00037  *
00038  * Revision 1.12  2002/05/28 03:58:42  jrush
00039  * Sources modified to comply with GPL licensing.
00040  *
00041  * Revision 1.11  2002/04/12 11:48:50  jrush
00042  * Major reorganization of includes into a single base-include style.
00043  *
00044  * Revision 1.10  2002/04/10 18:01:54  jrush
00045  * Renamed class typeisa to IStreamAddr.
00046  *
00047  * Revision 1.9  2002/04/09 21:45:47  jrush
00048  * Renamed class 'tumbler' to 'Tumbler', for consistency with Python sources,
00049  * and changed typeisa from typedef to a subclass, in preparation for cleaning
00050  * up the type/class tree.
00051  *
00052  * Revision 1.8  2002/04/06 19:51:30  jrush
00053  * Renamed TRUE/FALSE constant use to the C++ standard of true/false.
00054  *
00055  * Revision 1.7  2002/04/06 17:05:57  jrush
00056  * Switched from referring to 'task' for a client connection to 'session',
00057  * and converted the typetask typedef/struct into a Session C++ class.
00058  *
00059  * Revision 1.6  2002/04/06 15:01:45  jrush
00060  * Changed INT to just 'int'.
00061  *
00062  * Revision 1.5  2002/04/02 17:12:52  jrush
00063  * Pure cosmetic changes.
00064  *
00065  * Revision 1.4  2002/02/14 10:08:25  jrush
00066  * Cleaned up source:
00067  *
00068  * 1. ran thru the indent tool to achieve a standard look,
00069  * 2. added structured comments at top for use with DOxygen reporting
00070  *    as well as CVS keywords,
00071  * 3. centralized prototypes in protos.h, removing incomplete ones,
00072  * 4. cleaned up use of bool/BOOLEAN type to suit C++ type,
00073  * 5. fixed initializer nesting in tumbler constants,
00074  * 6. converted select() int bits into ANSI fd_set type,
00075  * 7. added Makefile.am for use by automake.
00076  *
00077  */
00078 
00079 #include <unistd.h>
00080 #include "udanax.h"
00081 
00082 #define MINEXP  -10
00083 
00084 void  putnum(FILE * outfile, int num);
00085 void  putitem(Session * sess, typeitem * itemptr);
00086 void  putspan(Session * sess, typespan * spanptr);
00087 void  puttext(Session * sess, typetext * textptr);
00088 void  putspanpair(Session * sess, typespanpair * spanpair);
00089 
00097     void
00098 prompt(
00099     Session *sess,    
00100     char    *string)
00101 {
00102     fprintf(sess->outp, "%s", string);
00103 }
00104 
00112     void
00113 error(
00114     Session *sess,    
00115     char    *string)
00116 {
00117     fprintf(sess->errp, "%s", string);
00118 }
00119 
00127     void
00128 puttumbler(
00129     FILE    *outfile,
00130     Tumbler *tumblerptr)
00131 {
00132     int i, place;
00133 
00134     if (!tumblercheck(tumblerptr) || tumblerptr->exp < MINEXP) {
00135         dumptumbler(tumblerptr);
00136         return;
00137     }
00138 
00139     if (tumblerptr->sign)
00140         fprintf(outfile, "-");
00141 
00142     for (i = tumblerptr->exp; i < 0; ++i)
00143         fprintf(outfile, "0.");
00144 
00145     place = NPLACES;
00146     do {
00147         --place;
00148     } while (place > 0 && tumblerptr->mantissa[place] == 0);
00149 
00150     for (i = 0; i <= place; ++i) {
00151         putnum(outfile, tumblerptr->mantissa[i]);
00152         if (i < place)
00153             putc('.', outfile);
00154     }
00155 }
00156 
00164     void
00165 putnum(
00166     FILE *outfile,
00167     int   num)
00168 {
00169     fprintf(outfile, "%d", num);
00170 }
00171 
00179     void
00180 putisa(
00181     Session     *sess,    
00182     IStreamAddr *isaptr)
00183 {
00184     puttumbler(sess->outp, isaptr);
00185 }
00186 
00194     void
00195 putitemset(
00196     Session     *sess,    
00197     typeitemset  itemset)
00198 {
00199     if (itemset == NULL) {
00200         fprintf(sess->outp, "  \nitemset empty\n");
00201         return;
00202     }
00203     for (; itemset; itemset = (typeitemset) ((typeitemheader *) itemset)->next) {
00204         putitem(sess, itemset);
00205         if (!
00206             (((typeitemheader *) itemset)->next && ((typeitemheader *) itemset)->itemid == TEXTID
00207              && ((typeitemheader *) itemset)->next->itemid == TEXTID))
00208             putc('\n', sess->outp);
00209     }
00210 }
00211 
00219     void
00220 putitem(
00221     Session  *sess,    
00222     typeitem *itemptr)
00223 {
00224     switch (((typeitemheader *) itemptr)->itemid) {
00225     case ISPANID:
00226         fprintf(sess->outp, "  ispan\n");
00227         putspan(sess, (typespan *) itemptr);
00228         break;
00229     case VSPANID:
00230         fprintf(sess->outp, "  vspan\n");
00231         putspan(sess, (typespan *) itemptr);
00232         break;
00233     case VSPECID:
00234         fprintf(sess->outp, "document: ");
00235         putisa(sess, &((typevspec *) itemptr)->docisa);
00236         fprintf(sess->outp, "\nspans");
00237         putitemset(sess, (typeitem *) ((typevspec *) itemptr)->vspanset);
00238         break;
00239     case TEXTID:
00240         puttext(sess, (typetext *) itemptr);
00241         break;
00242     case LINKID:
00243         putisa(sess, &((typelink *) itemptr)-> /* link */ address);
00244         break;
00245 
00246 #ifndef DISTRIBUTION
00247     case SPORGLID:
00248         fprintf(sess->outp, "sporgl address: ");
00249         putisa(sess, &((typesporgl *) itemptr)->sporgladdress);
00250 
00251         fprintf(sess->outp, "\n   sporgl origin: ");
00252         putisa(sess, (IStreamAddr *) &((typesporgl *) itemptr)->sporglorigin);
00253 
00254         fprintf(sess->outp, "\n   sporgl width: ");
00255         putisa(sess, (IStreamAddr *) &((typesporgl *) itemptr)->sporglwidth);
00256 
00257         fprintf(sess->outp, "\n");
00258         break;
00259 #endif
00260     default:
00261         error(sess, "illegal item id for putitem ");
00262         fprintf(sess->outp, "%x  %d\nd", (int) itemptr, ((typeitemheader *) itemptr)->itemid);
00263         return;
00264     }
00265 }
00266 
00274     void
00275 putspan(
00276     Session  *sess,    
00277     typespan *spanptr)
00278 {
00279     fprintf(sess->outp, "   span address: ");
00280     puttumbler(sess->outp, &spanptr->stream);
00281     fprintf(sess->outp, "\n   span width: ");
00282     puttumbler(sess->outp, &spanptr->width);
00283 }
00284 
00292     void
00293 puttext(
00294     Session  *sess,    
00295     typetext *textptr)
00296 {
00297     write(fileno(sess->outp), textptr->string, textptr->length);
00298 }
00299 
00307     void
00308 putspanpairset(
00309     Session         *sess,    
00310     typespanpairset  spanpairset)
00311 {
00312     if (!spanpairset)
00313         fprintf(sess->outp, "NULL relationship\n");
00314     else
00315         for (; spanpairset; spanpairset = spanpairset->nextspanpair)
00316             putspanpair(sess, spanpairset);
00317 }
00318 
00326     void
00327 putspanpair(
00328     Session      *sess,    
00329     typespanpair *spanpair)
00330 {
00331     fprintf(sess->outp, "start1:  ");
00332     puttumbler(sess->outp, &spanpair->stream1);
00333     fprintf(sess->outp, "\nstart2:  ");
00334     puttumbler(sess->outp, &spanpair->stream2);
00335     fprintf(sess->outp, "\nwidth:  ");
00336     puttumbler(sess->outp, &spanpair->widthofspan);
00337     fprintf(sess->outp, "\n");
00338 }
00339 
00347     void
00348 putcreatelink(
00349     Session     *sess,    
00350     IStreamAddr *istreamptr)
00351 {
00352     fprintf(sess->outp, "\nlink made: ");
00353     putisa(sess, istreamptr);
00354     fprintf(sess->outp, "\n");
00355 }
00356 
00364     void
00365 putfollowlink(
00366     Session     *sess,    
00367     typespecset  specset)
00368 {
00369     fprintf(sess->outp, "link endset is:\n");
00370     putitemset(sess, (typeitem *) specset);
00371 }
00372 
00380     void
00381 putretrievedocvspanset(
00382     Session     *sess,    
00383     typespanset *spansetptr)
00384 {
00385     fprintf(sess->outp, "docvspans are:\n");
00386     putitemset(sess, (typeitem *) *spansetptr);
00387 }
00388 
00396     void
00397 putretrievedocvspan(
00398     Session  *sess,    
00399     typespan *vspanptr)
00400 {
00401     fprintf(sess->outp, "docvspan is:\n");
00402     putspan(sess, vspanptr);
00403 }
00404 
00412     void
00413 putretrievev(
00414     Session       *sess,    
00415     typevstuffset *vstuffsetptr)
00416 {
00417     fprintf(sess->outp, "\nvstuff is:\n");
00418     putitemset(sess, (typeitem *) *vstuffsetptr);
00419 }
00420 
00428     void
00429 putfindlinksfromtothree(
00430     Session     *sess,    
00431     typelinkset  linkset)
00432 {
00433     fprintf(sess->outp, "\nlinks\n");
00434     putitemset(sess, (typeitem *) linkset);
00435 }
00436 
00444     void
00445 putfindnumoflinksfromtothree(
00446     Session *sess,    
00447     int      num)
00448 {
00449     fprintf(sess->outp, "\nnumber of links: %d\n", num);
00450 }
00451 
00459     void
00460 putfindnextnlinksfromtothree(
00461     Session     *sess,    
00462     int          n,
00463     typelinkset  nextlinkset)
00464 {
00465     fprintf(sess->outp, "next number of links: %d\n", n);
00466     putitemset(sess, (typeitem *) nextlinkset);
00467 }
00468 
00476     void
00477 putshowrelationof2versions(
00478     Session         *sess,    
00479     typespanpairset  relation)
00480 {
00481     fprintf(sess->outp, "relation between versions:\n");
00482     putspanpairset(sess, relation);
00483 }
00484 
00492     void
00493 putcreatenewdocument(
00494     Session     *sess,    
00495     IStreamAddr *newdocisaptr)
00496 {
00497     fprintf(sess->outp, "new document: ");
00498     putisa(sess, newdocisaptr);
00499     fprintf(sess->outp, "\n\n");
00500 }
00501 
00509     void
00510 putcreatenewversion(
00511     Session     *sess,    
00512     IStreamAddr *newdocisaptr)
00513 {
00514     fprintf(sess->outp, "new version: ");
00515     putisa(sess, newdocisaptr);
00516     fprintf(sess->outp, "\n");
00517 }
00518 
00519     void
00520 putfinddocscontaining(
00521     Session     *sess,    
00522     typeitemset  addressset)
00523 {
00524     fprintf(sess->outp, "\ndocuments\n");
00525     putitemset(sess, addressset);
00526 }
00527 
00535     void
00536 putretrieveendsets(
00537     Session     *sess,    
00538     typespecset  fromset,
00539     typespecset  toset,
00540     typespecset  threeset)
00541 {
00542     fprintf(sess->outp, "\nfromset\n");
00543     putitemset(sess, (typeitem *) fromset);
00544     fprintf(sess->outp, "\ntoset\n");
00545     putitemset(sess, (typeitem *) toset);
00546     fprintf(sess->outp, "\nthreeset\n");
00547     putitemset(sess, (typeitem *) toset);
00548 }
00549 
00557     void
00558 putinsert(
00559     Session *sess)    
00560 {
00561 }
00562 
00570     void
00571 putcopy(
00572     Session *sess)    
00573 {
00574 }
00575 
00583     void
00584 putdeletevspan(
00585     Session *sess)    
00586 {
00587 }
00588 
00596     void
00597 putrearrange(
00598     Session * sess)    
00599 {
00600 }
00601 
00609     void
00610 putrequestfailed(
00611     Session * sess)    
00612 {
00613     fprintf(sess->outp, "?\n");
00614 }
00615 
00623     bool
00624 kluge()
00625 {
00626     return true;
00627 }
00628 
00636     void
00637 putxaccount(
00638     Session * sess)    
00639 {
00640 }
00641 
00649     void
00650 putcreatenode_or_account(
00651     Session *sess,    
00652     Tumbler *tp)
00653 {
00654     puttumbler(sess->outp, tp);
00655 }
00656 
00664     void
00665 putopen(
00666     Session *sess,    
00667     Tumbler *tp)
00668 {
00669     puttumbler(sess->outp, tp);
00670 }
00671 
00679     void
00680 putclose(
00681     Session *sess)    
00682 {
00683 }
00684 
00692     void
00693 putquitxanadu(
00694     Session * sess)    
00695 {
00696     fprintf(sess->outp, "Good Bye.\n");
00697 }

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