-----BEGIN PGP SIGNED MESSAGE----- # # This patch is for the Red Hat findutils 4.1 # Under GPL. No warranty at all. # It applies an extension by Antonomasia # to allow a new predicate '-content' # find . -content a gets text files (A for ASCII) # find . -content b gets binary files (B for Binary) # # First done in May 1997; repeated June 1998 with no 'indent' runs # to make spurious changes. # # cd /usr/src/redhat/BUILD/findutils-4.1/find # patch < findpatch *** findutils-4.1/find/defs.h Sat Jun 6 13:24:04 1998 - --- findutils-4.1/find/defs.h.ant Sat Jun 6 13:27:34 1998 *************** *** 56,59 **** - --- 56,62 ---- #define false 0 + #define ANT_ASCII 1 + #define ANT_BINARY 2 + /* Pointer to function returning boolean. */ typedef boolean (*PFB)(); *************** *** 286,289 **** - --- 289,293 ---- boolean pred_true P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_type P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); + boolean pred_content P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_uid P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); boolean pred_used P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); *** findutils-4.1/find/find.1 Wed Nov 2 20:59:16 1994 - --- findutils-4.1/find/find.1.ant Sat Jun 6 13:27:34 1998 *************** *** 110,113 **** - --- 110,117 ---- \-cnewer is affected by \-follow only if \-follow comes before \-cnewer on the command line. + .IP \-content + Look at file content (if readable) to determine whether it + is Ascii (\-content a) or Binary (\-content b). The file + matches the form requested. .IP "\-ctime \fIn\fR" File's status was last changed \fIn\fR*24 hours ago. *** findutils-4.1/find/parser.c Sat Jun 6 13:24:04 1998 - --- findutils-4.1/find/parser.c.ant Sat Jun 6 13:27:34 1998 *************** *** 124,127 **** - --- 124,128 ---- static boolean parse_true P_((char *argv[], int *arg_ptr)); static boolean parse_type P_((char *argv[], int *arg_ptr)); + static boolean parse_content P_((char *argv[], int *arg_ptr)); static boolean parse_uid P_((char *argv[], int *arg_ptr)); static boolean parse_used P_((char *argv[], int *arg_ptr)); *************** *** 140,143 **** - --- 141,145 ---- static boolean get_num P_((char *str, unsigned long *num, enum comparison_type *comp_type)); static boolean insert_num P_((char *argv[], int *arg_ptr, PFB pred)); + static boolean insert_content P_((char *argv[], int *arg_ptr,PFB pred)); static FILE *open_output_file P_((char *path)); *************** *** 225,228 **** - --- 227,231 ---- {"true", parse_true}, /* GNU */ {"type", parse_type}, + {"content", parse_content}, /* ant notatla.demon.co.uk */ {"uid", parse_uid}, /* GNU */ {"used", parse_used}, /* GNU */ *************** *** 1240,1243 **** - --- 1243,1254 ---- static boolean + parse_content (argv, arg_ptr) + char *argv[]; + int *arg_ptr; + { + return insert_content (argv, arg_ptr, pred_content); + } + + static boolean parse_uid (argv, arg_ptr) char *argv[]; *************** *** 1324,1327 **** - --- 1335,1367 ---- { return insert_type (argv, arg_ptr, pred_xtype); + } + + static boolean + insert_content (argv, arg_ptr, which_pred) + char *argv[]; + int *arg_ptr; + boolean (*which_pred) (); + { + unsigned long content_cell; + struct predicate *our_pred; + + if ((NULL==argv) || (NULL==argv[*arg_ptr]) + || ( 1 != strlen (argv[*arg_ptr]))) + return (false); + switch (argv[*arg_ptr][0]) + { + case 'a': /* ascii */ + content_cell = ANT_ASCII; + break; + case 'b': /* binary */ + content_cell = ANT_BINARY; + break; + default: /* None of the above ... nuke 'em. */ + return (false); + } + our_pred = insert_primary (which_pred); + our_pred->args.type = content_cell; + (*arg_ptr)++; /* Move on to next argument. */ + return (true); } *** findutils-4.1/find/pred.c Sat Jun 6 13:24:04 1998 - --- findutils-4.1/find/pred.c.ant Sat Jun 6 13:27:34 1998 *************** *** 29,32 **** - --- 29,36 ---- #include "modetype.h" #include "wait.h" + #include + #include + #include + #if !defined(SIGCHLD) && defined(SIGCLD) *************** *** 146,149 **** - --- 150,154 ---- {pred_true, "true "}, {pred_type, "type "}, + {pred_content, "content "}, {pred_uid, "uid "}, {pred_used, "used "}, *************** *** 1212,1215 **** - --- 1217,1301 ---- else return (false); + } + + boolean + pred_content (pathname, stat_buf, pred_ptr) + char *pathname; + struct stat *stat_buf; + struct predicate *pred_ptr; + { + int plainfile, i, want, got, islink; + unsigned char buf[500]; + FILE *fp; + struct predicate tmppred, *pp; + /** + *** We call pred_xtype, to check + *** this is plain file (or a link to one if following links). + *** If not a plain file or a link to one return false. + *** + *** Then test the file for matching the selected content. + *** Ascii or Binary. + **/ + + want = (pred_ptr->args.type); + + switch (want) + { + case ANT_ASCII: + break; + + case ANT_BINARY: + break; + + default: + fprintf (stderr, + "find: checking for file content of unknown code number %d\n", want); + abort (); + break; + } + + pp = &tmppred; + pp->args.type = S_IFLNK; + islink = pred_type (pathname, stat_buf, pp); + if (dereference && islink) + { + pp->args.type = S_IFREG; + plainfile = pred_xtype (pathname, stat_buf, pp); + if (!plainfile){ + return false; /* pred_xtype rejects this pathname */ + } + } + else + { + pp->args.type = S_IFREG; + plainfile = pred_type (pathname, stat_buf, pp); + if (!plainfile) { + return false; /* pred_type rejects this pathname */ + } + } + + + /*** room to do more if given some thought ***/ + + pathname=basename(pathname); + fp = fopen (pathname, "r"); + if (NULL == fp) { + fprintf(stderr,"find: could not open %s\n",pathname); + perror(strerror(errno)); + return false; + } + i = fread (&buf, sizeof (unsigned char), 499, fp); + fclose (fp); + + got = 0; + for (i--; (i>0) && (!got); i--) { + if (!isascii (buf[i])) got = ANT_BINARY; + } + + if (!got) + got = ANT_ASCII; /** ASCII if in doubt - includes empty files **/ + + return (want == got); /* true if we asked for an ASCII file and got it + or we asked for a binary file and got it */ } *** findutils-4.1/find/version.c Fri Nov 4 04:19:16 1994 - --- findutils-4.1/find/version.c.ant Sat Jun 6 13:27:34 1998 *************** *** 1 **** ! char *version_string = "4.1"; - --- 1 ---- ! char *version_string = "4.1.1"; -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: noconv iQCVAgUBNXk8rkrZ5ZQH9XIxAQE+aAQAivBIycc1z2eKL7RdHkXNndtm5gzNU1mw hPLE5CjsF4/e0R8TJDVnDUvXNs+pwmiJDPI7DUTYdmREOvvL2SHWSxyqA1kLT+3X ol2JzuOf1M6E9gpb1rr6uve0g6sm/YLW3d7yUHaheB70mpIYtpu5p77oFgO5VPIk EGaXCQB65bg= =w37e -----END PGP SIGNATURE-----