I was instructed to write a data collection program for Unitech HT630 , which runs its own DOS operating system, which can run executable files compiled for 16-bit MS DOS with some restrictions. I am using the Digital Mars C / C ++ compiler, which still works.
One of the requirements of the application is that the data file should be easy to read by a person, which means that the file can be imported into Excel or Notepad is opened. I am using a variable-length recording format similar to CSV, which I have successfully implemented using the file input / output functions of the standard C library.
When saving a record, I must calculate whether the updated record is larger or smaller than the version of the record currently in the data file. If more, I will first change all records immediately after the current record forward with the difference of the difference calculated before saving the updated record. EOF automatically expands the OS to accommodate additional data. If less, I shift all records backward at my calculated offset. This works well, however, I did not find a way to change the EOF token or file size to ignore data after the last write.
Most time records will grow in size because the data collection program will populate some of the empty fields with data when the record is saved. Records will be reduced only if the correction is made in an existing record or while maintaining a normal record, if the descriptive data in the record is greater than what the program reads in memory.
In the situation of reducing the record, after the last record in the file, I remain with what data was there before the shift. I wrote the EOF delimiter to the file after “shortening the record” to signal where my records end and fill in the blanks with the remaining data, but then I no longer have a clean file until the “growing record saves” expand the file size over the space filled a space. The truncate() function in unistd.h does not work (now I think it is only for * nix accessories?).
One suggested solution that I saw involves creating a second file and writing all the data you want to save to that file, and then deleting the original. Since I only have 4 MB of disk space, this works if the file size is less than 2 MB minus the size of executable files and program configuration files, but will not work otherwise. It is very likely that when this happens, users will receive a file larger than 2 MB.
I looked through the Ralph Brown interrupt list and the interrupt link in the IBM PC Assembly Language and Programming , and I cannot find anything to update the file size or similar.
Reduces file size without creating a second file in DOS?