1. HELP- with open("ab")

--------------A23D4B41DCE6550F0385724E
Content-Transfer-Encoding: 8bit

I'm having trouble with appending a line of test to an existing text file. The
source is a different file.
The target file is opened in 'append' mode open(fn,"ab"). The new line is
appended with
puts(FileToUpdate,UpdateRecord)

The problem is that an ascii 26 (eof) is present as the first byte of the
appended record, so other software cannot see
the appended record(s).

I think the ascii 26 was there to begin with, since subsequent runs of the
program do not have that code as the first
byte of the appended records, only the 1st run.

Is the a way to get rid of the ascii 26 code, or amd I using thw wrong Euphoria
code to do the open or the append?

Any help will be greatly appreciated.

Program is included with sample input and ouput inserted as comments.

Thanks.

Jim

--------------A23D4B41DCE6550F0385724E
 name="Update.ex"
Content-Disposition: inline;
 filename="Update.ex"

-- update.ex
-- while true do
--    read TODAYS.TXT -- use field 1 (File ID) to select existing history file
--    open named history file
--    append from TODAYS.TXT
-- end while

include file.e
include get.e

with trace
without warning
allow_break(1)

sequence buffer,CodeField,TxtField,String,test,x,YearPart,ReadRecord

integer  DirFile,true,false,RecCount,TotRecs,BOF,EOF,RecLen,OK

object   Record,wait

atom     a,b,c,IsNumeric,z

true     = 1
false    = 0
buffer   = {}
RecCount = 0

-------------------------------------------------------------
--    update daily files with today's data (in TODAYS.TXT. --
------------------------------------------------------------
sequence FileName, Field, WhichFile, UpdateRecord

integer  TodaysData, pos, FieldNo, len1, len2, FilesUpdated

object   char, RestOfRecord, FileToUpdate, input_string, file_id

    -------------------------------------------------
    --  unpack Todays.exe in \CANDLES\DOWNLOAD\    --
    -------------------------------------------------
system("\\CANDLES\\DOWNLOAD\\TODAYS.EXE",2)    -- unpack Todays.TXT

TodaysData = open("\\CANDLES\\DOWNLOAD\\TODAYS.TXT","rb")

if TodaysData = -1 then
   printf(1,"Can't open file \n %s", "TODAYS.TXT")
   abort(1)
end if

----------------------------------------------------------------------------------
-- read TODAYS.TXT and append the current record to the appropriate history file
-
-- format of TODAYS.TXT :
----------------------------------------------------------------------------------
--"AD00U","08/22/2000","   58.92000","   59.05000","   58.80000","   58.92000","
      1815","         18335"
--"AD00Z","08/22/2000","   59.00000","   59.05000","   58.85000","   58.95000","
        32","           660"
--"AD01H","08/22/2000","   58.92000","   59.05000","   58.80000","   58.92000","
      1815","         18335"
--"AD01M","08/22/2000","   58.91000","   58.95000","   58.81000","   58.85000","
         0","             0"
--
------------------------------------------------------
-- Get the name of the history file to be updated   --
-- object #1 of TODAYS.TXT                          --
------------------------------------------------------
-- format of the history file to be appended to is ...
--"08/18/2000","   59.26000","   59.28000","   58.95000","   59.05000","      
1772","        18068"
--"08/21/2000","   58.92000","   59.05000","   58.80000","   58.92000","      
1815","        18335"

pos          = 1
char         = {}
FieldNo      = 1
Field        = {}
WhichFile    = {}
UpdateRecord = {}
FileToUpdate = {}
FilesUpdated = 0
EOF          = false

while true do

   if FieldNo = 1 then                       -- accessing TODAYS.TXT
      UpdateRecord  = get(TodaysData)        -- the 1st object, file name

      if UpdateRecord[1] = GET_EOF then
         EOF = true
         exit
      end if

      if not UpdateRecord[1] = GET_SUCCESS then
         puts(1,"Get of Today's Data failed. Aborting...")
         exit
      end if
   else      -- FieldNo > 1
      UpdateRecord  = gets(TodaysData) -- gets() will get rest of record
   end if

   if atom(UpdateRecord) then
      EOF = true
      exit
   end if

   if FieldNo = 1 then
      WhichFile = UpdateRecord[2]&".TXT"
      WhichFile = "\\CANDLES\\DAILY\\TEST\\"&WhichFile

      FileToUpdate = open(WhichFile,"ab")  -- open History file for append

      if FileToUpdate = -1 then
         puts(1,"History File could not be opened...Aborting ...")
         puts(1,WhichFile)
         wait = wait_key()    -- abort(1)
      end if

      FieldNo += 1    -- get ready for next read (of TodaysData)
   else
