kolibrios/programs/system/shell/cmd/cmd_ls.c
siemargl 4e23975970 better cp, 64-bit fileops
git-svn-id: svn://kolibrios.org@6857 a494cfbc-eb01-0410-851d-a64ba20cac60
2017-02-06 12:35:58 +00:00

65 lines
1.2 KiB
C

int cmd_ls(char dir[])
{
kol_struct70 k70;
unsigned *n;
unsigned num_of_file;
unsigned *t;
unsigned type_of_file;
int i, result;
k70.p00 = 1;
k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = 2; // just for test exist & read number of entries
k70.p16 = (unsigned) malloc(32+k70.p12*560);
k70.p20 = 0;
/// !!!
// …᫨ ls § ¯ã᪠¥âáï ¡¥§ ¯ à ¬¥â஢, ¯à®á¬ âਢ ¥¬ ⥪ã騩 ª â «®£
if ( !strlen(dir) )
k70.p21 = cur_dir;
else
k70.p21 = dir;
result = kol_file_70(&k70);
if ( !((result==0) || (result==6)) ) // ¯à®¢¥à塞 áãé¥á⢮¢ ­¨¥ ª â «®£ 
{
free( (void*) k70.p16);
return FALSE;
}
n = (unsigned*) (k70.p16+8);
num_of_file = *n; // ç¨á«® ä ©«®¢ ¢ ª â «®£¥
// now read full directory
k70.p12 = num_of_file;
free( (void*) k70.p16);
k70.p16 = (unsigned) malloc(32+k70.p12*560);
if ( !k70.p16 )
return FALSE;
result = kol_file_70(&k70);
if ( !((result==0) || (result==6)) )
{
free( (void*) k70.p16);
return FALSE;
}
for (i = 0; i < num_of_file; i++)
{
printf (" %s", k70.p16+32+40+(264+40)*i);
t = (unsigned*) (k70.p16+32+(264+40)*i);
type_of_file = *t;
if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) )
printf ("/");
printf ("\n\r");
}
free((void*)k70.p16);
return TRUE;
}