home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / randomz4.zip / DataInput.cmd next >
OS/2 REXX Batch file  |  2001-07-29  |  11KB  |  513 lines

  1. /*
  2.     DataInput 4.0
  3.     (c) 2001 by Don Eitner
  4.  
  5.     Front-end to create database for use with 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 SysCls
  18. call AnsiSetup
  19.  
  20. if DataFile = '' then
  21. do
  22.     call CharOut, 'Enter the name of the data file you wish to use: '
  23.     parse pull DataFile
  24.     if DataFile = '' then
  25.         DataFile = 'RandomData.txt'
  26. end
  27.  
  28. delim = '09'x
  29. delim2 = ','
  30.  
  31. Fields = linein(DataFile,,1)
  32. Count = puns(Fields, delim)
  33.  
  34. do Num = 1 to Count
  35.     Item.Num = linein(DataFile,,1)
  36. end
  37.  
  38. call lineout(DataFile)
  39.  
  40. do forever
  41.     call FieldMenu
  42.     if Save = 1 then
  43.         signal SaveIt
  44. end
  45.  
  46. exit
  47.  
  48.  
  49. SaveIt:
  50.  
  51.     RC = SysFileDelete(DataFile)
  52.     call lineout DataFile, Fields
  53.     do Num = 1 to Count
  54.         call lineout DataFile, Item.Num
  55.     end
  56.     call lineout(DataFile)
  57.  
  58. return
  59.  
  60.  
  61. FieldMenu:
  62.  
  63.     Count = puns(Fields, delim)
  64.     call SysCls
  65.     say center('Main Fields Menu', 80)
  66.     do Num = 1 to Count
  67.         Data.Num = pun(Fields, delim, Num)
  68.         Display.Num = pun(Data.Num, delim2, 1)
  69.         call ArrangeDisplay
  70.     end
  71.     call SysCurPos 18, 0
  72.     say copies('-', 80)
  73.     call SysCurPos 18, 28
  74.     say LWhi||'Please Select From Below'||Non
  75.     call SysCurPos 19, 8
  76.     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'
  77.     call SysCurPos 20, 8
  78.     say '('||LBro||'H'||Non||')elp  ('||LBro||'S'||Non||')ave & Quit  ('||LBro||'Q'||Non||')uit w/o Save  Or enter a # from above'
  79.     call SysCurPos 21, 0
  80.     say copies('-', 80)
  81.     call ClearInput
  82.     parse upper pull Selection
  83.  
  84.     select
  85.         when (datatype(Selection) = 'NUM') & (Selection <= Count) then
  86.             signal ItemMenu
  87.  
  88.         when Selection = 'A' then
  89.             do
  90.                 call ClearInput
  91.                 call CharOut, 'Enter new field name: '
  92.                 Count = Count + 1
  93.                 parse pull Data.Count
  94.                 Item.Count = 'edit me!'
  95.                 call RewriteFields
  96.                 signal FieldMenu
  97.             end
  98.  
  99.         when Selection = 'D' then
  100.             do
  101.                 call ClearInput
  102.                 call CharOut, 'Which field # do you wish to delete? '
  103.                 parse pull Selection2
  104.                 if (Selection2 <= Count) & (Selection2 > 0) then
  105.                     do
  106.                         call ClearInput
  107.                         call CharOut, 'Are you sure you want to delete this field and all its items? '
  108.                         parse pull Junk
  109.                         if translate(Junk) = 'Y' then
  110.                             do
  111.                                 Data.Selection2 = ''
  112.                                 Item.Selection2 = ''
  113.                                 call RewriteFields
  114.                                 do Num = 2 to Count
  115.                                     PrevNum = Num - 1
  116.                                     if Item.PrevNum = '' then
  117.                                         do
  118.                                             Item.PrevNum = Item.Num
  119.                                             Item.Num = ''
  120.                                         end
  121.                                 end
  122.                                 signal FieldMenu
  123.                             end
  124.                         else
  125.                             signal FieldMenu
  126.                     end
  127.                 else
  128.                     signal FieldMenu
  129.             end
  130.  
  131.         when Selection = 'E' then
  132.             do
  133.                 call ClearInput
  134.                 call CharOut, 'Which field # do you wish to edit? '
  135.                 parse pull Selection2
  136.                 if (Selection2 <= Count) & (Selection2 > 0) then
  137.                     do
  138.                         call ClearInput
  139.                         call CharOut, 'Current value of field' Selection2 'is' Display.Selection2||'.  Enter new value: '
  140.                         parse pull Data.Selection2
  141.                         if Data.Selection2 = '' then
  142.                             signal FieldMenu
  143.                         else
  144.                         do
  145.                             call RewriteFields
  146.                             signal FieldMenu
  147.                         end
  148.                     end
  149.                 else
  150.                     signal FieldMenu
  151.             end
  152.  
  153.         when Selection = 'M' then
  154.             do
  155.                 call ClearInput
  156.                 call CharOut, 'Which field # do you wish to mark/unmark for multiple selections? '
  157.                 parse pull Selection2
  158.                 if (Selection2 <= Count) & (Selection2 > 0) then
  159.                     do
  160.                         if pos('',Data.Selection2) = 1 then
  161.                             do
  162.                                 Data.Selection2 = pun(Data.Selection2, delim2, 1)
  163.                                 Data.Selection2 = substr(Data.Selection2,2)||',1,1'
  164.                             end
  165.                         else
  166.                             do
  167.                                 Data.Selection2 = pun(Data.Selection2, delim2, 1)
  168.                                 Data.Selection2 = ''||Data.Selection2||',0,'||puns(Item.Selection2, delim)
  169.                             end
  170.                         Fields = ''
  171.                         do Num = 1 to Count
  172.                             if Data.Num = '' then
  173.                                 iterate
  174.                             if Fields = '' then
  175.                                 Fields = Data.Num
  176.                             else
  177.                                 Fields = Fields||'09'x||Data.Num
  178.                         end
  179.                         signal FieldMenu
  180.                     end
  181.                 else
  182.                     signal FieldMenu
  183.             end
  184.  
  185.         when Selection = 'H' then
  186.             do
  187.                 call GiveHelp
  188.             end
  189.  
  190.         when Selection = 'S' then
  191.             do
  192.                 Save = '1'
  193.                 return save
  194.             end
  195.  
  196.         when Selection = 'Q' then
  197.             exit
  198.  
  199.         otherwise
  200.             signal FieldMenu
  201.  
  202.         Selection = ''
  203.  
  204.     end
  205.  
  206. return
  207.  
  208.  
  209. ItemMenu:
  210.  
  211.     Count = puns(Item.Selection, delim)
  212.     call SysCls
  213.     say center(pun(pun(Fields, delim, Selection), delim2, 1) 'Sub-Menu', 80)
  214.     do Num = 1 to Count
  215.         Data.Num = pun(Item.Selection, delim, Num)
  216.         Display.Num = pun(Data.Num, delim2, 1)
  217.         call ArrangeDisplay
  218.     end
  219.     call SysCurPos 18, 0
  220.     say copies('-', 80)
  221.     call SysCurPos 18, 28
  222.     say LWhi||'Please Select From Below'||Non
  223.     call SysCurPos 19, 8
  224.     say '('||LBro||'A'||Non||')dd an Item  ('||LBro||'D'||Non||')elete an item  ('||LBro||'E'||Non||')dit an Item  ('||LBro||'P'||Non||')revious Menu'
  225.     call SysCurPos 20, 0
  226.     say copies('-', 80)
  227.     call ClearInput
  228.     parse upper pull Selected
  229.  
  230.     select
  231.         when Selected = 'A' then
  232.             do
  233.                 call ClearInput
  234.                 call CharOut, 'Enter new item: '
  235.                 Count = Count + 1
  236.                 parse pull Data.Count
  237.                 call RewriteItems
  238.                 signal ItemMenu
  239.             end
  240.  
  241.         when Selected = 'D' then
  242.             do
  243.                 call ClearInput
  244.                 call CharOut, 'Which item # do you wish to delete? '
  245.                 parse pull Selected2
  246.                 if (Selected2 <= Count) & (Selected2 > 0) then
  247.                     do
  248.                         call ClearInput
  249.                         call CharOut, 'Are you sure you want to delete this item? '
  250.                         parse pull Junk
  251.                         if translate(Junk) = 'Y' then
  252.                             do
  253.                                 Data.Selected2 = ''
  254.                                 call RewriteItems
  255.                                 signal ItemMenu
  256.                             end
  257.                         else
  258.                             signal ItemMenu
  259.                     end
  260.                 else
  261.                     signal ItemMenu
  262.             end
  263.  
  264.         when Selected = 'E' then
  265.             do
  266.                 call ClearInput
  267.                 call CharOut, 'Which item # do you wish to edit? '
  268.                 parse pull Selected2
  269.                 if (Selected2 <= Count) & (Selected2 > 0) then
  270.                     do
  271.                          call ClearInput
  272.                         call CharOut, 'Current value of item' Selected2 'is' Display.Selected2||'.  Enter new value: '
  273.                         parse pull Data.Selected2
  274.                         if Data.Selected2 = '' then
  275.                             signal ItemMenu
  276.                         else
  277.                             do
  278.                                 call RewriteItems
  279.                                 signal ItemMenu
  280.                             end
  281.                     end
  282.                 else
  283.                     signal ItemMenu
  284.             end
  285.  
  286.         when Selected = 'P' then
  287.             signal FieldMenu
  288.  
  289.         otherwise
  290.             signal ItemMenu
  291.     end
  292.  
  293.     Selected = ''
  294.  
  295. return
  296.  
  297.  
  298. ArrangeDisplay:
  299.  
  300.     Num2 = Num
  301.     HighCount = trunc(Count / 45)
  302.     do Count2 = 1 to HighCount
  303.         if (Num > 45 * Count2) & (Num < (45 * (Count2 + 1) + 1)) then
  304.             Num2 = Num - (45 * Count2)
  305.     end
  306.  
  307.     select
  308.         when (Num2 > 0) & (Num2 < 16) then
  309.             do
  310.                 Row = Num2 + 1
  311.                 Col = 2
  312.             end
  313.         when (Num2 > 15) & (Num2 < 31) then
  314.             do
  315.                 Row = Num2 - 14
  316.                 Col = 29
  317.             end
  318.         when (Num2 > 30) & (Num2 < 46) then
  319.             do
  320.                 Row = Num2 - 29
  321.                 Col = 56
  322.             end
  323.         otherwise
  324.             do
  325.                 say "Error!  Num2 out of range:" Num2
  326.                 exit
  327.             end
  328.     end
  329.  
  330.     call SysCurPos Row, Col
  331.     call CharOut, LTur||Num||')'||Non Display.Num
  332.  
  333.     do Count2 = 0 to HighCount
  334.         if (Num = 45 * Count2) & (Num <> Count) then
  335.             do
  336.                 call SysCurPos 17, 0
  337.                 call CharOut, LPur||"Showing" Num - 44||"-"||Num "of" Count||". ENTER for more."||Non
  338.                 pull junk
  339.                     call SysCls
  340.             end
  341.         if (Num = Count) & (Num <> 45 * Count2) then
  342.             do
  343.                 call SysCurPos 17, 0
  344.                 call CharOut, LPur||"Showing" Max(Num - 44, 45 * Count2 + 1)||"-"||Num "of" Count||"."||Non
  345.             end
  346.         if (Num = Count) & (Num = 45 * Count2) then
  347.             do
  348.                 call SysCurPos 17, 0
  349.                 call CharOut, LPur||"Showing" Num - 44||"-"||Num "of" Count||"."||Non
  350.             end
  351.     end
  352.  
  353. return
  354.  
  355.  
  356. ClearInput:
  357.  
  358.     call SysCurPos 22, 0
  359.     say copies(' ', 80)
  360.     call SysCurPos 22, 0
  361.  
  362. return
  363.  
  364.  
  365. RewriteFields:
  366.  
  367.     Fields = ''
  368.     do Num = 1 to Count
  369.         if Data.Num = '' then
  370.             iterate
  371.         if Fields = '' then
  372.             Fields = Data.Num
  373.         else
  374.             Fields = Fields||'09'x||Data.Num
  375.     end
  376.  
  377. return
  378.  
  379.  
  380. RewriteItems:
  381.  
  382.     Item.Selection = ''
  383.     do Num = 1 to Count
  384.         if Data.Num = '' then
  385.             iterate
  386.         if Item.Selection = '' then
  387.             Item.Selection = Data.Num
  388.         else
  389.             Item.Selection = Item.Selection||'09'x||Data.Num
  390.     end
  391.  
  392. return
  393.  
  394.  
  395. GiveHelp:
  396.  
  397.     call SysCls
  398.     say 'Add a Field allows you to create arrays from which other programs can'
  399.     say 'select one or more items.'
  400.     say
  401.     say 'Delete a Field will delete an entire array of items permanently.'
  402.     say LBro||'Use with great caution!'||Non
  403.     say
  404.     say 'Edit a Field allows you to edit the name of a chosen array.'
  405.     say
  406.     say 'Mark a Field allows you to set a chosen array to be selected from multiple'
  407.     say 'times by a calling program which supports this (ie. randomizer.cmd).'
  408.     say
  409.     say 'Save will save the currently open data file with the currently active'
  410.     say 'array names and items within each array.'
  411.     say
  412.     say 'Quit will exit DataInput without saving changes you have made.'
  413.     key = SysGetKey('NOECHO')
  414.  
  415. return
  416.  
  417.  
  418. AnsiSetup:
  419.  
  420.     Esc=d2c(27)d2c(91)
  421.  
  422. /* Attributes */
  423.     Hig=Esc'1m'
  424.     Non=Esc'0m'
  425.  
  426. /* Foreground Colors */
  427.     Bla=Esc'30m'
  428.     Red=Esc'31m'
  429.     Gre=Esc'32m'
  430.     Bro=Esc'33m'
  431.     Blu=Esc'34m'
  432.     Pur=Esc'35m'
  433.     Tur=Esc'36m'
  434.     Whi=Esc'37m'
  435.     LBla=Hig||Bla
  436.     LRed=Hig||Red
  437.     LGre=Hig||Gre
  438.     LBro=Hig||Bro
  439.     LBlu=Hig||Blu
  440.     LPur=Hig||Pur
  441.     LTur=Hig||Tur
  442.     LWhi=Hig||Whi
  443.  
  444. /* Background Colors */
  445.     BBla=Esc'40m'
  446.     BRed=Esc'41m'
  447.     BGre=Esc'42m'
  448.     BBro=Esc'43m'
  449.     BBlu=Esc'44m'
  450.     BCya=Esc'45m'
  451.     BTur=Esc'46m'
  452.     BWhi=Esc'47m'
  453.  
  454. return
  455.  
  456.  
  457. puns: procedure
  458.  
  459.     PARSE ARG string, delim
  460.     CALL split string, delim
  461.  
  462. RETURN substring.0
  463.  
  464.  
  465. pun: procedure
  466.  
  467.     PARSE ARG string, delim, word
  468.     CALL split string, delim
  469.  
  470. RETURN substring.word
  471.  
  472.  
  473. delpun: procedure
  474.  
  475.     PARSE ARG string, delim, word, length
  476.     CALL split string, delim
  477.     DO x = word to (word - 1 + length)
  478.         substring.x = ''
  479.     END
  480.     DO y = 1 to substring.0
  481.         IF substring.y = '' THEN
  482.             iterate
  483.         IF string = '' THEN
  484.             string = substring.y
  485.         ELSE
  486.             string = string||delim||substring.y
  487.     END
  488.  
  489. RETURN string
  490.  
  491.  
  492. split:
  493.  
  494.     PARSE ARG string, delim
  495.     num = 0
  496.     DO WHILE string <> ''
  497.         num = num + 1
  498.         stop = pos(delim, string)
  499.         IF stop = 0 THEN
  500.             stop = length(string)+1
  501.         substring.num = substr(string, 1, stop-1)
  502.         string = substr(string, stop+1)
  503.     END
  504.     substring.0 = num
  505.  
  506.     IF delim = ',' | delim = ';' | delim = ':' THEN
  507.         DO x = 1 to substring.0
  508.             substring.x = strip(substring.x,b,'"')
  509.         END
  510.  
  511. RETURN
  512.  
  513.