-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwwivcat.cpp
102 lines (90 loc) · 2.39 KB
/
wwivcat.cpp
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
/**************************************************************************\
** WWIVcat - command line tool to display files with WWIV Color Codes **
** Copyright (c) 2014 Eric Manuel Pareja **
** **
\**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void set_color (char ch){
switch(ch) {
case '1':
printf("\x1b[0;1;36m"); // high cyan
break;
case '2':
printf("\x1b[0;1;33m"); // high yellow
break;
case '3':
printf("\x1b[0;35m"); // low magenta
break;
case '4':
printf("\x1b[0;1;44m"); // white on blue
break;
case '5':
printf("\x1b[0;32m"); // low green
break;
case '6':
printf("\x1b[0;1;5;31m"); // high blinking red
break;
case '7':
printf("\x1b[0;1;34m"); // high blue
break;
case '8':
printf("\x1b[0;34m"); // low blue
break;
case '9':
printf("\x1b[0;36m"); // low cyan
break;
default:
printf("\x1b[0m"); // low grey
}
}
int main(int argc, char *argv[])
{
char ch;
int speed=2400; // Default speed is 2400 bps :)
FILE *file;
switch ( argc ) {
case 1:
file=stdin;
break;
case 3:
speed=atoi(argv[2]);
case 2:
file=fopen( argv[1], "r");
if (!file)
{
printf("Couldn't open file: %s\n", argv[1]);
return (1);
}
break;
default:
printf("Too many arguments. I can't take it anymore!\n");
return (0);
}
// printf("\x1b[?25l"); //turn cursor off
while ( ch = getc(file) ) {
if ( ( ch == EOF ) || ( ch == '\032' ) ) {
printf("\x1b[0m");
// printf("\x1b[?25h"); //turn cursor on
return(0);
} else {
if (ch == 3 ) {
ch = getc(file);
set_color(ch);
} else if ( ch == '|' ) {
ch = getc(file);
if (ch == '#' ) {
ch = getc(file);
set_color(ch);
} else {
printf("|%c",ch);
}
} else {
printf("%c",ch);
}
usleep(10000000 / speed);
fflush(NULL);
}
}
}