Jack2 1.9.6

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 #include <string.h>
00026 #include "types.h"
00027 
00028 #ifdef __cplusplus
00029 extern "C"
00030 {
00031 #endif
00032 
00033     /* variable argument structure */
00034     typedef struct {
00035         char *server_name;              /* server name */
00036         char *load_name;                /* load module name */
00037         char *load_init;                /* initialization string */
00038     }
00039     jack_varargs_t;
00040 
00041     static const char* jack_default_server_name (void) 
00042         {
00043         const char *server_name;
00044         if ((server_name = getenv("JACK_DEFAULT_SERVER")) == NULL)
00045             server_name = "default";
00046         return server_name;
00047     }
00048 
00049     static inline void jack_varargs_init (jack_varargs_t *va) 
00050         {
00051         memset (va, 0, sizeof(jack_varargs_t));
00052         va->server_name = (char*)jack_default_server_name();
00053     }
00054 
00055     static inline void jack_varargs_parse (jack_options_t options, va_list ap, jack_varargs_t *va) 
00056         {
00057         // initialize default settings
00058         jack_varargs_init (va);
00059 
00060         if ((options & JackServerName)) {
00061             char *sn = va_arg(ap, char *);
00062             if (sn)
00063                 va->server_name = sn;
00064         }
00065         if ((options & JackLoadName))
00066             va->load_name = va_arg(ap, char *);
00067         if ((options & JackLoadInit))
00068             va->load_init = va_arg(ap, char *);
00069     }
00070 
00071 #ifdef __cplusplus
00072 }
00073 #endif
00074 
00075 #endif /* __jack_varargs_h__ */