-
Notifications
You must be signed in to change notification settings - Fork 2
/
update-mib.lisp
107 lines (93 loc) · 3.66 KB
/
update-mib.lisp
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
;;;; -*- Mode: Lisp -*-
;;;; $Id$
(in-package :snmp)
(defparameter *preload-mibs*
'("MIB:ietf;SNMPv2-SMI"
"MIB:ietf;SNMPv2-TC"
"MIB:ietf;SNMPv2-TM"
"MIB:ietf;SNMPv2-CONF"
"MIB:ietf;SNMPv2-MIB"
"MIB:iana;IANAifType-MIB"
"MIB:ietf;IF-MIB"
"MIB:ietf;HOST-RESOURCES-MIB"))
(defparameter *lisp-mibs*
'("MIB:lisp;LISP-MIB.txt"
"MIB:lisp;ABCL-MIB.txt"
"MIB:lisp;CLOZURE-MIB.txt"
"MIB:lisp;CMUCL-MIB.txt"
"MIB:lisp;ECL-MIB.txt"
"MIB:lisp;FRANZ-MIB.txt"
"MIB:lisp;LISPWORKS-MIB.txt"
"MIB:lisp;SBCL-MIB.txt"
"MIB:lisp;SCL-MIB.txt"))
(defun compile-mib (&rest args)
(apply #'compile-asn.1 args))
(defun load-mib (&rest args)
(apply #'load-asn.1 args))
(defvar *mib-expression* "SNMP:mib.lisp-expr")
(defvar *mib-dependency-file* "SNMP:mib-depend.lisp")
(defvar *pathname-base*)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro make-mib-pathname (type pathname)
`(merge-pathnames (make-pathname :name (string-downcase
(pathname-name (translate-logical-pathname ,pathname)))
:type ,type
:directory (append (pathname-directory *pathname-base*)
'("compiled-mibs")))
*pathname-base*)))
(defun lisp-file (pathname)
(make-mib-pathname "lisp" pathname))
(defun expr-file (pathname)
(make-mib-pathname "lisp-expr" pathname))
(defun update-mib-internal (mib-list &key (global t))
"Update mib.lisp-expr"
(setq *pathname-base*
(translate-logical-pathname "SNMP:"))
(let ((mib.lisp-expr '())
(mib-depend.lisp '())
(*package* *asn.1-package*))
(dolist (i mib-list)
(format t "; Compiling ~A~%" i)
(compile-asn.1 (pathname i) :to (lisp-file i))
(let ((depends (with-open-file (s (expr-file i) :direction :input)
(read s)))
(name (string-downcase (pathname-name (lisp-file i)))))
(push (if (cdr depends)
`(:file ,name
:depends-on ,(mapcar #'(lambda (x) (string-downcase (symbol-name x)))
(cdr depends)))
`(:file ,name))
mib.lisp-expr)
(if (cdr depends)
(push depends mib-depend.lisp))))
;;; Update MIB Dependency, it's for ASDF
(when global
(with-open-file (s *mib-expression*
:direction :output
:if-exists :supersede)
(format s ";;;; -*- Mode: Lisp -*-~%;;;; Generated by #p\"SNMP:UPDATE-MIB.LISP\"~%")
(pprint (setf mib.lisp-expr (nreverse mib.lisp-expr)) s)
(terpri s)))
;;; Update MIB Dependency, it's for MIB Browser
(when global
(with-open-file (s *mib-dependency-file*
:direction :output
:if-exists :supersede)
(format s ";;;; -*- Mode: Lisp -*-~%;;;; Generated by #p\"SNMP:UPDATE-MIB.LISP\"~%")
(dolist (i `((in-package :asn.1)
:break-line
(eval-when (:load-toplevel :execute)
(mapcar #'(lambda (asn.1::x)
(setf (gethash (car asn.1::x)
asn.1:*mib-module-dependency*)
(cdr asn.1::x)))
',mib-depend.lisp))))
(if (eq i :break-line)
(terpri s)
(pprint i s)))
(terpri s)))))
(defun update-mib ()
(update-mib-internal *preload-mibs* :global t)
(update-mib-internal *lisp-mibs* :global nil)
(asdf:clear-system :snmp)
(asdf:load-system :snmp))