text stringlengths 0 357 |
|---|
#include <string.h> |
#include "dc_context.h" |
#include "dc_tools.h" |
static char* find_param(char* haystack, int key, char** ret_p2) |
{ |
char* p1 = NULL; |
char* p2 = NULL; |
/* let p1 point to the start of the */ |
p1 = haystack; |
while (1) { |
if (p1==NULL || *p1==0) { |
return NULL; |
} |
else if (*p1==key && p1[1]=='=') { |
break; |
} |
else { |
p1 = strchr(p1, '\n'); /* if `\r\n` is used, this `\r` is also skipped by this*/ |
if (p1) { |
p1++; |
} |
} |
} |
/* let p2 point to the character _after_ the value - eiter `\n` or `\0` */ |
p2 = strchr(p1, '\n'); |
if (p2==NULL) { |
p2 = &p1[strlen(p1)]; |
} |
*ret_p2 = p2; |
return p1; |
} |
/** |
* Create new parameter list object. |
* |
* @private @memberof dc_param_t |
* @return The created parameter list object. |
*/ |
dc_param_t* dc_param_new() |
{ |
dc_param_t* param = NULL; |
if ((param=calloc(1, sizeof(dc_param_t)))==NULL) { |
exit(28); /* cannot allocate little memory, unrecoverable error */ |
} |
param->packed = calloc(1, 1); |
return param; |
} |
/** |
* Free an parameter list object created eg. by dc_param_new(). |
* |
* @private @memberof dc_param_t |
* @param param The parameter list object to free. |
*/ |
void dc_param_unref(dc_param_t* param) |
{ |
if (param==NULL) { |
return; |
} |
dc_param_empty(param); |
free(param->packed); |
free(param); |
} |
/** |
* Delete all parameters in the object. |
* |
* @memberof dc_param_t |
* @param param Parameter object to modify. |
* @return None. |
*/ |
void dc_param_empty(dc_param_t* param) |
{ |
if (param==NULL) { |
return; |
} |
param->packed[0] = 0; |
} |
/** |
* Store a parameter set. The parameter set must be given in a packed form as |
* `a=value1\nb=value2`. The format should be very strict, additional spaces are not allowed. |
* |
* Before the new packed parameters are stored, _all_ existant parameters are deleted. |
* |
* @private @memberof dc_param_t |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.