1 /* 2 * Copyright (C) 2004 Jack O'Quin 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation; either version 2.1 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 */ 19 20 #ifndef __jack_varargs_h__ 21 #define __jack_varargs_h__ 22 23 #include <stdlib.h> 24 #include <stdarg.h> 25 #include <string.h> 26 #include "types.h" 27 28 #ifdef __cplusplus 29 extern "C" 30 { 31 #endif 32 33 /* variable argument structure */ 34 typedef struct { 35 char *server_name; /* server name */ 36 char *load_name; /* load module name */ 37 char *load_init; /* initialization string */ 38 jack_uuid_t session_id; /* requested session_id */ 39 } 40 jack_varargs_t; 41 jack_default_server_name(void)42 static const char* jack_default_server_name (void) 43 { 44 const char *server_name; 45 if ((server_name = getenv("JACK_DEFAULT_SERVER")) == NULL) 46 server_name = "default"; 47 return server_name; 48 } 49 jack_varargs_init(jack_varargs_t * va)50 static inline void jack_varargs_init (jack_varargs_t *va) 51 { 52 memset (va, 0, sizeof(jack_varargs_t)); 53 va->server_name = (char*)jack_default_server_name(); 54 } 55 jack_varargs_parse(jack_options_t options,va_list ap,jack_varargs_t * va)56 static inline void jack_varargs_parse (jack_options_t options, va_list ap, jack_varargs_t *va) 57 { 58 // initialize default settings 59 jack_varargs_init (va); 60 61 if ((options & JackServerName)) { 62 char *sn = va_arg(ap, char *); 63 if (sn) 64 va->server_name = sn; 65 } 66 if ((options & JackLoadName)) 67 va->load_name = va_arg(ap, char *); 68 if ((options & JackLoadInit)) 69 va->load_init = va_arg(ap, char *); 70 if ((options & JackSessionID)) { 71 char *sid = va_arg(ap, char *); 72 if (sid) { 73 const long long id = atoll( sid ); 74 if (id > 0) 75 va->session_id = id; 76 } 77 } 78 } 79 80 #ifdef __cplusplus 81 } 82 #endif 83 84 #endif /* __jack_varargs_h__ */ 85