~ubuntu-branches/ubuntu/saucy/python-scipy/saucy

« back to all changes in this revision

Viewing changes to scipy/sandbox/xplt/src/play/unix/slinks.c

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * slinks.c -- $Id: slinks.c 685 2003-03-08 15:26:51Z travo $
 
3
 * u_track_link and u_find_exe functions from playu.h
 
4
 *
 
5
 * Copyright (c) 2000.  See accompanying LEGAL file for details.
 
6
 */
 
7
 
 
8
/* need these to pick up readlink prototype (unistd.h) */
 
9
#ifndef _XOPEN_SOURCE
 
10
#define _XOPEN_SOURCE 1
 
11
#endif
 
12
#ifndef _XOPEN_SOURCE_EXTENDED
 
13
#define _XOPEN_SOURCE_EXTENDED 1
 
14
#endif
 
15
 
 
16
#include "config.h"
 
17
 
 
18
#include "playu.h"
 
19
#include "pstdlib.h"
 
20
#include "pstdio.h"
 
21
 
 
22
#include <unistd.h>
 
23
 
 
24
char *
 
25
u_track_link(const char *name)
 
26
{
 
27
  if (name) {
 
28
    char link[P_WKSIZ+1];
 
29
    int i, len;
 
30
    if (name != p_wkspc.c)
 
31
      for (i=0 ; (p_wkspc.c[i] = name[i]) && i<P_WKSIZ ; i++);
 
32
    for (;;) {
 
33
      len = readlink(p_wkspc.c, link, P_WKSIZ);
 
34
      if (len < 0) break;
 
35
      for (i=0 ; i<len ; i++) p_wkspc.c[i] = link[i];
 
36
      p_wkspc.c[i] = '\0';
 
37
    }
 
38
    return p_wkspc.c;
 
39
  } else {
 
40
    return 0;
 
41
  }
 
42
}
 
43
 
 
44
char *
 
45
u_find_exe(const char *argv0)
 
46
{
 
47
  char *wkspc = p_wkspc.c;
 
48
  int i = 0;
 
49
  if (!argv0) return 0;
 
50
 
 
51
  while (argv0[i] && argv0[i]!='/') i++;
 
52
 
 
53
  if (!argv0[i]) {   /* search for argv0 on PATH environment variable */
 
54
    char *path = getenv("PATH");
 
55
    char c = path? path[0] : 0;
 
56
    int s, j, k=0;
 
57
    while (c) {
 
58
      while (c && c!=':') c = path[k++];
 
59
      if (k > 1) {
 
60
        for (j=0 ; j<k-1 && j<P_WKSIZ ; j++) wkspc[j] = path[j];
 
61
        if (wkspc[j-1] == '/') s = 0;
 
62
        else s = 1, wkspc[j] = '/';
 
63
        for (; j<k+i && j<P_WKSIZ ; j++) wkspc[j+s] = argv0[j-k+1];
 
64
        if (access(wkspc, X_OK) >= 0) break;
 
65
      }
 
66
      path += k;
 
67
      k = 0;
 
68
      c = path[0];
 
69
    }
 
70
    return k? wkspc : 0;
 
71
  }
 
72
 
 
73
  if (i) {           /* argv0 refers to subdirectory of cwd */
 
74
    wkspc = p_getcwd();
 
75
    if (wkspc) {
 
76
      int j;
 
77
      for (j=0 ; wkspc[j] ; j++);
 
78
      if (j && wkspc[j-1] != '/') wkspc[j++] = '/';
 
79
      while (argv0[0]=='.' && argv0[1]=='/') argv0 += 2;
 
80
      for (i=j ; argv0[i-j] && i<P_WKSIZ ; i++) wkspc[i] = argv0[i-j];
 
81
    } else {
 
82
      i = 0;
 
83
      wkspc = p_wkspc.c;
 
84
    }
 
85
 
 
86
  } else {           /* argv0 is absolute pathname */
 
87
    for (i=0 ; argv0[i] && i<P_WKSIZ ; i++) wkspc[i] = argv0[i];
 
88
  }
 
89
 
 
90
  wkspc[i] = '\0';
 
91
  return (access(wkspc, X_OK) >= 0)? wkspc : 0;
 
92
}