66
77char * currentPath (short * len );
88short terminalWidth ();
9+ bool isHelp (char * arg );
910void printShort (short * plen , char * path , short deltaLen );
1011
1112int main (int argc , char * argv []) {
1213 short alen = 0 , plen = 0 ; //Init len vars
1314 char * cpath = currentPath (& plen ); //Get current path and its lenght
1415
15- if (argc > 1 ) alen = atoi (argv [1 ]); //Get aviable len (if exists)
16- else alen = terminalWidth ();
16+ if (argc > 1 ) {
17+ if (!isHelp (argv [1 ])) alen = atoi (argv [1 ]); //Get aviable len (if exists)
18+ else return 0 ;
19+ } else alen = terminalWidth (); //Set the terminal widht if it is not a help exec
1720
1821 /* check for the ability to write the path in the available len */
1922 if (plen <= alen ) printf (cpath ); //Print default path
@@ -34,6 +37,18 @@ short terminalWidth() {
3437 return w .ws_col ;
3538}
3639
40+ bool strcomp (char * str1 , char * str2 ) {
41+ for (short i = 0 ; str1 [i ] != '\0' || str2 [i ] != '\0' ; i ++ )
42+ if (str1 [i ] != str2 [i ]) return false;
43+ return true;
44+ }
45+
46+ bool isHelp (char * arg ) {
47+ if (!strcomp (arg , "-h" ) && !strcomp (arg , "--help" )) return false;
48+ printf ("Usage:\n spwd <max width>\nExample:\n spwd 123" );
49+ return true;
50+ }
51+
3752/* Get all titles' lenght */
3853short * titleLenghts (char * path , short * size ) {
3954 short * buffer = (short * )malloc (512 * sizeof (short ));
0 commit comments