~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to elisp/man1-to-texi.el

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;;;;if you are in a buffer which has a man page you can try
 
2
;; M-x doit, to do an at least partial conversion of tcl tk man pages to
 
3
;; texinfo
 
4
 
 
5
;; file for converting the tcl/tk man pages to texinfo and suitable for gcl/tk
 
6
;          .bp     begin new page
 
7
;          .br     break output line here
 
8
;          .sp n   insert n spacing lines
 
9
;          .ls n   (line spacing) n=1 single, n=2 double space
 
10
;          .na     no alignment of right margin
 
11
;          .ce n   center next n lines
 
12
;          .ul n   underline next n lines
 
13
;          .sz +n  add n to point size
 
14
;
 
15
;  Requests
 
16
;     Request     Cause   If no     Explanation
 
17
;                 Break   Argument
 
18
;
 
19
;     .B t        no      t=n.t.l.* Text is in bold font.
 
20
;     .BI t       no      t=n.t.l.  Join words,  alternating  bold
 
21
;                 and italic.
 
22
;     .BR t       no      t=n.t.l.  Join words,  alternating  bold
 
23
;                 and roman.
 
24
;     .DT         no      .5i 1i... Restore default tabs.
 
25
;     .HP i       yes     i=p.i.*   Begin paragraph  with  hanging
 
26
;                 indent.  Set prevailing indent to i.
 
27
;     .I t        no      t=n.t.l.  Text is italic.
 
28
;     .IB t       no      t=n.t.l.  Join words, alternating italic
 
29
;                 and bold.
 
30
;
 
31
;     .IP x i     yes     x=""      Same as .TP with tag x.
 
32
;     .IR t       no      t=n.t.l.  Join words, alternating italic
 
33
;                 and roman.
 
34
;     .IX t       no      -         Index macro, for Sun  internal
 
35
;                 use.
 
36
;     .LP         yes     -         Begin left-aligned  paragraph.
 
37
;                 Set prevailing indent to .5i.
 
38
;     .PD d       no      d=.4v     Set vertical distance  between
 
39
;                 paragraphs.
 
40
;     .PP         yes     -         Same as .LP.
 
41
;     .RE         yes     -         End   of   relative    indent.
 
42
;                 Restores prevailing indent.
 
43
;     .RB t       no      t=n.t.l.  Join words, alternating  roman
 
44
;                 and bold.
 
45
;     .RI t       no      t=n.t.l.  Join words, alternating  roman
 
46
;                 and italic.
 
47
;     .RS i       yes     i=p.i.    Start     relative     indent,
 
48
;                 increase indent by i.  Sets prevailing indent to
 
49
;                 .5i                   for nested indents.
 
50
;     .SB t       no      -         Reduce  size  of  text  by   1
 
51
;                 point, make text boldface.
 
52
;     .SH t       yes     -         Section Heading.
 
53
;     .SM t       no      t=n.t.l.  Reduce  size  of  text  by   1
 
54
;                 point.
 
55
;     .SS t       yes     t=n.t.l.  Section Subheading.
 
56
;     .TH n s d f m
 
57
;                 yes     -         Begin  reference  page  n,  of
 
58
;                 section   s;   d   is   the  date  of  the  most
 
59
;                                   recent change.  If present,  f
 
60
;                 is    the   left   page   footer;   m   is   the
 
61
;                                   main  page  (center)   header.
 
62
;                 Sets prevailing indent and tabs to .5i.
 
63
;     .TP i       yes     i=p.i.    Begin indented paragraph, with
 
64
;                 the    tag    given    on    the    next    text
 
65
;                                   line.  Set  prevailing  indent
 
66
;                 to i.
 
67
;
 
68
;     .TX t p     no      -         Resolve the title abbreviation
 
69
;                 t;  join  to  punctuation  mark  (or text) p.  *
 
70
;                 n.t.l. =  next  text  line;  p.i.  =  prevailing
 
71
;                 indent
 
72
; .HS name section [date [version]]
 
73
;       Replacement for .TH in other man pages.  See below for valid
 
74
;       section names.
 
75
;
 
76
; .AP type name in/out [indent]
 
