Skip to content

Commit

Permalink
[modernization] Migrated code base to use cstdint
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanAlling-DojoFive committed Feb 14, 2023
1 parent 513ba3b commit da88b66
Show file tree
Hide file tree
Showing 258 changed files with 995 additions and 984 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ m4/lt~obsolete.m4

# CMake
/build

# clangd
.cache/*
2 changes: 1 addition & 1 deletion srec_cat/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ main(int argc, char **argv)
int address_length = 0;
std::string header;
bool header_set = false;
unsigned long execution_start_address = 0;
uint32_t execution_start_address = 0;
bool execution_start_address_set = false;
int output_block_size = 0;
bool output_block_packing = false;
Expand Down
14 changes: 5 additions & 9 deletions srecord/adler16.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,23 @@

#include <srecord/adler16.h>

unsigned short
srecord::adler16::get()
const
uint16_t srecord::adler16::get() const
{
return ((((unsigned short)sum_b) << 8) | sum_a);
return ((((uint16_t)sum_b) << 8) | sum_a);
}


void
srecord::adler16::next(unsigned char c)
void srecord::adler16::next(uint8_t c)
{
// This is not portable to int=16-bit machines
sum_a = (sum_a + c) % 251;
sum_b = (sum_b + sum_a) % 251;
}


void
srecord::adler16::nextbuf(const void *data, size_t nbytes)
void srecord::adler16::nextbuf(const void *data, size_t nbytes)
{
const auto *dp = (const unsigned char *)data;
const auto *dp = (const uint8_t *)data;
while (nbytes > 0)
{
next(*dp);
Expand Down
11 changes: 6 additions & 5 deletions srecord/adler16.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define SRECORD_ADLER16_H

#include <cstddef>
#include <cstdint>

namespace srecord
{
Expand All @@ -35,12 +36,12 @@ class adler16
/**
* The get method is used to obtain the running value of the checksum.
*/
unsigned short get() const;
uint16_t get() const;

/**
* The next method is used to advance the state by one byte.
*/
void next(unsigned char);
void next(uint8_t);

/**
* The nextbuf method is used to advance the state by a series of bytes.
Expand All @@ -52,15 +53,15 @@ class adler16
* The sum_a instance variable is used to remember the sum of bytes
* scanned.
*/
unsigned char sum_a{1};
uint8_t sum_a{1};

/**
* The sum_b instance variable is used to remember the sum of the
* sum of bytes scanned.
*/
unsigned char sum_b{0};
uint8_t sum_b{0};
};

};
} // namespace srecord

#endif // SRECORD_ADLER16_H
10 changes: 4 additions & 6 deletions srecord/adler32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@

#include <srecord/adler32.h>

unsigned long
srecord::adler32::get()
const
uint32_t srecord::adler32::get() const
{
return ((((unsigned long)sum_b) << 16) | sum_a);
return ((((uint32_t)sum_b) << 16) | sum_a);
}


