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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
/* dictdplugin_dbi.c --
* Created: Thu Mar 18 18:43:50 2004 by vle@gmx.net
* Copyright 2004 Aleksey Cheusov <vle@gmx.net>
* This program comes with ABSOLUTELY NO WARRANTY.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 1, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/********************************************************************/
#include "dictP.h"
#include "plugins_common.h"
#include <maa.h>
static const int static_minus1_array [] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
const int *alloc_minus1_array (size_t count)
{
int *p;
if (count <= sizeof (static_minus1_array) / sizeof (int)){
return static_minus1_array;
}else{
p = (int *) xmalloc (count * sizeof (int));
memset (p, -1, count * sizeof (int));
return p;
}
}
void free_minus1_array (int *p)
{
if (p != static_minus1_array && p){
xfree (p);
}
}
/********************************************************************/
/* returns 0 if success */
static int process_line (
char *s,
void *data,
int (*process_name_value) (const char *opt, const char *val, void *data),
void (*set_error_message) (const char *bad_line, void *data))
{
char * value = NULL;
size_t len = 0;
value = strchr (s, '=');
if (!value){
// snprintf (
// dict_data -> m_err_msg,
// BUFSIZE,
// "invalid configure line: '%s'",
// s);
set_error_message (s, data);
return 1;
}
*value++ = 0;
len = strlen (value);
if (len <= 0)
return 0;
if (value [0] == '"' && value [len - 1] == '"'){
value [len - 1] = 0;
++value;
len -= 2;
}
return process_name_value (s, value, data);
}
static void remove_spaces (char *s)
{
char *p;
int quote = 0;
for (p = s; *s; ){
if (*s == '"'){
*p++ = *s++;
quote = 1 - quote;
continue;
}
if (*s == '#'){
break;
}
if (*s != ' ' || quote)
*p++ = *s++;
else
++s;
}
*p = 0;
}
int process_lines (
char *buf, int len,
void *data,
int (*process_name_value) (const char *opt, const char *val, void *data),
void (*set_error_message) (const char *bad_line, void *data))
{
char *p = NULL;
int comment = 0;
int i = 0;
int ret = 0;
// int eq_sign = 0;
for (i=0; i <= len; ++i){
switch (buf [i]){
case '\n':
case '\0':
buf [i] = 0;
if (p){
remove_spaces (p);
if (*p){
ret = process_line (
p, data, process_name_value, set_error_message);
if (ret){
return ret;
}
}
}
comment = 0;
p = NULL;
break;
case '#':
comment = 1;
break;
// case '=':
// eq_sign = 1;
// break;
default:
if (!p && !isspace (buf [i]))
p = buf + i;
}
if (comment){
buf [i] = 0;
}
}
return 0;
}
|