summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/plaparse.cpp
diff options
context:
space:
mode:
author Vas Crabb <cuavas@users.noreply.github.com>2024-02-25 02:27:26 +1100
committer GitHub <noreply@github.com>2024-02-25 02:27:26 +1100
commit1615b8551a3a73532ac234973cfb04dd8ed98ba4 (patch)
tree25575506b4117afa614b94b4370af7f16eb9dbb5 /src/lib/util/plaparse.cpp
parent334ec12e0043ef939be418283235e3dbe5a005fe (diff)
util/ioprocs.cpp: Added wrappers for common patterns. (#11608)
emu/diimage.h: Removed fread overloads that allocate memory for output. util/core_file.cpp: Changed output size of load to size_t.
Diffstat (limited to 'src/lib/util/plaparse.cpp')
-rw-r--r--src/lib/util/plaparse.cpp40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/lib/util/plaparse.cpp b/src/lib/util/plaparse.cpp
index 423939b41a8..9f4d1c0bc14 100644
--- a/src/lib/util/plaparse.cpp
+++ b/src/lib/util/plaparse.cpp
@@ -68,11 +68,14 @@ static uint32_t suck_number(util::random_read &src)
uint32_t value = 0;
// find first digit
- uint8_t ch;
- std::size_t actual;
bool found = false;
- while (!src.read(&ch, 1, actual) && actual == 1)
+ while (true)
{
+ uint8_t ch;
+ auto const [err, actual] = read(src, &ch, 1);
+ if (err || (1 != actual))
+ break;
+
// loop over and accumulate digits
if (isdigit(ch))
{
@@ -189,8 +192,8 @@ static bool process_terms(jed_data *data, util::random_read &src, uint8_t ch, pa
curoutput = 0;
}
- std::size_t actual;
- if (src.read(&ch, 1, actual))
+ auto const [err, actual] = read(src, &ch, 1);
+ if (err)
return false;
if (actual != 1)
return true;
@@ -227,9 +230,11 @@ static bool process_field(jed_data *data, util::random_read &src, parse_info *pi
int destptr = 0;
uint8_t seek;
- std::size_t actual;
- while (!src.read(&seek, 1, actual) && actual == 1 && isalpha(seek))
+ while (true)
{
+ auto const [err, actual] = read(src, &seek, 1);
+ if (err || (actual != 1) || !isalpha(seek))
+ break;
dest[destptr++] = tolower(seek);
if (destptr == sizeof(dest))
break;
@@ -275,8 +280,11 @@ static bool process_field(jed_data *data, util::random_read &src, parse_info *pi
// output polarity (optional)
case KW_PHASE:
if (LOG_PARSE) printf("Phase...\n");
- while (!src.read(&seek, 1, actual) && actual == 1 && !iscrlf(seek) && pinfo->xorptr < (JED_MAX_FUSES/2))
+ while (true)
{
+ auto const [err, actual] = read(src, &seek, 1);
+ if (err || (actual != 1) || iscrlf(seek) || (pinfo->xorptr >= (JED_MAX_FUSES / 2)))
+ break;
if (seek == '0' || seek == '1')
{
// 0 is negative
@@ -322,19 +330,23 @@ int pla_parse(util::random_read &src, jed_data *result)
result->numfuses = 0;
memset(result->fusemap, 0, sizeof(result->fusemap));
- uint8_t ch;
- std::size_t actual;
- while (!src.read(&ch, 1, actual) && actual == 1)
+ while (true)
{
+ std::error_condition err;
+ size_t actual;
+ uint8_t ch;
+ std::tie(err, actual) = read(src, &ch, 1);
+ if (err || (actual != 1))
+ break;
switch (ch)
{
// comment line
case '#':
- while (!src.read(&ch, 1, actual) && actual == 1)
+ do
{
- if (iscrlf(ch))
- break;
+ std::tie(err, actual) = read(src, &ch, 1);
}
+ while (!err && (actual == 1) && !iscrlf(ch));
break;
// keyword