Skip to content
Snippets Groups Projects
Commit 5b0d533c authored by James K. Lowden's avatar James K. Lowden :anchor:
Browse files

whitspace

parent 4d60e89c
No related branches found
No related tags found
No related merge requests found
...@@ -8,33 +8,33 @@ there, of course, via the `CALL` statement. But that's not very ...@@ -8,33 +8,33 @@ there, of course, via the `CALL` statement. But that's not very
convenient, and offers no parameter validation. convenient, and offers no parameter validation.
GCC COBOL as of this writing works *only* in a Posix environment. This GCC COBOL as of this writing works *only* in a Posix environment. This
directory exists to make using OS-provided functions a bit more convenient. directory exists to make using OS-provided functions a bit more convenient.
## Contents ## Contents
The machine-shop tools are in this directory. Things directly usable The machine-shop tools are in this directory. Things directly usable
by a COBOL program are in the `udf/` and `c/` directories. by a COBOL program are in the `udf/` and `c/` directories.
- `scrape.awk` extracts function prototypes from the SYNOPSIS of a man page. - `scrape.awk` extracts function prototypes from the SYNOPSIS of a man page.
- `udf-gen` reads function declarations and, for each one, produces a - `udf-gen` reads function declarations and, for each one, produces a
COBOL User Defined Function (UDF) that calls the function. COBOL User Defined Function (UDF) that calls the function.
- `Makefile` produces a list of function prototypes from Section 2 of - `Makefile` produces a list of function prototypes from Section 2 of
the manual. the manual.
- `c/` contains helper functions in C that cannot be expressed in - `c/` contains helper functions in C that cannot be expressed in
COBOL. For example, the C `errno` "variable" may be a macro, and may COBOL. For example, the C `errno` "variable" may be a macro, and may
not be declared except by `errno.h`, which is not accessible to not be declared except by `errno.h`, which is not accessible to
COBOL. COBOL.
- `udf/Makefile` builds some infrastructure and examples: - `udf/Makefile` builds some infrastructure and examples:
- `udf/libposix-errno.so`, to get at the C `errno` variable and its - `udf/libposix-errno.so`, to get at the C `errno` variable and its
string representation. string representation.
- `udf/posix-mkdir.cbl` automatically from the manual, using `udf-gen`. - `udf/posix-mkdir.cbl` automatically from the manual, using `udf-gen`.
- `udf/t/errno` and - `udf/t/errno` and
- `udf/t/exit` as examples of COBOL programs using these Posix UDFs. - `udf/t/exit` as examples of COBOL programs using these Posix UDFs.
## Prerequisites ## Prerequisites
`udf-gen` is a Python program that imports `udf-gen` is a Python program that imports
the [PLY pycparser module](http://www.dabeaz.com/ply/) module, which must be installed. the [PLY pycparser module](http://www.dabeaz.com/ply/) module, which must be installed.
`udf-gen` is lightly documented, use `udf-gen --help`. It can be a `udf-gen` is lightly documented, use `udf-gen --help`. It can be a
little tedious to set up the first time, but if you want to use more a little tedious to set up the first time, but if you want to use more a
...@@ -42,7 +42,7 @@ few functions, it will be faster than doing the work by hand. ...@@ -42,7 +42,7 @@ few functions, it will be faster than doing the work by hand.
## Limitations ## Limitations
`udf-gen` does not `udf-gen` does not
- generate a working UDF for function parameters of type `struct`, - generate a working UDF for function parameters of type `struct`,
such as is used by **stat**(2). This is because the information is such as is used by **stat**(2). This is because the information is
...@@ -52,14 +52,14 @@ few functions, it will be faster than doing the work by hand. ...@@ -52,14 +52,14 @@ few functions, it will be faster than doing the work by hand.
None of this is particularly difficult; it's just a matter of time and None of this is particularly difficult; it's just a matter of time and
need. The `scrape.awk` script finds 560 functions in the Ubuntu LTS need. The `scrape.awk` script finds 560 functions in the Ubuntu LTS
22.04 manual. Which of those is important is for users to decide. 22.04 manual. Which of those is important is for users to decide.
## Other Options ## Other Options
IBM and Microfocus both supply intrinsic functions to interface with IBM and Microfocus both supply intrinsic functions to interface with
the OS, each in their own way. GnuCOBOL implements some of those functions. the OS, each in their own way. GnuCOBOL implements some of those functions.
## Portability ## Portability
The UDF produced by `udf-gen` is pure ISO COBOL. The code should be The UDF produced by `udf-gen` is pure ISO COBOL. The code should be
compilable by any ISO COBOL compiler. compilable by any ISO COBOL compiler.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#define fd_set struct fd_set #define fd_set struct fd_set
#define id_t unsigned int #define id_t unsigned int
// typedef int mqd_t; // typedef int mqd_t;
#define mqd_t int #define mqd_t int
// typedef unsigned long int nfds_t; // typedef unsigned long int nfds_t;
#define nfds_t unsigned long int #define nfds_t unsigned long int
...@@ -21,8 +21,8 @@ define struct py_sigset_t \ ...@@ -21,8 +21,8 @@ define struct py_sigset_t \
unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))]; \ unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))]; \
}; };
#else #else
#define kernel_sigset_t sigset_t #define kernel_sigset_t sigset_t
#define old_kernel_sigset_t sigset_t #define old_kernel_sigset_t sigset_t
#endif #endif
#if 0 #if 0
...@@ -35,4 +35,3 @@ typedef enum ...@@ -35,4 +35,3 @@ typedef enum
#else #else
#define idtype_t int #define idtype_t int
#endif #endif
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import sys, os, getopt, re, copy import sys, os, getopt, re, copy
from pycparser import c_parser, c_generator, c_ast, parse_file from pycparser import c_parser, c_generator, c_ast, parse_file
def starify(param): def starify(param):
...@@ -51,7 +51,7 @@ def linkage_str( i, name, param ) -> str: ...@@ -51,7 +51,7 @@ def linkage_str( i, name, param ) -> str:
is_array = False; is_array = False;
node = param node = param
if( isinstance(node, c_ast.Decl) ): if( isinstance(node, c_ast.Decl) ):
node = node.type node = node.type
...@@ -59,7 +59,7 @@ def linkage_str( i, name, param ) -> str: ...@@ -59,7 +59,7 @@ def linkage_str( i, name, param ) -> str:
is_array = True; is_array = True;
node = node.type node = node.type
(stars, node) = starify(node) (stars, node) = starify(node)
if( isinstance(node, c_ast.TypeDecl) ): if( isinstance(node, c_ast.TypeDecl) ):
level = 1 level = 1
...@@ -75,10 +75,10 @@ def linkage_str( i, name, param ) -> str: ...@@ -75,10 +75,10 @@ def linkage_str( i, name, param ) -> str:
output = '01 FILLER.\n 02 %s %s %s OCCURS 100' \ output = '01 FILLER.\n 02 %s %s %s OCCURS 100' \
% (item_name, picture, usage) % (item_name, picture, usage)
return (None, None, output) return (None, None, output)
if( isinstance(node.type, c_ast.Struct) ): if( isinstance(node.type, c_ast.Struct) ):
stars = None stars = None
if isinstance(node.type, c_ast.IdentifierType): if isinstance(node.type, c_ast.IdentifierType):
ctype = node.type.names[-1] ctype = node.type.names[-1]
if ctype == 'void': if ctype == 'void':
...@@ -99,7 +99,7 @@ def linkage_str( i, name, param ) -> str: ...@@ -99,7 +99,7 @@ def linkage_str( i, name, param ) -> str:
output = "%02d %s" % (level, ' '.join((item_name, 'PIC ' + picture, usage))) output = "%02d %s" % (level, ' '.join((item_name, 'PIC ' + picture, usage)))
return (stars, item_name, output) return (stars, item_name, output)
node.show() node.show()
return (None, None, '???') return (None, None, '???')
...@@ -115,7 +115,7 @@ def using_str( i, name, param ) -> str: ...@@ -115,7 +115,7 @@ def using_str( i, name, param ) -> str:
if( isinstance(node, c_ast.ArrayDecl) ): if( isinstance(node, c_ast.ArrayDecl) ):
node = node.type node = node.type
(stars, node) = starify(node) (stars, node) = starify(node)
if( isinstance(node, c_ast.TypeDecl) ): if( isinstance(node, c_ast.TypeDecl) ):
item_name = '' item_name = ''
...@@ -141,7 +141,7 @@ def parameter_str( i, name, param ) -> str: ...@@ -141,7 +141,7 @@ def parameter_str( i, name, param ) -> str:
t = [0, 1, 2] # qual, type, name t = [0, 1, 2] # qual, type, name
is_array = False; is_array = False;
node = param node = param
if( isinstance(node, c_ast.Decl) ): if( isinstance(node, c_ast.Decl) ):
node = node.type node = node.type
...@@ -149,7 +149,7 @@ def parameter_str( i, name, param ) -> str: ...@@ -149,7 +149,7 @@ def parameter_str( i, name, param ) -> str:
is_array = True; is_array = True;
node = node.type node = node.type
(stars, node) = starify(node) (stars, node) = starify(node)
if( isinstance(node, c_ast.TypeDecl) ): if( isinstance(node, c_ast.TypeDecl) ):
t[0] = ' '.join(node.quals) t[0] = ' '.join(node.quals)
...@@ -180,7 +180,7 @@ def parameter_str( i, name, param ) -> str: ...@@ -180,7 +180,7 @@ def parameter_str( i, name, param ) -> str:
class VisitPrototypes(c_ast.NodeVisitor): class VisitPrototypes(c_ast.NodeVisitor):
def __init__(self): def __init__(self):
self.done = set() self.done = set()
def type_of(self, node): def type_of(self, node):
while( not isinstance(node.type, c_ast.TypeDecl) ): while( not isinstance(node.type, c_ast.TypeDecl) ):
node = node.type node = node.type
...@@ -191,13 +191,13 @@ class VisitPrototypes(c_ast.NodeVisitor): ...@@ -191,13 +191,13 @@ class VisitPrototypes(c_ast.NodeVisitor):
if name in self.done: if name in self.done:
return return
self.done.add(name) self.done.add(name)
params = [] params = []
cbl_args = [] cbl_args = []
linkage_items = [] linkage_items = []
string_items = [] string_items = []
returns = '???' returns = '???'
if False and isinstance(node.type, c_ast.FuncDecl): if False and isinstance(node.type, c_ast.FuncDecl):
function_decl = node.type function_decl = node.type
print('Function: %s' % node.name) print('Function: %s' % node.name)
...@@ -228,7 +228,7 @@ class VisitPrototypes(c_ast.NodeVisitor): ...@@ -228,7 +228,7 @@ class VisitPrototypes(c_ast.NodeVisitor):
string_items.append(item) string_items.append(item)
linkage_items.append(definition) linkage_items.append(definition)
(stars, rets) = starify(node.type) (stars, rets) = starify(node.type)
if isinstance(rets, c_ast.TypeDecl): if isinstance(rets, c_ast.TypeDecl):
q = ' '.join(rets.quals) q = ' '.join(rets.quals)
...@@ -237,7 +237,7 @@ class VisitPrototypes(c_ast.NodeVisitor): ...@@ -237,7 +237,7 @@ class VisitPrototypes(c_ast.NodeVisitor):
else: else:
t = ' '.join(rets.type.names) t = ' '.join(rets.type.names)
returns = ' '.join((q, t, stars)) returns = ' '.join((q, t, stars))
if name == None: if name == None:
return return
...@@ -263,7 +263,7 @@ class VisitPrototypes(c_ast.NodeVisitor): ...@@ -263,7 +263,7 @@ class VisitPrototypes(c_ast.NodeVisitor):
print( ' Procedure Division %s Returning Return-Value.' print( ' Procedure Division %s Returning Return-Value.'
% args ) % args )
for item in string_items: for item in string_items:
print( ' Inspect Backward %s ' % item + print( ' Inspect Backward %s ' % item +
'Replacing Leading Space By Low-Value' ) 'Replacing Leading Space By Low-Value' )
using_args = '' using_args = ''
if args: if args:
...@@ -281,7 +281,7 @@ for var in ('CPATH', 'C_INCLUDE_PATH'): ...@@ -281,7 +281,7 @@ for var in ('CPATH', 'C_INCLUDE_PATH'):
dir = os.getenv(var) dir = os.getenv(var)
if dir: if dir:
cpp_args = '' cpp_args = ''
def process(srcfile): def process(srcfile):
ast = parse_file(srcfile, use_cpp=True, cpp_args=cpp_args) ast = parse_file(srcfile, use_cpp=True, cpp_args=cpp_args)
# print(c_generator.CGenerator().visit(ast)) # print(c_generator.CGenerator().visit(ast))
...@@ -293,10 +293,10 @@ SYNOPSIS ...@@ -293,10 +293,10 @@ SYNOPSIS
udf-gen [-I include-path] [header-file ...] udf-gen [-I include-path] [header-file ...]
DESCRIPTION DESCRIPTION
For each C function declared in header-file, For each C function declared in header-file,
produce an ISO COBOL user-defined function definition to call it. produce an ISO COBOL user-defined function definition to call it.
If no filename is supplied, declarations are read from standard input. If no filename is supplied, declarations are read from standard input.
All output is written to standard output. All output is written to standard output.
This Python script uses the PLY pycparser module, This Python script uses the PLY pycparser module,
(http://www.dabeaz.com/ply/), which supplies a set of simplified "fake (http://www.dabeaz.com/ply/), which supplies a set of simplified "fake
...@@ -310,7 +310,7 @@ header files. ...@@ -310,7 +310,7 @@ header files.
LIMITATIONS LIMITATIONS
udf-gen does not recognize C struct parameters, such as used by stat(2). udf-gen does not recognize C struct parameters, such as used by stat(2).
No attempt has been made to define "magic" values, such as would No attempt has been made to define "magic" values, such as would
be needed for example by chmod(2). be needed for example by chmod(2).
""" """
...@@ -329,7 +329,7 @@ def main( argv=None ): ...@@ -329,7 +329,7 @@ def main( argv=None ):
# process options # process options
astfile = None astfile = None
for opt, arg in opts: for opt, arg in opts:
if opt in ("-h", "--help"): if opt in ("-h", "--help"):
print(__doc__) print(__doc__)
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
Linkage Section. Linkage Section.
77 Return-Value Binary-Long. 77 Return-Value Binary-Long.
01 Error-Msg PIC X ANY LENGTH. 01 Error-Msg PIC X ANY LENGTH.
Procedure Division Procedure Division
using Error-Msg using Error-Msg
Returning Return-Value. Returning Return-Value.
...@@ -16,4 +16,3 @@ ...@@ -16,4 +16,3 @@
returning error-msg. returning error-msg.
Goback. Goback.
END FUNCTION posix-errno. END FUNCTION posix-errno.
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
Linkage Section. Linkage Section.
77 Return-Value Binary-Long. 77 Return-Value Binary-Long.
77 Exit-Status Binary-Long. 77 Exit-Status Binary-Long.
Procedure Division using Exit-Status Returning Return-Value. Procedure Division using Exit-Status Returning Return-Value.
CALL "_exit" using by value Exit-Status. CALL "_exit" using by value Exit-Status.
Goback. Goback.
......
COPY posix-mkdir. COPY posix-mkdir.
COPY posix-errno. COPY posix-errno.
Identification Division. Identification Division.
Program-ID. test-errno. Program-ID. test-errno.
Data Division. Data Division.
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
77 error-msg PIC X(100). 77 error-msg PIC X(100).
77 errnum Binary-Long. 77 errnum Binary-Long.
77 Filename PIC X(100) Value '/'. 77 Filename PIC X(100) Value '/'.
Procedure Division. Procedure Division.
Display 'calling posix-mkdir with a foolish name ...' Display 'calling posix-mkdir with a foolish name ...'
Move Function posix-mkdir(Filename, 0) to Return-Value. Move Function posix-mkdir(Filename, 0) to Return-Value.
...@@ -22,6 +22,5 @@ ...@@ -22,6 +22,5 @@
Else Else
Display 'Return-Value is ' Return-Value Display 'Return-Value is ' Return-Value
End-If. End-If.
Goback. Goback.
\ No newline at end of file
COPY posix-exit. COPY posix-exit.
Identification Division. Identification Division.
Program-ID. test-exit. Program-ID. test-exit.
Data Division. Data Division.
Working-Storage Section. Working-Storage Section.
77 Return-Value Binary-Long. 77 Return-Value Binary-Long.
77 Exit-Status Binary-Long Value 1. 77 Exit-Status Binary-Long Value 1.
Procedure Division. Procedure Division.
Display 'calling posix-exit ...' Display 'calling posix-exit ...'
Move Function posix-exit(Exit-Status) to Return-Value. Move Function posix-exit(Exit-Status) to Return-Value.
* Does not return, Does not print * Does not return, Does not print
Display 'How did we get here?' Display 'How did we get here?'
Goback. Goback.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment