Infsect is an INF/INI file manipulation utility for the command line. It has a number of advantages over some other INI editors, such as the ability to use the program itself to prompt for input when executed in a batch script.
While derived from a Bash script in the original incarnation of Hierma, it is a total rewrite in the C language, easily making it around 20x faster. Its original goal was to be a part of a new, DOS-based Hierma, but that has not made any progress since this program was first written.
Finally, after 19 months, the next version is here... it took me way longer than I would've liked it to. For most of that time, development was completely inactive, as I had turned my attention to other things, including spending three months developing The First Cell. Infsect has gone through yet another major restructuring, which I began work on earlier in 2023 but only now managed to finish.
The serious restructuring of the program allowed me to finally implement a new feature I had always been intending to throw in, and that's the ability to take many lines of arguments from a batch script! The usage of that is described further below in the main page. This feature is potentially useful as it could greatly speed up operations when you have a lot to do on a single file, as multiple read/write operations are performed in a memory buffer and the file is only written once after the batch script completes. Batch mode was implemented primarily to better position Infsect for use in a new version of Hierma, a project which had not been updated since 2019 (and make it at least 20x faster than it is now, no exaggeration).
As this new version uses double buffering of files whenever it needs to perform a write operation, the MS-DOS version has an inherent limitation, being a 16-bit program and all. Currently, it can only work with files up to 32KB in size, as there is no mechanism in place right now to handle more than one memory segment. I have plans to get around this limitation in a future version... as soon as I can learn how to handle memory segmentation in C. The DOS program will try to break out if it finds a buffer is going to exceed 32KB in size to avoid a crash. The Win32 version and any other 32-bit or 64-bit targets you may compile Infsect for do not have this limitation.
It's also worth noting that I reverted to Visual C++ 1.5 for compiling the DOS build. I may consider IA16-GCC again at a later point, but it seems to have been pretty slow compared to VC with the new buffering procedure in place.
If you have implemented Infsect in the past, you should check the guide again for a quick brushup, as its behavior has changed considerably to take Hierma into account. For example, Infsect now strips out quote marks when retrieving a value if it is surrounded by them.
Download Infsect 0.8 (MS-DOS, 17.2 KB)
Download Infsect 0.8 (Win32, 36 KB)
Download source code (9.2 KB)
System Recommendations and Running
The supplied MS-DOS executable is compiled to run on anything as low as the Intel 8088 CPU, found in IBM XTs. It is recommended that you use MS-DOS 3.30 or later, and have 256KB of RAM or more. The Win32 executable requires Windows 95, Windows NT, or later, and is absolutely necessary for 64-bit versions of Windows.
Infsect should be highly portable to other operating systems as it only requires standard C libraries. To compile this program for something like Linux, all you need to do is run a command like this (assuming you have GCC installed):
gcc main.c -o ~/opt/bin/infsect
The -o switch followed by a path generates an executable named infsect located at opt/bin in your home directory. Make sure infsect.h is present in the same directory as main.c.
If you need to run Infsect under DOS, keep in mind that you'll be limited to working with files up to approximately 32KB in size due to inherent memory limitations. If you need to work with larger files and are working with a 32-bit or 64-bit version of Windows, get the Win32 build. Getting around existing file size limitations in DOS is planned for a future release.
How to Use
If you type infsect -h (or no switches at all), this message is displayed:
INFSECT Usage: infsect [file] -s [section] [-g | -d | -i ] [field | field=value] [-a | -r] infsect [file] -l | infsect [file] -k [section] infsect [file] -b [batch_file] [ -4 | -5 ] General switches: -s Section name (use without any other args to print) -g Read or write field value (trail with =value to write) -d Delete a field -i Interactive prompt to input value -j Interactive input character limit (used with -i, default 128) -4 | -5 Force REGEDIT version 4/5 header (used with REG files) -a | -r Append/remove subvalue (used with -g) -u | -w Force UNIX or DOS/Windows line format Alternate switches: -l List all sections -k Delete a section -b Batch file containing lines of arguments Program information: -h Display this usage reference -v Display program version
Use of this program requires at least some understanding of the structure of INI/INF files or anything else this covers. As for how this program is used, it would be best to look at some examples...
We'll use this sample file to experiment with the tool:
[version] Signature = "$CHICAGO$" SetupClass = BASE [SectionOther] FamilyValues = NO ; Comment ;Ignore = YES DoNotIgnore = huh?, UNACCEPTABLE [Section] Value = Value1 Quote = "C:\WINDOWS\INF;C:\WINDOWS\OPTIONS\CABS" [OtherSection] Value = Value2 Which = C:\WINDOWS [Lousy] Standalone
When you're dealing with large files comprised of many sections, it may help to narrow your output using Infsect instead of piping the TYPE command to MORE. You can use the -l switch to list all of the sections found in a file:
infsect test.inf -l
And you get:
version SectionOther Section OtherSection Lousy
Using the -s without any additional arguments will print the contents of the specified section to the screen.
infsect test.inf -s OtherSection
Value = Value2 Which = C:\WINDOWS
Retrieve a value
Here, I want to retrieve the value stored in the field Value at [Section]. To do this, I type:
infsect test.inf -s section -g value
and this is returned to standard output:
Note that Infsect is not case sensitive when it comes to specifying the names of sections or fields, respecting the case insensitive nature of Windows. As such, you can type a section name in all lowercase letters even if it uses title casing.
If you were to try to retrive the value from the field Ignore in [SectionOther], it would not be picked up because the field is cancelled out by a semicolon comment marker.
If a field contains a value surrounded by quote marks, the quote marks are not returned alongside the value.
infsect test.inf -s section -g quote
This change in behavior was introduced in version 0.8 for the purpose of making the output fit more comfortably into, say, a variable to be stored in the execution of a shell script in a Unix-like environment.
Assign a new value
To put a new value in a field, the same -g switch is used, but this time the field name is immediately followed by an equals symbol (=). This tells the program you intend to overwrite an existing field with a new value, or create a new field.
To create a new field NewVal storing the value Purplefish, you would type:
infsect test.inf -s section -g NewVal=Purplefish
If you check the file now, [Section] will look something like this:
[Section] NewVal=Purplefish Value = Value1 Quote = "C:\WINDOWS\INF;C:\WINDOWS\OPTIONS\CABS"
To overwrite the value in Value with BrandNew, type:
infsect test.inf -s section -g value=BrandNew
and the section will look like this:
[Section] NewVal=Purplefish value=BrandNew Quote = "C:\WINDOWS\INF;C:\WINDOWS\OPTIONS\CABS"
Note that while it knows to overwrite Value in title casing even when typing value in lowercase, Infsect also changes the casing of the field name to what the user specifies. Also keep in mind that there must be NO whitespace surrounding the equals sign.
To enter a value with spaces surrounded by quote marks, you type:
infsect test.inf -s section -g Value="\"Brand New\""
\" is an escape character for a literal quote mark. The two escape quotes should be sandwiched inside the outermost standalone quote marks, which are used to actually tell the program you're writing a single argument. You can also write the command like this if desired (this is the required approach in DOS and Win32):
infsect test.inf -s section -g "Value=\"Brand New\""
Using escaped quote marks on the outside is not necessary if you're specifying a default value for the -i switch, as that will take care of it automatically.
Depending on your command line environment, there are other kinds of characters which you may need to escape with a backslash. If you're writing a batch script, test your commands to make sure they return the intended results.
You can also create a new section by adding a field to it, like this:
infsect test.inf -s newsect -g twest=ok
Prompt user to assign new value
Instead of dealing with extra programs like PUTINENV, you can tell Infsect to prompt the user for a value to assign when you call the program from a batch script. You can type something like this:
infsect test.inf -s section -i Value
When run this way, the user is given the above message and must type a new value themselves before proceeding.
If the user inputs egg, that becomes the new value of Value. If no value is entered, the existing one remains unaffected. If you want to use a default value when the user enters nothing, you'd type something like this:
infsect test.inf -s section -i Value=salad
This ensures that the value salad will be entered if the user doesn't input anything.
You can also limit the number of characters a user can input interactively with the -j switch:
infsect test.inf -s section -i Value=salad -j 10
Value2 (default salad, limit 10):
Excess characters from user input to stdin will be cut off.
Delete a field
To delete a field outright, replace -g with -d followed by the field name, like this:
infsect test.inf -s section -d Value
Delete a section
To delete an entire section from a file, replace the -s switch with -k:
infsect test.inf -k section
Infsect has the ability to work with comma-terminated subvalues in a field. Dealing with subvalues is common in Windows 95-style INF scripts used for installation procedures. While a normal write operation is perfectly fine for defining all of the subvalues you want to write at once to a field, it is inflexible if you are wanting to do this from a batch script where the subvalues that need to be applied may vary greatly depending on a user's choices.
Infsect has append and remove modes designed to resolve this shortcoming. By adding the -a switch, you can append a subvalue to a field without affecting the other subvalues. If the new subvalue is not already in the field, it is added to the end of the entire value after a comma. If the new subvalue already exists, it is not duplicated, but it is also moved to the end of the line nonetheless.
Using the -r switch, you can remove a subvalue from a field. If the subvalue does not exist in the field, the other subvalues remain unaffected. Also, when appending or removing subvalues, Infsect automatically cuts off any leading and/or trailing whitespace around every subvalue when performing a write operation, so as to lean down on the file size just a bit.
In the above sample INF file, there is a field labeled DoNotIgnore at the section SectionOther. It contains two subvalues, one being huh? and another being UNACCEPTABLE. Let's add a third subvalue to this with the following command:
infsect test.inf -s sectionother -g DoNotIgnore=okay -a
Note the use of that -a switch at the end; this will activate the append mode. Using this switch, the value of DoNotIgnore is not overwritten with okay, but is added to the end of the existing value instead, like this:
The excess whitespace is trimmed off from the subvalues, and the new subvalue okay appears next to those preceding it. If the field specified does not exist in a section, Infsect will create it and add the new subvalue to it as if you were performing a normal write operation.
Note that if a subvalue already exists in a field, the new subvalue is not added.
Now, we shall remove the subvalue UNACCEPTABLE from the field:
infsect test.inf -s sectionother -g DoNotIgnore=UNACCEPTABLE -r
And you get:
Modifying Registry Scripts
Because .REG scripts share a very similar syntax to INI/INF files, Infsect can be used to modify such registry editor scripts. When you modify a file with a .REG extension, Infsect automatically knows to give the file special treatment, which is really nothing more than being mindful to apply a version header to the top of the file.
Using the -4 or -5 switches, you can change the registry editor version header on the fly with any write operation. If you are creating a new registry script, Infsect defaults to using the REGEDIT4 header used by Windows 95, 98, ME, and NT 4.0. If you plan to work with systems running Windows 2000 or later, it's best to apply the -5 switch every time you want to create or modify a registry script, though Infsect will leave an existing registry version header untouched if it already exists.
Even though the syntax is technically the same otherwise, you should be mindful that the Registry Editor in Windows always surrounds field names in quote marks, as well as values if they are strings (binary values are not encapsulated in quotes). You'll need to employ some escaped quotes and possibly escaped backslashes (that is, precede such characters with a backslash). You'd have to write a command like this:
infsect test.reg -s HKEY_LOCAL_MACHINE\USERS\.DEFAULT -g \"OkayProcedure\"=\"1\"
Depending on the shell you're working with (or maybe just how the program was compiled), you may need to use double backslashes; this is definitely the case when compiling Infsect using GCC and running it under Bash. However, double backslashes may be taken literally in the MS-DOS or Windows command prompts. I hope I can fix this inconsistency in a future release, but in the offchance you are writing a script designed to be run under Linux, you might consider surrounding static values with single quote marks to avoid the need for double backslashes.
The Two Line Break Styles
Internally, Infsect doesn't care which line break format a file uses; it happily accepts both CRLF (DOS/Windows) and LF (Unix). When Infsect buffers a file, it stores it in the LF format. Then, when it needs to write to the file, it checks a bit to determine whether to use CRLF or LF. On Unix/Linux, it will use LF by default, while DOS and Win32 builds use CRLF by default. You can override this with your own desired line break format by adding the switch -u to force the use of LF or -w to force the use of CRLF.
If CRLF is to be used, Infsect performs an additional buffer write for the conversion to add a CR character before every LF. While LF is a lot more sane as it takes one byte instead of two, CRLF is necessary if you need to modify files used by DOS or Windows programs. Inversely, various programs running in some sort of Unix environment often expect files to be stored in the LF format, and may undesirably treat CR as if it's part of a string.
If an existing file is already being worked on, adding either switch is not necessary unless you need to enforce a line format for a target platform with certainty. Infsect should respect the line format of an existing file unless one is explicitly specified on execution.
To convert a CRLF file to LF in a write, you'd run a command like this:
infsect test.inf -s OtherSection -g Destination=Nowhere -u
And vice versa:
infsect test.inf -s OtherSection -g Destination=Somewhere -w
If you're creating a batch script for Infsect to process, either of the two switches should be set in the first line. This setting will be retained for any successive lines in the batch script.
A new feature for Infsect version 0.8 is the ability to read a long list of arguments from a plain text file, so as to efficiently perform many operations on the same file. This is primarily useful in cases where you have to modify a ton of lines in a file. Arguments are placed in a text file in much the same way as you would write them when executing the program normally, with some exceptions.
To give you an idea, here is what a batch script for Infsect looks like:
-w -s Version -g signature="$CHICAGO$" -s Version -g class=BASE -s Version -g garbage=remove -s version -g LayoutFile=LAYOUT.INF -s Optional2 -g param=01,00 ;-s Optional2 -g param=02 -a ;-s Optional2 -g param=00 -r -s Optional2 -g nextLine=this -s Optional2 -s Optional2 -g param -s Optional -g param=01,00 -s Optional -g param=02 -a -s Optional -g param=00 -r -s Optional -g nextLine=this ; Interactive input -s Optional -i param=03 -j 4 -a -s Optional -i param -j 4 -a -k Optional2 -s version -d garbage -s version -g new=thing ; Attempt another deletion of a now nonexistent field -s version -d garbage
The first thing you should see is that only the arguments that take place after the program and file name are written. Every line must begin with a hyphen, otherwise it will not be processed at all. You can organize your batch script with comments in much the same way as INI files themselves.
The arguments following the filename can be written in much the same way as in the command line, except the line format switch needs to be in the first line of the program, and you cannot use a registry header switch. That still has to be set at the command line.
To run a batch script on a file, you can simply type this, assuming the batch script is saved as batch.txt:
infsect test.inf -b batch.txt
To enforce a version 5 header on a registry script you're running a batch on, type this:
infsect test.reg -b batch.txt -5
Now that Infsect is loaded up with plenty more features, it is in a prime position to be integrated into Hierma. The primary focus of its future releases will be to make it adapt to the needs of Hierma. As mentioned before, I also hope to overcome the current 32KB file size limitation for the DOS build.
Otherwise, it is now in a position where it should be reliable and useful for anyone pressed to modify INI-style files from within their batch scripts. As more needs arise, it should continue to improve on its flexibility to make up for the limited capabilities of MS-DOS and its narrow selection of utilities.