Jack2 1.9.8

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         int   session_id;               /* requested session_id */
00039     }
00040     jack_varargs_t;
00041 
00042     static const char* jack_default_server_name (void)
00043     {
00044         const char *server_name;
00045         if ((server_name = getenv("JACK_DEFAULT_SERVER")) == NULL)
00046             server_name = "default";
00047         return server_name;
00048     }
00049 
00050     static inline void jack_varargs_init (jack_varargs_t *va)
00051     {
00052         memset (va, 0, sizeof(jack_varargs_t));
00053         va->server_name = (char*)jack_default_server_name();
00054         va->session_id = -1;
00055     }
00056 
00057     static inline void jack_varargs_parse (jack_options_t options, va_list ap, jack_varargs_t *va)
00058     {
00059         // initialize default settings
00060         jack_varargs_init (va);
00061 
00062         if ((options & JackServerName)) {
00063             char *sn = va_arg(ap, char *);
00064             if (sn)
00065                 va->server_name = sn;
00066         }
00067         if ((options & JackLoadName))
00068             va->load_name = va_arg(ap, char *);
00069         if ((options & JackLoadInit))
00070             va->load_init = va_arg(ap, char *);
00071         if ((options & JackSessionID)) {
00072             char *sid = va_arg(ap, char *);
00073             if (sid)
00074                 va->session_id = atoi( sid );
00075         }
00076     }
00077 
00078 #ifdef __cplusplus
00079 }
00080 #endif
00081 
00082 #endif /* __jack_varargs_h__ */