FreeBSD/bin/ls/ls.c
/*
 * Traverse() walks the logical directory structure specified by the argv list
 * in the order specified by the mastercmp() comparison function.  During the
 * traversal it passes linked lists of structures to display() which represent
 * a superset (may be exact set) of the files to be displayed.
 */
Traverse() walks the logical directory structure specified by the argv list
in the order specified by the mastercmp() comparison function.  During the
traversal it passes linked lists of structures to display() which represent
a superset (may be exact set) of the files to be displayed.
Traverse () walks the logical directory structure specified by the argv list in the order specified by the mastercmp () comparison function . During the traversal it passes linked lists of structures to display () which represent a superset ( may be exact set ) of the files to be displayed .
static void
traverse(int argc, char *argv[], int options)
{
	FTS *ftsp;
	FTSENT *p, *chp;
	int ch_options;
	int first = 1;
	if ((ftsp =
	    fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL)
		xo_err(1, "fts_open");
	chp = fts_children(ftsp, 0);
	if (chp != NULL)
		display(NULL, chp, options);
	if (f_listdir)
		return;
	ch_options = !f_recursive && !f_label &&
	    options & FTS_NOSTAT ? FTS_NAMEONLY : 0;
	while ((p = fts_read(ftsp)) != NULL)
		switch (p->fts_info) {
		case FTS_DC:
			xo_warnx("%s: directory causes a cycle", p->fts_name);
			break;
		case FTS_DNR:
		case FTS_ERR:
			xo_warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
			rval = 1;
			break;
		case FTS_D:
			if (p->fts_level != FTS_ROOTLEVEL &&
			    p->fts_name[0] == '.' && !f_listdot)
				break;
			if (first) {
				first = 0;
				xo_open_list("directory");
			}
			xo_open_instance("directory");
			if (output) {
				xo_emit("\n");
				(void)printname("path", p->fts_path);
				xo_emit(":\n");
			} else if (argc > 1) {
				(void)printname("path", p->fts_path);
				xo_emit(":\n");
				output = 1;
			}
			chp = fts_children(ftsp, ch_options);
			display(p, chp, options);
			xo_close_instance("directory");
			if (!f_recursive && chp != NULL)
				(void)fts_set(ftsp, p, FTS_SKIP);
			break;
		default:
			break;
		}
	if (!first)
		xo_close_list("directory");
	if (errno)
		xo_err(1, "fts_read");
}
static void traverse ( int argc , char * argv [ ] , int options ) { FTS * ftsp ; FTSENT * p , * chp ; int ch_options ; int first = 1 ; if ( ( ftsp = fts_open ( argv , options , f_nosort ? NULL : mastercmp ) ) == NULL ) xo_err ( 1 , " " ) ; chp = fts_children ( ftsp , 0 ) ; if ( chp != NULL ) display ( NULL , chp , options ) ; if ( f_listdir ) return ; ch_options = ! f_recursive && ! f_label && options & FTS_NOSTAT ? FTS_NAMEONLY : 0 ; while ( ( p = fts_read ( ftsp ) ) != NULL ) switch ( p -> fts_info ) { case FTS_DC : xo_warnx ( " " , p -> fts_name ) ; break ; case FTS_DNR : case FTS_ERR : xo_warnx ( " " , p -> fts_path , strerror ( p -> fts_errno ) ) ; rval = 1 ; break ; case FTS_D : if ( p -> fts_level != FTS_ROOTLEVEL && p -> fts_name [ 0 ] == ' ' && ! f_listdot ) break ; if ( first ) { first = 0 ; xo_open_list ( " " ) ; } xo_open_instance ( " " ) ; if ( output ) { xo_emit ( " \n " ) ; ( void ) printname ( " " , p -> fts_path ) ; xo_emit ( " \n " ) ; } else if ( argc > 1 ) { ( void ) printname ( " " , p -> fts_path ) ; xo_emit ( " \n " ) ; output = 1 ; } chp = fts_children ( ftsp , ch_options ) ; display ( p , chp , options ) ; xo_close_instance ( " " ) ; if ( ! f_recursive && chp != NULL ) ( void ) fts_set ( ftsp , p , FTS_SKIP ) ; break ; default : break ; } if ( ! first ) xo_close_list ( " " ) ; if ( errno ) xo_err ( 1 , " " ) ; }
Traverse() walks the logical directory structure specified by the argv list
 in the order specified by the mastercmp() comparison function.
Traverse () walks the logical directory structure specified by the argv list in the order specified by the mastercmp () comparison function .
/*
	 * We ignore errors from fts_children here since they will be
	 * replicated and signalled on the next call to fts_read() below.
	 */ /*
	 * If not recursing down this tree and don't need stat info, just get
	 * the names.
	 */ /*
			 * If already output something, put out a newline as
			 * a separator.  If multiple arguments, precede each
			 * directory with its name.
			 */