/*  Adept 1.08a5+ to Adept v0.01 - 1.07 Menu Converter */
/*  ================================================== */
/*         use it, but dont worry about                */
/*  Remove all *.old and *.new files in menu dir !!!   */
/*  BK  */

/*  Converting order:
Key   Command   OutputString   DataString   Color   MinAge   MaxAge   Sec1   Sec2   Flags1   Flags2   StartTime   EndTime   Gender   MinCredit   MaxCredit   MinTime   MaxTime   MinCall   MaxCall   MinPosts   MaxPosts   MinUpl   MaxUpl   MinDl   MaxDl   Group   PortFlags
*/

call RxFuncAdd 'SysLoadFuncs', 'rexxutil', 'SysLoadFuncs'
call 'SysLoadFuncs'
     tmp=syscls()

SIGNAL ON FAILURE NAME CLEANUP
SIGNAL ON HALT    NAME CLEANUP
SIGNAL ON SYNTAX  NAME CLEANUP


'@echo off'

say 'Menu Converion Program for AdeptXBBS v1.07'
say ''
say 'Run this program from in your Menus sub-directory'

Call CharOut, 'Enter in the Drive Letter Adept is installed on. [ie D:] : '
Pull Drive
If Pos(':',Drive) = 0 Then Drive = Drive || ':'

OldDirectory = Directory()

rc = Directory(Drive || '\Adept\Menus')

RC = SysFileTree('*.menu', 'fline', 'FO')

	say ''
	say '**************************************************************'
	say 'Start converting 'fline.0' 1.08a menus back to 1.07(x) menu structure'
	say' Your directory: 'Directory(Drive || '\Adept\Menus')
	Call CharOut, 'PRESS Enter or Q to quit '
	say ''
	say '**************************************************************'
	say ''
	Pull zeichen
	parse upper value zeichen with zeichen
	if zeichen ='Q' then do
	  say ' ... leaving'
	  call cleanup
	end

