mei_rt2mei_rt2_fix_1meiyap-rt1rt2
Last change
on this file since 8fa2c49 was
c586a3c,
checked in by Mei <mei@…>, 13 years ago
|
1) add support for float static range constraint
2) add a testcase for testing float static range constraint
3) add runall-fast (skipping the creddy part)
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[7f25a67f] | 1 | #include <err.h> |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include <string.h> |
---|
| 4 | |
---|
| 5 | /** |
---|
| 6 | * Malloc, fatal on error. |
---|
| 7 | */ |
---|
[3c251d0] | 8 | void *abac_xmalloc(size_t size) { |
---|
[7f25a67f] | 9 | void *ret; |
---|
| 10 | |
---|
| 11 | ret = malloc(size); |
---|
| 12 | if (ret == NULL) |
---|
| 13 | err(1, "malloc"); |
---|
| 14 | |
---|
| 15 | return ret; |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | /** |
---|
| 19 | * strdup fatal on error |
---|
| 20 | */ |
---|
[3c251d0] | 21 | char *abac_xstrdup(char *source) { |
---|
[7f25a67f] | 22 | char *ret; |
---|
| 23 | |
---|
[ff3d104] | 24 | if (source == NULL) |
---|
| 25 | return NULL; |
---|
| 26 | |
---|
[7f25a67f] | 27 | ret = strdup(source); |
---|
| 28 | if (ret == NULL) |
---|
| 29 | err(1, "strdup"); |
---|
| 30 | |
---|
| 31 | return ret; |
---|
| 32 | } |
---|
[9a411d7] | 33 | |
---|
[c586a3c] | 34 | /* make a brand new string with or without being trimmed */ |
---|
| 35 | char *abac_trim_quotes(char *string) { |
---|
| 36 | char *tmp=abac_xstrdup(string); |
---|
| 37 | int len=strlen(tmp); |
---|
| 38 | if( (tmp[len-1] == '\'' || tmp[len-1] == '"') && |
---|
| 39 | (tmp[0] == '\'' || tmp[0] == '"')) { |
---|
| 40 | tmp[len-1]='\0'; |
---|
| 41 | char *ntmp=abac_xstrdup(&tmp[1]); |
---|
| 42 | free(tmp); |
---|
| 43 | return ntmp; |
---|
| 44 | } |
---|
| 45 | return tmp; |
---|
| 46 | } |
---|
| 47 | |
---|
[9a411d7] | 48 | /** |
---|
| 49 | * Split a string based on the given delimiter. |
---|
| 50 | */ |
---|
| 51 | void abac_split(char *string, char *delim, char **ret, int *num) { |
---|
| 52 | int len = strlen(delim); |
---|
| 53 | char *start = string; |
---|
| 54 | int count = 0; |
---|
| 55 | |
---|
| 56 | // split the string by the delim |
---|
| 57 | while ((start = strstr(string, delim)) != NULL) { |
---|
| 58 | *start = 0; |
---|
| 59 | ret[count++] = string; |
---|
| 60 | string = start + len; |
---|
| 61 | } |
---|
| 62 | ret[count++] = string; |
---|
| 63 | |
---|
| 64 | *num = count; |
---|
| 65 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.