/* MakeReadMe.ged by Roy E Brown <roy@ebrown.demon.co.uk>

   $vers MakeReadMe.ged V1.3 (29.12.96)

   For use with GoldED.

   Based on the scripts for CED and FSE with similar names by Kenneth C. Nilsen

   Thanks must also go to Eric Gerard for a couple of suggestions.

   This AREXX script will make a .readme header for use with AmiNet uploads.

   It must be called from within GoldEd, and it requires the Aminet TREE file -
   with minor modifications - which is included in the archive.

   Please modify the 'Author' and 'Uploader' variables.
*/

Options Results                             /* enable return codes     */

If (Left(Address(),6)~="GOLDED") Then       /* not started by GoldEd ? */
    Address 'GOLDED.1'

'LOCK CURRENT RELEASE=4'                    /* lock GUI, gain access   */
If (RC ~= 0) Then
    Exit

Options Failat 6                            /* ignore warnings         */
Signal On Syntax                            /* ensure clean exit       */

/***** Start of my code *****/

/******** CHANGE THE NEXT 2 LINES TO YOUR REQUIREMENTS ********/

Author   ="roy@ebrown.demon.co.uk (Roy E Brown)"
Uploader ="Author"

/******** CHANGE THE ABOVE 2 LINES TO YOUR REQUIREMENTS ********/

DirList=''
SubList=''
Titel="MakeReadMe V1.3 1996 Roy E Brown"

'REQUEST TITLE="'Titel'"
         BODY="This script will create the|header lines required for a|standard Aminet .readme file"
         BUTTON="OK"'

If ~Exists('GoldEd:ARexx/TREE')=1 Then
  Do
    'REQUEST PROBLEM "Aminet Directory list not found"'
    'UNLOCK'
     Exit
  End

/* Read the Aminet Directory Tree */

If Open(AmiTree,'GoldEd:ARexx/TREE',r)=1 Then
  n=0
  Do Until EOF(AmiTree)
     List=ReadLn(AmiTree)
     MainDir.n=Compress(Left(List,(Index(List,'/'))),'/')
     y=n-1
     If MainDir.n=Maindir.y Then
       Iterate
     DirList=DirList||MainDir.n' '
     n=n+1
  End

C=Close(Amitree)

'REQUEST TITLE="'Titel'"
         BODY "Enter name of .readme or use a file|requester to ''Browse'' for your archive?"
         BUTTON="Enter|Browse|Cancel"'
If Result=0 Then Call Cancel

If Result=1 Then
  Do
    'REQUEST STRING TITLE="'Titel'"
             BODY "Enter name the of your .readme"
             OLD=".readme" MAX=21 VAR=Rname'
    If RC=5 Then Call Cancel
    Call NewName
  End
Else
Do
  Do
   'REQUEST TITLE="Please select your archive file ..."
            FILE VAR=aname'
    If RC=5 Then Call Cancel
  End
  If right(aname,4)~=".lha" Then
  aname=aname||".lha"
  'NAME NEW 'aname''
  'QUERY PATH'
   pathh=result
  'QUERY FILE'
   name=Result
  If Length(name)>18 Then
    Do  
     'REQUEST TITLE="'Titel'"
              BODY "Aminet limits the maximum filename length to|18 chars (including the''.lha'' suffix).|Please rename your archive."
              BUTTON "Rename|No Thanks|Cancel"'
      If Result=0 Then Call Cancel
      If Result=1 Then
        Do
          'REQUEST STRING TITLE="'Titel'"
                   BODY "Please amend your archive title"
                   OLD "'name'" VAR nname'
           If RC=5 Then Call Cancel
           Address Command 'Rename 'aname pathh||nname''
           Rname=pathh||Substr(name,1,Pos(".",name)-1)".readme"
           Call NewName
        End
      Else
        Do
          'REQUEST TITLE="'Titel'"
                   BODY "You are advised that Aminet will|trim your archive name to 18 chars|(including the ''.lha'')"
                   BUTTON "NOTED"'
           Rname=Substr(aname,1,Pos(".",aname)-1)".readme"
           Call NewName
        End
    End
  Else
    Do
      Rname=Substr(aname,1,Pos(".",aname)-1)".readme"
      Call NewName
    End
End

Call Start

If Desc='' Then
  Do
    'REQUEST PROBLEM="You must have a file description"'
    Call Start
  End

'REQLIST ENTRY 'DirList' VAR TYP1'
If RC=5 Then Call Cancel

If Open(AmiTree,'GoldEd:ARexx/TREE',r)=1 Then
  num=0
  Do Until EOF(AmiTree)
     List=ReadLn(AmiTree)
     If Left(List,Length(TYP1))~=TYP1 Then
       Iterate
     Short=Delstr(List,(Index(List,' ')))
     Subdir.num=compress(Substr(Short,Lastpos('/',Short)),'/')
     SubList=SubList||Subdir.num' '
     num=num+1
  End

C=Close(Amitree)

'REQLIST ENTRY 'Sublist' VAR TYP2'
If RC=5 Then Call Cancel

'REQUEST STRING TITLE="Requires: (OPTIONAL)" BODY="Enter any specific requirements." MAX=40 VAR=Req'
If RC=5 Then Call Cancel

'REQUEST STRING TITLE="Replaces: (OPTIONAL)" BODY="Full path of file to replace" MAX=40 VAR=Rep'
If RC=5 Then Call Cancel

'REQUEST STRING TITLE="Version: (OPTIONAL)" BODY="Enter the version number" MAX=20 VAR=Ver'
If RC=5 Then Call Cancel

'REQUEST TITLE="Distribution: (OPTIONAL)" BODY="Is it OK to put your upload|on future Aminet CDs?" BUTTON="CD OK|NO CD"'

If RESULT=0 Then Dis='NOCD'
Else Dis=''

/* OK, lets put it all together and print to screen */

'TEXT T="Short:    'Desc'" CR'
'TEXT T="Author:   'Author'" CR'
'TEXT T="Uploader: 'Uploader'" CR'
'TEXT T="Type:     'TYP1'/'TYP2'" CR'
If Req>0 Then 'TEXT T="Requires: 'Req'" CR'
If Rep>0 Then 'TEXT T="Replaces: 'Rep'" CR'
If Ver>0 Then 'TEXT T="Version:  'Ver'" CR'
If Dis>0 Then 'TEXT T="Distribution: 'Dis'" CR'
'TEXT CR'

/* All done, let's unlock the GUI and Exit */
'UNLOCK'   
Exit
 
Start:
'REQUEST STRING TITLE="Short: (REQUIRED)" BODY="Please enter a file description" MAX=40 VAR=Desc'
If RC=5 Then Call Cancel
Return

NewName:
'NAME NEW 'Rname''  /* Reset the filename of the current document */
Return

Cancel:
 Do
   'UNLOCK'
    Exit
 End
Return

/***** End of my code *****/

SYNTAX:

Say "Sorry, error line" SIGL ":" ERRORTEXT(RC) ":-("
'UNLOCK'
Exit
