home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / random31.zip / DataInput.cmd next >
OS/2 REXX Batch file  |  2000-05-24  |  10KB  |  441 lines

  1. /*
  2.      DataInput.cmd
  3.      Randomizer v3.1 by Don Eitner, 2000
  4.  
  5.      Sets up user-defined fields and items for Randomizer.cmd.
  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. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  13. call SysLoadFuncs
  14.  
  15. parse arg DataFile
  16.  
  17. call AnsiSetup
  18.  
  19. if DataFile = '' then
  20. do
  21.     say 'Enter the name of the data file you wish to use.'
  22.     parse pull DataFile
  23.     if DataFile = '' then
  24.        DataFile = 'RandomData.dat'
  25. end
  26.  
  27. Fields = linein(DataFile,,1)
  28. Count = words(Fields)
  29.  
  30. do Num = 1 to Count
  31.     Item.Num = linein(DataFile,,1)
  32. end
  33.  
  34. call lineout(DataFile)
  35.  
  36. do forever
  37.     call FieldMenu
  38.     if Save = 1 then
  39.        signal SaveIt
  40. end
  41.  
  42. exit
  43.  
  44.  
  45. SaveIt:
  46.  
  47.     RC = SysFileDelete(DataFile)
  48.     call lineout DataFile, Fields
  49.     do Num = 1 to Count
  50.        call lineout DataFile, Item.Num
  51.     end
  52.     call lineout(DataFile)
  53.  
  54. return
  55.  
  56.  
  57. FieldMenu:
  58.  
  59.     Count = words(Fields)
  60.     call SysCls
  61.     say center('Main Fields Menu', 80)
  62.     do Num = 1 to Count
  63.        Data.Num = word(Fields, Num)
  64.         Display.Num = Data.Num
  65.  
  66.        X1 = lastpos('', Display.Num)
  67.        do while X1 <> '0'
  68.           Data2 = substr(Display.Num, X1+1)
  69.           Data1 = substr(Display.Num, 1, X1-1)
  70.           Display.Num = Data1||' '||Data2
  71.           X1 = lastpos('', Display.Num)
  72.        end
  73.  
  74.        call ArrangeDisplay
  75.        call SysCurPos Row, Col
  76.        say '('||Num||')' Display.Num
  77.     end
  78.     call SysCurPos 17, 0
  79.     say copies('-', 80)
  80.     call SysCurPos 17, 28
  81.     say LWhi||'Please Select From Below'||Non
  82.     call SysCurPos 18, 8
  83.     say '('||LBro||'A'||Non||')dd a Field  ('||LBro||'D'||Non||')elete a Field  ('||LBro||'E'||Non||')dit a Field  ('||LBro||'M'||Non||')ark a field'
  84.     call SysCurPos 19, 21
  85.     say '('||LBro||'H'||Non||')elp  ('||LBro||'S'||Non||')ave & Exit  ('||LBro||'Q'||Non||')uit w/o Save'
  86.     call SysCurPos 20, 0
  87.     say copies('-', 80)
  88.     parse upper pull Selection
  89.  
  90.     select
  91.         when (datatype(Selection) = 'NUM') & (Selection <= Count) then
  92.           signal ItemMenu
  93.  
  94.        when Selection = 'A' then
  95.        do
  96.           Fields = ''
  97.           say 'Enter new field name.'
  98.           Count = Count + 1
  99.           parse pull Data.Count
  100.           X1 = lastpos(' ', Data.Count)
  101.           do while X1 <> '0'
  102.              Data2 = substr(Data.Count, X1+1)
  103.              Data1 = substr(Data.Count, 1, X1-1)
  104.              Data.Count = Data1||''||Data2 /* That's ASCII code ALT-29 */
  105.              X1 = lastpos(' ', Data.Count)
  106.           end
  107.           Item.Count = 'editme!'
  108.           do Num = 1 to Count
  109.              Fields = Fields Data.Num
  110.           end
  111.           signal FieldMenu
  112.        end
  113.  
  114.        when Selection = 'D' then
  115.        do
  116.           say 'Which field do you wish to delete?'
  117.           parse pull Selection2
  118.           if (Selection2 <= Count) & (Selection2 > 0) then
  119.           do
  120.              say 'Are you sure you want to delete this field and its items?'
  121.              parse pull Junk
  122.              if translate(Junk) = 'Y' then
  123.              do
  124.                 Fields = ''
  125.                 Data.Selection2 = ''
  126.                 Item.Selection2 = ''
  127.                 do Num = 1 to Count
  128.                     Fields = Fields Data.Num
  129.                 end
  130.                 do Num = 2 to Count
  131.                     PrevNum = Num - 1
  132.                     if Item.PrevNum = '' then
  133.                     do
  134.                        Item.PrevNum = Item.Num
  135.                        Item.Num = ''
  136.                     end
  137.                 end
  138.                 signal FieldMenu
  139.              end
  140.              else
  141.                 signal FieldMenu
  142.           end
  143.           else
  144.              signal FieldMenu
  145.        end
  146.  
  147.        when Selection = 'E' then
  148.        do
  149.           say 'Which field do you wish to edit?'
  150.           parse pull Selection2
  151.           if (Selection2 <= Count) & (Selection2 > 0) then
  152.           do
  153.              say 'Current value of field' Selection2 'is' Display.Selection2||'.  Enter new value.'
  154.              parse pull Data.Selection2
  155.              if Data.Selection2 = '' then
  156.                 signal FieldMenu
  157.              else
  158.              do
  159.                 Fields = ''
  160.                 X1 = lastpos(' ', Data.Selection2)
  161.                 do while X1 <> '0'
  162.                     Data2 = substr(Data.Selection2, X1+1)
  163.                     Data1 = substr(Data.Selection2, 1, X1-1)
  164.                     Data.Selection2 = Data1||''||Data2
  165.                     X1 = lastpos(' ', Data.Selection2)
  166.                 end
  167.                 do Num = 1 to Count
  168.                     Fields = Fields Data.Num
  169.                 end
  170.                 signal FieldMenu
  171.              end
  172.           end
  173.           else
  174.              signal FieldMenu
  175.        end
  176.  
  177.        when Selection = 'M' then
  178.        do
  179.           say 'Which field do you wish to mark/unmark for multiple selections?'
  180.           parse pull Selection3
  181.           if (Selection3 <= Count) & (Selection3 > 0) then
  182.           do
  183.              if pos('',Data.Selection3) = 1 then
  184.                 Data.Selection3 = substr(Data.Selection3,2)
  185.              else
  186.                 Data.Selection3 = ''||Data.Selection3
  187.              Fields = ''
  188.              do Num = 1 to Count
  189.                 Fields = Fields Data.Num
  190.              end
  191.              signal FieldMenu
  192.           end
  193.           else
  194.              signal FieldMenu
  195.        end
  196.  
  197.        when Selection = 'H' then
  198.        do
  199.           call GiveHelp
  200.        end
  201.  
  202.        when Selection = 'S' then
  203.        do
  204.           Save = '1'
  205.           return save
  206.        end
  207.  
  208.        when Selection = 'Q' then
  209.           exit
  210.  
  211.        otherwise
  212.           signal FieldMenu
  213.  
  214.        Selection = ''
  215.  
  216.     end
  217.  
  218. return
  219.  
  220.  
  221. ItemMenu:
  222.  
  223.     Count = words(Item.Selection)
  224.     call SysCls
  225.     say center(word(Fields, Selection) 'Sub-Menu', 80)
  226.     do Num = 1 to Count
  227.        Data.Num = word(Item.Selection, Num)
  228.         Display.Num = Data.Num
  229.  
  230.        X1 = lastpos('', Display.Num)
  231.        do while X1 <> '0'
  232.           Data2 = substr(Display.Num, X1+1)
  233.           Data1 = substr(Display.Num, 1, X1-1)
  234.           Display.Num = Data1||' '||Data2
  235.           X1 = lastpos('', Display.Num)
  236.        end
  237.  
  238.        call ArrangeDisplay
  239.        call SysCurPos Row, Col
  240.        say '('||Num||')' Display.Num
  241.     end
  242.     call SysCurPos 17, 0
  243.     say copies('-', 80)
  244.     call SysCurPos 17, 28
  245.     say LWhi||'Please Select From Below'||Non
  246.     call SysCurPos 18, 8
  247.     say '('||LBro||'A'||Non||')dd an Item  ('||LBro||'D'||Non||')elete an item  ('||LBro||'E'||Non||')dit an Item  ('||LBro||'P'||Non||')revious Menu'
  248.     call SysCurPos 19, 0
  249.     say copies('-', 80)
  250.     parse upper pull Selected
  251.  
  252.     select
  253.  
  254.        when Selected = 'A' then
  255.        do
  256.           Item.Selection = ''
  257.           say 'Enter new item.'
  258.           Count = Count + 1
  259.           parse pull Data.Count
  260.           X1 = lastpos(' ', Data.Count)
  261.           do while X1 <> '0'
  262.              Data2 = substr(Data.Count, X1+1)
  263.              Data1 = substr(Data.Count, 1, X1-1)
  264.              Data.Count = Data1||''||Data2 /* That's ASCII code ALT-29 */
  265.              X1 = lastpos(' ', Data.Count)
  266.           end
  267.           do Num = 1 to Count
  268.              Item.Selection = Item.Selection Data.Num
  269.           end
  270.           signal ItemMenu
  271.        end
  272.  
  273.        when Selected = 'D' then
  274.        do
  275.           say 'Which item do you wish to delete?'
  276.           parse pull Selected2
  277.           if (Selected2 <= Count) & (Selected2 > 0) then
  278.           do
  279.              say 'Are you sure you want to delete this item?'
  280.              parse pull Junk
  281.              if translate(Junk) = 'Y' then
  282.              do
  283.              Item.Selection = ''
  284.                 Data.Selected2 = ''
  285.                 do Num = 1 to Count
  286.                     Item.Selection = Item.Selection Data.Num
  287.                 end
  288.                 signal ItemMenu
  289.           end
  290.              else
  291.              signal ItemMenu
  292.           end
  293.           else
  294.              signal ItemMenu
  295.        end
  296.  
  297.        when Selected = 'E' then
  298.        do
  299.           say 'Which item do you wish to edit?'
  300.           parse pull Selected2
  301.           if (Selected2 <= Count) & (Selected2 > 0) then
  302.           do
  303.              say 'Current value of item' Selected2 'is' Display.Selected2||'.  Enter new value.'
  304.              parse pull Data.Selected2
  305.              if Data.Selected2 = '' then
  306.                 signal ItemMenu
  307.              else
  308.              do
  309.                 Item.Selection = ''
  310.                 X1 = lastpos(' ', Data.Selected2)
  311.                 do while X1 <> '0'
  312.                     Data2 = substr(Data.Selected2, X1+1)
  313.                     Data1 = substr(Data.Selected2, 1, X1-1)
  314.                     Data.Selected2 = Data1||''||Data2
  315.                     X1 = lastpos(' ', Data.Selected2)
  316.                 end
  317.                 do Num = 1 to Count
  318.                     Item.Selection = Item.Selection Data.Num
  319.                 end
  320.                 signal ItemMenu
  321.              end
  322.           end
  323.           else
  324.              signal ItemMenu
  325.        end
  326.  
  327.        when Selected = 'P' then
  328.           signal FieldMenu
  329.  
  330.        otherwise
  331.        signal ItemMenu
  332.     end
  333.  
  334.     Selected = ''
  335.  
  336. return
  337.  
  338.  
  339. ArrangeDisplay:
  340.  
  341.     Num2 = Num
  342.     if (Count / 45) > 1 then
  343.        do
  344.           HighCount = trunc(Count / 45)
  345.           do Count2 = 1 to HighCount
  346.              if (Num2 > (45 * Count2)) & (Num2 < (45 * (Count2 + 1)) + 1) then
  347.              do
  348.                 if Num2 = ((45 * Count2) + 1) then
  349.                 do
  350.                     say 'Press ENTER for next screen of Numbers.'
  351.                     pull Junk
  352.                     call SysCls
  353.                 end
  354.                 Num2 = Num2 - (45 * Count2)
  355.              end
  356.           end
  357.        end
  358.  
  359.        select
  360.           when (Num2 > 0) & (Num2 < 16) then
  361.           do
  362.              Row = Num2 + 1
  363.              Col = 2
  364.           end
  365.           when (Num2 > 15) & (Num2 < 31) then
  366.           do
  367.              Row = Num2 - 14
  368.              Col = 29
  369.           end
  370.           when (Num2 > 30) & (Num2 < 46) then
  371.           do
  372.              Row = Num2 - 29
  373.              Col = 56
  374.           end
  375.        end
  376.  
  377. return
  378.  
  379.  
  380. GiveHelp:
  381.  
  382.     call SysCls
  383.     say 'Add a Field allows you to create arrays from which other programs can'
  384.     say 'select one or more items.'
  385.     say
  386.     say 'Delete a Field will delete an entire array of items permanently.'
  387.     say LBro||'USE WITH GREAT CAUTION!'||Non
  388.     say
  389.     say 'Edit a Field allows you to edit the name of a chosen array.'
  390.     say
  391.     say 'Mark a Field allows you to set a chosen array to be selected from multiple'
  392.     say 'times by a calling program which supports this (ie. randomizer2.cmd).'
  393.     say
  394.     say 'Save will save the currently open data file with the currently active'
  395.     say 'array names and items within each array.'
  396.     say
  397.     say 'Quit will exit DataInput without saving changes you have made.'
  398.     key = SysGetKey('NOECHO')
  399.  
  400. return
  401.  
  402.  
  403. AnsiSetup:
  404.  
  405.     Esc=d2c(27)d2c(91)
  406.  
  407. /* Attributes */
  408.     Hig=Esc'1m'
  409.     Non=Esc'0m'
  410.  
  411. /* Foreground Colors */
  412.     Bla=Esc'30m'
  413.     Red=Esc'31m'
  414.     Gre=Esc'32m'
  415.     Bro=Esc'33m'
  416.     Blu=Esc'34m'
  417.     Pur=Esc'35m'
  418.     Tur=Esc'36m'
  419.     Whi=Esc'37m'
  420.     LBla=Hig||Bla
  421.     LRed=Hig||Red
  422.     LGre=Hig||Gre
  423.     LBro=Hig||Bro
  424.     LBlu=Hig||Blu
  425.     LPur=Hig||Pur
  426.     LTur=Hig||Tur
  427.     LWhi=Hig||Whi
  428.  
  429. /* Background Colors */
  430.     BBla=Esc'40m'
  431.     BRed=Esc'41m'
  432.     BGre=Esc'42m'
  433.     BBro=Esc'43m'
  434.     BBlu=Esc'44m'
  435.     BCya=Esc'45m'
  436.     BTur=Esc'46m'
  437.     BWhi=Esc'47m'
  438.  
  439. return
  440.  
  441.