#include <stdio.h>

int match_pattern(char *s, int is, char *p, int ip) {
	int res;
	while (1) {
		if (p[ip] == 0)
			if (s[is] == 0)
				return 1;
			else
				return 0;
		else if (p[ip] == '*') {
			ip++;
			for (; s[is]; is++) {
				res = match_pattern(s, is, p, ip);
				if (res == 1)
					return 1;
			}
			if (res == 0)
				return 0;
		} else if (s[is] == 0 && p[ip] != '?' && s[is] != p[ip])
			return 0;
		else {
			is++;
			ip++;
		}
	}
}


int main(int argc, char **argv) {
	if (argc != 3) {
		fprintf(stderr, "Usage: ./match <string> <patter>\n");
		return 1;
	}
	int result = match_pattern(argv[1], 0, argv[2], 0);
	printf("%d\n", result);
	/*
	if (result)
		printf("String %s matches pattern %s\n",
			argv[1], argv[2]);
	else
		printf("String %s does NOT match pattern %s\n",
			argv[1], argv[2]);
	*/
	return 0;
}