77
;       Start paragraph describing an argument to a library procedure.
 
78
;       type is type of argument (int, etc.), in/out is either "in", "out",
 
79
;       or "in/out" to describe whether procedure reads or modifies arg,
 
80
;       and indent is equivalent to second arg of .IP (shouldn't ever be
 
81
;       needed;  use .AS below instead)
 
82
;
 
83
; .AS [type [name]]
 
84
;       Give maximum sizes of arguments for setting tab stops.  Type and
 
85
;       name are examples of largest possible arguments that will be passed
 
86
;       to .AP later.  If args are omitted, default tab stops are used.
 
87
;
 
88
; .BS
 
89
;       Start box enclosure.  From here until next .BE, everything will be
 
90
;       enclosed in one large box.
 
91
;
 
92
; .BE
 
93
;       End of box enclosure.
 
94
;
 
95
; .VS
 
96
;       Begin vertical sidebar, for use in marking newly-changed parts
 
97
;       of man pages.
 
98
;
 
99
; .VE
 
100
;       End of vertical sidebar.
 
101
;
 
102
; .DS
 
103
;       Begin an indented unfilled display.
 
104
;
 
105
; .DE
 
106
;       End of indented unfilled display.
 
107
 
108
 
 
109
(defun do-replace (lis &optional not-in-string)
 
110
  (let (x case-fold-search)
 
111
    (while lis
 
112
      (setq x (car lis)) (setq lis (cdr lis))
 
113
      (goto-char (point-min))
 
114
      (message "doing %s " x)
 
115
      (while (re-search-forward (nth 0 x) nil t)
 
116
        (and not-in-string
 
117
             (progn (forward-char -1)
 
118
                    (not (in-a-string))))
 
119
        (let ((f (nth 1 x)))
 
120
          (cond ((stringp f)
 
121
                 (replace-match f t))
 
122
                (t (let ((i 0) ans)
 
123
                     (while (match-beginning i)
 
124
                       (setq ans (cons (buffer-substring
 
125
                                        (match-beginning i)
 
126
                                        (match-end i)) ans))
 
127
                       (setq i (+ i 1)))
 
128
                     (setq ans (nreverse ans))
 
129
                     (goto-char (match-beginning 0))
 
130
                     (delete-region (match-beginning 0)
 
131
                                    (match-end 0))
 
132
                     (apply f ans)))))))))
 
133
 
 
134
 
 
135
 
 
136
 
 
137
(defun doit ()
 
138
  (interactive)
 
139
  (texinfo-mode)
 
140
  (goto-char (point-min))
 
141
  (do-replace '(("@" "@@")
 
142
                ("^[.]VS\n" "")
 
143
                ("^[.]VE\n" "")
 
144
                ))
 
145
  (goto-char (point-min))
 
146
  (insert "@setfilename foo.info")
 
147
  (insert "\n")
 
148
  (do-tables)
 
149
;  (do-nf)
 
