[PATCH] CMD.EXE: Implement a basic 'more'

Jason Edmeades us at edmeades.me.uk
Fri Apr 13 15:34:05 CDT 2007


This implements a basic more, eg 'dir | more' or 'more file.c'
but it does not support the flags or keys which can control it.
Basically its not worth implementing those, as in some modes
we cannot read a single key, we have to wait for <enter> anyway.

If we find any application or user which needs any of the flags,
we can implement those at a later time.
---
 programs/cmd/Cs.rc       |    4 ++
 programs/cmd/De.rc       |    4 ++
 programs/cmd/En.rc       |    4 ++
 programs/cmd/Es.rc       |    4 ++
 programs/cmd/Fr.rc       |    4 ++
 programs/cmd/Ja.rc       |    4 ++
 programs/cmd/Ko.rc       |    4 ++
 programs/cmd/Nl.rc       |    4 ++
 programs/cmd/No.rc       |    4 ++
 programs/cmd/Pl.rc       |    4 ++
 programs/cmd/Pt.rc       |    7 +++
 programs/cmd/Ru.rc       |    4 ++
 programs/cmd/Si.rc       |    4 ++
 programs/cmd/Tr.rc       |    4 ++
 programs/cmd/builtins.c  |  109 ++++++++++++++++++++++++++++++++++++++++++++++
 programs/cmd/directory.c |    2 +-
 programs/cmd/wcmd.h      |    7 ++-
 programs/cmd/wcmdmain.c  |   14 ++++--
 18 files changed, 184 insertions(+), 7 deletions(-)

diff --git a/programs/cmd/Cs.rc b/programs/cmd/Cs.rc
index 83d01b2..5862a4a 100644
--- a/programs/cmd/Cs.rc
+++ b/programs/cmd/Cs.rc
@@ -199,6 +199,8 @@ Pøíznak verify nemá ve Wine žádnou funkci.\n"
 
   WCMD_VOL,    "Nápovìda k VOL\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT ukonèí bìžící sezení a vrátí kontrolu\n\
 operaènímu systému nebo pøíkazovému interpretu,\n\
@@ -217,6 +219,7 @@ DIR\t\tVypíše obsah adresáøe\n\
 ECHO\t\tVypíše text na terminál\n\
 HELP\t\tZobrazí detailní nápovìdu k tématu\n\
 MD (MKDIR)\tVytvoøí adresáø\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tPøesune soubor, skupinu souborù nebo adresáøový strom\n\
 PATH\t\tNastaví nebo ukáže prohledávané cesty\n\
 PROMPT\t\tZmìní výzvu pøíkazového øádku\n\
@@ -237,4 +240,5 @@ Zadejte HELP <pøíkaz> pro podrobnìjší informace o nìkterém z výše uvedených pøík
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/De.rc b/programs/cmd/De.rc
index b60cd2a..ab4d576 100644
--- a/programs/cmd/De.rc
+++ b/programs/cmd/De.rc
@@ -215,6 +215,8 @@ Das Verify Flag hat keine Funktion in Wine.\n"
 
   WCMD_VOL,    "Hilfe für VOL\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT beendet die aktuelle Befehlssitzung und kehrt zum\n\
 Betriebssystem oder der Shell zurück, von der CMD gestart wurde.\n"
@@ -233,6 +235,7 @@ DIR\t\tListet den Inhalt eines Verzeichnisses\n\
 ECHO\t\tKopiert den Text direkt zur Konsolenausgabe\n\
 HELP\t\tZeigt detalierte Informationen zu einen Thema\n\
 MD (MKDIR)\tErzeugt ein Unterverzeichnis\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tBewegt eine oder mehrere Dateien oder einen Verzeichnisbaum\n\
 PATH\t\tSetzt oder zeigt den Suchpfad an\n\
 PROMPT\t\tÄndert den Befehlszeilenprompt\n\
@@ -254,4 +257,5 @@ obigen Befehle erhalten.\n"
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/En.rc b/programs/cmd/En.rc
index 7fd28a6..4615def 100644
--- a/programs/cmd/En.rc
+++ b/programs/cmd/En.rc
@@ -202,6 +202,8 @@ stack, and then changes the current directory to the supplied one.\n"
   WCMD_POPD,   "POPD changes current directory to the last one saved with\n\
 PUSHD.\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT terminates the current command session and returns\n\
 to the operating system or shell from which you invoked cmd.\n"
