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)
char* DLLCALL alias(scfg_t* cfg, char* name, char* buf)
{
int file;
char line[128];
char* p;
char* np;
char* tp;
char* vp;
char fname[MAX_PATH+1];
size_t namelen;
size_t cmplen;
......@@ -1976,24 +1976,29 @@ char* DLLCALL alias(scfg_t* cfg, char* name, char* buf)
p=name;
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);
}
while(!feof(fp)) {
if(!fgets(line,sizeof(line),fp))
break;
np=line;
SKIP_WHITESPACE(np);
if(*np==';')
if(*np==';' || *np==0) /* no name value, or comment */
continue;
tp=np;
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=='*') {
np++;
cmplen=strlen(np);
......@@ -2002,21 +2007,15 @@ char* DLLCALL alias(scfg_t* cfg, char* name, char* buf)
continue;
if(strnicmp(np,name+(namelen-cmplen),cmplen))
continue;
np=tp+1;
SKIP_WHITESPACE(np);
truncsp(np);
if(*np=='*')
sprintf(buf,"%.*s%s",(int)(namelen-cmplen),name,np+1);
if(*vp=='*')
sprintf(buf,"%.*s%s",(int)(namelen-cmplen),name,vp+1);
else
strcpy(buf,np);
strcpy(buf,vp);
p=buf;
break;
}
if(!stricmp(np,name)) {
np=tp+1;
SKIP_WHITESPACE(np);
truncsp(np);
strcpy(buf,np);
strcpy(buf,vp);
p=buf;
break;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment