[net.sources] RT-11 floppy -- listdir.c

jrb@wdl1.UUCP (John R Blaker) (02/17/84)

/*==========================================================================*
 *			      == L I S T D I R ==			    *
 *==========================================================================*
 * John R Blaker -- Ford Aerospace & Communications Corporation -- Oct 1982 *
 *==========================================================================*
 * This file contains those routines neccessary to listing the disc         *
 * directory.  It contains the following functions:			    *
 *	listdir()	List the directory				    *
 *==========================================================================*
 */

/*
 * Include files
 */

#include	"rt11.h"	/* Global definitions */

/*
 * listdir()
 * This function prints the directory by traversing
 * the in-memory directory printing the filename.  If the
 * VERBOSE flag is set the size (in blocks) and the creation
 * date are printed as well.
 * The date has the following format in the entry:
 *     +--+--------------+--------------+--------------+
 *     |15|14 13 12 11 10| 9  8  7  6  5| 4  3  2  1  0|
 *     +--+--------------+--------------+--------------+
 *     |  | Month, in    | Day, in      | Year - 110   |
 *     |  |  decimal     |   decimal    |  in octal    |
 *     +--+--------------+--------------+--------------+
 */

listdir()
{
	MEM_DIR		*cur_dir;	/* Current entry */
	static char	*Month[] = {
		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
	};			/* An array to hold the month names */
	unsigned	day;	/* Day of creation */
	unsigned	month;	/* Month of creation */
	int		year;	/* Year of creation */

	verbose("LISTING DIRECTORY");
	trace("Got to listdir()");
	verbose("Name   \t\tSize\tDate");
	verbose("==================================");
	cur_dir = dir_header;
	while (cur_dir -> md_next != NULL) {
		if (VERBOSE) {
			if (cur_dir -> md_date == 0)
				printf("-----------\n");
			else {
				day = month = year = cur_dir -> md_date;
				day >> 5;
				day &= 037;
				month >> 10;
				month &= 037;
				year &= 037;
				year += 0110;
				printf("%s   \t%u\t", cur_dir -> md_name,
					((cur_dir -> md_size) / BLOCKSIZE));
				printf("%u--%s--%u\n", day, Month[month], year);
			} /* if...else */
		} else
			printf("%s\n", cur_dir -> md_name);
		cur_dir = cur_dir -> md_next;
	} /* while */
} /* listdir */