Sharp X68000 Disassemblies
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xlate.c 674B

1234567891011121314151617181920212223242526272829303132
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main(int argc, char **argv) {
  4. char buf[512];
  5. while(fgets(buf, sizeof(buf), stdin)) {
  6. char *from = buf;
  7. char *to = strchr(buf, '\t');
  8. if(!to) continue;
  9. *to = 0;
  10. to++;
  11. char *end = strchr(to, '\n');
  12. if(end) *end = 0;
  13. printf("s/");
  14. for(unsigned char *c = from; *c; c++) {
  15. if(*c > 127) printf("\\x%02x", *c);
  16. else if(strchr("$.*[\\^/", *c)) printf("\\%c", *c);
  17. else printf("%c", *c);
  18. }
  19. printf("/");
  20. for(unsigned char *c = to; *c; c++) {
  21. if(strchr("/", *c)) printf("\\%c", *c);
  22. else if(strchr("'", *c)) printf("',$%02x,'", *c);
  23. else printf("%c", *c);
  24. }
  25. printf("/g\n");
  26. }
  27. return 0;
  28. }