1 : /* SLV2
2 : * Copyright (C) 2007-2009 Dave Robillard <http://drobilla.net>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it
5 : * under the terms of the GNU General Public License as published by the Free
6 : * Software Foundation; either version 2 of the License, or (at your option)
7 : * any later version.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 : * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 : * for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License along
15 : * with this program; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #define _XOPEN_SOURCE 500
20 :
21 : #include <stdlib.h>
22 : #include <string.h>
23 : #include <assert.h>
24 : #include <stdarg.h>
25 : #include "slv2/util.h"
26 :
27 :
28 : char*
29 : slv2_strjoin(const char* first, ...)
30 1195 : {
31 : /* FIXME: This is, in fact, as stupid as it looks */
32 :
33 1195 : size_t len = strlen(first);
34 1195 : char* result = NULL;
35 : va_list args;
36 :
37 1195 : va_start(args, first);
38 : while (1) {
39 5720 : const char* const s = va_arg(args, const char *);
40 5720 : if (s == NULL)
41 1195 : break;
42 4525 : len += strlen(s);
43 4525 : }
44 1195 : va_end(args);
45 :
46 1195 : result = malloc(len + 1);
47 1195 : if (!result)
48 0 : return NULL;
49 :
50 1195 : strcpy(result, first);
51 1195 : va_start(args, first);
52 : while (1) {
53 5720 : const char* const s = va_arg(args, const char *);
54 5720 : if (s == NULL)
55 1195 : break;
56 4525 : strcat(result, s);
57 4525 : }
58 1195 : va_end(args);
59 :
60 1195 : return result;
61 : }
62 :
63 :
64 : const char*
65 : slv2_uri_to_path(const char* uri)
66 3 : {
67 3 : if (!strncmp(uri, "file://", (size_t)7))
68 1 : return (char*)(uri + 7);
69 : else
70 2 : return NULL;
71 : }
72 :
73 :
74 : char*
75 : slv2_get_lang()
76 4 : {
77 : static char lang[32];
78 4 : lang[31] = '\0';
79 4 : char* tmp = getenv("LANG");
80 4 : if (!tmp) {
81 4 : lang[0] = '\0';
82 : } else {
83 0 : strncpy(lang, tmp, 31);
84 0 : for (int i = 0; i < 31 && lang[i]; ++i) {
85 0 : if (lang[i] == '_') {
86 0 : lang[i] = '-';
87 0 : } else if ( !(lang[i] >= 'a' && lang[i] <= 'z')
88 : && !(lang[i] >= 'A' && lang[i] <= 'Z')) {
89 0 : lang[i] = '\0';
90 0 : break;
91 : }
92 : }
93 : }
94 :
95 4 : return lang;
96 : }
97 :
|