1 /* Tolerant /proc file parser. Copyright 1998 Andi Kleen */
2 /* $Id: proc.c,v 1.4 1999/01/05 20:54:00 philip Exp $ */
3 /* Fixme: cannot currently cope with removed fields */
10 /* Caller must free return string. */
12 char *proc_gen_fmt(char *name
, int more
, FILE * fh
,...)
14 char buf
[512], format
[512] = "";
15 char *title
, *head
, *hdr
;
18 if (!fgets(buf
, (sizeof buf
) - 1, fh
))
23 title
= va_arg(ap
, char *);
24 for (hdr
= buf
; hdr
;) {
25 while (isspace(*hdr
) || *hdr
== '|')
28 hdr
= strpbrk(hdr
, "| \t\n");
32 if (!strcmp(title
, head
)) {
33 strcat(format
, va_arg(ap
, char *));
34 title
= va_arg(ap
, char *);
38 strcat(format
, "%*s"); /* XXX */
45 fprintf(stderr
, "warning: %s does not contain required field %s\n",
49 return strdup(format
);
53 * this will generate a bitmask of present/missing fields in the header of
56 int proc_guess_fmt(char *name
, FILE *fh
, ...)
63 if (!fgets(buf
, (sizeof buf
) - 1, fh
))
67 while((tmp
= va_arg(ap
, char *))) {
68 int f
= va_arg(ap
, int);
69 if (strstr(buf
,tmp
) != 0)