1 #include <lib9.h> 2 #include <bio.h> 3 4 void 5 main(int argc, char *argv[]) 6 { 7 Biobuf bin, bout; 8 long len; 9 int n; 10 uchar block[16], *c; 11 12 if(argc != 2){ 13 fprint(2, "usage: data2s name\n"); 14 exits("usage"); 15 } 16 setbinmode(); 17 Binit(&bin, 0, OREAD); 18 Binit(&bout, 1, OWRITE); 19 Bprint(&bout, "unsigned char %scode[] = {\n", argv[1]); 20 for(len=0; (n=Bread(&bin, block, sizeof(block))) > 0; len += n){ 21 for(c=block; c < block+n; c++) 22 if(*c) 23 Bprint(&bout, "0x%ux,", *c); 24 else 25 Bprint(&bout, "0,"); 26 Bprint(&bout, "\n"); 27 } 28 if(len == 0) 29 Bprint(&bout, "0\n"); /* avoid empty initialiser */ 30 Bprint(&bout, "};\n"); 31 Bprint(&bout, "int %slen = %ld;\n", argv[1], len); 32 exits(0); 33 } 34