77 * @param _hexadecimal char* (string)
88 * @return uint8_t
99 */
10- uint8_t isHex ( char * _hexadecimal ){
11- return strlen (_hexadecimal ) >= 3 && _hexadecimal [0 ]== '0' && (_hexadecimal [1 ]== 'x' || _hexadecimal [1 ]== 'X' );
10+ uint8_t isHex ( wchar_t * _hexadecimal ){
11+ return wcslen (_hexadecimal ) >= 3 && _hexadecimal [0 ]== L '0' && (_hexadecimal [1 ]== L 'x'|| _hexadecimal [1 ]== L 'X' );
1212}
1313
1414/**
@@ -18,10 +18,10 @@ uint8_t isHex( char* _hexadecimal ){
1818 * @param _octal char* (string)
1919 * @return uint8_t
2020 */
21- uint8_t isOct ( char * _octal ){
22- if (strlen (_octal ) <= 1 || _octal [strlen (_octal )- 1 ] != 'o' ) return 0 ;
21+ uint8_t isOct ( wchar_t * _octal ){
22+ if (wcslen (_octal ) <= 1 || _octal [wcslen (_octal )- 1 ] != L 'o' ) return 0 ;
2323
24- for (uint8_t i = 0 ; i < strlen (_octal )- 1 ; i ++ ){
24+ for (uint8_t i = 0 ; i < wcslen (_octal )- 1 ; i ++ ){
2525 if (!(_octal [i ] >= 48 && _octal [i ] <= 55 )) return 0 ;
2626 }
2727
@@ -35,10 +35,10 @@ uint8_t isOct( char* _octal ){
3535 * @param _binary char* (string)
3636 * @return uint8_t
3737 */
38- uint8_t isBin ( char * _binary ){
39- if (strlen (_binary ) <= 1 || _binary [strlen (_binary )- 1 ] != 'b' ) return 0 ;
38+ uint8_t isBin ( wchar_t * _binary ){
39+ if (wcslen (_binary ) <= 1 || _binary [wcslen (_binary )- 1 ] != L 'b' ) return 0 ;
4040
41- for (uint8_t i = 0 ; i < strlen (_binary )- 1 ; i ++ ){
41+ for (uint8_t i = 0 ; i < wcslen (_binary )- 1 ; i ++ ){
4242 if (!(_binary [i ] == 48 || _binary [i ] == 49 )) return 0 ;
4343 }
4444
@@ -52,10 +52,10 @@ uint8_t isBin( char* _binary ){
5252 * @param _binary char* (string)
5353 * @return uint8_t
5454 */
55- uint8_t isDec ( char * _decimal ){
56- if (strlen (_decimal ) <= 1 || _decimal [strlen (_decimal )- 1 ] != 'd' ) return 0 ;
55+ uint8_t isDec ( wchar_t * _decimal ){
56+ if (wcslen (_decimal ) <= 1 || _decimal [wcslen (_decimal )- 1 ] != L 'd' ) return 0 ;
5757
58- for (uint8_t i = 0 ; i < strlen (_decimal )- 1 ; i ++ ){
58+ for (uint8_t i = 0 ; i < wcslen (_decimal )- 1 ; i ++ ){
5959 if (!(_decimal [i ] >= 48 && _decimal [i ] <= 57 )) return 0 ;
6060 }
6161
@@ -70,7 +70,7 @@ uint8_t isDec( char* _decimal ){
7070 * @param args char** (string[])
7171 * @return asciiParams
7272 */
73- asciiParams parseParameter (int argv , char * * args ){
73+ asciiParams parseParameter (int argv , wchar_t * * args ){
7474 asciiParams params = {0 };
7575 if (argv <= 1 ){
7676 params .order = 1 ;
@@ -79,44 +79,43 @@ asciiParams parseParameter(int argv, char** args){
7979
8080 for (uint8_t i = 1 ; i < argv ; i ++ ){
8181
82- if (!(strlen (args [i ]) >= 2 && args [i ][0 ] == '-' && args [i ][1 ] == '-' )){
82+ if (!(wcslen (args [i ]) >= 2 && args [i ][0 ] == L '-' && args [i ][1 ] == L '-' )){
8383
8484 uint8_t base = 0 ;
8585 if ( (base = isHex (args [i ])) || (base = isOct (args [i ])) || (base = isBin ( args [i ])) || (base = isDec ( args [i ])) ){
86- uint8_t number = (uint8_t ) strtol (args [i ],NULL ,isHex (args [i ])?0 :base );
86+ wchar_t number = (wchar_t ) wcstol (args [i ],NULL ,isHex (args [i ])?0 :base );
8787
8888 free (args [i ]);
89- args [i ] = (uint8_t * ) calloc (2 ,sizeof (uint8_t ));
89+ args [i ] = (wchar_t * ) calloc (2 ,sizeof (wchar_t ));
9090
9191 args [i ][0 ] = number ;
92- args [i ][1 ] = '\0' ;
92+ args [i ][1 ] = L '\0' ;
9393 params .contentSize ++ ;
94- }else params .contentSize += strlen (args [i ]);
94+ }else params .contentSize += wcslen (args [i ]);
95+
96+ if (params .content == NULL ) params .content = (wchar_t * )args [i ];
97+ else wcscat (params .content ,(wchar_t * ) args [i ]);
9598
96- if (params .content == NULL ) params .content = (uint8_t * )args [i ];
97- else strcat (params .content ,(uint8_t * ) args [i ]);
98-
9999 continue ;
100100 }
101101
102- if (strcmp (args [i ],"--all" ) == 0 ) params .showAll = 128 ;
103- else if (strcmp (args [i ],"--digits" ) == 0 ) params .showAllDigits = 10 ;
104- else if (strcmp (args [i ],"--alphas" ) == 0 ) params .showAllAlphas = 52 ;
105-
106- else if (strcmp (args [i ],"--controls" ) == 0 ) params .showControlChars = 33 ;
107- else if (strcmp (args [i ],"--specials" ) == 0 ) params .showSpecialChars = 33 ;
102+ if (wcscmp (args [i ],L"--all" ) == 0 ) params .showAll = 128 ;
103+ else if (wcscmp (args [i ],L"--digits" ) == 0 ) params .showAllDigits = 10 ;
104+ else if (wcscmp (args [i ],L"--alphas" ) == 0 ) params .showAllAlphas = 52 ;
108105
109- else if (strcmp (args [i ],"--octa" ) == 0 ) params .onlyOct = true;
110- else if (strcmp (args [i ],"--dec" ) == 0 ) params .onlyDec = true;
111- else if (strcmp (args [i ],"--hex" ) == 0 ) params .onlyHex = true;
112- else if (strcmp (args [i ],"--bin" ) == 0 ) params .onlyBin = true;
113- // else if(strcmp(args[i],"--char") == 0) params.onlyChar = true;
106+ else if (wcscmp (args [i ],L"--controls" ) == 0 ) params .showControlChars = 33 ;
107+ else if (wcscmp (args [i ],L"--specials" ) == 0 ) params .showSpecialChars = 33 ;
114108
115- else if (strcmp (args [i ],"--asc" )== 0 ) params .order = 1 ;
116- else if (strcmp (args [i ],"--desc" )== 0 ) params .order = 2 ;
109+ else if (wcscmp (args [i ],L"--octa" ) == 0 ) params .onlyOct = true;
110+ else if (wcscmp (args [i ],L"--dec" ) == 0 ) params .onlyDec = true;
111+ else if (wcscmp (args [i ],L"--hex" ) == 0 ) params .onlyHex = true;
112+ else if (wcscmp (args [i ],L"--bin" ) == 0 ) params .onlyBin = true;
113+ // else if(wcscmp(args[i],L"--char") == 0) params.onlyChar = true;
117114
118- else if (strcmp (args [i ],"--vt100" )== 0 ) params .color = true;
115+ else if (wcscmp (args [i ],L"--asc" )== 0 ) params .order = 1 ;
116+ else if (wcscmp (args [i ],L"--desc" )== 0 ) params .order = 2 ;
119117
118+ else if (wcscmp (args [i ],L"--vt100" )== 0 ) params .color = true;
120119 }
121120
122121 params .onlyChar = 1 ; //hardcoded;
@@ -140,9 +139,11 @@ asciiParams parseParameter(int argv, char** args){
140139 * @param params asciiParams*
141140 */
142141void removeDuplicateChars (asciiParams * params ){
143- uint8_t occur [256 ] = {0 };int i ;int idx = 0 ;
142+ wchar_t occur [256 ] = {0 };int i ;int idx = 0 ;
143+
144144 for (i = 0 ; i < params -> contentSize ; i ++ ){
145145 if (!occur [params -> content [i ]]){
146+
146147 if (idx != i ){
147148 params -> content [idx ] = params -> content [i ];
148149 }
@@ -154,16 +155,16 @@ void removeDuplicateChars(asciiParams *params){
154155
155156 if (idx == params -> contentSize ) return ;
156157
157- uint8_t * tmp = (uint8_t * )calloc (idx ,sizeof (uint8_t ));
158+ wchar_t * tmp = (wchar_t * )calloc (idx ,sizeof (wchar_t ));
158159 params -> contentSize = idx ;
159160
160- strncpy (tmp , params -> content , idx );tmp [idx ] = '\0' ;
161+ wcsncpy (tmp , params -> content , idx );tmp [idx ] = '\0' ;
161162 // free(params->content);
162163 params -> content = tmp ;
163164}
164165
165- static int ascCmp (const void * a , const void * b ){return * (uint8_t * )a - * (uint8_t * )b ;}
166- static int desCmp (const void * a , const void * b ){return * (uint8_t * )b - * (uint8_t * )a ;}
166+ static int ascCmp (const void * a , const void * b ){return * (wchar_t * )a - * (wchar_t * )b ;}
167+ static int desCmp (const void * a , const void * b ){return * (wchar_t * )b - * (wchar_t * )a ;}
167168
168169/**
169170 * @brief sort the input content in ascending / descending order
@@ -173,8 +174,8 @@ static int desCmp(const void* a, const void* b){return *(uint8_t *)b - *(uint8_t
173174 */
174175void sortChars (asciiParams * params ){
175176 if (params -> order ){
176- if (params -> order == 1 ) qsort (params -> content , params -> contentSize , sizeof (uint8_t ), ascCmp );
177- else qsort (params -> content , params -> contentSize , sizeof (uint8_t ), desCmp );
177+ if (params -> order == 1 ) qsort (params -> content , params -> contentSize , sizeof (wchar_t ), ascCmp );
178+ else qsort (params -> content , params -> contentSize , sizeof (wchar_t ), desCmp );
178179 }
179180}
180181
@@ -185,55 +186,55 @@ void sortChars(asciiParams *params){
185186 * @param character
186187 * @return bool
187188 */
188- bool isPrintable (uint8_t character ){
189+ bool isPrintable (wchar_t character ){
189190 return !(character >= 0 && character <= 32 || character == 127 );
190191}
191192
192193/**
193194 * @brief Get the printable custom value for non printable characters
194195 *
195196 * @param content
196- * @return uint8_t *
197+ * @return wchar_t *
197198 */
198- uint8_t * getPrintable (uint8_t content ){
199- if (!(content >= 0 && content <= 32 || content == 127 )) return " " ;
199+ wchar_t * getPrintable (wchar_t content ){
200+ if (!(content >= 0 && content <= 32 || content == 127 )) return L " " ;
200201
201202 switch (content ){
202- case 0 : return "NUL (null)" ;
203- case 1 : return "SOH (start of heading)" ;
204- case 2 : return "STX (start of text)" ;
205- case 3 : return "ETX (end of text)" ;
206- case 4 : return "EOT (end of transmission)" ;
207- case 5 : return "ENQ (enquiry)" ;
208- case 6 : return "ACK (acknowledge)" ;
209- case 7 : return "BEL (bell)" ;
210- case 8 : return "BS (backspace)" ;
211- case 9 : return "TAB (horizontal tab)" ;
212- case 10 : return "LF (NL line feed, new line)" ;
213- case 11 : return "VT (vertical tab)" ;
214- case 12 : return "FF (NP form feed, new page)" ;
215- case 13 : return "CR (carriage return)" ;
216- case 14 : return "SO (shift out)" ;
217- case 15 : return "SI (shift in)" ;
218- case 16 : return "DLE (data link escape)" ;
219- case 17 : return "DC1 (device control 1)" ;
220- case 18 : return "DC2 (device control 2)" ;
221- case 19 : return "DC3 (device control 3)" ;
222- case 20 : return "DC4 (device control 4)" ;
223- case 21 : return "NAK (negative acknowledge)" ;
224- case 22 : return "SYN (synchronous idle)" ;
225- case 23 : return "ETB (end of trans. block)" ;
226- case 24 : return "CAN (cancel)" ;
227- case 25 : return "EM (end of medium)" ;
228- case 26 : return "SUB (substitute)" ;
229- case 27 : return "ESC (escape)" ;
230- case 28 : return "FS (file separator)" ;
231- case 29 : return "GS (group separator)" ;
232- case 30 : return "RS (record separator)" ;
233- case 31 : return "US (unit separator)" ;
234- case 32 : return "SPACE" ;
235- case 127 :return "DEL (delete control)" ;
236- default : return " " ;
203+ case 0 : return L "NUL (null)" ;
204+ case 1 : return L "SOH (start of heading)" ;
205+ case 2 : return L "STX (start of text)" ;
206+ case 3 : return L "ETX (end of text)" ;
207+ case 4 : return L "EOT (end of transmission)" ;
208+ case 5 : return L "ENQ (enquiry)" ;
209+ case 6 : return L "ACK (acknowledge)" ;
210+ case 7 : return L "BEL (bell)" ;
211+ case 8 : return L "BS (backspace)" ;
212+ case 9 : return L "TAB (horizontal tab)" ;
213+ case 10 : return L "LF (NL line feed, new line)" ;
214+ case 11 : return L "VT (vertical tab)" ;
215+ case 12 : return L "FF (NP form feed, new page)" ;
216+ case 13 : return L "CR (carriage return)" ;
217+ case 14 : return L "SO (shift out)" ;
218+ case 15 : return L "SI (shift in)" ;
219+ case 16 : return L "DLE (data link escape)" ;
220+ case 17 : return L "DC1 (device control 1)" ;
221+ case 18 : return L "DC2 (device control 2)" ;
222+ case 19 : return L "DC3 (device control 3)" ;
223+ case 20 : return L "DC4 (device control 4)" ;
224+ case 21 : return L "NAK (negative acknowledge)" ;
225+ case 22 : return L "SYN (synchronous idle)" ;
226+ case 23 : return L "ETB (end of trans. block)" ;
227+ case 24 : return L "CAN (cancel)" ;
228+ case 25 : return L "EM (end of medium)" ;
229+ case 26 : return L "SUB (substitute)" ;
230+ case 27 : return L "ESC (escape)" ;
231+ case 28 : return L "FS (file separator)" ;
232+ case 29 : return L "GS (group separator)" ;
233+ case 30 : return L "RS (record separator)" ;
234+ case 31 : return L "US (unit separator)" ;
235+ case 32 : return L "SPACE" ;
236+ case 127 :return L "DEL (delete control)" ;
237+ default : return L " " ;
237238 }
238239}
239240
0 commit comments