Skip to content

Commit 4c17ae0

Browse files
committed
More updates
1 parent 1c11acc commit 4c17ae0

File tree

11 files changed

+157
-34
lines changed

11 files changed

+157
-34
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ NEWS - user visible changes -*- outline -*-
7373
** New options -M, -MP, -MG, -MD and -MQ to output COPY dependencies
7474
to a file (see "Dependencies options" in the GnuCOBOL manual)
7575

76+
** New option --gentable to build EBCDIC/ASCII translation tables,
77+
for use with the --febcdic-table option
78+
7679
* More notable changes
7780

7881
** execution times were significantly reduced for the following:

build_windows/ChangeLog.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
2025-03-26 David Declerck <david.declerck@ocamlpro.com>
3+
4+
* general for cobc: include new gentable.c
5+
26
2024-10-07 Simon Sobisch <simonsobisch@gnu.org>
37

48
* set_env_vs_dist: supporting space-included paths (not recommended)
@@ -337,7 +341,7 @@
337341
version_libcob.rc, version_cobcrun.rc provided by Simon)
338342

339343

340-
Copyright 2014-2024 Free Software Foundation, Inc.
344+
Copyright 2014-2025 Free Software Foundation, Inc.
341345

342346
Copying and distribution of this file, with or without modification, are
343347
permitted provided the copyright notice and this notice are preserved.

cobc/ChangeLog

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
2025-03-26 David Declerck <david.declerck@ocamlpro.com>
3+
4+
* gentable.c: generate EBCDIC/ASCII translation tables
5+
* cobc.c, help.c: new --gentable option
6+
27
2022-12-08 Simon Sobisch <simonsobisch@gnu.org>
38

49
* cobc.c (process_command_line): fix leak for --copy and -include parsing
@@ -10205,7 +10210,7 @@
1020510210
dropping some options for now
1020610211

1020710212

10208-
Copyright 2001-2024 Free Software Foundation, Inc.
10213+
Copyright 2001-2025 Free Software Foundation, Inc.
1020910214

1021010215
Copying and distribution of this file, with or without modification, are
1021110216
permitted provided the copyright notice and this notice are preserved.

cobc/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Makefile gnucobol/cobc
33
#
4-
# Copyright (C) 2003-2012, 2014-2021 Free Software Foundation, Inc.
4+
# Copyright (C) 2003-2012, 2014-2021, 2025 Free Software Foundation, Inc.
55
# Written by Keisuke Nishida, Roger While, Simon Sobisch
66
#
77
# This file is part of GnuCOBOL.

cobc/cobc.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2001-2024 Free Software Foundation, Inc.
2+
Copyright (C) 2001-2025 Free Software Foundation, Inc.
33
44
Authors:
55
Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Brian Tiffin,
@@ -3411,15 +3411,21 @@ process_command_line (const int argc, char **argv)
34113411
break;
34123412

34133413
case CB_FLAG_GETOPT_GENTABLE: {
3414-
/* -gentable=<enc-from>,<enc-to> */
3415-
const char *from, *to;
3414+
/* --gentable=<ebcdic-enc>,<ascii-enc>[+] */
3415+
char *code_ebcdic, *code_ascii, reversible = 0;
34163416
int res;
3417-
from = strtok (cob_optarg, ",");
3418-
to = strtok (NULL, "");
3419-
if ((from == NULL) || (to == NULL)) {
3420-
cobc_err_exit (COBC_INV_PAR, "-gentable");
3421-
}
3422-
res = gentable (stdout, from, to);
3417+
size_t len;
3418+
code_ebcdic = strtok (cob_optarg, ",");
3419+
code_ascii = strtok (NULL, "");
3420+
if ((code_ebcdic == NULL) || (code_ascii == NULL)) {
3421+
cobc_err_exit (COBC_INV_PAR, "--gentable");
3422+
}
3423+
len = strlen(code_ascii);
3424+
if (code_ascii[len - 1] == '+') {
3425+
reversible = 1;
3426+
code_ascii[len - 1] = '\0';
3427+
}
3428+
res = gentable (stdout, code_ebcdic, code_ascii, reversible);
34233429
exit (res ? EXIT_FAILURE : EXIT_SUCCESS);
34243430
}
34253431

