~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Source/Swig/include.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2009-11-15 14:00:28 UTC
  • mfrom: (1.2.9 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091115140028-me7amr2rie8zz1xn
Tags: 1.3.40-2ubuntu1
* Merge from Debian testing (LP: #356529), remaining changes:
  - Drop libchicken-dev from the build-depends (it's in universe)
  - Remove Pike from package description and from configure flags
  - drop "--without-mzscheme", we don't have it in our build-depends
  - use php-config5
  - Clean Runtime/ as well.
  - debian/rules (clean): Remove Lib/ocaml/swigp4.ml.
* debian/rules: Remove hardcoded python version.
* Remove upper limit for python from Build-Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 * are provided.
10
10
 * ----------------------------------------------------------------------------- */
11
11
 
12
 
char cvsroot_include_c[] = "$Id: include.c 10540 2008-06-21 15:23:02Z wsfulton $";
 
12
char cvsroot_include_c[] = "$Id: include.c 11080 2009-01-24 13:15:51Z bhy $";
13
13
 
14
14
#include "swig.h"
15
15
 
33
33
 * Adds a directory to the SWIG search path.
34
34
 * ----------------------------------------------------------------------------- */
35
35
 
36
 
List *Swig_add_directory(const String_or_char *dirname) {
 
36
List *Swig_add_directory(const_String_or_char_ptr dirname) {
37
37
  String *adirname;
38
38
  if (!directories)
39
39
    directories = NewList();
53
53
 * the preprocessor to grab files in the same directory as other included files.
54
54
 * ----------------------------------------------------------------------------- */
55
55
 
56
 
void Swig_push_directory(const String_or_char *dirname) {
 
56
void Swig_push_directory(const_String_or_char_ptr dirname) {
57
57
  String *pdirname;
58
58
  if (!Swig_get_push_dir())
59
59
    return;
73
73
 * the preprocessor.
74
74
 * ----------------------------------------------------------------------------- */
75
75
 
76
 
void Swig_pop_directory() {
 
76
void Swig_pop_directory(void) {
77
77
  if (!Swig_get_push_dir())
78
78
    return;
79
79
  if (!pdirectories)
87
87
 * Returns the full pathname of the last file opened. 
88
88
 * ----------------------------------------------------------------------------- */
89
89
 
90
 
String *Swig_last_file() {
 
90
String *Swig_last_file(void) {
91
91
  assert(lastpath);
92
92
  return lastpath;
93
93
}
94
94
 
95
95
/* -----------------------------------------------------------------------------
96
 
 * Swig_search_path() 
 
96
 * Swig_search_path_any() 
97
97
 * 
98
98
 * Returns a list of the current search paths.
99
99
 * ----------------------------------------------------------------------------- */
151
151
/* -----------------------------------------------------------------------------
152
152
 * Swig_open()
153
153
 *
154
 
 * Looks for a file and open it.  Returns an open  FILE * on success.
 
154
 * open a file, optionally looking for it in the include path.  Returns an open  
 
155
 * FILE * on success.
155
156
 * ----------------------------------------------------------------------------- */
156
157
 
157
 
static FILE *Swig_open_any(const String_or_char *name, int sysfile) {
 
158
static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_include_path) {
158
159
  FILE *f;
159
160
  String *filename;
160
161
  List *spath = 0;
169
170
  filename = NewString(cname);
170
171
  assert(filename);
171
172
  f = fopen(Char(filename), "r");
172
 
  if (!f) {
 
173
  if (!f && use_include_path) {
173
174
    spath = Swig_search_path_any(sysfile);
174
175
    ilen = Len(spath);
175
176
    for (i = 0; i < ilen; i++) {
182
183
    Delete(spath);
183
184
  }
184
185
  if (f) {
185
 
#if defined(_WIN32)             /* Note not on Cygwin else filename is displayed with double '/' */
186
 
    Replaceall(filename, "\\\\", "\\"); /* remove double '\' in case any already present */
187
 
    Replaceall(filename, "\\", "\\\\");
188
 
#endif
189
186
    Delete(lastpath);
190
 
    lastpath = Copy(filename);
 
187
    lastpath = Swig_filename_escape(filename);
191
188
  }
192
189
  Delete(filename);
193
190
  return f;
194
191
}
195
192
 
196
 
FILE *Swig_open(const String_or_char *name) {
197
 
  return Swig_open_any(name, 0);
 
193
/* Open a file - searching the include paths to find it */
 
194
FILE *Swig_include_open(const_String_or_char_ptr name) {
 
195
  return Swig_open_file(name, 0, 1);
 
196
}
 
197
 
 
198
/* Open a file - does not use include paths to find it */
 
199
FILE *Swig_open(const_String_or_char_ptr name) {
 
200
  return Swig_open_file(name, 0, 0);
198
201
}
199
202
 
200
203
 
230
233
 * Opens a file and returns it as a string.
231
234
 * ----------------------------------------------------------------------------- */
232
235
 
233
 
static String *Swig_include_any(const String_or_char *name, int sysfile) {
 
236
static String *Swig_include_any(const_String_or_char_ptr name, int sysfile) {
234
237
  FILE *f;
235
238
  String *str;
236
239
  String *file;
237
240
 
238
 
  f = Swig_open_any(name, sysfile);
 
241
  f = Swig_open_file(name, sysfile, 1);
239
242
  if (!f)
240
243
    return 0;
241
244
  str = Swig_read_file(f);
248
251
  return str;
249
252
}
250
253
 
251
 
String *Swig_include(const String_or_char *name) {
 
254
String *Swig_include(const_String_or_char_ptr name) {
252
255
  return Swig_include_any(name, 0);
253
256
}
254
257
 
255
 
String *Swig_include_sys(const String_or_char *name) {
 
258
String *Swig_include_sys(const_String_or_char_ptr name) {
256
259
  return Swig_include_any(name, 1);
257
260
}
258
261
 
262
265
 * Copies the contents of a file into another file
263
266
 * ----------------------------------------------------------------------------- */
264
267
 
265
 
int Swig_insert_file(const String_or_char *filename, File *outfile) {
 
268
int Swig_insert_file(const_String_or_char_ptr filename, File *outfile) {
266
269
  char buffer[4096];
267
270
  int nbytes;
268
 
  FILE *f = Swig_open(filename);
 
271
  FILE *f = Swig_include_open(filename);
269
272
 
270
273
  if (!f)
271
274
    return -1;
286
289
 
287
290
static Hash *named_files = 0;
288
291
 
289
 
void Swig_register_filebyname(const String_or_char *filename, File *outfile) {
 
292
void Swig_register_filebyname(const_String_or_char_ptr filename, File *outfile) {
290
293
  if (!named_files)
291
294
    named_files = NewHash();
292
295
  Setattr(named_files, filename, outfile);
298
301
 * Get a named file
299
302
 * ----------------------------------------------------------------------------- */
300
303
 
301
 
File *Swig_filebyname(const String_or_char *filename) {
 
304
File *Swig_filebyname(const_String_or_char_ptr filename) {
302
305
  if (!named_files)
303
306
    return 0;
304
307
  return Getattr(named_files, filename);
310
313
 * Returns the suffix of a file
311
314
 * ----------------------------------------------------------------------------- */
312
315
 
313
 
char *Swig_file_suffix(const String_or_char *filename) {
 
316
char *Swig_file_suffix(const_String_or_char_ptr filename) {
314
317
  char *d;
315
318
  char *c = Char(filename);
316
319
  int len = Len(filename);
332
335
 * Returns the filename with no suffix attached.
333
336
 * ----------------------------------------------------------------------------- */
334
337
 
335
 
char *Swig_file_basename(const String_or_char *filename) {
 
338
char *Swig_file_basename(const_String_or_char_ptr filename) {
336
339
  static char tmp[1024];
337
340
  char *c;
338
341
  strcpy(tmp, Char(filename));
346
349
 *
347
350
 * Return the file with any leading path stripped off
348
351
 * ----------------------------------------------------------------------------- */
349
 
char *Swig_file_filename(const String_or_char *filename) {
 
352
char *Swig_file_filename(const_String_or_char_ptr filename) {
350
353
  static char tmp[1024];
351
354
  const char *delim = SWIG_FILE_DELIMITER;
352
355
  char *c;
364
367
 *
365
368
 * Return the name of the directory associated with a file
366
369
 * ----------------------------------------------------------------------------- */
367
 
char *Swig_file_dirname(const String_or_char *filename) {
 
370
char *Swig_file_dirname(const_String_or_char_ptr filename) {
368
371
  static char tmp[1024];
369
372
  const char *delim = SWIG_FILE_DELIMITER;
370
373
  char *c;