@@ -219,6 +221,7 @@ DIR\t\tList the contents of a directory\n\
 ECHO\t\tCopy text directly to the console output\n\
 HELP\t\tShow brief help details on a topic\n\
 MD (MKDIR)\tCreate a subdirectory\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tMove a file, set of files or directory tree\n\
 PATH\t\tSet or show the search path\n\
 POPD\t\tRestores the directory to the last one saved with PUSHD\n\
@@ -241,4 +244,5 @@ Enter HELP <command> for further information on any of the above commands\n"
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/Es.rc b/programs/cmd/Es.rc
index 0933496..11cf009 100644
--- a/programs/cmd/Es.rc
+++ b/programs/cmd/Es.rc
@@ -212,6 +212,8 @@ La bandera de verificación no tiene funcionalidad en Wine.\n"
 
   WCMD_VOL,    "Ayuda sobre VOL\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT termina la sesión de comandos actual y regresa al sistema\n\
 operativo o intérprete de comandos desde el que invocó cmd.\n"
@@ -229,6 +231,7 @@ DIR\t\tListar el contenido de un directorio\n\
 ECHO\t\tCopiar texto directamente a la salida de consola\n\
 HELP\t\tMostrar detalles breves de ayuda sobre un tema\n\
 MD (MKDIR)\tCrear un subdirectorio\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tMover un archivo, conjunto de archivos o árbol de directorio\n\
 PATH\t\tAjustar o cambiar la ruta de búsqueda\n\
 PROMPT\t\tCambiar el prompt de comandos\n\
@@ -249,4 +252,5 @@ Introduzca HELP <comando> para más información sobre cualquiera de los comandos\
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/Fr.rc b/programs/cmd/Fr.rc
index 6897438..05098c7 100644
--- a/programs/cmd/Fr.rc
+++ b/programs/cmd/Fr.rc
@@ -194,6 +194,8 @@ Le flag de verification n'a pas de fonction dans Wine.\n"
 
   WCMD_VOL, "\t\tAffiche le nom de volume d'un lecteur de disque\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT termine la session de ligne de commande et retourne\n\
 au système d'exploitation ou au shell où vous avez invoqué cmd.\n"
@@ -211,6 +213,7 @@ DIR\t\tListe le contenu d'un répertoire\n\
 ECHO\t\tAffiche du texte sur la console\n\
 HELP\t\tAffiche de brefs détails sur l'utilisation d'une commande\n\
 MD (MKDIR)\tCrée un répertoire\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tDéplace un fichier, un groupe de fichiers ou un répertoire\n\
 PATH\t\tRègle ou affiche le chemin de recherche\n\
 PROMPT\t\tChange l'invite de commande\n\
@@ -231,4 +234,5 @@ Entrez HELP <commande> pour plus d'informations sur les commandes ci-dessus\n"
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/Ja.rc b/programs/cmd/Ja.rc
index f7435a6..d2a4eb2 100644
--- a/programs/cmd/Ja.rc
+++ b/programs/cmd/Ja.rc
@@ -199,6 +199,8 @@ WineŠÂ‹«‚Å‚Íverifyƒtƒ‰ƒO‚͈Ӗ¡‚ðŽ‚¿‚Ü‚¹‚ñB\n"
 
   WCMD_VOL,    "VOL‚̃wƒ‹ƒv\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT ‚ÍŒ»Ý‚̃Rƒ}ƒ“ƒhƒZƒbƒVƒ‡ƒ“‚ðI—¹‚µ‚Äcmd‚ðŒÄ‚яo‚µ‚½OS‚Ü‚½‚̓VƒFƒ‹‚É–ß‚µ‚Ü‚·B\n"
 
