H2cpy command-line options

An option begins with a hyphen (-) and is case sensitive. Single letter options that take no parameters can be grouped behind one hyphen. For example, the three options "-v -C -h" can also be written as "-vCh". Options can be entered in any order.

The forward slash (/) can be used in place of the hyphen. Options that begin with a hyphen must not be used before specifying the first filename.

The following list describes each option in detail. Options are listed in alphabetical order, with upper-case letters preceding lower-case letters. Spaces between the option letter and any parameter are optional.

Option Description
-A Removes strict ANSI interpretation of C-language.

There are some obscure areas in which the current ANSI/ISO C standard differs from earlier C language implementations. If you have problems and suspect it is due to old fashioned C, try using this option.

-C Embeds C code within generated COBOL.

The embedded C source lines start with an asterisk (*) and space and are ignored by the COBOL Compiler. The embedded code has been through the C preprocessor.

-D name[=val] Declare a macro name, optionally giving a value. The value can be a numeric or a string literal.
-E Expand all occurrences of structures and unions.

The COBOL for a structure or union is only given in full when it is first declared. Later references are by name.

-F name=val Equate a C function calling convention name to a COBOL CALL-CONVENTION value val for CALL protoypes, where name can be one of the following:
Name Default value
cdecl 0
default 0
fastcall 2
optlink 16
pascal 11
stdcall 74
system 16

These names match C keywords, possibly with one or more leading underscore characters, except for default which represents the default C calling convention when a convention is not explicitly specified.

