1 | #!/usr/local/bin/perl |
---|
2 | # $Id$ |
---|
3 | ################################################################### |
---|
4 | # |
---|
5 | # FILE: lib.pl |
---|
6 | # PURPOSE: generate template for library menu |
---|
7 | # AUTHOR: obachman |
---|
8 | #### |
---|
9 | $Usage = <<EOT; |
---|
10 | $0 [-singular_dir singular_dir] libraries |
---|
11 | Generates template for library menu |
---|
12 | EOT |
---|
13 | |
---|
14 | # |
---|
15 | # default settings of command-line arguments |
---|
16 | # |
---|
17 | # here I expect libparse and LIB/*.lib |
---|
18 | $Singular_Dir = "../Singular/"; |
---|
19 | # |
---|
20 | # parse command line options |
---|
21 | # |
---|
22 | while (@ARGV && $ARGV[0] =~ /^-/) |
---|
23 | { |
---|
24 | $_ = shift(@ARGV); |
---|
25 | if (/^-s(ingular_dir)?$/) { $Singular_Dir = shift(@ARGV); next;} |
---|
26 | die "Unrecognized option: $_\n$Usage"; |
---|
27 | } |
---|
28 | $libparse = "$Singular_Dir/libparse"; |
---|
29 | die "Can not find $libparse" unless -x $libparse; |
---|
30 | $lib_dir = "$Singular_Dir/LIB"; |
---|
31 | die "$Singular_Dir/LIB is not a directory" unless -d $lib_dir; |
---|
32 | |
---|
33 | for $lib (@ARGV) |
---|
34 | { |
---|
35 | my $category; |
---|
36 | die "Can not read $lib_dir/$lib" unless -r "$lib_dir/$lib"; |
---|
37 | open(CAT_PIPE, "$libparse -c -f $lib_dir/$lib|") || die "'$libparse -c -f $lib_dir/$lib' failed"; |
---|
38 | |
---|
39 | while (<CAT_PIPE>) |
---|
40 | { |
---|
41 | $category = $_; |
---|
42 | last; |
---|
43 | } |
---|
44 | close(CAT_PIPE); |
---|
45 | $category = "Miscellaneous" unless $category; |
---|
46 | $libraries{$category} .= ($libraries{$category} ? " $lib" : $lib); |
---|
47 | } |
---|
48 | |
---|
49 | print <<EOT; |
---|
50 | (setq singular-standard-libraries-with-categories |
---|
51 | '( |
---|
52 | EOT |
---|
53 | # font-lock-trick ' |
---|
54 | |
---|
55 | for $cat (sort {($b cmp $a)} keys %libraries) |
---|
56 | { |
---|
57 | |
---|
58 | print <<EOT; |
---|
59 | ("$cat" |
---|
60 | EOT |
---|
61 | for $lib (sort {($b cmp $a)} split (/\s+/, $libraries{$cat})) |
---|
62 | { |
---|
63 | print <<EOT; |
---|
64 | ("$lib") |
---|
65 | EOT |
---|
66 | } |
---|
67 | print <<EOT |
---|
68 | ) |
---|
69 | EOT |
---|
70 | } |
---|
71 | |
---|
72 | print "))\n"; |
---|
73 | |
---|
74 | |
---|
75 | __END__ |
---|
76 | |
---|
77 | [1 <text/plain; us-ascii (7bit)>] |
---|
78 | Hallo Olaf! |
---|
79 | |
---|
80 | Probier' es mal hiermit... |
---|
81 | |
---|
82 | Das File lib-cmpl.el sollte jetzt folgendes Aussehen haben: |
---|
83 | |
---|
84 | ----[ snip ]---- |
---|
85 | ; Do not edit this file: It was automatically generated by cmpl.pl |
---|
86 | (setq singular-standard-libraries-with-categories |
---|
87 | '( |
---|
88 | ("Category_z" |
---|
89 | ("z_file_z") |
---|
90 | ("z_file_y") |
---|
91 | ... |
---|
92 | ("z_file_a")) |
---|
93 | ("Category_y" |
---|
94 | ("y_file_z") |
---|
95 | ("y_file_y") |
---|
96 | ... |
---|
97 | ("y_file_a")) |
---|
98 | ... |
---|
99 | ("Category_a" |
---|
100 | ("a_file_z") |
---|
101 | ("a_file_y") |
---|
102 | ... |
---|
103 | ("a_file_a")) |
---|
104 | ("file_without_cat_z") |
---|
105 | ("file_without_cat_y") |
---|
106 | ... |
---|
107 | ("file_without_cat_a") |
---|
108 | ) |
---|
109 | ----[ snip ]---- |
---|
110 | |
---|
111 | (beachte, dass sich der Name der lisp-Variablen geaendert hat!). Wie |
---|
112 | bisher stehen die Filenamen in umgekehrter alphabetischer Reihenfolge, |
---|
113 | sowohl auf top-level, als auch in den sub-menues. Das Menue wird im |
---|
114 | Emacs genau so aufgebaut, wie angeben, nur in umgekehrter Reihenfolge. |
---|
115 | Eintraege mit Categories und ohne koennen beliebig gemischt werden: |
---|
116 | |
---|
117 | ----[ snip ]---- |
---|
118 | (setq singular-standard-libraries-with-categories |
---|
119 | '( |
---|
120 | ("Category_z" |
---|
121 | ("z_file_z") |
---|
122 | ("z_file_y") |
---|
123 | ("z_file_a")) |
---|
124 | ("file_without_cat_z") |
---|
125 | ("file_without_cat_y") |
---|
126 | ("Category_y" |
---|
127 | ("y_file_z") |
---|
128 | ("y_file_y") |
---|
129 | ("y_file_a")) |
---|
130 | ("file_without_cat_a") |
---|
131 | ) |
---|
132 | ----[ snip ]---- |
---|
133 | |
---|
134 | Und, um dem ganzen noch eins draufzusetzen: man kann es sogar beliebig |
---|
135 | tief schachteln! |
---|
136 | |
---|
137 | ----[ snip ]---- |
---|
138 | (setq singular-standard-libraries-with-categories |
---|
139 | '( |
---|
140 | ("Category_z" |
---|
141 | ("z_file_z") |
---|
142 | ("Sub_Category_zz" ("zz_file1") ("zz_file2")) |
---|
143 | ("z_file_y") |
---|
144 | ("Sub_Category_aa" ("aa_file_a") ("aa_file_b"))) |
---|
145 | ("file_without_cat_z") |
---|
146 | ("file_without_cat_y") |
---|
147 | ("Category_y" |
---|
148 | ("y_file_z") |
---|
149 | ("y_file_y") |
---|
150 | ("y_file_a")) |
---|
151 | ("file_without_cat_a") |
---|
152 | ) |
---|
153 | ----[ snip ]---- |
---|
154 | |
---|
155 | Ich habe es auf emacs 20.4, xemacs 20.4 und xemacs 21.1-p3 getestet. |
---|
156 | Ich hoffe, dass alles funktioniert! |
---|
157 | |
---|
158 | Es sollte auch noch mit alten lib-cmpl.el-Datein funktionieren (obwohl |
---|
159 | sich der Variablen-Name geaendert hat) |
---|
160 | |
---|
161 | Kannst Dich ja mal melden, ob alles wie gewollt klappt. |
---|
162 | |
---|
163 | Viele Gruesse, |
---|
164 | T. |
---|
165 | |
---|
166 | |
---|
167 | |
---|