@@ -215,6 +217,7 @@ DIR\t\tƒfƒBƒŒƒNƒgƒŠ‚Ì“à—e‚ð•\Ž¦\n\
 ECHO\t\t•¶Žš—ñ‚𒼐ڃRƒ“ƒ\[ƒ‹o—͂ɃRƒs[\n\
 HELP\t\tƒgƒsƒbƒN‚̏ڍׂȃwƒ‹ƒv‚ð•\Ž¦\n\
 MD (MKDIR)\tƒTƒuƒfƒBƒŒƒNƒgƒŠ‚ðì¬\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tƒtƒ@ƒCƒ‹‚Ü‚½‚̓fƒBƒŒƒNƒgƒŠƒcƒŠ[‚ðˆÚ“®\n\
 PATH\t\tƒpƒX‚ð•\Ž¦–”‚͐ݒè\n\
 PROMPT\t\tƒRƒ}ƒ“ƒhƒvƒƒ“ƒvƒg‚ð•ÏX\n\
@@ -235,4 +238,5 @@ EXIT\t\tCMD‚ðI—¹\n\n\
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/Ko.rc b/programs/cmd/Ko.rc
index 0a5b2fd..0bd6958 100644
--- a/programs/cmd/Ko.rc
+++ b/programs/cmd/Ko.rc
@@ -194,6 +194,8 @@ verify Ç÷¡±×´Â Wine¿¡¼­´Â ¾î¶² Àϵµ ¾ÈÇÕ´Ï´Ù.\n"
 
   WCMD_POPD,   "POPD´Â ÇöÀç µð·ºÅ丮¸¦ PUSH·Î ¸¶Áö¸·À¸·Î ÀúÀåÇß´ø °ÍÀ¸·Î ¹Ù²Û´Ù.\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT´Â ÇöÀç ¸í·É ¼¼¼ÇÀ» ÁߴܽÃÅ°°í ¿î¿µÃ¼Á¦·Î µ¹¾Æ°¡°Å³ª cmd¸¦\n\
 È£ÃâÇÑ ¼¿·Î µ¹¾Æ°©´Ï´Ù.\n"
@@ -211,6 +213,7 @@ DIR\t\tµð·ºÅ丮 ³»¿ë º¸¿©ÁÖ±â\n\
 ECHO\t\t¹®ÀÚ¸¦ ¹Ù·Î È­¸é Ãâ·ÂÀ¸·Î º¹»ç\n\
 HELP\t\t ¸ñÂ÷ÀÇ Â©¸·ÇÑ µµ¿ò¸» Ç׸ñ º¸¿©ÁÜ\n\
 MD (MKDIR)\tÇÏÀ§ µð·ºÅ丮 ¸¸µé±â\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tÆÄÀÏ À̳ª ¿©·¯ ÆÄÀÏ,±×¸®°í µð·ºÅ丮 ±¸Á¶ À̵¿\n\
 PATH\t\tŽ»ö °æ·Î º¸¿©Áְųª ¼³Á¤Çϱâ\n\
 POPD\t\tPUSHD·Î ¸¶Áö¸·À¸·Î ÀúÀåÇß´ø µð·ºÅ丮·Î µ¹¾Æ°¡±â\n\
@@ -233,4 +236,5 @@ HELP <¸í·É>À» Ä¡¸é ±× ¸í·ÉÀÇ »ó¼¼ÇÑ Á¤º¸¸¦ º¸¿©ÁÜ\n"
   WCMD_NOASSOC, "ÀÌ ÆÄÀÏÈ®ÀåÀÚ %s¿¡ ¿¬°áµÈ Ç®±×¸²ÀÌ ¾ø½À´Ï´Ù. \n"
   WCMD_NOFTYPE, "ÀÌ ÆÄÀÏ Çü½Ä '%s'°ú ¿¬°áµÈ ¾î¶°ÇÑ ¸í·Éµµ ¾ø½À´Ï´Ù.'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/Nl.rc b/programs/cmd/Nl.rc
index ef6c7e2..3dc765e 100644
--- a/programs/cmd/Nl.rc
+++ b/programs/cmd/Nl.rc
@@ -197,6 +197,8 @@ De verify-schakelaar heeft geen functie binnen Wine.\n"
 
   WCMD_VOL,    "Uitleg bij VOL\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT beëindigt de lopende sessie en keert terug\n\
 naar het besturingssysteem of de schil van waaruit cmd werd gestart.\n"
@@ -214,6 +216,7 @@ DIR\t\tToon de inhoud van een directory\n\
 ECHO\t\tKopiëer tekst direct naar het uitvoerapparaat\n\
 HELP\t\tToon een korte uitleg over een onderwerp\n\
 MD (MKDIR)\tMaak een directory\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tVerplaats een bestand, een verzameling bestanden of een directory\n\
 PATH\t\tWijzig of toon het zoekpad\n\
 PROMPT\t\tWijzig de prompt\n\
@@ -234,4 +237,5 @@ type HELP <opdracht> voor meer informatie over bovengenoemde opdrachten\n"
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/No.rc b/programs/cmd/No.rc
index 87e84d2..72f084e 100644
--- a/programs/cmd/No.rc
+++ b/programs/cmd/No.rc
@@ -195,6 +195,8 @@ VERIFY		Viser ON hvis på ellerr OFF hvis av.\n\
 
   WCMD_VOL,    "Hjelp til VOL\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT avslutter gjeldende kommandoøkt og returnerer til operativsystemet\n\
 eller skallet CMD ble startet fra.\n"
@@ -212,6 +214,7 @@ DIR\t\tViser innholdet i en katalgo\n\
 ECHO\t\tKopierer tekst direkte til konsoll-utdataen\n\
 HELP\t\tViser en kort hjelpebeskrivelse om et emne\n\
 MD (MKDIR)\tLager en underkatalog\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tFlytter en eller flere filer, eller en katalogtre\n\
 PATH\t\tEndrer eller viser søkestien\n\
 PROMPT\t\tEndrer kommando-klartegnet\n\
@@ -232,4 +235,5 @@ Skriv «HELP <kommando>» for mer informasjon om kommandoene ovenfor\n"
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/Pl.rc b/programs/cmd/Pl.rc
index 59afcf0..3199d92 100644
--- a/programs/cmd/Pl.rc
+++ b/programs/cmd/Pl.rc
@@ -197,6 +197,8 @@ Ustawienia flagi nic nie zmieniaj¹ pod Wine'em.\n"
   WCMD_POPD, "POPD ustala aktualny katalog na ostatni katalog zapamiêtany przez\n\
               PUSHD\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT koñczy bierz¹c¹ sesjê cmd i powraca do systemu operacyjnego\n\
 lub pow³oki, w której uruchomiono cmd.\n"
@@ -214,6 +216,7 @@ DIR\t\tWyœwietla zawartoœæ katalogu\n\
 ECHO\t\tKopiuje tekst na wyjœcie konsoli\n\
 HELP\t\tWyœwietla dok³adniejsz¹ pomoc o komendzie\n\
 MD (MKDIR)\tTworzy katalog\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tPrzenosi katalog lub pliki\n\
 PATH\t\tUstawia lub wyœwietla œcie¿kê przeszukiwania\n\
 POPD\t\tWraca do katalogu zapamiêtanego przez PUSHD\n\
@@ -236,4 +239,5 @@ Wpisz HELP <komenda> dla dok³adniejszych informacji o komendzie\n"
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/Pt.rc b/programs/cmd/Pt.rc
index 3c9809f..7bf7696 100644
--- a/programs/cmd/Pt.rc
+++ b/programs/cmd/Pt.rc
@@ -196,6 +196,8 @@ O flag de verificação não tem função no Wine.\n"
 
   WCMD_VOL,    "Ajuda do comando VOL\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT termina a sessão de comando atual e retorna ao sistema operacional\n\
 ou shell que tenha invocado o cmd.\n"
@@ -213,6 +215,7 @@ DIR\t\tMostra o conteúdo de um diretórios\n\
 ECHO\t\tCopia texto diretamente na saída do console\n\
 HELP\t\tMostra breves detalhes de um tópico\n\
 MD (MKDIR)\tCria um subdiretório\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tMove um arquivo, conjunto de arquivos ou uma árvore de diretórios\n\
 PATH\t\tConfigira o caminho de procura\n\
 PROMPT\t\tMuda o 'prompt' de comando\n\
@@ -404,6 +407,8 @@ O flag de verificação não tem função no Wine.\n"
 
   WCMD_VOL,    "Ajuda do comando VOL\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT termina a sessão de comando actual e retorna ao sistema operacional\n\
 ou shell que tenha invocado o cmd.\n"
@@ -421,6 +426,7 @@ DIR\t\tMostra o conteúdo de um directório\n\
 ECHO\t\tCopia o texto diretamente na saída da consola\n\
 HELP\t\tMostra breves detalhes de um tópico\n\
 MD (MKDIR)\tCria um subdirectório\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tMove um ficheiro, conjunto de ficheiros ou uma árvore de directórios\n\
 PATH\t\tConfigura o caminho de procura\n\
 PROMPT\t\tMuda a 'prompt' de comando\n\
@@ -441,4 +447,5 @@ Digite HELP <comando> para mais informações sobre alguns dos comandos acima\n"
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/Ru.rc b/programs/cmd/Ru.rc
index 781aa26..a60803e 100644
--- a/programs/cmd/Ru.rc
+++ b/programs/cmd/Ru.rc
@@ -208,6 +208,8 @@ stack, and then changes the current directory to the supplied one.\n"
   WCMD_POPD,   "POPD changes current directory to the last one saved with\n\
 PUSHD.\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT çàâåðøàåò òåêóùóþ êîìàíäíóþ ñåññèþ è âîçâðàùàåò\n\
 â îïåðàöèîííóþ ñèñòåìó èëè îáîëî÷êó èç êîòîðîé áûë çàïóùåí cmd.\n"
@@ -225,6 +227,7 @@ DIR\t\tÏîêàçàòü ñîäåðæàíèå ïàïêè\n\
 ECHO\t\tÑêîïèðîâàòü òåêñò ïðÿìî íà âûõîä êîíñîëè\n\
 HELP\t\tÏîêàçàòü êðàäêóþ ïîäñêàçêó ïî êîìàíäå\n\
 MD (MKDIR)\tÑîçäàòü ïàïêó\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tÏåðåìåñòèòü ôàéë, íàáîð ôàéëîâ èëè äåðåâî ïàïîê\n\
 PATH\t\tÏîêàçàòü èëè èçìåíèòü ïóòü ïîèñêà ïðîãðàìì\n\
 POPD\t\tRestores the directory to the last one saved with PUSHD\n\
@@ -247,4 +250,5 @@ EXIT\t\tÂûéòè èç CMD\n\n\
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/Si.rc b/programs/cmd/Si.rc
index f70c915..1048dac 100644
--- a/programs/cmd/Si.rc
+++ b/programs/cmd/Si.rc
@@ -196,6 +196,8 @@ The verify flag has no function in Wine.\n"
 
   WCMD_VOL,    "Help about VOL\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT terminates the current command session and returns\n\
 to the operating system or shell from which you invoked cmd.\n"
@@ -213,6 +215,7 @@ DIR\t\tList the contents of a directory\n\
 ECHO\t\tCopy text directly to the console output\n\
 HELP\t\tShow brief help details on a topic\n\
 MD (MKDIR)\tCreate a subdirectory\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tMove a file, set of files or directory tree\n\
 PATH\t\tSet or show the search path\n\
 PROMPT\t\tChange the command prompt\n\
@@ -233,4 +236,5 @@ Enter HELP <command> for further information on any of the above commands\n"
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/Tr.rc b/programs/cmd/Tr.rc
index 8b4820b..78dad37 100644
--- a/programs/cmd/Tr.rc
+++ b/programs/cmd/Tr.rc
@@ -198,6 +198,8 @@ Doðrulama bayraðýnýn Wine'da bir iþlevi yoktur.\n"
 
   WCMD_VOL,    "VOL hakkýnda yardým\n"
 
+  WCMD_MORE,   "MORE displays output of files or piped input in pages.\n"
+  
   WCMD_EXIT,
 "EXIT geçerli komut oturumunu sonlandýrýr ve cmd'yi çaðýrdýðýnýz\n\
 yerden iþletim sistemine döner.\n"
@@ -215,6 +217,7 @@ DIR\t\tDizin içeriðini listele\n\
 ECHO\t\tMetni doðrudan konsol çýkýþýna kopyala\n\
 HELP\t\tBir konu üzerinde özet yardým göster\n\
 MD (MKDIR)\tAlt dizin oluþtur\n\
+MORE\t\tDisplay output in pages\n\
 MOVE\t\tBir veya daha fazla dosyayý ya da dizin aðacýný taþý\n\
 PATH\t\tArama yolunu düzenle veya göster\n\
 PROMPT\t\tKomut istemini deðiþtir\n\
@@ -235,4 +238,5 @@ Yukarýdaki komutlar hakkýnda daha fazla bilgi için HELP <komut> girin\n"
   WCMD_NOASSOC, "File association missing for extension %s\n"
   WCMD_NOFTYPE, "No open command associated with file type '%s'\n"
   WCMD_OVERWRITE, "Overwrite"
+  WCMD_MORESTR, "More..."
 }
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 3d4f034..fc15c16 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1689,6 +1689,115 @@ void WCMD_type (char *command) {
 }
 
 /****************************************************************************
+ * WCMD_more
+ *
+ * Output either a file or stdin to screen in pages
+ */
+
+void WCMD_more (char *command) {
+
+  int   argno         = 0;
+  char *argN          = command;
+  BOOL  useinput      = FALSE;
+  char  moreStr[100];
+  char  moreStrPage[100];
+  char  buffer[512];
+  DWORD count;
+
+  /* Prefix the NLS more with '-- ', then load the text */
+  errorlevel = 0;
+  strcpy(moreStr, "-- ");
+  LoadString (hinst, WCMD_MORESTR, &moreStr[3], sizeof(moreStr)-3);
+
+  if (param1[0] == 0x00) {
+
+    /* Wine implements pipes via temporary files, and hence stdin is
+       effectively reading from the file. This means the prompts for
+       more are satistied by the next line from the input (file). To
+       avoid this, ensure stdin is to the console                    */
+    HANDLE hstdin  = GetStdHandle(STD_INPUT_HANDLE);
+    HANDLE hConIn = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
+                         FILE_SHARE_READ, NULL, OPEN_EXISTING,
+                         FILE_ATTRIBUTE_NORMAL, 0);
+    SetStdHandle(STD_INPUT_HANDLE, hConIn);
+
+    /* Warning: No easy way of ending the stream (ctrl+z on windows) so
+       once you get in this bit unless due to a pipe, its going to end badly...  */
+    useinput = TRUE;
+    sprintf(moreStrPage, "%s --\n", moreStr);
+
+    WCMD_enter_paged_mode(moreStrPage);
+    while (ReadFile (hstdin, buffer, sizeof(buffer)-1, &count, NULL)) {
+      if (count == 0) break;	/* ReadFile reports success on EOF! */
+      buffer[count] = 0;
+      WCMD_output_asis (buffer);
+    }
+    WCMD_leave_paged_mode();
+
+    /* Restore stdin to what it was */
+    SetStdHandle(STD_INPUT_HANDLE, hstdin);
+    CloseHandle(hConIn);
+
+    return;
+  } else {
+    BOOL needsPause = FALSE;
+
+    /* Loop through all args */
+    WCMD_enter_paged_mode(moreStrPage);
+    
+    while (argN) {
+      char *thisArg = WCMD_parameter (command, argno++, &argN);
+      HANDLE h;
+
+      if (!argN) break;
+
+      if (needsPause) {
+        
+        /* Wait */
+        sprintf(moreStrPage, "%s (100%%) --\n", moreStr);
+        WCMD_leave_paged_mode();
+        WCMD_output_asis(moreStrPage);
+        ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer), &count, NULL);
+        WCMD_enter_paged_mode(moreStrPage);
+      }
+
+
+      WINE_TRACE("more: Processing arg '%s'\n", thisArg);
+      h = CreateFile (thisArg, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
+          	FILE_ATTRIBUTE_NORMAL, NULL);
+      if (h == INVALID_HANDLE_VALUE) {
+        WCMD_print_error ();
+        WCMD_output ("%s :Failed\n", thisArg);
+        errorlevel = 1;
+      } else {
+        ULONG64 curPos  = 0;
+        ULONG64 fileLen = 0;
+        WIN32_FILE_ATTRIBUTE_DATA   fileInfo;
+
+        /* Get the file size */
+        GetFileAttributesEx(thisArg, GetFileExInfoStandard, (void*)&fileInfo);
+        fileLen = (((ULONG64)fileInfo.nFileSizeHigh) << 32) + fileInfo.nFileSizeLow;
+
+        needsPause = TRUE;
+        while (ReadFile (h, buffer, sizeof(buffer), &count, NULL)) {
+          if (count == 0) break;	/* ReadFile reports success on EOF! */
+          buffer[count] = 0;
+          curPos += count;
+
+          /* Update % count (would be used in WCMD_output_asis as prompt) */
+          sprintf(moreStrPage, "%s (%2.2d%%) --\n", moreStr, (int) min(99, (curPos * 100)/fileLen));
+
+          WCMD_output_asis (buffer);
+        }
+        CloseHandle (h);
+      }
+    }
+
+    WCMD_leave_paged_mode();
+  }
+}
+
+/****************************************************************************
  * WCMD_verify
  *
  * Display verify flag.
diff --git a/programs/cmd/directory.c b/programs/cmd/directory.c
index ac1e59d..801d59d 100644
--- a/programs/cmd/directory.c
+++ b/programs/cmd/directory.c
@@ -277,7 +277,7 @@ void WCMD_directory (char *cmd) {
           max_width = 80;
   }
   if (paged_mode) {
-     WCMD_enter_paged_mode();
+     WCMD_enter_paged_mode(NULL);
   }
 
   argno         = 0;
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index 2873ea2..a6deef4 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -39,13 +39,14 @@ void WCMD_delete (char *);
 void WCMD_directory (char *);
 void WCMD_echo (const char *);
 void WCMD_endlocal (void);
-void WCMD_enter_paged_mode(void);
+void WCMD_enter_paged_mode(char *);
 void WCMD_exit (void);
 void WCMD_for (char *);
 void WCMD_give_help (char *command);
 void WCMD_goto (void);
 void WCMD_if (char *);
 void WCMD_leave_paged_mode(void);
+void WCMD_more (char *);
 void WCMD_move (void);
 void WCMD_output (const char *format, ...);
 void WCMD_output_asis (const char *message);
@@ -163,9 +164,10 @@ struct env_stack
 #define WCMD_ASSOC  40
 #define WCMD_COLOR  41
 #define WCMD_FTYPE  42
+#define WCMD_MORE   43
 
 /* Must be last in list */
