5 # Program to create IDLWAVE library catalogs.
7 # (c) 2002-2003 J.D. Smith <jdsmith@as.arizona.edu>
9 # Scans all IDL ".pro" files at the current level and recursively in
10 # all directories beneath it, compiling a catalog of information for
11 # each directory with any routines found, stored in a file named
12 # ".idlwave_catalog". Any such "library catalogs" on the IDL path
13 # will be automatically loaded into IDLWAVE.
15 # Usage: idlwave_catalog [-l] [-v] [-d] [-s] [-f] [-h] libname
16 # libname - Unique name of the catalog (4 or more alphanumeric
17 # characters -- only 10 will be shown in routine info).
18 # -l - Scan local directory only, otherwise recursively
19 # catalog all directories at or beneath this one.
20 # -v - Print verbose information.
21 # -d - Instead of scanning, delete all .idlwave_catalog files
24 # -f - Force overwriting any catalogs found with a different
26 # -h - Print this usage.
28 # You can arrange to have this script run automatically to update
29 # libraries which change frequently. The name will be used to refer
30 # to the routines collectively, so make it unique and descriptive
31 # (without spaces). E.g. "NasaLib". A file named .idlwave_catalog
32 # will be created in each directory with ".pro" routine files.
34 # $Id: idlwave_catalog,v 1.1 2003-08-12 12:26:18 dominik Exp $
37 $opt_l=$opt_s=$opt_f=$opt_v=$opt_d=$opt_h=0;
44 $libname=shift or usage();
45 if (length($libname)<=3 or ($libname=~tr/A-Za-z0-9_//c)) {
47 "LibName must be alphanumeric, >3 characters, and contains no spaces.\n"
51 $cat=".idlwave_catalog";
59 print "Removing catalog $File::Find::name\n" if $opt_v;
61 warn "Can't remove catalog $File::Find::name: $!\n"
65 $dirs{$File::Find::dir}{cat}=libname($_);
70 return unless -f and /\.pro$/i;
71 parsefile($File::Find::dir, $_);
73 } else { #Just process the local directory
74 opendir(DIR,".") || die "Can't open this directory: $!";
78 print "Removing catalog $cat\n" if $opt_v;
80 warn "Can't remove catalog $cat: $!\n" unless $opt_s;
83 $dirs{"."}{cat}=libname($cat);
87 foreach (grep {-f and /\.pro$/i} readdir(DIR)) {
94 exit if $opt_d; #Nothing more to do
96 foreach $dir (keys %dirs) {
97 print "Cataloging $dir\n" if $opt_v;
99 if (exists $dirs{$dir}{cat} && $dirs{$dir}{cat} ne $libname) {
101 warn "Overwriting existing \"$dirs{$dir}{cat}\" catalog in " .
102 ($dir eq "."?"this directory":$dir) . ".\n" unless $opt_s;
104 warn "Skipping existing \"$dirs{$dir}{cat}\" catalog in " .
105 ($dir eq "."?"this directory":$dir) .
106 " (-f overrides).\n" unless $opt_s;
111 unless (open CATALOG, ">$dir/$cat") {
112 warn "Can't open catalog file $dir/$cat for writing... skipping\n";
118 ;; IDLWAVE catalog for library $libname
119 ;; Automatically Generated -- do not edit.
120 ;; Created by idlwave_catalog on $time
122 (setq idlwave-library-catalog-libname "$libname")
123 (setq idlwave-library-catalog-routines
125 print CATALOG " '(".join("\n ",@{$dirs{$dir}{pro}});
126 print CATALOG "))\n";
130 if($opt_v && !%dirs) {
131 print $opt_l?"Current directory contains no .pro files.\n":
132 "No directories with .pro files found.\n";
137 my ($call,@kwds,@args,@entries);
141 /^[ \t]*(pro|function)[ \t]+(?:([a-zA-Z0-9\$_]+)::)?([a-zA-Z0-9\$_]+)/i;
142 ($type,$class,$name)=(lc($1) eq "pro"?"pro":"fun",$2,$3);
145 while (/[ \t]*\$\s*(;.*)?[\r\n]+/) { # Continuations
148 while (/^\s*(;.*)?[\r\n]+/) {$_=<FILE>} #skip blank or comment lines
150 s/\s*(;.*)?[\r\n]+//;
152 while($call=~/,\s*([a-zA-Z][a-zA-Z0-9\$_]*|(?:_ref)?_extra)\s*(=)?/gi) {
159 $is_func=$type eq "fun";
160 @kwds=sort {lc($a) cmp lc($b)} @kwds;
163 push @{$dirs{$dir}{pro}},
164 qq{("$name" $type } . ($class?qq("$class"):"nil") .
165 # Source (source-type file dir library-name)
166 qq< (lib "$file" nil "$libname") > .
168 '"' . ($is_func?"Result = ":"") . ($class?'Obj ->[%s::]':"") . '%s' .
170 (@args?($is_func?"(":", ") .
172 ($is_func?')':""):"") . '"' .
174 ' (nil' . (@kwds?' ("'.join('") ("', @kwds).'")':"") . "))";
185 return $1 if /\(setq idlwave-library-catalog-libname "([^"]+)"\)/;
192 Usage: idlwave_catalog [-l] [-v] [-d] [-s] [-f] [-h] libname
193 libname - Unique name of the catalog (4 or more alphanumeric
194 characters -- only 10 will be shown in routine info).
195 -l - Scan local directory only, otherwise recursively
196 catalog all directories at or beneath this one.
197 -v - Print verbose information.
198 -d - Instead of scanning, delete all .idlwave_catalog files
201 -f - Force overwriting any catalogs found with a different
203 -h - Print this usage.