A catalogue of my books for DOS, “knjige” meaning books, written in C in four days in August
1995. It shows one book at a time: the original title, author and awards, then the Serbian translation, its translator,
publisher and edition, and a note. You can page through the books, sort them by any field, search any field, and print a book.
The books are read from a text file, and this one is my catalogue as I last saved it, in May 1998. It runs here as it did in
DOS, in Serbian, with the English translation of the screen beside it. Click the screen and type, or use the buttons.
Keys:
The DOS screen
In English
The printer
O prints the book on the screen to stdprn, the printer, after asking if it is completely ready; D is
“da”, yes. Each book ends with a form feed, a new page, which a comment in the code calls “desirable for
InkJet and Laser (thanks to Magda)”. Magda is Davor Magdić.
Nothing printed yet.
The database
The books are in BAZA.KNJ, a text file: @ and a book's number, then one line
for each field, #1 to #E. The help screen (U) explains it, with the limits.
The bugs, and the fixes
Search, End, then Next hung it. After a search, End went to the position of the last of all the books, 158,
instead of the last one found. Previous from there showed books that weren't found, and Next looked for a book past
the list, which isn't in the file, and at the end of the file the loop that reads a book's number never ends.
Sorting by the note (E) lost most of the books. The sort reads the first four characters of the field, even past
the end of its line. The note is the last field, so when it was empty, those four characters included the next
book's @ and number, and that book was sorted under the number before it. Paging through, only 9 of the
158 books appear.
The 15th time you went back to all the books, it quit with “FATALNA GRESKA : ne mogu da otvorim
fajl baze!” (can't open the database file). Going back opened the file again without closing it, and Borland C
has 20 files open at most, five of them taken from the start.
PRVI !, ZADNJI! and NEMA ! (first, last, none found) were printed and at once covered by the redrawn screen, so
only the beep was left.
A search lost the sort: the books found came in the order of the file, though a comment says the sort should win.
The sort wrote past its memory. It asked for 2 bytes a book, the size of a pointer, instead of the 7 its records
take. With 158 books that ran into memory nothing else was using, but the comment at the top says bugs appeared after a
sort when the limit was 9,999 books, and this may have been why. It also took that memory before asking which field,
and kept it if you pressed Esc. The page doesn't simulate DOS memory, so neither of these shows here.
Smaller ones: char sort[1] is written at sort[1], one past its end; and the help says F1 is the
same as [H], where the key is [U].
Fixed corrects the first five. The port was checked against the original C, compiled with a simulated DOS
screen, keyboard and printer: in 280 sessions, on this database and on a made-up one with every field at and past its
limits, it shows the same screens, beeps, printouts and hangs.