|
|
1.1 ! root 1: /* wildcard.c */ ! 2: ! 3: /* Author: ! 4: * Guntram Blohm ! 5: * Buchenstrasse 19 ! 6: * 7904 Erbach, West Germany ! 7: * Tel. ++49-7305-6997 ! 8: * sorry - no regular network connection ! 9: */ ! 10: ! 11: /* this program implements wildcard expansion for elvis/dos. It works ! 12: * like UNIX echo, but uses the dos wildcard conventions ! 13: * (*.* matches all files, * matches files without extension only, ! 14: * filespecs may contain drive letters, wildcards not allowed in directory ! 15: * names). ! 16: * ! 17: * It is also #included into ctags.c, ref.c, ...; in this case, ! 18: * we don't want a main function here. ! 19: */ ! 20: ! 21: #include <stdio.h> ! 22: #include <ctype.h> ! 23: #ifdef __TURBOC__ ! 24: #include <dir.h> ! 25: #endif ! 26: #ifdef M_I86 ! 27: #define findfirst(a,b,c) _dos_findfirst(a,c,b) ! 28: #define findnext _dos_findnext ! 29: #define ffblk find_t ! 30: #define ff_name name ! 31: #include <dos.h> ! 32: #endif ! 33: #ifdef M68000 ! 34: #include <stat.h> ! 35: #include <osbind.h> ! 36: #define findfirst(a,b,c) (Fsetdta(b), (Fsfirst(a,c))) ! 37: #define findnext(x) (Fsnext()) ! 38: #define ff_name d_fname ! 39: #endif ! 40: #define MAXFILES 1000 ! 41: ! 42: int pstrcmp(); ! 43: extern char *calloc(); ! 44: ! 45: char *files[MAXFILES]; ! 46: int nfiles; ! 47: ! 48: #ifndef WILDCARD_NO_MAIN ! 49: ! 50: main(argc, argv) ! 51: char **argv; ! 52: { ! 53: int i; ! 54: ! 55: for (i=1; i<argc; i++) ! 56: expand(argv[i]); ! 57: if (nfiles) ! 58: printf("%s", files[0]); ! 59: for (i=1; i<nfiles; i++) ! 60: { ! 61: printf(" %s", files[i]); ! 62: } ! 63: putchar('\n'); ! 64: return 0; ! 65: } ! 66: ! 67: #else ! 68: char **wildexpand(argc, argv) ! 69: int *argc; ! 70: char **argv; ! 71: { ! 72: int i; ! 73: ! 74: for (i=0; i<*argc; i++) ! 75: expand(argv[i]); ! 76: *argc=nfiles; ! 77: return files; ! 78: } ! 79: #endif ! 80: ! 81: expand(name) ! 82: char *name; ! 83: { ! 84: char *filespec; ! 85: int wildcard=0; ! 86: #ifdef M68000 ! 87: DMABUFFER findbuf; ! 88: #else ! 89: struct ffblk findbuf; ! 90: #endif ! 91: int err; ! 92: char buf[80]; ! 93: int lastn; ! 94: ! 95: strcpy(buf, name); ! 96: for (filespec=buf; *filespec; filespec++) ! 97: ; ! 98: ! 99: while (--filespec>=buf) ! 100: { if (*filespec=='?' || *filespec=='*') ! 101: wildcard=1; ! 102: if (*filespec=='/' || *filespec=='\\' || *filespec==':') ! 103: break; ! 104: } ! 105: if (!wildcard) ! 106: addfile(buf); ! 107: else ! 108: { ! 109: lastn=nfiles; ! 110: filespec++; ! 111: if ((err=findfirst(buf, &findbuf, 0))!=0) ! 112: addfile(buf); ! 113: while (!err) ! 114: { ! 115: strcpy(filespec, findbuf.ff_name); ! 116: addfile(buf); ! 117: err=findnext(&findbuf); ! 118: } ! 119: if (lastn!=nfiles) ! 120: qsort(files+lastn, nfiles-lastn, sizeof(char *), pstrcmp); ! 121: } ! 122: } ! 123: ! 124: addfile(buf) ! 125: char *buf; ! 126: { ! 127: char *p; ! 128: ! 129: for (p=buf; *p; p++) ! 130: *p=tolower(*p); ! 131: ! 132: if (nfiles<MAXFILES && (files[nfiles]=calloc(strlen(buf)+1, 1))!=0) ! 133: strcpy(files[nfiles++], buf); ! 134: } ! 135: ! 136: int pstrcmp(a, b) ! 137: char **a, **b; ! 138: { ! 139: return strcmp(*a, *b); ! 140: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.