* To compile: * CRTRPGMOD MODULE(xxx/EKOR4) SRCFILE(xxx/QRPGLESRC) SRCMBR(EKOR4) * CRTPGM PGM(xxx/EKOR4) MODULE(EKOR4) BNDSRVPGM(STDIO) BNDDIR(QC2LE) H option(*srcstmt) /copy prototypes,stdio D EOL c const(x'0D25') // ==================================== D EKOR4 pr extpgm('EKOR4') D Option1 2a D EKOR4 pi D Option1 2a D sds D PgmName *proc D PgmStatus 11 15 D PgmStmtNbr 21 28 D PgmException 40 46 D PgmErrorMsg 91 170 D bflag s n D datalen s 10i 0 D pssrStatus s n D CurrentChar s 1a D i s 10i 0 D Word s 4096a varying D Line s 4096a varying D Info s 4096a varying /free if %parms > *zero; bflag = (Option1 = '-b'); endif; datalen = stdin (info); dow datalen > *zero; exsr Reverse; datalen = stdin (info); enddo; *inlr = *on; exit (0); // ********************************** // begsr Reverse; for i = 1 to datalen; CurrentChar = %subst(Info:i:1); select; when CurrentChar = x'25'; // line feed exsr EndLine; when CurrentChar = x'0d'; // carriage return // ignore when CurrentChar = *blank; exsr EndWord; other; Word = Word + CurrentChar; endsl; endfor; endsr; // ********************************** // begsr EndLine; if %len(Word) > *zero; Line = Word + ' ' + Line; %len(Word) = *zero; endif; if %len(Line) > *zero; stdout (Line + EOL); %len(Line) = *zero; endif; endsr; // ********************************** // begsr EndWord; if %len(Word) > *zero; Line = Word + ' ' + Line; %len(Word) = *zero; elseif bflag; Line = ' ' + Line; endif; endsr; // ********************************** // begsr *pssr; *inlr = *on; if pssrStatus = *off; pssrStatus = *on; else; return; endif; stderr ('Unexpected error.' + CRLF); stderr ('Program....: ' + PgmName + CRLF); stderr ('Statement..: ' + PgmStmtNbr + CRLF); stderr ('Status.....: ' + PgmStatus + CRLF); stderr ('Exception..: ' + PgmException + CRLF); stderr (PgmErrorMsg + CRLF); exit (1); //return; endsr; /end-free