Skip to content

Commit 6b2aa60

Browse files
committed
- merge with json modifications from this repo - removed unused json_helper.c - corrected x86 -> win32 in vs solution
1 parent b126901 commit 6b2aa60

File tree

4 files changed

+59
-142
lines changed

4 files changed

+59
-142
lines changed

NppJSONViewer/NPPJSONViewer.sln

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|x64 = Debug|x64
11-
Debug|x86 = Debug|x86
11+
Debug|Win32 = Debug|Win32
1212
Release|x64 = Release|x64
13-
Release|x86 = Release|x86
13+
Release|Win32 = Release|Win32
1414
EndGlobalSection
1515
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1616
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|x64.ActiveCfg = Debug|x64
1717
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|x64.Build.0 = Debug|x64
18-
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|x86.ActiveCfg = Debug|Win32
19-
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|x86.Build.0 = Debug|Win32
18+
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|Win32.ActiveCfg = Debug|Win32
19+
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|Win32.Build.0 = Debug|Win32
2020
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|x64.ActiveCfg = Release|x64
2121
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|x64.Build.0 = Release|x64
22-
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|x86.ActiveCfg = Release|Win32
23-
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|x86.Build.0 = Release|Win32
22+
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|Win32.ActiveCfg = Release|Win32
23+
{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|Win32.Build.0 = Release|Win32
2424
EndGlobalSection
2525
GlobalSection(SolutionProperties) = preSolution
2626
HideSolutionNode = FALSE

NppJSONViewer/json.c

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
#include <stdlib.h>
2424
#include <stdio.h>
2525
#include <assert.h>
26-
#include <memory.h>
27-
#include <sys/types.h>
2826
#include <string.h>
27+
#include <sys/types.h>
2928

3029

3130
enum LEX_VALUE
@@ -63,14 +62,14 @@ rcstring *
6362
rcs_create (size_t length)
6463
{
6564
rcstring *rcs;
66-
rcs = malloc (sizeof (rcstring)); /* allocates memory for a struct rcstring */
65+
rcs = (rcstring *)malloc (sizeof (rcstring)); /* allocates memory for a struct rcstring */
6766
if (rcs == NULL)
6867
return NULL;
6968

7069
rcs->max = length;
7170
rcs->length = 0;
7271

73-
rcs->text = malloc ((rcs->max + 1) * sizeof (char));
72+
rcs->text = (char *)malloc ((rcs->max + 1) * sizeof (char));
7473
if (rcs->text == NULL)
7574
{
7675
free (rcs);
@@ -106,7 +105,7 @@ rcs_resize (rcstring * rcs, size_t length)
106105
char *temp;
107106
assert (rcs != NULL);
108107

109-
temp = realloc (rcs->text, sizeof (char) * (length + 1)); /* length plus '\0' */
108+
temp = (char *)realloc (rcs->text, sizeof (char) * (length + 1)); /* length plus '\0' */
110109
if (temp == NULL)
111110
{
112111
free (rcs);
@@ -164,7 +163,7 @@ rcs_unwrap (rcstring * rcs)
164163
out = NULL;
165164
else
166165
{
167-
out = realloc (rcs->text, sizeof (char) * (strlen (rcs->text) + 1));
166+
out = (char *)realloc (rcs->text, sizeof (char) * (strlen (rcs->text) + 1));
168167
}
169168

170169
free (rcs);
@@ -189,7 +188,7 @@ enum json_error
189188
json_stream_parse (FILE * file, json_t ** document)
190189
{
191190
char buffer[1024]; /* hard-coded value */
192-
unsigned int error = JSON_INCOMPLETE_DOCUMENT;
191+
enum json_error error = JSON_INCOMPLETE_DOCUMENT;
193192

194193
struct json_parsing_info state;
195194

@@ -242,7 +241,7 @@ json_new_value (const enum json_value_type type)
242241
{
243242
json_t *new_object;
244243
/* allocate memory to the new object */
245-
new_object = malloc (sizeof (json_t));
244+
new_object = (json_t *)malloc (sizeof (json_t));
246245
if (new_object == NULL)
247246
return NULL;
248247

@@ -267,13 +266,13 @@ json_new_string (const char *text)
267266
assert (text != NULL);
268267

269268
/* allocate memory for the new object */
270-
new_object = malloc (sizeof (json_t));
269+
new_object = (json_t *)malloc (sizeof (json_t));
271270
if (new_object == NULL)
272271
return NULL;
273272

274273
/* initialize members */
275274
length = strlen (text) + 1;
276-
new_object->text = malloc (length * sizeof (char));
275+
new_object->text = (char *)malloc (length * sizeof (char));
277276
if (new_object->text == NULL)
278277
{
279278
free (new_object);
@@ -299,13 +298,13 @@ json_new_number (const char *text)
299298
assert (text != NULL);
300299

301300
/* allocate memory for the new object */
302-
new_object = malloc (sizeof (json_t));
301+
new_object = (json_t *)malloc (sizeof (json_t));
303302
if (new_object == NULL)
304303
return NULL;
305304

306305
/* initialize members */
307306
length = strlen (text) + 1;
308-
new_object->text = malloc (length * sizeof (char));
307+
new_object->text = (char *)malloc (length * sizeof (char));
309308
if (new_object->text == NULL)
310309
{
311310
free (new_object);
@@ -1136,7 +1135,7 @@ json_format_string (const char *text)
11361135

11371136

11381137
char *
1139-
json_escape (char *text)
1138+
json_escape (const char *text)
11401139
{
11411140
rcstring *output;
11421141
size_t i, length;
@@ -1189,7 +1188,7 @@ json_escape (char *text)
11891188
}
11901189
else if (text[i] < 0x20)
11911190
{
1192-
_snprintf (buffer, 7, "\\u%4.4x", text[i]);
1191+
sprintf (buffer, "\\u%4.4x", text[i]);
11931192
rcs_catcs (output, buffer, 6);
11941193
}
11951194
else
@@ -1202,9 +1201,9 @@ json_escape (char *text)
12021201

12031202

12041203
char *
1205-
json_unescape (char *text)
1204+
json_unescape (const char *text)
12061205
{
1207-
char *result = malloc (strlen (text) + 1);
1206+
char *result = (char *)malloc (strlen (text) + 1);
12081207
size_t r; /* read cursor */
12091208
size_t w; /* write cursor */
12101209

@@ -1298,11 +1297,11 @@ json_unescape (char *text)
12981297
char three = 0x80; /* 10 000000 */
12991298
char four = 0x80; /* 10 000000 */
13001299

1301-
if (!text[++r] == '\\')
1300+
if ( text[++r] != '\\')
13021301
{
13031302
break;
13041303
}
1305-
if (!text[++r] == 'u')
1304+
if ( text[++r] != 'u')
13061305
{
13071306
break;
13081307
}
@@ -1378,8 +1377,8 @@ windows.
13781377
So, added a check for consecutive occurance of CRLF, in this particular
13791378
case line number is incremented only once.
13801379
*/
1381-
1382-
int lexer (char *buffer, char **p, unsigned int *state, rcstring ** text, size_t *line, size_t *char_num)
1380+
int
1381+
lexer (const char *buffer, const char **p, unsigned int *state, rcstring ** text, size_t *line, size_t *char_num)
13831382
{
13841383
int crOccured=0; //flag to mark occurance of CR, fix for windows style line termination which is "CRLF"
13851384
assert (buffer != NULL);
@@ -1415,7 +1414,7 @@ int lexer (char *buffer, char **p, unsigned int *state, rcstring ** text, size_t
14151414
break;
14161415
}
14171416
case '\x0D': /* Carriage return */
1418-
*line += 1; // increment line number
1417+
*line += 1; /* increment line number */
14191418
crOccured=1; //sets the flag for CR occurance
14201419
break;
14211420

@@ -1529,8 +1528,7 @@ int lexer (char *buffer, char **p, unsigned int *state, rcstring ** text, size_t
15291528
case 29:
15301529
case 30:
15311530
case 31:
1532-
/* ASCII control characters can only be present in a JSON string if they are escaped.
1533-
If not then the document is invalid */
1531+
/* ASCII control characters can only be present in a JSON string if they are escaped. If not then the document is invalid */
15341532
return LEX_INVALID_CHARACTER;
15351533
break;
15361534

@@ -2155,7 +2153,7 @@ int lexer (char *buffer, char **p, unsigned int *state, rcstring ** text, size_t
21552153

21562154

21572155
enum json_error
2158-
json_parse_fragment (struct json_parsing_info *info, char *buffer)
2156+
json_parse_fragment (struct json_parsing_info *info, const char *buffer)
21592157
{
21602158
json_t *temp = NULL;
21612159

@@ -2184,7 +2182,7 @@ json_parse_fragment (struct json_parsing_info *info, char *buffer)
21842182
break;
21852183

21862184
default:
2187-
fprintf (stderr, "JSON: state %d: defaulted at line %zd\n", info->state, info->line);
2185+
fprintf (stderr, "JSON: state %u: defaulted at line %zu\n", info->state, info->line);
21882186
return JSON_MALFORMED_DOCUMENT;
21892187
break;
21902188
}
@@ -2283,7 +2281,7 @@ json_parse_fragment (struct json_parsing_info *info, char *buffer)
22832281

22842282
default:
22852283
/* this should never run */
2286-
fprintf (stderr, "JSON: state %d: defaulted at line %zu\n", info->state, info->line);
2284+
fprintf (stderr, "JSON: state %u: defaulted at line %zu\n", info->state, info->line);
22872285
return JSON_MALFORMED_DOCUMENT;
22882286
break;
22892287
}
@@ -2342,7 +2340,7 @@ json_parse_fragment (struct json_parsing_info *info, char *buffer)
23422340
break;
23432341

23442342
default:
2345-
fprintf (stderr, "JSON: state %d: defaulted at line %zu\n", info->state, info->line);
2343+
fprintf (stderr, "JSON: state %u: defaulted at line %zu\n", info->state, info->line);
23462344
return JSON_MALFORMED_DOCUMENT;
23472345
break;
23482346
}
@@ -2378,7 +2376,7 @@ json_parse_fragment (struct json_parsing_info *info, char *buffer)
23782376
break;
23792377

23802378
default: /* this should never run */
2381-
fprintf (stderr, "JSON: state %d: defaulted at line %zu\n", info->state, info->line);
2379+
fprintf (stderr, "JSON: state %u: defaulted at line %zu\n", info->state, info->line);
23822380
return JSON_MALFORMED_DOCUMENT;
23832381
break;
23842382
}
@@ -2402,7 +2400,7 @@ json_parse_fragment (struct json_parsing_info *info, char *buffer)
24022400
break;
24032401

24042402
default:
2405-
fprintf (stderr, "JSON: state %d: defaulted at line %zu\n", info->state, info->line);
2403+
fprintf (stderr, "JSON: state %u: defaulted at line %zu\n", info->state, info->line);
24062404
return JSON_MALFORMED_DOCUMENT;
24072405
break;
24082406
}
@@ -2411,12 +2409,11 @@ json_parse_fragment (struct json_parsing_info *info, char *buffer)
24112409

24122410
case 6: /* label, pos name separator */
24132411
{
2414-
unsigned int value; /* to avoid redundant code */
24152412
/* perform tree sanity checks */
24162413
assert (info->cursor != NULL);
24172414
assert (info->cursor->type == JSON_STRING);
24182415

2419-
switch (value = lexer (buffer, &info->p, &info->lex_state, &info->lex_text, &info->line,&info->char_num))
2416+
switch (lexer (buffer, &info->p, &info->lex_state, &info->lex_text, &info->line,&info->char_num))
24202417
{
24212418
case LEX_STRING:
24222419
if ((temp = json_new_value (JSON_STRING)) == NULL)
@@ -2541,7 +2538,7 @@ json_parse_fragment (struct json_parsing_info *info, char *buffer)
25412538
break;
25422539

25432540
default:
2544-
fprintf (stderr, "JSON: state %d: defaulted at line %zu\n", info->state, info->line);
2541+
fprintf (stderr, "JSON: state %u: defaulted at line %zu\n", info->state, info->line);
25452542
return JSON_MALFORMED_DOCUMENT;
25462543
break;
25472544
}
@@ -2692,7 +2689,7 @@ json_parse_fragment (struct json_parsing_info *info, char *buffer)
26922689
break;
26932690

26942691
default:
2695-
fprintf (stderr, "JSON: state %d: defaulted at line %zu\n", info->state, info->line);
2692+
fprintf (stderr, "JSON: state %u: defaulted at line %zu\n", info->state, info->line);
26962693
return JSON_MALFORMED_DOCUMENT;
26972694
break;
26982695
}
@@ -2753,7 +2750,7 @@ json_parse_fragment (struct json_parsing_info *info, char *buffer)
27532750
break;
27542751

27552752
default:
2756-
fprintf (stderr, "JSON: state %d: defaulted at line %zu\n", info->state, info->line);
2753+
fprintf (stderr, "JSON: state %u: defaulted at line %zu\n", info->state, info->line);
27572754
return JSON_MALFORMED_DOCUMENT;
27582755
break;
27592756
}
@@ -2782,7 +2779,7 @@ json_parse_fragment (struct json_parsing_info *info, char *buffer)
27822779
break;
27832780

27842781
default:
2785-
fprintf (stderr, "JSON: state %d: defaulted at line %zu\n", info->state, info->line);
2782+
fprintf (stderr, "JSON: state %u: defaulted at line %zu\n", info->state, info->line);
27862783
return JSON_UNKNOWN_PROBLEM;
27872784
}
27882785
}
@@ -2796,7 +2793,7 @@ json_parse_fragment (struct json_parsing_info *info, char *buffer)
27962793

27972794

27982795
enum json_error
2799-
json_parse_document (json_t ** root, char *text)
2796+
json_parse_document (json_t ** root, const char *text)
28002797
{
28012798
enum json_error error;
28022799
struct json_parsing_info *jpi;
@@ -2806,7 +2803,7 @@ json_parse_document (json_t ** root, char *text)
28062803
assert (text != NULL);
28072804

28082805
/* initialize the parsing structure */
2809-
jpi = malloc (sizeof (struct json_parsing_info));
2806+
jpi = (struct json_parsing_info *)malloc (sizeof (struct json_parsing_info));
28102807
if (jpi == NULL)
28112808
{
28122809
return JSON_MEMORY;
@@ -2831,14 +2828,9 @@ json_parse_document (json_t ** root, char *text)
28312828
enum json_error
28322829
json_saxy_parse (struct json_saxy_parser_status *jsps, struct json_saxy_functions *jsf, char c)
28332830
{
2834-
/*TODO handle a string instead of a single char */
2835-
/* temp variables */
2836-
rcstring *temp;
2837-
28382831
/* make sure everything is in it's place */
28392832
assert (jsps != NULL);
28402833
assert (jsf != NULL);
2841-
temp = NULL;
28422834

28432835
/* goto where we left off */
28442836
switch (jsps->state)

0 commit comments

Comments
 (0)