Porting C-Source to OS/400: Difference between revisions

From Try-AS/400
Jump to navigation Jump to search
Created page with "{{FIXME|Complete with Links to all necessary Books.}} == Compiling in QSYS.LIB == * Find out longest line in all C- und H-Files, ** Create '''two''' appropriate SRCPF with ma..."
 
Reworked
Line 1: Line 1:
{{FIXME|Complete with Links to all necessary Books.}}
{{FIXME|Complete with Links to all necessary Books.}}
Because of the ''uncommon'' file handling, name length and character constraints, porting is already a mostly manual task.<ref>It's possible to use stream files in IFS as compiler input, but compiled objects have to be put into a ''QSYS.LIB'', library. So, the file name restrictions apply anyway. The line length problem is mostly gone, though.</ref>


== Compiling in QSYS.LIB ==
Most often, the real challenge is to manually put together a ''config.h'' file. Since there's no capable UNIX shell environment, <code>./configure</code> is no option.<ref>With V4R5, IBM claims to have implemented the C90 standard in Compiler and C-Library. I did not yet find a readymade ''config.h'' with all statements needed for a C90 environment.</ref>
* Find out longest line in all C- und H-Files,
 
** Create '''two''' appropriate SRCPF with matching maximum line lengths:
== Preparations for QSYS.LIB ==
***One for C-Files (may be named ''QCSRC''),
Preparations are mostly one on UNIX/Linux side.
***One for H-Files ('''must''' be named ''H'').
 
* Copy all C-Files into ''QCSRC'',
# Convert Tabs to spaces:<ref>Tabs appear in SEU as only one blank. This makes source indentation hardly visible.</ref><br><code>for FILE in *.c *.h; do cp ${FILE} ${FILE}~; expand -i -t4 < ${FILE}~ > ${FILE}; done</code>
** omit the ''.c''-extension on files,
# Find out longest line in all C- und H-Files.<br><code>wc -L *.c |sort -rn |head</code>
** set type to ''C''.
# Eliminate too long lines by wrapping. This is easily done with <code>set colorcolumn=80</code> in ''vim'', and scrolling through the files with a wide window. <ref>Wider than 80 chars, that is.</ref>
* Copy all H-Files into a ''H'',
# Create (at least) '''two''' appropriate SRCPF with matching maximum line lengths through the RCDLEN parameter for CRTSRCPF:
** omit the ''.h''-extension on files,
## One (or more) for C-Files (''may'' be named ''QCSRC''),<ref>It could be clever to create one PF per subdirectory.</ref>
** set type to ''C''.
## One for H-Files ('''must''' be named ''H'').
# Upload.
## If the file names are already shorter than 10 Characters (excluding file extension), just upload to a SRC PF:<br><code>for FILE in *.c; do echo -n "put ${FILE} MYLIB/QCSRC."; basename ${FILE} .c; done |ftp as400</code><ref>Automatic login and switching to ASCII mode is done though a ''~/.netrc''-file.</ref><ref>FTP ASCII takes care to convert ASCII to EBCDIC.</ref>.
## If the file names are longer, you'll have considerable fun to come up with shorter names, possibly ''grep'' through and replace in all text files if you needed to shorten a ''.h'' name, manually put together a textfile with approopriate ''put'' commands, and hope for the best.
# Change file type to ''C'':<br><code>for FILE in *.c; do echo "quote rcmd CHGPFM FILE(MYLIB/QCSRC) MBR(`basename ${FILE} .c`) SRCTYPE(C)"; done |ftp as400</code><ref>This is a good example how to exploit the ftp server's ability to call CL commands as a replacement for ''rcmd''.</ref>


The precompiler searches private includes in ''*LIBL/H'', without the ''.h''-Extension.
The precompiler searches private includes in ''*LIBL/H'', without the ''.h''-Extension.


