1 | #!/usr/local/bin/perl |
---|
2 | # $Id: cmpl.pl,v 1.5 1999-08-17 15:37:44 wichmann Exp $ |
---|
3 | ################################################################### |
---|
4 | # |
---|
5 | # FILE: cmpl.pl |
---|
6 | # PURPOSE: generate completion strings for singular emacs mode |
---|
7 | # AUTHOR: obachman |
---|
8 | #### |
---|
9 | $Usage = <<EOT; |
---|
10 | $0 [-Singular binary] [-hlp file] [cmpl 'hlp|cmd|lib'] [-help] |
---|
11 | Generates completion strings for singular emacs mode and prints it to STDOUT |
---|
12 | EOT |
---|
13 | |
---|
14 | # |
---|
15 | # default settings of command-line arguments |
---|
16 | # |
---|
17 | $Singular = "../Singular/Singular"; |
---|
18 | $hlp = "../doc/singular.hlp"; |
---|
19 | $cmpl = "cmd"; |
---|
20 | %symbol = (cmd=>"singular-commands-alist", |
---|
21 | hlp=>"singular-help-topics-alist", |
---|
22 | lib=>"singular-standard-libraries-alist"); |
---|
23 | |
---|
24 | # |
---|
25 | # parse command line options |
---|
26 | # |
---|
27 | while (@ARGV && $ARGV[0] =~ /^-/) |
---|
28 | { |
---|
29 | $_ = shift(@ARGV); |
---|
30 | if (/^-S(ingular)?$/) { $Singular = shift(@ARGV); next;} |
---|
31 | if (/^-hlp$/) { $hlp = shift(@ARGV); next;} |
---|
32 | if (/^-c(mpl)?$/) { $cmpl = shift(@ARGV); next;} |
---|
33 | if (/^-h(elp)?$/) { print $Usage; exit;} |
---|
34 | die "Unrecognized option: $_\n$Usage"; |
---|
35 | } |
---|
36 | |
---|
37 | # |
---|
38 | # get array of strings |
---|
39 | # |
---|
40 | if ($cmpl eq 'cmd') |
---|
41 | { |
---|
42 | $strings = `$Singular -tq --exec='reservedName();\$'`; |
---|
43 | die "Error in execution of: $Singular -tq --exec='reservedName();\$': $!\n" |
---|
44 | if ($?); |
---|
45 | @strings = split(/\s+/, $strings); |
---|
46 | } |
---|
47 | elsif ($cmpl eq 'lib') |
---|
48 | { |
---|
49 | @strings = split(/\s+/, <>); |
---|
50 | } |
---|
51 | elsif ($cmpl eq 'hlp') |
---|
52 | { |
---|
53 | open(FH, "<$hlp") || die "Can not open file $hlp: $!\n"; |
---|
54 | while (<FH>) |
---|
55 | { |
---|
56 | if (/Node: Index/) |
---|
57 | { |
---|
58 | while (<FH>) |
---|
59 | { |
---|
60 | last if /\* Menu:/; |
---|
61 | } |
---|
62 | <FH>; |
---|
63 | while (<FH>) |
---|
64 | { |
---|
65 | last if /^\s*$/; |
---|
66 | s/\* (.*):.*/$1/; |
---|
67 | s/(.*) <\d+>$/$1/; |
---|
68 | s/^\s*(.*)\s*/$1/; |
---|
69 | s/([\\#"])/\\$1/g; #' |
---|
70 | push @strings, $_ if $_ && $_ ne $prev; |
---|
71 | $prev = $_; |
---|
72 | } |
---|
73 | last; |
---|
74 | } |
---|
75 | } |
---|
76 | close(FH); |
---|
77 | } |
---|
78 | else |
---|
79 | { |
---|
80 | die "Error: Can not make completion list for $cmpl\n $Usage"; |
---|
81 | } |
---|
82 | print STDOUT <<EOT; |
---|
83 | ; Do not edit this file: It was automatically generated by $0 |
---|
84 | (setq $symbol{$cmpl} |
---|
85 | '( |
---|
86 | EOT |
---|
87 | #' prevents breaking of fontification |
---|
88 | |
---|
89 | foreach $string (@strings) |
---|
90 | { |
---|
91 | print STDOUT qq[ ("$string")\n]; |
---|
92 | } |
---|
93 | |
---|
94 | print STDOUT "))\n"; |
---|
95 | |
---|