home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / hl10osrc.zoo / Lib / ListRecord.cc < prev    next >
Text File  |  2009-11-06  |  2KB  |  86 lines

  1. /* -*- Mode: C -*- */
  2. /* ListRecord.cc - ListRecord implementation
  3.  * Created by Robert Heller on Sat Dec  7 00:13:55 1991
  4.  *
  5.  * ------------------------------------------------------------------
  6.  * Home Libarian by Deepwoods Software
  7.  * Common Class library implementation code
  8.  * ------------------------------------------------------------------
  9.  * Modification History:
  10.  * ------------------------------------------------------------------
  11.  * Contents:
  12.  * ------------------------------------------------------------------
  13.  * 
  14.  * 
  15.  * Copyright (c) 1991,1992 by Robert heller (D/B/A Deepwoods Software)
  16.  *        All Rights Reserved
  17.  * 
  18.  */
  19. #ifdef MESSYDOS
  20. #include <listrec.h>
  21. #else
  22. #include <ListRecord.h>
  23. #endif
  24.  
  25. char *ListRecord::dummy = NULL;
  26.  
  27. // ListRecord constructor, given a Record
  28. ListRecord::ListRecord(Record* record)
  29. {
  30.     RawData = *record;        // copy data
  31.     char* str = RawData.buffer;    // get data pointer
  32.     int bytesleft = RawData.size;    // and size
  33.     char* p = str;            // temp pointe
  34.     int bl = bytesleft;        // temp counter
  35.  
  36.     // find element count
  37.     for (numelts = 0;
  38.         bl > 0 && *p != '\n'; numelts++) {
  39.         int slen = strlen(p)+1;
  40.         p += slen; bl -= slen;
  41.     }
  42.     // allocate vector
  43.     elems = new char* [numelts];
  44.     // fill in pointers
  45.     for (int i = 0; i < numelts; i++) {
  46.         elems[i] = str;
  47.         str += strlen(str)+1;
  48.     }
  49. }
  50.  
  51. // ListRecord constructor, given a string vector
  52. ListRecord::ListRecord (int numitems,char* inelems[])
  53. {
  54.     numelts = numitems;            // number of elements
  55.     elems = new char* [numelts];        // allocate a vector
  56.     for (int i = 0; i < numelts; i++) {    // copy vector
  57.         elems[i] = inelems[i];
  58.     }
  59. }
  60.  
  61. // create a fresh record, given the string vector
  62. void ListRecord::UpdateRecord ()
  63. {
  64.     int rsize = 2;        // "\n\0"    // size
  65.  
  66.     for (int i = 0; i < numelts; i++) {    // compute buffer size
  67.         rsize += strlen(elems[i])+1;
  68.     }
  69.     char* str = new char[rsize]; char *p = str;    // allocate buffer
  70.     // copy strings into the buffer
  71.     for (i = 0; i < numelts; i++) {
  72.         strcpy(p,elems[i]);
  73.         elems[i] = p;
  74.         p += strlen(p)+1;
  75.     }
  76.     // add terminator
  77.     *p++ = '\n'; *p++ = 0;
  78.     // free up old buffer
  79.     RawData.NewBuffer(0);
  80.     // paste in new buffer
  81.     RawData.size = rsize;
  82.     RawData.buffer = str;
  83. }
  84.  
  85.  
  86.