Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? SafeChars.dll question

May
3,515
5
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.
 
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?
 
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
 
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...
 
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

Back
Top