Output file ownership

Fairlight fairlite at fairlite.com
Fri May 19 09:43:45 PDT 2006


At Fri, May 19, 2006 at 01:05:42AM -0500 or thereabouts, 
suspect Tom was observed uttering:
> Mark. Thanks for the help. I reworked the code as follows. Not sure if 
> it's anything like you would have done but here it is and then another 
> question at the end

Well, yes and no.  You tried doing everything in two swipes, but they were
the wrong two swipes.  :) 

> html:::
> ::declare rptstring, handle(8,.0), jobname(8,*)
> ::jobname="we"{doedit(4,"mdy","6"):
> :jobname co chr("32")           'eliminate any space in job name
> :jobname=xlate(jobname,chr("32"),""):
> ::rptstring="/appl/fp/rreport scheddet -f sched -v schedsel -a -ia -u 
> -r" <1 <"-rw" <4 <"-rx" <5:
> ::rptstring=rptstring <"-h" <"\"" <jobname <"\"" <"-pn nocodes -p 
> /appl/fpmerge/html/ " {jobname&".html":
> ::system rptstring:
> ::handle=OPEN("/appl/fpmerge/html/"&jobname&".html","rwt"):
> :handle le "0"   'Open failed.
> :end:
> ::x = WRITELINE(handle,"<PRE>"):
> ::x = seek(handle,"0","e")    'position to end of file:
> ::x = WRITELINE(handle,"</PRE>"):
> ::system "ftp -in </usr/apps/fpftpsched"&1:
> ::x = REMOVE("/appl/fpmerge/html/"{jobname&".html"):
> 
> Appearing below are the first few lines of the resultant file. The issue 
> is that it's cutting off the first three characters (should be SCHEDULE, 
> not EDULE). Any direction on that issue? Thanks again.
> 
> <PRE>
> EDULE -- W/E 05/28/2006       Store No. 14  Printed 05/19/06 00:51  Rev.  5

I suspect that it's how you're handling the <PRE> tag, although I can't for
the life of me figure out why you don't end up with "LE -- W/E" as the
start of the next line at the moment, as six characters should go missing,
not three.

Basically, you have a file, you're opening it, and you're expecting the
contents to shift six characters (five plus the newline) by prepending at
the beginning.  Doesn't work that way though.

Incidentally, you want to check for lt, not le on an open().  Someone was
quite recently bitten by that.  The docs clearly say open status will be
a negative number if it fails.

The code below is a combination of your code, and some of my code from
elsewhere modified to fit your code.  If you're using 'ln' as a variable
elsewhere, you'll want to change the name; essentially it acts the same as
your 'x' but I didn't want to break anything in this quick example.

This is how I'd have done it, and I'll toss in a few extra comments for you
to follow:

::declare rptstring, jobname(8,*), IHandle(8,.0), OHandle(8,.0), FPos(20,.0):
::declare tmpfile,htmlfile,FLine,FSize(20,.0):
:'added a few extra declares:':
::jobname="we"{doedit(4,"mdy","6"):
:jobname co chr("32")           'eliminate any space in job name
:jobname=xlate(jobname,chr("32"),""):
::rptstring="/appl/fp/rreport scheddet -f sched -v schedsel -a -ia -u -r" <1 <"-rw" <4 <"-rx" <5:
:'Left your code alone through here.:':
::rptstring=rptstring <"-h" <"\"" <jobname <"\"" <"-pn nocodes -p /appl/fpmerge/html/ " {jobname&".tmp":
:'In the line above, I modified it to use a .tmp extension:'going back to the two-file approach here:
::system rptstring:
::tmpfile="/appl/fpmerge/html/"&jobname&".tmp":
::htmlfile="/appl/fpmerge/html/"&jobname&".html":
::OHandle=open(htmlfile,"wc0b"):
:'I always do my file operations in binary mode for portability.:'This actually has no effect on *nix systems:
:OHandle lt "0":end:
::FLine="<PRE>";ln=writeline(OHandle,FLine):
:'There, we wrote the beginning of the file with the pre tag:'Time to start copying the other file in:
::IHandle=open(tmpfile,"rb"):
:IHandle lt "0":end:
::FSize=filesize(IHandle):
::FPos="0":
:'File opened, size determined, tracker zeroed, start copying:':
cploop::ln=read(IHandle,FLine,"8192"):
:FPos lt FSize and ln eq "0" 'Premture end of file:end:
::lo=write(OHandle,FLine):
:lo ne ln 'Couldn't write as much as we read:end:
:FPos lt FSize:FPos=FPos+ln;goto cploop:
:'Fall through to here when nothing left to copy:'Now we finish off with the pre close tag:
::ln=writeline(OHandle,"</PRE>"):
::ln=close(IHandle);ln=close(OHandle);end:


Okay, that's pretty much it.  I went over it twice, and don't see anything
amiss with it off the cuff.  Even if there's a tiny bug, you get the idea,
which is what I'm trying to convey more than actual code (although unless I
made a typo somewhere, this should plug right in).

You do your report to a separate file as you originally were.  Then you
open the final file, stuff in your opening contents, copy the temp file in
after that, and tack on the ending all in one fell swoop.

NOTICE:  This complete combined code segment has -NOT- been tested as a
whole on a live system.  It was revamped on the fly, in vi inside email,
using your code and a modified bit of mine.  This code is provided AS-IS,
as an example of how one can achieve the desired results.  Any use of this
code, modified or unmodified, is done soley at your own risk.  Take the
appropriate precautions.

Okay, there's my CYA paragraph.  Sorry, had to.

Hope this more complete example helps.

mark->


More information about the Filepro-list mailing list