tb1/tb1_snes/tools/string_to_bytes.c
Vince Weaver dbaf404ec3 snes: rename tb_snes to tb1_snes
I kept typing it wrong anyway, and hey, git makes rename easy
2013-01-22 09:53:01 -05:00

36 lines
661 B
C

#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
char buffer[BUFSIZ],*result;
int i;
int quotes_open=0;
while(1) {
result=fgets(buffer,BUFSIZ,stdin);
if (result==NULL) return 0;
printf("\t.byte ");
for(i=0;i<strlen(buffer);i++) {
if (buffer[i] < 32) {
if (quotes_open) printf("\",");
printf("$%02x",buffer[i]);
if (i<strlen(buffer)-1) printf(", ");
quotes_open=0;
}
else {
if (!quotes_open) printf("\"");
printf("%c",buffer[i]);
quotes_open=1;
}
}
if (quotes_open) printf("\"");
quotes_open=0;
printf("\n");
}
return 0;
}