~ubuntu-branches/ubuntu/intrepid/swi-prolog/intrepid

« back to all changes in this revision

Viewing changes to src/pl-wic.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2008-05-14 02:47:49 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080514024749-out53uysriunvn32
Tags: 5.6.55-1
* New upstream release.
* Use correct shared object file extension on HPPA to fix FTBFS on this
  architecture since 5.6.53-2. Patch backported from upstream repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2278
2278
}
2279
2279
 
2280
2280
static bool
2281
 
qlfLoad(char *file, Module *module ARG_LD)
2282
 
{ IOSTREAM *fd;
2283
 
  bool rval;
 
2281
qlfLoad(IOSTREAM *fd, Module *module ARG_LD)
 
2282
{ bool rval;
2284
2283
  int lversion;
2285
 
  char *absloadname;
 
2284
  const char *absloadname;
2286
2285
  char tmp[MAXPATHLEN];
2287
2286
  int saved_wsize;
2288
 
 
2289
 
  wicFile = file;
2290
 
  if ( !(absloadname = AbsoluteFile(wicFile, tmp)) )
2291
 
    fail;
 
2287
  atom_t file;
 
2288
 
 
2289
  if ( (file = fileNameStream(fd)) )
 
2290
  { PL_chars_t text;
 
2291
 
 
2292
    if ( !get_atom_text(file, &text) )
 
2293
      fail;
 
2294
    if ( !PL_mb_text(&text, REP_FN) )
 
2295
    { PL_free_text(&text);
 
2296
      fail;
 
2297
    }
 
2298
    wicFile = text.text.t;
 
2299
    if ( !(absloadname = AbsoluteFile(wicFile, tmp)) )
 
2300
      fail;
 
2301
    PL_free_text(&text);
 
2302
  } else
 
2303
  { absloadname = NULL;
 
2304
  }
2292
2305
  
2293
 
  if ( !(fd = Sopen_file(file, "rbr")) )
2294
 
  { term_t f = PL_new_term_ref();
2295
 
 
2296
 
    PL_put_atom_chars(f, file);
2297
 
    return PL_error(NULL, 0, OsError(), ERR_FILE_OPERATION,
2298
 
                    ATOM_open, ATOM_source_sink, f);
2299
 
  }
2300
2306
  if ( !(lversion = qlfVersion(fd)) || lversion < LOADVERSION )
2301
 
  { Sclose(fd);
2302
 
    if ( lversion )
 
2307
  { if ( lversion )
2303
2308
      warning("$qlf_load/1: %s bad version (file version = %d, prolog = %d)",
2304
2309
              wicFile, lversion, VERSION);
2305
2310
    fail;
2321
2326
  popXrIdTable(PASS_LD1);
2322
2327
  popPathTranslation();
2323
2328
 
2324
 
  Sclose(fd);
2325
 
 
2326
2329
  return rval;
2327
2330
}
2328
2331
 
2476
2479
}
2477
2480
 
2478
2481
 
2479
 
word
2480
 
pl_qlf_load(term_t file, term_t module)
 
2482
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
2483
$qlf_load(:Stream, -ModuleOut)
 
2484
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
2485
 
 
2486
static
 
2487
PRED_IMPL("$qlf_load", 2, qlf_load, PL_FA_TRANSPARENT)
2481
2488
{ GET_LD
 
2489
  term_t qstream = A1;
 
2490
  term_t module = A2;
2482
2491
  Module m, oldsrc = LD->modules.source;
2483
2492
  char *fn;
2484
2493
  bool rval;
2485
 
  term_t name = PL_new_term_ref();
 
2494
  term_t stream = PL_new_term_ref();
 
2495
  IOSTREAM *fd;
 
2496
  IOENC saved_enc;
2486
2497
 
2487
2498
  m = oldsrc;
2488
 
  if ( !PL_strip_module(file, &m, name) )
 
2499
  if ( !PL_strip_module(qstream, &m, stream) )
2489
2500
    fail;
2490
 
  if ( !PL_get_file_name(name, &fn, 0) )
 
2501
  if ( !PL_get_stream_handle(stream, &fd) )
2491
2502
    fail;
2492
2503
 
 
2504
  saved_enc = fd->encoding;
 
2505
  fd->encoding = ENC_OCTET;
2493
2506
  LD->modules.source = m;
2494
 
  rval = qlfLoad(fn, &m PASS_LD);
 
2507
  rval = qlfLoad(fd, &m PASS_LD);
2495
2508
  LD->modules.source = oldsrc;
2496
 
 
2497
 
  if ( !rval )
2498
 
    fail;
2499
 
 
2500
 
  if ( m )
2501
 
    return PL_unify_atom(module, m->name);
2502
 
  else
 
2509
  fd->encoding = saved_enc;
 
2510
 
 
2511
  if ( rval )
 
2512
  { if ( m )
 
2513
      return PL_unify_atom(module, m->name);
 
2514
 
2503
2515
    return PL_unify_integer(module, 0);
 
2516
  }
 
2517
 
 
2518
  fail;
2504
2519
}
2505
2520
 
2506
2521
 
2785
2800
 
2786
2801
BeginPredDefs(wic)
2787
2802
  PRED_DEF("$qlf_info", 5, qlf_info, 0)
 
2803
  PRED_DEF("$qlf_load", 2, qlf_load, PL_FA_TRANSPARENT)
2788
2804
EndPredDefs