RosettaCodeData/Task/Read-a-configuration-file/XPL0/read-a-configuration-file.xpl0
2025-06-11 20:16:52 -04:00

56 lines
1.6 KiB
Text

string 0; \use zero-terminated strings
proc StrIn(Str); \Read alphanumeric string from input file
char Str;
int I, C;
[I:= 0;
loop [C:= ChIn(3);
if C<$20 or C=^, then quit;
Str(I):= C; I:= I+1;
];
Str(I):= 0;
];
char FullName(100), FavoriteFruit(100), OtherFamily(2, 100);
int NeedsPeeling, SeedsRemoved;
int C;
[NeedsPeeling:= false; SeedsRemoved:= false;
FullName(0):= 0; FavoriteFruit(0):= 0;
OtherFamily(0, 0):= 0; OtherFamily(1, 0):= 0;
FSet(FOpen("configfile.txt", 0), ^i);
OpenI(3);
C:= ChIn(3);
while C # $1A \EOF\ do
[if C = $0A \LF\ then
[C:= ChIn(3);
if C = ^N then NeedsPeeling:= true;
if C = ^O then
[repeat C:= ChIn(3) until C <= $20;
StrIn(@OtherFamily(0, 0));
C:= ChIn(3);
StrIn(@OtherFamily(1, 0));
];
if C = ^F then
[C:= ChIn(3);
if C = ^U then
[repeat C:= ChIn(3) until C <= $20;
StrIn(FullName);
];
if C = ^A then
[repeat C:= ChIn(3) until C <= $20;
StrIn(FavoriteFruit);
];
];
]
else C:= ChIn(3);
];
Text(0, "Full name: "); Text(0, FullName); CrLf(0);
Text(0, "Favorite fruit: "); Text(0, FavoriteFruit); CrLf(0);
Text(0, "Needs peeling: "); Text(0, if NeedsPeeling then "true" else "false");
CrLf(0);
Text(0, "Seeds removed: "); Text(0, if SeedsRemoved then "true" else "false");
CrLf(0);
Text(0, "Other family: "); Text(0, @OtherFamily(0, 0));
Text(0, ", "); Text(0, @OtherFamily(1, 0));
CrLf(0);
]