Freelance software grandad
software created
extended or repaired
Follow me on Mastodon
Applications, Libraries, Code
Talks & Presentations
STinC++ rewrites the programs in Software Tools in Pascal using C++
And so, my friends, we’re into the final stretch of chapter 3. Chapter 3 broadly follows the pattern of its predecessors - presenting several small programs exploring various aspects of the matter under examination, before pulling the threads together into a slightly larger program. This chapter is all about files and file handling - opening files, reading their contents, creating and writing new files - and the last program of the chapter brings all that together in archive
, a file archiving utility not unlike tar
or cpio
.
PROGRAM |
|
USAGE |
|
FUNCTION |
In each case, the "named members" are the zero or more filenames given as arguments following The The create command An archive is a concatentation of zero or more entities, each consisting of a header and an exact copy of the original file. The header format is |
EXAMPLE |
To replace two files in an existing archive, add a new one, then print the table of contents: |
archive -u archfile old1 old2 new1 archive -t archfile |
It is, frankly, a bit of beast. The discussion of archive
takes as many pages as does all the preceding programs in the chapter. I suspect I’ll probably end up with a similar ratio, but rather than write one monstrous great article (which would be tiring and, frankly, dispiriting for all of us) I’m going to take the excellent advice Kernighan and Plauger give at the start of the section.
The archive program is a natural for what we like to call "left-corner" construction. The idea is to nibble off a small, manageable corner of the program - a part that does something useful - and make that work. Once it does, more and more pieces are added until the whole thing is done. If care is taken with the original design, later pieces should fit in relatively smoothly. Debugging and testing are easier, for the pieces are only added one at a time. Furthermore, if you decide to scrap the whole thing at some point, you are scrapping only that fraction built so far.
They continue …
The beauty of left-corner construction is that the progam does some part of its job very early in the game. By implementing the most useful functions first, you get an idea of how valuable the program will be before investing any time in the difficult or esoteric services (which often prove to be unnecessary or unwanted anyway). You also ensure that the simpler and more common functions are handled simply, which leads to greater efficiency in the end.
Again, Software Tools in Pascal was written in the 1970s and published in 1981. Collectively it took us another twenty years for this kind of thing to become remotely mainstream, and even now there are people who’ll tell you this kind of incremental development, focusing on software that actually does stuff, is dangerous nonsense and what we really need is more design documents and planning meetings.
So anyway, I guess it makes sense to start with -c
create an archive. Join me again tomorrow - same C++ time, same C++ channel - as I dive in and have a go.
Freelance software grandad
software created
extended or repaired
Follow me on Mastodon
Applications, Libraries, Code
Talks & Presentations