home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!rutgers!cmcl2!panix!mfikes
- From: mfikes@panix.com (Michael Fikes)
- Newsgroups: comp.lang.ada
- Subject: Problems with Temporary Internal Files
- Summary: Temporary Internal Files creating lost allocation chains
- Keywords: Ada, temporary internal file
- Message-ID: <1992Jul29.230837.10518@panix.com>
- Date: 29 Jul 92 23:08:37 GMT
- Organization: PANIX Public Access Unix, NYC
- Lines: 79
-
-
- I am having problems with temporary internal files. Whenever I make
- use of one in an Ada program, I end up with lost allocation units on
- my disk. What I want to know is: Is there something I'm doing wrong,
- or, is it the compiler I'm using?
-
- I've provided a sample program below that will produce the lost
- allocation unit chain each time it is executed. I'm using Meridian
- Open Ada v4.1.1 and DOS 5.0. I have tried this program on one other
- computer with exactly the same result.
-
- The program simply loads in a pre-existing text file, DATA.TXT, copies it
- to a temporary internal file, changing lower case characters to upper
- case in the process, and then overwrites DATA.TXT with the contents
- of the temporary internal file.
-
- After executing the program, chkdsk /f, will report a lost allocation
- unit chain and allow me to convert it to a file. If I look at the
- file that is produced (file0000.chk), it will contain what appears
- to have been the contents of the temporary internal file, namely DATA.TXT
- converted to upper case, followed by a stream of garbage characters.
- If I look at DATA.TXT, it will have been successfully converted to upper
- case.
-
- I hope this program is not doing anything more damaging than creating
- lost allocation chains. :-( I would like to know if I'm closing files
- in the wrong order, or violating some other rule. I'm pretty new to
- Ada. Well, here it is; have at it:
-
- with Text_IO; use Text_IO;
- procedure Upper_Case is
- Data_File : File_Type;
- Temp_File : File_Type;
- Buffer : Character;
- ASCII_Shift : constant INTEGER
- := Character'Pos ('a') - Character'Pos ('A');
- begin
-
- -- First, copy DATA.TXT to an internal
- -- temporary file, changing lower case
- -- characters to upper case as they are copied.
-
- Open (Data_File, In_File, "DATA.TXT");
- Create (Temp_File);
- loop
- exit when End_Of_File (Data_File);
- loop
- exit when End_Of_Line (Data_File);
- Get (Data_File, Buffer);
- if Buffer in 'a' .. 'z' then
- Buffer := Character'Val ( Character'Pos (Buffer) - ASCII_Shift );
- end if;
- Put (Temp_File, Buffer);
- end loop;
- Skip_Line (Data_File);
- New_Line (Temp_File);
- end loop;
- Close (Data_File);
-
- -- Next, simply copy the contents of the internal
- -- temporary file back to DATA.TXT.
-
- Create (Data_File, Out_File, "DATA.TXT");
- Reset (Temp_File, In_File);
- loop
- exit when End_Of_File (Temp_File);
- loop
- exit when End_Of_Line (Temp_File);
- Get (Temp_File, Buffer);
- Put (Data_File, Buffer);
- end loop;
- Skip_Line (Temp_File);
- New_Line (Data_File);
- end loop;
- Close (Data_File);
- Close (Temp_File);
- end Upper_Case;
- --
- Michael Fikes mfikes@panix.com PANIX Public Access Unix, NYC
-