Skip to content

Commit

Permalink
Удалены устаревшие функции FWriteLine и FReadLine (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazdaywik committed Apr 10, 2020
1 parent afcd760 commit 93ae359
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 120 deletions.
10 changes: 5 additions & 5 deletions autotests/Library/Library-FOpen-Append.sref
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//FROM Library
$EXTERN FOpen, FWriteLine, Close, FReadLine;
$EXTERN FOpen, Putout, Close, Get;

$ENTRY Go {
=
Expand All @@ -16,7 +16,7 @@ AppendLine {
<
{
s.FileHandle =
<FWriteLine s.FileHandle e.Line>
<Putout s.FileHandle e.Line>
<Close s.FileHandle>;
}
<FOpen 'a' e.FileName>
Expand All @@ -27,12 +27,12 @@ CheckContent {
s.FileHandle e.Lines =
<
{
(s.FileHandle e.NextLine 0) (e.NextLine 0) e.Lines^ =
(e.NextLine 0) (e.NextLine 0) e.Lines^ =
<Close s.FileHandle>;

(s.FileHandle e.NextLine) (e.NextLine) e.Lines^ =
(e.NextLine) (e.NextLine) e.Lines^ =
<CheckContent s.FileHandle e.Lines>;
}
(<FReadLine s.FileHandle>) e.Lines
(<Get s.FileHandle>) e.Lines
>;
}
16 changes: 0 additions & 16 deletions autotests/Library/Library-FOpen-FWriteLine-Close.sref

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//FROM Library
$EXTERN FOpen, FReadLine, Close;
$EXTERN FOpen, Get, Close;

$ENTRY Go {
=
Expand All @@ -17,17 +17,17 @@ CheckContent {
DoCheckContent {
s.FileHandle e.Lines =
<DoCheckContent-EatLine
s.FileHandle (<FReadLine s.FileHandle>) e.Lines
s.FileHandle (<Get s.FileHandle>) e.Lines
>;
}

Empty { /* пусто */ = ; }

DoCheckContent-EatLine {
s.FileHandle (s.FileHandle e.NextLine 0) (e.NextLine 0) =
s.FileHandle (e.NextLine 0) (e.NextLine 0) =
/* всё, все строчки прочтены */
<Empty <Close s.FileHandle>>;

s.FileHandle (s.FileHandle e.NextLine) (e.NextLine) e.Lines =
s.FileHandle (e.NextLine) (e.NextLine) e.Lines =
<DoCheckContent s.FileHandle e.Lines>;
}
15 changes: 15 additions & 0 deletions autotests/Library/Library-FOpen-Putout-Close.sref
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//FROM Library
$EXTERN FOpen, Putout, Close;

$ENTRY Go {
= <FillFile <FOpen 'W' '__written_file.txt'>>;
}

Empty { /* пусто */ = ; }

FillFile {
s.FileHandle =
<Empty <Putout s.FileHandle 'Hello'>>
<Empty <Putout s.FileHandle 'World'>>
<Empty <Close s.FileHandle>>;
}
17 changes: 7 additions & 10 deletions autotests/Library/Library-FOpen-extended-mode.sref
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
//FROM Library
$EXTERN FOpen, FWriteLine, Close;
$EXTERN FOpen, Putout, Close;

$ENTRY Go {
=
<SaveFile <FOpen 'w' '__written_file.txt'> ('Ehllo') ('World')>
<Close
<FWriteLine
<FOpen ('r+') '__written_file.txt'>
'Hello'
>
>;
= <SaveFile <FOpen 'w' '__written_file.txt'> ('Ehllo') ('World')> : /* empty */
= <FOpen ('r+') '__written_file.txt'> : s.FileHandle
= <Putout s.FileHandle 'Hello'>
<Close s.FileHandle>;
}

SaveFile {
s.FileHandle (e.Line) e.Lines =
<SaveFile <FWriteLine s.FileHandle e.Line> e.Lines>;
<Putout s.FileHandle e.Line>
<SaveFile s.FileHandle e.Lines>;

s.FileHandle /* кончились строчки */ =
<Close s.FileHandle>;
Expand Down
6 changes: 0 additions & 6 deletions autotests/Library/Library-FReadLine-0-Fail.sref

This file was deleted.

14 changes: 7 additions & 7 deletions autotests/Library/Library-FSeek.sref
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//FROM Library
$EXTERN FOpen, FReadLine, FSeek, Close;
$EXTERN FOpen, Get, FSeek, Close;

$ENTRY Go {
= <Test-FSeek <FOpen 'r' '2lines-no-eol.txt'>>;
Expand All @@ -9,16 +9,16 @@ Eq { (e.X) e.X = ; }

Test-FSeek {
s.FH =
<Eq (s.FH 'Hello') <FReadLine s.FH>>
<Eq ('Hello') <Get s.FH>>
<Eq () <FSeek s.FH #BEGIN '+' 0>>
<Eq (s.FH 'Hello') <FReadLine s.FH>>
<Eq ('Hello') <Get s.FH>>
<Eq () <FSeek s.FH #BEGIN '+' 3>>
<Eq (s.FH 'lo') <FReadLine s.FH>>
<Eq ('lo') <Get s.FH>>
<Eq () <FSeek s.FH #CURRENT '+' 2>>
<Eq (s.FH 'rld' 0) <FReadLine s.FH>>
<Eq ('rld' 0) <Get s.FH>>
<Eq () <FSeek s.FH #CURRENT '-' 5>>
<Eq (s.FH 'World' 0) <FReadLine s.FH>>
<Eq ('World' 0) <Get s.FH>>
<Eq () <FSeek s.FH #END '-' 4>>
<Eq (s.FH 'orld' 0) <FReadLine s.FH>>
<Eq ('orld' 0) <Get s.FH>>
<Close s.FH>;
}
6 changes: 0 additions & 6 deletions autotests/Library/Library-FWrite-unopened-file-Fail.sref

This file was deleted.

6 changes: 0 additions & 6 deletions autotests/Library/Library-FWriteLine-0-Fail.sref

This file was deleted.

4 changes: 2 additions & 2 deletions autotests/Library/Library-WriteBytes.sref
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//FROM Library
$EXTERN FOpen, WriteBytes, FWriteLine, Close;
$EXTERN FOpen, WriteBytes, Putout, Close;

$ENTRY Go {
=
Expand All @@ -9,7 +9,7 @@ $ENTRY Go {
// Hello в десятичных кодах
<IsEmpty <WriteBytes s.FileHandle 72 101 108 25600108 111>>
// перевод строки
<FWriteLine s.FileHandle>
<Putout s.FileHandle>
// World без перевода строки в конце
<IsEmpty <WriteBytes s.FileHandle 'World'>>
<Close s.FileHandle>;
Expand Down
4 changes: 2 additions & 2 deletions autotests/Library/Library-symbolic-file-handles.sref
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//FROM Library
$EXTERN Put, Putout, FWriteLine, Get, Close, Close;
$EXTERN Put, Putout, Get, Close, Close;

$ENTRY Go {
= <Get #stdin> : e.FirstLine
= <Put "stdout" e.FirstLine> : 'Hello'
= <Putout #stderr e.FirstLine> : /* empty */
= <Get "stdin"> : e.SecondLine
= <Put #stderr e.SecondLine> : 'World'
= <FWriteLine "stout" e.SecondLine> : #stout /* empty */
= <Putout "stout" e.SecondLine> : /* empty */
/* this functions must do nothing: */
= <Close #stdin> : /* empty */
= <Close #stdout> : /* empty */
Expand Down
13 changes: 5 additions & 8 deletions autotests/Library/run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ setlocal
Library-LongMath-Mod-OK ^
Library-LongMath-Numb-OK ^
Library-LongMath-Symb-OK ^
Library-FOpen-FReadLine-Close ^
Library-FOpen-Get-Close ^
Library-IntFromStr-StrFromInt-Chr-Ord ^
Library-SymbCompare ^
Library-Type ^
Expand All @@ -82,9 +82,6 @@ setlocal
Library-Math-Div-Fail ^
Library-Math-Mod-Fail ^
Library-FOpen-Fail ^
Library-FWrite-unopened-file-Fail ^
Library-FReadLine-0-Fail ^
Library-FWriteLine-0-Fail ^
Library-SymbCompare-Fail ^
Library-Implodes-Fail ^
Library-PtrFromName-Fail ^
Expand All @@ -104,11 +101,11 @@ setlocal
call :CLEANUP Library-WriteLine-Expr
)

if exist Library-FOpen-FWriteLine-Close.exe (
echo Pass Library-FOpen-FWriteLine-Close test...
call :RUN_EXE Library-FOpen-FWriteLine-Close || exit /b 1
if exist Library-FOpen-Putout-Close.exe (
echo Pass Library-FOpen-Putout-Close test...
call :RUN_EXE Library-FOpen-Putout-Close || exit /b 1
call :COMPARE __written_file.txt 2lines.txt || exit /b 1
call :CLEANUP Library-FOpen-FWriteLine-Close
call :CLEANUP Library-FOpen-Putout-Close
)

if exist Library-ReadLine-2lines.exe (
Expand Down
13 changes: 5 additions & 8 deletions autotests/Library/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ run_all_tests() {
Library-LongMath-Mod-OK \
Library-LongMath-Numb-OK \
Library-LongMath-Symb-OK \
Library-FOpen-FReadLine-Close \
Library-FOpen-Get-Close \
Library-IntFromStr-StrFromInt-Chr-Ord \
Library-SymbCompare \
Library-Type \
Expand All @@ -72,9 +72,6 @@ run_all_tests() {
Library-Math-Div-Fail \
Library-Math-Mod-Fail \
Library-FOpen-Fail \
Library-FWrite-unopened-file-Fail \
Library-FReadLine-0-Fail \
Library-FWriteLine-0-Fail \
Library-SymbCompare-Fail \
Library-Implodes-Fail \
Library-PtrFromName-Fail
Expand All @@ -93,11 +90,11 @@ run_all_tests() {
cleanup Library-WriteLine-Expr
fi

if [ -e Library-FOpen-FWriteLine-Close ]; then
echo Pass Library-FOpen-FWriteLine-Close test...
run_exe Library-FOpen-FWriteLine-Close
if [ -e Library-FOpen-Putout-Close ]; then
echo Pass Library-FOpen-Putout-Close test...
run_exe Library-FOpen-Putout-Close
compare __written_file.txt 2lines.txt
cleanup Library-FOpen-FWriteLine-Close
cleanup Library-FOpen-Putout-Close
fi

if [ -e Library-ReadLine-2lines ]; then
Expand Down
28 changes: 1 addition & 27 deletions src/lib/Library.ref
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,6 @@ $ENTRY Put {
namespace cookie_ns {

enum {
cFlags_ReturnHandle = 1 << 3,
cFlags_Transparent = 1 << 5,
cFlags_NoEOL = 1 << 8,
};
Expand Down Expand Up @@ -1438,13 +1437,8 @@ refalrts::FnResult cookie_ns::fwrite_line(
return refalrts::cRecognitionImpossible;
}

refalrts::Iter res = arg_begin;
if (flags & cFlags_Transparent) {
res = refalrts::splice_evar(res, content_b, content_e);
}

if (flags & cFlags_ReturnHandle) {
refalrts::splice_stvar(res, pfile_handle);
refalrts::splice_evar(arg_begin, content_b, content_e);
}

refalrts::splice_to_freelist(vm, arg_begin, arg_end);
Expand Down Expand Up @@ -3061,26 +3055,6 @@ $ENTRY FOpen {
}


/**
<FReadLine s.FileNo> == s.FileNo s.CHAR* 0?
*/
$ENTRY FReadLine {
s.FileNo = s.FileNo <Get-Aux s.FileNo>;
}


/**
<FWriteLine s.FileNo e.AnyExpression> == s.FileNo
*/
$ENTRY FWriteLine {
%%
return cookie_ns::fwrite_line(
vm, identifiers, arg_begin, arg_end, cookie_ns::cFlags_ReturnHandle
);
%%
}


/*
<GetFreeHandle> == s.FileNo
Function fails if free handle is not found.
Expand Down
24 changes: 12 additions & 12 deletions src/lib/LibraryEx.ref
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$INCLUDE "LibraryEx";

*$FROM Library
$EXTERN FOpen, Close, FReadLine, FWriteLine, Add, Sub, IntFromStr, Arg,
$EXTERN FOpen, Close, Get, Putout, Add, Sub, IntFromStr, Arg,
SymbCompare, ReadBytes, WriteBytes;

$ENTRY Apply;
Expand All @@ -23,15 +23,17 @@ $ENTRY UnBracket;
$ENTRY DelAccumulator;

$ENTRY LoadFile {
e.FileName = <DoLoadFile <FReadLine <FOpen 'r' e.FileName>>>;
e.FileName
= <FOpen 'r' e.FileName> : t.File
= <DoLoadFile t.File <Get t.File>>;
}

DoLoadFile {
t.File 0 = <Close t.File>;

t.File e.Line 0 = (e.Line) <Close t.File>;

t.File e.Line = (e.Line) <DoLoadFile <FReadLine t.File>>;
t.File e.Line = (e.Line) <DoLoadFile t.File <Get t.File>>;
}

$ENTRY SaveFile {
Expand All @@ -44,15 +46,13 @@ $ENTRY AppendFile {

SaveFile-Handle {
s.FileHandle e.Lines
= <Close
<Reduce
{
s.FileHandle^ (e.Line) = <FWriteLine s.FileHandle e.Line>;
}
s.FileHandle
e.Lines
>
>;
= <Map
{
(e.Line) = <Putout s.FileHandle e.Line>;
}
e.Lines
>
<Close s.FileHandle>;
}

$ENTRY LoadBytes {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/common/Library.refi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $INCLUDE "refal5-builtins.refi";
$EXTERN PtrFromName;

*$FROM Library
$EXTERN FOpen, FReadLine, FWriteLine, ReadLine, WriteLine, IntFromStr,
$EXTERN FOpen, ReadLine, WriteLine, IntFromStr,
StrFromInt, SymbCompare, WriteBytes, ReadBytes, FTell, FSeek, RenameFile;

*$FROM Library
Expand Down

0 comments on commit 93ae359

Please sign in to comment.