supress write-lock on files opened in hex-mode

Ideas for new features

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
HHRüger
Posts: 6
Joined: Fri Jan 23, 2004 4:44 pm
Location: Thueringen
Contact:

supress write-lock on files opened in hex-mode

Post by HHRüger »

TP makes a difference in locking txt- and hex-files against write access. A permanent write-protection on hex-files is obsolet. There should be at least a switch "disable hex-file write-protection" or a rearangement of the "keep files locked.." - option into "keep background file open while editing foreground-instance".
HHR
HHRüger
Posts: 6
Joined: Fri Jan 23, 2004 4:44 pm
Location: Thueringen
Contact:

Post by HHRüger »

To 'insist' in my OP:
Compile this, use TP's configuration menu to bind it as a tool and let it work with any txt- and bin files opened. You soon will agree, than bin-file-kocking is more than annoying.
HHRü

#include<stdio.h>
#include<stdlib.h>

int main(int argc, char *argv[])
{
FILE *fp;
long i,j,position;
char ch,word[100];
if(argc!=4)
{
printf("Usage: xins <file> <position> <string> xmpl:\n");
printf("in \"x.bin\" at hex-pos FFF overstrike A[Tab]B: \"xins x.bin 0FFF A#09B\"\n");
printf("in \"a.txt\" at position 80 overstrike [CR,LF]: \"xins a.txt 80 #13#10\"\n");
exit(0);
}
sscanf(argv[3],"%s",word);
//kick out escape character "#"
for(i=0,j=0;;i++,j++)
{
if(word==0)
{
word[j]=0;
break;
}
ch=word;
if(word==35)
{
ch=(word[i+1]-48)*10+word[i+2]-48;
i+=2;
}
word[j]=ch;
}
//letop: index hex/dec starts with 0/1
if(argv[2][0]==48)
{
if(sscanf(&argv[2][1],"%x",&position)!=1) exit(0);
}
else
{
if(sscanf(argv[2],"%ld",&position)!=1) exit(0);
position--;
}
//overstrike
if((fp=fopen(argv[1],"r+"))==NULL) exit(0);
if(fseek(fp,position,SEEK_SET)!=0) exit(0);
fwrite(word,(size_t)1,(size_t)strlen(word),fp);
fclose(fp);
printf("done\n");
return(0);
}
Post Reply