-#define WCMD_EXIT   43
+#define WCMD_EXIT   44
 
 /* Some standard messages */
 extern const char nyi[];
@@ -180,6 +182,7 @@ extern const char anykey[];
 #define WCMD_NOASSOC  1004
 #define WCMD_NOFTYPE  1005
 #define WCMD_OVERWRITE 1006
+#define WCMD_MORESTR  1007
 
 /* msdn specified max for Win XP */
 #define MAXSTRING 8192
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 5ef6ef6..fcbf77e 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -36,7 +36,7 @@ const char * const inbuilt[] = {"ATTRIB", "CALL", "CD", "CHDIR", "CLS", "COPY",
 		"PROMPT", "REM", "REN", "RENAME", "RD", "RMDIR", "SET", "SHIFT",
                 "TIME", "TITLE", "TYPE", "VERIFY", "VER", "VOL",
                 "ENDLOCAL", "SETLOCAL", "PUSHD", "POPD", "ASSOC", "COLOR", "FTYPE",
-                "EXIT" };
+                "MORE", "EXIT" };
 
 HINSTANCE hinst;
 DWORD errorlevel;
@@ -49,6 +49,7 @@ const char anykey[] = "Press Return key to continue: ";
 char quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH];
 BATCH_CONTEXT *context = NULL;
 extern struct env_stack *pushd_directories;
