home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / batch / mxmnu233.zip / NOVTRANS.MNU < prev    next >
Text File  |  1991-05-27  |  13KB  |  408 lines

  1. Comment
  2. ========================================================================
  3.  
  4. Novell menu to MarxMenu Translator:
  5.  
  6. Copyright 1989-91 by Marc Perkel * All rights reserved.
  7.  
  8. Usage: MARXMENU NOVTRANS <novell menu>
  9.  
  10. This program was written to translate Novell menus to MarxMenus. It is
  11. not an exact translation, but does the bulk of the work. It is up to you
  12. to edit the output file and tune the menu the way you want.
  13.  
  14. I have made no attempt to copy color information. I am not presenting
  15. selections in sorted order, but in the order in which they are defined.
  16.  
  17. The program creates a MarxMenu file names <menu>.TMP where <menu> is the
  18. name of your Novell menu file. Then it compiles <menu>.TMP into
  19. <menu>.MRX file that should be ready to run. if the menu needs to be
  20. altered, you will have to rename the <menu>.TMP file to a MNU file and
  21. then you can work with it like any other MarxMenu source file.
  22.  
  23. ========================================================================
  24. EndComment
  25.  
  26. Var
  27.    NovLines Menus Tmp MenuPtr ChoicePtr CommandPtr LinePtr
  28.    BoxDim X Y Z VarNum PromptLine Out Cap InputAVar NovellFileName
  29.    MarxMenuFileName NovellTempFileName Greek
  30.  
  31. ;----- Translator Messages
  32.  
  33. Const
  34.    TopMessage = "Joe Blow's Master Menu"
  35.    BottomMessage = "*-<< Acme Manufacturing Company >>-*"
  36.  
  37. ;----- If you want the Greek Column effect, set to true
  38.  
  39. Greek = False
  40.  
  41. Qualifier MenuName YPos XPos MenuColor MenuChoices
  42. Qualifier ChoiceName ChoiceCmd
  43.  
  44. Comment
  45. ========================================================================
  46.  
  47. This is the main body of the NovTrans Program.
  48.  
  49. ========================================================================
  50. EndComment
  51.  
  52. if not NetWorkVersion
  53.    ClearScreen
  54.    Writeln
  55.    Writeln 'This translator requires the network version of MarxMenu to Run!'
  56. endif
  57.  
  58. PreAmble
  59. PrepareFiles
  60. Header
  61. Parse
  62. WriteOutMenus
  63. Footer
  64.  
  65. ClearScreenFirst Off
  66. Writeln
  67. Execute 'MARXCOMP.EXE ' + MarxMenuFileName
  68.  
  69. Writeln
  70. Writeln 'To test your menu type MARX ' NovellFileName '. When you are satisfied with'
  71. Writeln 'the translation, replace the Novell ' NovellFileName '.MNU file'
  72. Writeln 'with the ' MarxMenuFileName ' file that NovTrans just created.'
  73.  
  74. Comment
  75. =====================================
  76.  
  77. Subroutine area.
  78.  
  79. =====================================
  80. EndComment
  81.  
  82. ;----- Initilize Variables and Environment
  83.  
  84. Procedure PreAmble
  85.   ClearScreenOnExit Off
  86.   StandardIO
  87.   Writeln
  88.   NovellFileName = UpperCase(ParamStr(2))
  89.   Usage
  90. EndProc
  91.  
  92. ;----- Proper Usage Procedure
  93.  
  94. Procedure Usage
  95.   if NovellFileName = ''
  96.     Writeln('Usage: MarxMenu NovTrans <menu>')
  97.     Writeln('Converts Novell menus to MarxMenus.')
  98.     Writeln('Be sure to backup your original menus before running!!')
  99.     ExitMenu
  100.   endif
  101. EndProc
  102.  
  103. ;----- Create FileNames and open Files
  104.  
  105. Procedure PrepareFiles
  106.   if pos('.',NovellFileName) > 0
  107.     NovellFileName = left(NovellFileName,pred(pos('.',NovellFileName)))
  108.   endif
  109.  
  110.   NovellTempFileName = NovellFileName + '.MNU'
  111.   MarxMenuFileName = ForceExtension(NovellTempFileName,'TMP')
  112.  
  113.   ReadTextFile NovellTempFileName NovLines
  114.   Writeln 'Creating ' MarxMenuFileName
  115.  
  116.   FileAssign(Out,MarxMenuFileName)
  117.   FileCreate(Out)
  118. EndProc
  119.  
  120.  
  121. Procedure BlankLine
  122.    FileWriteln(Out,'')
  123. EndProc
  124.  
  125. ;----- Write out the MarxMenu Source Header
  126.  
  127. Procedure Header
  128.   BlankLine
  129.   FileWriteln(Out,'Comment')
  130.   FileWriteln(Out,'==========================================================')
  131.   BlankLine
  132.   FileWriteln(Out,'This File was converted from Novell Menu: ',NovellTempFileName)
  133.   BlankLine
  134.   FileWriteln(Out,'It should behave in a similar way to the original menu but')
  135.   FileWriteln(Out,'not necessarilly exactly the same. It will be close enough')
  136.   FileWriteln(Out,'for you to fine tune it the way you want.')
  137.   BlankLine
  138.   FileWriteln(Out,'To add a choice to a menu simply use the AddChoice command')
  139.   FileWriteln(Out,'then add the appropiate Onkey statement.')
  140.   FileWriteln(Out,'The menu will make the size adjustments accordinaly.')
  141.   BlankLine
  142.   FileWriteln(Out,'  Example:')
  143.   FileWriteln(Out,'      AddChoice("Print Console",10)')
  144.   FileWriteln(Out,'      ... ')
  145.   FileWriteln(Out,'      ... ')
  146.   FileWriteln(Out,'      OnKey Task(10)')
  147.   FileWriteln(Out,'        PConsole')
  148.   FileWriteln(Out,'      ...')
  149.   BlankLine
  150.   FileWriteln(Out,"If you want to change the menu's center, pass the XY")
  151.   FileWriteln(Out,"coordinates to menu's CenterStretchBox procedure.")
  152.   BlankLine
  153.   FileWriteln(Out,'   Example:')
  154.   FileWriteln(Out,'      CenterStretchBox("Menu Header",10,10)')
  155.   BlankLine
  156.   FileWriteln(Out,'This will cause the menu to center at Col 10, Row 10')
  157.   BlankLine
  158.   FileWriteln(Out,'Once you are satisfied with the translation you can copy the TMP file')
  159.   FileWriteln(Out,'over the old Novell MNU file and just work with the MarxMenu version.')
  160.   BlankLine
  161.   FileWriteln(Out,'To control custom features, edit CUSTOM.INC and other INCLUDE Files.')
  162.   BlankLine
  163.   FileWriteln(Out,'=========================================================')
  164.   FileWriteln(Out,'EndComment')
  165.   BlankLine
  166.   FileWriteln(Out,';----- Create Variables')
  167.   BlankLine
  168.   FileWriteln(Out,'var')
  169.   FileWriteln(Out,'  %NovVar1')
  170.   FileWriteln(Out,'  %NovVar2')
  171.   FileWriteln(Out,'  %NovVar3')
  172.   FileWriteln(Out,'  %NovVar4')
  173.   FileWriteln(Out,'  %NovVar5')
  174.   FileWriteln(Out,'  %NovVar6')
  175.   FileWriteln(Out,'  %NovVar7')
  176.   FileWriteln(Out,'  %NovVar8')
  177.   FileWriteln(Out,'  %NovVar9')
  178.   FileWriteln(Out,'  %NovVar10')
  179.   FileWriteln(Out,'  KeepUsersInMenu')
  180.   BlankLine
  181.   BlankLine
  182.   FileWriteln(Out,';----- Here is where you add you own menu title and status line message')
  183.   BlankLine
  184.   FileWriteln(Out,'MenuTitle      = "',TopMessage,'"')
  185.   FileWriteln(Out,'StatusLineText = "',BottomMessage,'"')
  186.   BlankLine
  187.   FileWriteln(Out,';----- Load Novell look and feel routines')
  188.   BlankLine
  189.   FileWriteln(Out,'Include "CUSTOM.INC"')
  190.   if Greek then FileWriteln(Out,'Greek = True')
  191.   BlankLine
  192.   FileWriteln(Out,'KeepUsersInMenu Off')
  193.   BlankLine
  194.   FileWriteln(Out,'Comment')
  195.   FileWriteln(Out,'=================================')
  196.   BlankLine
  197.   FileWriteln(Out,'In order to add menu choices conditionally you would append the')
  198.   FileWriteln(Out,'choices to the end of the array after all the default choices')
  199.   FileWriteln(Out,'are set. For Example:')
  200.   BlankLine
  201.   FileWriteln(Out,'   if NovInGroup("ACCOUNTING")')
  202.   FileWriteln(Out,'      AddChoice("Payroll Menu",10)')
  203.   FileWriteln(Out,'   endif')
  204.   BlankLine
  205.   FileWriteln(Out,'Here is where menus are created.')
  206.   BlankLine
  207.   FileWriteln(Out,'=================================')
  208.   FileWriteln(Out,'EndComment')
  209.   BlankLine
  210.   FileFlush(Out);
  211. EndProc
  212.  
  213.  
  214. ;----- Write out the MarxMenu Source Footer
  215.  
  216. Procedure Footer
  217.    BlankLine
  218.    FileWriteln(Out,';----- End of Menu')
  219.    FileClose(Out)
  220. EndProc
  221.  
  222.  
  223. ;----- Delete all spaces in a string to make them a valid MarxMenu label
  224. ;      Returns a string
  225.  
  226. Procedure DeleteSpaces(St)
  227.    while Pos(' ',St) > 0
  228.       Delete(St,Pos(' ',St),1)
  229.    endwhile
  230.    while Pos('-',St) > 0
  231.       Delete(St,Pos('-',St),1)
  232.    endwhile
  233.    while Pos('.',St) > 0
  234.       Delete(St,Pos('.',St),1)
  235.    endwhile
  236.    while Pos('/',St) > 0
  237.       Delete(St,Pos('/',St),1)
  238.    endwhile
  239.    if (Mid(St,2,1) >= '0') and (Mid(St,2,1) <= '9')
  240.       Insert('X',St,2)
  241.    endif
  242.    Return St
  243. EndProc
  244.  
  245. ;----- Parse Novell Source into MenuName, MenuChoices, MenuCommands
  246. ;----- Returns a integer pointing to the end of the menu prompt
  247.  
  248. Procedure FindEndOfMenuPrompt(St)
  249. Var CommaPos Tail
  250.  
  251.   CommaPos = Pos(',',St)
  252.   if CommaPos = 0 Then Return Length(St) + 1
  253.   Tail = Mid(St,CommaPos + 1,255)
  254.   loop(Length(Tail))
  255.     if Pos(Mid(Tail,LoopIndex,1), '0123456789,') = 0
  256.       Writeln
  257.       Writeln('Error : There must not be any embedded commas in menu title!')
  258.       Writeln(St)
  259.       Writeln
  260.       ExitMenu
  261.     endif
  262.   endloop
  263.   Return CommaPos
  264. EndProc
  265.  
  266. ;----- Preprocess Lines
  267.  
  268. Procedure Parse
  269. Var TotalLines
  270.   TotalLines = NumberOfElements(NovLines)
  271.   Writeln('Parsing Novell Menu source code ...')
  272.   MenuPtr = 0
  273.   loop(TotalLines)
  274.      if (LoopIndex Mod 10 = 0) or (LoopIndex = TotalLines)
  275.        Write Cr
  276.        Write('Processing Line # ',LoopIndex,' of ',TotalLines)
  277.      endif
  278.      if left(NovLines[LoopIndex],1) = '%'
  279.         ChoicePtr = 0
  280.         CommandPtr = 0
  281.         MenuPtr = MenuPtr + 1
  282.         Tmp = mid(NovLines[LoopIndex],2,255)
  283.         X = FindEndOfMenuPrompt(Tmp)
  284.         Menus[MenuPtr].MenuName = ':' + left(Tmp,X - 1)
  285.         Tmp = mid(Tmp,X + 1,255)
  286.         Menus[MenuPtr].YPos = value(NextWord(Tmp))
  287.         Menus[MenuPtr].XPos = value(NextWord(Tmp))
  288.         Menus[MenuPtr].MenuColor = value(NextWord(Tmp))
  289.      else
  290.         if left(NovLines[LoopIndex],1) > ' '
  291.            CommandPtr = 0
  292.            ChoicePtr = ChoicePtr + 1
  293.            Trim(NovLines[LoopIndex])
  294.            if Mid(NovLines[LoopIndex], 2, 1) = '.'
  295.              Delete(NovLines[LoopIndex],1,2)
  296.              Trim(NovLines[LoopIndex])
  297.            endif
  298.            Menus[MenuPtr].MenuChoices[ChoicePtr].ChoiceName = NovLines[LoopIndex]
  299.         else
  300.            if ChoicePtr = 0
  301.               Writeln
  302.               Writeln 'Error in menu line: ' LoopIndex
  303.               ExitMenu
  304.            endif
  305.            CommandPtr = CommandPtr + 1
  306.            Menus[MenuPtr].MenuChoices[ChoicePtr].ChoiceCmd[CommandPtr] = NovLines[LoopIndex]
  307.         endif
  308.      endif
  309.   endloop
  310. EndProc
  311.  
  312. ;----- Create the Menu Choices Array
  313.  
  314. Procedure WriteOutMenuChoices
  315.   Writeln
  316.   Write('Translating: ' + mid(Menus[MenuPtr].MenuName,2,255) + ' ... ')
  317.   BlankLine
  318.   FileWriteln(Out,';----- Translating: ' + mid(Menus[MenuPtr].MenuName,2,255))
  319.   BlankLine
  320.   if MenuPtr > 1
  321.      Tmp = Menus[MenuPtr].MenuName
  322.      Tmp = DeleteSpaces(Tmp)
  323.      FileWriteln(Out,Tmp)
  324.      BlankLine
  325.   endif
  326.   loop(NumberOfElements(Menus[MenuPtr].MenuChoices))
  327.      FileWriteln(Out,'  AddChoice("' + Menus[MenuPtr].MenuChoices[LoopIndex].ChoiceName + '",' + Str(LoopIndex) + ')')
  328.   endloop
  329.   BlankLine
  330.   FileWriteln(Out,'CenterStretchBox("' + Mid(Menus[MenuPtr].MenuName,2,255) + '",' + Str(Menus[MenuPtr].XPos) + ',' + Str(Menus[MenuPtr].YPos) + ')')
  331.   BlankLine
  332. EndProc
  333.  
  334. ;----- Create the Onkey Statements
  335.  
  336. Procedure WriteOutOnkeyChoices
  337.   loop(NumberOfElements(Menus[MenuPtr].MenuChoices))
  338.     ChoicePtr = LoopIndex
  339.     Tmp = Menus[MenuPtr].MenuChoices[ChoicePtr].ChoiceName
  340.     FileWriteln(Out,'OnKey Task(' + Str(ChoicePtr) + ')')
  341.     loop(NumberOfElements(Menus[MenuPtr].MenuChoices[ChoicePtr].ChoiceCmd))
  342.       CommandPtr = LoopIndex
  343.       Tmp = Menus[MenuPtr].MenuChoices[ChoicePtr].ChoiceCmd[CommandPtr]
  344.       Trim(Tmp)
  345.       if UpperCase(Tmp) = '!LOGOUT' then Tmp = '|Logoff'
  346.       if Left(Tmp,1) = '%'
  347.         Tmp = DeleteSpaces(Tmp)
  348.         Tmp = '^' + Mid(Tmp,2,255)
  349.       endif
  350.       if (pos('@',Tmp) > 0) And (Pos('@ECHO',UpperCase(Tmp)) = 0)
  351.         X = 1
  352.         while X <= length(Tmp)
  353.           while (X <= length(Tmp)) and (mid(Tmp,X,1) <> '@')
  354.              X = X + 1
  355.           endwhile
  356.           Z[1] = mid(Tmp,X,1)
  357.           Z[2] = mid(Tmp,X + 1,1)
  358.           if (Z[1] = '@') and (((Z[2] > '0') and (Z[3] <= '9')) or (Z[2] = '"'))
  359.             if Z[2] = '"'
  360.               insert(' ',Tmp,X + 1)
  361.               VarNum = 10
  362.             else
  363.               VarNum = ord(Z[2]) - 48
  364.             endif
  365.             InputAVar = mid(Tmp,X + 2,1) = '"'
  366.             if InputAVar
  367.               Y = X + 3
  368.               while (mid(Tmp,Y,1) <> '"') and (Y <= length(Tmp))
  369.                 Y = Y + 1
  370.               endwhile
  371.               PromptLine = mid(Tmp,X + 3,Y - (X + 3))
  372.             else
  373.               Y = X + 1
  374.             endif
  375.           delete(Tmp,X,Y - X + 1)
  376.           insert('%NovVar' + Str(VarNum)  ,Tmp,X)
  377.           if InputAVar
  378.             FileWriteln(Out,'   |%NovVar',Str(VarNum), ' = ReadTextLine("' + PromptLine + '","",0,21)')
  379.           endif
  380.         endif
  381.       endwhile
  382.     endif
  383.       FileWriteln(Out,'   ' + Tmp)
  384.     endloop
  385.     BlankLine
  386.   endloop
  387. EndProc
  388.  
  389. ;----- Create the Menus
  390.  
  391. Procedure WriteOutMenus
  392. Var LoopCount
  393.   Writeln
  394.   LoopCount = MenuPtr
  395.   Loop LoopCount
  396.      MenuPtr = LoopIndex
  397.      WriteOutMenuChoices
  398.      WriteOutOnkeyChoices
  399.      if MenuPtr = 1
  400.         FileWriteln(Out,'OnKey ESC')
  401.         FileWriteln(Out,'   |if not KeepUsersInMenu or NovConsoleOperator')
  402.         FileWriteln(Out,'   |   LeaveMenu')
  403.         FileWriteln(Out,'   |endif')
  404.         BlankLine
  405.      endif
  406.   EndLoop
  407. EndProc
  408.