Skip to content

Commit

Permalink
fixes z
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerboa-app committed Feb 7, 2024
1 parent f335a4c commit 6ea4903
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tools/z/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

const uint8_t width = 80;

std::string byteToHex(char c)
std::string byteToHex(uint8_t c)
{
std::stringstream ss;

ss << std::hex << std::setw(2) << std::setfill('0') << c;
ss << std::hex << std::setw(2) << std::setfill('0') << int(c);

std::string s = ss.str();

Expand All @@ -21,7 +21,7 @@ std::string byteToHex(char c)

int main(int argc, char ** argv)
{
if (argc == 2)
if (argc >= 2)
{
// read in a file
std::string file = argv[1];
Expand Down Expand Up @@ -75,20 +75,22 @@ int main(int argc, char ** argv)
{
out << "static const unsigned char bytes[] __attribute__((unused)) = {\n";
unsigned w = 0;
unsigned n = 0;
for (uint8_t c : zd)
{
out << c;
out << byteToHex(c);
w += 5;

if (w >= width)
{
out << "\n";
w = 0;
}
else
else if (n < zd.size()-1)
{
out << ",";
}
n+=1;
}
out << "}";
}
Expand Down

0 comments on commit 6ea4903

Please sign in to comment.