Skip to content

Commit 6068c82

Browse files
Implement -java-package option (#70)
1 parent 95d121c commit 6068c82

File tree

7 files changed

+50
-18
lines changed

7 files changed

+50
-18
lines changed

cobj/cobj.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ int cb_saveargc;
163163
char **cb_saveargv;
164164

165165
const char *cob_config_dir;
166+
extern char *cb_java_package_name = NULL;
166167

167168
#define PROGRAM_ID_LIST_MAX_LEN 1024
168169
char* program_id_list[PROGRAM_ID_LIST_MAX_LEN];
@@ -296,6 +297,7 @@ static const struct option long_options[] = {
296297
{"list-intrinsics", no_argument, NULL, '6'},
297298
{"list-mnemonics", no_argument, NULL, 'q'},
298299
{"save-temps", optional_argument, NULL, '_'},
300+
{"java-package", optional_argument, NULL, 'P'},
299301
{"std", required_argument, NULL, '$'},
300302
{"conf", required_argument, NULL, '&'},
301303
{"debug", no_argument, NULL, 'd'},
@@ -834,19 +836,20 @@ cobc_print_usage (void)
834836
{
835837
puts (_("Usage: cobj [options] file..."));
836838
puts (_("Options:"));
837-
puts (_(" --help Display this message"));
838-
puts (_(" --version, -V Display compiler version"));
839-
puts (_(" -m Create jar files instead of class files (an experimental feature)"));
840-
puts (_(" -free Use free source format"));
841-
puts (_(" -free_1col_aster Use free(1col_aster) source format"));
842-
puts (_(" -g Enable Java compiler debug"));
843-
puts (_(" -E Preprocess only; do not compile or link"));
844-
puts (_(" -C Translation only; convert COBOL to Java"));
845-
puts (_(" -t <file> Generate and place a program listing into <file>"));
846-
puts (_(" -I <directory> Add <directory> to copy files search path"));
847-
puts (_(" -B <options> Add <options> to the Java compiler"));
848-
puts (_(" --list-reserved Display reserved words"));
849-
puts (_(" -assign_external Set the file assign to external"));
839+
puts (_(" --help Display this message"));
840+
puts (_(" --version, -V Display compiler version"));
841+
puts (_(" -m Create jar files instead of class files (an experimental feature)"));
842+
puts (_(" -free Use free source format"));
843+
puts (_(" -free_1col_aster Use free(1col_aster) source format"));
844+
puts (_(" -g Enable Java compiler debug"));
845+
puts (_(" -E Preprocess only; do not compile or link"));
846+
puts (_(" -C Translation only; convert COBOL to Java"));
847+
puts (_(" -t <file> Generate and place a program listing into <file>"));
848+
puts (_(" -I <directory> Add <directory> to copy files search path"));
849+
puts (_(" -B <options> Add <options> to the Java compiler"));
850+
puts (_(" --list-reserved Display reserved words"));
851+
puts (_(" -assign_external Set the file assign to external"));
852+
puts (_(" -java-package(=<package name>) Specify the package name of the generated source code"));
850853
putchar ('\n');
851854

852855
#undef CB_WARNDEF
@@ -1036,6 +1039,11 @@ process_command_line (const int argc, char *argv[])
10361039
}
10371040
}
10381041
break;
1042+
case 'P':
1043+
/* --java-package : Java package name to be written in the head of generated source code */
1044+
if(optarg) {
1045+
cb_java_package_name = optarg;
1046+
}
10391047

10401048
case '3': /* --constant */
10411049
if (optarg) {
@@ -1723,7 +1731,7 @@ process_compile (struct filename *fn)
17231731
}
17241732

17251733
for(char** program_id = program_id_list; *program_id; ++program_id) {
1726-
sprintf(buff, "javac %s -encoding SJIS %s.java",
1734+
sprintf(buff, "javac %s -encoding SJIS -d . %s.java",
17271735
cob_java_flags,
17281736
*program_id);
17291737
ret = process (buff);

cobj/cobj.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ extern int cb_source_line;
138138

139139
extern const char *cob_config_dir;
140140

141+
extern char *cb_java_package_name;
142+
141143
extern char *source_name;
142144
extern char *demangle_name;
143145
extern FILE *cb_storage_file;

cobj/codegen.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4165,7 +4165,7 @@ joutput_java_entrypoint (struct cb_program *prog, cb_tree parameter_list)
41654165
char arg_field_name[COB_SMALL_BUFF];
41664166

41674167
joutput_prefix();
4168-
joutput ("CobolResultSet execute (");
4168+
joutput ("public CobolResultSet execute (");
41694169

41704170
int k;
41714171
for (l = parameter_list; l; l = CB_CHAIN (l)) {
@@ -4286,7 +4286,7 @@ joutput_internal_function (struct cb_program *prog, cb_tree parameter_list)
42864286
//output (")\n");
42874287
//output_indent ("{");
42884288

4289-
joutput_line ("int %s_ (int entry, CobolDataStorage ...argStorages) {", prog->program_id);
4289+
joutput_line ("public int %s_ (int entry, CobolDataStorage ...argStorages) {", prog->program_id);
42904290
joutput_indent_level += 2;
42914291

42924292
joutput_line("this.entry = entry;");
@@ -5923,6 +5923,10 @@ codegen (struct cb_program *prog, const int nested, char** program_id_list)
59235923
//output ("\n");
59245924
}
59255925

5926+
if(cb_java_package_name) {
5927+
joutput_line("package %s;\n", cb_java_package_name);
5928+
}
5929+
59265930
joutput_line("import java.io.UnsupportedEncodingException;");
59275931
joutput_line("import jp.osscons.opensourcecobol.libcobj.*;");
59285932
joutput_line("import jp.osscons.opensourcecobol.libcobj.common.*;");

tests/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ command_line_options_DEPENDENCIES = \
151151
command-line-options.src/ftrace-ftraceall.at \
152152
command-line-options.src/fsyntax-only.at \
153153
command-line-options.src/fserial-variable.at \
154-
command-line-options.src/fshort-variable.at
154+
command-line-options.src/fshort-variable.at \
155+
command-line-options.src/java-package.at
155156

156157
misc_DEPENDENCIES = \
157158
misc.src/signed-comp3.at \

tests/Makefile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,8 @@ command_line_options_DEPENDENCIES = \
690690
command-line-options.src/ftrace-ftraceall.at \
691691
command-line-options.src/fsyntax-only.at \
692692
command-line-options.src/fserial-variable.at \
693-
command-line-options.src/fshort-variable.at
693+
command-line-options.src/fshort-variable.at \
694+
command-line-options.src/java-package.at
694695

695696
misc_DEPENDENCIES = \
696697
misc.src/signed-comp3.at \

tests/command-line-options.at

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ m4_include([t.at])
88
m4_include([B.at])
99
m4_include([list-reserved.at])
1010
m4_include([assign_external.at])
11+
m4_include([java-package.at])
1112
m4_include([Wunreachable.at])
1213
m4_include([ftrace-ftraceall.at])
1314
m4_include([fsyntax-only.at])
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
AT_SETUP([-java-package])
2+
3+
AT_DATA([prog.cbl], [
4+
IDENTIFICATION DIVISION.
5+
PROGRAM-ID. prog.
6+
PROCEDURE DIVISION.
7+
DISPLAY "Hello".
8+
])
9+
10+
AT_CHECK([${COBJ} -java-package=libcobj.test prog.cbl])
11+
AT_CHECK([java libcobj.test.prog], [0],
12+
[Hello
13+
])
14+
15+
AT_CLEANUP

0 commit comments

Comments
 (0)