150
 (do-replace
 
151
  '(
 
152
    (".SH \"SEE ALSO\"\n\\([^\n]*\\)" "@xref{\\1}")
 
153
    ("^[.]SH NAME" "")
 
154
    ("^'[\\]\"[^\n]*\n" "")
 
155
    ("^'[/]\"[^\n]*\n" "")
 
156
    ("^[.]so[^\n]+\n" "")
 
157
    ("[.]HS \\([^ \n]+\\)\\([^\n]*\\)\n"
 
158
     "@node \\1\n@subsection \\1\n")
 
159
    ("^[.]VS\n" "")
 
160
    ("^[.]VE\n" "")
 
161
    (".nf\nName:\t\\([^\n]*\\)\nClass:\t\\([^\n]*\\)\nCommand-Line Switch:\t\\([^\n]*\\)\n.fi\n" do-keyword)
 
162
    ("Name:\t\\([^\n]*\\)\nClass:\t\\([^\n]*\\)\nCommand-Line Switch:\t\\([^\n]*\\)\n" do-keyword)
 
163
    ("Name:\t\\([^\n]*\\)\n" "@*@w{  Name: @code{\\1}}\n")
 
164
    ("Class:\t\\([^\n]*\\)\n" "@*@w{  Class: @code{\\1}}\n")
 
165
    ("Command-Line Switch:\t\\([^\n]*\\)\n" "@*@w{  Keyword: @code{\\1}}\n")
 
166
    ("[\\]-\\([a-z]\\)" ":\\1")
 
167
    ("^[.]nf\n" "@example\n")
 
168
    ("^[.]fi\n" "@end example\n")
 
169
    ("^[.]ta[^\n]*\n" do-ta)
 
170
    ("^[.]IP\n" "\n")
 
171
    ("[\\]f\\([A-Z]\\)\\([^\\\n]*\\)[\\]f"
 
172
     do-font)
 
173
    ("^\\([^\n]+\\)\n[.]br" "@*@w{\\1}@*")
 
174
    ("^[.]SH \\([^\n]*\\)"
 
175
     (lambda (a0 a1)
 
176
       (insert  "@unnumberedsubsec " (capitalize a1))))
 
177
    ("[\\]fR" "")
 
178
    
 
179
    ("^[.]BS" "@cartouche")
 
180
    ("^[.]BE" "@end cartouche")
 
181
    ("^[.]sp \\([0-9]\\)" "@sp \\1")
 
182
    ("^[.]sp" "@sp 1")
 
183
    ("^[.]LP\n" "\n\n")
 
184
    ("^[.][LP]P" "")
 
185
    ("^[.]DS[^\n]*\n" "\n@example\n")
 
186
    ("^[.]DE[^\n]*\n" "@end example\n\n")
 
187
    ("^[.]DS[^\n]*\n" "\n@example\n")
 
188
    ("^[.]DE[^\n]*\n" "@end example\n\n")
 
189
    ("^[.]RS\n" "")  ; relative indent increased..
 
190
    ("^[.]rE\n" "")
 
191
    ("^[\\]&\\([^\n]*\\)\n" "@*@w{   \\1}\n")
 
192
;    ("Command-Line Switch" "Keyword")
 
193
    ("pathName }@b{\\([a-z]\\)" "pathName }@b{:\\1")
 
194
    ("[\\]0" " ")
 
195
    ("%\\([a-z#]\\)\\([^a-zA-Z0-9%]\\)" "|%\\1|\\2")
 
196
    ("^[.]TP[^\n]*\n" "@item ")
 
197
    ))
 
198
 (add-keywords)
 
199
 )
 
200
 
 
201
(defun do-font (ign a b)
 
202
  (let ((ch (assoc (aref a 0)
 
203
                   '((?R . "@r{")
 
204
                     (?I . "@i{")
 
205
                     (?B . "@b{")))))
 
206
    (cond (ch (insert (cdr ch) b "}\\f")
 
207
              (forward-char -2)
 
208
              )
 
209
          (t     (error "unknown leter %s" a)))))
 
210
 
 
211
(defun do-keyword (ign name class key)
 
212
  (insert "@table  \n@item @code{"key "}"
 
213
          "\n@flushright\nName=@code{\""name"\"} Class=@code{\""class "\"}\n"
 
214
          "@end flushright\n@sp 1\n")
 
215
  (save-excursion
 
216
    (cond ((re-search-forward "[.]LP\\|[.]BE\\|[.]SH" nil t)
 
217
           (beginning-of-line)
 
218
           (insert "@end table\n")))))
 
219
  
 
220
  
 
221
          
 
222
          
 
223
(defun try ()
 
224
  (interactive)
 
225
  (if (get-buffer "foo.texi")
 
226
      (kill-buffer (get-buffer "foo.texi")))
 
227
 
 
228
  (if (get-buffer "foo.info")
 
229
      (kill-buffer (get-buffer "foo.info")))
 
230
 
 
231
  (find-file "foo.n")
 
232
  (toggle-read-only 0)
 
233
  (doit)
 
234
  (write-file "foo.texi")
 
235
  (makeinfo-buffer ))
 
236
 
 
237
(defun foo ()
 
238
  (re-search-forward "\n\\|\\([\\]f[a-zA-Z]\\)" nil t)
 
239
  (list (match-beginning 0) (match-beginning 1) (match-beginning 2)))
 
