// All characters' metrics are specced to be the same as prevailing #include #include #include #include #include #include #include #define basename *(argv + 1) // #define height_s *(argv + 2) #define width_s *(argv + 3) int main(int _, char ** argv) { (void) _; char fname[256]; sprintf(fname, "%s.x", basename); mkdir(fname, 0777); if(chdir(fname)) return fprintf(stderr, "%d %s\n", errno, fname), 1; errno = 0; // int height = strtoul(height_s, NULL, 0); int width = strtoul(width_s, NULL, 0); char * line = NULL; size_t line_s = 0; for(int i = 0; getline(&line, &line_s, stdin) != -1; ++i) { *(line + strlen(line) - 1) = '\0'; char * charname = strchr(line, '#') + 2; if(!strcmp(charname, "/")) charname = "slash"; else if(!strcmp(charname, "M-/")) charname = "M-slash"; *strchr(line, '#') = '\0'; sprintf(fname, "%02x-%s.blk", i, charname); if(!freopen(fname, "w", stdout)) return fprintf(stderr, "%d %s\n", errno, fname), 1; for(char * tok = strtok(strstr(line, "0x"), ", "); tok; tok = strtok(NULL, ", ")) { unsigned row = strtoul(tok, NULL, 0); for(int i = 0; i < width; ++i) { fputs(row & (1 << (width - 1)) ? "█" : " ", stdout); row <<= 1; } putchar('\n'); } } if(errno) fprintf(stderr, "%d\n", errno); }