Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cobj/cobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1048,12 +1048,28 @@ static int process_command_line(const int argc, char *argv[]) {
case 'o':
/* -o : the directory where class files are stored */
/* -class-file-dir : the directory where class files are stored */
if (optarg == NULL || *optarg == '\0') {
fprintf(stderr, "Error: Missing directory path argument\n");
exit(1);
}
if (stat(optarg, &st) != 0 || !(S_ISDIR(st.st_mode))) {
fprintf(stderr, "Error: '%s' is not a valid directory\n", optarg);
exit(1);
}
output_name = strdup(optarg);
break;

case 'j':
/* -j : the directory where java files are stored */
/* -java-source-dir : the directory where java files are stored */
if (optarg == NULL || *optarg == '\0') {
fprintf(stderr, "Error: Missing directory path argument\n");
exit(1);
}
if (stat(optarg, &st) != 0 || !(S_ISDIR(st.st_mode))) {
fprintf(stderr, "Error: '%s' is not a valid directory\n", optarg);
exit(1);
}
java_source_dir = strdup(optarg);
break;

Expand Down
38 changes: 38 additions & 0 deletions tests/command-line-options.src/file-path.at
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,42 @@ AT_CHECK([test ! -e class_dir/prog.class])
AT_CHECK([test ! -e prog.java])
AT_CHECK([rm -f *.java *.class class_dir/* java_dir/*])

AT_CLEANUP


AT_SETUP([file-path options with non-existent directory])

AT_DATA([prog.cbl], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
DISPLAY "HELLO".
])

AT_CHECK([${COBJ} -j java_dir prog.cbl], [1], [],
[Error: 'java_dir' is not a valid directory
])

AT_CHECK([${COBJ} -java-source-dir=java_dir prog.cbl], [1], [],
[Error: 'java_dir' is not a valid directory
])

AT_CHECK([${COBJ} -java-source-dir= prog.cbl], [1], [],
[Error: Missing directory path argument
])

AT_CHECK([${COBJ} -o class_dir prog.cbl], [1], [],
[Error: 'class_dir' is not a valid directory
])

AT_CHECK([${COBJ} -class-file-dir=class_dir prog.cbl], [1], [],
[Error: 'class_dir' is not a valid directory
])

AT_CHECK([${COBJ} -class-file-dir= prog.cbl], [1], [],
[Error: Missing directory path argument
])

AT_CLEANUP