示例#1
0
文件: czzcat.c 项目: baotiao/Asenal
int main(int argc, char *argv[])
{
    FILE *fp;

    if (argc == 1) {
        errno = 1;
        char *str = "chenzongzhi";
        perror(str);

        fprintf(stderr, "There is only one input %s\n", argv[0]);
        filecpy(stdin, stdout);
    } else {
        fp = fopen(argv[1], "r");
        filecpy(fp, stdout);
    }
    return 0;
}
示例#2
0
int main(int argc, char *argv[]) {
    FILE *fp;
    char* prog = argv[0];
    
    if (argc == 1) {
        filecpy(stdin, stdout);
    } else {
        while (--argc > 0) {
            if ((fp = fopen(*++argv, "r")) == NULL) {
                fprintf(stderr, "%s: can't open %s\n", prog, *argv);
                return 1;
            } else {
                filecpy(fp, stdout);
                fclose(fp);
            }
        }
    }
    return 0;
}
示例#3
0
文件: catman.c 项目: Hooman3/minix
/*
 * Copy both recno and btree databases into the destination.
 * Call in to begin recreating HTML files.
 * Return -1 on fatal error and 1 if the update went well.
 */
static int
update(char *dst, char *src)
{
	size_t		 dsz, ssz;

	dsz = strlen(dst);
	ssz = strlen(src);

	xstrlcat(src, "/", MAXPATHLEN);
	xstrlcat(dst, "/", MAXPATHLEN);

	xstrlcat(src, MANDOC_DB, MAXPATHLEN);
	xstrlcat(dst, MANDOC_DB, MAXPATHLEN);

	if ( ! filecpy(dst, src))
		return(-1);
	if (verbose)
		printf("%s\n", dst);

	dst[(int)dsz] = src[(int)ssz] = '\0';

	xstrlcat(src, "/", MAXPATHLEN);
	xstrlcat(dst, "/", MAXPATHLEN);

	xstrlcat(src, MANDOC_IDX, MAXPATHLEN);
	xstrlcat(dst, MANDOC_IDX, MAXPATHLEN);

	if ( ! filecpy(dst, src))
		return(-1);
	if (verbose)
		printf("%s\n", dst);

	dst[(int)dsz] = src[(int)ssz] = '\0';

	return(indexhtml(src, ssz, dst, dsz));
}
示例#4
0
文件: catman.c 项目: Hooman3/minix
/*
 * Pass over the recno database and re-create HTML pages if they're
 * found to be out of date.
 * Returns -1 on fatal error, 1 on success.
 */
static int
indexhtml(char *src, size_t ssz, char *dst, size_t dsz)
{
	DB		*idx;
	DBT		 key, val;
	int		 c, rc;
	unsigned int	 fl;
	const char	*f;
	char		*d;
	char		 fname[MAXPATHLEN];
	pid_t		 pid;

	pid = -1;

	xstrlcpy(fname, dst, MAXPATHLEN);
	xstrlcat(fname, "/", MAXPATHLEN);
	xstrlcat(fname, MANDOC_IDX, MAXPATHLEN);

	idx = dbopen(fname, O_RDONLY, 0, DB_RECNO, NULL);
	if (NULL == idx) {
		perror(fname);
		return(-1);
	}

	fl = R_FIRST;
	while (0 == (c = (*idx->seq)(idx, &key, &val, fl))) {
		fl = R_NEXT;
		/*
		 * If the record is zero-length, then it's unassigned.
		 * Skip past these.
		 */
		if (0 == val.size)
			continue;

		f = (const char *)val.data + 1;
		if (NULL == memchr(f, '\0', val.size - 1))
			break;

		src[(int)ssz] = dst[(int)dsz] = '\0';

		xstrlcat(dst, "/", MAXPATHLEN);
		xstrlcat(dst, f, MAXPATHLEN);

		xstrlcat(src, "/", MAXPATHLEN);
		xstrlcat(src, f, MAXPATHLEN);

		if (-1 == (rc = isnewer(dst, src))) {
			fprintf(stderr, "%s: File missing\n", f);
			break;
		} else if (0 == rc)
			continue;

		d = strrchr(dst, '/');
		assert(NULL != d);
		*d = '\0';

		if (-1 == mkpath(dst, 0755, 0755)) {
			perror(dst);
			break;
		}

		*d = '/';

		if ( ! filecpy(dst, src))
			break;
		if (verbose)
			printf("%s\n", dst);
	}

	(*idx->close)(idx);

	if (c < 0)
		perror(fname);
	else if (0 == c) 
		fprintf(stderr, "%s: Corrupt index\n", fname);

	return(1 == c ? 1 : -1);
}