int ZIPFAM::SkipRecord(PGLOBAL g, bool header) { // Skip this record if (gzeof(Zfile)) return RC_EF; else if (gzgets(Zfile, To_Buf, Buflen) == Z_NULL) return Zerror(g); if (header) RecordPos(g); return RC_OK; } // end of SkipRecord
int ZIPFAM::ReadBuffer(PGLOBAL g) { char *p; int rc; if (!Zfile) return RC_EF; if (!Placed) { /*******************************************************************/ /* Record file position in case of UPDATE or DELETE. */ /*******************************************************************/ if (RecordPos(g)) return RC_FX; CurBlk = Rows++; // Update RowID } else Placed = false; if (gzeof(Zfile)) { rc = RC_EF; } else if (gzgets(Zfile, To_Buf, Buflen) != Z_NULL) { p = To_Buf + strlen(To_Buf) - 1; if (*p == '\n') *p = '\0'; // Eliminate ending new-line character if (*(--p) == '\r') *p = '\0'; // Eliminate eventuel carriage return strcpy(Tdbp->GetLine(), To_Buf); IsRead = true; rc = RC_OK; num_read++; } else rc = Zerror(g); if (trace > 1) htrc(" Read: '%s' rc=%d\n", To_Buf, rc); return rc; } // end of ReadBuffer
int DOSFAM::ReadBuffer(PGLOBAL g) { char *p; int rc; if (!Stream) return RC_EF; if (trace > 1) htrc("ReadBuffer: Tdbp=%p To_Line=%p Placed=%d\n", Tdbp, Tdbp->To_Line, Placed); if (!Placed) { /*******************************************************************/ /* Record file position in case of UPDATE or DELETE. */ /*******************************************************************/ if (RecordPos(g)) return RC_FX; CurBlk = (int)Rows++; if (trace > 1) htrc("ReadBuffer: CurBlk=%d\n", CurBlk); } else Placed = false; if (trace > 1) htrc(" About to read: stream=%p To_Buf=%p Buflen=%d\n", Stream, To_Buf, Buflen); if (fgets(To_Buf, Buflen, Stream)) { p = To_Buf + strlen(To_Buf) - 1; if (trace > 1) htrc(" Read: To_Buf=%p p=%c\n", To_Buf, To_Buf, p); #if defined(UNIX) if (true) { // Data files can be imported from Windows (having CRLF) #else if (Bin) { // Data file is read in binary so CRLF remains #endif if (*p == '\n' || *p == '\r') { // is this enough for Unix ??? *p = '\0'; // Eliminate ending CR or LF character if (p > To_Buf) { // is this enough for Unix ??? p--; if (*p == '\n' || *p == '\r') *p = '\0'; // Eliminate ending CR or LF character } // endif To_Buf } // endif p } else if (*p == '\n') *p = '\0'; // Eliminate ending new-line character if (trace > 1) htrc(" To_Buf='%s'\n", To_Buf); strcpy(Tdbp->To_Line, To_Buf); num_read++; rc = RC_OK; } else if (feof(Stream)) { rc = RC_EF; } else { #if defined(UNIX) sprintf(g->Message, MSG(READ_ERROR), To_File, strerror(0)); #else sprintf(g->Message, MSG(READ_ERROR), To_File, _strerror(NULL)); #endif if (trace) htrc("%s\n", g->Message); rc = RC_FX; } // endif's fgets if (trace > 1) htrc("ReadBuffer: rc=%d\n", rc); IsRead = true; return rc; } // end of ReadBuffer /***********************************************************************/ /* WriteBuffer: File write routine for DOS access method. */ /***********************************************************************/ int DOSFAM::WriteBuffer(PGLOBAL g) { char *crlf = "\n"; int curpos = 0; bool moved = true; // T_Stream is the temporary stream or the table file stream itself if (!T_Stream) if (UseTemp && Tdbp->Mode == MODE_UPDATE) { if (OpenTempFile(g)) return RC_FX; } else T_Stream = Stream; if (Tdbp->Mode == MODE_UPDATE) { /*******************************************************************/ /* Here we simply rewrite a record on itself. There are two cases */ /* were another method should be used, a/ when Update apply to */ /* the whole file, b/ when updating the last field of a variable */ /* length file. The method could be to rewrite a new file, then */ /* to erase the old one and rename the new updated file. */ /*******************************************************************/ curpos = ftell(Stream); if (trace) htrc("Last : %d cur: %d\n", Fpos, curpos); if (UseTemp) { /*****************************************************************/ /* We are using a temporary file. Before writing the updated */ /* record, we must eventually copy all the intermediate records */ /* that have not been updated. */ /*****************************************************************/ if (MoveIntermediateLines(g, &moved)) return RC_FX; Spos = curpos; // New start position } else // Update is directly written back into the file, // with this (fast) method, record size cannot change. if (fseek(Stream, Fpos, SEEK_SET)) { sprintf(g->Message, MSG(FSETPOS_ERROR), 0); return RC_FX; } // endif } // endif mode /*********************************************************************/ /* Prepare the write buffer. */ /*********************************************************************/ #if defined(WIN32) if (Bin) crlf = "\r\n"; #endif // WIN32 strcat(strcpy(To_Buf, Tdbp->To_Line), crlf); /*********************************************************************/ /* Now start the writing process. */ /*********************************************************************/ if ((fputs(To_Buf, T_Stream)) == EOF) { sprintf(g->Message, MSG(FPUTS_ERROR), strerror(errno)); return RC_FX; } // endif EOF if (Tdbp->Mode == MODE_UPDATE && moved) if (fseek(Stream, curpos, SEEK_SET)) { sprintf(g->Message, MSG(FSEEK_ERROR), strerror(errno)); return RC_FX; } // endif if (trace) htrc("write done\n"); return RC_OK; } // end of WriteBuffer