Compile Object files as follows:
Compile object files as follows:
  CMD(CRTCMOD MODULE(*CURLIB/MAIN) SRCFILE(*CURLIB/QCSRC) DEFINE(DEF1 DEF2=1) OPTION(*LOGMSG)
  CRTCMOD MODULE(MYLIB/MAIN) SRCFILE(MYLIB/QCSRC) DEFINE(DEF1 DEF2=1) OPTION(*LOGMSG) OUTPUT(*PRINT)<ref>Possibly add ''SYSIFCOPT(*IFS64IO)'' if large file support is desired.</ref>
 
If compilation fails, output will go into a spooled file in ''QEZJOBLOG'' queue.


Possibly add ''SYSIFCOPT(*IFS64IO)'' if large file support is desired.
Link object files to a program as follows:
CRTPGM PGM(MYLIB/MYPG) MODULE(MYLIB/*ALL) ENTMOD(*PGM) ACTGRP(*NEW) DETAIL(*BASIC)


If Compilation fails, output will go into a spooled file in ''QEZJOBLOG'' queue.
== Footnotes ==
<references />


[[Category:Programming]]
[[Category:Programming]]

Revision as of 10:52, 16 July 2020

This article isn't finished yet or needs to be revised. Please keep in mind that thus it may be incomplete.

Reason: Complete with Links to all necessary Books.

Because of the uncommon file handling, name length and character constraints, porting is already a mostly manual task.[1]

Most often, the real challenge is to manually put together a config.h file. Since there's no capable UNIX shell environment, ./configure is no option.[2]

Preparations for QSYS.LIB

Preparations are mostly one on UNIX/Linux side.

  1. Convert Tabs to spaces:[3]
    for FILE in *.c *.h; do cp ${FILE} ${FILE}~; expand -i -t4 < ${FILE}~ > ${FILE}; done
  2. Find out longest line in all C- und H-Files.
    wc -L *.c |sort -rn |head
  3. Eliminate too long lines by wrapping. This is easily done with set colorcolumn=80 in vim, and scrolling through the files with a wide window. [4]
  4. Create (at least) two appropriate SRCPF with matching maximum line lengths through the RCDLEN parameter for CRTSRCPF:
    1. One (or more) for C-Files (may be named QCSRC),[5]
    2. One for H-Files (must be named H).
  5. Upload.
    1. If the file names are already shorter than 10 Characters (excluding file extension), just upload to a SRC PF:
      for FILE in *.c; do echo -n "put ${FILE} MYLIB/QCSRC."; basename ${FILE} .c; done |ftp as400[6][7].
    2. If the file names are longer, you'll have considerable fun to come up with shorter names, possibly grep through and replace in all text files if you needed to shorten a .h name, manually put together a textfile with approopriate put commands, and hope for the best.
  6. Change file type to C:
    for FILE in *.c; do echo "quote rcmd CHGPFM FILE(MYLIB/QCSRC) MBR(`basename ${FILE} .c`) SRCTYPE(C)"; done |ftp as400[8]

The precompiler searches private includes in *LIBL/H, without the .h-Extension.

Compile object files as follows:

CRTCMOD MODULE(MYLIB/MAIN) SRCFILE(MYLIB/QCSRC) DEFINE(DEF1 DEF2=1) OPTION(*LOGMSG) OUTPUT(*PRINT)[9]

If compilation fails, output will go into a spooled file in QEZJOBLOG queue.

Link object files to a program as follows:

CRTPGM PGM(MYLIB/MYPG) MODULE(MYLIB/*ALL) ENTMOD(*PGM) ACTGRP(*NEW) DETAIL(*BASIC)

Footnotes

  1. ↑ It's possible to use stream files in IFS as compiler input, but compiled objects have to be put into a QSYS.LIB, library. So, the file name restrictions apply anyway. The line length problem is mostly gone, though.
  2. ↑ With V4R5, IBM claims to have implemented the C90 standard in Compiler and C-Library. I did not yet find a readymade config.h with all statements needed for a C90 environment.
  3. ↑ Tabs appear in SEU as only one blank. This makes source indentation hardly visible.
  4. ↑ Wider than 80 chars, that is.
  5. ↑ It could be clever to create one PF per subdirectory.
  6. ↑ Automatic login and switching to ASCII mode is done though a ~/.netrc-file.
  7. ↑ FTP ASCII takes care to convert ASCII to EBCDIC.
  8. ↑ This is a good example how to exploit the ftp server's ability to call CL commands as a replacement for rcmd.
  9. ↑ Possibly add SYSIFCOPT(*IFS64IO) if large file support is desired.