static void writeWstring(const wchar_t *s, tfile_t *tf) { size_t nwc = wcslen(s); writeScalar(nwc, tf); tfWrite(tf, s, (nwc+1)*sizeof(wchar_t)); }
static void writeStringOrNull(const char *s, tfile_t *tf) { char exists = (s != NULL); writeScalar(exists, tf); if (exists) { writeString(s, tf); } }
/* * Write out a string (e.g., "structName" or "dir/subdir/structName") for * each struct directly referenced by this template. */ static void writeTemplateRefs(template_t *t, tfile_t *tf) { evl_listnode_t *head = t->tm_imports, *p, *end; int nImports = _evlGetListSize(head); writeScalar(nImports, tf); for (end=NULL, p=head; p!=end; end=head, p=p->li_next) { tmpl_struct_ref_t *sref = (tmpl_struct_ref_t*) p->li_data; writeString(sref->sr_path, tf); } }
static void writeTmplFormat(template_t *t, tfile_t *tf) { evl_list_t *head = t->tm_parsed_format; evl_listnode_t *p, *end; int nSegs = _evlGetListSize(head); writeScalar(nSegs, tf); for (p=head, end=NULL; p!=end; end=head, p=p->li_next) { writeFmtSegment((evl_fmt_segment_t*) p->li_data, t, tf); } }
static void writeAttributes(template_t *t, tfile_t *tf) { evl_list_t *head = t->tm_attributes; evl_listnode_t *p, *end; int nAttrs = _evlGetListSize(head); writeScalar(nAttrs, tf); for (p=head, end=NULL; p!=end; end=head, p=p->li_next) { writeAttribute((tmpl_attribute_t*) p->li_data, t, tf); } }
static void writeTemplate(const template_t *tc, tfile_t *tf) { int magic = TMPL_MAGIC; /* * We discard 'const' because the various I/O functions don't * promise const (because they're 'I' as well as 'O'). */ template_t *t = (template_t*) tc; writeScalar(magic, tf); writeHeader(t, tf); writeScalar(t->tm_flags, tf); writeScalar(t->tm_alignment, tf); writeScalar(t->tm_minsize, tf); writeTemplateRefs(t, tf); writeAttributes(t, tf); if (isRedirectTmpl(t)) { writeTmplRedirection(t, tf); } writeTmplFormat(t, tf); }
static void writeRedirectedAtt(struct redirectedAttribute *ra, int att, tfile_t *tf) { if (ra) { writeScalar(ra->type, tf); switch (ra->type) { case TMPL_RD_NONE: break; case TMPL_RD_CONST: if (att == POSIX_LOG_ENTRY_FACILITY) { writeScalar(ra->u.faccode, tf); } else { writeScalar(ra->u.evtype, tf); } break; case TMPL_RD_ATTNAME: writeString(ra->u.attname, tf); break; } } else { enum redirection_type rdty = TMPL_RD_NONE; writeScalar(rdty, tf); } }
/* * ref is a pointer to a struct template that is referenced by one of the * client template's attributes. Find that struct template in the client's * import list, and write out the index of that struct ref. */ static void writeTmplRef(template_t *ref, template_t *client, tfile_t *tf) { evl_listnode_t *head = client->tm_imports, *p, *end; tmpl_struct_ref_t *sref; int i; for (i=0, end=NULL, p=head; p!=end; end=head, p=p->li_next, i++) { sref = (tmpl_struct_ref_t*) p->li_data; if (sref->sr_template == ref) { writeScalar(i, tf); return; } } fprintf(stderr, "Internal error writing %s: No struct ref for %s\n", tf->tf_path, ref->tm_name); tf->tf_errors++; }
/* Grid output wrapper function: prints arrays related to the grid (rho, u etc) */ void writeGridOutput(struct grid *g, int nGridPoints, double t) { writeScalar(g->rho, t, nGridPoints, "output/rho1D.txt"); writeScalar(g->u, t, nGridPoints, "output/potential1D.txt"); writeVector(g->J, t, nGridPoints, "output/J1D.txt"); }
/* Field output function: prints arrays related to the field (E, B) */ void writeFieldOutput(struct field *f, int nGridPoints, double t) { writeScalar(f->Bz, t, nGridPoints, "output/Bz1D.txt"); writeVector(f->E, t, nGridPoints, "output/E1D.txt"); }
static void writeAttRef(tmpl_attribute_t *att, template_t *t, tfile_t *tf) { writeScalar(att->ta_index, tf); }