cobc/cobc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2001-2012, 2014-2024 Free Software Foundation, Inc.
2+
Copyright (C) 2001-2012, 2014-2025 Free Software Foundation, Inc.
33
Written by Keisuke Nishida, Roger While, Simon Sobisch,
44
Edward Hart, Ron Norman, Dave Pitts
55
@@ -695,6 +695,6 @@ extern unsigned char cb_toupper (const unsigned char);
695695
extern unsigned char cb_tolower (const unsigned char);
696696

697697
/* gentable.c */
698-
extern int gentable (FILE *, const char *, const char *);
698+
extern int gentable (FILE *, const char *, const char *, char);
699699

700700
#endif /* CB_COBC_H */

cobc/gentable.c

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ output_table (FILE *stream, const char *table)
4646

4747
/* Build a pair of EBCDIC/ASCII translation tables using iconv */
4848
int
49-
gentable (FILE *stream, const char *code_ebcdic, const char *code_ascii)
49+
gentable (FILE *stream, const char *code_ebcdic, const char *code_ascii, char reversible)
5050
{
5151
char ebcdic[UCHAR_MAX + 1], ascii[UCHAR_MAX + 1] = { 0 };
5252
char *ebcdic_ptr = ebcdic, *ascii_ptr = ascii;
@@ -56,7 +56,7 @@ gentable (FILE *stream, const char *code_ebcdic, const char *code_ascii)
5656
iconv_t ic = iconv_open (code_ascii, code_ebcdic);
5757
if (ic == (iconv_t)-1) {
5858
cb_error (_("conversion from %s to %s is not supported by your iconv implementation"),
59-
code_ascii, code_ebcdic);
59+
code_ebcdic, code_ascii);
6060
return -1;
6161
}
6262

@@ -102,15 +102,8 @@ gentable (FILE *stream, const char *code_ebcdic, const char *code_ascii)
102102

103103
iconv_close (ic);
104104

