Check output device is a terminal: Difference between revisions

m
→‎{{header|REXX}}: changed wording a bit, fixed a typo, added whitespace, changed some comments, used a template for the output section, added the output from R4 REXX.
(added Ol)
m (→‎{{header|REXX}}: changed wording a bit, fixed a typo, added whitespace, changed some comments, used a template for the output section, added the output from R4 REXX.)
Line 496:
{{works with|Personal REXX under DOS or in a DOS window under MS Windows}}
{{works with|Regina in a DOS window under MS Windows}}
 
 
Programming note:   The comment about the REXX statements have to be on one line isn't quite true,
<br>but because the REXX special variable '''SIGL''' is defined where it's executed, it makes coding simpler.
 
<br><br>'''SIGL''' &nbsp; is set to the REXX statment number where:
 
<br><br>'''SIGL''' &nbsp; is set to the REXX statmentstatement number where:
:::* &nbsp; a '''CALL''' statement is used
:::* &nbsp; a ''function'' is invoked
:::* &nbsp; a '''SIGNAL''' statement is used
 
Method used: &nbsp; since REXX has no direct way of determining if the STDIN is a terminal or not, the REXX code (below)
<br>actually &nbsp; ''raises'' &nbsp; (which is no way to run a railroad) &nbsp; a syntax error when attempting to read the 2<sup>nd</sup> line from &nbsp; STDIN,
<br>which causes a routine &nbsp; (named '''syntax:''') &nbsp; to get control, &nbsp; determines where the syntax error occurred, &nbsp; and returns an
<br>an appropriate string indicating if STDIN is a '''terminal''' &nbsp; (or '''other''').
<br><br>Note that under VM/CMS, this can be accomplished with a (host) command within REXX and then examining the results.
<br>On IBM mainframes, a user can have STDIN defined, but the terminal can be ''disconnected''.
<lang rexx>/*REXX program determines if the STDIN is a terminal or other. */
signal on syntax /*if syntax error, jump──► SYNTAX*/
say 'output device:' testSTDIN() /*displays terminal ──or── other */
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────TESTSTDIN subroutine────────────────*/
testSTDIN: syntax.=1; signal .; .: z.=sigl; call linein ,2; ..: syntax.=0
return z.. /* [↑] must all be on one line.*/
/*──────────────────────────────────SYNTAX subroutine───────────────────*/
syntax: z..='other' /*when SYNTAX occur, come here. */
if syntax. then do /*handling STDIN thingy error? */
if sigl==z. then z..='terminal'; signal .. /*stdin ?*/
end /* [↑] can't use a RETURN here.*/
 
<lang rexx>/*REXX program determines if the STDIN is a terminal device or other. */
/* ··· handle other REXX syntax errors here ··· */</lang>
signal on syntax /*if syntax error, jump──►then jump ──► SYNTAX*/
'''output'''
say 'output device:' testSTDIN() /*displays terminal ──or── other */
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
testSTDIN: syntax.=1; signal .; .: z.= sigl; call linein ,2; ..: syntax.= 0; return z..
return z.. /* [↑] must all/should be all on one line.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
syntax: z..= 'other' /*when a SYNTAX occur,error occurs, come here. */
if syntax. then do /*are we handling STDIN thingy error? */
if sigl==z. then z..= 'terminal'; signal .. /*is this a stdin ?*/
end /* [↑] can't use a RETURN here. */
 
/* ··· handle other REXX syntax errors here ··· */</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
output device: terminal
</pre>
 
 
 
 
{{works with|R4 REXX under DOS or in a DOS window under MS Windows}}
 
 
The following is the output when used with '''R4''' REXX:
 
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Reading console input (Press Ctrl-Z to quit):
◄■■■■■■■■ user input (pressed ENTER)
◄■■■■■■■■ user input (pressed ENTER a 2nd time)
output device: 6
</pre>