FreeBSD/usr.bin/catman/catman.c
/*
 * Processes a single man page source by using nroff to create
 * the preformatted cat page.
 */
Processes a single man page source by using nroff to create
the preformatted cat page.
Processes a single man page source by using nroff to create the preformatted cat page .
static void
process_page(char *mandir, char *src, char *cat, enum Ziptype zipped)
{
	int src_test, cat_test;
	time_t src_mtime, cat_mtime;
	char cmd[MAXPATHLEN];
	dev_t src_dev;
	ino_t src_ino;
	const char *link_name;
	src_test = test_path(src, &src_mtime);
	if (!(src_test & (TEST_FILE|TEST_READABLE))) {
		if (!(src_test & TEST_DIR)) {
			warnx("%s/%s: unreadable", mandir, src);
			exit_code = 1;
			if (rm_junk && is_symlink(src))
				junk(mandir, src, "bogus symlink");
		}
		return;
	}
	src_dev = test_st.st_dev;
	src_ino = test_st.st_ino;
	cat_test = test_path(cat, &cat_mtime);
	if (cat_test & (TEST_FILE|TEST_READABLE)) {
		if (!force && cat_mtime >= src_mtime) {
			if (verbose) {
				fprintf(stderr, "\t%s/%s: up to date\n",
				    mandir, src);
			}
			return;
		}
	}
	if ((link_name = find_hashtable(links, src_ino, src_dev)) != NULL) {
		if (verbose || pretend) {
			fprintf(stderr, "%slink %s -> %s\n",
			    verbose ? "\t" : "", cat, link_name);
		}
		if (!pretend) {
			(void) unlink(cat);
			if (link(link_name, cat) < 0)
				warn("%s %s: link", link_name, cat);
		}
		return;
	}
	insert_hashtable(links, src_ino, src_dev, strdup(cat));
	if (verbose || pretend) {
		fprintf(stderr, "%sformat %s -> %s\n",
		    verbose ? "\t" : "", src, cat);
		if (pretend)
			return;
	}
	snprintf(tmp_file, sizeof tmp_file, "%s.tmp", cat);
	snprintf(cmd, sizeof cmd,
	    "%scat %s | tbl | nroff -c -T%s -man | %s > %s.tmp",
	    zipped == BZIP ? BZ2CAT_CMD : zipped == GZIP ? GZCAT_CMD : "",
	    src, nroff_device,
	    zipped == BZIP ? BZ2_CMD : zipped == GZIP ? GZ_CMD : "cat",
	    cat);
	if (system(cmd) != 0)
		err(1, "formatting pipeline");
	if (rename(tmp_file, cat) < 0)
		warn("%s", cat);
	tmp_file[0] = '\0';
}
static void process_page ( char * mandir , char * src , char * cat , enum Ziptype zipped ) { int src_test , cat_test ; time_t src_mtime , cat_mtime ; char cmd [ MAXPATHLEN ] ; dev_t src_dev ; ino_t src_ino ; const char * link_name ; src_test = test_path ( src , & src_mtime ) ; if ( ! ( src_test & ( TEST_FILE | TEST_READABLE ) ) ) { if ( ! ( src_test & TEST_DIR ) ) { warnx ( " " , mandir , src ) ; exit_code = 1 ; if ( rm_junk && is_symlink ( src ) ) junk ( mandir , src , " " ) ; } return ; } src_dev = test_st . st_dev ; src_ino = test_st . st_ino ; cat_test = test_path ( cat , & cat_mtime ) ; if ( cat_test & ( TEST_FILE | TEST_READABLE ) ) { if ( ! force && cat_mtime >= src_mtime ) { if ( verbose ) { fprintf ( stderr , " \t \n " , mandir , src ) ; } return ; } } if ( ( link_name = find_hashtable ( links , src_ino , src_dev ) ) != NULL ) { if ( verbose || pretend ) { fprintf ( stderr , " \n " , verbose ? " \t " : " " , cat , link_name ) ; } if ( ! pretend ) { ( void ) unlink ( cat ) ; if ( link ( link_name , cat ) < 0 ) warn ( " " , link_name , cat ) ; } return ; } insert_hashtable ( links , src_ino , src_dev , strdup ( cat ) ) ; if ( verbose || pretend ) { fprintf ( stderr , " \n " , verbose ? " \t " : " " , src , cat ) ; if ( pretend ) return ; } snprintf ( tmp_file , sizeof tmp_file , " " , cat ) ; snprintf ( cmd , sizeof cmd , " " , zipped == BZIP ? BZ2CAT_CMD : zipped == GZIP ? GZCAT_CMD : " " , src , nroff_device , zipped == BZIP ? BZ2_CMD : zipped == GZIP ? GZ_CMD : " " , cat ) ; if ( system ( cmd ) != 0 ) err ( 1 , " " ) ; if ( rename ( tmp_file , cat ) < 0 ) warn ( " " , cat ) ; tmp_file [ 0 ] = ' \0 ' ; }
Processes a single man page source by using nroff to create
 the preformatted cat page.
Processes a single man page source by using nroff to create the preformatted cat page .
/*
	 * Is the man page a link to one we've already processed?
	 */