6
6
7
7
#define MAX_COL 4
8
8
#define MAX_ROW 32
9
- #define YEL "\x1B [33m"
10
- #define RESET "\x1B [0m"
9
+ #define YEL "\x1b [33m"
10
+ #define RESET "\x1b [0m"
11
11
12
12
typedef struct parameter {
13
13
@@ -29,7 +29,7 @@ typedef struct parameter{
29
29
30
30
31
31
void splashScreen (){
32
- printf (" ascii - ASCII character set encoded in octal, decimal, and hexadecimal\n\n"
32
+ printf ("ascii - ASCII character set encoded in octal, decimal, and hexadecimal\n\n"
33
33
"Oct Dec Hex " YEL "Chr" RESET " | Oct Dec Hex " YEL "Chr" RESET " | Oct Dec Hex " YEL "Chr" RESET " | Oct Dec Hex " YEL "Chr" RESET "\n"
34
34
"--------------------------------------------+-----------------------+---------------------+--------------------\n"
35
35
"000 0 00 " YEL "NUL (null)" RESET " | 040 32 20 " YEL "SPACE" RESET " | 100 64 40 " YEL "@" RESET " | 140 96 60 " YEL "`" RESET "\n"
@@ -103,22 +103,28 @@ asciiParams parseParameter(int argv, char** args){
103
103
104
104
static int ascCmp (const void * a , const void * b ){return * (char * )a > * (char * )b ;}
105
105
static int desCmp (const void * a , const void * b ){return * (char * )a < * (char * )b ;}
106
- void manipulateData (asciiParams params ){
107
-
108
- char occur [256 ] = {0 };int i ;
109
- for (i = 0 ; i < strlen (params .content ); i ++ ){
110
- if (occur [params .content [i ]]){
111
- memmove (& params .content [i ], & params .content [i + 1 ], strlen (params .content ) - i );
112
- i -- ;
113
- }else occur [params .content [i ]] = 1 ;
114
-
115
- }
116
- params .content [i ] = '\0' ;
106
+ void manipulateData (asciiParams * params ){
107
+
108
+ char occur [256 ] = {0 };int i ;int idx = 0 ;
117
109
110
+ for (i = 0 ; i < strlen (params -> content ); i ++ ){
111
+ if (!occur [params -> content [i ]]){
112
+ if (idx != i ){
113
+ params -> content [idx ] = params -> content [i ];
114
+ }
115
+
116
+ idx ++ ;
117
+ occur [params -> content [i ]] = 1 ;
118
+ }
119
+ }
120
+
121
+ char * tmp = (char * )malloc ((idx ) * sizeof (char ));
122
+ strncpy (tmp , params -> content , idx );tmp [idx ] = '\0' ;
123
+ params -> content = tmp ;
118
124
119
- if (params . order ){
120
- if (params . order == 1 ) qsort (params . content , strlen (params . content ), sizeof (char ), ascCmp );
121
- else qsort (params . content , strlen (params . content ), sizeof (char ), desCmp );
125
+ if (params -> order ){
126
+ if (params -> order == 1 ) qsort (params -> content , strlen (params -> content ), sizeof (char ), ascCmp );
127
+ else qsort (params -> content , strlen (params -> content ), sizeof (char ), desCmp );
122
128
}
123
129
}
124
130
@@ -163,20 +169,21 @@ int main(int argv, char** args){
163
169
if (params .showAll ){
164
170
splashScreen ();
165
171
return 0 ;
172
+ }else if (params .showAllAlphas && params .showAllDigits ){
173
+ params .content = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
166
174
}else if (params .showAllAlphas ){
167
- params .content = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " ;
175
+ params .content = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz " ;
168
176
}else if (params .showAllDigits ){
169
177
params .content = "0123456789" ;
170
178
}
171
179
172
180
//@todo: print the data first in the center
173
181
// and then print the table output ..
174
182
175
- // testing params: will be removed on release
176
- // 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);
177
-
178
- manipulateData (params );
183
+ manipulateData (& params );
179
184
printData (params );
180
185
186
+ // free(params.content);
187
+
181
188
return 0 ;
182
189
}
0 commit comments