counter=0
do i = 1 to fline.0                  /* read in stem *.menu */

   Pos = LASTPOS('\', fline.i)
   Len = LENGTH(fline.i)
   FileName = RIGHT(fline.i, (Len - Pos))


   NewName = FileName||'.New'
   OldName = FileName
   NewOld  = FileName||'.old'

   File = FileName

   laenge = length(file)
   space=''
   do x=1 to 20-laenge
     space=space||' '
   end
   Say 'Converting menu 'File||space||'->       'file'.NEW'

   ret = STREAM( (file) , "C" , "OPEN" )
   ret = STREAM( (newname) , "C" , "OPEN" )

   MenuLine = Strip(LineIn(File))
  
   if(MenuLine \= 'BEGINMENU') then do
      say File || ' Already Converted!'
      ret = STREAM( (file) , "C" , "CLOSE" )
      ret = STREAM( (newname) , "C" , "CLOSE" )
      iterate
   end

   counter=counter+1
   MenuLine = Strip(LineIn(File,1,1))
   do while(menuline \='BEGINMENUITEM')
            MenuLine = Strip(LineIn(File))
   end

   line=''
   key =''
   menucommand =''
   displaystring =''
   displaycolor =''
   DATAOPTION =''
   MINAGE =''
   MAXAGE =''
   SEC1 =''
   SEC2 =''
   FLAGS1 =''
   FLAGS2 =''
   GENDER =''
   STARTTIME =''
   ENDTIME =''
   MINTIME =''
   MAXTIME =''
   MINCALL =''
   MAXCALL =''
   MINPOSTS =''
   MAXPOSTS =''
   MINUPLOADS =''
   MAXUPLOADS =''
   MINDOWNLOADS =''
   MAXDOWNLOADS =''
   GROUP =''
   PORTFLAGS =''
   line=''


            do while (Lines(File) == 1)           /* Schleife einlesen und abfrage begin */
               MenuLine = Strip(LineIn(File))
	       parse value menuline with keyword rest
	       keyword=strip(keyword, 'B')
	       rest=strip(rest, 'B')

               if(keyword == 'MENUCOMMENT')  then do
                  RC = LineOut(NewName, '; '||rest 
                  Iterate
               end

               if(MenuLine == '') | (keyword == 'BEGINMENUITEM') then do
                  Iterate
               end

                  if (Keyword == 'KEY') then key=rest
                  if (keyword == 'MENUCOMMAND') then menucommand=rest
                  if (keyword == 'DISPLAYSTRING') then displaystring=rest
                  if (keyword == 'DISPLAYCOLOR') then displaycolor=rest
                  if (keyword == 'DATAOPTION') then dataoption=rest
                  if (keyword == 'MINAGE') then minage=rest
                  if (keyword == 'MAXAGE') then maxage=rest
                  if (keyword == 'MINSEC1') then sec1=rest
                  if (keyword == 'MINSEC2') then sec2=rest
                  if (keyword == 'FLAGS1') then flags1=rest
                  if (keyword == 'FLAGS2') then flags2=rest
                  if (keyword == 'GENDER') then gender=rest
                  if (keyword == 'STARTTIME') then starttime=rest
                  if (keyword == 'ENDTIME') then endtime=rest

                  if (keyword == 'MINONLINETIME') then mintime=rest
                  if (keyword == 'MAXONLINETIME') then maxtime=rest


                  if (keyword == 'MINCALLS') then mincalls=rest
                  if (keyword == 'MAXCALLS') then maxcalls=rest

                  if (keyword == 'MINPOSTS') then minposts=rest
                  if (keyword == 'MAXPOSTS') then maxposts=rest
                  if (keyword == 'MINUPLOADS') then minuploads=rest
                  if (keyword == 'MAXUPLOADS') then maxuploads=rest
                  if (keyword == 'MINDOWNLOADS') then mindownloads=rest
                  if (keyword == 'MAXDOWNLOADS') then maxdownloads=rest
                  if (keyword == 'GROUP') then group=rest
                  if (keyword == 'PORTFLAGS') then portflags=rest

		  mincredit=''
		  maxcredit=''

                  if (keyword == 'ENDMENUITEM') then do
		     line=key','menucommand','displaystring','dataoption','displaycolor','minage','maxage','
		     line=line||sec1','sec2','flags1','flags2','starttime','endtime','gender','mincredit','
      		     line=line||maxcredit','mintime','maxtime','mincall','maxcall','minposts','maxposts','
		     line=line||minuploads','maxuploads','mindownloads','maxdownloads','group','portflags
		     line=strip(line, 'T',',')
                     RC = LineOut(NewName, line)
			  key =''
			  menucommand =''
			  displaystring =''
			  displaycolor =''
        	          DATAOPTION =''
                	  MINAGE =''
	                  MAXAGE =''
        	          SEC1 =''
                	  SEC2 =''
	                  FLAGS1 =''
        	          FLAGS2 =''
                	  GENDER =''
	                  STARTTIME =''
        	          ENDTIME =''
                	  MINTIME =''
                	  MAXTIME =''
	                  MINCALL =''
        	          MAXCALL =''
                	  MINPOSTS =''
	                  MAXPOSTS =''
        	          MINUPLOADS =''
                	  MAXUPLOADS =''
	                  MINDOWNLOADS =''
        	          MAXDOWNLOADS =''
                	  GROUP =''
	                  PORTFLAGS =''
			  line=''
	          end                               /* Ende ENDMENUITEM */
            end                                     /* Schleife einlesen und abfrage ende */

	    ret = STREAM( (file) , "C" , "CLOSE" )
	    ret = STREAM( (newname) , "C" , "CLOSE" )

            AdCmd = 'Ren ' || OldName || ' ' || NewOld
            AdCmd
            AdCmd = 'Ren ' || NewName || ' ' || OldName
            AdCmd

end 						    /* ende stem schleife */

Call Directory(OldDirectory)
say ''
say ' ==========================================================================='
Say ' 'fline.0' 1.08-Menus found and 'counter' menus converted into 1.07 menu structure, Done..'
say ''
say ' Renaming 108-menus -> *.menu.old    Renaming *.menu.new -> *.menu '

exit

CLEANUP:
exit
