Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tranquility Virtual Machine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vishnu Menon
Tranquility Virtual Machine
Commits
a6ef581f
Commit
a6ef581f
authored
1 year ago
by
Vishnu Menon
Browse files
Options
Downloads
Patches
Plain Diff
basic json parsing + error handling
parent
3a82cb92
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.c
+22
-9
22 additions, 9 deletions
src/main.c
with
22 additions
and
9 deletions
src/main.c
+
22
−
9
View file @
a6ef581f
...
...
@@ -6,36 +6,37 @@
// my everlasting commitment to ridding code of magic numbers :)
#define MEMORY_SIZE 65535
#define BUFFER_SIZE 32767
#define MAX_TOKEN_LENGTH 32767
int
memory
[
MEMORY_SIZE
];
// no idea what these are yet, when i figure that out i'll rename them something better
int
sp
,
fp
=
MEMORY_SIZE
;
int
img
,
but
,
lab
,
tab
=
0
;
// renaming these too
int
sp
,
fp
=
MEMORY_SIZE
;
/* no idea what these are yet, when i figure that out i'll rename them something better */
int
img
,
but
,
lab
,
tab
=
0
;
/* renaming these too */
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
)
{
printf
(
"Error: Did not specify file."
);
return
1
;
return
EXIT_FAILURE
;
}
else
if
(
argc
>
2
)
{
printf
(
"Error: Too many arguments!"
);
return
1
;
return
EXIT_FAILURE
;
}
FILE
*
executable
=
fopen
(
argv
[
1
],
"r"
);
if
(
executable
==
NULL
)
{
printf
(
"Error: Could not locate %s"
,
argv
[
1
]);
return
1
;
return
EXIT_FAILURE
;
}
char
buffer
[
BUFFER_SIZE
];
while
(
fgets
(
buffer
,
BUFFER_SIZE
-
1
,
executable
)
!=
NULL
)
{
char
instruction_set
[
BUFFER_SIZE
];
jsmn_parser
parser
;
jsmntok_t
tokens
[
MAX_TOKEN_LENGTH
];
// cleanup for easier jsmm parsing
...
...
@@ -54,8 +55,20 @@ int main(int argc, char* argv[]) {
}
}
jsmn_init
(
&
parser
);
int
result
=
jsmn_parse
(
&
parser
,
instruction_set
,
strlen
(
instruction_set
),
tokens
,
sizeof
(
tokens
)
/
sizeof
(
tokens
[
0
]));
// debug line
printf
(
"%s
\n
"
,
instruction_set
);
if
(
result
<
1
||
tokens
[
0
].
type
!=
JSMN_ARRAY
)
{
printf
(
"Error: Bad JSON, is root token not an array?"
);
return
EXIT_FAILURE
;
}
}
return
0
;
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment