-
Notifications
You must be signed in to change notification settings - Fork 2
/
iron-main-hercules-cmds.el
161 lines (132 loc) · 4.74 KB
/
iron-main-hercules-cmds.el
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
;;; iron-main-hercules-cmds --- A major mode to handle MVS or Z/OS JCL.
;;; -*- Mode: Emacs-Lisp; lexical-binding: t; -*-
;;; iron-main-hercules-cmds.el
;;
;; See the file COPYING license and copyright information.
;;
;; Author: Marco Antoniotti <marcoxa [at] gmail.com>
;;
;; Created: December 17th, 2020.
;;
;; Version: 20201229.1
;;
;; Keywords: languages, operating systems.
;;; Commentary:
;;
;; Commands that can be issued to a running Hercules instance.
;; Cfr., `iron-main-hercules-cmd' and
;; `iron-main-hercules-is-listening'.
;;; Code:
;;;; IRON MAIN Hercules commands.
(require 'cl-lib)
(require 'iron-main-vars)
(require 'iron-main-utils)
(require 'iron-main-panels)
;;;; Hercules commands.
;; The following functions implement a subset of the commands that can
;; be issued to a HTTP-enabled Hercules instance. Note that the
;; commands are essentially "query" and "display" commands that do not
;; modify the state of the Hercules instance.
;;
;; In general "query" commands return strings or numbers, while
;; "display" commands return buffers that can then be used later on.
;;
;; Not all commands available are implemented. Please refer to the
;; "Hercules – User Reference Guide" and to the
;; "Hercules – Operations and Utilities Guide", either the (a bit old)
;; PDFs dowloadable from the "http://hercules-390.eu" site or the more
;; up-to-date versions contained in the
;; "https://sdl-hercules-390.github.io/html/" site.
;;
;; Notes:
;;
;; 20201228
;; Hercules HTTP returns HTML, with a <pre> element that just contains
;; the printout produced by the command (which is intended to be
;; issued at the console). Of course, it's be much nicer if Hercules
;; contained a REST and JSON (or better, S-expr) server, alas, su such
;; luxury at the end of 2020.
(cl-defmacro define-hercules-cmd (cmd args &body forms)
"A useful macro to avoid repeating too much boilerplate.
Expands in a `cl-defun' that is named 'iron-main-hercules-xxx',
where xxx is CMD, with (extented) arguments ARGS, calling FORMS.
The variables HOST, PORT, TIMEOUT and CHECK-LISTENING are
declared '&key' in the extended arguments list and available in
FORMS (as in `iron-main-hercules-cmd'); they are also collected
in the KEYS &rest variable."
(let ((cmd-fun-name (intern (format "iron-main-hercules-%s" cmd))))
`(cl-defun ,cmd-fun-name
,(append args
'(&rest
keys
&key
(host
iron-main-hercules-http-host)
(port
iron-main-hercules-http-port)
(timeout 15)
(check-listening nil)
))
,@forms)))
;;;; Hercules console commands.
;;
;; There are two categories of commands (sorry, you have to read the
;; documentation strings): those that return a value -- usually a
;; string or a list of strings -- and those that switch to another
;; buffer/panel showing the output (the "help" command is one of
;; these).
;;
;; Notes:
;; 20210406: MA: implementation of -help command still incomplete.
(defun iron-main--cmd (cmd-string &rest string-args)
(with-output-to-string
(princ cmd-string)
(dolist (sa string-args) ; Maybe remove empty string?
(princ " ")
(princ sa))
))
(defun iron-main--get-html-pre-output (buffer)
(with-current-buffer buffer
(message ">>> CMD result buffer %S" buffer)
(goto-char (point-min))
(let* ((pre-start "<PRE>")
(pre-end "</PRE>")
(pre-start-point (search-forward pre-start nil t))
(pre-end-point (search-forward pre-end nil t))
)
(if (and pre-start-point pre-end-point)
(buffer-substring pre-start-point (- pre-end-point 6))
"")
)))
(define-hercules-cmd "help" (&optional (cmd ""))
"Return result of running the Hercules 'help' command."
(let* ((helpcmd (iron-main--cmd "help" cmd))
(cmdbuf (apply 'iron-main-hercules-cmd helpcmd keys))
)
(when cmdbuf
(iron-main--get-html-pre-output cmdbuf))))
(define-hercules-cmd "qpid" ()
"Return the host process id of the running Hercules instance.
The value returned is a string containing the host system process id
or NIL if the command could not be issued (most likely because there
is no running Hercules instance)."
(let ((cmdbuf (apply 'iron-main-hercules-cmd "qpid" keys)))
(when cmdbuf
(with-current-buffer cmdbuf
(goto-char (point-min))
(let ((pid-re "HHC17013I Process ID = \\([0-9]+\\)"))
(re-search-forward pid-re)
(match-string 1)
)))
))
(define-hercules-cmd "devlist" (&optional (class-or-id ""))
"Return result of running the Hercules 'devlist' command."
(let* ((devlistcmd (iron-main--cmd "devlist" class-or-id))
(cmdbuf (apply 'iron-main-hercules-cmd devlistcmd keys))
)
(when cmdbuf
(iron-main--get-html-pre-output cmdbuf))))
;;;; Epilogue
;;;; ========
(provide 'iron-main-hercules-cmds)
;;; iron-main-hercules-cmds.el ends here