Simple TACL macro to purge and create new file

1k Views Asked by At

I want to purge existing file, create new file using tedit and copy the contents of unstructured file to new file using jlist with the help of TACL macro.

? TACL MACRO 
#PURGE $A.B.C
#TEDIT $A.B.C !
#JLIST $D.E.F, PUT $A.B.C, NOPRINT

If I run above code through RUN command in tacl prompt it gives me error like 'name is not either variable or built in function'. Please help, I am new to TACL programming .

2

There are 2 best solutions below

0
On BEST ANSWER

It looks like #TEDIT and #JLIST are causing your issue. They are not valid builtins in the TACL language. To make your macro work, I would substitute EDIT there as in below:

? TACL MACRO
#PURGE $A.B.C
EDIT $A.B.C !
EDIT $D.E.F, PUT $A.B.C, NOPRINT

Alternatively, you could save yourself the startup time for the 3 runs (PURGE, EDIT and EDIT), by specifying a input file and doing it all within Edit as in below. Note that this will only work if you don't care if $A.B.C just gets its data purged, instead of actually getting rid of $A.B.C and recreating it each time.

?TACL MACRO
#Frame               == Localizes your variables to this run session
#Push InFile         == Create a new variable to be used
#Set InFile Get $A.B.C !  == Puts the data in the variable just created.  Gets the file to be worked upon.
#Append InFile D F/L   == Deletes all of the data in the file ($A.B.C)
#Append InFile G $D.E.F F/L to F == Gets the data from the new file from the first to last of the file and moves it to the file being edited at the first of the file.
#Append InFile Exit  == Exits Edit
EDIT/INV InFile/  == executes the commands put into InFile
#Unframe == Removes any localized variables created by this run
0
On

Here you go, use ROUTINE instead of MACRO, it is way better.

?tacl routine

 #output CRE8COPY Mark H. Poriss, Sr.

 ==
 == RUN CRE8COPY <file to be copied> <new file from file to be copied>
 ==
 #frame

 == Create a set of variables to work with
 #push makeCopyOfThisFile copyContentsToThisFile resultOfPurge copyV

 == Accepts arguments from the run(command) line
 #if [#argument/value makeCopyOfThisFile/filename end]
 #if [#argument/value copyContentsToThisFile/filename/syntax/]

 == Make filenames uppercase (looks better)
 #set makeCopyOfThisFile [#shiftstring [makeCopyOfThisFile]]
 #set copyContentsToThisFile [#shiftstring [copyContentsToThisFile]]

 == Use #FILEINFO with EXISTENCE to see if the file exists
 == Use #PURGE to actually delete the file passing back a result

 #output Purge copy file if it exists
 [#if [#fileinfo/existence/[copyContentsToThisFile]] |then|
      #set resultOfPurge [#purge [copyContentsToThisFile]]
      [#if [resultOfPurge = 0] |then|
           #output File [copyContentsToThisFile] purged ok
      |else|
           #output Error [resultOfPurge] on purge of [copyContentsOfThisFile]
      ]
 |else|
      #output File [copyContentsToThisFile] does not exist, ok to continue
 ]

 == Use EDIT with PUT to create your new file

 #output Using EDIT to create [copyContentsToThisFile]
 #push editV
 edit /outv editV/ [makeCopyOfThisFile] put [copyContentsToThisFile] !;exit

 #unframe