void
srecord::adler32::next(unsigned char c)
srecord::adler32::next(uint8_t c)
{
// This is not portable to int=16-bit machines
sum_a = (sum_a + c) % 65521;
Expand All @@ -38,7 +36,7 @@ srecord::adler32::next(unsigned char c)
void
srecord::adler32::nextbuf(const void *data, size_t nbytes)
{
const auto *dp = (const unsigned char *)data;
const auto *dp = (const uint8_t *)(data);
while (nbytes > 0)
{
next(*dp);
Expand Down
9 changes: 5 additions & 4 deletions srecord/adler32.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define SRECORD_ADLER32_H

#include <cstddef>
#include <cstdint>

namespace srecord
{
Expand All @@ -38,12 +39,12 @@ class adler32
* The get method is used to obtain the running value of the
* checksum.
*/
unsigned long get() const;
uint32_t get() const;

/**
* The next method is used to advance the state by one byte.
*/
void next(unsigned char);
void next(uint8_t);

/**
* The nextbuf method is used to advance the state by a series of bytes.
Expand All @@ -55,13 +56,13 @@ class adler32
* The sum_a instance variable is used to remember the sum of bytes
* scanned.
*/
unsigned short sum_a{1};
uint16_t sum_a{1};

/**
* The sum_b instance variable is used to remember the sum of the
* sum of bytes scanned.
*/
unsigned short sum_b{0};
uint16_t sum_b{0};
};

};
Expand Down
6 changes: 3 additions & 3 deletions srecord/arglex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ srecord::arglex::read_arguments_file(const char *filename)
int sc = getc(fp);
if (sc == EOF)
break;
unsigned char c = sc;
uint8_t c = sc;

//
// Ignore white space between words.
Expand Down Expand Up @@ -144,10 +144,10 @@ srecord::arglex::compare(const char *formal, const char *actual)
{
for (;;)
{
unsigned char ac = *actual++;
uint8_t ac = *actual++;
if (isupper(ac))
ac = tolower(ac);
unsigned char fc = *formal++;
uint8_t fc = *formal++;
switch (fc)
{
case 0:
Expand Down
2 changes: 1 addition & 1 deletion srecord/arglex/abbreviate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ srecord::arglex::abbreviate(const char *s)
std::string result;
for (;;)
{
unsigned char c = *s++;
uint8_t c = *s++;
switch (c)
{
case '\0':
Expand Down
10 changes: 5 additions & 5 deletions srecord/arglex/tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ srecord::arglex_tool::can_get_number()


void
srecord::arglex_tool::get_address(const char *name, unsigned long &address)
srecord::arglex_tool::get_address(const char *name, uint32_t &address)
{
if (!can_get_number())
{
Expand All @@ -283,7 +283,7 @@ srecord::arglex_tool::get_address(const char *name, unsigned long &address)

void
srecord::arglex_tool::get_address_and_nbytes(const char *name,
unsigned long &address, int &nbytes)
uint32_t &address, int &nbytes)
{
if (!can_get_number())
{
Expand All @@ -300,7 +300,7 @@ srecord::arglex_tool::get_address_and_nbytes(const char *name,
{
fatal_error
(
"the %s address (0x%8.8lX) and byte count (%d) may not span the "
"the %s address (0x%8.8X) and byte count (%d) may not span the "
"top of memory",
name,
address,
Expand All @@ -313,7 +313,7 @@ srecord::arglex_tool::get_address_and_nbytes(const char *name,

void
srecord::arglex_tool::get_address_nbytes_width(const char *name,
unsigned long &address, int &nbytes, int &width)
uint32_t &address, int &nbytes, int &width)
{
address = get_number("address");
nbytes = 4;
Expand All @@ -330,7 +330,7 @@ srecord::arglex_tool::get_address_nbytes_width(const char *name,
{
fatal_error
(
"the %s address (0x%8.8lX) and byte count (%d) may not span the "
"the %s address (0x%8.8X) and byte count (%d) may not span the "
"top of memory",
name,
address,
Expand Down
10 changes: 5 additions & 5 deletions srecord/arglex/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class arglex_tool:
* The get_number method is used to parse a numeric value from the
* command line.
*/
unsigned long get_number(const char *caption);
uint32_t get_number(const char *caption);

/**
* The get_number method is used to parse a numeric value
Expand All @@ -257,7 +257,7 @@ class arglex_tool:
* @param max
* The maximum acceptable value (inclusive)
*/
unsigned long get_number(const char *caption, long min, long max);
uint32_t get_number(const char *caption, long min, long max);

/**
* The can_get_number method is used to determine if it is possible
Expand Down Expand Up @@ -345,7 +345,7 @@ class arglex_tool:
* line) a fatal error will be issued and the method call will
* not return.
*/
void get_address(const char *err_msg_caption, unsigned long &addr);
void get_address(const char *err_msg_caption, uint32_t &addr);

/**
* The get_address_and_nbytes method is used to parse an address
Expand All @@ -356,7 +356,7 @@ class arglex_tool:
* not return.
*/
void get_address_and_nbytes(const char *err_msg_caption,
unsigned long &addr, int &nbytes);
uint32_t &addr, int &nbytes);

/**
* The get_address_nbytes_width method is used to parse an address
Expand All @@ -367,7 +367,7 @@ class arglex_tool:
* not return.
*/
void get_address_nbytes_width(const char *err_msg_caption,
unsigned long &addr, int &nbytes, int &width);
uint32_t &addr, int &nbytes, int &width);

/**
* The stdin_used instance variable is used to remember whether
Expand Down
6 changes: 3 additions & 3 deletions srecord/arglex/tool/get_interval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ srecord::arglex_tool::get_interval_factor(const char *name)
);
// NOTREACHED
}
unsigned long n1 = get_number("address range minimum");
unsigned long n2 = 0;
uint32_t n1 = get_number("address range minimum");
uint32_t n2 = 0;
if (can_get_number())
{
n2 = get_number("address range maximum");
Expand All @@ -84,7 +84,7 @@ srecord::arglex_tool::get_interval_factor(const char *name)
{
fatal_error
(
"the %s range %lu..%lu is invalid",
"the %s range %u..%u is invalid",
name,
n1,
n2
Expand Down
8 changes: 4 additions & 4 deletions srecord/arglex/tool/get_number.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
#include <srecord/input/interval.h>


unsigned long
uint32_t
srecord::arglex_tool::get_number(const char *caption)
{
unsigned long value = 0;
unsigned long multiple;
uint32_t value = 0;
uint32_t multiple;
interval over;

switch (token_cur())
Expand Down Expand Up @@ -132,7 +132,7 @@ srecord::arglex_tool::get_number(const char *caption)
}


unsigned long
uint32_t
srecord::arglex_tool::get_number(const char *caption, long minimum,
long maximum)
{
Expand Down
Loading

0 comments on commit da88b66

Please sign in to comment.