annotate src/fn-cache.cc @ 5540:cda6a105ae9a before-ov-branch

[project @ 2005-11-17 05:47:13 by jwe]
author jwe
date Thu, 17 Nov 2005 05:47:13 +0000
parents 4c8a2e4e0717
children ace8d8d26933
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
1 /*
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
2
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2492
diff changeset
3 Copyright (C) 1996, 1997 John W. Eaton
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
4
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
6
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
10 later version.
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
11
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
15 for more details.
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
16
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
5307
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 4215
diff changeset
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 4215
diff changeset
20 02110-1301, USA.
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
21
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
22 */
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
23
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
26 #endif
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
27
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
28 #include <string>
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
29
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
30 #include "file-stat.h"
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
31 #include "str-vec.h"
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
32
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2370
diff changeset
33 #include <defaults.h>
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
34 #include "dir-ops.h"
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
35 #include "dirfns.h"
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
36 #include "error.h"
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
37 #include "fn-cache.h"
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
38 #include "pathsearch.h"
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
39
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
40 octave_fcn_file_name_cache *octave_fcn_file_name_cache::instance = 0;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
41
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
42 // Update the cache. Returns TRUE if something needed to be updated.
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
43
2233
0da2c91573d9 [project @ 1996-05-17 17:27:17 by jwe]
jwe
parents: 2232
diff changeset
44 // We just accumulate all directories ever referenced in the cache and
0da2c91573d9 [project @ 1996-05-17 17:27:17 by jwe]
jwe
parents: 2232
diff changeset
45 // we don't delete any old ones.
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
46
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
47 bool
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3195
diff changeset
48 octave_fcn_file_name_cache::update (const std::string& path)
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
49 {
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
50 bool something_changed = false;
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
51
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 2926
diff changeset
52 dir_path p = path.empty () ? Vload_path_dir_path : dir_path (path);
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
53
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
54 string_vector dirs = p.all_directories ();
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
55
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
56 int len = dirs.length ();
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
57
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
58 for (int i = 0; i < len; i++)
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
59 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3195
diff changeset
60 std::string d = dirs[i];
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
61
4215
bc6059c5ddc7 [project @ 2002-12-04 05:21:08 by jwe]
jwe
parents: 4128
diff changeset
62 if (cache.find (d) != cache.end ())
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
63 {
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
64 if (cache[d].update (d))
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
65 something_changed = true;
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
66 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
67 else
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
68 {
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
69 cache[d] = file_name_cache_elt (d);
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
70 something_changed = true;
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
71 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
72 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
73
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
74 return something_changed;
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
75 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
76
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
77 string_vector
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3195
diff changeset
78 octave_fcn_file_name_cache::list (const std::string& path, bool no_suffix)
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
79 {
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
80 string_vector retval;
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
81
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
82 if (! instance)
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
83 instance = new octave_fcn_file_name_cache ();
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
84
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
85 if (instance)
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
86 retval = instance->do_list (path, no_suffix);
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
87 else
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
88 error ("unable to create file name cache object!");
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
89
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
90 return retval;
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
91 }
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2286
diff changeset
92
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
93 // Check to see if any of the elements in the cache need to be
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
94 // updated, then return the list of names in the cache.
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
95
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
96 string_vector
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3195
diff changeset
97 octave_fcn_file_name_cache::do_list (const std::string& path, bool no_suffix)
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
98 {
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
99 update (path);
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
100
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
101 string_vector fcn_file_names;
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
102 string_vector fcn_file_names_no_suffix;
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
103
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
104 // For now, always generate the list of function files on each
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
105 // call.
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
106
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
107 // XXX FIXME XXX -- this could probably be improved by keeping lists
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
108 // of all the function files for the current load path and only
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
109 // updating that when the load path changes. Have to be careful to
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
110 // return the right thing when we are only looking for a subset of
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
111 // all the files in the load path.
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
112
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
113 int total_len = 0;
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
114
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 2926
diff changeset
115 dir_path p = path.empty () ? Vload_path_dir_path : dir_path (path);
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
116
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
117 string_vector dirs = p.all_directories ();
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
118
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
119 int ndirs = dirs.length ();
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
120
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
121 if (ndirs > 1)
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
122 {
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
123 for (int i = 0; i < ndirs; i++)
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
124 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3195
diff changeset
125 std::string d = dirs[i];
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
126
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
127 total_len += cache[d].length ();
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
128 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
129
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
130 fcn_file_names.resize (total_len);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
131 fcn_file_names_no_suffix.resize (total_len);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
132
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
133 int k = 0;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
134
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
135 for (int j = 0; j < ndirs; j++)
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
136 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3195
diff changeset
137 std::string d = dirs[j];
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
138
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
139 file_name_cache_elt elt = cache[d];
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
140
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
141 int len = elt.length ();
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
142
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
143 string_vector ffn = elt.fcn_file_names;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
144 string_vector ffnns = elt.fcn_file_names_no_suffix;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
145
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
146 for (int i = 0; i < len; i++)
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
147 {
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
148 fcn_file_names[k] = ffn[i];
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
149 fcn_file_names_no_suffix[k] = ffnns[i];
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
150
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
151 k++;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
152 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
153 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
154 }
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
155 else if (ndirs == 1)
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
156 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3195
diff changeset
157 std::string d = dirs[0];
2286
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
158
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
159 file_name_cache_elt elt = cache[d];
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
160
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
161 fcn_file_names = elt.fcn_file_names;
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
162 fcn_file_names_no_suffix = elt.fcn_file_names_no_suffix;
c0eed36e660d [project @ 1996-05-31 04:41:50 by jwe]
jwe
parents: 2283
diff changeset
163 }
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
164
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
165 return no_suffix ? fcn_file_names_no_suffix : fcn_file_names;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
166 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
167
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
168 // Create a list of the function names in a given directory. Returns
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
169 // TRUE if the cache element was out of date.
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
170
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
171 bool
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3195
diff changeset
172 file_name_cache_elt::update (const std::string& dir_name)
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
173 {
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
174 bool retval = false;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
175
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
176 file_stat file (dir_name);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
177
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
178 // If the directory doesn't exist, delete the names in the cache.
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
179 // If it does exist,read it only if it is out of date.
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
180
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
181 if (file)
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
182 {
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
183 if (file.is_newer (timestamp))
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
184 {
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
185 retval = true;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
186
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
187 timestamp = file.mtime ();
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
188
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
189 dir_entry dir (dir_name);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
190
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
191 if (dir)
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
192 {
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
193 string_vector tmp = dir.read ();
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
194
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
195 int max_len = tmp.length ();
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
196
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
197 fcn_file_names.resize (max_len);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
198 fcn_file_names_no_suffix.resize (max_len);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
199
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
200 int k = 0;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
201 int i;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
202 for (i = 0; i < max_len; i++)
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
203 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3195
diff changeset
204 std::string entry = tmp[i];
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
205
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
206 int len = entry.length ();
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
207
4128
919b2f6573ee [project @ 2002-10-25 20:36:14 by jwe]
jwe
parents: 3523
diff changeset
208 #if defined (ENABLE_DYNAMIC_LINKING)
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
209 if ((len > 2
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
210 && entry[len-2] == '.' && entry[len-1] == 'm')
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
211 || (len > 4
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
212 && entry[len-4] == '.' && entry[len-3] == 'o'
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
213 && entry[len-2] == 'c' && entry[len-1] == 't'))
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
214 #else
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
215 if (len > 2
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
216 && entry[len-2] == '.' && entry[len-1] == 'm')
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
217 #endif
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
218 {
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
219 fcn_file_names[k] = entry;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
220
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
221 fcn_file_names_no_suffix[k] = (entry[len-1] == 'm')
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3195
diff changeset
222 ? std::string (entry, 0, len-2)
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3195
diff changeset
223 : std::string (entry, 0, len-4);
2232
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
224
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
225 k++;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
226 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
227 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
228
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
229 fcn_file_names.resize (k);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
230 fcn_file_names_no_suffix.resize (k);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
231 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
232 else
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
233 {
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
234 fcn_file_names.resize (0);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
235 fcn_file_names_no_suffix.resize (0);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
236 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
237 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
238 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
239 else
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
240 {
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
241 fcn_file_names.resize (0);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
242 fcn_file_names_no_suffix.resize (0);
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
243 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
244
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
245 return retval;
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
246 }
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
247
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
248 /*
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
249 ;;; Local Variables: ***
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
250 ;;; mode: C++ ***
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
251 ;;; End: ***
834eab508368 [project @ 1996-05-17 17:11:40 by jwe]
jwe
parents:
diff changeset
252 */