varargs.h

00001 /*
00002 *  Copyright (C) 2004 Jack O'Quin
00003 *  
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU Lesser General Public License as published by
00006 *  the Free Software Foundation; either version 2.1 of the License, or
00007 *  (at your option) any later version.
00008 *  
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU Lesser General Public License for more details.
00013 *  
00014 *  You should have received a copy of the GNU Lesser General Public License
00015 *  along with this program; if not, write to the Free Software 
00016 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 *
00018 */
00019 
00020 #ifndef __jack_varargs_h__
00021 #define __jack_varargs_h__
00022 
00023 #include <stdlib.h>
00024 #include <stdarg.h>
00025 
00026 #ifdef __cplusplus
00027 extern "C"
00028 {
00029 #endif
00030 
00031     /* variable argument structure */
00032     typedef struct {
00033         char *server_name;              /* server name */
00034         char *load_name;                /* load module name */
00035         char *load_init;                /* initialization string */
00036     }
00037     jack_varargs_t;
00038 
00039     static const char* jack_default_server_name (void) {
00040         const char *server_name;
00041         if ((server_name = getenv("JACK_DEFAULT_SERVER")) == NULL)
00042             server_name = "default";
00043         return server_name;
00044     }
00045 
00046     static inline void jack_varargs_init (jack_varargs_t *va) {
00047         memset (va, 0, sizeof(jack_varargs_t));
00048         va->server_name = (char*)jack_default_server_name();
00049     }
00050 
00051     static inline void jack_varargs_parse (jack_options_t options, va_list ap, jack_varargs_t *va) {
00052         // initialize default settings
00053         jack_varargs_init (va);
00054 
00055         if ((options & JackServerName)) {
00056                    char *sn = va_arg(ap, char *);
00057             if (sn) 
00058                                 va->server_name = sn;
00059             }
00060         if ((options & JackLoadName))
00061             va->load_name = va_arg(ap, char *);
00062         if ((options & JackLoadInit))
00063             va->load_init = va_arg(ap, char *);
00064     }
00065 
00066 #ifdef __cplusplus
00067 }
00068 #endif
00069 
00070 #endif /* __jack_varargs_h__ */

Generated on Thu Feb 14 11:16:02 2008 for Jackdmp by  doxygen 1.5.1