240
        
 
241
(defun list-current-line ()
 
242
  (beginning-of-line)
 
243
  (let (ans at-end (beg (point)))
 
244
    (save-excursion
 
245
      (while (not at-end)
 
246
        (re-search-forward "\n\\|\\([\\]f[a-zA-Z]\\)" nil t)
 
247
        (if (match-beginning 1) (replace-match "")
 
248
          (setq at-end t))))
 
249
    (setq at-end nil)
 
250
    (beginning-of-line)
 
251
    (while (not at-end)
 
252
      (re-search-forward "[\t\n]" nil t)
 
253
      (let ((x (buffer-substring beg (- (point) 1))))
 
254
        (or (equal x "")
 
255
            (setq ans (cons x     ans))))
 
256
      
 
257
      (setq beg (point))
 
258
      (setq at-end (equal (char-after (- (point) 1)) ?\n)))
 
259
    (nreverse ans)
 
260
    ))
 
261
 
 
262
(defun do-ta (a0)
 
263
  (let ((beg (point))
 
264
        items (vec (make-vector 10 0)) i (tot 0) surplus)
 
265
    (while (not (looking-at "[.][LDI]"))
 
266
      (cond ((looking-at "[.]")(forward-line 1))
 
267
            (t
 
268
             (setq items (cons (list-current-line) items))
 
269
             (let ((tem (car items))
 
270
                   (i 0))
 
271
               (while tem
 
272
                 (aset vec i (max (real-length (car tem)) (aref vec i)))
 
273
                 (setq i (+ i 1))
 
274
                 (setq tem (cdr tem)))
 
275
               ))))
 
276
;    (message "%s" (list beg (point)))
 
277
;    (sit-for 1)
 
278
    
 
279
    (delete-region beg (point))
 
280
;     (forward-line -2)
 
281
;    (message "%s" vec)
 
282
;    (sit-for 2)
 
283
    (setq items (nreverse items))
 
284
    (setq i 0)
 
285
    (while (< i (length vec)) (setq tot (+ (aref vec i) tot)) (setq i (+ i 1)))
 
286
    (setq surplus (/ (- 70 tot) (+ 1 (length (car items)))))
 
287
    (while items
 
288
      (setq tem (car items))
 
289
      (setq i 0)
 
290
      (let (ans x)
 
291
        (insert "")
 
292
        (while tem
 
293
          (insert (tex-center (car tem) (+ (aref vec i) surplus) 'left
 
294
                              (real-length (car tem))))
 
295
          (setq tem (cdr tem)) (setq i (+ i 1)))
 
296
        (insert "\n"))
 
297
      (setq items (cdr items)))
 
298
    )
 
299
  )
 
300
        
 
301
        
 
302
      
 
303
    
 
304
 
 
305
  
 
306
  
 
307
(defun real-length (item)
 
308
  (let* ((n (length item)) (m (- n 1)) (start 0))
 
309
    (while (setq start (string-match "[\\]f" item start))
 
310
      (setq n (- n 3))
 
311
      (if (<  start m) (setq start (+ start 1))))
 
312
    n))
 
313
 
 
314
 
 
315
(defun do-tables ()
 
316
  (goto-char (point-min))
 
317
  (while (re-search-forward "^[.]TP" nil t)
 
318
    (beginning-of-line)
 
319
    (insert "\n@table @asis\n")
 
320
    (forward-line 2)
 
321
    (re-search-forward "^[.]\\(LP\\|BE\\|SH\\)" nil t)
 
322
    (beginning-of-line)
 
323
    (insert "@end table\n")
 
324
    ))
 
325
(defun do-nf ()
 
326
  (goto-char (point-min))
 
327
  (while (re-search-forward "^[.]nf" nil t)
 
328
    (forward-line 1) (beginning-of-line)
 
329
      (while (not (looking-at "[.]fi"))
 
330
        (insert "@w{" ) (end-of-line) (insert "}")
 
331
            (forward-line 1) (beginning-of-line))))
 
