summaryrefslogtreecommitdiff
path: root/docset_xml_gen.scm
blob: 3de3a53ddb0517c5b0525dc70ee075d677acbd06 (plain)
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
#!/usr/bin/env guile
!#

(define title (car (command-line)))
(define args (cdr (command-line)))

; Initialize globals
(define docset-path "")
(define plist-path "")
(define out-path "")
(define doc-name "")
(define doc-other-versions "")
(define doc-url "")
(define doc-version "")

; Define help message
(define (print-help)
  (display (string-append "Usage: " title " [OPTION]... DOCSET\n"))
  (display "Generate XML file for importing docsets into Dash or Zeal\n")
  (display (string-append "Example: " title " -o Ncurses.xml Ncurses.docset\n"))
  (display "\n")
  (display "Options:\n")
  (display "  -h, --help                      Print this help message and exit\n")
  (display "  -n, --name NAME                 Set the value of the \"name\" tag.\n")
  (display "                                  Automatically determined if not set manually\n")
  (display "  -o, --out FILE                  Output to FILE instead of stdout\n")
  (display "      --other-versions VERSION    Add additional versions under the \"other-versions\" tag.\n")
  (display "                                  Multiple values may be set using comma-separation\n")
  (display "  -u, --url URL                   Set the value of the \"url\" tag.\n")
  (display "                                  Multiple values may be set using comma-separation.\n")
  (display "                                  Set to the local path if not set manually\n")
  (display "  -v, --version VERSION           Set the value of the \"version\" tag.\n")
  (display "                                  Automatically determined if not set manually\n"))

; Check for option
(define (check-options arg option-list)
  (cond
	((null? option-list) #f)
	((equal? arg (car option-list)) #t)
	(else
	  (check-options arg (cdr option-list)))))

; Read through options
; TODO split args for certain flags on ','
(define (read-options args)
  (cond
	((null? args)
	 (begin
	   (display "Error: missing DOCSET argument\n")
	   (exit)))
	((check-options (car args) '("-h" "--help"))
	 (begin
	   (print-help)
	   (exit)))
	((check-options (car args) '("-n" "--name"))
	 (begin
	   (set! doc-name (cadr args))
	   (read-options (cddr args))))
	((check-options (car args) '("--other-versions"))
	 (begin
	   (set! doc-other-versions (cadr args))
	   (read-options (cddr args))))
	((check-options (car args) '("-o" "--out"))
	 (begin
	   (set! out-path (cadr args))
	   (read-options (cddr args))))
	((check-options (car args) '("-u" "--url"))
	 (begin
	   (set! doc-url (cadr args))
	   (read-options (cddr args))))
	((check-options (car args) '("-v" "--version"))
	 (begin
	   (set! doc-version (cadr args))
	   (read-options (cddr args))))
	((check-options (car args) '("--"))
	 (set! docset-path (cadr args)))
	(else
	  (set! docset-path (car args)))))

(read-options args)

; Check validity of docset-path
(if (not (access? docset-path R_OK)) 
  (begin
	(display (string-append "Error: " docset-path " is not a valid path\n"))
	(exit)))
(if (not (equal? (stat:type (stat docset-path)) (string->symbol "directory")))
  (begin
	(display (string-append "Error: " docset-path " must be a directory\n"))
	(exit)))

; Attempt to locate plist-path
(set! plist-path (string-append docset-path "/Contents/Info.plist"))
(if (or (not (access? plist-path F_OK)) (not (equal? (stat:type (stat plist-path)) (string->symbol "regular"))))
  (begin
	(display (string-append "Error: " docset-path " is not a valid docset (could not find " plist-path ")\n"))
	(exit)))