FreeBSD/usr.bin/catman/catman.c
/*
 * Processes a single top-level man directory.  If section isn't NULL,
 * it will only process that section sub-directory, otherwise it will
 * process all of them.
 */
Processes a single top-level man directory.  If section isn't NULL,
it will only process that section sub-directory, otherwise it will
process all of them.
Processes a single top - level man directory . If section isn ' t NULL it will only process that section sub - directory otherwise it will process all of them .
static void
process_mandir(char *dir_name, char *section)
{
	if (fchdir(starting_dir) < 0)
		err(1, "fchdir");
	if (already_visited(NULL, dir_name, section == NULL))
		return;
	check_writable(dir_name);
	if (verbose)
		fprintf(stderr, "man directory %s\n", dir_name);
	if (pretend)
		fprintf(stderr, "cd %s\n", dir_name);
	if (chdir(dir_name) < 0) {
		warn("%s: chdir", dir_name);
		exit_code = 1;
		return;
	}
	if (section != NULL) {
		process_section(dir_name, section);
	} else {
		struct dirent **entries;
		char *machine_dir, *arch_dir;
		int nsections;
		int i;
		nsections = scandir(".", &entries, select_sections, alphasort);
		if (nsections < 0) {
			warn("%s", dir_name);
			exit_code = 1;
			return;
		}
		for (i = 0; i < nsections; i++) {
			process_section(dir_name, entries[i]->d_name);
			asprintf(&machine_dir, "%s/%s", entries[i]->d_name,
			    machine);
			if (test_path(machine_dir, NULL) & TEST_DIR)
				process_section(dir_name, machine_dir);
			free(machine_dir);
			if (strcmp(machine_arch, machine) != 0) {
				asprintf(&arch_dir, "%s/%s", entries[i]->d_name,
				    machine_arch);
				if (test_path(arch_dir, NULL) & TEST_DIR)
					process_section(dir_name, arch_dir);
				free(arch_dir);
			}
			free(entries[i]);
		}
		free(entries);
	}
}
static void process_mandir ( char * dir_name , char * section ) { if ( fchdir ( starting_dir ) < 0 ) err ( 1 , " " ) ; if ( already_visited ( NULL , dir_name , section == NULL ) ) return ; check_writable ( dir_name ) ; if ( verbose ) fprintf ( stderr , " \n " , dir_name ) ; if ( pretend ) fprintf ( stderr , " \n " , dir_name ) ; if ( chdir ( dir_name ) < 0 ) { warn ( " " , dir_name ) ; exit_code = 1 ; return ; } if ( section != NULL ) { process_section ( dir_name , section ) ; } else { struct dirent * * entries ; char * machine_dir , * arch_dir ; int nsections ; int i ; nsections = scandir ( " " , & entries , select_sections , alphasort ) ; if ( nsections < 0 ) { warn ( " " , dir_name ) ; exit_code = 1 ; return ; } for ( i = 0 ; i < nsections ; i ++ ) { process_section ( dir_name , entries [ i ] -> d_name ) ; asprintf ( & machine_dir , " " , entries [ i ] -> d_name , machine ) ; if ( test_path ( machine_dir , NULL ) & TEST_DIR ) process_section ( dir_name , machine_dir ) ; free ( machine_dir ) ; if ( strcmp ( machine_arch , machine ) != 0 ) { asprintf ( & arch_dir , " " , entries [ i ] -> d_name , machine_arch ) ; if ( test_path ( arch_dir , NULL ) & TEST_DIR ) process_section ( dir_name , arch_dir ) ; free ( arch_dir ) ; } free ( entries [ i ] ) ; } free ( entries ) ; } }
Processes a single top-level man directory.
Processes a single top - level man directory .