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

  1. /* Create a MakeDesk definition for INI.RC to allow
  2.    rebuilding stock objects. */
  3.  
  4. /* Modified from ReCreate.CMD by Greg Czaja - Jul 29, 1992 */
  5. /* This version by Matthew Palcic - 10 Feb 93 */
  6.  
  7. Ver='v1.21'
  8.  
  9. say 'DefGen 'Ver' - Copyright 1993, Matthew J. Palcic'
  10. say
  11.  
  12. Parse arg DefArgs
  13. IniFile = '\OS2\INI.RC'
  14.  
  15. call GetArgs DefArgs
  16.  
  17. if Lines(file_name) = 0 then do
  18.   say 'Could not locate file: 'file_name
  19.   exit
  20.   end
  21. else
  22.   if OutFile <> '' then
  23.     call lineout OutFile,,1
  24. say 'Converting "'file_name'" into "'OutFile'"'
  25. Do While Lines(file_name) > 0
  26.    Title = ''; Object = ''; ObjID = ''; ShadID = ''; RepFlag = 'Update';
  27.    line=Linein(file_name);
  28.    If line='' Then Iterate;        /* skip blanks   */
  29.    Parse Var line '"PM_InstallObject"' line;
  30.    If line='' Then Iterate;
  31.    Parse Var line '"'head'" 'line; /* get header */
  32.  
  33.    /* gc this Parse will strip of " - important for Parse below */
  34.    Parse Var line '"'setup'"' .;   /* get setup string */
  35.  
  36.    Parse Var head title';'object';'location;
  37.    call lineout OutFile,'Title     'Title
  38.    call lineout OutFile,'Class     'Object
  39.  
  40.    PARSE VAR Location Location ';' RepFlag
  41.    call lineout OutFile,'Location  'Location
  42.  
  43.    If Right(setup,1) <> ';'   /* ending ; there ? */
  44.       Then setup=setup';'     /* no - append      */
  45.    Parse Var setup part1 'SHADOWID=' ShadID ';' part2;
  46.    setup=part1||part2;
  47.    Parse Var setup part1 'OBJECTID=' ObjID ';' part2;
  48.    setup=part1||part2;
  49.    if ShadID <> '' then do
  50.      ObjID = ShadID
  51.      end
  52.  
  53.    if ObjID <> '' then /* We have an ObjectID */
  54.      call lineout OutFile,'ObjectID  'ObjID
  55.    if RepFlag = 'REPLACE' then
  56.      call lineout OutFile,'Setup     Replace'
  57.    else
  58.      call lineout OutFile,'Setup     Update'
  59.    do while Setup <> ''
  60.      Parse VAR Setup SetVal ';' Setup
  61.      call lineout OutFile,SetVal
  62.      end /* do */
  63.    call lineout OutFile,''
  64.    End
  65.  
  66. rc=Stream(file_name,'C','Close');
  67. Return
  68.  
  69. BootDrive:
  70.   return filespec('drive',value('RUNWORKPLACE',,'OS2ENVIRONMENT'))
  71.  
  72. ShowParams:
  73.   say '  Description:'
  74.   say '     OS/2 profile resource (.RC) to MakeDesk (.DEF) converter'
  75.   say
  76.   say '  Syntax:'
  77.   say '     DefGen drive|infile outfile'
  78.   say
  79.   say '  Parameters:'
  80.   say '     drive      Drive letter containing \OS2\INI.RC'
  81.   say '                Default - boot drive'
  82.   say '                Example - E:'
  83.   say '     infile     Filename to process'
  84.   say '                Default extension - (.rc)'
  85.   say '                Example: E:\OS2\WIN_30.RC'
  86.   say
  87.   say '     outfile    Object definition file to create.'
  88.   say '                Default extension - (.def)'
  89.   say '                Example: D:\Defs\Win_30.def'
  90.   exit
  91.   return
  92.  
  93. GetArgs:
  94.   parse arg ARG1 ARG2
  95.   parse arg Args
  96.  
  97.   do ArgNum = 1 to Words(Args)
  98.     select
  99.       when WordPos(Word(Args,ArgNum),'-? /?') > 0 then
  100.         call ShowParams
  101.       otherwise
  102.         nop
  103.       end
  104.     end
  105.  
  106.   ALen = length(ARG1)
  107.   select
  108.     when ALen = 2 then do
  109.       parse upper var ARG1 DriveLetter':'Blah
  110.       if ((DriveLetter >= 'A') & (DriveLetter <='Z')) then
  111.         file_Name = DriveLetter':'IniFile
  112.       else
  113.         file_name = BootDrive()||IniFile
  114.       end
  115.     when ALen > 2 then
  116.       file_name = AddDefExt('rc',ARG1)
  117.     otherwise
  118.       call ShowParams
  119.       nop
  120.     end  /* select */
  121.  
  122.   if length(ARG2) > 0 then
  123.     OutFile = AddDefExt('def',ARG2)
  124.   else
  125.     call ShowParams
  126.   return
  127.  
  128. AddDefExt: procedure
  129.   parse arg DefExt,FileName
  130.   LastDot = lastpos('.',FileName)
  131.   if LastDot > 0 then
  132.     NewFileName = FileName /*NewFileName = overlay(DefExt,FileName,LastDot+1)*/
  133.   else
  134.     NewFileName = FileName'.'DefExt
  135.   return NewFileName
  136.  
  137.