How to? SafeChars.dll question

May 20, 2008
3,515
4
Elkridge, MD, USA
Charles:

I would appreciate help with the problem below.

I have dynamically created pure ASCII files I try to analyze. The file is styled like a configuration file of sections and entries, but typically it has many entries with the same name in a section, so I cannot use the @iniread function [OT: Rex has long ago refused my request to extend @iniread to support this style, very common before the days of WinAPI calls for reading and writing configuration files, and still common on non-Windows platforms]. Some of the lines contain unsafe characters, thus processing them in a TCC batch program results in error messages. My batch program tries to locate and process all entries with the keyword "file" in a specific section (never the first). It processes each line of the file using the "DO line in @file" syntax; ignores every line until it detects the line containing the section name; then it processes every line until EOF or a line that does not start with "file=".

I tried to insert "set line=%@safeexp[line]" immediately after DO to avoid error messages; now I can no longer detect the section title line, even after I switched from direct comparison to trying to match "%safeline" with %@safeenv["[section]"].

I suppose I could switch to reading the file into a binary buffer, but that would require processing a character at a time, instead of a line at a time. Using an array is not a real alternative, because each line is still unsafe.

There are only two literal strings that I need to be able to match (section title and entry name), but I could not figure out how to set these matches so that a safed line (or part thereof) could be matched against them using EQC.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,462
88
Albuquerque, NM
prospero.unm.edu
I tried to insert "set line=%@safeexp[line]" immediately after DO to avoid error messages; now I can no longer detect the section title line, even after I switched from direct comparison to trying to match "%safeline" with %@safeenv["[section]"].

Does it work if you make that "set line=%@safeenv[line]" instead of @safeexp?

What is the section title you're trying to match? Does it contain funky characters?
 
May 31, 2008
382
2
I have a batch file that extracts section names and uses safechars.dll - maybe it can help you?
Below DBF is the .ini file
Code:
set tmpf=%@unique["%[TEMP]"]
gosub GETSECTIONS
type "%[tmpf]"
quit
 
:GETSECTIONS
rem SUB: ascending alpha sort DBF section names into "%tmpf%" {{{
*ffind /K /V /M /E"^\s*[[]" "%DBF%" >"%tmpf%"
rem remove surrounding []
(do i in @"%tmpf%" (if "" != "%@SAFEEXP[i]" echo %@left[-1,%@right[-1,%@SAFEEXP[i]]])) >"%tmpf%2"
"%SystemRoot%\system32\sort.exe" "%tmpf%2" /O "%tmpf%"
echo DBF{%@inc[%@lines["%tmpf%"]]} records
return
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Stefano, thanks for your file. It did't run in my environment. I had to eliminate its dependence on NoClobber=No; I just had to replace the redirection of stdout from ">" to ">!". Actually, for the file created by %@unique[] I found it generally to be simplest to just use ">>" instead of ">", appending redirected output, since the file already exists and is empty. {4nt/tcc does that to make sure that a concurrent other instance won't come up with the same name, an excellent method.} After I discovered that DBF must be specified explicitly, it worked well. However, the program is unrelated to my requirement of finding ALL entries with the name "file" in a section of known name "[brief]", when it is guaranteed that the section exists, and that it has at least one entry "file" entry. My issue was that the file may have lines that have parsing issues BEFORE my section of interest...
 
May 31, 2008
382
2
Thank you for your comments about my code, there's always something I can learn.
However, the program is unrelated to my requirement of finding ALL entries with the name "file" in a section of known name "[brief]"...
You're right, I misread your post and thought you had several sections by the same name. Well, you know, in school I must have learned to write before learning to read! :)
 
Similar threads
Thread starter Title Forum Replies Date
M How to? Use SafeChars plugin... Plugins 2
dcantor Error in SAFECHARS plugin v 1.9.0 Plugins 2
thedave SafeChars: Escaped version of @unsafe Plugins 7
M SafeChars plugin misbehaving... Plugins 3
dcantor Suggestion for SafeChars plugin Plugins 7
M Charles, I just installed the "new" SafeChars plugin, ... Plugins 5
Stefano Piccardi SafeChars thank you Plugins 2
M A problem with the SafeChars Plugin... Plugins 30
M A (presumbly pretty simple) SafeChars plugin request... Plugins 2
M A "SafeChars" plugin request... Plugins 2
S SafeChars plugin Plugins 2
Charles Dye New plugin: SafeChars Plugins 15
Joe Caverly November 10 is Thursday? (ISO8601-x64.dll) Plugins 6
Joe Caverly ISO8601-x64.dll and TCC 21 Plugins 5
dcantor 4console64.dll does not load Plugins 8
S Documentation Plugin everything.dll Plugins 5
S How to? Does WAITWIN (in sysutils.dll) detect title change? Plugins 3
Joe Caverly How to? Use exported functions from TakeCmd.dll Plugins 0
S UIstuff.dll enhancements: SCREENRES command Plugins 11
S 4CONSOLE.DLL Plugins 15
S 4console.dll - divide by zero Plugins 0
S CHILL.DLL Plugins 5
S CONSIZE command in Vince's 4console.dll Plugins 3
dcantor 4UTILS.DLL in TCC v11 Plugins 16
S 4autotray.dll Plugins 3
vefatica Tough (?) programming question Plugins 5
vefatica Question about screen buffer handles Plugins 2
vefatica Question for someone with sysutils and Windows 10 Plugins 4
vefatica Question for Rex Plugins 1
Charles Dye SearchPaths() question Plugins 4
vefatica Question for Rex Plugins 0
Charles Dye A weirdoid plugin question Plugins 6
Charles Dye Keystroke plugins question Plugins 7
vefatica A question for Rex Plugins 5
Charles Dye Binary buffers question Plugins 0
M Just a curiosity question related to the "default" set of re-mapped characters... Plugins 2
vefatica Question about Ctrl events Plugins 2
vefatica Generic programming question Plugins 2
vefatica Compiler question Plugins 8
vefatica Plugin keyhandler observation/question Plugins 15
vefatica PLUGININFO question Plugins 9
vefatica Plugin keyhandler question Plugins 1
vefatica Pipe question Plugins 6
vefatica Code page question Plugins 2
vefatica Unicode question (revisited, question for Rex) Plugins 0
vefatica Sprintf question Plugins 1
vefatica Unicode question Plugins 13
vefatica Question about GetToken() Plugins 7
vefatica Plugin question Plugins 3
vefatica Another Sscanf question Plugins 1

Similar threads