105-
fprintf (stream, "# GnuCOBOL %s <-> %s translation tables\n", code_ebcdic, code_ascii);
106-
107-
fprintf (stream, "\n# %s to %s translation table\n\n", code_ebcdic, code_ascii);
108-
output_table (stream, ascii);
105+
if (nb_irreversible > 0) {
109106

110-
fprintf (stream, "\n# %s to %s translation table\n\n", code_ascii, code_ebcdic);
111-
if (nb_irreversible == 0) {
112-
fprintf (stream, "# This translation being symmetric, the table is built from the previous one.\n\n");
113-
} else {
114107
/* Build the (partial) reverse translation table */
115108
memset (ebcdic, EBCDIC_SUBST_CHAR, UCHAR_MAX + 1);
116109
for (i = 0; i <= UCHAR_MAX; ++i) {
@@ -121,12 +114,40 @@ gentable (FILE *stream, const char *code_ebcdic, const char *code_ascii)
121114
times, the loop above probably did not set it correctly */
122115
ebcdic[(unsigned char)ASCII_SUBST_CHAR] = EBCDIC_SUBST_CHAR;
123116

117+
if (reversible != 0) {
118+
/* If a reversible translation table is requested, we arbitrarily
119+
map together unused characters from both encodings */
120+
unsigned short j = 0;
121+
for (i = 0; i <= UCHAR_MAX; ++i) {
122+
if ((ascii[i] == ASCII_SUBST_CHAR) && (i != EBCDIC_SUBST_CHAR)) {
123+
while ((ebcdic[j] != EBCDIC_SUBST_CHAR) || (j == ASCII_SUBST_CHAR)) {
124+
++j;
125+
}
126+
ascii[i] = (char)j;
127+
ebcdic[j] = (char)i;
128+
}
129+
}
130+
cb_note (COB_WARNOPT_NONE, 0,
131+
_("%d non-reversible conversions were arbitrarily made reversible, you might want to review the generated table"),
132+
nb_irreversible);
133+
} else {
134+
cb_note (COB_WARNOPT_NONE, 0,
135+
_("%d non-reversible conversions were performed, you might want to review the generated table"),
136+
nb_irreversible);
137+
}
138+
}
139+
140+
fprintf (stream, "# GnuCOBOL %s <-> %s translation tables\n", code_ebcdic, code_ascii);
141+
142+
fprintf (stream, "\n# %s to %s translation table\n\n", code_ebcdic, code_ascii);
143+
output_table (stream, ascii);
144+
145+
fprintf (stream, "\n# %s to %s translation table\n\n", code_ascii, code_ebcdic);
146+
if ((nb_irreversible == 0) || (reversible != 0)) {
147+
fprintf (stream, "# This translation being symmetric, the table is built from the previous one.\n\n");
148+
} else {
124149
output_table (stream, ebcdic);
125150
fprintf (stream, "\n");
126-
127-
cb_note (COB_WARNOPT_NONE, 0,
128-
_("%d non-reversible conversions were performed, you might want to review the generated table"),
129-
nb_irreversible);
130151
}
131152

132153
return 0;
@@ -135,11 +156,12 @@ gentable (FILE *stream, const char *code_ebcdic, const char *code_ascii)
135156
#else
136157

137158
int
138-
gentable (FILE *stream, const char *code_ebcdic, const char *code_ascii)
159+
gentable (FILE *stream, const char *code_ebcdic, const char *code_ascii, char reversible)
139160
{
140161
COB_UNUSED (stream);
141162
COB_UNUSED (code_ebcdic);
142163
COB_UNUSED (code_ascii);
164+
COB_UNUSED (reversible);
143165

144166
cb_error (_("runtime is not configured to support %s"), "iconv");
145167
cb_error (_("translation table generation is not available"));

cobc/help.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2001-2024 Free Software Foundation, Inc.
2+
Copyright (C) 2001-2025 Free Software Foundation, Inc.
33
Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch,
44
Brian Tiffin, Edward Hart, Dave Pitts
55
@@ -150,7 +150,7 @@ cobc_print_usage_common_options (void)
150150
puts (_(" -MD output dependencies in .d files while compiling"));
151151
puts (_(" -ext <extension> add file extension for resolving COPY"));
152152
puts (_(" -fcopybook-deps output copybook names as dependencies"));
153-
puts (_(" --gentable=<enc-from>,<enc-to>\toutput to stdout an EBCDIC/ASCII translation table between the given encodings and exit"));
153+
puts (_(" --gentable=<ebcdic-enc>,<ascii-enc>[+]\toutput to stdout an EBCDIC/ASCII translation table between the given encodings and exit (append + to make the translation reversible)"));
154154
putchar ('\n');
155155
}
156156

doc/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
2025-03-26 David Declerck <david.declerck@ocamlpro.com>
3+
4+
* gnucobol.texi: document the new --gentable option
5+
26
2025-01-09 David Declerck <david.declerck@ocamlpro.com>
37

48
* cbrunt.tex.gen: fix for missing "@end verbatim"

doc/gnucobol.texi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ together with a designated C compiler and linker.
6666
This manual corresponds to GnuCOBOL @value{VERSION}.
6767
@page
6868
@vskip 0pt plus 1filll
69-
Copyright @copyright{} 2002-2012, 2014-2024 Free Software Foundation, Inc.@*
69+
Copyright @copyright{} 2002-2012, 2014-2025 Free Software Foundation, Inc.@*
7070
Written by Keisuke Nishida, Roger While, Brian Tiffin, Simon Sobisch.
7171

7272
@insertcopying
@@ -1051,8 +1051,9 @@ Save intermediate files (by default, in current directory).
10511051
@item -fimplicit-init
10521052
Do automatic initialization of the COBOL runtime system.
10531053

1054-
@item --gentable=@var{enc-from},@var{enc-to}
1055-
Build an EBCDIC/ASCII translation table between @var{enc-from} and @var{enc-to}.
1054+
@item --gentable=@var{ebcdic-enc},@var{ascii-enc}[+]
1055+
Build an EBCDIC/ASCII translation table between @var{ebcdic-enc} and @var{ascii-enc}, and exit.
1056+
The translation might not be reversible: append + to arbitrarily make it reversible.
10561057

10571058
@end table
10581059

0 commit comments

Comments
 (0)