Skip to content
Snippets Groups Projects
Commit de05580e authored by rswindell's avatar rswindell
Browse files

alias() now handles blank lines and blank alias values correctly.

parent 8cd79975
No related branches found
No related tags found
No related merge requests found
...@@ -1960,11 +1960,11 @@ char* DLLCALL usermailaddr(scfg_t* cfg, char* addr, char* name) ...@@ -1960,11 +1960,11 @@ char* DLLCALL usermailaddr(scfg_t* cfg, char* addr, char* name)
char* DLLCALL alias(scfg_t* cfg, char* name, char* buf) char* DLLCALL alias(scfg_t* cfg, char* name, char* buf)
{ {
int file;
char line[128]; char line[128];
char* p; char* p;
char* np; char* np;
char* tp; char* tp;
char* vp;
char fname[MAX_PATH+1]; char fname[MAX_PATH+1];
size_t namelen; size_t namelen;
size_t cmplen; size_t cmplen;
...@@ -1976,24 +1976,29 @@ char* DLLCALL alias(scfg_t* cfg, char* name, char* buf) ...@@ -1976,24 +1976,29 @@ char* DLLCALL alias(scfg_t* cfg, char* name, char* buf)
p=name; p=name;
sprintf(fname,"%salias.cfg",cfg->ctrl_dir); sprintf(fname,"%salias.cfg",cfg->ctrl_dir);
if((file=sopen(fname,O_RDONLY|O_BINARY,SH_DENYNO))==-1) if((fp=fopen(fname,"r"))==NULL)
return(name);
if((fp=fdopen(file,"rb"))==NULL) {
close(file);
return(name); return(name);
}
while(!feof(fp)) { while(!feof(fp)) {
if(!fgets(line,sizeof(line),fp)) if(!fgets(line,sizeof(line),fp))
break; break;
np=line; np=line;
SKIP_WHITESPACE(np); SKIP_WHITESPACE(np);
if(*np==';') if(*np==';' || *np==0) /* no name value, or comment */
continue; continue;
tp=np; tp=np;
FIND_WHITESPACE(tp); FIND_WHITESPACE(tp);
if(*tp) *tp=0;
if(*tp==0) /* no alias value */
continue;
*tp=0;
vp=tp+1;
SKIP_WHITESPACE(vp);
truncsp(vp);
if(*vp==0) /* no value */
continue;
if(*np=='*') { if(*np=='*') {
np++; np++;
cmplen=strlen(np); cmplen=strlen(np);
...@@ -2002,21 +2007,15 @@ char* DLLCALL alias(scfg_t* cfg, char* name, char* buf) ...@@ -2002,21 +2007,15 @@ char* DLLCALL alias(scfg_t* cfg, char* name, char* buf)
continue; continue;
if(strnicmp(np,name+(namelen-cmplen),cmplen)) if(strnicmp(np,name+(namelen-cmplen),cmplen))
continue; continue;
np=tp+1; if(*vp=='*')
SKIP_WHITESPACE(np); sprintf(buf,"%.*s%s",(int)(namelen-cmplen),name,vp+1);
truncsp(np);
if(*np=='*')
sprintf(buf,"%.*s%s",(int)(namelen-cmplen),name,np+1);
else else
strcpy(buf,np); strcpy(buf,vp);
p=buf; p=buf;
break; break;
} }
if(!stricmp(np,name)) { if(!stricmp(np,name)) {
np=tp+1; strcpy(buf,vp);
SKIP_WHITESPACE(np);
truncsp(np);
strcpy(buf,np);
p=buf; p=buf;
break; break;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment