void display_Ls_tmp( int cnt ){
display_Ls( cnt );
return ;
}
/**********************************************************
ls /tmp 的分栏输出
***********************************************************/
void do_ls( int myJudge,char myOrder[] ){
char dirname[ maxL ];
if( myJudge!=LS_TMP && myJudge!=LS_L){
strcpy( dirname,"." );
}
else {
strcpy( dirname,myOrder );
}
DIR * dir_ptr;
struct dirent *direntp;
int cntOutput = 0;
int cntOutputPoint = 0;
char full_path[256];
if( ( dir_ptr = opendir( dirname ) )==NULL ){
fprintf( stderr,"my god, i cannot open %s\n",dirname );
}
else{
if(myJudge!=LS_L ) {
while( (direntp = readdir( dir_ptr ) )!=NULL ){
if( direntp->d_name[ 0 ]=='.' ) {
strcpy( OutputPoint[ cntOutputPoint ].FileName,direntp->d_name );
OutputPoint[ cntOutputPoint ].file_type = get_file_type( OutputPoint[ cntOutputPoint ].FileName );
OutputPoint[ cntOutputPoint ].modify_time = get_modify_time( OutputPoint[ cntOutputPoint ].FileName );
cntOutputPoint ++;
}
else {
strcpy( Output[ cntOutput ].FileName,direntp->d_name );
Output[ cntOutput ].file_type = get_file_type( Output[ cntOutput ].FileName );
Output[ cntOutput ].modify_time = get_modify_time( Output[ cntOutput ].FileName );
cntOutput ++;
}
}
}
if( myJudge==LS_T ){
qsort( OutputPoint,cntOutputPoint,sizeof( OutputPoint[0] ),cmp2 );
qsort( Output,cntOutput,sizeof( Output[0] ),cmp2 );
}
else {
qsort( OutputPoint,cntOutputPoint,sizeof( OutputPoint[0] ),cmp1 );
qsort( Output,cntOutput,sizeof( Output[0] ),cmp1 );
}
/**********************************************************
预处理输出
***********************************************************/
if( myJudge==LS||myJudge==LS_T ){
display_Ls( cntOutput );
closedir( dir_ptr );
}
/**********************************************************
ls && ls -t
***********************************************************/
else if( myJudge==LS_A ){
display_Ls_a( cntOutputPoint,cntOutput );
closedir( dir_ptr );
}
/**********************************************************
ls -a
***********************************************************/
else if( myJudge==LS_L ){
while( (direntp = readdir( dir_ptr ) )!=NULL ){
if( direntp->d_name[ 0 ]=='.' ) {
strcpy( OutputPoint[ cntOutputPoint ].FileName,direntp->d_name );
OutputPoint[ cntOutputPoint ].file_type = get_file_type( OutputPoint[ cntOutputPoint ].FileName );
OutputPoint[ cntOutputPoint ].modify_time = get_modify_time( OutputPoint[ cntOutputPoint ].FileName );
cntOutputPoint ++;
}
else {
strcpy(full_path, dirname);
int dir_len = strlen(dirname);
strcpy(full_path + dir_len, direntp->d_name);
strcpy( Output[ cntOutput ].FileName,full_path );
Output[ cntOutput ].file_type = get_file_type( Output[ cntOutput ].FileName );
Output[ cntOutput ].modify_time = get_modify_time( Output[ cntOutput ].FileName );