void extract_command_name(int index, char **argv) {
	assert(argv);
	assert(argv[index]);


	// configure command index
	cfg.original_program_index = index;

	char *str = strdup(argv[index]);
	if (!str)
		errExit("strdup");

	// if we have a symbolic link, use the real path to extract the name
	if (is_link(argv[index])) {
		char*newname = realpath(argv[index], NULL);
		if (newname) {
			free(str);
			str = newname;
		}
	}

	// configure command name
	cfg.command_name = str;
	if (!cfg.command_name)
		errExit("strdup");

	// restrict the command name to the first word
	char *ptr = cfg.command_name;
	while (*ptr != ' ' && *ptr != '\t' && *ptr != '\0')
		ptr++;
	*ptr = '\0';

	// remove the path: /usr/bin/firefox becomes firefox
	ptr = strrchr(cfg.command_name, '/');
	if (ptr) {
		ptr++;
		if (*ptr == '\0') {
			fprintf(stderr, "Error: invalid command name\n");
			exit(1);
		}

		char *tmp = strdup(ptr);
		if (!tmp)
			errExit("strdup");

		// limit the command to the first '.'
		char *ptr2 = tmp;
		while (*ptr2 != '.' && *ptr2 != '\0')
			ptr2++;
		*ptr2 = '\0';
			
		free(cfg.command_name);
		cfg.command_name = tmp;
	}
}
void extract_command_name(int index, char **argv) {
	assert(argv);
	assert(argv[index]);


	 
	cfg.original_program_index = index;

	char *str = strdup(argv[index]);
	if (!str)
		errExit("strdup");

	 
	if (is_link(argv[index])) {
		char*newname = realpath(argv[index], NULL);
		if (newname) {
			free(str);
			str = newname;
		}
	}

	 
	cfg.command_name = str;
	if (!cfg.command_name)
		errExit("strdup");

	 
	char *ptr = cfg.command_name;
	while (*ptr != ' ' && *ptr != '\t' && *ptr != '\0')
		ptr++;
	*ptr = '\0';

	 
	ptr = strrchr(cfg.command_name, '/');
	if (ptr) {
		ptr++;
		if (*ptr == '\0') {
			fprintf(stderr, "Error: invalid command name\n");
			exit(1);
		}

		char *tmp = strdup(ptr);
		if (!tmp)
			errExit("strdup");

		 
		char *ptr2 = tmp;
		while (*ptr2 != '.' && *ptr2 != '\0')
			ptr2++;
		*ptr2 = '\0';
			
		free(cfg.command_name);
		cfg.command_name = tmp;
	}
}