2010-10-27 04:36:24 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include "jansson_private.h"
|
|
|
|
|
|
|
|
void jsonp_error_init(json_error_t *error, const char *source)
|
|
|
|
{
|
|
|
|
if(error)
|
|
|
|
{
|
|
|
|
error->text[0] = '\0';
|
|
|
|
error->line = -1;
|
|
|
|
error->column = -1;
|
2011-02-22 16:47:02 +08:00
|
|
|
error->position = 0;
|
2011-02-23 01:08:41 +08:00
|
|
|
if(source)
|
|
|
|
jsonp_error_set_source(error, source);
|
|
|
|
else
|
|
|
|
error->source[0] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void jsonp_error_set_source(json_error_t *error, const char *source)
|
|
|
|
{
|
|
|
|
if(!error || !source)
|
|
|
|
return;
|
2010-10-27 04:36:24 +08:00
|
|
|
|
2011-02-23 01:08:41 +08:00
|
|
|
size_t length = strlen(source);
|
|
|
|
if(length < JSON_ERROR_SOURCE_LENGTH)
|
|
|
|
strcpy(error->source, source);
|
|
|
|
else {
|
|
|
|
size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4;
|
|
|
|
strcpy(error->source, "...");
|
|
|
|
strcpy(error->source + 3, source + extra);
|
2010-10-27 04:36:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void jsonp_error_set(json_error_t *error, int line, int column,
|
2011-02-22 16:47:02 +08:00
|
|
|
size_t position, const char *msg, ...)
|
2010-10-27 04:36:24 +08:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2011-01-24 03:14:19 +08:00
|
|
|
va_start(ap, msg);
|
2011-02-22 16:47:02 +08:00
|
|
|
jsonp_error_vset(error, line, column, position, msg, ap);
|
2011-01-24 03:14:19 +08:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void jsonp_error_vset(json_error_t *error, int line, int column,
|
2011-02-22 16:47:02 +08:00
|
|
|
size_t position, const char *msg, va_list ap)
|
2011-01-24 03:14:19 +08:00
|
|
|
{
|
2010-10-27 04:36:24 +08:00
|
|
|
if(!error)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(error->text[0] != '\0') {
|
|
|
|
/* error already set */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
error->line = line;
|
|
|
|
error->column = column;
|
2011-02-22 16:47:02 +08:00
|
|
|
error->position = position;
|
2010-10-27 04:36:24 +08:00
|
|
|
|
|
|
|
vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap);
|
|
|
|
}
|