Resource Index

Quick Links

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.

Version 0.4

As I've been using Infsect more frequently in the automation of various routines involving INI and INF files, it needs to grow more flexible and resilient. Starting with this version, one very significant change has been made to how Infsect modifies files: rather than creating a temporary scratch file, Infsect stores the write buffer directly in memory, and then dumps it over the existing file. This fixes the problem of some writes in MS-DOS failing completely.

Depending on the file size, this means Infsect may require more memory, but memory allocation has been reworked to compensate for this, so the program doesn't take up so many giant 128 byte or 4KB chunks. Plus, most of the files you'll probably be using this with will be well under 64KB in size, anyway.

This version also includes a number of new features, like being able to list every section in an INF file and listing the contents of an entire section to console output. It's also better at handling user input when run interactively; when Infsect is called with the -i switch and the user inputs a value with one or more spaces, Infsect surrounds the value in quote marks when writing to a file. This ensures the spaces will be included when the setup engine in Windows 9x reads the file in question. You can also use the -j switch to limit the number of characters allowed in interactive input.

As usual, a number of bugs have also been fixed with this version. I plan to add yet more features down the road to make this program yet more useful for batch programmers working with INI and INF files. Once it has everything I want in there, I may want to try incorporating it into the long dead Hierma project and see how much faster it actually runs.

Floppy disk Download Infsect 0.4 (MS-DOS, 16.6 KB)

Floppy disk Download Infsect 0.4 (Win32, 32 KB)

Floppy disk Download source code (5.5 KB)

View change log

Version 0.3

This is a bugfix release, making the program more usable on Unix/Linux as well as in DOS/Win32. It also raises some arbitrary limits that the previous version of Infsect suffered from, particularly the file name length.

Note that if you use Infsect on a CRLF file in a Unix environment, CRLFs will be converted to LFs by this program, so remember to use unix2dos to convert them back to the native line break format used by DOS and Windows if you intend to use your INFs there.

Version 0.2

Once again, Infsect is completely rewritten, this time with a modest DOS-first approach. The fundamental problem with the last version was that it was trying to do too much all at once right from the start, all for a larger thing that never took off. After being tested in both MS-DOS and Win32, Infsect 0.2 should be better suited as a standalone utility for certain routines. It promises less functionality than the last version, but hey, at least it works now.

Knowing that not very many people are going to end up using this as I previously imagined, I ditched the GPL for it and released every bit of it into the public domain, so it can be used and modified without any restrictions.

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.

How to Use

If you type infsect -h (or no switches at all), this message is displayed:

 infsect [file] -s [section] [-g | -d] [field | field=value]
 infsect [file] -s [section] -i [field | field=value] [-j limit]
 infsect [file] -l
 infsect [file] -k [section]

General switches:
	[file]		Name of file
	-s		Section name
	-g		Read or write field value (trail with =value to write)
	-d		Delete a field
	-i		Interactive prompt to input value
	-j		Character limit for interactive input

Use -s without any further arguments to print an entire section.

Alternate switches:
	-l		List all sections
	-k		Delete a section

Program information:
	-h		Display this usage reference
	-v		Display program version

Use of this program requires at least some understanding of the structure of 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:

Signature	= "$CHICAGO$"
SetupClass	= BASE

FamilyValues	= NO	; Comment
;Ignore		= YES
DoNotIgnore	= huh?, UNACCEPTABLE

Value		= Value1

Value		= Value2
Which		= C:\WINDOWS


Listing Sections

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:


Using the -s without any additional arguments will print the contents of the specified section to the screen.

infsect test.inf -s OtherSection

Will return:

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. [1]

If a field contains a value surrounded by quote marks, the quote marks are returned alongside the value.

infsect test.inf -s section -g quote

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:

NewVal = Purplefish
Value		= Value1

To overwrite the value in Value with BrandNew, type:

infsect test.inf -s section -g value=BrandNew

and the section will look like this:

NewVal = Purplefish
value = BrandNew

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:

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.

Value: egg

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

What's Next?

Obviously, Infsect has to get back up to par with what it was earlier. The "start small" approach worked very well and may be enough for most people, but just in case, I might want to add more things to it like the ability to manipulate subvalues within values later on when I get the time.

Now that Infsect is in a decent position, it'll also allow me to bring about a really cool guide in the future which will need this program. Beyond that, it's not much, but it's a small victory in the way of getting myself into the kind of programming I want to do.


1 Currently, Infsect does not actually skip comments. This will be addressed in a future release.