int WriteHeader(FieldList list, int arch, FILE *file, Annot *annotate) { FILE *temp; /* temporary file */ int okay; /* success or failure? */ long rec_size; /* record size */ long fld_size; /* field-list size */ static char buf[BUFSIZ]; /* buffer for file copy */ char *architecture; /* architecture name */ int n; /* byte count for file copy */ long tot; /* byte count total for file copy */ /* Make temp file. */ temp = tmpfile(); if (temp == NULL) return FALSE; /* Failure to make temp file. */ /* Write field list to temp file; get record size. */ switch (arch) { case NATIVE: okay = WriteNativeFieldList(list, temp); architecture = EsignalArch; if (okay) rec_size = NativeRecordSize(list); break; case EDR1: /* * On machines whose native architecture is EDR1, could call * WriteNativeFieldList here. */ okay = WriteEdrFieldList(list, temp, EDR1); architecture = "EDR1"; if (okay) rec_size = EdrRecordSize(list, EDR1); break; case EDR2: /* * On machines whose native architecture is EDR2, could call * WriteNativeFieldList here. */ okay = WriteEdrFieldList(list, temp, EDR2); architecture = "EDR2"; if (okay) rec_size = EdrRecordSize(list, EDR2); break; case ASCII: okay = WriteAsciiFieldList(list, temp, annotate); architecture = "ASCII"; if (okay) rec_size = -1; break; default: DebugMsg(1, "WriteHeader: unrecognized architecture code."); okay = FALSE; /* Unsupported architecture. */ break; } if (!okay) { fclose(temp); return FALSE; /* Failure to write field list. */ } /* Get field-list size */ fld_size = ftell(temp); /* Write preamble. */ if (!WritePreamble(architecture, fld_size, rec_size, file)) return FALSE; /* Failure to write preamble. */ /* Copy field list from temp file. */ rewind(temp); tot = 0; while ((n = fread(buf, 1, BUFSIZ, temp)) > 0) { fwrite(buf, 1, n, file); tot += n; } if (tot != fld_size) return FALSE; /* I/O error or wrong fld_size. */ return TRUE; /* success */ }
PictureBook::PictureBook(std::string filename) { fLatexFile.open(filename.c_str(), std::ofstream::out); WritePreamble(); }