home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / ada / 2233 < prev    next >
Encoding:
Internet Message Format  |  1992-07-29  |  3.2 KB

  1. Path: sparky!uunet!sun-barr!rutgers!cmcl2!panix!mfikes
  2. From: mfikes@panix.com (Michael Fikes)
  3. Newsgroups: comp.lang.ada
  4. Subject: Problems with Temporary Internal Files
  5. Summary: Temporary Internal Files creating lost allocation chains
  6. Keywords: Ada, temporary internal file
  7. Message-ID: <1992Jul29.230837.10518@panix.com>
  8. Date: 29 Jul 92 23:08:37 GMT
  9. Organization: PANIX Public Access Unix, NYC
  10. Lines: 79
  11.  
  12.  
  13. I am having problems with temporary internal files.  Whenever I make
  14. use of one in an Ada program, I end up with lost allocation units on
  15. my disk.  What I want to know is:  Is there something I'm doing wrong,
  16. or, is it the compiler I'm using?
  17.  
  18. I've provided a sample program below that will produce the lost 
  19. allocation unit chain each time it is executed.  I'm using Meridian
  20. Open Ada v4.1.1 and DOS 5.0.  I have tried this program on one other
  21. computer with exactly the same result.  
  22.  
  23. The program simply loads in a pre-existing text file, DATA.TXT, copies it 
  24. to a temporary internal file, changing lower case characters to upper
  25. case in the process, and then overwrites DATA.TXT with the contents
  26. of the temporary internal file.
  27.  
  28. After executing the program, chkdsk /f, will report a lost allocation
  29. unit chain and allow me to convert it to a file.  If I look at the
  30. file that is produced (file0000.chk), it will contain what appears
  31. to have been the contents of the temporary internal file, namely DATA.TXT
  32. converted to upper case, followed by a stream of garbage characters.
  33. If I look at DATA.TXT, it will have been successfully converted to upper
  34. case.
  35.  
  36. I hope this program is not doing anything more damaging than creating
  37. lost allocation chains.  :-(  I would like to know if I'm closing files
  38. in the wrong order, or violating some other rule.  I'm pretty new to 
  39. Ada.  Well, here it is; have at it:
  40.  
  41. with Text_IO; use Text_IO;
  42. procedure Upper_Case is
  43.    Data_File   : File_Type;
  44.    Temp_File   : File_Type;
  45.    Buffer      : Character;
  46.    ASCII_Shift : constant INTEGER
  47.            := Character'Pos ('a') - Character'Pos ('A');
  48. begin
  49.  
  50. --                            First, copy DATA.TXT to an internal
  51. --                            temporary file, changing lower case
  52. --                            characters to upper case as they are copied.
  53.  
  54.    Open (Data_File, In_File, "DATA.TXT");
  55.    Create (Temp_File);
  56.    loop
  57.       exit when End_Of_File (Data_File);
  58.       loop
  59.       exit when End_Of_Line (Data_File);
  60.       Get (Data_File, Buffer);
  61.       if Buffer in 'a' .. 'z' then
  62.          Buffer := Character'Val ( Character'Pos (Buffer) - ASCII_Shift );
  63.       end if;
  64.       Put (Temp_File, Buffer);
  65.       end loop;
  66.       Skip_Line (Data_File);
  67.       New_Line (Temp_File);
  68.    end loop;
  69.    Close (Data_File);
  70.  
  71. --                            Next, simply copy the contents of the internal
  72. --                            temporary file back to DATA.TXT.
  73.  
  74.    Create (Data_File, Out_File, "DATA.TXT");
  75.    Reset (Temp_File, In_File);
  76.    loop
  77.       exit when End_Of_File (Temp_File);
  78.       loop
  79.       exit when End_Of_Line (Temp_File);
  80.       Get (Temp_File, Buffer);
  81.       Put (Data_File, Buffer);
  82.       end loop;
  83.       Skip_Line (Temp_File);
  84.       New_Line (Data_File);
  85.    end loop;
  86.    Close (Data_File);
  87.    Close (Temp_File);
  88. end Upper_Case;
  89. -- 
  90. Michael Fikes    mfikes@panix.com    PANIX Public Access Unix, NYC
  91.