summaryrefslogtreecommitdiff
path: root/web/matlabweb/pathopen.c
blob: 626a7117c5661eb1bd8c868a6fea1e4a660f3d90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*4:*/
#line 88 "/u/norman/pu/web/dist/src/master/pathopen.web"

/*9:*/
#line 171 "/u/norman/pu/web/dist/src/master/pathopen.web"
#include<stdio.h>

/*:9*/
#line 89 "/u/norman/pu/web/dist/src/master/pathopen.web"


static int nextpath= 0;
static char pathtexts[1024];
static char *searchpath[64]= {pathtexts};
static char *maxpathtexts= pathtexts+1024;

void pathreset()
{
nextpath= 0;
searchpath[nextpath]= pathtexts;
}

/*:4*//*5:*/
#line 103 "/u/norman/pu/web/dist/src/master/pathopen.web"

void pathaddname(name)
char *name;
{char *t= searchpath[nextpath];
if(name==NULL)return;
if(nextpath>=64)overflow("paths");
while( *name){
if(t>=maxpathtexts)overflow("path texts");
 *t++=  *name++;
}
/*6:*/
#line 118 "/u/norman/pu/web/dist/src/master/pathopen.web"

if(t==searchpath[nextpath])nextpath--;
else if(t==searchpath[nextpath]+1&&
 *searchpath[nextpath]=='/')
t--;

/*:6*/
#line 114 "/u/norman/pu/web/dist/src/master/pathopen.web"

searchpath[++nextpath]= t;
}

/*:5*//*7:*/
#line 125 "/u/norman/pu/web/dist/src/master/pathopen.web"

#line 126 "/u/norman/pu/web/dist/src/master/pathopen.web"
void pathaddpath(path,path_separator)
char *path;
char path_separator;
{
char *t= searchpath[nextpath];
if(path!=NULL){
while( *path){
if(nextpath>=64)overflow("paths");
while( *path!=path_separator&& *path!='\0'){
if(t>=maxpathtexts)overflow("path texts");
 *t++=  *path++;
}
/*6:*/
#line 118 "/u/norman/pu/web/dist/src/master/pathopen.web"

if(t==searchpath[nextpath])nextpath--;
else if(t==searchpath[nextpath]+1&&
 *searchpath[nextpath]=='/')
t--;

/*:6*/
#line 138 "/u/norman/pu/web/dist/src/master/pathopen.web"

searchpath[++nextpath]= t;
if( *path)path++;
}
}
}

/*:7*//*8:*/
#line 151 "/u/norman/pu/web/dist/src/master/pathopen.web"

FILE *pathopen(name)
char *name;
{
FILE *fp;
char pathname[1024];
char *s, *t;
int i;

if(( *(name)=='/'))
return fopen(name,"r");
else{
if((fp= fopen(name,"r"))!=NULL)return fp;
for(i= 0;i<nextpath;i++){
/*10:*/
#line 173 "/u/norman/pu/web/dist/src/master/pathopen.web"

#line 174 "/u/norman/pu/web/dist/src/master/pathopen.web"
for(s= pathname,t= searchpath[i];t<searchpath[i+1];){
 *s++=  *t++;
if(s>pathname+1024)overflow("path name length");
}
 *s++= '/';
if(s>pathname+1024)overflow("path name length");
t= name;
while( *s++=  *t++)
if(s>pathname+1024)overflow("path name length");
if((fp= fopen(pathname,"r"))!=NULL)return fp;


/*:10*/
#line 165 "/u/norman/pu/web/dist/src/master/pathopen.web"

}
}
return NULL;
}

/*:8*/