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: session.cxx,v $ 00032 * Revision 1.10 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.9 2004/09/04 16:02:18 jrush 00037 * Added Doxygen headers before each and every function definition. 00038 * 00039 * Revision 1.8 2002/07/14 08:35:24 jrush 00040 * Replace gerror(), qerror() with assert() 00041 * 00042 * Revision 1.7 2002/05/28 04:22:29 jrush 00043 * Adjusted source files to comply with GPL licensing. 00044 * 00045 * Revision 1.6 2002/04/12 11:56:43 jrush 00046 * Reorganized include file layout, renamed xanadu.h to udanax.h and 00047 * typecontext/typecrumcontext to C++ class Context/CrumContext. 00048 * 00049 * Revision 1.5 2002/04/10 18:01:54 jrush 00050 * Renamed class typeisa to IStreamAddr. 00051 * 00052 * Revision 1.4 2002/04/09 21:45:46 jrush 00053 * Renamed class 'tumbler' to 'Tumbler', for consistency with Python sources, 00054 * and changed typeisa from typedef to a subclass, in preparation for cleaning 00055 * up the type/class tree. 00056 * 00057 * Revision 1.3 2002/04/06 20:42:50 jrush 00058 * Switch from sess->alloc() style to new(sess) Object parameterized allocator. 00059 * 00060 * Revision 1.2 2002/04/06 19:51:30 jrush 00061 * Renamed TRUE/FALSE constant use to the C++ standard of true/false. 00062 * 00063 * Revision 1.1 2002/04/06 17:01:48 jrush 00064 * Renamed file task.cxx to the more meaningful session.cxx 00065 * 00066 * Revision 1.3 2002/04/06 15:01:17 jrush 00067 * Changed INT to just 'int'. 00068 * 00069 * Revision 1.2 2002/02/14 09:27:43 jrush 00070 * Cleaned up source: 00071 * 00072 * 1. ran thru the indent tool to achieve a standard look, 00073 * 2. added structured comments at top for use with DOxygen reporting 00074 * as well as CVS keywords, 00075 * 3. fixed compiler warnings re ambiguous assign/compares, 00076 * needed casts and unused/uninitialized variables, 00077 * 4. fixed funcs that didn't specify a return type, 00078 * 5. centralized prototypes in protos.h, removing incomplete ones, 00079 * 6. cleaned up use of bool/BOOLEAN type to suit C++ type, 00080 * 7. fixed initializer nesting in tumbler constants, 00081 * 8. renamed vars that conflict with C++ keywords (new, this), 00082 * 9. fixed global/extern confusion re some global vars. 00083 * 00084 */ 00085 00086 #include "udanax.h" 00087 00095 Session::Session() 00096 { 00097 inp = stdin; 00098 outp = stdout; 00099 errp = stderr; 00100 tempspacehead = NULL; 00101 tempspacetail = NULL; 00102 00103 /* tumblerclear(&account); */ 00104 } 00105 00113 bool 00114 Session::getaccount( 00115 IStreamAddr *accountptr) 00116 { 00117 tumblerclear((Tumbler *) accountptr); 00118 return true; 00119 00120 /* prompt (sess, "account? "); */ 00121 00122 /* gettumbler (sess, accountptr) && validaccount(sess, accountptr); L("in get account \n"); 00123 * return(true); */ 00124 } 00125 00133 void * 00134 operator new( 00135 size_t nbytes, 00136 Session *sess) 00137 { 00138 return sess->alloc(nbytes); 00139 } 00140 00148 int * 00149 Session::alloc( 00150 int nbytes) 00151 { 00152 Session::typetthingheader *head = tempspacehead; 00153 00154 Session::typetthingheader *xthis = (Session::typetthingheader *) eallocwithtag((unsigned) (sizeof(Session::typetthingheader) + nbytes), SESSTAG); 00155 00156 assert((((unsigned) xthis) & 1) == 0); // ERROR: ealloc returned unaligned pointer 00157 00158 xthis->tnext = head; 00159 xthis->tlast = NULL; 00160 00161 if (head) 00162 head->tlast = xthis; 00163 00164 tempspacehead = xthis; 00165 00166 ++xthis; 00167 assert((((unsigned) xthis) & 1) == 0); // ERROR: talloc trying to return unaligned pointer 00168 00169 return (int *) xthis; 00170 } 00171 00179 void 00180 Session::free() 00181 { 00182 Session::typetthingheader *p; 00183 00184 Session::typetthingheader *ptr; 00185 for (ptr = tempspacehead; ptr; ptr = p) { 00186 p = ptr->tnext; 00187 checkpointer("Session::free: ", (char *) ptr); 00188 00189 /* 00190 * if (ptr > (char *) 0x1b0000) 00191 * assert(0); // Session::free: ptr pointing into stack region 00192 */ 00193 00194 efree((char *)ptr); 00195 } 00196 tempspacehead = NULL; 00197 } 00198 00206 void 00207 Session::freeexplicit( 00208 char *ptr) 00209 { 00210 checkpointer("Session::freeexplicit: ", ptr); 00211 00212 Session::typetthingheader *header = (Session::typetthingheader *) ptr; 00213 00214 --header; 00215 00216 if (header->tnext) 00217 header->tnext->tlast = header->tlast; 00218 00219 if (header->tlast) 00220 header->tlast->tnext = header->tnext; 00221 00222 if (header == tempspacehead) 00223 tempspacehead = header->tnext; 00224 00225 efree((char *)header); 00226 } 00227 00235 void 00236 Session::freeitemset( 00237 typeitemset itemset) 00238 { 00239 typeitem *nextitem; 00240 00241 for (; itemset; itemset = nextitem) { 00242 checkitem("Session::freeitemset: ", itemset); 00243 00244 nextitem = (typeitem *) ((typeitemheader *) itemset)->next; 00245 00246 if (((typeitemheader *) itemset)->itemid == VSPECID) 00247 freeitemset((typeitemset) ((typevspec *) itemset)->vspanset); 00248 00249 freeexplicit((char *)itemset); 00250 } 00251 }
1.3.4