Anonymous user
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''' is set to the REXX statment number where:▼
:::* a '''CALL''' statement is used
:::* a ''function'' is invoked
:::* a '''SIGNAL''' statement is used
Method used: since REXX has no direct way of determining if the STDIN is a terminal or not, the REXX code (below)
<br>actually ''raises'' (which is no way to run a railroad) a syntax error when attempting to read the 2<sup>nd</sup> line from STDIN,
<br>which causes a routine (named '''syntax:''') to get control, determines where the syntax error occurred, and returns
<br>an appropriate string indicating if STDIN is a '''terminal''' (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: syntax.=1; signal .; .: z.=sigl; call linein ,2; ..: syntax.=0▼
return z.. /* [↑] must all be on one line.*/▼
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>▼
▲say 'output device:' testSTDIN() /*displays terminal ──or── other */
▲exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
▲ 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= 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= 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>
|