-
Notifications
You must be signed in to change notification settings - Fork 4
/
line2bitmap.c
56 lines (50 loc) · 1.02 KB
/
line2bitmap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char** argv){
size_t bar_width = 1, image_height = 64, i;
FILE* source = stdin;
size_t x, y;
for(i = 1; i < argc; i++){
if(!strcmp(argv[i], "--width")){
if(i + 1 < argc){
bar_width = strtoul(argv[i + 1], NULL, 10);
i++;
}
else{
fprintf(stderr, "Missing argument for --width\n");
return 1;
}
}
else if(!strcmp(argv[i], "--height")){
if(i + 1 < argc){
image_height = strtoul(argv[i + 1], NULL, 10);
i++;
}
else{
fprintf(stderr, "Missing argument for --height\n");
return 1;
}
}
else{
if(source && source != stdin){
fclose(source);
}
source = fopen(argv[i], "r");
}
}
if(!source){
fprintf(stderr, "Failed to open input file\n");
return 1;
}
for(i = fgetc(source); i && i != EOF && i != '\n'; i = fgetc(source)){
for(x = 0; x < bar_width; x++){
for(y = 0; y < image_height; y++){
fputc(i, stdout);
}
fputc('\n', stdout);
}
}
fclose(source);
return 0;
}