image provider

INI File Tidier


Disclaimer

This essay does not describe an existing computer program, just one that should exist. This essay is about a suggested student project in Java programming. This essay gives a rough overview of how it might work. I have no source, object, specifications, file layouts or anything else useful to implementing this project. Everything I have prepared to help you is right here.

This project outline is not like the artificial, tidy little problems you are spoon-fed in school, when all the facts you need are included, nothing extraneous is mentioned, the answer is fully specified, along with hints to nudge you toward a single expected canonical solution. This project is much more like the real world of messy problems where it is up to you to fully the define the end point, or a series of ever more difficult versions of this project and research the information yourself to solve them.

Everything I have to say to help you with this project is written below. I am not prepared to help you implement it; or give you any additional materials. I have too many other projects of my own.

Though I am a programmer by profession, 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 in any way you please and to keep all the profits from your endeavour.

Please do not email me about this project without reading the disclaimer above.

Windows 9x/NT still use INI files in addition to the registry. A *.INI file has [sections], parameters and comments:

; sample ini file
[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 (Random Access Memory).

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 download my source code.

ini
Sort

This page is posted
on the web at:

http://mindprod.com/project/inifiletidier.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\project\inifiletidier.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[54.163.218.81]
You are visitor number