---------------------------------------------------------------------------------
      puts(FileToUpdate,UpdateRecord)  -- note -- an ascii 26 is present
      -- at beginning of appended record, after first append, but not after
      -- subsequent appends of same data.
      -- SAMPLE OF UPDATED FILE: first append is the 3rd record shown.
"08/18/2000","   59.25000","   59.25000","   58.98000","   59.08000","       
640","          648"
"08/21/2000","   59.00000","   59.05000","   58.85000","   58.95000","        
32","          660"
"08/23/2000","   56.90000","   57.35000","   56.90000","   57.16000","       
 529","           809"
"08/23/2000","   56.90000","   57.35000","   56.90000","   57.16000","       
529","           809"
"08/23/2000","   56.90000","   57.35000","   56.90000","   57.16000","       
529","           809"

---------------------------------------------------------------------------------
      close(FileToUpdate)
      FilesUpdated +=1

      FieldNo = 1   -- ready to start at beginning of the next rec in TODAYS.TXT
   end if

end while

clear_screen()
printf(1,"Files Updated:  %6.0f ",FilesUpdated)
close(TodaysData)
abort(1)

--------------A23D4B41DCE6550F0385724E--

new topic     » topic index » view message » categorize

2. Re: HELP- with open("ab")

The problem is a text file should be opened in "a" mode (append text).

  --Sample:

  --say textfile1.txt is an existing text file...

  include file.e

  atom fp1

  --opens text file in append text mode:
  fp1=open("c:\\Euphoria\\Projects\\Tests\\textfile1.txt", "a")

  --prints next line in text file:
  printf(fp1,"%s\n",{"This will be next line printed to text file."})

  --closes the file:
  close(fp1)

  --the documentation for Euphoria v2.0 says the file must exist, yet
  --opening in the "a" mode with a filename that doesnt exist starts
  --a new 0 length file as if opened in the "w" mode.

  Good luck with it,
    --Al

new topic     » goto parent     » topic index » view message » categorize

3. Re: HELP- with open("ab")

Al,

Thanks for the suggestion. Tried open(fn,"a") and printf(), as you suggested, 
but it also results in the ascii 26 (eof)
character being present befor the newly appended record. Also, text editors (not
ED, which doesn't see past the ascii
26) show an additional (apparently completely empty) line following the appended
record.

I, no doubt could use EDS to handle the job, but I really would like to
understand what's causing the problem (me, I'm
sure, but how?).

Regards,

Jim Duffy


Really stumped by this problem.

Al Getz wrote:

> The problem is a text file should be opened in "a" mode (append text).
>
>   --Sample:
>
>   --say textfile1.txt is an existing text file...
>
>   include file.e
>
>   atom fp1
>
>   --opens text file in append text mode:
>   fp1=open("c:\\Euphoria\\Projects\\Tests\\textfile1.txt", "a")
>
>   --prints next line in text file:
>   printf(fp1,"%s\n",{"This will be next line printed to text file."})
>
>   --closes the file:
>   close(fp1)
>
>   --the documentation for Euphoria v2.0 says the file must exist, yet
>   --opening in the "a" mode with a filename that doesnt exist starts
>   --a new 0 length file as if opened in the "w" mode.
>
>   Good luck with it,
>     --Al

new topic     » goto parent     » topic index » view message » categorize

4. Re: HELP- with open("ab")

Did you try deleting the last byte of the file i.e. the 26 (decimal) ?
WinEdit.exe handles that, the 26 shows up as a small square.

(To enter a 26 use the alt-0-2-6 entry sequence, holding down the
alt key for all three numerals.)

Any more problems email me the file if its not too security sensitive, or
the last few lines if possible.

Good luck,
  Al

new topic     » goto parent     » topic index » view message » categorize

5. Re: HELP- with open("ab")

Al,

Thanks for the response. Problem is, I have 460 files to update (append to ) on
a daily basis... so I need an automated
solution. I've been pounding away at this problem for fiteen hours (way past my
bedtime), with no success.

I will try to delete it, as you suggest, but within the program, via seek()
to the byte immediately before the eof byte, and see if I can append from that
location.

I can email you the file, nothing secretive about it, just commodity prices.
But, I'd like to try the above, first. I'll let you know tomorrow whether that
worked.

Thanks for your help.

Regards,

Jim

Al Getz wrote:

> Did you try deleting the last byte of the file i.e. the 26 (decimal) ?
> WinEdit.exe handles that, the 26 shows up as a small square.
>
> (To enter a 26 use the alt-0-2-6 entry sequence, holding down the
> alt key for all three numerals.)
>
> Any more problems email me the file if its not too security sensitive, or
> the last few lines if possible.
>
> Good luck,
>   Al

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu