INI File Tidier INI File Tidier
home Student Projects no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
This essay is about a suggested student project in Java programming. This essay gives a rough overview of how it might work. It does not describe an actual complete program. I have no source, object, specifications, file layouts or anything else useful to implementing this project. Everything I have to say to help you with this project is written below. I am not prepared to help you implement it; I have too many other projects of my own.

I do contract work for a living, which could include writing a program such as this. However, I don’t do people’s homework for them. That just robs them of an education.

You have my full permission to implement this project any way you please.

Windows 9x/NT still use INI files in addition to the registry. A *.INI file has [sections], parameters and comments:
[USER PREFS]
HOME URL=D:\mydir\index.html
; this is a comment on a line by itself
MAX WINDOW HISTORY LINES=100 ; this is a tail end comment
The task of your program is to sort all the sections in alphabetical order, and within each section sort all the parameters in order. Any sections without any entries are deleted. There may be duplicate sections in the orignal. Merge them. When there are duplicate parameters in a section, take the first one and ignore the rest. Delete any parameters with null values. For readability, put a blank line between sections.

The only thing tricky about this is handling comments. Does a comment belong with the parameter/section above or below? If there is a blank line separating it from one but not the other, the answer in obvious. If the comment is the first or last line of the file, again the answer is obvious. If you can’t resolve what to do with the comment you can handle the ambiguity in one of four configurable ways:

  1. Get the user to resolve the ambiguity by inserting a blank line, then rerunning your program.
  2. Assume it belongs to the line above.
  3. Assume it belongs to the line below.
  4. Assume it belongs to both, and duplicate the comment.
By configurable, I mean the user makes this choice ahead of time. You don’t ask the user on every comment. Or you could just say, screw-em, and insist that comments belong to the line following and end of line comments belong to that line.

You could do the sorting and merging of duplicates in at least three ways:

  1. Create one giant array with cleverly constructed keys and sort it. Then merge.
  2. Create an array of arrays with variable length rows. Sort the rows then sort each column. Then merge. You may need two or more passes through the data to find out how big to make the rows and columns.
  3. Create a tree — binary, BTree or n-ary. As you build the tree, keep it in order and merge duplicates.
Since INI files are not that large, you can use totally RAM-resident techniques, and you don’t have to worry too much about the efficiency of your algorithm in terms of order(n).

Once you have that working, you can then create variants on a theme. Merge a small ini file of changes into a big one. Setting a parameter to nothing deletes the parameter. A section with no entries is deleted.

Compare two messy ini files and display the essential differences by creating a tidied, comment-less version of both and comparing the parse trees in RAM.

Get your friends to donate a variety of real-life messy INI files, the dirtier the better, for you to test your program on.

Once you have that working, create this variant. You create a template example ini file that contains all the currently legal sections and fields. You use that model to clean out a messy INI file that is full of junk fields left over from previous versions of the program.

I have implemented this project myself and you can dhowload my source code.

Sort
ini


CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.18] The information on this page is for non-military use only.
You are visitor number 4,113. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/project/inifiletidier.html J:\mindprod\project\inifiletidier.html