c/cosmic.c: A barebones globals implementation
This commit is contained in:
parent
7da798d8fa
commit
a4000ec9b3
|
@ -0,0 +1,32 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int match(const char *needle, const char *haystack) {
|
||||||
|
while(*haystack) {
|
||||||
|
if(*needle == '*' && *(needle + 1) == '*') {
|
||||||
|
needle += 1;
|
||||||
|
} else if(*needle == '*') {
|
||||||
|
if(*(needle + 1) == '\0') {
|
||||||
|
return 0;
|
||||||
|
} else if(*(needle + 1) == *haystack) {
|
||||||
|
needle += 1;
|
||||||
|
} else {
|
||||||
|
haystack += 1;
|
||||||
|
}
|
||||||
|
} else if(*needle == *haystack) {
|
||||||
|
needle += 1;
|
||||||
|
haystack += 1;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *needle != '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
if(argc != 3) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return match(argv[1], argv[2]);
|
||||||
|
}
|
Loading…
Reference in New Issue