summaryrefslogtreecommitdiff
path: root/tool/p8bin2uart.c
diff options
context:
space:
mode:
authorJulian Blake Kongslie2022-04-17 15:57:49 -0700
committerJulian Blake Kongslie2022-04-17 15:58:55 -0700
commit2f0a2dd8ef3dfd40457fb5a0b14a7c1a00b43fdc (patch)
treec5fa87806bb2dc2f62b7a5efa9b2d84a1b67c954 /tool/p8bin2uart.c
parentWorking (but very slow) RS232 UART (diff)
downloadmultipdp8-2f0a2dd8ef3dfd40457fb5a0b14a7c1a00b43fdc.tar.xz
Fix whitespace/maxlinesize handling in p8bin2uart.
Diffstat (limited to '')
-rw-r--r--tool/p8bin2uart.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/tool/p8bin2uart.c b/tool/p8bin2uart.c
index 944227a..de5a328 100644
--- a/tool/p8bin2uart.c
+++ b/tool/p8bin2uart.c
@@ -146,13 +146,13 @@ print(const char *fmt, ...)
146 va_start(args, fmt); 146 va_start(args, fmt);
147 vsnprintf(tmp, size, fmt, args); 147 vsnprintf(tmp, size, fmt, args);
148 va_end(args); 148 va_end(args);
149 strncat(buf, tmp, MAX_LINE_SIZE * 2 - 1); 149 strcat(buf, tmp);
150 if (strlen(buf) > MAX_LINE_SIZE) { 150 if (strlen(buf) > MAX_LINE_SIZE) {
151 char *space = strrchr(buf, ' '); 151 char *space = strrchr(buf, ' ');
152 assert(space); 152 assert(space);
153 assert(space - buf <= MAX_LINE_SIZE); 153 assert(space - buf <= MAX_LINE_SIZE);
154 *space = 0; 154 assert(*space == ' ');
155 ++space; 155 *space++ = '\0';
156 assert(strlen(buf) <= MAX_LINE_SIZE); 156 assert(strlen(buf) <= MAX_LINE_SIZE);
157 printf("%s\n", buf); 157 printf("%s\n", buf);
158 memmove(buf, space, buf + sizeof(buf) - space); 158 memmove(buf, space, buf + sizeof(buf) - space);
@@ -181,18 +181,17 @@ dump(unsigned int wordsperline)
181 if (allzero) continue; 181 if (allzero) continue;
182 if (nextaddr != a) { 182 if (nextaddr != a) {
183 if (nextaddr + wordsperline == a) 183 if (nextaddr + wordsperline == a)
184 print("= "); 184 print(" =");
185 else 185 else
186 print("!%x ", (unsigned int)((a - nextaddr) / wordsperline)); 186 print(" !%x", (unsigned int)((a - nextaddr) / wordsperline));
187 } 187 }
188 print("="); 188 print(" =");
189 for (uint_fast32_t i = 0; i < wordsperline; ++i) 189 for (uint_fast32_t i = 0; i < wordsperline; ++i)
190 print(i == 0 ? "%x" : ":%04x", (unsigned int)words[i]); 190 print(i == 0 ? "%x" : ":%04x", (unsigned int)words[i]);
191 print(" ");
192 nextaddr = a + wordsperline; 191 nextaddr = a + wordsperline;
193 } 192 }
194 if (nextaddr != 32768) 193 if (nextaddr != 32768)
195 print("!%x\n", (unsigned int)((32768 - nextaddr) / wordsperline)); 194 print(" !%x\n", (unsigned int)((32768 - nextaddr) / wordsperline));
196 flush(); 195 flush();
197} 196}
198 197