summaryrefslogtreecommitdiff
path: root/hw2/main.c
blob: d6312ea81bb35f1ac88c4fad2806cb2562591a8e (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <stdio.h>
#include <string.h>

/*
    /////     ______________ 
   d|o-o|b   |              |
     \O/    .:______________|
      `                     
*/
#define MAN_LINE_1 "\
     ////      _______________________________________________________________"

#define MAN_LINE_2_START "\
   d|o-o|b    |"

#define MAN_LINE_3_START "\
     \\O/     .:"

#define MAN_LINE_4_START "\
      `       |"

#define MAN_LINE_BLANK "\
              |"

int main(int argc, char **argv){
	char c = '\0';
	int column = 0;
	int line = 0;
	int i;
	//Grab until the new line character
	while(c != '\n'){
		//Only upercase if it's the first character
		if(c == '\0'){
			c = getchar();
			//and it's between a and z
			if(c >= 'a' && c <= 'z'){
				//223 = b 1101 1111
				c = c & 223;//Set the 32 bit to 0
			}
		}else{
			c = getchar();
		}
		if(c == '\n') break;
		if(line == 0){
			printf("%s\n",MAN_LINE_1);
			line++;
			column = 0;
		}
		if(line == 1 && column == 0){
			printf("%s",MAN_LINE_2_START);
			column = strlen(MAN_LINE_2_START);
		}
		putchar(c);
		column++;
		if(line == 1 && column == 78){
			printf("|\n");
			printf("%s",MAN_LINE_3_START);
			line++;
			column = strlen(MAN_LINE_3_START);
		}
		if(line == 2 && column == 78){
			printf("|\n");
			printf("%s",MAN_LINE_4_START);
			line++;
			column = strlen(MAN_LINE_4_START);
		}
		if(line >= 3 && column == 78){
			printf("|\n");
			printf("%s",MAN_LINE_BLANK);
			line++;
			column = strlen(MAN_LINE_BLANK);
		}
	}
	//Don't break, fall through to finish whatever lines we havn't done yet
	switch(line){
	case 1:
		i = 78 - column;
		while(i-- > 0)
			printf(" ");
		printf("|\n");
		printf("%s",MAN_LINE_3_START);
		column = strlen(MAN_LINE_3_START);
	case 2:
		i = 78 - column;
		while(i-- > 0)
			printf(" ");
		printf("|\n");
		printf("%s",MAN_LINE_4_START);
		column = strlen(MAN_LINE_4_START);
	default:
		//Finish off the line
		i = 78 - column;
		while(i-- > 0)
			printf(" ");
		printf("|\n");
		//Then print our bottom border
		printf("%s",MAN_LINE_BLANK);
		column = strlen(MAN_LINE_BLANK);
		i = 78 - column;
		while(i-- > 0)
			printf("_");
		printf("|\n");
		break;
	}

	return 0;
}