Skip to content

Instantly share code, notes, and snippets.

@miyamuko
Created January 2, 2012 10:06
Show Gist options
  • Save miyamuko/1550137 to your computer and use it in GitHub Desktop.
Save miyamuko/1550137 to your computer and use it in GitHub Desktop.
xl-winhttp の関数生成
(defun to-api (api)
(setf api (substitute-string api "^WinHttp" ""))
(setf api (substitute-string api "[A-Z][a-z]+" "\\0-"))
(setf api (substitute-string api "-$" ""))
(string-downcase api))
(defun gen-winhttp-api ()
(let ((api-list-html (xhr:xhr-get "http://msdn.microsoft.com/en-us/library/windows/desktop/aa384257.aspx"
:key #'xhr:xhr-response-text)))
(with-output-to-temp-buffer ("*tmp*")
(ppcre:do-register-groups (url title)
("<a href=\"(.*?)\" title=\".*?\">(WinHttp.*?)<" api-list-html)
(setf url (substitute-string url "(v=.*?)" ""))
(let ((api (to-api title))
(api-html (xhr:xhr-get url :key #'xhr:xhr-response-text)))
(let ((code (ppcre:register-groups-bind (code)
("(?s)<pre>\\s*(.*?)</pre>" api-html)
(substitute-string code "\\?" " ")))
(desc (ppcre:register-groups-bind (desc)
((concat "(?s)<p>\\s*The\\s+<strong>" title "</strong>\\s+functions?(.*?)</p>") api-html)
(setf desc (substitute-string desc "<[^<>]+>" ""))
(setf desc (ppcre:regex-replace-all "WinHttp[A-Za-z]+" desc
#'(lambda (m)
(format nil "winhttp:~A" (to-api m)))
:simple-calls t))
(setf desc (string-trim " " desc))
(substitute-string desc "\\`\\([a-z]\\)" "\\U\\1"))))
(format t "~{;; ~A~%~}" (cons url (split-string code #\LFD)))
(format t "(defun ~A ()~%" api)
(format t " \"~A\"~%" desc)
(format t " ;; TODO~%")
(format t " )~%~%")))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment