1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/******************************************************
*
* audiosettings - get/set audio preferences from within Pd-patches
* Copyright (C) 2010-2012 IOhannes m zmölnig
*
* forum::für::umläute
*
* institute of electronic music and acoustics (iem)
* university of music and dramatic arts, graz (kug)
*
*
******************************************************
*
* license: GNU General Public License v.3 or later
*
******************************************************/
#include "m_pd.h"
#include "s_stuff.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAXNDEV 20
#define DEVDESCSIZE 80
/**
* find EOS of a string of tokens
* where EOS might be indicated by \0, }
*/
unsigned int findEOT(const char*s, unsigned int length) {
unsigned int len=0;
do {
char c=s[len];
len++;
switch(c) {
case '{':
len+=findEOT(s+len, length-len);
break;
case '}':
if('{'!=s[0])
return len;
else
return len-1;
case '\0':
return len;
}
} while(len<length);
return len;
}
/**
* parse a string like "jack 3" into the name "jack" and the ID '3'
*/
static
int common_parsedriver(const char*str, const int inlen,
char*name, int length,
int *id) {
/* find beginning of trailing number */
int stop=inlen-1;
int start1=0;
int stop1=0;
int start=0;
int ret=0;
while('\0'==str[stop] && stop>=0)
stop--;
start=stop;
while(start>=0) {
char c=str[start];
if(c<48 || c>=57) break;
start--;
}
if(start==stop || start<0)
return ret;
stop1=start;
while(stop1>=0) {
char c=str[stop1];
if(!isspace(c))
break;
stop1--;
}
if(stop1<0)
return ret;
if(( str[start1]=='"' && str[stop1]=='"')
|| (str[start1]=='\'' && str[stop1]=='\'')
|| (str[start1]=='{' && str[stop1]=='}')
) {
start1++;
stop1--;
}
stop1+=2;
if(stop1>=length)stop1=length-1;
snprintf(name, stop1-start1, "%s", str+start1);
ret=(1==sscanf(str+start, "%d", id));
return ret;
}
|