src/gitflow.c
static const char * extract_command(int argc, const char * argv[]) {
	int i = 0;
	int j = 0;
	int k = 0;
	int len = argc;

	alias * a;
	command * s;

	while(i < len) {

		if(argv[i][0] == '-') {
			// This is a flag or an option. No need to search it 
			// for a command. Just check if the user needs help.
			if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
				return "help";
			}
		}
		else {
			// Search in the commands array to see if the command 
			// matches one of the pre-defined commands.
			for(j = ARRAY_SIZE(commands) - 1; j >= 0; j--) {
				s = &commands[j];

				if( !strcmp(argv[i], s->cmd) ) {
					return s->cmd;
				}
			}

			// No command found. Check aliases.
			for(j = ARRAY_SIZE(aliases) - 1; j >= 0; j--) {
				a = &aliases[j];

				if( !strcmp(argv[i], a->alias) ) {
					return a->cmd;
				} 
			}

			// If the command doesn't exist in either the alias 
			// array or the commands array, compare the command 
			// letter by letter to see if it is the beginning of a 
			// command that exists. Matches down to three letters.
			for(j = ARRAY_SIZE(commands) - 1; j >= 0; j--) {
				s = &commands[j];

				for(k = strlen(argv[i]); k >= 2; k--) {

					if( !strncmp(argv[i], s->cmd, k) ) {
						return s->cmd;
					}
				}
			}

		}

		i++;
	}

	return "help";
}
// Extract_Commands Function
// -------------------------
// Searches through the list of arguments, starting at the beginning, 
// for one that matches a command listed in the commands array. If no 
// matches are found, search through aliases to find commands that 
// are possible mistyped or shortened intentionally.
Extract_Commands Function
Searches through the list of arguments, starting at the beginning,
for one that matches a command listed in the commands array. If no
matches are found, search through aliases to find commands that
are possible mistyped or shortened intentionally.
Extract_Commands Function Searches through the list of arguments starting at the beginning for one that matches a command listed in the commands array . If no matches are found search through aliases to find commands that are possible mistyped or shortened intentionally .
static const char * extract_command(int argc, const char * argv[]) {
	int i = 0;
	int j = 0;
	int k = 0;
	int len = argc;
	alias * a;
	command * s;
	while(i < len) {
		if(argv[i][0] == '-') {
			if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
				return "help";
			}
		}
		else {
			for(j = ARRAY_SIZE(commands) - 1; j >= 0; j--) {
				s = &commands[j];
				if( !strcmp(argv[i], s->cmd) ) {
					return s->cmd;
				}
			}
			for(j = ARRAY_SIZE(aliases) - 1; j >= 0; j--) {
				a = &aliases[j];
				if( !strcmp(argv[i], a->alias) ) {
					return a->cmd;
				} 
			}
			for(j = ARRAY_SIZE(commands) - 1; j >= 0; j--) {
				s = &commands[j];
				for(k = strlen(argv[i]); k >= 2; k--) {
					if( !strncmp(argv[i], s->cmd, k) ) {
						return s->cmd;
					}
				}
			}
		}
		i++;
	}
	return "help";
}
static const char * extract_command ( int argc , const char * argv [ ] ) { int i = 0 ; int j = 0 ; int k = 0 ; int len = argc ; alias * a ; command * s ; while ( i < len ) { if ( argv [ i ] [ 0 ] == ' ' ) { if ( ! strcmp ( argv [ i ] , " " ) || ! strcmp ( argv [ i ] , " " ) ) { return " " ; } } else { for ( j = ARRAY_SIZE ( commands ) - 1 ; j >= 0 ; j -- ) { s = & commands [ j ] ; if ( ! strcmp ( argv [ i ] , s -> cmd ) ) { return s -> cmd ; } } for ( j = ARRAY_SIZE ( aliases ) - 1 ; j >= 0 ; j -- ) { a = & aliases [ j ] ; if ( ! strcmp ( argv [ i ] , a -> alias ) ) { return a -> cmd ; } } for ( j = ARRAY_SIZE ( commands ) - 1 ; j >= 0 ; j -- ) { s = & commands [ j ] ; for ( k = strlen ( argv [ i ] ) ; k >= 2 ; k -- ) { if ( ! strncmp ( argv [ i ] , s -> cmd , k ) ) { return s -> cmd ; } } } } i ++ ; } return " " ; }
Extract_Commands Function
Searches through the list of arguments, starting at the beginning,
for one that matches a command listed in the commands array.
Extract_Commands Function Searches through the list of arguments starting at the beginning for one that matches a command listed in the commands array .
// This is a flag or an option. No need to search it  // for a command. Just check if the user needs help. // Search in the commands array to see if the command  // matches one of the pre-defined commands. // No command found. Check aliases. // If the command doesn't exist in either the alias  // array or the commands array, compare the command  // letter by letter to see if it is the beginning of a  // command that exists. Matches down to three letters.