home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / MDSK14.ZIP / MakeDesk.cmd < prev    next >
OS/2 REXX Batch file  |  1993-02-10  |  9KB  |  320 lines

  1. /*
  2.  Build desktop objects from a definition (.DEF) file
  3.  
  4.  Developed by Matthew Palcic - Copyright 1993.
  5.  Released as freeware.  All rights reserved.
  6.  */
  7.  
  8. call SetupAnsi
  9. DefaultExt = 'def'
  10.  
  11. call RxFuncAdd SysLoadFuncs, RexxUtil, SysLoadFuncs; call SysLoadFuncs
  12.  
  13. DoAllFlag = 0
  14. parse Arg AllArgs
  15. DefFileSpec = ''
  16. call GetArgs AllArgs
  17.  
  18. Ver = 'v1.40'
  19. ProgTitle = 'MakeDesk 'Ver' - Copyright 1993, Matthew Palcic'
  20. '@ECHO OFF'; say Ansi.Normal;'CLS'; say '';say Ansi.Bold||ProgTitle||Ansi.NoBold
  21.  
  22. if DefFileSpec = '' then
  23.   call TellParameters
  24. call ParseDefFile DefFileSpec
  25. call CleanUp
  26. exit
  27.  
  28. ParseDefFile: arg DefFile
  29.   say
  30.   if \lines(DefFile) then /* Invalid file */
  31.     DefFile = AddDefExt(DefaultExt,DefFile)
  32.   if \lines(DefFile) then /* Still invalid */
  33.     call BadDefFile
  34.   say 'Processing: 'DefFile
  35.   say
  36.   UserVar.0 = 0
  37.   UserVal.0 = 0
  38.   UserIndex = 0
  39.  
  40.   Var = '~LF~'
  41.   Val = '0A'X
  42.   call DefineVar
  43.  
  44.   do while lines(DefFile)
  45.     DefLine = linein(DefFile)
  46.     parse value DefLine with Cmd Rest
  47.     Cmd = Translate(Cmd)
  48.     select
  49.       when SubStr(DefLine,1,1) = '*' then /* Comment specifier */
  50.         say Ansi.BrightCyan||SubStr(DefLine,2)||Ansi.Normal
  51.       when Cmd = 'DEFINE' then do /* Define command */
  52.         parse value Rest with Var Val
  53.         call DefineVar
  54.         end
  55.       when Cmd = 'TITLE' then do /* Title command */
  56.         Rest = Replace(Rest)
  57.         Title = Strip(Rest); Location=''; Setup=''
  58.         Drop SetupStr SetupStr.
  59.         SetupStr.0 = 0; Exists = 'U'; ObjectClass = ''; Done = 0; SetupStrX = 0
  60.         do while (Done = 0) /* Loop until end of file or blank line to separate objects */
  61.           ObjLine = linein(DefFile)
  62.           parse value ObjLine with Cmd Rest
  63.           Cmd = Translate(Cmd)
  64.           Rest = Replace(Rest)
  65.           if \Lines(DefFile) then
  66.             Done = 1
  67.           select
  68.             when Length(ObjLine) = 0 then 
  69.               Done = 1
  70.             when SubStr(ObjLine,1,1) = '*' then
  71.               nop /* Do nothing for a comment within an object block */
  72.             when Cmd = 'CLASS' then       /* Class subcommand */
  73.               ObjectClass = Strip(Rest)
  74.             when Cmd = 'LOCATION' then    /* Location subcommand */
  75.               parse upper value Strip(Rest) with Location
  76.             when Cmd = 'OBJECTID' then    /* ObjectID subcommand */
  77.               parse upper value Strip(Rest) with ObjectID
  78.             when Cmd = 'SETUP' then do    /* Setup type subcommand */
  79.               parse value Strip(Rest) with CreateFlag
  80.               CreateFlag = Translate(SubStr(CreateFlag,1,1))
  81.               end
  82.  
  83.             /* Add your own subcommands using this format.  Fill
  84.                in your own processing between the do and end statements.
  85.  
  86.                  when Cmd = '' then then do
  87.                    MyOwnProcessingCode
  88.                    end
  89.             */
  90.  
  91.             otherwise do /* Must be a Setup string */
  92.               SetupStrX = SetupStrX + 1
  93.               SetupStr.SetupStrX = Replace(ObjLine)
  94.               if Substr(SetupStr.SetupStrX,Length(SetupStr.SetupStrX),1) \= ';' then
  95.                 SetupStr.SetupStrX = SetupStr.SetupStrX||';'
  96.               end
  97.             end
  98.           end /* Finished with loop for this object */
  99.  
  100.         /* Process this definition */
  101.         Setup = Setup||'OBJECTID='||ObjectID||';'
  102.         do SetupLoop = 1 to SetupStrX
  103.           Setup = Setup||SetupStr.SetupLoop
  104.           end
  105.  
  106.         if 'Title' \= '' & ObjectClass \= '' & Location \= '' then do
  107.           /* Have title, class & location, build it */
  108.           if ObjectClass = 'WPShadow' then
  109.             Setup = 'SHADOWID='ObjectID /* Shadows need this */
  110.           call BldObj
  111.           end
  112.         else /* Not a valid title, class and location */
  113.           say 'Bad object definition.'
  114.         end
  115.  
  116.       /* Add your own main commands using this format.  Fill
  117.          in your own processing between the do and end statements.
  118.  
  119.          when Cmd = '' then then do
  120.            MyOwnProcessingCode
  121.            end
  122.       */
  123.  
  124.       otherwise /* Unknown command */
  125.         nop
  126.       end /* select */
  127.     end
  128.   return
  129.  
  130. AskAbout: parse arg Prompt
  131. if DoAllFlag = 1 then do
  132.   say
  133.   return 'Y'
  134.   end
  135. CF = GetDefType(CreateFlag)
  136. call charout ,Ansi.NoBold||CF' 'ObjectClass
  137. call charout ,' 'Ansi.Bold||Prompt||Ansi.NoBold'? ['
  138. call charout ,Ansi.Bold'Yes'Ansi.NoBold'/No/All/<Esc>] '
  139. key = ''
  140. do while (key \= 'Y') & (key \= 'N') & (C2D(key) \= 13) & (key \= 'A')
  141.   parse upper value SysGetKey('NOECHO') with key
  142.   if C2D(key) = 27 then do
  143.     say 'Esc'
  144.     call Escaped
  145.     end
  146.   end
  147. if C2D(key) = 13 then
  148.   Answer = 'Y'
  149. else
  150.   do
  151.   if key = 'A' then do
  152.     DoAllFlag = 1
  153.     say 'All'
  154.     return 'Y'
  155.     end
  156.   else
  157.     Answer = key
  158.   end
  159. select
  160.   when Answer = 'N' then
  161.     say 'No'
  162.   when Answer = 'Y' then
  163.     say 'Yes'
  164.   otherwise
  165.     nop
  166.   end
  167. return Answer
  168.  
  169. SaySuccess:
  170.   call charout ,'Success.'
  171.   return
  172.  
  173. SayFail:
  174.   call charout ,Ansi.BrightRed'Failed!'Ansi.Normal
  175.   return
  176.  
  177. /* Build Object */
  178. BldObj:
  179. DispTitle = translate(Title,' ',XRANGE('0'x,'1F'x),' ')
  180. ObjId = ObjectID
  181. if AskAbout(DispTitle) = 'N' then do
  182.   call WipePrompt
  183.   call charout ,'Skipping 'ObjectClass Title', 'ObjectID; say
  184.   return
  185.   end
  186. call WipePrompt
  187. call charout ,'Processing 'ObjectClass DispTitle', 'ObjectID'  '
  188. RC = SysCreateObject(ObjectClass, Title, Location, Setup, CreateFlag)
  189. If RC = 1 Then
  190.   call SaySuccess
  191. Else
  192.   call SayFail
  193. say
  194. return
  195.  
  196. Escaped:
  197.   beep(262,70);
  198.   say; say Ansi.Bold'Program terminated with <Esc>.'Ansi.NoBold
  199.   call CleanUp
  200.   exit
  201.   return
  202.  
  203. DefineVar:
  204.   UserIndex = UserIndex + 1
  205.   UserVar.UserIndex = Var
  206.   UserVal.UserIndex = Val
  207.   return
  208.  
  209. SetupAnsi:
  210.   Ansi.Bold = ''
  211.   Ansi.NoBold = ''
  212.   Ansi.BrightRed = ''
  213.   Ansi.Cyan = ''
  214.   Ansi.BrightCyan = ''
  215.   Ansi.Normal = Ansi.NoBold
  216.   Ansi.Plain = ''
  217.   Ansi.Up1AndClear = 'A'
  218.   return
  219.  
  220. DropAnsi:
  221.   Ansi.Bold = ''
  222.   Ansi.NoBold = ''
  223.   Ansi.BrightRed = ''
  224.   Ansi.Cyan = ''
  225.   Ansi.BrightCyan = ''
  226.   Ansi.Normal = Ansi.NoBold
  227.   Ansi.Plain = ''
  228.   Ansi.Up1AndClear = ''
  229.   return
  230.  
  231. WipePrompt:
  232.   call charout ,Ansi.Up1AndClear
  233.   return
  234.  
  235. Replace: parse arg Haystack
  236.   do x = 1 to UserIndex
  237.     RepDone = 0
  238.     NSpot = 1
  239.     do while RepDone = 0
  240.       NSpot = Pos(UserVar.x,Haystack,NSpot)
  241.       if NSpot = 0 then
  242.         RepDone = 1
  243.       else
  244.         do
  245.         Haystack = DelStr(Haystack,NSpot,Length(UserVar.x))
  246.         Haystack = Insert(UserVal.x, HayStack, NSpot-1)
  247.         NSpot = NSpot + Length(UserVal.x) - 1
  248.         end
  249.       end
  250.     end
  251.   return Haystack
  252.  
  253. GetBootDrive: procedure
  254.   call charout , 'Drive your machine boots from? '
  255.   parse upper value SysGetKey('NOECHO') with btdrv
  256.   if C2D(btdrv) = 27 then call Escaped
  257.   say btdrv':'
  258.   return btdrv
  259.  
  260. TellParameters:
  261.   say; say '  Description:'
  262.   say '    Process Workplace Shell objects from a .DEF file'
  263.   say
  264.   say '  Syntax:'
  265.   say '    MakeDesk [/a,/d] deffile'
  266.   say
  267.   say '  Parameters:'
  268.   say '    /a        process all objects in definition file without prompts'
  269.   say '    /d        disable ANSI colorization of display'
  270.   say '    deffile   Definition (.DEF) file to process'
  271.   say '              Example - System.def'
  272.   call CleanUp
  273.   exit
  274.   return
  275.  
  276. GetDefType: procedure; arg CFlag
  277.   select
  278.     when CFlag = 'U' then
  279.       CF = 'Update'
  280.     when CFlag = 'R' then
  281.       CF = 'Replace'
  282.     otherwise
  283.       CF = 'Create'
  284.     end
  285.   return CF
  286.  
  287. AddDefExt: procedure
  288.   parse arg DefExt,FileName
  289.   LastDot = lastpos('.',FileName)
  290.   if LastDot > 0 then
  291.     NewFileName = overlay(DefExt,FileName,LastDot+1)
  292.   else
  293.     NewFileName = FileName'.'DefExt
  294.   return NewFileName
  295.  
  296. BadDefFile:
  297.   say '  The definition file "'DefFile'" is invalid.'
  298.   say '  Check the file and try again.'
  299.   call CleanUp
  300.   exit
  301.   return
  302.  
  303. CleanUp:
  304.   say Ansi.BrightCyan; say 'Thank you for using MakeDesk 'Ver' by Matthew J. Palcic'Ansi.Plain
  305.   call SysDropFuncs
  306.   return
  307.  
  308. GetArgs: arg Args
  309.   do ArgNum = 1 to Words(Args)
  310.     select
  311.       when WordPos(Word(Args,ArgNum),'-a -A /a /A') > 0 then
  312.         DoAllFlag = 1 /* Do all objects in the definition file */
  313.       when WordPos(Word(Args,ArgNum),'-d -D /d /D') > 0 then
  314.         call DropAnsi
  315.       otherwise
  316.         DefFileSpec = Word(Args,ArgNum)
  317.       end
  318.     end
  319.   return
  320.