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