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
2 changes: 1 addition & 1 deletion cobj/typeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -7623,7 +7623,7 @@ void cb_emit_search_all(cb_tree table, cb_tree at_end, cb_tree when, cb_tree stm

void cb_emit_setenv(cb_tree x, cb_tree y)
{
cb_emit(cb_build_funcall_2("CobolTerminal.setEnvironment", x, y));
cb_emit(cb_build_funcall_2("CobolUtil.setEnv", x, y));
}

void cb_emit_set_to(cb_tree vars, cb_tree x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Map.Entry;
import java.util.UUID;
import jp.osscons.opensourcecobol.libcobj.common.CobolConstant;
import jp.osscons.opensourcecobol.libcobj.common.CobolUtil;
import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField;
import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage;
import jp.osscons.opensourcecobol.libcobj.exceptions.CobolCallException;
Expand Down Expand Up @@ -72,7 +73,7 @@ public static void CobolInitCall() {
// call_entry_buff = cob_malloc (COB_SMALL_BUFF);
// call_entry2_buff = cob_malloc (COB_SMALL_BUFF);

s = System.getenv("COB_LOAD_CASE");
s = CobolUtil.getEnv("COB_LOAD_CASE");
if (s != null) {
String sU = s.toUpperCase();
if (sU.equals("LOWER")) {
Expand All @@ -82,7 +83,7 @@ public static void CobolInitCall() {
}
}

s = System.getenv("COB_LIBRARY_PATH");
s = CobolUtil.getEnv("COB_LIBRARY_PATH");
if (s == null || s.equals("")) {
buf = "." + System.getProperty("path.separator") + CobolConstant.COB_LIBRARY_PATH;
} else {
Expand All @@ -95,11 +96,11 @@ public static void CobolInitCall() {
}
setLibraryPath(buf);

s = System.getenv("COB_PACKAGE_PATH");
s = CobolUtil.getEnv("COB_PACKAGE_PATH");
setPackagePath(s);

// TODO プリロードの扱いを検討する
s = System.getenv("COB_PRE_LOAD");
s = CobolUtil.getEnv("COB_PRE_LOAD");

// 用途不明
// call_buffer = cob_malloc (CALL_BUFF_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Properties;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -76,6 +77,8 @@ abstract class handlerlist {
public static final int FERROR_CHAINING = 2;
public static final int FERROR_STACK = 3;

private static Properties envVarTable = new Properties();

/**
* libcob/common.cのcob_check_envの実装
*
Expand All @@ -88,7 +91,7 @@ public static int checkEnv(String name, String value) {
return 0;
}

String s = System.getenv(name);
String s = CobolUtil.getEnv(name);
if (s != null) {
if (s.contentEquals(value)) {
return 1;
Expand All @@ -108,10 +111,11 @@ public static void cob_init(String[] argv, boolean cob_initialized) {
CobolInspect.initString();
CobolFile.cob_init_fileio();
CobolIntrinsic.init();
CobolUtil.envVarTable = new Properties();

for (int i = 0; i < 8; ++i) {
String envVariableName = String.format("COB_SWITCH_%d", i + 1);
String envValue = System.getenv(envVariableName);
String envValue = CobolUtil.getEnv(envVariableName);
if (envValue == null) {
CobolUtil.cobSwitch[i] = false;
} else {
Expand All @@ -121,7 +125,7 @@ public static void cob_init(String[] argv, boolean cob_initialized) {
}

cal = Calendar.getInstance();
String s = System.getenv("COB_DATE");
String s = CobolUtil.getEnv("COB_DATE");
if (s != null) {
Scanner scan = new Scanner(s);
Pattern p = Pattern.compile("([0-9]{4})/([0-9]{2})/([0-9]{2})");
Expand Down Expand Up @@ -150,7 +154,7 @@ public static void cob_init(String[] argv, boolean cob_initialized) {
}
}

s = System.getenv("COB_VERBOSE");
s = CobolUtil.getEnv("COB_VERBOSE");
if (s != null && s.length() > 0 && (s.charAt(0) == 'y' || s.charAt(0) == 'Y')) {
CobolUtil.cob_verbose = true;
}
Expand Down Expand Up @@ -226,7 +230,7 @@ public static void runtimeError(String s) {
* @param envval
*/
public static void getEnvironment(AbstractCobolField envname, AbstractCobolField envval) {
String p = System.getenv(envname.fieldToString());
String p = CobolUtil.getEnv(envname.fieldToString());
if (p == null) {
CobolException.setException(CobolExceptionId.COB_EC_IMP_ACCEPT);
p = " ";
Expand Down Expand Up @@ -668,4 +672,34 @@ public static void setLocation(
System.err.flush();
}
}

public static String getEnv(String envVarName) {
String envVarInTable = CobolUtil.envVarTable.getProperty(envVarName);
if (envVarInTable != null) {
return envVarInTable;
} else {
return System.getenv(envVarName);
}
}

/**
* get environemnt variable
*
* @param envVarName the name of an environment variable.
* @return the value of envVarName, or null if the envVarName is not defined.
*/
public static void setEnv(String envVarName, String envVarValue) {
CobolUtil.envVarTable.setProperty(envVarName, envVarValue);
}

/**
* Set environemnt variable
*
* @param envVarName the name of an environment variable. The leading and trailing spaces are
* ignored.
* @param envVarValue the value of an environment variable to be set.
*/
public static void setEnv(AbstractCobolField envVarName, AbstractCobolField envVarValue) {
CobolUtil.envVarTable.setProperty(envVarName.getString().trim(), envVarValue.getString());
}
}
22 changes: 11 additions & 11 deletions libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public static int invokeFun(
byte[] tmpfnstatus = String.format("%02d", 0).getBytes();
byte[] pTmpfnstatus = tmpfnstatus;
String p_excpcode = "";
String s = System.getenv(TIS_DEFINE_USERFH);
String s = CobolUtil.getEnv(TIS_DEFINE_USERFH);
int iRet = 0;
char ret = '0';
int status1 = 0;
Expand Down Expand Up @@ -645,7 +645,7 @@ public void open(int mode, int sharing, AbstractCobolField fnstatus) {
file_open_env[j] = src[src_i + 1 + j];
}
file_open_env[i - 1] = 0;
String p = System.getenv(new String(Arrays.copyOfRange(file_open_env, 0, i - 1)));
String p = CobolUtil.getEnv(new String(Arrays.copyOfRange(file_open_env, 0, i - 1)));
if (p != null) {
byte[] pbytes = p.getBytes();
for (int j = 0; j < pbytes.length; ++j) {
Expand All @@ -669,7 +669,7 @@ public void open(int mode, int sharing, AbstractCobolField fnstatus) {
for (i = 0; i < NUM_PREFIX; i++) {
byte[] file_open_buff = String.format("%s%s", prefix[i], file_open_name).getBytes();
String p;
if ((p = System.getenv(new String(file_open_buff))) != null) {
if ((p = CobolUtil.getEnv(new String(file_open_buff))) != null) {
file_open_name_bytes = p.getBytes();
break;
}
Expand All @@ -690,8 +690,8 @@ public void open(int mode, int sharing, AbstractCobolField fnstatus) {
was_not_exist = true;
if (mode != COB_OPEN_OUTPUT
&& !this.flag_optional
&& (mode != COB_OPEN_I_O || !System.getenv(COB_IO_CREATES).equals("yes"))
&& (mode != COB_OPEN_EXTEND || !System.getenv(COB_EXTEND_CREATES).equals("yes"))) {
&& (mode != COB_OPEN_I_O || !CobolUtil.getEnv(COB_IO_CREATES).equals("yes"))
&& (mode != COB_OPEN_EXTEND || !CobolUtil.getEnv(COB_EXTEND_CREATES).equals("yes"))) {
saveStatus(COB_STATUS_35_NOT_EXISTS, fnstatus);
return;
}
Expand Down Expand Up @@ -1319,7 +1319,7 @@ protected void cob_sync(CobolFile f, int mode) {

/** libcob/fileio.cのcob_init_fileioの実装 */
public static void cob_init_fileio() {
String s = System.getenv("COB_SYNC");
String s = CobolUtil.getEnv("COB_SYNC");
if (s != null) {
if (s.charAt(0) == 'Y' || s.charAt(0) == 'y') {
cob_do_sync = 1;
Expand All @@ -1329,15 +1329,15 @@ public static void cob_init_fileio() {
}
}

cob_file_path = System.getenv("COB_FILE_PATH");
cob_file_path = CobolUtil.getEnv("COB_FILE_PATH");
if (cob_file_path != null) {
if (cob_file_path.charAt(0) == '\0' || cob_file_path.charAt(0) == ' ') {
cob_file_path = null;
}
}

cob_ls_nulls = System.getenv("COB_LS_NULLS");
cob_ls_fixed = System.getenv("COB_LS_FIXED");
cob_ls_nulls = CobolUtil.getEnv("COB_LS_NULLS");
cob_ls_fixed = CobolUtil.getEnv("COB_LS_FIXED");

file_open_env = new byte[COB_SMALL_BUFF];
// file_open_name = new byte[COB_SMALL_BUFF];
Expand Down Expand Up @@ -1474,7 +1474,7 @@ public void cob_delete_file(AbstractCobolField fnstatus) {
file_open_env[j] = src[src_i + 1 + j];
}
file_open_env[i - 1] = 0;
String p = System.getenv(new String(Arrays.copyOfRange(file_open_env, 0, i - 1)));
String p = CobolUtil.getEnv(new String(Arrays.copyOfRange(file_open_env, 0, i - 1)));
if (p != null) {
byte[] pbytes = p.getBytes();
for (int j = 0; j < pbytes.length; ++j) {
Expand All @@ -1498,7 +1498,7 @@ public void cob_delete_file(AbstractCobolField fnstatus) {
for (i = 0; i < NUM_PREFIX; i++) {
byte[] file_open_buff = String.format("%s%s", prefix[i], file_open_name).getBytes();
String p;
if ((p = System.getenv(new String(file_open_buff))) != null) {
if ((p = CobolUtil.getEnv(new String(file_open_buff))) != null) {
file_open_name_bytes = p.getBytes();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ private static CobolItem newItem(CobolSort hp) {
private static FileIO tmpfile() {
String s;
FileIO fp = new FileIO();
if ((s = System.getenv("TMPDIR")) == null
&& (s = System.getenv("TMP")) == null
&& (s = System.getenv("TEMP")) == null) {
if ((s = CobolUtil.getEnv("TMPDIR")) == null
&& (s = CobolUtil.getEnv("TMP")) == null
&& (s = CobolUtil.getEnv("TEMP")) == null) {
s = "/tmp";
}
if (cob_process_id.equals("")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public static void displayEnvValue(AbstractCobolField f) {
public static void acceptEnvironment(AbstractCobolField f) {
String p = null;
if (CobolUtil.cobLocalEnv != null) {
p = System.getenv(CobolUtil.cobLocalEnv);
p = CobolUtil.getEnv(CobolUtil.cobLocalEnv);
}

if (p == null) {
Expand Down
3 changes: 2 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ misc_DEPENDENCIES = \
misc.src/high-low-value.at \
misc.src/move-sign-leading-separate-to-signed-comp3.at \
misc.src/java-interface.at \
misc.src/comp3-int.at
misc.src/comp3-int.at \
misc.src/env.at

EXTRA_DIST = $(srcdir)/package.m4 \
$(TESTS) \
Expand Down
3 changes: 2 additions & 1 deletion tests/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,8 @@ misc_DEPENDENCIES = \
misc.src/high-low-value.at \
misc.src/move-sign-leading-separate-to-signed-comp3.at \
misc.src/java-interface.at \
misc.src/comp3-int.at
misc.src/comp3-int.at \
misc.src/env.at

EXTRA_DIST = $(srcdir)/package.m4 \
$(TESTS) \
Expand Down
3 changes: 2 additions & 1 deletion tests/misc.at
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ m4_include([comp3-is-numeric.at])
m4_include([high-low-value.at])
m4_include([move-sign-leading-separate-to-signed-comp3.at])
m4_include([java-interface.at])
m4_include([comp3-int.at])
m4_include([comp3-int.at])
m4_include([env.at])
35 changes: 35 additions & 0 deletions tests/misc.src/env.at
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
AT_SETUP([Environment variable])

AT_DATA([prog.cbl],[
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 env-var-name PIC X(14) value "COB_ENV_TEST".
01 env-var-name1 PIC X(12) value "COB_ENV_TEST".
01 env-var-value PIC X(10).
PROCEDURE DIVISION.
accept env-var-value from environment env-var-name
end-accept.
display env-var-value.

set environment env-var-name to "world".
accept env-var-value from environment env-var-name
end-accept.
display env-var-value.

initialize env-var-value.
set environment env-var-name1 to "world".
accept env-var-value from environment env-var-name1
end-accept.
display env-var-value.
])

AT_CHECK([${COBJ} prog.cbl])
AT_CHECK([COB_ENV_TEST=hello java prog], [0],
[hello @&t@
world @&t@
world @&t@
])

AT_CLEANUP