/* * DibbsFamGrep.c * Sample Complex FAMgrep code. * This is the FAMgrep used by DIBBS. */ /***************************************************************** This FAMgrep takes four arguments. The first is a digit representing which type of GREP to perform and for now must always be zero. The second is the prefix of the filename. If the filename does not start with this prefix then DibbsGrep will return FALSE. The third is the line tag to look for. DibbsGrep will return FALSE if there is no line in the contents that starts with this string. The fourth is the value. If the line containing the indicated line tag does not contain the contents as a separate word then DibbsGrep will return FALSE. If the file name starts with argument two and it contains a line that starts with argument three and that line contains a word matching argument four then DibbsGrep returns true. ******************************************************************/ #include "exec/types.h" #include "FAM.h" #include "string.h" long DibbsFamGrep(struct ScanListNode * node, char * p) { char buf[256]; char * prefix, * tag, * word; unsigned short i; /* first, parse the parameters */ while (*p && *p <= ' ') p += 1; if (!*p) return 0; if (*p++ != '0') return 0; /* unknown grep type */ while (*p && *p <= ' ') p += 1; if (!*p) return 0; if (sizeof(buf) <= strlen(p)) return 0; strcpy(buf, p); prefix = p = buf; while (' ' < *p) p += 1; if (*p == ' ') *p++ = '\0'; else return 0; tag = p; while (' ' < *p) p += 1; if (*p == ' ') *p++ = '\0'; else return 0; word = p; while (' ' < *p) p += 1; *p = '\0'; /* Here, check if file fullfills requirements */ if (0 != strncmp(prefix, node->node.ln_Name, strlen(prefix))) return 0; i = strlen(tag); for (p = node->contents; p != NULL; ) { if (strncmp(p, tag, i) == 0) break; p = strchr(p, '\n'); if (p) p += 1; } if (p == NULL) return 0; i = strlen(word); do { while (*p && *p != ' ') p += 1; while (*p == ' ') p += 1; if (!*p) break; if (0 == strncmp(p, word, i) && (p[i] == ' ' || p[i] == '\n' || p[i] == '\0')) { return 1; /* we found it! */ } } while (1); /* internal break gets us out */ return 0; /* oh well. */ }