-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathredxlate.clp
82 lines (69 loc) · 2.67 KB
/
redxlate.clp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
PGM PARM(&TXT &SRC &TGT)
DCL VAR(&TXT) TYPE(*CHAR) LEN(512)
DCL VAR(&SRC) TYPE(*CHAR) LEN(2)
DCL VAR(&TGT) TYPE(*CHAR) LEN(2)
DCL VAR(&DQNAME) TYPE(*CHAR) LEN(10) VALUE('HTTPRESP')
DCL VAR(&DQLIB) TYPE(*CHAR) LEN(10) VALUE('QGPL')
DCL VAR(&DQLEN) TYPE(*DEC) LEN(5 0)
DCL VAR(&DQDATA) TYPE(*CHAR) LEN(512)
DCL VAR(&DQWAIT) TYPE(*DEC) LEN(5 0) VALUE(0)
DCL VAR(&QCMD) TYPE(*CHAR) LEN(1024) VALUE(' ')
DCL VAR(&Z) TYPE(*CHAR) LEN(1)
DCL VAR(&ESC) TYPE(*CHAR) LEN(3)
DCL VAR(&BLANK) TYPE(*CHAR) VALUE(' ')
DCL VAR(&X) TYPE(*INT) VALUE(0)
DCL VAR(&XTXT) TYPE(*CHAR) LEN(512)
DCL VAR(&XLEN) TYPE(*DEC) LEN(5 0)
DCL VAR(&ETXT) TYPE(*CHAR) LEN(512) VALUE(' ')
/* GET RID OF TRAILING ENVIRONMENTAL NOISE */
CHGVAR VAR(&XTXT) VALUE(%TRIM(&TXT))
CHGVAR VAR(&SRC) VALUE(%TRIM(&SRC))
CHGVAR VAR(&TGT) VALUE(%TRIM(&TGT))
/* GET LENGTH OF INPUT TEXT */
RTVMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(%TRIM(&XTXT)) MSGLEN(&XLEN)
/* ESCAPE SPACES AND APOSTROPHES FOR URL QUERY */
DOUNTIL COND(&X *EQ &XLEN)
CHGVAR VAR(&ESC) VALUE(%TRIM(&BLANK))
CHGVAR VAR(&X) VALUE(&X + 1)
CHGVAR VAR(&Z) VALUE(%SUBSTRING(&XTXT &X 1))
SELECT
WHEN (&Z *EQ ' ') DO
CHGVAR VAR(&ESC) VALUE('%20')
CHGVAR VAR(&Z) VALUE(%TRIM(&BLANK))
ENDDO
WHEN (&Z *EQ '''') DO
CHGVAR VAR(&ESC) VALUE('%27')
CHGVAR VAR(&Z) VALUE(%TRIM(&BLANK))
ENDDO
WHEN (&Z *EQ '&') DO
CHGVAR VAR(&ESC) VALUE('%26')
CHGVAR VAR(&Z) VALUE(%TRIM(&BLANK))
ENDDO
ENDSELECT
CHGVAR VAR(&ETXT) VALUE(&ETXT *TCAT &Z *TCAT &ESC)
ENDDO
CHGVAR VAR(&QCMD) VALUE('/QOpenSys/usr/bin/qsh -x -c')
CHGVAR VAR(&QCMD) VALUE(&QCMD *BCAT '"')
CHGVAR VAR(&QCMD) VALUE(&QCMD *TCAT '/QOpenSys/pkgs/bin/curl ')
CHGVAR VAR(&QCMD) VALUE(&QCMD *BCAT 'http://127.0.0.1:1880/translate?')
CHGVAR VAR(&QCMD) VALUE(&QCMD *TCAT 'src=' *TCAT %LOWER(&SRC) *TCAT '\&')
CHGVAR VAR(&QCMD) VALUE(&QCMD *TCAT 'tgt=' *TCAT %LOWER(&TGT) *TCAT '\&')
CHGVAR VAR(&QCMD) VALUE(&QCMD *TCAT 'text=')
/* ESCAPED TEXT TO TRANSLATE */
CHGVAR VAR(&QCMD) VALUE(&QCMD *TCAT &ETXT)
CHGVAR VAR(&QCMD) VALUE(&QCMD *BCAT ' | ')
/* CAPTURE THE TRANSLATED TEXT INTO DATAQ */
CHGVAR VAR(&QCMD) VALUE(&QCMD *BCAT '/usr/bin/dataq -w ')
CHGVAR VAR(&QCMD) VALUE(&QCMD *BCAT &DQNAME)
CHGVAR VAR(&QCMD) VALUE(&QCMD *TCAT '"')
/*DMPCLPGM*/
/* PREP DATAQ */
CHKOBJ OBJ(&DQLIB/&DQNAME) OBJTYPE(*DTAQ)
MONMSG MSGID(CPF9801) EXEC(CRTDTAQ DTAQ(&DQLIB/&DQNAME) MAXLEN(1024))
/* TELL QSH TO RUN BUT NOT WAIT AFTER COMMAND COMPLETES */
ADDENVVAR ENVVAR(QIBM_QSH_CMD_OUTPUT) VALUE(NONE) REPLACE(*YES)
QSH CMD(&QCMD)
/* GET THE TRANSLATED TEXT AND SEND AS PGMMSG */
CALL QRCVDTAQ PARM(&DQNAME &DQLIB &DQLEN &DQDATA &DQWAIT)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&DQDATA)
ENDPGM