- made support for paged output a generic feature in wcmd

- rewrote DIR command accordingly
This commit is contained in:
Eric Pouech 2003-02-25 03:58:42 +00:00 committed by Alexandre Julliard
parent abef9da1be
commit 841d9828e9
3 changed files with 56 additions and 61 deletions

View File

@ -43,9 +43,8 @@ extern int echo_mode;
extern char quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH]; extern char quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH];
extern DWORD errorlevel; extern DWORD errorlevel;
int file_total, dir_total, line_count, page_mode, recurse, wide, bare, static int file_total, dir_total, recurse, wide, bare, max_width;
max_width; static ULONGLONG byte_total;
ULONGLONG byte_total;
/***************************************************************************** /*****************************************************************************
* WCMD_directory * WCMD_directory
@ -54,19 +53,18 @@ ULONGLONG byte_total;
* *
*/ */
void WCMD_directory () { void WCMD_directory (void) {
char path[MAX_PATH], drive[8]; char path[MAX_PATH], drive[8];
int status; int status, paged_mode;
ULARGE_INTEGER avail, total, free; ULARGE_INTEGER avail, total, free;
CONSOLE_SCREEN_BUFFER_INFO consoleInfo; CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
line_count = 5;
byte_total = 0; byte_total = 0;
file_total = dir_total = 0; file_total = dir_total = 0;
/* Handle args */ /* Handle args */
page_mode = (strstr(quals, "/P") != NULL); paged_mode = (strstr(quals, "/P") != NULL);
recurse = (strstr(quals, "/S") != NULL); recurse = (strstr(quals, "/S") != NULL);
wide = (strstr(quals, "/W") != NULL); wide = (strstr(quals, "/W") != NULL);
bare = (strstr(quals, "/B") != NULL); bare = (strstr(quals, "/B") != NULL);
@ -78,11 +76,15 @@ CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo); GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo);
max_width = consoleInfo.dwSize.X; max_width = consoleInfo.dwSize.X;
} }
if (paged_mode) {
WCMD_enter_paged_mode();
}
if (param1[0] == '\0') strcpy (param1, "."); if (param1[0] == '\0') strcpy (param1, ".");
status = GetFullPathName (param1, sizeof(path), path, NULL); status = GetFullPathName (param1, sizeof(path), path, NULL);
if (!status) { if (!status) {
WCMD_print_error(); WCMD_print_error();
if (paged_mode) WCMD_leave_paged_mode();
return; return;
} }
lstrcpyn (drive, path, 3); lstrcpyn (drive, path, 3);
@ -90,6 +92,7 @@ CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
if (!bare) { if (!bare) {
status = WCMD_volume (0, drive); status = WCMD_volume (0, drive);
if (!status) { if (!status) {
if (paged_mode) WCMD_leave_paged_mode();
return; return;
} }
} }
@ -108,6 +111,7 @@ CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
WCMD_output (" %18s bytes free\n\n", WCMD_filesize64 (free.QuadPart)); WCMD_output (" %18s bytes free\n\n", WCMD_filesize64 (free.QuadPart));
} }
} }
if (paged_mode) WCMD_leave_paged_mode();
} }
/***************************************************************************** /*****************************************************************************
@ -128,12 +132,11 @@ char string[1024], datestring[32], timestring[32];
char mem_err[] = "Memory Allocation Error"; char mem_err[] = "Memory Allocation Error";
char *p; char *p;
char real_path[MAX_PATH]; char real_path[MAX_PATH];
DWORD count;
WIN32_FIND_DATA *fd; WIN32_FIND_DATA *fd;
FILETIME ft; FILETIME ft;
SYSTEMTIME st; SYSTEMTIME st;
HANDLE hff; HANDLE hff;
int status, dir_count, file_count, entry_count, i, widest, linesout, cur_width, tmp_width; int status, dir_count, file_count, entry_count, i, widest, cur_width, tmp_width;
ULARGE_INTEGER byte_count, file_size; ULARGE_INTEGER byte_count, file_size;
dir_count = 0; dir_count = 0;
@ -141,7 +144,6 @@ ULARGE_INTEGER byte_count, file_size;
entry_count = 0; entry_count = 0;
byte_count.QuadPart = 0; byte_count.QuadPart = 0;
widest = 0; widest = 0;
linesout = 0;
cur_width = 0; cur_width = 0;
/* /*
@ -202,14 +204,6 @@ ULARGE_INTEGER byte_count, file_size;
if (!bare) { if (!bare) {
if (level != 0) WCMD_output ("\n\n"); if (level != 0) WCMD_output ("\n\n");
WCMD_output ("Directory of %s\n\n", real_path); WCMD_output ("Directory of %s\n\n", real_path);
if (page_mode) {
line_count += 2;
if (line_count > 23) {
line_count = 0;
WCMD_output (anykey);
ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
}
}
} }
for (i=0; i<entry_count; i++) { for (i=0; i<entry_count; i++) {
@ -224,9 +218,7 @@ ULARGE_INTEGER byte_count, file_size;
tmp_width = cur_width; tmp_width = cur_width;
if ((fd+i)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if ((fd+i)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
WCMD_output ("["); WCMD_output ("[%s]", (fd+i)->cFileName);
WCMD_output ("%s", (fd+i)->cFileName);
WCMD_output ("]");
dir_count++; dir_count++;
tmp_width = tmp_width + strlen((fd+i)->cFileName) + 2; tmp_width = tmp_width + strlen((fd+i)->cFileName) + 2;
} else { } else {
@ -247,7 +239,6 @@ ULARGE_INTEGER byte_count, file_size;
if ((cur_width + widest) > max_width) { if ((cur_width + widest) > max_width) {
WCMD_output ("\n"); WCMD_output ("\n");
cur_width = 0; cur_width = 0;
linesout++;
} else { } else {
WCMD_output ("%*.s", (tmp_width - cur_width) ,""); WCMD_output ("%*.s", (tmp_width - cur_width) ,"");
} }
@ -258,12 +249,10 @@ ULARGE_INTEGER byte_count, file_size;
if (!bare) { if (!bare) {
WCMD_output ("%10s %8s <DIR> %s\n", WCMD_output ("%10s %8s <DIR> %s\n",
datestring, timestring, (fd+i)->cFileName); datestring, timestring, (fd+i)->cFileName);
linesout++;
} else { } else {
if (!((strcmp((fd+i)->cFileName, ".") == 0) || if (!((strcmp((fd+i)->cFileName, ".") == 0) ||
(strcmp((fd+i)->cFileName, "..") == 0))) { (strcmp((fd+i)->cFileName, "..") == 0))) {
WCMD_output ("%s%s\n", recurse?real_path:"", (fd+i)->cFileName); WCMD_output ("%s%s\n", recurse?real_path:"", (fd+i)->cFileName);
linesout++;
} }
} }
} }
@ -281,32 +270,14 @@ ULARGE_INTEGER byte_count, file_size;
WCMD_output ("%10s %8s %10s %s\n", WCMD_output ("%10s %8s %10s %s\n",
datestring, timestring, datestring, timestring,
WCMD_filesize64(file_size.QuadPart), (fd+i)->cFileName); WCMD_filesize64(file_size.QuadPart), (fd+i)->cFileName);
linesout++;
} else { } else {
WCMD_output ("%s%s\n", recurse?real_path:"", (fd+i)->cFileName); WCMD_output ("%s%s\n", recurse?real_path:"", (fd+i)->cFileName);
linesout++;
}
}
if (page_mode) {
line_count = line_count + linesout;
linesout = 0;
if (line_count > 23) {
line_count = 0;
WCMD_output (anykey);
ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
} }
} }
} }
if (wide && cur_width>0) { if (wide && cur_width>0) {
WCMD_output ("\n"); WCMD_output ("\n");
if (page_mode) {
if (++line_count > 23) {
line_count = 0;
WCMD_output (anykey);
ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
}
}
} }
if (!bare) { if (!bare) {
@ -316,13 +287,6 @@ ULARGE_INTEGER byte_count, file_size;
else { else {
WCMD_output ("%8d files %24s bytes\n", file_count, WCMD_filesize64 (byte_count.QuadPart)); WCMD_output ("%8d files %24s bytes\n", file_count, WCMD_filesize64 (byte_count.QuadPart));
} }
if (page_mode) {
if (++line_count > 23) {
line_count = 0;
WCMD_output (anykey);
ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
}
}
} }
byte_total = byte_total + byte_count.QuadPart; byte_total = byte_total + byte_count.QuadPart;
file_total = file_total + file_count; file_total = file_total + file_count;
@ -331,13 +295,6 @@ ULARGE_INTEGER byte_count, file_size;
if (!bare) { if (!bare) {
if (dir_count == 1) WCMD_output ("1 directory "); if (dir_count == 1) WCMD_output ("1 directory ");
else WCMD_output ("%8d directories", dir_count); else WCMD_output ("%8d directories", dir_count);
if (page_mode) {
if (++line_count > 23) {
line_count = 0;
WCMD_output (anykey);
ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
}
}
} }
for (i=0; i<entry_count; i++) { for (i=0; i<entry_count; i++) {
if ((recurse) && if ((recurse) &&

View File

@ -40,10 +40,12 @@ void WCMD_create_dir (void);
void WCMD_delete (int recurse); void WCMD_delete (int recurse);
void WCMD_directory (void); void WCMD_directory (void);
void WCMD_echo (char *); void WCMD_echo (char *);
void WCMD_enter_paged_mode(void);
void WCMD_for (char *); void WCMD_for (char *);
void WCMD_give_help (char *command); void WCMD_give_help (char *command);
void WCMD_goto (void); void WCMD_goto (void);
void WCMD_if (char *); void WCMD_if (char *);
void WCMD_leave_paged_mode(void);
void WCMD_move (void); void WCMD_move (void);
void WCMD_output (char *format, ...); void WCMD_output (char *format, ...);
void WCMD_output_asis (char *message); void WCMD_output_asis (char *message);
@ -52,7 +54,7 @@ void WCMD_pause (void);
void WCMD_pipe (char *command); void WCMD_pipe (char *command);
void WCMD_print_error (void); void WCMD_print_error (void);
void WCMD_process_command (char *command); void WCMD_process_command (char *command);
int WCMD_read_console (char *string, int str_len); int WCMD_read_console (char *string, int str_len);
void WCMD_remove_dir (void); void WCMD_remove_dir (void);
void WCMD_rename (void); void WCMD_rename (void);
void WCMD_run_program (char *command); void WCMD_run_program (char *command);

View File

@ -587,12 +587,31 @@ void WCMD_output (char *format, ...) {
va_list ap; va_list ap;
char string[1024]; char string[1024];
DWORD count;
va_start(ap,format); va_start(ap,format);
vsprintf (string, format, ap); vsprintf (string, format, ap);
WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), string, lstrlen(string), &count, NULL);
va_end(ap); va_end(ap);
WCMD_output_asis(string);
}
static int line_count;
static int max_height;
static BOOL paged_mode;
void WCMD_enter_paged_mode(void)
{
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo);
max_height = consoleInfo.dwSize.Y;
paged_mode = TRUE;
line_count = 5; /* keep 5 lines from previous output */
}
void WCMD_leave_paged_mode(void)
{
paged_mode = FALSE;
} }
/******************************************************************* /*******************************************************************
@ -602,9 +621,26 @@ DWORD count;
void WCMD_output_asis (char *message) { void WCMD_output_asis (char *message) {
DWORD count; DWORD count;
WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), message, lstrlen(message), &count, NULL); char* ptr;
} char string[1024];
if (paged_mode) {
do {
if ((ptr = strchr(message, '\n')) != NULL) ptr++;
WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), message,
(ptr) ? ptr - message : lstrlen(message), &count, NULL);
if (ptr) {
if (++line_count >= max_height - 1) {
line_count = 0;
WCMD_output_asis (anykey);
ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
}
}
} while ((message = ptr) != NULL);
} else {
WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), message, lstrlen(message), &count, NULL);
}
}
/*************************************************************************** /***************************************************************************