Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Input-loop/00-META.yaml
Normal file
3
Task/Input-loop/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Input_loop
|
||||
note: Text processing
|
||||
13
Task/Input-loop/00-TASK.txt
Normal file
13
Task/Input-loop/00-TASK.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{{selection|Short Circuit|Console Program Basics}}
|
||||
[[Category:Basic language learning]]
|
||||
[[Category:Streams]]
|
||||
[[Category:Simple]]
|
||||
{{omit from|PARI/GP|No access to streams other than input}}
|
||||
{{omit from|TI-89 BASIC}} <!-- No streams other than user input, not really applicable. -->
|
||||
|
||||
;Task:
|
||||
Read from a text stream either word-by-word or line-by-line until the stream runs out of data.
|
||||
|
||||
The stream will have an unknown amount of data on it.
|
||||
<br><br>
|
||||
|
||||
160
Task/Input-loop/AArch64-Assembly/input-loop.aarch64
Normal file
160
Task/Input-loop/AArch64-Assembly/input-loop.aarch64
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program inputLoop64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
|
||||
.equ BUFSIZE, 10000
|
||||
.equ LINESIZE, 100
|
||||
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
szMessErreur: .asciz "Erreur ouverture fichier input.\n"
|
||||
szMessErreur1: .asciz "Erreur fermeture fichier.\n"
|
||||
szMessErreur2: .asciz "Erreur lecture fichier.\n"
|
||||
szCarriageReturn: .asciz "\n"
|
||||
szMessEndLine: .asciz "<<<<<< End line.\n"
|
||||
|
||||
szMessCodeErr: .asciz "Error code décimal : @ \n"
|
||||
|
||||
szNameFileInput: .asciz "input.txt"
|
||||
|
||||
/*******************************************/
|
||||
/* DONNEES NON INITIALISEES */
|
||||
/*******************************************/
|
||||
.bss
|
||||
sZoneConv: .skip 24
|
||||
sBuffer: .skip BUFSIZE
|
||||
sBufferWord: .skip LINESIZE
|
||||
/**********************************************/
|
||||
/* -- Code section */
|
||||
/**********************************************/
|
||||
.text
|
||||
.global main
|
||||
main:
|
||||
/* open file */
|
||||
mov x0,AT_FDCWD
|
||||
ldr x1,qAdrszNameFileInput // file name
|
||||
mov x2,O_RDONLY // flags
|
||||
mov x3,0 // mode
|
||||
mov x8,OPEN // call system OPEN
|
||||
svc 0
|
||||
cmp x0,0 // open error ?
|
||||
ble erreur
|
||||
/* read file */
|
||||
mov x9,x0 // save File Descriptor
|
||||
ldr x1,qAdrsBuffer // buffer address
|
||||
mov x2,BUFSIZE // buffer size
|
||||
mov x8,READ // call system READ
|
||||
svc 0
|
||||
cmp x0,0 // read error ?
|
||||
ble erreur2
|
||||
mov x2,x0 // length read characters
|
||||
/* buffer analyze */
|
||||
ldr x3,qAdrsBuffer // buffer address
|
||||
ldr x5,qAdrsBufferWord // buffer address
|
||||
mov x7,0 // word byte counter
|
||||
mov x4,0 // byte counter
|
||||
mov x10,1
|
||||
1:
|
||||
ldrb w6,[x3,x4] // load byte buffer
|
||||
cmp x6,' ' // space ?
|
||||
csel x8,xzr,x10,eq // yes 0-> x8
|
||||
beq 2f
|
||||
cmp x6,0xA // end line ?
|
||||
csel x8,x10,xzr,eq // yes 1 -> x8
|
||||
beq 2f
|
||||
cmp x6,0xD // end line ?
|
||||
csel x8,x10,xzr,eq
|
||||
beq 3f
|
||||
strb w6,[x5,x7] // store byte
|
||||
add x7,x7,1 // increment word byte counter
|
||||
b 4f
|
||||
2: // word end
|
||||
cmp x7,0
|
||||
beq 3f
|
||||
mov x6,0 // store 0 final
|
||||
strb w6,[x5,x7]
|
||||
mov x0,x5 // display word
|
||||
bl affichageMess
|
||||
ldr x0,qAdrszCarriageReturn
|
||||
bl affichageMess
|
||||
mov x7,0 // raz word byte counter
|
||||
3:
|
||||
cmp x8,1 // end line ?
|
||||
bne 4f
|
||||
ldr x0,qAdrszMessEndLine
|
||||
bl affichageMess
|
||||
4:
|
||||
add x4,x4,1 // increment read buffer counter
|
||||
cmp x4,x2 // end bytes ?
|
||||
blt 1b // no -> loop
|
||||
|
||||
4:
|
||||
/* close imput file */
|
||||
mov x0,x9 // Fd
|
||||
mov x8,CLOSE // call system CLOSE
|
||||
svc 0
|
||||
cmp x0,0 // close error ?
|
||||
blt erreur1
|
||||
|
||||
mov x0,0 // return code OK
|
||||
b 100f
|
||||
erreur:
|
||||
ldr x1,qAdrszMessErreur
|
||||
bl displayError
|
||||
mov x0,1 // error return code
|
||||
b 100f
|
||||
erreur1:
|
||||
ldr x1,qAdrszMessErreur1
|
||||
bl displayError
|
||||
mov x0,1 // error return code
|
||||
b 100f
|
||||
erreur2:
|
||||
ldr x1,qAdrszMessErreur2
|
||||
bl displayError
|
||||
mov x0,1 // error return code
|
||||
b 100f
|
||||
|
||||
100: // end program
|
||||
mov x8,EXIT
|
||||
svc 0
|
||||
qAdrszNameFileInput: .quad szNameFileInput
|
||||
qAdrszMessErreur: .quad szMessErreur
|
||||
qAdrszMessErreur1: .quad szMessErreur1
|
||||
qAdrszMessErreur2: .quad szMessErreur2
|
||||
qAdrszCarriageReturn: .quad szCarriageReturn
|
||||
qAdrszMessEndLine: .quad szMessEndLine
|
||||
qAdrsBuffer: .quad sBuffer
|
||||
qAdrsBufferWord: .quad sBufferWord
|
||||
/******************************************************************/
|
||||
/* display error message */
|
||||
/******************************************************************/
|
||||
/* x0 contains error code */
|
||||
/* x1 contains address error message */
|
||||
displayError:
|
||||
stp x2,lr,[sp,-16]! // save registers
|
||||
mov x2,x0 // save error code
|
||||
mov x0,x1 // display message error
|
||||
bl affichageMess
|
||||
mov x0,x2
|
||||
ldr x1,qAdrsZoneConv // conversion error code
|
||||
bl conversion10S // decimal conversion
|
||||
ldr x0,qAdrszMessCodeErr
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at @ character
|
||||
bl affichageMess // display message final
|
||||
ldp x2,lr,[sp],16 // restaur 2 registers
|
||||
ret // return to address lr x30
|
||||
qAdrsZoneConv: .quad sZoneConv
|
||||
qAdrszMessCodeErr: .quad szMessCodeErr
|
||||
/********************************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
11
Task/Input-loop/ALGOL-68/input-loop-1.alg
Normal file
11
Task/Input-loop/ALGOL-68/input-loop-1.alg
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
main:(
|
||||
PROC raise logical file end = (REF FILE f) BOOL: ( except logical file end );
|
||||
on logical file end(stand in, raise logical file end);
|
||||
DO
|
||||
print(read string);
|
||||
read(new line);
|
||||
print(new line)
|
||||
OD;
|
||||
except logical file end:
|
||||
SKIP
|
||||
)
|
||||
18
Task/Input-loop/ALGOL-68/input-loop-2.alg
Normal file
18
Task/Input-loop/ALGOL-68/input-loop-2.alg
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
main:(
|
||||
PROC raise logical file end = (REF FILE f) BOOL: ( except logical file end );
|
||||
on logical file end(stand in, raise logical file end);
|
||||
DO
|
||||
PROC raise page end = (REF FILE f) BOOL: ( except page end );
|
||||
on page end(stand in, raise page end);
|
||||
DO
|
||||
print(read string);
|
||||
read(new line);
|
||||
print(new line)
|
||||
OD;
|
||||
except page end:
|
||||
read(new page);
|
||||
print(new page)
|
||||
OD;
|
||||
except logical file end:
|
||||
SKIP
|
||||
)
|
||||
12
Task/Input-loop/ALGOL-W/input-loop.alg
Normal file
12
Task/Input-loop/ALGOL-W/input-loop.alg
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
begin
|
||||
string(80) line;
|
||||
% allow the program to continue after reaching end-of-file %
|
||||
% without this, end-of-file would cause a run-time error %
|
||||
ENDFILE := EXCEPTION( false, 1, 0, false, "EOF" );
|
||||
% read lines until end of file %
|
||||
read( line );
|
||||
while not XCPNOTED(ENDFILE) do begin
|
||||
write( line );
|
||||
read( line )
|
||||
end
|
||||
end.
|
||||
14
Task/Input-loop/APL/input-loop.apl
Normal file
14
Task/Input-loop/APL/input-loop.apl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
h ← ⊃ (⎕fio['read_text'] 'corpus/sample1.txt')
|
||||
⍴h
|
||||
7 49
|
||||
]boxing 8
|
||||
h
|
||||
┌→────────────────────────────────────────────────┐
|
||||
↓This is some sample text. │
|
||||
│The text itself has multiple lines, and │
|
||||
│the text has some words that occur multiple times│
|
||||
│in the text. │
|
||||
│ │
|
||||
│This is the end of the text. │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────┘
|
||||
146
Task/Input-loop/ARM-Assembly/input-loop.arm
Normal file
146
Task/Input-loop/ARM-Assembly/input-loop.arm
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program inputLoop.s */
|
||||
|
||||
/* REMARK 1 : this program use routines in a include file
|
||||
see task Include a file language arm assembly
|
||||
for the routine affichageMess conversion10
|
||||
see at end of this program the instruction include */
|
||||
|
||||
/*********************************************/
|
||||
/*constantes */
|
||||
/********************************************/
|
||||
.equ STDOUT, 1 @ Linux output console
|
||||
.equ EXIT, 1 @ Linux syscall
|
||||
.equ READ, 3
|
||||
.equ WRITE, 4
|
||||
.equ OPEN, 5
|
||||
.equ CLOSE, 6
|
||||
.equ CREATE, 8
|
||||
/* file */
|
||||
.equ O_RDONLY, 0x0 @ open for reading only
|
||||
|
||||
.equ BUFSIZE, 10000
|
||||
.equ LINESIZE, 100
|
||||
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
szMessErreur: .asciz "Erreur ouverture fichier input.\n"
|
||||
szMessErreur1: .asciz "Erreur fermeture fichier.\n"
|
||||
szMessErreur2: .asciz "Erreur lecture fichier.\n"
|
||||
szCarriageReturn: .asciz "\n"
|
||||
szMessEndLine: .asciz "<<<<<< End line.\n"
|
||||
|
||||
szNameFileInput: .asciz "input.txt"
|
||||
|
||||
/*******************************************/
|
||||
/* DONNEES NON INITIALISEES */
|
||||
/*******************************************/
|
||||
.bss
|
||||
sBuffer: .skip BUFSIZE
|
||||
sBufferWord: .skip LINESIZE
|
||||
/**********************************************/
|
||||
/* -- Code section */
|
||||
/**********************************************/
|
||||
.text
|
||||
.global main
|
||||
main:
|
||||
/* open file */
|
||||
ldr r0,iAdrszNameFileInput @ file name
|
||||
mov r1,#O_RDONLY @ flags
|
||||
mov r2,#0 @ mode
|
||||
mov r7,#OPEN @ call system OPEN
|
||||
svc #0
|
||||
cmp r0,#0 @ open error ?
|
||||
ble erreur
|
||||
/* read file */
|
||||
mov r9,r0 @ save File Descriptor
|
||||
ldr r1,iAdrsBuffer @ buffer address
|
||||
mov r2,#BUFSIZE @ buffer size
|
||||
mov r7, #READ @ call system READ
|
||||
svc 0
|
||||
cmp r0,#0 @ read error ?
|
||||
ble erreur2
|
||||
mov r2,r0 @ length read characters
|
||||
/* buffer analyze */
|
||||
ldr r3,iAdrsBuffer @ buffer address
|
||||
ldr r5,iAdrsBufferWord @ buffer address
|
||||
mov r7,#0 @ word byte counter
|
||||
mov r4,#0 @ byte counter
|
||||
1:
|
||||
ldrb r6,[r3,r4] @ load byte buffer
|
||||
cmp r6,#' ' @ space ?
|
||||
moveq r8,#0 @ yes
|
||||
beq 2f
|
||||
cmp r6,#0xA @ end line ?
|
||||
moveq r8,#1
|
||||
beq 2f
|
||||
cmp r6,#0xD @ end line ?
|
||||
beq 3f
|
||||
strb r6,[r5,r7] @ store byte
|
||||
add r7,#1 @ increment word byte counter
|
||||
b 4f
|
||||
2: @ word end
|
||||
cmp r7,#0
|
||||
beq 3f
|
||||
mov r6,#0 @ store 0 final
|
||||
strb r6,[r5,r7]
|
||||
mov r0,r5 @ display word
|
||||
bl affichageMess
|
||||
ldr r0,iAdrszCarriageReturn
|
||||
bl affichageMess
|
||||
mov r7,#0 @ raz word byte counter
|
||||
3:
|
||||
cmp r8,#1 @ end line ?
|
||||
bne 4f
|
||||
ldr r0,iAdrszMessEndLine
|
||||
bl affichageMess
|
||||
4:
|
||||
add r4,#1 @ increment read buffer counter
|
||||
cmp r4,r2 @ end bytes ?
|
||||
blt 1b @ no -> loop
|
||||
|
||||
4:
|
||||
/* close imput file */
|
||||
mov r0,r9 @ Fd
|
||||
mov r7, #CLOSE @ call system CLOSE
|
||||
svc 0
|
||||
cmp r0,#0 @ close error ?
|
||||
blt erreur1
|
||||
|
||||
|
||||
mov r0,#0 @ return code OK
|
||||
b 100f
|
||||
erreur:
|
||||
ldr r1,iAdrszMessErreur
|
||||
bl displayError
|
||||
mov r0,#1 @ error return code
|
||||
b 100f
|
||||
erreur1:
|
||||
ldr r1,iAdrszMessErreur1
|
||||
bl displayError
|
||||
mov r0,#1 @ error return code
|
||||
b 100f
|
||||
erreur2:
|
||||
ldr r1,iAdrszMessErreur2
|
||||
bl displayError
|
||||
mov r0,#1 @ error return code
|
||||
b 100f
|
||||
|
||||
|
||||
100: @ end program
|
||||
mov r7, #EXIT
|
||||
svc 0
|
||||
iAdrszNameFileInput: .int szNameFileInput
|
||||
iAdrszMessErreur: .int szMessErreur
|
||||
iAdrszMessErreur1: .int szMessErreur1
|
||||
iAdrszMessErreur2: .int szMessErreur2
|
||||
iAdrszCarriageReturn: .int szCarriageReturn
|
||||
iAdrszMessEndLine: .int szMessEndLine
|
||||
iAdrsBuffer: .int sBuffer
|
||||
iAdrsBufferWord: .int sBufferWord
|
||||
/***************************************************/
|
||||
/* ROUTINES INCLUDE */
|
||||
/***************************************************/
|
||||
.include "../affichage.inc"
|
||||
1
Task/Input-loop/AWK/input-loop-1.awk
Normal file
1
Task/Input-loop/AWK/input-loop-1.awk
Normal file
|
|
@ -0,0 +1 @@
|
|||
{ print $0 }
|
||||
1
Task/Input-loop/AWK/input-loop-2.awk
Normal file
1
Task/Input-loop/AWK/input-loop-2.awk
Normal file
|
|
@ -0,0 +1 @@
|
|||
1
|
||||
19
Task/Input-loop/Action-/input-loop.action
Normal file
19
Task/Input-loop/Action-/input-loop.action
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
PROC ReadStream(BYTE stream)
|
||||
CHAR ARRAY line(255)
|
||||
|
||||
WHILE Eof(stream)=0
|
||||
DO
|
||||
InputSD(stream,line)
|
||||
PrintE(line)
|
||||
OD
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
BYTE streamId=[1]
|
||||
|
||||
Close(streamId)
|
||||
Open(streamId,"H6:INPUT_PU.ACT",4)
|
||||
PrintE("Reading from stream...") PutE()
|
||||
ReadStream(streamId)
|
||||
Close(streamId)
|
||||
RETURN
|
||||
18
Task/Input-loop/Ada/input-loop.ada
Normal file
18
Task/Input-loop/Ada/input-loop.ada
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
|
||||
procedure Read_Stream is
|
||||
Line : String(1..10);
|
||||
Length : Natural;
|
||||
begin
|
||||
while not End_Of_File loop
|
||||
Get_Line(Line, Length); -- read up to 10 characters at a time
|
||||
Put(Line(1..Length));
|
||||
-- The current line of input data may be longer than the string receiving the data.
|
||||
-- If so, the current input file column number will be greater than 0
|
||||
-- and the extra data will be unread until the next iteration.
|
||||
-- If not, we have read past an end of line marker and col will be 1
|
||||
if Col(Current_Input) = 1 then
|
||||
New_Line;
|
||||
end if;
|
||||
end loop;
|
||||
end Read_Stream;
|
||||
9
Task/Input-loop/Aime/input-loop.aime
Normal file
9
Task/Input-loop/Aime/input-loop.aime
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
void
|
||||
read_stream(file f)
|
||||
{
|
||||
text s;
|
||||
|
||||
while (f_line(f, s) != -1) {
|
||||
# the read line available as -s-
|
||||
}
|
||||
}
|
||||
26
Task/Input-loop/AmigaE/input-loop.amiga
Normal file
26
Task/Input-loop/AmigaE/input-loop.amiga
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
CONST BUFLEN=1024, EOF=-1
|
||||
|
||||
PROC consume_input(fh)
|
||||
DEF buf[BUFLEN] : STRING, r
|
||||
REPEAT
|
||||
/* even if the line si longer than BUFLEN,
|
||||
ReadStr won't overflow; rather the line is
|
||||
"splitted" and the remaining part is read in
|
||||
the next ReadStr */
|
||||
r := ReadStr(fh, buf)
|
||||
IF buf[] OR (r <> EOF)
|
||||
-> do something
|
||||
WriteF('\s\n',buf)
|
||||
ENDIF
|
||||
UNTIL r=EOF
|
||||
ENDPROC
|
||||
|
||||
PROC main()
|
||||
DEF fh
|
||||
|
||||
fh := Open('basicinputloop.e', OLDFILE)
|
||||
IF fh
|
||||
consume_input(fh)
|
||||
Close(fh)
|
||||
ENDIF
|
||||
ENDPROC
|
||||
14
Task/Input-loop/Applesoft-BASIC/input-loop.basic
Normal file
14
Task/Input-loop/Applesoft-BASIC/input-loop.basic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
100 INPUT "FILENAME:";F$
|
||||
110 D$ = CHR$(4)
|
||||
120 PRINT D$"VERIFY"F$
|
||||
130 PRINT D$"OPEN"F$
|
||||
140 PRINT D$"READ"F$
|
||||
150 ONERR GOTO 190
|
||||
|
||||
160 GET C$
|
||||
170 PRINT CHR$(0)C$;
|
||||
180 GOTO 160
|
||||
|
||||
190 POKE 216,0
|
||||
200 IF PEEK(222) <> 5 THEN RESUME
|
||||
210 PRINT D$"CLOSE"F$
|
||||
4
Task/Input-loop/Arturo/input-loop.arturo
Normal file
4
Task/Input-loop/Arturo/input-loop.arturo
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
while [true][
|
||||
i: input "> "
|
||||
print i
|
||||
]
|
||||
4
Task/Input-loop/AutoHotkey/input-loop.ahk
Normal file
4
Task/Input-loop/AutoHotkey/input-loop.ahk
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Loop, Read, Input.txt, Output.txt
|
||||
{
|
||||
FileAppend, %A_LoopReadLine%`n
|
||||
}
|
||||
9
Task/Input-loop/BASIC256/input-loop.basic
Normal file
9
Task/Input-loop/BASIC256/input-loop.basic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
f = freefile
|
||||
open f, "test.txt"
|
||||
|
||||
while not eof(f)
|
||||
linea$ = readline(f)
|
||||
print linea$ # echo to the console
|
||||
end while
|
||||
close f
|
||||
end
|
||||
11
Task/Input-loop/BBC-BASIC/input-loop.basic
Normal file
11
Task/Input-loop/BBC-BASIC/input-loop.basic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
STD_INPUT_HANDLE = -10
|
||||
STD_OUTPUT_HANDLE = -11
|
||||
SYS "GetStdHandle", STD_INPUT_HANDLE TO @hfile%(1)
|
||||
SYS "GetStdHandle", STD_OUTPUT_HANDLE TO @hfile%(2)
|
||||
SYS "SetConsoleMode", @hfile%(1), 0
|
||||
*INPUT 13
|
||||
*OUTPUT 14
|
||||
REPEAT
|
||||
INPUT A$
|
||||
PRINT A$
|
||||
UNTIL FALSE
|
||||
13
Task/Input-loop/BaCon/input-loop.bacon
Normal file
13
Task/Input-loop/BaCon/input-loop.bacon
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
'--- some generic header file to give it a real test
|
||||
PRINT "Enter any file name you want to read ex: /usr/include/X11/X.h"
|
||||
INPUT filename$
|
||||
|
||||
text$ = LOAD$(filename$)
|
||||
SPLIT text$ BY NL$ TO TOK$ SIZE dim
|
||||
i = 0
|
||||
|
||||
'---dynamic index the end of an array is always null terminated
|
||||
WHILE (TOK$[i] ISNOT NULL)
|
||||
PRINT TOK$[i]
|
||||
INCR i
|
||||
WEND
|
||||
1
Task/Input-loop/Batch-File/input-loop.bat
Normal file
1
Task/Input-loop/Batch-File/input-loop.bat
Normal file
|
|
@ -0,0 +1 @@
|
|||
for /f %%i in (file.txt) do if %%i@ neq @ echo %%i
|
||||
27
Task/Input-loop/Bracmat/input-loop.bracmat
Normal file
27
Task/Input-loop/Bracmat/input-loop.bracmat
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
( put$("This is
|
||||
a three line
|
||||
text","test.txt",NEW)
|
||||
& fil$("test.txt",r)
|
||||
& fil$(,STR," \t\r\n")
|
||||
& 0:?linenr
|
||||
& whl
|
||||
' ( fil$:(?line.?breakchar)
|
||||
& put
|
||||
$ ( str
|
||||
$ ( "breakchar:"
|
||||
( !breakchar:" "&SP
|
||||
| !breakchar:\t&"\\t"
|
||||
| !breakchar:\r&"\\r"
|
||||
| !breakchar:\n&"\\n"
|
||||
| !breakchar:&EOF
|
||||
)
|
||||
", word "
|
||||
(1+!linenr:?linenr)
|
||||
":"
|
||||
!line
|
||||
\n
|
||||
)
|
||||
)
|
||||
)
|
||||
& (fil$(,SET,-1)|out$"file closed")
|
||||
);
|
||||
43
Task/Input-loop/C++/input-loop-1.cpp
Normal file
43
Task/Input-loop/C++/input-loop-1.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include <istream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
|
||||
// word by word
|
||||
template<class OutIt>
|
||||
void read_words(std::istream& is, OutIt dest)
|
||||
{
|
||||
std::string word;
|
||||
while (is >> word)
|
||||
{
|
||||
// send the word to the output iterator
|
||||
*dest = word;
|
||||
}
|
||||
}
|
||||
|
||||
// line by line:
|
||||
template<class OutIt>
|
||||
void read_lines(std::istream& is, OutIt dest)
|
||||
{
|
||||
std::string line;
|
||||
while (std::getline(is, line))
|
||||
{
|
||||
// store the line to the output iterator
|
||||
*dest = line;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// 1) sending words from std. in std. out (end with Return)
|
||||
read_words(std::cin,
|
||||
std::ostream_iterator<std::string>(std::cout, " "));
|
||||
|
||||
// 2) appending lines from std. to vector (end with Ctrl+Z)
|
||||
std::vector<std::string> v;
|
||||
read_lines(std::cin, std::back_inserter(v));
|
||||
|
||||
return 0;
|
||||
}
|
||||
26
Task/Input-loop/C++/input-loop-2.cpp
Normal file
26
Task/Input-loop/C++/input-loop-2.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
template<class OutIt>
|
||||
void read_words(std::istream& is, OutIt dest)
|
||||
{
|
||||
typedef std::istream_iterator<std::string> InIt;
|
||||
std::copy(InIt(is), InIt(),
|
||||
dest);
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct ReadableLine : public std::string
|
||||
{
|
||||
friend std::istream & operator>>(std::istream & is, ReadableLine & line)
|
||||
{
|
||||
return std::getline(is, line);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template<class OutIt>
|
||||
void read_lines(std::istream& is, OutIt dest)
|
||||
{
|
||||
typedef std::istream_iterator<detail::ReadableLine> InIt;
|
||||
std::copy(InIt(is), InIt(),
|
||||
dest);
|
||||
}
|
||||
18
Task/Input-loop/C-sharp/input-loop.cs
Normal file
18
Task/Input-loop/C-sharp/input-loop.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// For stdin, you could use
|
||||
// new StreamReader(Console.OpenStandardInput(), Console.InputEncoding)
|
||||
|
||||
using (var b = new StreamReader("file.txt"))
|
||||
{
|
||||
string line;
|
||||
while ((line = b.ReadLine()) != null)
|
||||
Console.WriteLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Task/Input-loop/C/input-loop.c
Normal file
32
Task/Input-loop/C/input-loop.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char *get_line(FILE* fp)
|
||||
{
|
||||
int len = 0, got = 0, c;
|
||||
char *buf = 0;
|
||||
|
||||
while ((c = fgetc(fp)) != EOF) {
|
||||
if (got + 1 >= len) {
|
||||
len *= 2;
|
||||
if (len < 4) len = 4;
|
||||
buf = realloc(buf, len);
|
||||
}
|
||||
buf[got++] = c;
|
||||
if (c == '\n') break;
|
||||
}
|
||||
if (c == EOF && !got) return 0;
|
||||
|
||||
buf[got++] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
char *s;
|
||||
while ((s = get_line(stdin))) {
|
||||
printf("%s",s);
|
||||
free(s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
33
Task/Input-loop/COBOL/input-loop.cobol
Normal file
33
Task/Input-loop/COBOL/input-loop.cobol
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. input-loop.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
SELECT in-stream ASSIGN TO KEYBOARD *> or any other file/stream
|
||||
ORGANIZATION LINE SEQUENTIAL
|
||||
FILE STATUS in-stream-status.
|
||||
|
||||
DATA DIVISION.
|
||||
FILE SECTION.
|
||||
FD in-stream.
|
||||
01 stream-line PIC X(80).
|
||||
|
||||
WORKING-STORAGE SECTION.
|
||||
01 in-stream-status PIC 99.
|
||||
88 end-of-stream VALUE 10.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
OPEN INPUT in-stream
|
||||
|
||||
PERFORM UNTIL EXIT
|
||||
READ in-stream
|
||||
AT END
|
||||
EXIT PERFORM
|
||||
END-READ
|
||||
DISPLAY stream-line
|
||||
END-PERFORM
|
||||
|
||||
CLOSE in-stream
|
||||
.
|
||||
END PROGRAM input-loop.
|
||||
2
Task/Input-loop/Clojure/input-loop.clj
Normal file
2
Task/Input-loop/Clojure/input-loop.clj
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(defn basic-input [fname]
|
||||
(line-seq (java.io.BufferedReader. (java.io.FileReader. fname))))
|
||||
25
Task/Input-loop/Commodore-BASIC/input-loop.basic
Normal file
25
Task/Input-loop/Commodore-BASIC/input-loop.basic
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
10 rem input loop - rosetta code
|
||||
11 rem open command channel, clear screen, switch to lower case
|
||||
12 open 15,8,15
|
||||
15 print chr$(147);chr$(14):f$=""
|
||||
|
||||
20 input "Enter filename";f$
|
||||
25 if f$="" then end
|
||||
|
||||
30 open 5,8,5,f$+",s,r"
|
||||
40 gosub 1000
|
||||
50 if er=62 then print "That file is not found... Try again.":close 5:goto 20
|
||||
60 if er<>0 then print "There was an unexpected error.":close 5:gosub 1100
|
||||
|
||||
70 get#5,a$
|
||||
80 if st and 64 then close 5:close 15:end
|
||||
90 print a$;:goto 70
|
||||
|
||||
1000 rem check command channel for error
|
||||
1005 rem error number, error msg$, track number, sector number
|
||||
1010 input#15,er,er$,tk,sc
|
||||
1020 return
|
||||
|
||||
1100 rem print error
|
||||
1110 print:print er;"- ";er$;" track:";tk;"sector:";sc
|
||||
1120 return
|
||||
5
Task/Input-loop/Common-Lisp/input-loop.lisp
Normal file
5
Task/Input-loop/Common-Lisp/input-loop.lisp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defun basic-input (filename)
|
||||
(with-open-file (stream (make-pathname :name filename) :direction :input)
|
||||
(loop for line = (read-line stream nil nil)
|
||||
while line
|
||||
do (format t "~a~%" line))))
|
||||
23
Task/Input-loop/D/input-loop-1.d
Normal file
23
Task/Input-loop/D/input-loop-1.d
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
void main() {
|
||||
import std.stdio;
|
||||
|
||||
immutable fileName = "input_loop1.d";
|
||||
|
||||
foreach (const line; fileName.File.byLine) {
|
||||
pragma(msg, typeof(line)); // Prints: const(char[])
|
||||
// line is a transient slice, so if you need to
|
||||
// retain it for later use, you have to .dup or .idup it.
|
||||
line.writeln; // Do something with each line.
|
||||
}
|
||||
|
||||
// Keeping the line terminators:
|
||||
foreach (const line; fileName.File.byLine(KeepTerminator.yes)) {
|
||||
// line is a transient slice.
|
||||
line.writeln;
|
||||
}
|
||||
|
||||
foreach (const string line; fileName.File.lines) {
|
||||
// line is a transient slice.
|
||||
line.writeln;
|
||||
}
|
||||
}
|
||||
8
Task/Input-loop/D/input-loop-2.d
Normal file
8
Task/Input-loop/D/input-loop-2.d
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import tango.io.Console;
|
||||
import tango.text.stream.LineIterator;
|
||||
|
||||
void main (char[][] args) {
|
||||
foreach (line; new LineIterator!(char)(Cin.input)) {
|
||||
// do something with each line
|
||||
}
|
||||
}
|
||||
8
Task/Input-loop/D/input-loop-3.d
Normal file
8
Task/Input-loop/D/input-loop-3.d
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import tango.io.Console;
|
||||
import tango.text.stream.SimpleIterator;
|
||||
|
||||
void main (char[][] args) {
|
||||
foreach (word; new SimpleIterator!(char)(" ", Cin.input)) {
|
||||
// do something with each word
|
||||
}
|
||||
}
|
||||
17
Task/Input-loop/Delphi/input-loop.delphi
Normal file
17
Task/Input-loop/Delphi/input-loop.delphi
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
program InputLoop;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses SysUtils, Classes;
|
||||
|
||||
var
|
||||
lReader: TStreamReader; // Introduced in Delphi XE
|
||||
begin
|
||||
lReader := TStreamReader.Create('input.txt', TEncoding.Default);
|
||||
try
|
||||
while lReader.Peek >= 0 do
|
||||
Writeln(lReader.ReadLine);
|
||||
finally
|
||||
lReader.Free;
|
||||
end;
|
||||
end.
|
||||
5
Task/Input-loop/EasyLang/input-loop.easy
Normal file
5
Task/Input-loop/EasyLang/input-loop.easy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
repeat
|
||||
l$ = input
|
||||
until error = 1
|
||||
print l$
|
||||
.
|
||||
236
Task/Input-loop/Eiffel/input-loop.e
Normal file
236
Task/Input-loop/Eiffel/input-loop.e
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
note
|
||||
description : "{
|
||||
There are several examples included, including input from a text file,
|
||||
simple console input and input from standard input explicitly.
|
||||
See notes in the code for details.
|
||||
|
||||
Examples were compile using Eiffel Studio 6.6 with only the default
|
||||
class libraries.
|
||||
}"
|
||||
|
||||
class APPLICATION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature
|
||||
|
||||
make
|
||||
do
|
||||
-- These examples show non-console input (a plain text file)
|
||||
-- with end-of-input handling.
|
||||
read_lines_from_file
|
||||
read_words_from_file
|
||||
|
||||
-- These examples use simplified input from 'io', that
|
||||
-- handles the details of whether it's stdin or not
|
||||
-- They terminate on a line (word) of "q"
|
||||
read_lines_from_console_with_termination
|
||||
read_words_from_console_with_termination
|
||||
|
||||
-- The next examples show reading stdin explicitly
|
||||
-- as if it were a text file. It expects and end of file
|
||||
-- termination and so will loop indefinitely unless reading
|
||||
-- from a pipe or your console can send an EOF.
|
||||
read_lines_from_stdin
|
||||
read_words_from_stdin
|
||||
|
||||
-- These examples use simplified input from 'io', that
|
||||
-- handles the details of whether it's stdin or not,
|
||||
-- but have no explicit termination
|
||||
read_lines_from_console_forever
|
||||
read_words_from_console_forever
|
||||
end
|
||||
|
||||
--|--------------------------------------------------------------
|
||||
|
||||
read_lines_from_file
|
||||
-- Read input from a text file
|
||||
-- Echo each line of the file to standard output.
|
||||
--
|
||||
-- Some language examples omit file open/close operations
|
||||
-- but are included here for completeness. Additional error
|
||||
-- checking would be appropriate in production code.
|
||||
local
|
||||
tf: PLAIN_TEXT_FILE
|
||||
do
|
||||
print ("Reading lines from a file%N")
|
||||
create tf.make ("myfile") -- Create a file object
|
||||
tf.open_read -- Open the file in read mode
|
||||
|
||||
-- The actual input loop
|
||||
|
||||
from
|
||||
until tf.end_of_file
|
||||
loop
|
||||
tf.read_line
|
||||
print (tf.last_string + "%N")
|
||||
end
|
||||
|
||||
tf.close -- Close the file
|
||||
end
|
||||
|
||||
--|--------------------------------------------------------------
|
||||
|
||||
read_words_from_file
|
||||
-- Read input from a text file
|
||||
-- Echo each word of the file to standard output on a
|
||||
-- separate line.
|
||||
--
|
||||
-- Some language examples omit file open/close operations
|
||||
-- but are included here for completeness. Additional error
|
||||
-- checking would be appropriate in production code.
|
||||
local
|
||||
tf: PLAIN_TEXT_FILE
|
||||
do
|
||||
print ("Reading words from a file%N")
|
||||
create tf.make ("myfile") -- Create a file object
|
||||
tf.open_read -- Open the file in read mode
|
||||
|
||||
-- The actual input loop
|
||||
|
||||
from
|
||||
until tf.end_of_file
|
||||
loop
|
||||
-- This instruction is the only difference between this
|
||||
-- example and the read_lines_from_file example
|
||||
tf.read_word
|
||||
print (tf.last_string + "%N")
|
||||
end
|
||||
|
||||
tf.close -- Close the file
|
||||
end
|
||||
|
||||
--|--------------------------------------------------------------
|
||||
|
||||
read_lines_from_console_with_termination
|
||||
-- Read lines from console and echo them back to output
|
||||
-- until the line contains only the termination key 'q'
|
||||
--
|
||||
-- 'io' is acquired through inheritance from class ANY,
|
||||
-- the top of all inheritance hierarchies.
|
||||
local
|
||||
the_cows_come_home: BOOLEAN
|
||||
do
|
||||
print ("Reading lines from console%N")
|
||||
from
|
||||
until the_cows_come_home
|
||||
loop
|
||||
io.read_line
|
||||
if io.last_string ~ "q" then
|
||||
the_cows_come_home := True
|
||||
print ("Mooooo!%N")
|
||||
else
|
||||
print (io.last_string)
|
||||
io.new_line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--|--------------------------------------------------------------
|
||||
|
||||
read_words_from_console_with_termination
|
||||
-- Read words from console and echo them back to output, one
|
||||
-- word per line, until the line contains only the
|
||||
-- termination key 'q'
|
||||
--
|
||||
-- 'io' is acquired through inheritance from class ANY,
|
||||
-- the top of all inheritance hierarchies.
|
||||
local
|
||||
the_cows_come_home: BOOLEAN
|
||||
do
|
||||
print ("Reading words from console%N")
|
||||
from
|
||||
until the_cows_come_home
|
||||
loop
|
||||
io.read_word
|
||||
if io.last_string ~ "q" then
|
||||
the_cows_come_home := True
|
||||
print ("Mooooo!%N")
|
||||
else
|
||||
print (io.last_string)
|
||||
io.new_line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--|--------------------------------------------------------------
|
||||
|
||||
read_lines_from_console_forever
|
||||
-- Read lines from console and echo them back to output
|
||||
-- until the program is terminated externally
|
||||
--
|
||||
-- 'io' is acquired through inheritance from class ANY,
|
||||
-- the top of all inheritance hierarchies.
|
||||
do
|
||||
print ("Reading lines from console (no termination)%N")
|
||||
from
|
||||
until False
|
||||
loop
|
||||
io.read_line
|
||||
print (io.last_string + "%N")
|
||||
end
|
||||
end
|
||||
|
||||
--|--------------------------------------------------------------
|
||||
|
||||
read_words_from_console_forever
|
||||
-- Read words from console and echo them back to output, one
|
||||
-- word per line until the program is terminated externally
|
||||
--
|
||||
-- 'io' is acquired through inheritance from class ANY,
|
||||
-- the top of all inheritance hierarchies.
|
||||
do
|
||||
print ("Reading words from console (no termination)%N")
|
||||
from
|
||||
until False
|
||||
loop
|
||||
io.read_word
|
||||
print (io.last_string + "%N")
|
||||
end
|
||||
end
|
||||
|
||||
--|--------------------------------------------------------------
|
||||
|
||||
read_lines_from_stdin
|
||||
-- Read input from a stream on standard input
|
||||
-- Echo each line of the file to standard output.
|
||||
-- Note that we treat standard input as if it were a plain
|
||||
-- text file
|
||||
local
|
||||
tf: PLAIN_TEXT_FILE
|
||||
do
|
||||
print ("Reading lines from stdin (EOF termination)%N")
|
||||
tf := io.input
|
||||
|
||||
from
|
||||
until tf.end_of_file
|
||||
loop
|
||||
tf.read_line
|
||||
print (tf.last_string + "%N")
|
||||
end
|
||||
end
|
||||
|
||||
--|--------------------------------------------------------------
|
||||
|
||||
read_words_from_stdin
|
||||
-- Read input from a stream on standard input
|
||||
-- Echo each word of the file to standard output on a new
|
||||
-- line
|
||||
-- Note that we treat standard input as if it were a plain
|
||||
-- text file
|
||||
local
|
||||
tf: PLAIN_TEXT_FILE
|
||||
do
|
||||
print ("Reading words from stdin (EOF termination)%N")
|
||||
tf := io.input
|
||||
|
||||
from
|
||||
until tf.end_of_file
|
||||
loop
|
||||
tf.read_line
|
||||
print (tf.last_string + "%N")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
8
Task/Input-loop/Elena/input-loop-1.elena
Normal file
8
Task/Input-loop/Elena/input-loop-1.elena
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import system'routines;
|
||||
import system'io;
|
||||
import extensions'routines;
|
||||
|
||||
public program()
|
||||
{
|
||||
ReaderEnumerator.new(File.assign:"file.txt").forEach(printingLn)
|
||||
}
|
||||
12
Task/Input-loop/Elena/input-loop-2.elena
Normal file
12
Task/Input-loop/Elena/input-loop-2.elena
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import system'io;
|
||||
|
||||
public program()
|
||||
{
|
||||
using(var reader := File.assign:"file.txt".textreader())
|
||||
{
|
||||
while (reader.Available)
|
||||
{
|
||||
console.writeLine(reader.readLine())
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Task/Input-loop/Elixir/input-loop.elixir
Normal file
12
Task/Input-loop/Elixir/input-loop.elixir
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
defmodule RC do
|
||||
def input_loop(stream) do
|
||||
case IO.read(stream, :line) do
|
||||
:eof -> :ok
|
||||
data -> IO.write data
|
||||
input_loop(stream)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
path = hd(System.argv)
|
||||
File.open!(path, [:read], fn stream -> RC.input_loop(stream) end)
|
||||
8
Task/Input-loop/Erlang/input-loop.erl
Normal file
8
Task/Input-loop/Erlang/input-loop.erl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
% Implemented by Arjun Sunel
|
||||
-module(read_files).
|
||||
-export([main/0]).
|
||||
|
||||
main() ->
|
||||
Read = fun (Filename) -> {ok, Data} = file:read_file(Filename), Data end,
|
||||
Lines = string:tokens(binary_to_list(Read("read_files.erl")), "\n"),
|
||||
lists:foreach(fun (Y) -> io:format("~s~n", [Y]) end, lists:zipwith(fun(X,_)->X end, Lines, lists:seq(1, length(Lines)))).
|
||||
10
Task/Input-loop/Euphoria/input-loop.euphoria
Normal file
10
Task/Input-loop/Euphoria/input-loop.euphoria
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
procedure process_line_by_line(integer fn)
|
||||
object line
|
||||
while 1 do
|
||||
line = gets(fn)
|
||||
if atom(line) then
|
||||
exit
|
||||
end if
|
||||
-- process the line
|
||||
end while
|
||||
end procedure
|
||||
5
Task/Input-loop/F-Sharp/input-loop.fs
Normal file
5
Task/Input-loop/F-Sharp/input-loop.fs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
let lines_of_file file =
|
||||
seq { use stream = System.IO.File.OpenRead file
|
||||
use reader = new System.IO.StreamReader(stream)
|
||||
while not reader.EndOfStream do
|
||||
yield reader.ReadLine() }
|
||||
1
Task/Input-loop/Factor/input-loop.factor
Normal file
1
Task/Input-loop/Factor/input-loop.factor
Normal file
|
|
@ -0,0 +1 @@
|
|||
"file.txt" utf8 [ [ process-line ] each-line ] with-file-reader
|
||||
26
Task/Input-loop/Fantom/input-loop.fantom
Normal file
26
Task/Input-loop/Fantom/input-loop.fantom
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class Main
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
// example of reading by line
|
||||
str := "first\nsecond\nthird\nword"
|
||||
inputStream := str.in
|
||||
|
||||
inputStream.eachLine |Str line|
|
||||
{
|
||||
echo ("Line is: $line")
|
||||
}
|
||||
|
||||
// example of reading by word
|
||||
str = "first second third word"
|
||||
inputStream = str.in
|
||||
|
||||
word := inputStream.readStrToken // reads up to but excluding next space
|
||||
while (word != null)
|
||||
{
|
||||
echo ("Word: $word")
|
||||
inputStream.readChar // skip over the preceding space!
|
||||
word = inputStream.readStrToken
|
||||
}
|
||||
}
|
||||
}
|
||||
6
Task/Input-loop/Forth/input-loop.fth
Normal file
6
Task/Input-loop/Forth/input-loop.fth
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
4096 constant max-line
|
||||
: read-lines
|
||||
begin stdin pad max-line read-line throw
|
||||
while pad swap \ addr len is the line of data, excluding newline
|
||||
2drop
|
||||
repeat ;
|
||||
20
Task/Input-loop/Fortran/input-loop.f
Normal file
20
Task/Input-loop/Fortran/input-loop.f
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
program BasicInputLoop
|
||||
|
||||
implicit none
|
||||
|
||||
integer, parameter :: in = 50, &
|
||||
linelen = 1000
|
||||
integer :: ecode
|
||||
character(len=linelen) :: l
|
||||
|
||||
open(in, file="afile.txt", action="read", status="old", iostat=ecode)
|
||||
if ( ecode == 0 ) then
|
||||
do
|
||||
read(in, fmt="(A)", iostat=ecode) l
|
||||
if ( ecode /= 0 ) exit
|
||||
write(*,*) trim(l)
|
||||
end do
|
||||
close(in)
|
||||
end if
|
||||
|
||||
end program BasicInputLoop
|
||||
14
Task/Input-loop/FreeBASIC/input-loop.basic
Normal file
14
Task/Input-loop/FreeBASIC/input-loop.basic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Dim line_ As String ' line is a keyword
|
||||
Open "input.txt" For Input As #1
|
||||
|
||||
While Not Eof(1)
|
||||
Input #1, line_
|
||||
Print line_ ' echo to the console
|
||||
Wend
|
||||
|
||||
Close #1
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
2
Task/Input-loop/Frink/input-loop.frink
Normal file
2
Task/Input-loop/Frink/input-loop.frink
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
while (line = readStdin[]) != undef
|
||||
println[line]
|
||||
20
Task/Input-loop/FutureBasic/input-loop.basic
Normal file
20
Task/Input-loop/FutureBasic/input-loop.basic
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
include "NSLog.incl"
|
||||
|
||||
local fn ReadTextFile
|
||||
CFURLRef url
|
||||
CFStringRef string
|
||||
|
||||
url = openpanel 1, @"Select text file..."
|
||||
if ( url )
|
||||
string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
|
||||
if ( string )
|
||||
NSLog(@"%@",string)
|
||||
end if
|
||||
else
|
||||
// user cancelled
|
||||
end if
|
||||
end fn
|
||||
|
||||
fn ReadTextFile
|
||||
|
||||
HandleEvents
|
||||
13
Task/Input-loop/GDScript/input-loop.gd
Normal file
13
Task/Input-loop/GDScript/input-loop.gd
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
extends MainLoop
|
||||
|
||||
|
||||
func _process(_delta: float) -> bool:
|
||||
while true:
|
||||
# Read a line from stdin
|
||||
var input: String = OS.read_string_from_stdin()
|
||||
|
||||
# Empty lines are "\n" whereas end of input will be completely empty.
|
||||
if len(input) == 0:
|
||||
break
|
||||
printraw(input)
|
||||
return true # Exit
|
||||
1
Task/Input-loop/Gnuplot/input-loop.gnuplot
Normal file
1
Task/Input-loop/Gnuplot/input-loop.gnuplot
Normal file
|
|
@ -0,0 +1 @@
|
|||
!cat
|
||||
26
Task/Input-loop/Go/input-loop-1.go
Normal file
26
Task/Input-loop/Go/input-loop-1.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
in := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
s, err := in.ReadString('\n')
|
||||
if err != nil {
|
||||
// io.EOF is expected, anything else
|
||||
// should be handled/reported
|
||||
if err != io.EOF {
|
||||
log.Fatal(err)
|
||||
}
|
||||
break
|
||||
}
|
||||
// Do something with the line of text
|
||||
// in string variable s.
|
||||
_ = s
|
||||
}
|
||||
}
|
||||
24
Task/Input-loop/Go/input-loop-2.go
Normal file
24
Task/Input-loop/Go/input-loop-2.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := bufio.NewScanner(os.Stdin)
|
||||
// Select the split function, other ones are available
|
||||
// in bufio or you can provide your own.
|
||||
s.Split(bufio.ScanWords)
|
||||
for s.Scan() {
|
||||
// Get and use the next 'token'
|
||||
asBytes := s.Bytes() // Bytes does no alloaction
|
||||
asString := s.Text() // Text returns a newly allocated string
|
||||
_, _ = asBytes, asString
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
// Handle/report any error (EOF will not be reported)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
5
Task/Input-loop/Groovy/input-loop.groovy
Normal file
5
Task/Input-loop/Groovy/input-loop.groovy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def lineMap = [:]
|
||||
System.in.eachLine { line, i ->
|
||||
lineMap[i] = line
|
||||
}
|
||||
lineMap.each { println it }
|
||||
11
Task/Input-loop/Haskell/input-loop.hs
Normal file
11
Task/Input-loop/Haskell/input-loop.hs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import System.IO
|
||||
|
||||
readLines :: Handle -> IO [String]
|
||||
readLines h = do
|
||||
s <- hGetContents h
|
||||
return $ lines s
|
||||
|
||||
readWords :: Handle -> IO [String]
|
||||
readWords h = do
|
||||
s <- hGetContents h
|
||||
return $ words s
|
||||
10
Task/Input-loop/HicEst/input-loop.hicest
Normal file
10
Task/Input-loop/HicEst/input-loop.hicest
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
CHARACTER name='myfile.txt', string*1000
|
||||
|
||||
OPEN(FIle=name, OLD, LENgth=bytes, IOStat=errorcode, ERror=9)
|
||||
|
||||
DO line = 1, bytes ! loop terminates with end-of-file error at the latest
|
||||
READ(FIle=name, IOStat=errorcode, ERror=9) string
|
||||
WRITE(StatusBar) string
|
||||
ENDDO
|
||||
|
||||
9 WRITE(Messagebox, Name) line, errorcode
|
||||
8
Task/Input-loop/I/input-loop.i
Normal file
8
Task/Input-loop/I/input-loop.i
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
software {
|
||||
loop {
|
||||
read()
|
||||
errors {
|
||||
exit
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Task/Input-loop/IS-BASIC/input-loop-1.basic
Normal file
15
Task/Input-loop/IS-BASIC/input-loop-1.basic
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
100 PROGRAM "Type.bas"
|
||||
110 TEXT 80
|
||||
120 INPUT PROMPT "File name: ":F$
|
||||
130 WHEN EXCEPTION USE IOERROR
|
||||
140 OPEN #1:F$ ACCESS INPUT
|
||||
150 DO
|
||||
160 LINE INPUT #1,IF MISSING EXIT DO:F$
|
||||
170 PRINT F$
|
||||
180 LOOP
|
||||
190 CLOSE #1
|
||||
200 END WHEN
|
||||
210 HANDLER IOERROR
|
||||
220 PRINT EXSTRING$(EXTYPE)
|
||||
230 END
|
||||
240 END HANDLER
|
||||
11
Task/Input-loop/IS-BASIC/input-loop-2.basic
Normal file
11
Task/Input-loop/IS-BASIC/input-loop-2.basic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
100 PROGRAM "Type.bas"
|
||||
110 INPUT PROMPT "File name: ":F$
|
||||
120 WHEN EXCEPTION USE IOERROR
|
||||
130 OPEN #1:F$
|
||||
140 COPY FROM #1 TO #0
|
||||
150 CLOSE #1
|
||||
160 END WHEN
|
||||
170 HANDLER IOERROR
|
||||
180 PRINT EXSTRING$(EXTYPE)
|
||||
190 CLOSE #1
|
||||
200 END HANDLER
|
||||
14
Task/Input-loop/Icon/input-loop.icon
Normal file
14
Task/Input-loop/Icon/input-loop.icon
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
link str2toks
|
||||
# call either words or lines depending on what you want to do.
|
||||
procedure main()
|
||||
words()
|
||||
end
|
||||
|
||||
procedure lines()
|
||||
while write(read())
|
||||
end
|
||||
|
||||
procedure words()
|
||||
local line
|
||||
while line := read() do line ? every write(str2toks())
|
||||
end
|
||||
4
Task/Input-loop/J/input-loop-1.j
Normal file
4
Task/Input-loop/J/input-loop-1.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/ijconsole
|
||||
NB. read input until EOF
|
||||
((1!:1) 3)(1!:2) 4 NB. tested under j602
|
||||
exit ''
|
||||
10
Task/Input-loop/J/input-loop-2.j
Normal file
10
Task/Input-loop/J/input-loop-2.j
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
$ ./read-input-to-eof.ijs <<EOF
|
||||
> abc
|
||||
> def
|
||||
> ghi
|
||||
> now is the time for all good men ...
|
||||
> EOF
|
||||
abc
|
||||
def
|
||||
ghi
|
||||
now is the time for all good men ...
|
||||
25
Task/Input-loop/Java/input-loop-1.java
Normal file
25
Task/Input-loop/Java/input-loop-1.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InputLoop {
|
||||
public static void main(String args[]) {
|
||||
// To read from stdin:
|
||||
InputStream source = System.in;
|
||||
|
||||
/*
|
||||
Or, to read from a file:
|
||||
InputStream source = new FileInputStream(filename);
|
||||
|
||||
Or, to read from a network stream:
|
||||
InputStream source = socket.getInputStream();
|
||||
*/
|
||||
|
||||
Scanner in = new Scanner(source);
|
||||
while(in.hasNext()){
|
||||
String input = in.next(); // Use in.nextLine() for line-by-line reading
|
||||
|
||||
// Process the input here. For example, you could print it out:
|
||||
System.out.println(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Task/Input-loop/Java/input-loop-2.java
Normal file
31
Task/Input-loop/Java/input-loop-2.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
|
||||
public class InputLoop {
|
||||
public static void main(String args[]) {
|
||||
// To read from stdin:
|
||||
Reader reader = new InputStreamReader(System.in);
|
||||
|
||||
/*
|
||||
Or, to read from a file:
|
||||
Reader reader = new FileReader(filename);
|
||||
|
||||
Or, to read from a network stream:
|
||||
Reader reader = new InputStreamReader(socket.getInputStream());
|
||||
*/
|
||||
|
||||
try {
|
||||
BufferedReader inp = new BufferedReader(reader);
|
||||
while(inp.ready()) {
|
||||
int input = inp.read(); // Use in.readLine() for line-by-line
|
||||
|
||||
// Process the input here. For example, you can print it out.
|
||||
System.out.println(input);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// There was an input error.
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Task/Input-loop/JavaScript/input-loop.js
Normal file
8
Task/Input-loop/JavaScript/input-loop.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
var text_stream = WScript.StdIn;
|
||||
var i = 0;
|
||||
|
||||
while ( ! text_stream.AtEndOfStream ) {
|
||||
var line = text_stream.ReadLine();
|
||||
// do something with line
|
||||
WScript.echo(++i + ": " + line);
|
||||
}
|
||||
1
Task/Input-loop/Jq/input-loop-1.jq
Normal file
1
Task/Input-loop/Jq/input-loop-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
jq -r -R . FILENAME
|
||||
1
Task/Input-loop/Jq/input-loop-2.jq
Normal file
1
Task/Input-loop/Jq/input-loop-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
jq . FILENAME
|
||||
8
Task/Input-loop/Jsish/input-loop.jsish
Normal file
8
Task/Input-loop/Jsish/input-loop.jsish
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/* Input loop in Jsish */
|
||||
|
||||
var line;
|
||||
var cs = 0, ls = 0;
|
||||
|
||||
while (line = console.input()) { cs += line.length; ls += 1; }
|
||||
|
||||
printf("%d lines, %d characters\n", ls, cs);
|
||||
6
Task/Input-loop/Julia/input-loop.julia
Normal file
6
Task/Input-loop/Julia/input-loop.julia
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
stream = IOBuffer("1\n2\n3\n4\n\n6")
|
||||
|
||||
while !eof(stream)
|
||||
line = readline(stream)
|
||||
println(line)
|
||||
end
|
||||
17
Task/Input-loop/Kotlin/input-loop.kotlin
Normal file
17
Task/Input-loop/Kotlin/input-loop.kotlin
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// version 1.1
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println("Keep entering text or the word 'quit' to end the program:")
|
||||
val sc = Scanner(System.`in`)
|
||||
val words = mutableListOf<String>()
|
||||
while (true) {
|
||||
val input: String = sc.next()
|
||||
if (input.trim().toLowerCase() == "quit") {
|
||||
if (words.size > 0) println("\nYou entered the following words:\n${words.joinToString("\n")}")
|
||||
return
|
||||
}
|
||||
words.add(input)
|
||||
}
|
||||
}
|
||||
18
Task/Input-loop/LIL/input-loop.lil
Normal file
18
Task/Input-loop/LIL/input-loop.lil
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# canread test (note that canread is not available in LIL/FPLIL itself
|
||||
# but provided by the command line interfaces in main.c/lil.pas)
|
||||
#
|
||||
# You can either call this and enter lines directly (use Ctrl+Z/Ctrl+D
|
||||
# to finish) or a redirect (e.g. lil canread.lil < somefile.txt)
|
||||
#
|
||||
# Normally this is how you are supposed to read multiple lines from
|
||||
# the standard input using the lil executable. For an alternative way
|
||||
# that uses error catching via try see the eoferror.lil script.
|
||||
#
|
||||
|
||||
set count 0
|
||||
while {[canread]} {
|
||||
readline
|
||||
inc count
|
||||
}
|
||||
print $count lines
|
||||
16
Task/Input-loop/LSL/input-loop.lsl
Normal file
16
Task/Input-loop/LSL/input-loop.lsl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
string sNOTECARD = "Input_Loop_Data_Source.txt";
|
||||
default {
|
||||
integer iNotecardLine = 0;
|
||||
state_entry() {
|
||||
llOwnerSay("Reading '"+sNOTECARD+"'");
|
||||
llGetNotecardLine(sNOTECARD, iNotecardLine);
|
||||
}
|
||||
dataserver(key kRequestId, string sData) {
|
||||
if(sData==EOF) {
|
||||
llOwnerSay("EOF");
|
||||
} else {
|
||||
llOwnerSay((string)iNotecardLine+": "+sData);
|
||||
llGetNotecardLine(sNOTECARD, ++iNotecardLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
5
Task/Input-loop/Lang5/input-loop.lang5
Normal file
5
Task/Input-loop/Lang5/input-loop.lang5
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
: read-lines do read . "\n" . eof if break then loop ;
|
||||
: ==>contents
|
||||
'< swap open 'fh set fh fin read-lines fh close ;
|
||||
|
||||
'file.txt ==>contents
|
||||
10
Task/Input-loop/Lasso/input-loop.lasso
Normal file
10
Task/Input-loop/Lasso/input-loop.lasso
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
local(
|
||||
myfile = file('//path/to/file.txt'),
|
||||
textresult = array
|
||||
)
|
||||
|
||||
#myfile -> foreachline => {
|
||||
#textresult -> insert(#1)
|
||||
}
|
||||
|
||||
#textresult -> join('<br />')
|
||||
9
Task/Input-loop/Liberty-BASIC/input-loop.basic
Normal file
9
Task/Input-loop/Liberty-BASIC/input-loop.basic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
filedialog "Open","*.txt",file$
|
||||
if file$="" then end
|
||||
open file$ for input as #f
|
||||
while not(eof(#f))
|
||||
line input #f, t$
|
||||
print t$
|
||||
wend
|
||||
close #f
|
||||
end
|
||||
1
Task/Input-loop/Logo/input-loop.logo
Normal file
1
Task/Input-loop/Logo/input-loop.logo
Normal file
|
|
@ -0,0 +1 @@
|
|||
while [not eof?] [print readline]
|
||||
6
Task/Input-loop/Lua/input-loop-1.lua
Normal file
6
Task/Input-loop/Lua/input-loop-1.lua
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
lines = {}
|
||||
str = io.read()
|
||||
while str do
|
||||
table.insert(lines,str)
|
||||
str = io.read()
|
||||
end
|
||||
5
Task/Input-loop/Lua/input-loop-2.lua
Normal file
5
Task/Input-loop/Lua/input-loop-2.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
lines = {}
|
||||
|
||||
for line in io.lines() do
|
||||
table.insert(lines, line) -- add the line to the list of lines
|
||||
end
|
||||
23
Task/Input-loop/M2000-Interpreter/input-loop.m2000
Normal file
23
Task/Input-loop/M2000-Interpreter/input-loop.m2000
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Document A$={1st Line
|
||||
2nd line
|
||||
3rd line
|
||||
}
|
||||
Save.Doc A$, "test.txt", 0 ' 0 for utf16-le
|
||||
\\ we use Wide for utf16-le \\ without it we open using ANSI
|
||||
Open "test.txt" For Wide Input Exclusive as #N
|
||||
While Not Eof(#N) {
|
||||
Line Input #N, ThisLine$
|
||||
Print ThisLine$
|
||||
}
|
||||
Close #N
|
||||
Clear A$
|
||||
Load.Doc A$, "test.txt"
|
||||
\\ print proportional text, all lines
|
||||
Report A$
|
||||
\\ Print one line, non proportional
|
||||
\\ using paragraphs
|
||||
For i=0 to Doc.par(A$)-1
|
||||
Print Paragraph$(A$, i)
|
||||
Next i
|
||||
\\ List of current variables (in any scope, public only)
|
||||
List
|
||||
10
Task/Input-loop/MAXScript/input-loop.max
Normal file
10
Task/Input-loop/MAXScript/input-loop.max
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fn ReadAFile FileName =
|
||||
(
|
||||
local in_file = openfile FileName
|
||||
while not eof in_file do
|
||||
(
|
||||
--Do stuff in here--
|
||||
print (readline in_file)
|
||||
)
|
||||
close in_file
|
||||
)
|
||||
5
Task/Input-loop/MIRC-Scripting-Language/input-loop.mirc
Normal file
5
Task/Input-loop/MIRC-Scripting-Language/input-loop.mirc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
var %n = 1
|
||||
while (%n <= $lines(input.txt)) {
|
||||
write output.txt $read(input.txt,%n)
|
||||
inc %n
|
||||
}
|
||||
9
Task/Input-loop/Maple/input-loop.maple
Normal file
9
Task/Input-loop/Maple/input-loop.maple
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
readinput:=proc(filename)
|
||||
local line,file;
|
||||
file:="";
|
||||
line:=readline(filename);
|
||||
while line<>0 do
|
||||
line:=readline(filename);
|
||||
file:=cat(file,line);
|
||||
end do;
|
||||
end proc;
|
||||
3
Task/Input-loop/Mathematica/input-loop.math
Normal file
3
Task/Input-loop/Mathematica/input-loop.math
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
stream = OpenRead["file.txt"];
|
||||
While[a != EndOfFile, Read[stream, Word]];
|
||||
Close[stream]
|
||||
31
Task/Input-loop/Mercury/input-loop.mercury
Normal file
31
Task/Input-loop/Mercury/input-loop.mercury
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
:- module input_loop.
|
||||
:- interface.
|
||||
|
||||
:- import_module io.
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
|
||||
:- implementation.
|
||||
|
||||
main(!IO) :-
|
||||
io.stdin_stream(Stdin, !IO),
|
||||
io.stdout_stream(Stdout, !IO),
|
||||
read_and_print_lines(Stdin, Stdout, !IO).
|
||||
|
||||
:- pred read_and_print_lines(io.text_input_stream::in,
|
||||
io.text_output_stream::in, io::di, io::uo) is det.
|
||||
|
||||
read_and_print_lines(InFile, OutFile, !IO) :-
|
||||
io.read_line_as_string(InFile, Result, !IO),
|
||||
(
|
||||
Result = ok(Line),
|
||||
io.write_string(OutFile, Line, !IO),
|
||||
read_and_print_lines(InFile, OutFile, !IO)
|
||||
;
|
||||
Result = eof
|
||||
;
|
||||
Result = error(IOError),
|
||||
Msg = io.error_message(IOError),
|
||||
io.stderr_stream(Stderr, !IO),
|
||||
io.write_string(Stderr, Msg, !IO),
|
||||
io.set_exit_status(1, !IO)
|
||||
).
|
||||
23
Task/Input-loop/Modula-2/input-loop.mod2
Normal file
23
Task/Input-loop/Modula-2/input-loop.mod2
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
PROCEDURE ReadName (VAR str : ARRAY OF CHAR);
|
||||
|
||||
VAR n : CARDINAL;
|
||||
ch, endch : CHAR;
|
||||
|
||||
BEGIN
|
||||
REPEAT
|
||||
InOut.Read (ch);
|
||||
Exhausted := InOut.EOF ();
|
||||
IF Exhausted THEN RETURN END
|
||||
UNTIL ch > ' '; (* Eliminate whitespace *)
|
||||
IF ch = '[' THEN endch := ']' ELSE endch := ch END;
|
||||
n := 0;
|
||||
REPEAT
|
||||
InOut.Read (ch);
|
||||
Exhausted := InOut.EOF ();
|
||||
IF Exhausted THEN RETURN END;
|
||||
IF n <= HIGH (str) THEN str [n] := ch ELSE ch := endch END;
|
||||
INC (n)
|
||||
UNTIL ch = endch;
|
||||
IF n <= HIGH (str) THEN str [n-1] := 0C END;
|
||||
lastCh := ch
|
||||
END ReadName;
|
||||
14
Task/Input-loop/Modula-3/input-loop.mod3
Normal file
14
Task/Input-loop/Modula-3/input-loop.mod3
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
MODULE Output EXPORTS Main;
|
||||
|
||||
IMPORT Rd, Wr, Stdio;
|
||||
|
||||
VAR buf: TEXT;
|
||||
|
||||
<*FATAL ANY*>
|
||||
|
||||
BEGIN
|
||||
WHILE NOT Rd.EOF(Stdio.stdin) DO
|
||||
buf := Rd.GetLine(Stdio.stdin);
|
||||
Wr.PutText(Stdio.stdout, buf);
|
||||
END;
|
||||
END Output.
|
||||
21
Task/Input-loop/NetRexx/input-loop-1.netrexx
Normal file
21
Task/Input-loop/NetRexx/input-loop-1.netrexx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
-- Read from default input stream (console) until end of data
|
||||
lines = ''
|
||||
lines[0] = 0
|
||||
lineNo = 0
|
||||
|
||||
loop label ioloop forever
|
||||
inLine = ask
|
||||
if inLine = null then leave ioloop -- stop on EOF (Try Ctrl-D on UNIX-like systems or Ctrl-Z on Windows)
|
||||
lineNo = lineNo + 1
|
||||
lines[0] = lineNo
|
||||
lines[lineNo] = inLine
|
||||
end ioloop
|
||||
|
||||
loop l_ = 1 to lines[0]
|
||||
say l_.right(4)':' lines[l_]
|
||||
end l_
|
||||
|
||||
return
|
||||
20
Task/Input-loop/NetRexx/input-loop-2.netrexx
Normal file
20
Task/Input-loop/NetRexx/input-loop-2.netrexx
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
-- Read from default input stream (console) until end of data
|
||||
lines = ''
|
||||
lines[0] = 0
|
||||
|
||||
inScanner = Scanner(System.in)
|
||||
loop l_ = 1 while inScanner.hasNext()
|
||||
inLine = inScanner.nextLine()
|
||||
lines[0] = l_
|
||||
lines[l_] = inLine
|
||||
end l_
|
||||
inScanner.close()
|
||||
|
||||
loop l_ = 1 to lines[0]
|
||||
say l_.right(4)':' lines[l_]
|
||||
end l_
|
||||
|
||||
return
|
||||
3
Task/Input-loop/Nim/input-loop-1.nim
Normal file
3
Task/Input-loop/Nim/input-loop-1.nim
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var line = ""
|
||||
while stdin.readLine(line):
|
||||
echo line
|
||||
5
Task/Input-loop/Nim/input-loop-2.nim
Normal file
5
Task/Input-loop/Nim/input-loop-2.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import strutils
|
||||
|
||||
var lines = stdin.readAll()
|
||||
for line in lines.split("\n"):
|
||||
echo line
|
||||
4
Task/Input-loop/Nim/input-loop-3.nim
Normal file
4
Task/Input-loop/Nim/input-loop-3.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var i = open("input.txt")
|
||||
for line in i.lines:
|
||||
discard # process line
|
||||
i.close()
|
||||
2
Task/Input-loop/Nim/input-loop-4.nim
Normal file
2
Task/Input-loop/Nim/input-loop-4.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
for line in "input.text".lines:
|
||||
discard # process line
|
||||
6
Task/Input-loop/OCaml/input-loop-1.ocaml
Normal file
6
Task/Input-loop/OCaml/input-loop-1.ocaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
let rec read_lines ic =
|
||||
try
|
||||
let line = input_line ic in
|
||||
line :: read_lines ic
|
||||
with End_of_file ->
|
||||
[]
|
||||
12
Task/Input-loop/OCaml/input-loop-2.ocaml
Normal file
12
Task/Input-loop/OCaml/input-loop-2.ocaml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
let read_line_opt ic =
|
||||
try Some (input_line ic)
|
||||
with End_of_file -> None
|
||||
|
||||
let read_lines ic =
|
||||
let rec loop acc =
|
||||
match read_line_opt ic with
|
||||
| Some line -> loop (line :: acc)
|
||||
| None -> (List.rev acc)
|
||||
in
|
||||
loop []
|
||||
;;
|
||||
10
Task/Input-loop/OCaml/input-loop-3.ocaml
Normal file
10
Task/Input-loop/OCaml/input-loop-3.ocaml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
let read_lines f ic =
|
||||
let rec loop () =
|
||||
try f (input_line ic); loop ()
|
||||
with End_of_file -> ()
|
||||
in
|
||||
loop ()
|
||||
|
||||
let () =
|
||||
let ic = open_in Sys.argv.(1) in
|
||||
read_lines print_endline ic
|
||||
18
Task/Input-loop/Oberon-2/input-loop.oberon
Normal file
18
Task/Input-loop/Oberon-2/input-loop.oberon
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
MODULE InputLoop;
|
||||
IMPORT
|
||||
StdChannels,
|
||||
Channel;
|
||||
VAR
|
||||
reader: Channel.Reader;
|
||||
writer: Channel.Writer;
|
||||
c: CHAR;
|
||||
BEGIN
|
||||
reader := StdChannels.stdin.NewReader();
|
||||
writer := StdChannels.stdout.NewWriter();
|
||||
|
||||
reader.ReadByte(c);
|
||||
WHILE reader.res = Channel.done DO
|
||||
writer.WriteByte(c);
|
||||
reader.ReadByte(c)
|
||||
END
|
||||
END InputLoop.
|
||||
17
Task/Input-loop/Objeck/input-loop.objeck
Normal file
17
Task/Input-loop/Objeck/input-loop.objeck
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use IO;
|
||||
|
||||
bundle Default {
|
||||
class Test {
|
||||
function : Main(args : System.String[]) ~ Nil {
|
||||
f := FileReader->New("in.txt");
|
||||
if(f->IsOpen()) {
|
||||
string := f->ReadString();
|
||||
while(string->Size() > 0) {
|
||||
string->PrintLine();
|
||||
string := f->ReadString();
|
||||
};
|
||||
f->Close();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Task/Input-loop/Oforth/input-loop.fth
Normal file
1
Task/Input-loop/Oforth/input-loop.fth
Normal file
|
|
@ -0,0 +1 @@
|
|||
: readFile(filename) File new(filename) apply(#println) ;
|
||||
9
Task/Input-loop/OxygenBasic/input-loop.basic
Normal file
9
Task/Input-loop/OxygenBasic/input-loop.basic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
uses Console
|
||||
uses ParseUtil
|
||||
string s=getfile "t.txt"
|
||||
int le=len s
|
||||
int i=1
|
||||
while i<le
|
||||
print GetNextLine(s,i) cr
|
||||
wend
|
||||
pause
|
||||
7
Task/Input-loop/Oz/input-loop.oz
Normal file
7
Task/Input-loop/Oz/input-loop.oz
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
%% Returns a list of lines.
|
||||
%% Text: an instance of Open.text (a mixin class)
|
||||
fun {ReadAll Text}
|
||||
case {Text getS($)} of false then nil
|
||||
[] Line then Line|{ReadAll Text}
|
||||
end
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue