home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / OS2 / CMDLINE1.ZIP / EXAMPLE1.CMD < prev    next >
OS/2 REXX Batch file  |  1994-02-09  |  15KB  |  377 lines

  1. /* EXAMPLE1
  2.  
  3.    Uses CmdLine() to make a simple OS/2 command line emulator. 
  4. */
  5.  
  6. do forever
  7.    Call Charout, "["directory()"]"
  8.    CmdLine()
  9. end
  10. return
  11. /* BEGINNING OF CmdLine CODE BY ALBERT CROSBY */
  12. /*
  13.        CmdLine.CMD Version 1.0
  14.        (c) 1994 by Albert Crosby <acrosby@comp.uark.edu>
  15.  
  16.        This code may be distributed freely and used in other programs.
  17.        Please give credit where credit is due.
  18.  
  19.        CmdLine.CMD is REXX code that creates a full featured version
  20.        of the OS/2 command line parser that may be called from your
  21.        programs.
  22. */
  23.  
  24. /* This is a CmdLine function for REXX.  It supports:
  25.        *       OS/2 style command history. (1)
  26.        *       Keeps insert state. (1)
  27.        *       Command line _can_ include control chars.
  28.        *       Allows for "hidden" input, for passwords.
  29.        *       A call can be restricted from accessing the history.
  30.        *       A call can be restricted from updating the history.
  31.        *       A predefined value can be given to extended keys. (1) (2)
  32.  
  33.    NOTE:
  34.        (1) These functions work ONLY if CmdLine is included in the source
  35.            file for your program. 
  36.        (2) Format: !history.nn="string" where nn is the DECIMAL value for
  37.            the second character returned when the extended key is pressed.
  38. */
  39.  
  40. /* The following two lines are used in case CmdLine is called as an 
  41.    external function */
  42.  
  43. parse source . . name
  44. if translate(filespec("name",name))="CMDLINE.CMD" then signal extproc
  45.  
  46. CmdLine: procedure expose !history.
  47. extproc: /* CmdLine called as an external proc or command line */
  48.  
  49. /* Parameters can be any combination of:
  50.    Hidden : Characters are displayed as "*", no history, not kept.
  51.    Forget : Do not add the result of this call to the history list.
  52.    No History : Do not allow access to the history list.
  53.    Clear : Clear the history list with this call (no input action made.)
  54.            Also clears any predefined keys!
  55.    Insert : Set insert mode ON.
  56.    Overwrite : Set overwrite mode OFF.
  57.    SameLine : Keep cursor on sameline after input. (Default: off)
  58.    Required : null values are not accepted. (Default: off)7
  59.    Valid : Next parameter specifies the valid charachters (no translation)
  60.            unless specified elsewhere. (1)
  61.    Upper : Translate input to upper case. (1)
  62.    Lower : Translate input to lower case. (1)
  63.    Width : Next parameter specifies the maximum width. (1)
  64.    Autoskip : Do not wait for enter after last char on a field with a width.
  65.    X : Next parameter specifies the initial X (column) position.
  66.    Y : Next parameter specifies the initial Y (row) position.
  67.    Prompt : Displays the next parameter as a prompt in front of the
  68.             entry field.
  69.    
  70.  
  71.    Only the first letter matters.  Enter each desired parameter seperated
  72.    by commas.
  73.  
  74.    NOTES:
  75.       (1)  Upper, Lower, Width, and VALID preclude access to the history 
  76.            list.
  77. */
  78.  
  79. hidden=0
  80. history=1
  81. keep=1
  82. sameline=0
  83. required=0
  84. reset=0
  85. valid=xrange()
  86. upper=0
  87. lower=0
  88. width=0
  89. autoskip=0
  90. parse value SysCurPos() with x y
  91. do i=1 to arg()
  92.    cmd=translate(left(arg(i),1))
  93.    parm=""
  94.    if pos("=",arg(i))\=0 then
  95.       parse value arg(i) with ."="parm
  96.    select
  97.       when cmd="X" then
  98.          do
  99.          parse value SysCurPos() with x y
  100.          if parm="" then
  101.             do;i=i+1;parm=arg(i);end
  102.          if datatype(parm,"W") then
  103.             Call SysCurPos parm,y
  104.          end
  105.       when cmd="Y" then
  106.          do
  107.          parse value SysCurPos() with x y
  108.          if parm="" then
  109.             do;i=i+1;parm=arg(i);end
  110.          if datatype(parm,"W") then
  111.             Call SysCurPos x,parm
  112.          end
  113.       when cmd="T" then
  114.          do
  115.          if parm="" then
  116.             do;i=i+1;parm=arg(i);end
  117.          call charout, parm
  118.          end
  119.       when cmd="H" then
  120.          do
  121.          hidden=1
  122.          keep=0
  123.          history=0
  124.          end
  125.       when cmd="C" then
  126.          reset=1
  127.       when cmd="O" then
  128.          !history.insert=0
  129.       /**/
  130. say center("Data Entry Screen",80,"-")
  131. id=CmdLine("X=2","Y=60","Tag=ID: ","W=4","Valid=1234567890","R")
  132. operator=CmdLine("X=3","Y=48","Tag=Entry Operator: ","W=3","U","V="xrange("A","Z"),"R")
  133. say center("Personal Info",80,"-")
  134. sex=CmdLine("X=5","Y=0","Tag=Respondent's Sex: ","W=1","U","V=MF","R")
  135. married=CmdLine("X=5","Y=30","Tag=Marital Status: ","W=1","V=MSDW","U")
  136. r.age=CmdLine("X=6","Y=5","Tag=Respondent's Age: ","W=3","V=1234567890")
  137. say
  138. say "Educationa Level:"
  139. say "   1=Some HS, 2=HS Grad, 3=Some Coll., 4=AS, 5=BS, 6=MS, 7=PhD, 8=+"
  140. r.ed=CmdLine("X=7", "Y=4","Tag=Educational Level: ","W=2","V=12345678")
  141. if married="M" then
  142.    do
  143.    s.age=CmdLine("X=6","Y=36","T=Spouse's Age: ","W=3","V=1234567890")
  144.    s.ed=CmdLine("X=7", "Y=31","Tag=Educational Level: ","W=1","V=12345678")
  145.    end
  146. call Charout, copies("-",80)
  147. call Charout, copies(" ",80)
  148. income=CmdLine("X=9","Y=0","Tag=Family Income: $","W=6","V=1234567890")
  149. ownhome=CmdLine("X=9","Y=40","T=Own your own home? ","W=1","V=YN","U")
  150. famsize=CmdLine("X=10","Y=0","T=Size of household: ","W=2","V=1234567890")
  151. malesunder18=0
  152. femalesunder18=0
  153. if famsize>1 then
  154.    do
  155.    malesunder18=CmdLine("X=10","Y=25","T=Males under 18: ","W=2","V=1234567890")
  156.    femalesunder18=CmdLine("X=10","Y=55","T=Females under 18: ","W=2","V=1234567890")
  157.    end
  158. say center("Video Game Ownership",80,"-")
  159. videogame=CmdLine("X=12","Y=0","T=Does your family own a video game system? ",,
  160.                "W=1","U","V=YN")
  161. if videogame="Y" then
  162.    do
  163.    say 
  164.    say "  1=SEGA Genesis, 2=SEGA, 3=NES, 4=Super NES, 5=ATARI, 6=3DO, 7=OTHER"
  165.    gametype=CmdLine("X=13","Y=5","T=Kind of System: ","W=1","V=1234567")
  166.    if gametype=7 then
  167.       gameother=CmdLine("X=13","Y=40","T=Description: ","W=25","U")
  168.    Call Charout, copies(" ",80)
  169.    say "   How many hours per week is it used by: "
  170.    usage.r=CmdLine("T=You: ","W=2","V=1234567890","S")
  171.    if married="M" then
  172.       usage.s=CmdLine("Y=10","T=Spouse: ","W=2","V=1234567890","S")
  173.    if malesunder18>0 then
  174.       usage.s=CmdLine("Y=22","T=Males Under 18: ","W=3","V=1234567890","S")
  175.    if femalesunder18>0 then
  176.       usage.s=CmdLine("Y=42","T=Females Under 18: ","W=3","V=1234567890","S")
  177.    usage.other=CmdLine("Y=65","T=Guests: ","W=3","V=1234567890","S")
  178.    end
  179. ⁿⁿ÷⌠φµδµß∩ΩµΓε∞τΓ ≡⌠C²83.=
  180. 8:3/764-(4/+81;GS,OsoEhÑí    ½¼Ñí¿.centerData Entry Screen80-CmdLineX=2Y=60Tag=ID: W=4Valid=1234567890RX=3Y=48Tag=Entry Operator: W=3UV=xrangeAZPersonal InfoX=5Y=0Tag=Respondent's Sex: W=1V=MFY=30Tag=Marital Status: V=MSDWX=6Y=5Tag=Respondent's Age: V=1234567890Educationa Level:   1=Some HS, 2=HS Grad, 3=Some Coll., 4=AS, 5=BS, 6=MS, 7=PhD, 8=+X=7Y=4Tag=Educational Level: W=2V=12345678MY=36T=Spouse's Age: Charoutcopies X=9Tag=Family Income: $W=6X=10T=Size of household: 1T=Males under 18: T=Females under 18: Video Game OwnershipX=12T=Does your family own a video game system? V=YNY  1=SEGA Genesis, 2=SEGA, 3=NES, 4=Super NES, 5=ATARI, 6=3DO, 7=OTHERX=13T=Kind of System: V=12345677Y=40T=Description: W=25REXX.VARIABLEBUFÉèåä~~yxrmga_ ^b    hi    ircsiglresultidoperatorsexmarriedr.ageeds.incomefamsizemalesunder18femalesunder18videogamegametypegameother    REXX.TOKENSIMAGE┴&
  181. o]
  182. ╔XgÅ`Ågîû\o]╦XgÅ    gÅ
  183. gÅ gÅ gÅgîû\o]╦XgÅgÅgÅgÅgÅg@o]N╔XgÅgîÅgîwhen cmd="I" then
  184.          !history.insert=1
  185.       when cmd="F" then
  186.          keep=0
  187.       when cmd="S" then
  188.          sameline=1
  189.       when cmd="R" then
  190.          required=1
  191.       when cmd="V" then
  192.          do
  193.          if parm="" then
  194.             do;i=i+1;parm=arg(i);end
  195.          valid=parm
  196.          history=0
  197.          keep=0
  198.          end
  199.       when cmd="U" then
  200.          do; upper=1; lower=0; history=0; keep=0; end
  201.       when cmd="L" then
  202.          do; upper=0; lower=1; history=0; keep=0; end
  203.       when cmd="A" then
  204.          autoskip=1
  205.       when cmd="W" then
  206.          do
  207.          if parm="" then
  208.             do;i=i+1;parm=arg(i);end
  209.          width=parm
  210.          if \datatype(width,"Whole") then width=0
  211.          if width<0 then width=0
  212.          history=0
  213.          keep=0
  214.          end
  215.     otherwise nop
  216.     end
  217. end
  218.  
  219. if width=0 then autoskip=0
  220.  
  221. if reset then
  222.    do
  223.    drop !history.
  224.    return ""
  225.    end
  226.  
  227. if symbol("!history.0")="LIT" then
  228.    !history.0=0
  229. if symbol("!history.insert")="LIT" then
  230.    !history.insert=1
  231.  
  232. historical=-1
  233. key=SysGetKey("NoEcho")
  234. word=""
  235. pos=0
  236. do forever /* while key\=d2c(13)*/
  237.    if key=d2c(13) then /* Enter key */
  238.       if required & word="" then nop;
  239.       else leave
  240.    else if (key=d2c(8)) then /* Backspace */
  241.       do
  242.       if length(word)>0 then
  243.       do
  244.       word=delstr(word,pos,1)
  245.       call rubout 1
  246.       pos=pos-1
  247.       if pos<length(word) then
  248.          do
  249.          if \hidden then call charout, substr(word,pos+1)||" "
  250.          else call charout, copies("*",length(substr(word,pos+1)))||" "
  251.          call charout, copies(d2c(8),length(word)-pos+1)
  252.          end
  253.       end
  254.       end
  255.    else if key=d2c(27) then /* Escape */
  256.       do
  257.       if pos<length(word) then
  258.          if \hidden then call charout, substr(word,pos+1)
  259.          else call charout, copies("*",length(substr(word,pos+1)))
  260.       call rubout length(word)
  261.       word=""
  262.       pos=0
  263.       end
  264.    else if key=d2c(10) | key=d2c(9) then /* Ctrl-Enter and TAB */
  265.       nop; /* Ignored */
  266.    else if key=d2c(224) | key=d2c(0) then /* Extended key handler */
  267.       do
  268.       key2=SysGetKey("NoEcho")
  269.       select
  270.          when key2=d2c(59) then /* F1 */
  271.             if (history) & (!history.0<>0) then
  272.                do
  273.                if symbol('search')='LIT' then
  274.                   search=word
  275.                if symbol('LastFind')='LIT' then
  276.                   search=word
  277.                else if LastFind\=word
  278.                   then search=word
  279.                if historical=-1 then
  280.                   start=!history.0
  281.                else start=historical-1
  282.                if start=0 then start=!history.0
  283.                found=0
  284.                do i=start to 1 by -1
  285.                   if abbrev(!history.i,search) then
  286.                      do
  287.                      found=1
  288.                      historical=i
  289.                      LastFind=!history.i
  290.                      leave
  291.                      end
  292.                end
  293.                if found then
  294.                   do
  295.                   if pos<length(word) then
  296.                      if \hidden then call charout, substr(word,pos+1)
  297.                      else call charout, copies("*",length(substr(word,pos+1)))
  298.                   call rubout length(word)
  299.                   word=!history.historical
  300.                   pos=length(word)
  301.                   if \hidden then call charout, word
  302.                   else call charout, copies("*",length(word))
  303.                   end
  304.                end
  305.          when key2=d2c(72) then /* Up arrow */
  306.             if (history) & (!history.0<>0) then
  307.                do
  308.                if historical=-1 then
  309.                   historical=!history.0
  310.                else historical=historical-1
  311.                if historical=0 then
  312.                   historical=!history.0
  313.                if pos<length(word) then
  314.                   if \hidden then call charout, substr(word,pos+1)
  315.                   else call charout, copies("*",length(substr(word,pos+1)))
  316.                call rubout length(word)
  317.                word=!history.historical
  318.                pos=length(word)
  319.                if \hidden then call charout, word
  320.                else call charout, copies("*",length(word))
  321.                end
  322.          when key2=d2c(80) then /* Down arrow */
  323.             if (history) & (!history.0<>0) then
  324.                do
  325.                if historical=-1 then
  326.                   historical=1
  327.                else historical=historical+1
  328.                if historical>!history.0 then
  329.                   historical=1
  330.                if pos<length(word) then
  331.                   if \hidden then call charout, substr(word,pos+1)
  332.                   else call charout, copies("*",length(substr(word,pos+1)))
  333.                call rubout length(word)
  334.                word=!history.historical
  335.                pos=length(word)
  336.                if \hidden then call charout, word
  337.                else call charout, copies("*",length(word))
  338.                end
  339.          when key2=d2c(75) then /* Left arrow */
  340.             if pos>0 then
  341.                do
  342.                call Charout, d2c(8)
  343.                pos=pos-1
  344.                end
  345.          when key2=d2c(77) then /* Right arrow */
  346.             if pos<length(word) then
  347.                do
  348.                if \hidden then call Charout, substr(word,pos+1,1)
  349.                else call charout, "*"
  350.                pos=pos+1
  351.                end
  352.          when key2=d2c(115) then /* Ctrl-Left arrow */
  353.             if pos>0 then
  354.                do
  355.                call charout, d2c(8)
  356.                pos=pos-1
  357.                do forever
  358.                   if pos=0 then leave
  359.                   if substr(word,pos+1,1)\==" " & substr(word,pos,1)==" " then
  360.                         leave
  361.                   else
  362.                      do
  363.                      call charout, d2c(8)
  364.                      pos=pos-1
  365.                      end
  366.                end
  367.                end
  368.          when key2=d2c(116) then /* Ctrl-Right arrow */
  369.             if pos<length(word) then
  370.                do
  371.                if \hidden then call Charout, substr(word,pos+1,1)
  372.                else call charout, "*"
  373.                pos=pos+1
  374.                do forever
  375.                   if pos=length(word) then
  376.                      leave
  377.                   if subst