[insert project logo here (125x200px max)]

Navigator

Mailinglists

Please report any errors or ommissions you find to our `Help' mailinglist, or post a message in the Forums.

Copyright and Licensing Information

Snap is (c) Jonathan T. Moore, 1999-2002 and licensed under the GNU General Public License (GPL).

All other parts of Splash are (c) Willem de Bruijn, 2002-2003 and licensed under the BSD Open Source License.

All sourcecode is made publicly available.

Acknowledgement

Splash and the Splash website are hosted by SourceForge.net

SourceForge.net Logo

osi-open source certified logo

Splash - Documentation

SNMP Plus a Lightweight API for SNAP Handling

Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

snap-1.1-wjdb/lib/proc.c

Go to the documentation of this file.
00001 /* Tolerant /proc file parser. Copyright 1998 Andi Kleen */ 
00002 
00003 #include <string.h> 
00004 #include <stdarg.h>
00005 #include <stdio.h>
00006 
00007 /* Caller must free return string. */ 
00008 char * 
00009 proc_gen_fmt(char *name, FILE *fh, ...)
00010 {
00011     char buf[512], format[512] = ""; 
00012     char *title, *head; 
00013     va_list ap;
00014 
00015     if (!fgets(buf, sizeof buf, fh)) 
00016         return NULL; 
00017 
00018     va_start(ap,fh); 
00019     head = strtok(buf, " \t"); 
00020     title = va_arg(ap, char *); 
00021     while (title && head) { 
00022         if (!strcmp(title, head)) { 
00023             strcat(format, va_arg(ap, char *)); 
00024             title = va_arg(ap, char *); 
00025         } else {
00026             strcat(format, "%*[^ \t]"); 
00027         }
00028         strcat(format, " "); 
00029         head = strtok(NULL, " \t"); 
00030     }
00031     va_end(ap); 
00032 
00033     if (title) { 
00034         fprintf(stderr, "warning: %s does not contain required field %s\n",
00035                         name, title); 
00036         return NULL; 
00037     }
00038     return strdup(format); 
00039 }