+static char *pagedMessage = NULL;
 
 static char *WCMD_expand_envvar(char *start);
 
@@ -714,6 +715,9 @@ void WCMD_process_command (char *command)
       case WCMD_FTYPE:
         WCMD_assoc(p, FALSE);
         break;
+      case WCMD_MORE:
+        WCMD_more(p);
+        break;
       case WCMD_EXIT:
         WCMD_exit ();
         break;
@@ -1215,7 +1219,7 @@ static int line_count;
 static int max_height;
 static BOOL paged_mode;
 
-void WCMD_enter_paged_mode(void)
+void WCMD_enter_paged_mode(char *msg)
 {
   CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
 
@@ -1224,12 +1228,14 @@ void WCMD_enter_paged_mode(void)
   else
     max_height = 25;
   paged_mode = TRUE;
-  line_count = 5; /* keep 5 lines from previous output */
+  line_count = 0;
+  pagedMessage = (msg==NULL)?(char *)anykey:msg;
 }
 
 void WCMD_leave_paged_mode(void)
 {
   paged_mode = FALSE;
+  pagedMessage = NULL;
 }
 
 /*******************************************************************
@@ -1250,7 +1256,7 @@ void WCMD_output_asis (const char *message) {
       if (ptr) {
         if (++line_count >= max_height - 1) {
           line_count = 0;
-          WCMD_output_asis (anykey);
+          WCMD_output_asis (pagedMessage);
           ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string), &count, NULL);
         }
       }
-- 
1.5.0




More information about the wine-patches mailing list