| top | | | ^ | | | | | | section top | | | ^ | Referenced at: 4, 10, 38. | | | | | section top | |
Obj prefPath = 0;
chars home;
| ^ | | | | | | section top | |
home = getenv("HOME");
prefPath = incr(Tcl_NewObj());
if (home) Tcl_AppendToObj(prefPath,home,-1);
Tcl_AppendToObj(prefPath,"/.",-1);
Tcl_AppendToObj(prefPath,group,-1);
Tcl_AppendToObj(prefPath,"rc",-1);
| ^ | | | | | | section top | | | ^ | Definition continued at: 16, 18, 21. | | | | | section top | |
tempPath = incr(Tcl_NewObj());
if (home) Tcl_AppendToObj(tempPath,home,-1);
Tcl_AppendToObj(tempPath,"/.",-1);
Tcl_AppendToObj(tempPath,group,-1);
Tcl_AppendToObj(tempPath,".tmp",-1);
tempChan = Tcl_OpenFileChannel(intr,Tcl_GetStringFromObj(tempPath,0),"w",0644);
| ^ | | | | | | section top | |
Tcl_Channel prefChan = 0, tempChan = 0;
| ^ | Definition continued at: 18, 21. | | | | | section top | |
{
chars fn = Tcl_GetStringFromObj(prefPath,0); int fd; ClientData FD;
prefChan = Tcl_OpenFileChannel(intr,fn,"r",0);
if (prefChan) {
FD = &fd;
if (onError(Tcl_GetChannelHandle(prefChan,TCL_READABLE,&FD)==TCL_ERROR,intr,fn)) goto exit;
fd = (int)FD;
if (onError(flock(fd,LOCK_EX)<0,intr,fn)) goto exit;
}
if (value) {
fn = Tcl_GetStringFromObj(tempPath,0);
tempChan = Tcl_OpenFileChannel(intr,fn,"w",0644);
if (onError(!tempChan,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
FD = &fd;
if (onError(Tcl_GetChannelHandle(tempChan,TCL_WRITABLE,&FD)==TCL_ERROR,intr,fn)) goto exit;
fd = (int)FD;
if (onError(flock(fd,LOCK_EX)<0,intr,fn)) goto exit;
}
}
| ^ | | | | | | section top | |
int n = strlen(variable);
Obj line = incr(Tcl_NewObj());
| ^ | Definition continued at: 21. | | | | | section top | |
for (;;) {
int m; chars s,s1;
if (!prefChan) break;
Tcl_SetObjLength(line,0);
if (Tcl_GetsObj(prefChan,line)<=0) {
if (onError(!Tcl_Eof(prefChan),intr,Tcl_GetStringFromObj(prefPath,0))) goto exit;
break;
}
s = Tcl_GetStringFromObj(line,&m);
while (n>0 && isspace(*s)) {s++; n--;}
if (*s!='#' && m>n && s[n]=='=' && memcmp(s,variable,n)==0) {
r = incr(Tcl_NewStringObj(s+n+1,m-n-1));
if (tempChan) {
if (onError(Tcl_Write(tempChan,variable,-1)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
if (onError(Tcl_Write(tempChan,"=",-1)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
if (onError(Tcl_Write(tempChan,value,-1)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
if (onError(Tcl_Write(tempChan,"\n",-1)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
}
break;
}else {
if (tempChan) {
if (onError(Tcl_Write(tempChan,s,m)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
if (onError(Tcl_Write(tempChan,"\n",-1)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
}
}
}
if (tempChan && !r) {
if (onError(Tcl_Write(tempChan,variable,-1)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
if (onError(Tcl_Write(tempChan,"=",-1)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
if (*value) {
if (onError(Tcl_Write(tempChan,value,-1)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
}
if (onError(Tcl_Write(tempChan,"\n",-1)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
}
if (!r)
r = incr(Tcl_NewObj());
| ^ | | | | | | section top | |
if (tempChan && prefChan && !Tcl_Eof(prefChan)) {
for (;;) {
int m; chars s;
if (!prefChan) break;
Tcl_SetObjLength(line,0);
if (Tcl_GetsObj(prefChan,line)<=0) {
if (onError(!Tcl_Eof(prefChan),intr,Tcl_GetStringFromObj(prefPath,0))) goto exit;
break;
}
s = Tcl_GetStringFromObj(line,&m);
if (onError(Tcl_Write(tempChan,s,m)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
if (onError(Tcl_Write(tempChan,"\n",-1)<=0,intr,Tcl_GetStringFromObj(tempPath,0))) goto exit;
}
}
| ^ | | | | | | section top | | | ^ | | | | | | section top | |
prefName = Tcl_GetStringFromObj(prefPath,0);
tempName = Tcl_GetStringFromObj(tempPath,0);
unlink(prefName);
if (onError(link(tempName,prefName)<0,intr,"wyrm_preference: link new prefs")) goto exit;
unlink(tempName);
| ^ | | | | | | section top | |
exit:
decr(prefPath);
decr(tempPath);
if (prefChan) Tcl_Close(intr,prefChan);
if (tempChan) Tcl_Close(intr,tempChan);
decr(line);
return r;
| ^ | | | | | | section top | |
int wyrm_preferenceDelete(Intr intr,chars group) {
int rc; chars prefName;
<File path variables (Unix)>
<Determine preference file path (Unix)>
prefName = Tcl_GetStringFromObj(prefPath,0);
rc = unlink(prefName);
if (rc<0 && errno==ENOENT) {
rc = TCL_OK;
}else if (onError(rc<0,intr,"wyrm_preferenceDelete unlink")) {
rc = TCL_ERROR;
}else {
rc = TCL_OK;
}
decr(prefPath);
return rc;
}
| ^ | | | | | | section top | |
static bool onError(int ec,Intr intr,chars where) {
if (ec) {
if (intr) {
Tcl_ResetResult(intr);
Tcl_AppendResult(intr,where,": ",strerror(errno),0);
}
return true;
}else
return false;
}
| ^ | | |
| |