-G name Use the group of options specified by name and process them before those options specified on the command line. The options must be held as one or more lines in the file h2cpy.dir, and preceded by the header [name]. The file can be located in the current directory but if name is not found, then H2cpy searches the $COBDIR directory for the file h2cpy.dir. The options in the h2cpy.dir file can include the -G option on the first line after the heading, as long as the name is a forward reference. Lines starting with hash (#) or semi-colon (;) are treated as comment lines and ignored. If verbose mode is selected, then the h2cpy command displays name and the file in which it was found.

For example, the h2cpy.dir file could contain the following:

[default]
-G win32
[win32]
# For generating a simple, general win32 header file 
# from 32-bit windows.h
# This is set for the executable entry points, for dlls 
# add -D DLL
-e 32 -D _MSC_VER=1000 -D CHAR_UNSIGNED -D _M_IX86=500
-D _WIN32 -D WINVER=0x0400 -D WIN32_LEAN_AND_MEAN

If -G option is not specified, the default is -G default. The -G option cannot be combined with other options behind a hyphen (-).

-I path Insert the path at the beginning of the include search path list. This option can be used to add entries until the search path list is full. The list can hold up to fourteen entries.

The search list is initially empty unless the INCLUDE environment variable is used.

-J Change default for character type to unsigned
-K name Specifies that name should be recognized (and ignored) as a keyword. This option is useful for header files tailored for C compilers that are not covered by the -M option.
-M Disables the Microsoft keywords that are normally recognized:
cdecl dllexport dllimport except
far finally fortran interrupt
huge near pascal thread
_asm _based _cdecl _far
_emit _export _fastcall _fortran
_huge _inline _interrupt _loadds
_near _pascal _saveregs _segment
_segname _self    
__asm __based __cdecl __declspec
__export __far __fastcall __fortran
__huge __inline __int8 __int16
__int32 __int64 __leave __loadds
__near __pascal __saveregs __segname
__segment __self __stdcall __try
-O Disable the IBM C (for OS/2) keywords that are normally recognized:
_Cdecl _Far32 _Optlink _System
_Export _Fastcall _Packed _Pascal
_Far16 _Inline _Seg16
-P Just preprocess the C, do not generate the COBOL copyfile.

This option is equivalent to the -C option but additionally suppresses COBOL generation. It is useful if you suspect that H2cpy preprocesses the C source differently from your C compiler.

-R name Add a COBOL reserved word to the dictionary

All current known reserved words are already built into H2cpy. This option enables you to add new ones.

-S Generate COBOL for #define macro definitions into a separate file. The filename will be based on the output filename but with any extension replaced by .78.
-V Do not generate COBOL variable numbers of parameters

This option disables the generation of a provisional COBOL equivalent. (The C language ellipsis (...) has no standard COBOL equivalent at present, so H2cpy ignores it.)

-W Remove COBOL context-sensitive reserved words
-X Extend the COBOL equivalence of string pointers from just char* to both char* and unsigned char*

An unsigned char* parameter to a function prototype will generate, by default, a BY REFERENCE uns-char. The type uns-char is numeric which is generally suitable except for header files, such as os2.h, that use the type unsigned char* to define string pointers. Use the -X option when converting such files so that H2cpy generates BY REFERENCE ANY and you can pass string parameters as PIC X(n) items.

-a type=n Set the alignment for C type, where type is one of: int, char, short, long, llong, pointer, float, dfloat or dlfloat.

There are default alignments for all these C types (see the -e option). This option enables them to be varied individually. Alignment is modified by the #pragma pack directive, if used, in the C header file.

-c Generate all names in COBOL in lower case

H2cpy generates the first occurrence of COBOL names to be as close to the original C names as possible. The case of each letter in the name is as in the original C.

-e n Target environment where n is:
16/ LP32 int 16-bit, long & pointer 32-bit
32/ ILP32 int, long and pointer 32-bit
LLP64 int & long 32-bit, long long & pointer 64-bit
LP64 int 32-bit, long and pointer 64-bit
ILP64 int, long and pointer 64-bit
If this option is not specified, the default is 16 or 32 depending on the environment in which H2cpy is running.

The size and alignment of C types is dependent on the environment in which the code is to run. The 32-bit environment size and alignment for C types are:

char 1:1, short 2:2, int 4:4, long 4:4, long long 8:4, pointer 4:4, float 4:4, double float 8:8 or double long float 8:8.

You can modify the default values using the -a and -s options.

-f Pass #define floating point literals to COBOL

The COBOL Compiler validates the size and format of float literals. By default, if a #define directive specifies a macro as a floating constant, no COBOL is generated. Setting this option causes a COBOL equivalent to be generated; however, the COBOL Compiler may object to the size of the number.

If a floating constant is included in a constant expression and H2cpy evaluates that expression, then the floating constant is treated as zero and a warning given.

-h Convert hex #define value to decimal

By default, if a #define directive specifies a macro as a hexadecimal constant, H2cpy generates a COBOL hexadecimal constant. Setting this option causes H2cpy to generate the equivalent decimal value in the generated COBOL.

-o name Name the generated COBOL output file

By default, the names of the output files containing the generated COBOL are constructed from the basename of the first C header file, with extension .cpy for the main copyfile and .ext for the external declarations file. This option enables you to use an alternative name for the main file. The file containing generated external declarations always has the same basename as the main file.

-p Do not generate CALL prototypes

By default, H2cpy converts C function prototypes into COBOL CALL prototypes. The COBOL Compiler then ensures that any CALLs conform to the CALL prototypes. The checking for conformance is not always very flexible.

Set this option if you do not want H2cpy to generate CALL prototypes.

Beware of calls that pass a numeric literal (or level-78 item) as a parameter. The Compiler converts the item to COMP-5 format with the size being provided by the COBOL CALL prototype. If there is no CALL prototype present, then the default size of two bytes may be incorrect and the call may fail at run time. You must specify the correct size in bytes using the SIZE clause to the BY VALUE phrase in such cases.

-q Do not ask for user response if #include file not found
-r Remove COBOL reserved word list

Use this option to reduce start-up time if you are not going to compile the generated COBOL.

-s type=n Set the size for C type, where type is one of: int, char, short, long, llong, pointer, float, dfloat or dlfloat.
-v Toggle informational messages to screen on/off

This option switches the display of messages on the screen. Verbose mode displays the program banner and other messages, including a trace of nested #include files.

Silent mode displays only error messages. The default is verbose mode.

-w Remove COBOL managed-only reserved words
-z name Remove COBOL reserved word