home *** CD-ROM | disk | FTP | other *** search
- /*
- Stuff 2.0.
-
- Checksum: 927958532 (verify with "brik")
-
- (C) Copyright 1988 Rahul Dhesi. Permission is granted to copy and
- distribute this file in modified or unmodified form, whether for
- noncommercial or commercial use, provided (a) this copyright notice
- is preserved, (b) no attempt is made to restrict redistribution of
- this file, and (c) this file is not distributed as part of any
- collection whose redistribution is restricted by a compilation
- copyright.
- */
-
- #include "stuff.h"
- #include <stdio.h>
- #include <string.h>
- #include <dos.h>
-
- extern int last_opt;
- extern request_rec *options[];
- extern char fmtstr[];
- extern FILE *outfile;
-
- /*
- receives a filename that was found. Filters it and prints it
- if it is selected.
- */
-
- long total_size; /* accumulated file sizes */
- extern long size_limit; /* size limit per volume */
-
- void newfile(void)
- {
- printf ("---\n");
- }
-
- void dopath (char *pathname, struct file_info *file_info)
- {
- int i;
- int select = 0;
- int exclude = 0;
- int have_name = 0;
- int name_matched = 0;
- int have_condition = 0;
- request_rec *p_opt;
-
- strlwr (pathname);
- if (last_opt < 0) /* no selection */
- select = 1;
- else {
- for (i = 0; i <= last_opt; i++) {
- p_opt = options[i];
- switch (p_opt->choice) {
- case PRINT:
- break; /* ignore */
- case NAME: {
- int matched;
-
- have_condition = 1;
- if (findlast (p_opt->info.name, "/\\") == NULL) {
- matched = matchstr (fptr(pathname), p_opt->info.name);
- } else {
- matched = matchstr (pathname, p_opt->info.name);
- }
- if (p_opt->negate) {
- if (matched) {
- exclude = 1;
- goto done;
- }
- } else {
- have_name = 1; /* at least one filename argument */
- if (matched) {
- name_matched = 1; /* at least one filename matched */
- select = 1;
- }
- }
- break;
- }
- case MTIME: {
- int time_ok = 0;
- have_condition = 1;
- time_ok = cmptime (file_info->utime,
- p_opt->info.mtime_info.choice,
- p_opt->info.mtime_info.value * (60L * 60L * 24L));
- if (p_opt->negate && time_ok ||
- !p_opt->negate && !time_ok) {
- exclude = 1;
- goto done;
- } else
- select = 1;
- break;
- }
-
- case NEWER: {
- int time_ok = 0;
- have_condition = 1;
- time_ok = cmptime2 (file_info->utime,
- BIGGER,
- p_opt->info.mtime_info.value);
- if (p_opt->negate && time_ok ||
- !p_opt->negate && !time_ok) {
- exclude = 1;
- goto done;
- } else
- select = 1;
- break;
- }
-
- case OLDER: {
- int time_ok = 0;
- have_condition = 1;
- time_ok = cmptime2 (file_info->utime,
- SMALLER,
- p_opt->info.mtime_info.value);
- if (p_opt->negate && time_ok ||
- !p_opt->negate && !time_ok) {
- exclude = 1;
- goto done;
- } else
- select = 1;
- break;
- }
-
- case SIZE: {
- int size_ok = 0;
- have_condition = 1;
- size_ok = cmpsize (file_info->size,
- p_opt->info.size_info.choice,
- p_opt->info.size_info.value);
- if (p_opt->negate && size_ok ||
- !p_opt->negate && !size_ok) {
- exclude = 1;
- goto done;
- } else
- select = 1;
- break;
- }
-
- case MODIFIED: {
- int mod_ok = 0;
- have_condition = 1;
- if (file_info->attrib & FA_ARCH)
- mod_ok = 1;
- if (p_opt->negate && mod_ok ||
- !p_opt->negate && !mod_ok) {
- exclude = 1;
- goto done;
- } else
- select = 1;
- break;
- }
-
- default: bugreport("dopath");
- }
- }
- }
- done: /* come from case NAME in switch */
- #if 0
- printf ("have_condition=%d, exclude=%d, select=%d\n",
- have_condition, exclude, select);
- #endif
-
- if (
- have_condition && ((select || !have_name) && !exclude) &&
- (have_name && name_matched || !have_name)
- ||
- !have_condition
- )
- {
- /* accumulate file size; if too much, open next file */
- total_size = total_size + file_info->size;
- if (size_limit != 0L && total_size > size_limit) {
- total_size = file_info->size;
- newfile();
- }
-
- if (*fmtstr != '\0')
- fprintf (outfile, fmtstr, pathname);
- else
- fprintf (outfile, "%s\n", pathname);
- }
- }
-
- /*
- returns pointer to filename part of pathname
- */
- char *fptr (char *pathname)
- {
- char *p;
- p = findlast (pathname, ":/\\"); /* look for : / and \ */
- if (p == NULL)
- return (pathname);
- else
- return (p+1);
- }
-
-
- #define KBYTE 1024
-
- int cmpsize (long size, compare_pt choice, long value)
- {
- size /= KBYTE;
-
- if (choice == SAME && size == value ||
- choice == BIGGER && size > value ||
- choice == SMALLER && size < value) {
- return (1);
- } else {
- return (0);
- }
- }
-