Lines Matching +full:a +full:- +full:h

1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* kdc/tdumputil.c - utilities for tab-separated, etc. files */
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
33 #include "k5-int.h"
34 #include "k5-platform.h" /* for vasprintf */
35 #include <assert.h>
36 #include <stdarg.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
41 #include "tdumputil.h"
44 * Structure describing flavor of a tabular output format.
50 * quotechar begins and ends a quoted field. If an instance of quotechar
51 * occurs within a quoted field value, it is doubled.
81 * Double any quote characters present in a quoted field.
92 if (*sp == fl->quotechar) in qquote()
102 writequoted(struct rechandle *h, const char *fmt, va_list ap) in writequoted() argument
106 struct flavor fl = h->flavor; in writequoted()
122 ret = -1; in writequoted()
125 ret = fprintf(h->fh, "%c%s%c", fl.quotechar, qs, fl.quotechar); in writequoted()
127 ret = fprintf(h->fh, "%s", s); in writequoted()
136 * Return a rechandle with the requested file handle and rectype.
138 * rectype must be a valid pointer for the entire lifetime of the rechandle (or
144 struct rechandle *h = calloc(1, sizeof(*h)); in rechandle_common() local
146 if (h == NULL) in rechandle_common()
148 h->fh = fh; in rechandle_common()
149 h->rectype = rectype; in rechandle_common()
150 h->do_sep = 0; in rechandle_common()
151 return h; in rechandle_common()
155 * Return a rechandle for tab-separated output.
160 struct rechandle *h = rechandle_common(fh, rectype); in rechandle_tabsep() local
162 if (h == NULL) in rechandle_tabsep()
164 h->flavor = tabsep; in rechandle_tabsep()
165 return h; in rechandle_tabsep()
169 * Return a rechandle for CSV output.
174 struct rechandle *h = rechandle_common(fh, rectype); in rechandle_csv() local
176 if (h == NULL) in rechandle_csv()
178 h->flavor = csv; in rechandle_csv()
179 return h; in rechandle_csv()
183 * Free a rechandle.
186 rechandle_free(struct rechandle *h) in rechandle_free() argument
188 free(h); in rechandle_free()
192 * Start a record. This includes writing a record type prefix (rectype) if
196 startrec(struct rechandle *h) in startrec() argument
198 if (h->rectype == NULL) { in startrec()
199 h->do_sep = 0; in startrec()
202 h->do_sep = 1; in startrec()
203 return fputs(h->rectype, h->fh); in startrec()
207 * Write a single field of a record. This includes writing a separator
211 writefield(struct rechandle *h, const char *fmt, ...) in writefield() argument
215 struct flavor fl = h->flavor; in writefield()
217 if (h->do_sep) { in writefield()
218 ret = fputc(fl.fieldsep, h->fh); in writefield()
222 h->do_sep = 1; in writefield()
225 ret = vfprintf(h->fh, fmt, ap); in writefield()
227 ret = writequoted(h, fmt, ap); in writefield()
233 * Finish a record (line).
236 endrec(struct rechandle *h) in endrec() argument
239 struct flavor fl = h->flavor; in endrec()
241 ret = fputc(fl.recordsep, h->fh); in endrec()
242 h->do_sep = 0; in endrec()
247 * Write a header line if h->rectype is null. (If rectype is set, it will be
248 * prefixed to output lines, most likely in a mixed record type output file, so
249 * it doesn't make sense to output a header line in that case.)
252 writeheader(struct rechandle *h, char * const *a) in writeheader() argument
257 if (h->rectype != NULL) in writeheader()
259 for (p = a; *p != NULL; p++) { in writeheader()
260 ret = writefield(h, "%s", *p); in writeheader()
264 ret = endrec(h); in writeheader()