home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / random31.zip / Randomizer.cmd < prev    next >
OS/2 REXX Batch file  |  2000-05-24  |  3KB  |  147 lines

  1. /*
  2.      Randomizer.cmd
  3.      Randomizer v3.1 by Don Eitner, 2000
  4.  
  5.      Selects random items from a user-defined set of fields.
  6.  
  7.      This code is neither supported nor under warranty.  Feel free to
  8.      examine and modify this script for your own purposes.  See the
  9.      included readme.txt for additional information.
  10. */
  11.  
  12. parse arg CmdLine
  13. parse var CmdLine CL1 CmdLine
  14. CL1 = translate(CL1)
  15.  
  16. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  17. call SysLoadFuncs
  18.  
  19. call SysCls
  20.  
  21. DataFile = ''
  22.  
  23. call ParseInput
  24.  
  25. call SysCls
  26.  
  27. Fields = linein(DataFile,,1)
  28. Count = words(Fields)
  29.  
  30. do Num = 1 to Count
  31.     Item.Num = linein(DataFile,,1)
  32.     Field.Num = word(Fields, Num)
  33.  
  34.     if Pos('',Field.Num) = 1 then
  35.        Count2 = trunc(random(1, words(Item.Num)) / 2)
  36.     else
  37.        Count2 = 1
  38.  
  39.     if Pos('',Field.Num) = 1 then
  40.        Field.Num = substr(Field.Num,2)
  41.     X1 = lastpos('', Field.Num)
  42.     do while X1 <> '0'
  43.        Data2 = substr(Field.Num, X1+1)
  44.        Data1 = substr(Field.Num, 1, X1-1)
  45.        Field.Num = Data1||' '||Data2
  46.        X1 = lastpos('', Field.Num)
  47.     end
  48.  
  49.     do Rands = 1 to Count2
  50.            Rand = random(1, words(Item.Num))
  51.        Data.Num = word(Item.Num, Rand)
  52.  
  53.        X1 = lastpos('', Data.Num)
  54.        do while X1 <> '0'
  55.           Data2 = substr(Data.Num, X1+1)
  56.           Data1 = substr(Data.Num, 1, X1-1)
  57.           Data.Num = Data1||' '||Data2
  58.           X1 = lastpos('', Data.Num)
  59.        end
  60.  
  61.         Item.Num = delword(Item.Num, Rand, 1)
  62.  
  63.        say Field.Num' : 'Data.Num
  64.     end
  65.  
  66. end
  67.  
  68. call lineout(DataFile)
  69.  
  70. exit
  71.  
  72.  
  73. ParseInput:
  74.  
  75. Again:
  76.  
  77.     if (CL1 = '/Y') then
  78.     do
  79.        if DataInput = 'N' then
  80.             signal GiveHelp
  81.        DataInput = 'Y'
  82.        parse var CmdLine CL1 CmdLine
  83.        CL1 = translate(CL1)
  84.        signal Again
  85.     end
  86.  
  87.     if (CL1 = '/N') then
  88.     do
  89.        if DataInput = 'Y' then
  90.             signal GiveHelp
  91.         DataInput = 'N'
  92.        parse var CmdLine CL1 CmdLine
  93.        CL1 = translate(CL1)
  94.        signal Again
  95.     end
  96.  
  97.     if (CL1 = '/D') then
  98.     do
  99.         parse var CmdLine CL1 CmdLine
  100.        DataFile = CL1
  101.        parse var CmdLine CL1 CmdLine
  102.        CL1 = translate(CL1)
  103.        signal Again
  104.     end
  105.  
  106.     if DataFile = '' then
  107.         DataFile = 'RandomData.dat'
  108.  
  109.     select
  110.         when DataInput = 'N' then
  111.           return
  112.        when DataInput = 'Y' then
  113.           call DataInput(DataFile)
  114.        otherwise
  115.        do
  116.           do until (datatype(Junk) = 'CHAR') & (Junk = 'Y' | Junk = 'N')
  117.              say 'Would you like to edit the list of fields & items (Y/N)?'
  118.              Junk = translate(SysGetKey('NOECHO'))
  119.           end
  120.           if (Junk = 'Y') then
  121.              call DataInput(DataFile)
  122.        end
  123.     end
  124.  
  125. return
  126.  
  127.  
  128. GiveHelp:
  129.  
  130.     say 'Randomizer v3.0, 2000 by Don Eitner'
  131.     say 'Universal random item selector.'
  132.     say ''
  133.     say ' Usage:  Randomizer [[/Y | /N] [/D DataFile]] [/?]'
  134.     say ''
  135.     say '  Only one or the other parameter may be given, or neither.'
  136.     say '  If neither is given, program will prompt for input mode.'
  137.     say ''
  138.     say '  /Y = sets input mode on so you can add fields and items'
  139.     say '       to selected data file'
  140.     say '  /N = sets input mode off so you just get random selection'
  141.     say '       from selected data file'
  142.     say '  /D = allows you to choose the name of the data file to use'
  143.     say '  /? = shows this help screen'
  144.  
  145. exit
  146.  
  147.