File: sawfish-xgettext

package info (click to toggle)
sawfish 1%3A1.3.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 11,636 kB
  • ctags: 1,327
  • sloc: lisp: 22,765; ansic: 15,810; sh: 10,203; makefile: 675; perl: 19
file content (178 lines) | stat: -rwxr-xr-x 5,142 bytes parent folder | download | duplicates (3)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/sh
exec rep "$0" "$@"
!#

;; sawfish-xgettext -- extract i18n strings from lisp scripts
;; $Id: sawfish-xgettext,v 1.8 2001/04/20 21:40:50 jsh Exp $

;; This file is part of sawfish.

;; sawfish is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; sawfish is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with sawfish; see the file COPYING.  If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

(require 'rep.i18n.xgettext)
(require 'rep.lang.doc)

(defvar *write-c-file* nil)

(define (exit n) (throw 'quit n))

;; random hackery

;; from sawfish.ui.widgets.match-window
(define (beautify-symbol-name symbol)
  (cond ((stringp symbol) symbol)
	((not (symbolp symbol)) (format "%s" symbol))
	(t
	 (let ((name (copy-sequence (symbol-name symbol))))
	   (while (string-match "[-:]" name)
	     (setq name (concat (substring name 0 (match-start))
				?  (substring name (match-end)))))
	   (aset name 0 (char-upcase (aref name 0)))
	   name))))

;; from sawfish.ui.layouts.keymaps
(define (beautify-keymap-name symbol)
  (cond ((stringp symbol) symbol)
	((not (symbolp symbol)) (format "%s" symbol))
	(t
	 (let ((name (copy-sequence (symbol-name symbol))))
	   (when (string-match "-keymap" name)
	     (setq name (substring name 0 (match-start))))
	   (while (string-match "[-:]" name)
	     (setq name (concat (substring name 0 (match-start))
				?  (substring name (match-end)))))
	   (aset name 0 (char-upcase (aref name 0)))
	   name))))

;; helper function that groks sawfish specific forms

(define (get-key key args) (and (listp args) (memq key args)))

(define (helper form)
  (case (car form)
    ((defcustom)
     (let ((variable (nth 1 form))
	   (doc (nth 3 form))
	   (keys (nthcdr 4 form)))
       (let ((tooltip (cadr (get-key ':tooltip keys))))
	 (when tooltip
	   (setq doc (concat doc "\n\n" tooltip))))
       (let ((type* (cadr (get-key ':type* keys))))
	 (when type*
	   (scan type*)))
       (let ((options (cadr (get-key ':options keys))))
	 ;; extract `:options (foo bar..)' strings
	 (when (listp options)
	   (mapc (lambda (s)
		   (when s
		     (register (symbol-name s)))) options)))
       (let ((type (cadr (get-key ':type keys))))
	 ;; extract `:type (choice foo bar..)' strings
	 (when (eq (car type) 'choice)
	   (mapc (lambda (s)
		   (when (symbolp s)
		     (register (symbol-name s)))) (cdr type)))
	 ;; extract keymap names
	 (when (eq type 'keymap)
	   (register (beautify-keymap-name (symbol-name variable)))))
       (when (stringp doc)
	 (register doc))))

    ((defgroup)
     (let ((real-name (nth 2 form)))
       (when (stringp real-name)
	 (register real-name))))

    ((define-command)
     (let ((name (nth 1 form))
	   (def (nth 2 form))
	   (keys (nthcdr 3 form)))
       (when (and (eq (car name) 'quote)
		  (symbolp (cadr name)))
	 (register (beautify-symbol-name (cadr name))))
       (if (get-key #:doc keys)
	   (register (cadr (get-key #:doc keys)))
	 (let ((key (or (cadr (get-key #:doc-key keys))
			(and (symbolp def)
			     (doc-file-value-key
			      def (fluid current-module))))))
	   (when (stringp key)
	     (let ((doc (doc-file-ref key)))
	       (when doc
		 (register doc))))))
       (let ((type (car (cdr (get-key #:type keys)))))
	 (when type
	   (scan type)))))

    ((i18n-defvar i18n-define)
     (let ((name (cadr form))
	   (value (caddr form)))
       (case name
	 ((match-window-properties)
	  (mapc (lambda (x)
		  (mapc (lambda (y)
			  (register (beautify-symbol-name (car y)))) (cddr x)))
		;; remove a `(backquote X)'
		(nth 1 value)))

	 ((match-window-x-properties)
	  (mapc (lambda (x)
		  (register (cdr x)))
		;; strip a `(quote X)'
		(nth 1 value))))

       ;; always rescan as normal, to be sure not to miss anything
       (scan (cons (if (eq (car form) 'i18n-defvar)
		       'defvar
		     'define)
		   (cdr form)))))

    (t (scan-list form))))

;; entry point

(when (get-command-line-option "--help")
  (write standard-output "\
Usage: sawfish-xgettext [OPTIONS...] FILES...

Program to extract strings from sawfish Lisp files that should be
translated.

  --doc-file DOC
  --c
  --pot\n")
  (exit 0))

(when (or (get-command-line-option "-c") (get-command-line-option "--c"))
  (setq *write-c-file* t))
(when (or (get-command-line-option "-p") (get-command-line-option "--pot"))
  (setq *write-c-file* nil))

(let ((doc-file (get-command-line-option "--doc-file" t)))
  (when doc-file
    (setq documentation-files (list doc-file))))

(set-helper helper)
(set-included-definers '())
(mapc scan-file command-line-args)
(setq command-line-args '())

(if *write-c-file*
    (output-c-file)
  (output-pot-file))

;; Local variables:
;; major-mode: lisp-mode
;; End: