Skip to content

Commit 8e62378

Browse files
committed
add params, basic table output
add parameters add basic output table
1 parent d08c60d commit 8e62378

File tree

1 file changed

+105
-35
lines changed

1 file changed

+105
-35
lines changed

src/main.c

Lines changed: 105 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,100 @@
11
#include <stdio.h>
2+
#include <stdint.h>
3+
#include <string.h>
4+
#include <stdbool.h>
5+
6+
#define MAX_COL 4
7+
#define MAX_ROW 32
8+
9+
typedef struct parameter{
10+
11+
bool showAll; //--all shows all available ascii codes
12+
bool showAllDigits; //--digits shows all digits ascii codes
13+
bool showAllAlphas; //--alphas shows all alphabets ascii codes
14+
15+
bool onlyOct; //--octa shows only octa in output table
16+
bool onlyDec; //--dec shows only dec in output table
17+
bool onlyHex; //--hex shows only hex in output table
18+
bool onlyChar; //--char shows only char in output table
19+
bool _onlyAll; // if all only* 4 are false this will be set to true
20+
21+
char* content; // " " content / data
22+
23+
uint8_t order; //0 - default , 1 - ascending, 3 - desending ordered output table
24+
25+
}asciiParams;
226

327

428
void splashScreen(){
5-
printf(" ascii - ASCII character set encoded in octal, decimal, and hexadecimal\n"
6-
"Dec Char Dec Char Dec Char Dec Char\n"
7-
"--------- --------- --------- ----------\n"
8-
" 0 NUL (null) 32 SPACE 64 @ 96 `\n"
9-
" 1 SOH (start of heading) 33 ! 65 A 97 a\n"
10-
" 2 STX (start of text) 34 \" 66 B 98 b\n"
11-
" 3 ETX (end of text) 35 # 67 C 99 c\n"
12-
" 4 EOT (end of transmission) 36 $ 68 D 100 d\n"
13-
" 5 ENQ (enquiry) 37 %% 69 E 101 e\n"
14-
" 6 ACK (acknowledge) 38 & 70 F 102 f\n"
15-
" 7 BEL (bell) 39 ' 71 G 103 g\n"
16-
" 8 BS (backspace) 40 ( 72 H 104 h\n"
17-
" 9 TAB (horizontal tab) 41 ) 73 I 105 i\n"
18-
" 10 LF (NL line feed, new line) 42 * 74 J 106 j\n"
19-
" 11 VT (vertical tab) 43 + 75 K 107 k\n"
20-
" 12 FF (NP form feed, new page) 44 , 76 L 108 l\n"
21-
" 13 CR (carriage return) 45 - 77 M 109 m\n"
22-
" 14 SO (shift out) 46 . 78 N 110 n\n"
23-
" 15 SI (shift in) 47 / 79 O 111 o\n"
24-
" 16 DLE (data link escape) 48 0 80 P 112 p\n"
25-
" 17 DC1 (device control 1) 49 1 81 Q 113 q\n"
26-
" 18 DC2 (device control 2) 50 2 82 R 114 r\n"
27-
" 19 DC3 (device control 3) 51 3 83 S 115 s\n"
28-
" 20 DC4 (device control 4) 52 4 84 T 116 t\n"
29-
" 21 NAK (negative acknowledge) 53 5 85 U 117 u\n"
30-
" 22 SYN (synchronous idle) 54 6 86 V 118 v\n"
31-
" 23 ETB (end of trans. block) 55 7 87 W 119 w\n"
32-
" 24 CAN (cancel) 56 8 88 X 120 x\n"
33-
" 25 EM (end of medium) 57 9 89 Y 121 y\n"
34-
" 26 SUB (substitute) 58 : 90 Z 122 z\n"
35-
" 27 ESC (escape) 59 ; 91 [ 123 {\n"
36-
" 28 FS (file separator) 60 < 92 \\ 124 |\n"
37-
" 29 GS (group separator) 61 = 93 ] 125 }\n"
38-
" 30 RS (record separator) 62 > 94 ^ 126 ~\n"
39-
" 31 US (unit separator) 63 ? 95 _ 127 DEL\n");
29+
printf(" ascii - ASCII character set encoded in octal, decimal, and hexadecimal\n\n"
30+
"Oct Dec Hex Char | Oct Dec Hex Char | Oct Dec Hex Char | Oct Dec Hex Char\n"
31+
"------------------------------------------+----------------------+----------------------+----------------\n"
32+
"000 0 00 NUL (null) | 000 32 00 SPACE | 000 64 00 @ | 000 96 00 `\n"
33+
"001 1 01 SOH (start of heading) | 000 33 00 ! | 000 65 00 A | 000 97 00 a\n"
34+
"002 2 02 STX (start of text) | 000 34 00 \" | 000 66 00 B | 000 98 00 b\n"
35+
"003 3 03 ETX (end of text) | 000 35 00 # | 000 67 00 C | 000 99 00 c\n"
36+
"004 4 04 EOT (end of transmission) | 000 36 00 $ | 000 68 00 D | 000 100 00 d\n"
37+
"005 5 05 ENQ (enquiry) | 000 37 00 %% | 000 69 00 E | 000 101 00 e\n"
38+
"006 6 06 ACK (acknowledge) | 000 38 00 & | 000 70 00 F | 000 102 00 f\n"
39+
"007 7 07 BEL (bell) | 000 39 00 ' | 000 71 00 G | 000 103 00 g\n"
40+
"008 8 08 BS (backspace) | 000 40 00 ( | 000 72 00 H | 000 104 00 h\n"
41+
"009 9 09 TAB (horizontal tab) | 000 41 00 ) | 000 73 00 I | 000 105 00 i\n"
42+
"010 10 0A LF (NL line feed, new line) | 000 42 00 * | 000 74 00 J | 000 106 00 j\n"
43+
"011 11 0B VT (vertical tab) | 000 43 00 + | 000 75 00 K | 000 107 00 k\n"
44+
"012 12 0C FF (NP form feed, new page) | 000 44 00 , | 000 76 00 L | 000 108 00 l\n"
45+
"013 13 0D CR (carriage return) | 000 45 00 - | 000 77 00 M | 000 109 00 m\n"
46+
"014 14 0E SO (shift out) | 000 46 00 . | 000 78 00 N | 000 110 00 n\n"
47+
"015 15 0F SI (shift in) | 000 47 00 / | 000 79 00 O | 000 111 00 o\n"
48+
"016 16 10 DLE (data link escape) | 000 48 00 0 | 000 80 00 P | 000 112 00 p\n"
49+
"017 17 11 DC1 (device control 1) | 000 49 00 1 | 000 81 00 Q | 000 113 00 q\n"
50+
"018 18 12 DC2 (device control 2) | 000 50 00 2 | 000 82 00 R | 000 114 00 r\n"
51+
"019 19 13 DC3 (device control 3) | 000 51 00 3 | 000 83 00 S | 000 115 00 s\n"
52+
"020 20 14 DC4 (device control 4) | 000 52 00 4 | 000 84 00 T | 000 116 00 t\n"
53+
"021 21 15 NAK (negative acknowledge) | 000 53 00 5 | 000 85 00 U | 000 117 00 u\n"
54+
"022 22 16 SYN (synchronous idle) | 000 54 00 6 | 000 86 00 V | 000 118 00 v\n"
55+
"023 23 17 ETB (end of trans. block) | 000 55 00 7 | 000 87 00 W | 000 119 00 w\n"
56+
"024 24 18 CAN (cancel) | 000 56 00 8 | 000 88 00 X | 000 120 00 x\n"
57+
"025 25 19 EM (end of medium) | 000 57 00 9 | 000 89 00 Y | 000 121 00 y\n"
58+
"026 26 1A SUB (substitute) | 000 58 00 : | 000 90 00 Z | 000 122 00 z\n"
59+
"027 27 1B ESC (escape) | 000 59 00 ; | 000 91 00 [ | 000 123 00 {\n"
60+
"028 28 1C FS (file separator) | 000 60 00 < | 000 92 00 \\ | 000 124 00 |\n"
61+
"029 29 1D GS (group separator) | 000 61 00 = | 000 93 00 ] | 000 125 00 }\n"
62+
"030 30 1E RS (record separator) | 000 62 00 > | 000 94 00 ^ | 000 126 00 ~\n"
63+
"031 31 1F US (unit separator) | 000 63 00 ? | 000 95 00 _ | 177 127 00 DEL\n"
64+
"---------------------------------------------------------------------------------------------------------\n");
65+
}
66+
67+
asciiParams parseParameter(int argv, char** args){
68+
69+
asciiParams params = {0};
70+
71+
for(uint8_t i = 0; i < argv; i++){
72+
if (strcmp(args[i],"--all") == 0) params.showAll = true;
73+
else if(strcmp(args[i],"--digits") == 0) params.showAllDigits = true;
74+
else if(strcmp(args[i],"--alphas") == 0) params.showAllAlphas = true;
75+
else if(strcmp(args[i],"--octa") == 0) params.onlyOct = true;
76+
else if(strcmp(args[i],"--dec") == 0) params.onlyDec = true;
77+
else if(strcmp(args[i],"--hex") == 0) params.onlyHex = true;
78+
else if(strcmp(args[i],"--char") == 0) params.onlyChar = true;
79+
else if(strcmp(args[i],"--asc")==0) params.order = 1;
80+
else if(strcmp(args[i],"--des")==0) params.order = 2;
81+
else params.content = args[i];
82+
}
83+
84+
params._onlyAll = !(params.onlyChar || params.onlyDec || params.onlyHex || params.onlyOct);
85+
86+
return params;
87+
88+
}
89+
90+
void printData(asciiParams params){
91+
size_t s = 0;
92+
printf("Oct Dec Hex Char\n-----------------\n");
93+
while(strlen(params.content) - s){
94+
printf("%3o %3d %2X %c\n", params.content[s], params.content[s], params.content[s], params.content[s]);
95+
s++;
96+
}
97+
printf("-----------------\n");
4098
}
4199

42100
int main(int argv, char** args){
@@ -46,8 +104,20 @@ int main(int argv, char** args){
46104
return 0;
47105
}
48106

107+
asciiParams params = parseParameter(argv, args);
108+
109+
if(params.showAll){
110+
splashScreen();
111+
return 0;
112+
}
113+
114+
//@todo: print the data first in the center
115+
// and then print the table output ..
49116

117+
// testing params: will be removed on release
118+
printf("showAll:%i showAllAlphas:%i showAllDigits:%i onlyOct:%i onlyDec:%i onlyHex:%i onlyChar:%i;\ncontent: %s\n\n",params.showAll, params.showAllAlphas, params.showAllDigits, params.onlyOct, params.onlyDec, params.onlyHex, params.onlyChar, params.content);
50119

120+
printData(params);
51121

52122
return 0;
53123
}

0 commit comments

Comments
 (0)