Skip to content

Commit f1250b7

Browse files
committed
COMMON: Fixes for unit case sensitivity
1 parent 0053779 commit f1250b7

File tree

3 files changed

+50
-43
lines changed

3 files changed

+50
-43
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2016-04-26 (0.12.6)
2+
Fixes for unit case sensitivity
3+
14
2016-04-24 (0.12.6)
25
Fixes for RUN/EXEC
36

src/common/proc.c

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#include "common/pproc.h"
1212
#include "common/messages.h"
1313
#include "common/inet.h"
14+
1415
#include <limits.h>
16+
#include <dirent.h>
1517

1618
/*
1719
* returns the last-modified time of the file
@@ -39,11 +41,9 @@ time_t sys_filetime(const char *file) {
3941
int sys_search_path(const char *path, const char *file, char *retbuf) {
4042
const char *ps, *p;
4143
char cur_path[OS_PATHNAME_SIZE + 1];
44+
int found = 0;
4245

43-
if (path == NULL) {
44-
return 0;
45-
}
46-
if (strlen(path) == 0) {
46+
if (path == NULL || strlen(path) == 0) {
4747
return 0;
4848
}
4949
ps = path;
@@ -64,9 +64,7 @@ int sys_search_path(const char *path, const char *file, char *retbuf) {
6464

6565
// fix home directory
6666
if (cur_path[0] == '~') {
67-
char *old_path;
68-
69-
old_path = malloc(strlen(cur_path));
67+
char *old_path = malloc(strlen(cur_path));
7068
strcpy(old_path, cur_path + 1);
7169
#if defined(_UnixOS)
7270
sprintf(cur_path, "%s/%s", getenv("HOME"), old_path);
@@ -79,32 +77,38 @@ int sys_search_path(const char *path, const char *file, char *retbuf) {
7977
#endif
8078
free(old_path);
8179
}
82-
// build the final file-name
80+
81+
DIR *dp = opendir(cur_path);
82+
if (dp != NULL) {
83+
struct dirent *entry;
84+
while (!found && (entry = readdir(dp)) != NULL) {
85+
if (strcasecmp(entry->d_name, file) == 0) {
8386
#if defined(_UnixOS)
84-
strcat(cur_path, "/");
87+
strcat(cur_path, "/");
8588
#else
86-
strcat(cur_path, "\\");
89+
strcat(cur_path, "\\");
8790
#endif
88-
strcat(cur_path, file);
89-
90-
if (access(cur_path, R_OK) == 0) {
91-
if (retbuf) {
92-
strcpy(retbuf, cur_path);
91+
strcat(cur_path, entry->d_name);
92+
if (access(cur_path, R_OK) == 0) {
93+
if (retbuf) {
94+
strcpy(retbuf, cur_path);
95+
}
96+
found = 1;
97+
}
98+
}
9399
}
94-
return 1;
100+
closedir(dp);
95101
}
96-
97-
} while (p);
98-
99-
return 0;
102+
} while (p && !found);
103+
return found;
100104
}
101105

102106
/*
103107
* execute a user's expression (using one variable)
104108
* (note: keyword USE)
105109
*
106110
* var - the variable (the X)
107-
* ip - expression's address
111+
* ip - expression's address
108112
*/
109113
void exec_usefunc(var_t *var, bcip_t ip) {
110114
var_t *old_x;
@@ -129,7 +133,7 @@ void exec_usefunc(var_t *var, bcip_t ip) {
129133
*
130134
* var1 - the first variable (the X)
131135
* var2 - the second variable (the Y)
132-
* ip - expression's address
136+
* ip - expression's address
133137
*/
134138
void exec_usefunc2(var_t *var1, var_t *var2, bcip_t ip) {
135139
var_t *old_x, *old_y;
@@ -161,7 +165,7 @@ void exec_usefunc2(var_t *var1, var_t *var2, bcip_t ip) {
161165
* var1 - the first variable (the X)
162166
* var2 - the second variable (the Y)
163167
* var3 - the thrid variable (the Z)
164-
* ip - expression's address
168+
* ip - expression's address
165169
*/
166170
void exec_usefunc3(var_t *var1, var_t *var2, var_t *var3, bcip_t ip) {
167171
var_t *old_x, *old_y, *old_z;
@@ -706,7 +710,7 @@ int par_getpoly(pt_t **poly_pp) {
706710
}
707711
return 0;
708712
}
709-
//
713+
//
710714
el = v_elem(var, 0);
711715
if (el->type == V_ARRAY) {
712716
style = 1; // nested --- [ [x1,y1], [x2,y2], ... ]
@@ -817,7 +821,7 @@ int par_getipoly(ipt_t **poly_pp) {
817821
}
818822
return 0;
819823
}
820-
//
824+
//
821825
el = v_elem(var, 0);
822826
if (el && el->type == V_ARRAY) {
823827
style = 1; // nested --- [ [x1,y1], [x2,y2], ... ]
@@ -901,7 +905,7 @@ int par_getipoly(ipt_t **poly_pp) {
901905

902906
/*
903907
* returns true if the following code is descibing one var code
904-
* usefull for optimization
908+
* usefull for optimization
905909
* (one var can be used by the pointer; more than one it must be evaluated)
906910
*/
907911
int par_isonevar() {
@@ -970,7 +974,7 @@ int par_getpartable(par_t **ptable_pp, const char *valid_sep) {
970974
case kwTYPE_LEVEL_END: // end of parameters
971975
ready = 1;
972976
break;
973-
case kwTYPE_SEP: // separator
977+
case kwTYPE_SEP: // separator
974978
code_skipnext();
975979

976980
// check parameters separator
@@ -1068,7 +1072,7 @@ int par_massget_type_check(char fmt, par_t *par) {
10681072
* // the string is optional too
10691073
* pc = par_massget("Iis", &i1, &i2, &s1, &v);
10701074
*
1071-
* if ( pc != -1 ) {
1075+
* if ( pc != -1 ) {
10721076
* // no error; also, you can use prog_error because par_massget() will call rt_raise() on error
10731077
* printf("required integer = %d\n", i1);
10741078
*
@@ -1098,7 +1102,7 @@ int par_massget(const char *fmt, ...) {
10981102
free(ptable);
10991103
return -1;
11001104
}
1101-
1105+
11021106
/*
11031107
* count pars
11041108
*/
@@ -1112,7 +1116,7 @@ int par_massget(const char *fmt, ...) {
11121116
}
11131117
fmt_p++;
11141118
}
1115-
1119+
11161120
if (rqcount > pcount) {
11171121
err_parfmt(fmt);
11181122
}
@@ -1191,7 +1195,7 @@ int par_massget(const char *fmt, ...) {
11911195
case 'P':
11921196
// variable
11931197
vt = va_arg(ap, var_t**);
1194-
if (ptable[curpar].flags == 0)// byref
1198+
if (ptable[curpar].flags == 0)// byref
11951199
*vt = ptable[curpar].var;
11961200
else {
11971201
err_syntax(-1, "%P");

src/common/scan.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4002,21 +4002,21 @@ void comp_preproc_unit_path(char *p) {
40024002
if (*p == '=') {
40034003
p++;
40044004
SKIP_SPACES(p);
4005-
if (*p == '\"') {
4006-
p++;
4007-
char upath[SB_SOURCELINE_SIZE + 1];
4008-
char *up = upath;
4009-
while (*p != '\n' && *p != '\"') {
4010-
*up++ = *p++;
4011-
}
4012-
*up = '\0';
4005+
}
4006+
if (*p == '\"') {
4007+
p++;
4008+
char upath[SB_SOURCELINE_SIZE + 1];
4009+
char *up = upath;
4010+
while (*p != '\n' && *p != '\"') {
4011+
*up++ = *p++;
4012+
}
4013+
*up = '\0';
40134014
#ifdef __MINGW32__
4014-
sprintf(comp_bc_temp, "UNITPATH=%s", upath);
4015-
putenv(strdup(comp_bc_temp));
4015+
sprintf(comp_bc_temp, "UNITPATH=%s", upath);
4016+
putenv(strdup(comp_bc_temp));
40164017
#else
4017-
setenv(LCN_UNIT_PATH, upath, 1);
4018+
setenv(LCN_UNIT_PATH, upath, 1);
40184019
#endif
4019-
}
40204020
}
40214021
}
40224022

0 commit comments

Comments
 (0)