1 /*****************************************************************************/ 2 /* */ 3 /* (C) Copyright 1992-1997 Alberto Pasquale */ 4 /* Portions (C) Copyright 1999 Per Lundberg */ 5 /* */ 6 /* A L L R I G H T S R E S E R V E D */ 7 /* */ 8 /*****************************************************************************/ 9 /* */ 10 /* How to contact the author: Alberto Pasquale of 2:332/504@fidonet */ 11 /* Viale Verdi 106 */ 12 /* 41100 Modena */ 13 /* Italy */ 14 /* */ 15 /*****************************************************************************/ 16 17 #include "types.hpp" 18 #include "cfgdata.hpp" 19 20 //#pragma pack (1) // necessary for (packed) data blocks ! 21 22 #define _Adr_Indx 1 // for mkndx7 and loadblk 23 #define _Sys_Indx 2 24 #define _Pho_Indx 3 25 26 #define DATABLKSIZE 100000 27 28 #define NPhone(a) ((a)->name+(a)->namesize) 29 30 struct Node { 31 byte recsize; 32 byte namesize; // length of SysOp Name including terminating NULL 33 EXTADR adr; 34 dword datofs; 35 dword dtpofs; 36 dword entryn; // number of entry, 0 based 37 char name[1]; 38 }; 39 40 typedef Node * NODEP; 41 42 struct DBLK { 43 DBLK *next; 44 byte data[DATABLKSIZE]; 45 }; 46 47 48 struct NFILE { 49 NODEP *bp; // pointer to first element in array 50 dword n, // total number of elements 51 c; // index to current element 52 }; 53 54 55 struct Lnk { // To Link SysOps, Phones, fido structure 56 dword dtpofs; // Offset of DTP to be written 57 _DTPLnk dtplnk; // syslnk to be written at dtpofs 58 }; 59 60 61 class InMem { 62 private: 63 64 dword NStored; // Total number of stored entries. 65 dword TotN; // total number of unique entries (after MkNodeNdx) 66 DBLK *FirstBlk; // pointer to first data block 67 DBLK *CBlk; // pointer to current data block 68 dword cofs; // current offset in current data block 69 70 NODEP *np; // Points to array of pointers to nodes 71 Lnk *lp; // Points to array of Link-info blocks 72 _DTPNodeLnk dtpTopLnk; // Top level link-info 73 74 void WriteFidoUserLst (pcsz FidoUserLst); 75 void mkndx7 (int Select, pcsz OutName); 76 int loadblk (int Select, byte *ndxrec, byte *strbuf, uint *stringlen, 77 long *prevblk, long hiblk, NFILE *inp, NFILE *tmpout); 78 int WriteName (NODEP *n, FILE *fidouser); // 0 on success 79 dword RemoveDupes (); 80 int WriteName (NODEP n, FILE *fidouser); 81 dword EatDownSeg (dword i); 82 dword GetSeg (int SegType, dword i); 83 dword Link (int Select); 84 85 86 public: 87 88 InMem (); 89 ~InMem (); 90 91 void Open (); 92 93 void Write (const EXTADR *adr, 94 dword datofs, 95 dword dtpofs, 96 pcsz SysOp, // Empty string if not used 97 pcsz Phone); // Empty string if not used 98 99 void Close (); // Build list of pointers 100 101 102 dword MkNodeNdx (pcsz NodexNdx); // removes duplicates and 103 // points with no Boss. 104 // Creates nodex.ndx index. 105 // Returns the number 106 // of unique entries. 107 108 // MkSysLst, MkPhLst and FidoLnk 109 // MUST be preceded by MkNodeNdx. 110 111 void DTPLnkOpen (); 112 113 void FidoLnk (); // Set Fido Links 114 115 dword MkPhLst (pcsz NodexPdx); // Make Phone Index, 116 // Set Phone Links, 117 // Return Unique Phones 118 119 dword MkSysLst (pcsz NodexSdx, // NULL if not to be used 120 pcsz FidoUserLst // NULL if not to be used 121 ); // Make SysOp Index(es), 122 // Set SysOp Links, 123 // Return Unique SysOps. 124 125 void DTPLnkClose (pcsz NodexDtp, // Update DTP with stored links 126 bool OnDisk); // Must work on Disk ? 127 }; 128 129