LS_NEW.C
LIB3/STD/BASIC/LS_NEW.C · 4.5 KB
From the archive nm4dos.zip
Download the archive « Back to the archive contents
#pragma save_binary
/*
** NS-DOS list function
** Newstyle, 28/09/93
*/
#define COL "%^CYAN%^"
static int dd, df, dr, dl, db;
mixed do_level( string str );
static int new_list_files( string str1 )
{
string str2, str3;
int *ret;
/* Security check */
if( this_player( 1 ) != this_player() )
return 0;
/* Initialise flags */
df = dd = dr = dl = db = 0;
if( !str1 )
str1 = "";
str1 += " ";
/* Pick out and remove any flags */
while( sscanf( str1, "%s-%s %s", str1, str2, str3 ) == 3 )
{
str1 += str3;
if( sscanf( str2, "%s*%s", str2, str3 ) == 2 )
{
dl = 1;
str2 += str3;
}
if( sscanf( str2, "%so%s", str2, str3 ) == 2 )
{
db = 1;
str2 += str3;
}
if( sscanf( str2, "%sf%s", str2, str3 ) == 2 )
{
df = 1;
str2 += str3;
}
if( sscanf( str2, "%sr%s", str2, str3 ) == 2 )
{
dr = 1;
str2 += str3;
}
if( sscanf( str2, "%sd%s", str2, str3 ) == 2 )
{
dd = 1;
str2 += str3;
}
if( sscanf( str2, "%sv%s", str2, str3 ) == 2 )
{
dd = 1;
df = 1;
dl = 1;
db = 1;
str2 += str3;
}
if( sscanf( str2, "%sl%s", str2, str3 ) == 2 )
{
dd = 1;
df = 1;
dl = 1;
db = 1;
str2 += str3;
}
}
str1 = replace( str1, " ", "" );
str1 = (string)this_player()->get_path( str1 );
if( file_size( str1 ) == -2 && str1[ strlen( str1 ) - 1 ] != 47 )
str1 += "/";
ret = do_level( str1 );
/* Remember the base directory */
if( dr )
{
ret[ 1 ]++;
write( COL + ret[ 1 ] + " directories listed.%^RESET%^\n" );
}
if( df )
{
write( COL + ret[ 2 ] + " bytes in " + ret[ 0 ] + " files.%^RESET%^\n" );
if( !dr && ret[ 1 ] != 0 )
write( COL + ret[ 5 ] + " entries in " + ret[ 1 ] + " subdirectories.%^RESET%^\n" );
}
if( dl )
write( COL + ret[ 4 ] + " bytes loaded in " + ret[ 3 ] + " files.%^RESET%^\n" );
return 1;
}
int *do_level( string str )
{
mixed *dir;
int loop1, loop2, size, *ret, *sub;
string *subdir;
string output, tempstr;
/* Gets an array of arrays of file details from /global/path.c */
dir = get_dir( str, -1 );
ret = ({ 0, 0, 0, 0, 0, 0 });
/* Quick return from error/empty paths */
if( !sizeof( dir ) )
{
if( file_size( str ) == -1 )
write( COL + "File/path does not exist.%^RESET%^\n" );
else
write( COL + "Empty Directory : " + str + "%^RESET%^\n" );
return ret;
}
write( COL + "Directory of : " + str + "%^RESET%^\n" );
/* Removes anything after last directory */
if( str[ strlen( str ) - 1 ] != 47 )
{
subdir = explode( str, "/" );
str = implode( subdir[ 0..sizeof( subdir ) - 2 ], "/" ) + "/";
}
output = "";
subdir = ({ });
for( loop1 = 0; loop1 < sizeof( dir ); loop1++ )
{
size = dir[ loop1 ][ 1 ];
if( size != -2 )
{
ret[ 0 ]++;
/* File owner options */
if( db )
{
tempstr = "/secure/master"->creator_file( str + dir[ loop1 ][ 0 ] );
if( !tempstr )
tempstr = "no owner";
output += tempstr + " "[ 0..8 - strlen( tempstr ) ];
}
/* File size options */
if( df )
{
ret[ 2 ] += size;
tempstr = size + "";
output += " "[ 0..7 - strlen( tempstr ) ] + tempstr + " ";
}
else
{
tempstr = (size + 512) / 1024 + "";
output += " "[ 0..3 - strlen( tempstr ) ] + tempstr + " ";
}
/* Display time & date options */
if( dd )
output += ctime( dir[ loop1 ][ 2 ] ) + " ";
/* Display loaded file info options */
if( dl )
{
if( virtual_find_object( str + dir[ loop1 ][ 0 ] ) )
{
output += "(L) ";
ret[ 3 ]++;
ret[ 4 ] += size;
}
else
output += " ";
}
else
{
if( virtual_find_object( str + dir[ loop1 ][ 0 ] ) )
output += "*";
else
output += " ";
}
output += dir[ loop1 ][ 0 ] + "\n";
}
else
subdir += ({ dir[ loop1 ][ 0 ] + "/" });
}
ret[ 1 ] = sizeof( subdir );
for( loop1 = 0; loop1 < ret[ 1 ]; loop1++ )
{
if( df )
{
size = sizeof( get_dir( str + subdir[ loop1 ] ) );
ret[ 5 ] += size;
/* Display filesize options */
output += " "[ 0..3 - strlen( size + "" ) ] + "(" + size + ") ";
}
output += subdir[ loop1 ] + "\n";
}
printf( "%#-*s\n", ( int ) this_player()->query_cols() - 2, output );
/* Recursive directories. ret is an array of totals */
if( dr )
for( loop1 = 0; loop1 < sizeof( subdir ); loop1++ )
{
sub = do_level( str + subdir[ loop1 ] );
for( loop2 = 0; loop2 < 6; loop2++ )
ret[ loop2 ] += sub[ loop2 ];
}
return ret;
}