Skip to content

Commit 06c8d6e

Browse files
committed
Add LICENSE and Readme
1 parent 7d93d62 commit 06c8d6e

File tree

8 files changed

+61
-12
lines changed

8 files changed

+61
-12
lines changed

LICENSE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
The MIT License (MIT)
2+
=====================
3+
Copyright © `2023` `undefined-ux`
4+
5+
6+
Permission is hereby granted, free of charge, to any person
7+
obtaining a copy of this software and associated documentation
8+
files (the “Software”), to deal in the Software without
9+
restriction, including without limitation the rights to use,
10+
copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following
13+
conditions:
14+
15+
The above copyright notice and this permission notice shall be
16+
included in all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
19+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25+
OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 大一 C语言大作业
2+
3+
## json解析器
4+
5+
### 命令行版本
6+
7+
#### 使用
8+
```
9+
如果未指定输入或输出文件,则程序将默认使用标准输入或标准输出。
10+
注意:-c / --compress 和 -f / --format 选项不能同时使用
11+
-if, --input 指定输入文件(默认为标准输入)
12+
-of, --output 指定输出文件(默认为标准输出)
13+
-f, --format 使用树形缩进输出格式化的JSON
14+
-h, --help 显示此帮助并退出
15+
-c, --compress 输出压缩的JSON
16+
```
17+
[下载](https://github.com/undefined-ux/json-parser-homework/releases)
18+
[文档](https://undefined-ux.github.io/json-parser-homework)
19+
<del>GUI目前仍然是饼, 没做</del>

cli/cli.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@
126126
<WarningLevel>Level3</WarningLevel>
127127
<FunctionLevelLinking>true</FunctionLevelLinking>
128128
<IntrinsicFunctions>true</IntrinsicFunctions>
129-
<SDLCheck>true</SDLCheck>
129+
<SDLCheck>false</SDLCheck>
130130
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
131131
<ConformanceMode>true</ConformanceMode>
132+
<AdditionalIncludeDirectories>D:\code\homework\json-parser\core;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
132133
</ClCompile>
133134
<Link>
134135
<SubSystem>Console</SubSystem>

core/JsonObject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ void JsonObjInsert(
2525

2626
void destoryJsonObj(struct JsonObj* obj) {
2727
if(obj->key != NULL) destoryJsonString(obj->key);
28-
if(obj->val != NULL) destoryJsonVal(obj->value);
29-
28+
if(obj->value != NULL) destoryJsonVal(obj->value);
3029
}

core/core.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<CharacterSet>Unicode</CharacterSet>
4747
</PropertyGroup>
4848
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49-
<ConfigurationType>Application</ConfigurationType>
49+
<ConfigurationType>StaticLibrary</ConfigurationType>
5050
<UseDebugLibraries>false</UseDebugLibraries>
5151
<PlatformToolset>v143</PlatformToolset>
5252
<WholeProgramOptimization>true</WholeProgramOptimization>
@@ -116,7 +116,7 @@
116116
<WarningLevel>Level3</WarningLevel>
117117
<FunctionLevelLinking>true</FunctionLevelLinking>
118118
<IntrinsicFunctions>true</IntrinsicFunctions>
119-
<SDLCheck>true</SDLCheck>
119+
<SDLCheck>false</SDLCheck>
120120
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
121121
<ConformanceMode>true</ConformanceMode>
122122
</ClCompile>

core/parser.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ struct JsonVal* parseValue() {
2424
char c = fgetc(f);
2525
if (c == '{') return parseObject();
2626
else if (c == '[') return parseArray();
27-
else if (c == 'n') return parseNull();
27+
else if (c == 'n' || c == 'N') {
28+
ungetc(c, f);
29+
return parseNull();
30+
}
2831
else if (c == 't' || c == 'T' || c == 'F' || c == 'f') {
2932
ungetc(c, f);
3033
return parseBool();
@@ -106,7 +109,7 @@ struct JsonVal* parseNumber() {
106109
// 内存分配失败
107110
exit(1);
108111
}
109-
112+
ungetc(c, f);
110113
res->type = NUMBER;
111114
res->val = str;
112115
return res;
@@ -146,6 +149,7 @@ struct JsonVal* parseBool() {
146149
// 异常退出, OS进行内存回收
147150
exit(1);
148151
}
152+
149153
res->type = BOOL; res->val = JsonStringFromCharArray("true");
150154
return res;
151155
}
@@ -256,12 +260,12 @@ struct JsonVal* parseArray() {
256260

257261
struct JsonVal* parseNull() {
258262
char nullStr[] = "null", c;
259-
for (int i = 1; i < 5; i++) {
263+
for (int i = 0; i < 4; i++) {
260264
c = fgetc(f);
261265
if (c != nullStr[i] && c != nullStr[i] - 'a' + 'A') {
262266
fprintf(
263267
stderr,
264-
"Excepted token %c at %llu",
268+
"Unexcepted token %c at %llu",
265269
c, ftell(f) / sizeof(char)
266270
); // 写入报错到标准错误流
267271
exit(1);
@@ -271,7 +275,7 @@ struct JsonVal* parseNull() {
271275
if (c != ' ' && c != '\n' && c != ',' && c != ']' && c != '}') {
272276
fprintf(
273277
stderr,
274-
"Excepted token %c at %llu",
278+
"Unexcepted token %c at %llu",
275279
c, ftell(f) / sizeof(char)
276280
); // 写入报错到标准错误流
277281
exit(1);

cutest/cutest.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<WarningLevel>Level3</WarningLevel>
116116
<FunctionLevelLinking>true</FunctionLevelLinking>
117117
<IntrinsicFunctions>true</IntrinsicFunctions>
118-
<SDLCheck>true</SDLCheck>
118+
<SDLCheck>false</SDLCheck>
119119
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120120
<ConformanceMode>true</ConformanceMode>
121121
</ClCompile>

test/test.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@
116116
<WarningLevel>Level3</WarningLevel>
117117
<FunctionLevelLinking>true</FunctionLevelLinking>
118118
<IntrinsicFunctions>true</IntrinsicFunctions>
119-
<SDLCheck>true</SDLCheck>
119+
<SDLCheck>false</SDLCheck>
120120
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
121121
<ConformanceMode>true</ConformanceMode>
122+
<AdditionalIncludeDirectories>D:\code\homework\json-parser\cutest;D:\code\homework\json-parser\core;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
122123
</ClCompile>
123124
<Link>
124125
<SubSystem>Console</SubSystem>

0 commit comments

Comments
 (0)