data2s.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. void
  13. main(int argc, char *argv[])
  14. {
  15. Biobuf bin, bout;
  16. int32_t len, slen;
  17. int c;
  18. if(argc != 2){
  19. fprint(2, "usage: data2s name\n");
  20. exits("usage");
  21. }
  22. Binit(&bin, 0, OREAD);
  23. Binit(&bout, 1, OWRITE);
  24. for(len=0; (c=Bgetc(&bin))!=Beof; len++){
  25. if((len&7) == 0)
  26. Bprint(&bout, "DATA %scode+%ld(SB)/8, $\"", argv[1], len);
  27. if(c)
  28. Bprint(&bout, "\\%uo", c);
  29. else
  30. Bprint(&bout, "\\z");
  31. if((len&7) == 7)
  32. Bprint(&bout, "\"\n");
  33. }
  34. slen = len;
  35. if(len & 7){
  36. while(len & 7){
  37. Bprint(&bout, "\\z");
  38. len++;
  39. }
  40. Bprint(&bout, "\"\n");
  41. }
  42. Bprint(&bout, "GLOBL %scode+0(SB), $%ld\n", argv[1], len);
  43. Bprint(&bout, "GLOBL %slen+0(SB), $4\n", argv[1]);
  44. Bprint(&bout, "DATA %slen+0(SB)/4, $%ld\n", argv[1], slen);
  45. exits(0);
  46. }