Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swen90006-a2-2019
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
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
Li Zixuan
swen90006-a2-2019
Commits
5c824ec1
Commit
5c824ec1
authored
Sep 6, 2019
by
Toby Murray
Browse files
Options
Downloads
Patches
Plain Diff
take input file on command line including - for stdin
parent
88bad7c5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/passbook.c
+32
-4
32 additions, 4 deletions
src/passbook.c
with
32 additions
and
4 deletions
src/passbook.c
+
32
−
4
View file @
5c824ec1
...
...
@@ -365,7 +365,7 @@ void node_save(const node_t *p, FILE *f){
int
save_levelorder
(
const
node_t
*
p
,
const
char
*
filename
){
FILE
*
f
=
fopen
(
filename
,
"w"
);
if
(
f
==
NULL
){
debug_
printf
(
"Couldn't open file %s for writing.
\n
"
,
filename
);
f
printf
(
stderr
,
"Couldn't open file %s for writing.
\n
"
,
filename
);
return
-
1
;
}
nodeptr_list_t
lst
=
{.
head
=
NULL
,
.
last
=
NULL
};
...
...
@@ -450,6 +450,8 @@ static int execute(void){
return
0
;
}
/* returns >=0 on success, in which case the number of instructions executed
is returned. Returns < 0 on failure. */
static
int
run
(
FILE
*
f
){
debug_printf
(
"Attempting to read program. max line length: %d
\n
"
,
MAX_LINE_LENGTH
);
...
...
@@ -492,7 +494,7 @@ static int run(FILE *f){
instructionCount
++
;
int
r
=
execute
();
if
(
r
!=
0
){
return
r
;
return
-
1
;
}
}
...
...
@@ -528,7 +530,7 @@ static int run(FILE *f){
}
int
main
(
void
){
int
main
(
const
int
argc
,
const
char
*
argv
[]
){
cred_t
cred1
,
cred2
;
cred1
.
password
=
"asdfa"
;
cred1
.
username
=
"user1"
;
...
...
@@ -544,6 +546,32 @@ int main(void){
p
=
put
(
p
,
"http://blah.com"
,
cred2
);
assert
(
strcmp
(
lookup
(
p
,
"http://blah.com"
)
->
cred
.
username
,
cred2
.
username
)
==
0
);
run
(
stdin
);
if
(
argc
<=
1
){
fprintf
(
stderr
,
"Usage: %s file1 file2 ...
\n
"
,
argv
[
0
]);
fprintf
(
stderr
,
" use - to read from standard input
\n
"
);
exit
(
0
);
}
for
(
int
i
=
1
;
i
<
argc
;
i
++
){
FILE
*
f
;
if
(
strcmp
(
argv
[
i
],
"-"
)
==
0
){
f
=
stdin
;
}
else
{
f
=
fopen
(
argv
[
i
],
"r"
);
if
(
f
==
NULL
){
fprintf
(
stderr
,
"Error opening %s for reading
\n
"
,
argv
[
i
]);
exit
(
1
);
}
}
int
ans
=
run
(
f
);
if
(
ans
<
0
){
fprintf
(
stderr
,
"Error
\n
"
);
exit
(
1
);
}
/* do not close stdin */
if
(
f
!=
stdin
){
fclose
(
f
);
}
}
return
0
;
}
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