Take notes on the command line: Difference between revisions

Added XPL0 example.
m (→‎{{header|Phix}}: syntax coloured, simplified, marked p2js incompatible)
(Added XPL0 example.)
Line 2,609:
2021-09-29 16:51
my second note
</pre>
 
=={{header|XPL0}}==
Checks for unlikely array overflows have been omitted for simplicity.
<lang XPL0>include xpllib; \Date and Time routines
int I, NotesSize, Ch, CmdArgSize;
char Notes(1_000_000), CmdArg(1000);
[\Read in notes.txt, if it exists
Trap(false); \disable abort on errors
FSet(FOpen("notes.txt", 0), ^i);
OpenI(3);
if GetErr = 0 then \file exists
[I:= 0;
while GetErr = 0 do \GetErr detects end-of-file
[Notes(I):= ChIn(3);
I:= I+1;
];
NotesSize:= I-2; \remove 2 EOFs
];
\Get command-line argument, if any, from command line
I:= 0;
loop [Ch:= ChIn(8);
if Ch = CR then quit;
CmdArg(I):= Ch;
I:= I+1;
];
CmdArg(I):= 0; \terminate string
if I = 0 then \no args, just display notes.txt
for I:= 0 to NotesSize-1 do ChOut(0, Notes(I))
else \open notes.txt for output and append CmdArg
[FSet(FOpen("notes.txt", 1), ^o);
OpenO(3);
for I:= 0 to NotesSize-1 do ChOut(3, Notes(I));
DateOut(3, GetDosDate); ChOut(3, ^ );
TimeOut(3, GetDosTime); CrLf(3);
ChOut(3, Tab); Text(3, CmdArg); CrLf(3);
Close(3);
];
]</lang>
 
{{out}}
<pre>
18-Apr-2022 1:27:14p
first line
18-Apr-2022 1:27:30p
another line
18-Apr-2022 1:42:02p
final test
</pre>
 
772

edits