332
 
 
333
(defun add-keywords ()
 
334
  (let ((tem tk-control-options)x lis l y)
 
335
    (while tem
 
336
      (setq l (car tem))
 
337
      (setq tem (cdr tem))
 
338
      (setq x (symbol-name (car l )))
 
339
      (setq lis (car (cdr l)))
 
340
      (while lis
 
341
        (cond ((atom lis) (setq lis nil))
 
342
              (t (setq y (symbol-name (car lis)))
 
343
                 (do-replace (list (list (concat x  " "y "")
 
344
                                         (concat x " :"y "")
 
345
                                         )))))
 
346
        (setq lis (cdr lis))))))
 
347
 
 
348
(setq tk-control-options
 
349
      '((after fixnum) 
 
350
        (exit fixnum) 
 
351
        (lower window) 
 
352
        (place pathName (-anchor -bordermode -height
 
353
                                 -in -relheight -relwidth
 
354
                                 -relx -rely -width -x  -y))
 
355
        (send interpreter )
 
356
                                        ;(TKVARS "invalid command name \"tkvars\"") 
 
357
        (winfo  (atom atomname cells children class containing
 
358
                      depth exists fpixels geometry height id
 
359
                      interps ismapped name parent pathname pixels
 
360
                      reqheight reqwidth rgb rootx rooty screen
 
361
                      screencells screendepth screenheight screenmmheight
 
362
                      screenmmwidth screenvisual screenwidth toplevel
 
363
                      visual vrootheight vrootwidth vrootx vrooty width x y) )
 
364
        (focus (default  none) )
 
365
        (option (add clear get readfile)) 
 
366
        (raise pathname)
 
367
        (tk  colormodel) 
 
368
        (tkwait  ( variable visible window) ) 
 
369
        (wm  (aspect client command deiconify focusmodel frame geometry grid group iconbitmap iconify iconmask iconname iconposition iconwindow maxsize minsize overrideredirect positionfrom protocol sizefrom state title trace transient  withdraw))
 
370
        (destroy window) 
 
371
        (grab (current release set  status))
 
372
        (pack window (-after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, -side) argggg)
 
373
        (selection (clear get handle own))
 
374
        (tkerror "") 
 
375
        (update (idletasks)) 
 
376
        ))
 
377
 
 
378
(setq tk-widget-options
 
379
      '(
 
380
        (button (activate configure deactivate flash invoke)) 
 
381
        (listbox ( configure curselection delete get insert nearest
 
382
                             scan select size xview yview)) 
 
383
        (scale ( configure get set)) 
 
384
        (canvas ( addtag bbox bind canvasx canvasy configure coords
 
385
                         create dchars delete dtag find focus gettags
 
386
                         icursor index insert itemconfigure lower move
 
387
                         postscript raise scale scan select type xview yview)) 
 
388
        (menu ( activate add configure delete disable enable
 
389
                         entryconfigure index invoke post unpost yposition)) 
 
390
        (scrollbar ( configure get set)) 
 
391
        (checkbutton
 
392
         (     activate configure deactivate deselect flash
 
393
                        invoke select toggle)) 
 
394
        (menubutton
 
395
         (     activate configure deactivate)) 
 
396
        (text ( compare configure debug delete get index insert
 
397
                        mark scan tag yview)) 
 
398
        (entry ( configure delete get icursor index insert scan select view)) 
 
399
        (message ( configure)) 
 
400
        (frame ( configure)) 
 
401
        (label ( configure)) 
 
402
        (radiobutton
 
403
         (     activate configure deactivate deselect flash invoke  select)) 
 
404
        (toplevel ( configure)) 
 
405
        ))
 
406
 
 
407
(setq manual-sections
 
408
      '(after bind button canvas checkbutton destroy  entry exit focus foo frame grab label lbSingSel listbox lower menu menubar menubutton message option options pack-old pack place radiobutton raise scale scrollbar selection send text tk tkerror tkvars tkwait toplevel update winfo wm))
 
409
 
 
410
;(setq widgets (sort (mapcar 'car tk-widget-options) 'string-lessp))
 
411
;(let ((m manual-sections)(tem widgets)) (while tem  (setq manual-sections (delete (car tem) manual-sections))(setq tem (cdr tem))))
 
412
 
 
413
                        
 
414