Copy stdin to stdout: Difference between revisions
Content deleted Content added
→{{header|D}}: add crystal implementation |
Added Commodore BASIC. |
||
Line 99: | Line 99: | ||
std::cout << std::cin.rdbuf(); |
std::cout << std::cin.rdbuf(); |
||
}</lang> |
}</lang> |
||
=={{header|Commodore BASIC}}== |
|||
Commodore BASIC assigns device #0 (keyboard) as the standard input device, and device #3 (screen) as the standard output device. By opening channels for input and/or output, data can be sent to/from files, printers, and other peripheral devices. Although the keyboard and screen are the default input and output devices, they can be read from and written to using the same conventions as other devices, which is useful if a program wants to allow a user to direct output elsewhere (e.g. printing a hard copy of a report instead of displaying it on the screen) |
|||
{| class="wikitable" |
|||
|+Commodore Device Addresses |
|||
!Number |
|||
!Device |
|||
|- |
|||
|0 |
|||
|Keyboard |
|||
|- |
|||
|1 |
|||
|Datassette Tape Drive |
|||
|- |
|||
|2 |
|||
|User Port (RS-232) |
|||
|- |
|||
|3 |
|||
|Text Screen |
|||
|- |
|||
|4 |
|||
|rowspan="2"|IEC Bus Printers |
|||
|- |
|||
|5 |
|||
|- |
|||
|6 |
|||
|rowspan="2"|IEC Bus Plotters |
|||
|- |
|||
|7 |
|||
|- |
|||
|8-30 |
|||
|Floppy/Hard Disk Drives |
|||
|} |
|||
The following program opens channels to devices chosen by the user, then uses the GET# and PRINT# I/O statements instead of the standard GET and PRINT (for typical keyboard/screen interaction.) When keyboard and/or screen are chosen, BASIC ignores the extra filename and file type parameters normally used for other devices. Peripheral devices (tape, disk drive) use STATUS register to flag end of file, however the keyboard does not. When using the keyboard, the program terminates on a CTRL-Z. |
|||
<lang gwbasic>10 print chr$(147);chr$(14); |
|||
11 print "0:Keyboard 1:Tape 2:RS-232 3:Screen" |
|||
12 print "4-7:printers/plotters" |
|||
13 print "8-11:Disk Drives":print |
|||
14 input "Input device";d1 |
|||
15 if d1=1 or d1>=8 then input "Filename for INPUT";i$ |
|||
16 input "Output device";d2 |
|||
17 if d2=1 or d2>=8 then input "Filename for OUTPUT";o$ |
|||
18 print:if d1=0 then print "Begin typing. Press CTRL-Z to end.":print |
|||
20 open 5,d1,5,"0:"+i$+",s,r" |
|||
30 open 2,d2,2,"@0:"+o$+",s,w" |
|||
40 get#5,a$ |
|||
50 if (d1=0 and a$=chr$(26)) or (d1>0 and st>0) then close 5:close 2:end |
|||
60 print#2,a$; |
|||
70 goto 40</lang> |
|||
{{output}} |
|||
The output sample below demonstrates the following device input-output combinations: |
|||
* Keyboard (0) to Screen (3) |
|||
* Keyboard (0) to Disk File (8) |
|||
* Disk File (8) to Screen (3) |
|||
<pre> |
|||
0:Keyboard 1:Tape 2:RS-232 3:Screen |
|||
4-7:printers/plotters |
|||
8-11:Disk Drives |
|||
Input device? 0 |
|||
Output device? 3 |
|||
Begin typing. Press CTRL-Z to end. |
|||
Hello. This is so much fun on Rosetta Code! |
|||
Goodbye! |
|||
ready. |
|||
run |
|||
0:Keyboard 1:Tape 2:RS-232 3:Screen |
|||
4-7:printers/plotters |
|||
8-11:Disk Drives |
|||
Input device? 0 |
|||
Output device? 8 |
|||
Filename for OUTPUT? rosetta.txt |
|||
Begin typing. Press CTRL-Z to end. |
|||
[No echo of text because output is directed to file.] |
|||
ready. |
|||
run |
|||
0:Keyboard 1:Tape 2:RS-232 3:Screen |
|||
4-7:printers/plotters |
|||
8-11:Disk Drives |
|||
Input device? 8 |
|||
Filename for INPUT? rosetta.txt |
|||
Output device? 3 |
|||
These device numbers are unique to the Commodore line of 8-bit computers. |
|||
ready. |
|||
█ |
|||
</pre> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |