- Simplify CommandColor and document it. Checking whether one sets the same color for both foreground and background is now only checked inside SetScreenColor.
Based on a patch by Victor
CORE-7191 #resolve #comment Committed in rev.59055.

- Fix handling of /T:<color> option when starting cmd.exe
- Remove unneeded error string.

svn path=/trunk/; revision=59055
This commit is contained in:
Hermès Bélusca-Maïto 2013-05-20 17:43:37 +00:00
parent b7693777d9
commit f22dffe66a
22 changed files with 144 additions and 167 deletions

View file

@ -1733,9 +1733,9 @@ Initialize()
#ifdef INCLUDE_CMD_COLOR #ifdef INCLUDE_CMD_COLOR
else if (!_tcsnicmp(ptr, _T("/T:"), 3)) else if (!_tcsnicmp(ptr, _T("/T:"), 3))
{ {
/* process /t (color) argument */ /* process /T (color) argument */
wDefColor = (WORD)_tcstoul(&ptr[3], &ptr, 16); wDefColor = (WORD)_tcstoul(&ptr[3], &ptr, 16);
SetScreenColor(wDefColor, TRUE); SetScreenColor(wDefColor, FALSE);
} }
#endif #endif
else if (option == _T('U')) else if (option == _T('U'))

View file

@ -144,7 +144,7 @@ VOID PrintCommandListDetail (VOID);
LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA ); LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA );
/* Prototypes for COLOR.C */ /* Prototypes for COLOR.C */
VOID SetScreenColor(WORD wArgColor, BOOL bFill); BOOL SetScreenColor(WORD wColor, BOOL bNoFill);
INT CommandColor (LPTSTR); INT CommandColor (LPTSTR);
VOID ConInDummy (VOID); VOID ConInDummy (VOID);

View file

@ -24,34 +24,34 @@
#ifdef INCLUDE_CMD_COLOR #ifdef INCLUDE_CMD_COLOR
VOID SetScreenColor (WORD wColor, BOOL bNoFill) BOOL SetScreenColor(WORD wColor, BOOL bNoFill)
{ {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwWritten; DWORD dwWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
COORD coPos; COORD coPos;
/* Foreground and Background colors can't be the same */
if ((wColor & 0x0F) == (wColor & 0xF0) >> 4)
return FALSE;
if ((wColor & 0xF) == (wColor &0xF0) >> 4) /* Fill the whole background if needed */
if (bNoFill != TRUE)
{ {
ConErrResPuts(STRING_COLOR_ERROR1); GetConsoleScreenBufferInfo(hConsole, &csbi);
}
else
{
if (bNoFill != TRUE)
{
GetConsoleScreenBufferInfo (hConsole, &csbi);
coPos.X = 0; coPos.X = 0;
coPos.Y = 0; coPos.Y = 0;
FillConsoleOutputAttribute (hConsole, FillConsoleOutputAttribute(hConsole,
(WORD)(wColor & 0x00FF), wColor & 0x00FF,
(csbi.dwSize.X)*(csbi.dwSize.Y), csbi.dwSize.X * csbi.dwSize.Y,
coPos, coPos,
&dwWritten); &dwWritten);
}
SetConsoleTextAttribute (hConsole, (WORD)(wColor & 0x00FF));
} }
/* Set the text attribute */
SetConsoleTextAttribute(hConsole, wColor & 0x00FF);
return TRUE;
} }
/* /*
@ -59,73 +59,77 @@ VOID SetScreenColor (WORD wColor, BOOL bNoFill)
* *
* internal dir command * internal dir command
*/ */
INT CommandColor (LPTSTR rest) INT CommandColor(LPTSTR rest)
{ {
WORD wColor; WORD wColor = 0x00;
if (_tcsncmp (rest, _T("/?"), 2) == 0) /* The user asked for help */
if (_tcsncmp(rest, _T("/?"), 2) == 0)
{ {
ConOutResPaging(TRUE,STRING_COLOR_HELP1); ConOutResPaging(TRUE, STRING_COLOR_HELP1);
return 0; return 0;
} }
/* Let's prepare %ERRORLEVEL% */
nErrorLevel = 0; nErrorLevel = 0;
/* No parameter. Set the default colors */
if (rest[0] == _T('\0')) if (rest[0] == _T('\0'))
{ {
/* set default color */ SetScreenColor(wDefColor, FALSE);
wColor = wDefColor;
SetScreenColor (wColor, FALSE);
return 0; return 0;
} }
/* The parameter is just one character: Set color text */
if ( _tcslen(&rest[0])==1) if (_tcslen(rest) == 1)
{ {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); if ((rest[0] >= _T('0')) && (rest[0] <= _T('9')))
if ( (_tcscmp(&rest[0], _T("0")) >=0 ) && (_tcscmp(&rest[0], _T("9")) <=0 ) ) {
{ wColor = (WORD)_ttoi(rest);
SetConsoleTextAttribute (hConsole, (WORD)_ttoi(rest)); }
return 0; else if ((rest[0] >= _T('a')) && (rest[0] <= _T('f')))
} {
else if ( (_tcscmp(&rest[0], _T("a")) >=0 ) && (_tcscmp(&rest[0], _T("f")) <=0 ) ) wColor = (WORD)(rest[0] + 10 - _T('a'));
{ }
SetConsoleTextAttribute (hConsole, (WORD) (rest[0] + 10 - _T('a')) ); else if ((rest[0] >= _T('A')) && (rest[0] <= _T('F')))
return 0; {
} wColor = (WORD)(rest[0] + 10 - _T('A'));
else if ( (_tcscmp(&rest[0], _T("A")) >=0 ) && (_tcscmp(&rest[0], _T("F")) <=0 ) ) }
{ else /* Invalid character */
SetConsoleTextAttribute (hConsole, (WORD) (rest[0] + 10 - _T('A')) ); {
return 0; ConOutResPaging(TRUE, STRING_COLOR_HELP1);
} nErrorLevel = 1;
ConErrResPuts(STRING_COLOR_ERROR2); return 1;
nErrorLevel = 1; }
return 1;
} }
/* Color string: advanced choice: two-digits, "Color ON Color" , "Foreground ON Background" */
if (StringToColor(&wColor, &rest) == FALSE) else if (StringToColor(&wColor, &rest) == FALSE)
{ {
ConErrResPuts(STRING_COLOR_ERROR2); /* Invalid color string */
ConOutResPaging(TRUE, STRING_COLOR_HELP1);
nErrorLevel = 1; nErrorLevel = 1;
return 1; return 1;
} }
if (((bc) && (bc->bEcho)) || !bc) /* Print the chosen color if we are in echo mode (NOTE: Not Windows-compliant) */
if ((bc && bc->bEcho) || !bc)
{ {
ConErrResPrintf(STRING_COLOR_ERROR3, wColor); ConErrResPrintf(STRING_COLOR_ERROR3, wColor);
} }
if ((wColor & 0xF) == (wColor &0xF0) >> 4) /*
* Set the chosen color. Use also the following advanced flag:
* /-F to avoid changing already buffered foreground/background.
*/
if (SetScreenColor(wColor, (_tcsstr(rest, _T("/-F")) || _tcsstr(rest, _T("/-f")))) == FALSE)
{ {
ConErrResPrintf(STRING_COLOR_ERROR4, wColor); /* Failed because foreground and background colors were the same */
ConErrResPuts(STRING_COLOR_ERROR1);
nErrorLevel = 1; nErrorLevel = 1;
return 1; return 1;
} }
/* set color */ /* Return success */
SetScreenColor(wColor,
(_tcsstr (rest,_T("/-F")) || _tcsstr (rest,_T("/-f"))));
return 0; return 0;
} }

View file

@ -634,7 +634,6 @@ STRING_CMD_ERROR5, "Ausführend cmdexit.bat...\n"
STRING_COLOR_ERROR1, "Fehler: Hinter- und Vordergrund können nicht die selben Farben haben!" STRING_COLOR_ERROR1, "Fehler: Hinter- und Vordergrund können nicht die selben Farben haben!"
STRING_COLOR_ERROR2, "Fehler in der Farbangabe" STRING_COLOR_ERROR2, "Fehler in der Farbangabe"
STRING_COLOR_ERROR3, "Farbe %x\n" STRING_COLOR_ERROR3, "Farbe %x\n"
STRING_COLOR_ERROR4, "Fehler: Die selben Farben!"
STRING_CONSOLE_ERROR, "Unbekannter Fehler: %d\n" STRING_CONSOLE_ERROR, "Unbekannter Fehler: %d\n"
STRING_COPY_ERROR1, "Fehler: Quelle kann nicht geöffnet werden - %s!\n" STRING_COPY_ERROR1, "Fehler: Quelle kann nicht geöffnet werden - %s!\n"
STRING_COPY_ERROR2, "Fehler: Kann nicht über sich selbst kopiert werden.\n" STRING_COPY_ERROR2, "Fehler: Kann nicht über sich selbst kopiert werden.\n"

View file

@ -634,7 +634,6 @@ STRING_CMD_ERROR5, "Running cmdexit.bat...\n"
STRING_COLOR_ERROR1, "Same colors error! (Background and foreground can't be the same color)" STRING_COLOR_ERROR1, "Same colors error! (Background and foreground can't be the same color)"
STRING_COLOR_ERROR2, "error in color specification" STRING_COLOR_ERROR2, "error in color specification"
STRING_COLOR_ERROR3, "Color %x\n" STRING_COLOR_ERROR3, "Color %x\n"
STRING_COLOR_ERROR4, "same colors error!"
STRING_CONSOLE_ERROR, "Άγνωστο σφάλμα: %d\n" STRING_CONSOLE_ERROR, "Άγνωστο σφάλμα: %d\n"
STRING_COPY_ERROR1, "Σφάλμα: Δεν ήταν δυνατό το άνοιγμα της πηγής - %s!\n" STRING_COPY_ERROR1, "Σφάλμα: Δεν ήταν δυνατό το άνοιγμα της πηγής - %s!\n"
STRING_COPY_ERROR2, "Σφάλμα: Can't copy onto itself!\n" STRING_COPY_ERROR2, "Σφάλμα: Can't copy onto itself!\n"

View file

@ -637,7 +637,6 @@ STRING_CMD_ERROR5, "Running cmdexit.bat...\n"
STRING_COLOR_ERROR1, "Same colors error! (Background and foreground can't be the same color)" STRING_COLOR_ERROR1, "Same colors error! (Background and foreground can't be the same color)"
STRING_COLOR_ERROR2, "error in color specification" STRING_COLOR_ERROR2, "error in color specification"
STRING_COLOR_ERROR3, "Color %x\n" STRING_COLOR_ERROR3, "Color %x\n"
STRING_COLOR_ERROR4, "same colors error!"
STRING_CONSOLE_ERROR, "Unknown error: %d\n" STRING_CONSOLE_ERROR, "Unknown error: %d\n"
STRING_COPY_ERROR1, "Error: Cannot open source - %s!\n" STRING_COPY_ERROR1, "Error: Cannot open source - %s!\n"
STRING_COPY_ERROR2, "Error: Can't copy onto itself!\n" STRING_COPY_ERROR2, "Error: Can't copy onto itself!\n"

View file

@ -637,7 +637,6 @@ STRING_CMD_ERROR5, "Ejecutando cmdexit.bat...\n"
STRING_COLOR_ERROR1, "¡Mismos colores! (El color de frente y de fondo no pueden ser el mismo)" STRING_COLOR_ERROR1, "¡Mismos colores! (El color de frente y de fondo no pueden ser el mismo)"
STRING_COLOR_ERROR2, "Error en la especificación del color" STRING_COLOR_ERROR2, "Error en la especificación del color"
STRING_COLOR_ERROR3, "Color %x\n" STRING_COLOR_ERROR3, "Color %x\n"
STRING_COLOR_ERROR4, "¡Error: mismos colores!"
STRING_CONSOLE_ERROR, "Error desconocido: %d\n" STRING_CONSOLE_ERROR, "Error desconocido: %d\n"
STRING_COPY_ERROR1, "Error: No se puede abrir el origen - %s!\n" STRING_COPY_ERROR1, "Error: No se puede abrir el origen - %s!\n"
STRING_COPY_ERROR2, "Error: ¡No se puede copiar sobre si mismo!\n" STRING_COPY_ERROR2, "Error: ¡No se puede copiar sobre si mismo!\n"

View file

@ -652,7 +652,6 @@ STRING_CMD_ERROR5, "Lance cmdexit.bat...\n"
STRING_COLOR_ERROR1, "L'arrière plan et l'avant plan ne peuvent être de la même couleur" STRING_COLOR_ERROR1, "L'arrière plan et l'avant plan ne peuvent être de la même couleur"
STRING_COLOR_ERROR2, "Erreur dans la spécification des couleurs" STRING_COLOR_ERROR2, "Erreur dans la spécification des couleurs"
STRING_COLOR_ERROR3, "Couleur %x\n" STRING_COLOR_ERROR3, "Couleur %x\n"
STRING_COLOR_ERROR4, "Erreur : même couleur!"
STRING_CONSOLE_ERROR, "Erreur inconnue : %d\n" STRING_CONSOLE_ERROR, "Erreur inconnue : %d\n"
STRING_COPY_ERROR1, "Erreur : Ne peut ouvrir la source - %s !\n" STRING_COPY_ERROR1, "Erreur : Ne peut ouvrir la source - %s !\n"
STRING_COPY_ERROR2, "Erreur : Ne peut copier le fichier sur lui-même !\n" STRING_COPY_ERROR2, "Erreur : Ne peut copier le fichier sur lui-même !\n"

View file

@ -616,7 +616,6 @@ STRING_CMD_ERROR5, "cmdexit.bat futtatása...\n"
STRING_COLOR_ERROR1, "Ugyanaz a szín nem lehet! (Az elõ- és háttérszín nem lehet ugyanolyan)" STRING_COLOR_ERROR1, "Ugyanaz a szín nem lehet! (Az elõ- és háttérszín nem lehet ugyanolyan)"
STRING_COLOR_ERROR2, "Hibás szín megadás" STRING_COLOR_ERROR2, "Hibás szín megadás"
STRING_COLOR_ERROR3, "Szín %x\n" STRING_COLOR_ERROR3, "Szín %x\n"
STRING_COLOR_ERROR4, "Ugyanaz a szín nem lehet!"
STRING_CONSOLE_ERROR, "Ismeretlen hiba: %d\n" STRING_CONSOLE_ERROR, "Ismeretlen hiba: %d\n"
STRING_COPY_ERROR1, "Hiba: a forrás nem nyitható meg - %s!\n" STRING_COPY_ERROR1, "Hiba: a forrás nem nyitható meg - %s!\n"
STRING_COPY_ERROR2, "Hiba: nem másolhatod önmagára az állományt!\n" STRING_COPY_ERROR2, "Hiba: nem másolhatod önmagára az állományt!\n"

View file

@ -636,7 +636,6 @@ STRING_CMD_ERROR5, "Menjalankan cmdexit.bat...\n"
STRING_COLOR_ERROR1, "Warna sama salah! (Latar belakang dan latar depan tidak bisa berwarna sama)" STRING_COLOR_ERROR1, "Warna sama salah! (Latar belakang dan latar depan tidak bisa berwarna sama)"
STRING_COLOR_ERROR2, "Kesalahan dalam spesifikasi warna" STRING_COLOR_ERROR2, "Kesalahan dalam spesifikasi warna"
STRING_COLOR_ERROR3, "Warna %x\n" STRING_COLOR_ERROR3, "Warna %x\n"
STRING_COLOR_ERROR4, "warna sama salah!"
STRING_CONSOLE_ERROR, "Kesalahan tidak dikenal: %d\n" STRING_CONSOLE_ERROR, "Kesalahan tidak dikenal: %d\n"
STRING_COPY_ERROR1, "Salah: Tidak dapat membuka sumber - %s!\n" STRING_COPY_ERROR1, "Salah: Tidak dapat membuka sumber - %s!\n"
STRING_COPY_ERROR2, "Salah: Tidak dapat mengcopy ke dirinya sendiri!\n" STRING_COPY_ERROR2, "Salah: Tidak dapat mengcopy ke dirinya sendiri!\n"

View file

@ -642,7 +642,6 @@ STRING_CMD_ERROR5, "Esecuzione di cmdexit.bat...\n"
STRING_COLOR_ERROR1, "Il colore di primo piano e sfondo non possono essere uguali" STRING_COLOR_ERROR1, "Il colore di primo piano e sfondo non possono essere uguali"
STRING_COLOR_ERROR2, "errore nella indicazione dei colori" STRING_COLOR_ERROR2, "errore nella indicazione dei colori"
STRING_COLOR_ERROR3, "Colore %x\n" STRING_COLOR_ERROR3, "Colore %x\n"
STRING_COLOR_ERROR4, "i colori non possono essere uguali!"
STRING_CONSOLE_ERROR, "errore sconosciuto: %d\n" STRING_CONSOLE_ERROR, "errore sconosciuto: %d\n"
STRING_COPY_ERROR1, "Errore: Impossibile aprire il file sorgente - %s!\n" STRING_COPY_ERROR1, "Errore: Impossibile aprire il file sorgente - %s!\n"
STRING_COPY_ERROR2, "Errore: Impossibile copiare un file su se stesso!\n" STRING_COPY_ERROR2, "Errore: Impossibile copiare un file su se stesso!\n"

View file

@ -642,7 +642,6 @@ STRING_CMD_ERROR5, "cmdexit.bat を実行しています...\n"
STRING_COLOR_ERROR1, "エラー! 同じ色が指定されました。\n (前景色と背景色を同じ色にすることはできません)" STRING_COLOR_ERROR1, "エラー! 同じ色が指定されました。\n (前景色と背景色を同じ色にすることはできません)"
STRING_COLOR_ERROR2, "色の指定に問題があります。" STRING_COLOR_ERROR2, "色の指定に問題があります。"
STRING_COLOR_ERROR3, "Color %x\n" STRING_COLOR_ERROR3, "Color %x\n"
STRING_COLOR_ERROR4, "エラー! 同じ色が指定されました。"
STRING_CONSOLE_ERROR, "不明なエラー: %d\n" STRING_CONSOLE_ERROR, "不明なエラー: %d\n"
STRING_COPY_ERROR1, "エラー: 元のファイル %s を開けません!\n" STRING_COPY_ERROR1, "エラー: 元のファイル %s を開けません!\n"
STRING_COPY_ERROR2, "エラー: コピー元とコピー先が一緒です!\n" STRING_COPY_ERROR2, "エラー: コピー元とコピー先が一緒です!\n"

View file

@ -629,7 +629,6 @@ STRING_CMD_ERROR5, "Kjører cmdexit.bat...\n"
STRING_COLOR_ERROR1, "Samme farge feil! (Bakgrunn og forgrunn kan ikke ha samme farge)" STRING_COLOR_ERROR1, "Samme farge feil! (Bakgrunn og forgrunn kan ikke ha samme farge)"
STRING_COLOR_ERROR2, "feil i farge spesifikasjon" STRING_COLOR_ERROR2, "feil i farge spesifikasjon"
STRING_COLOR_ERROR3, "Farge %x\n" STRING_COLOR_ERROR3, "Farge %x\n"
STRING_COLOR_ERROR4, "samme farge feil!"
STRING_CONSOLE_ERROR, "Ukjent feil: %d\n" STRING_CONSOLE_ERROR, "Ukjent feil: %d\n"
STRING_COPY_ERROR1, "Feil: kan ikke åpne kilden - %s!\n" STRING_COPY_ERROR1, "Feil: kan ikke åpne kilden - %s!\n"
STRING_COPY_ERROR2, "Feil: kan ikke kopiere til seg selv!\n" STRING_COPY_ERROR2, "Feil: kan ikke kopiere til seg selv!\n"

View file

@ -637,7 +637,6 @@ STRING_CMD_ERROR5, "Wykonywanie cmdexit.bat...\n"
STRING_COLOR_ERROR1, "Błąd! Kolor tła i tekstu nie może być taki sam" STRING_COLOR_ERROR1, "Błąd! Kolor tła i tekstu nie może być taki sam"
STRING_COLOR_ERROR2, "Błąd w oznaczeniu kolorów." STRING_COLOR_ERROR2, "Błąd w oznaczeniu kolorów."
STRING_COLOR_ERROR3, "Kolor %x\n" STRING_COLOR_ERROR3, "Kolor %x\n"
STRING_COLOR_ERROR4, "Błąd - kolory takie same!"
STRING_CONSOLE_ERROR, "Nieznany błąd: %d\n" STRING_CONSOLE_ERROR, "Nieznany błąd: %d\n"
STRING_COPY_ERROR1, "Błąd: Nie można otworzyć źródła - %s!\n" STRING_COPY_ERROR1, "Błąd: Nie można otworzyć źródła - %s!\n"
STRING_COPY_ERROR2, "Błąd: Nie można przekopiować pliku na niego samego!\n" STRING_COPY_ERROR2, "Błąd: Nie można przekopiować pliku na niego samego!\n"

View file

@ -681,7 +681,6 @@ STRING_CMD_ERROR5, "Executare «cmdexit.bat»...\n"
STRING_COLOR_ERROR1, "Eroare de culoare identică! (Culorile nu trebuie să fie identice)" STRING_COLOR_ERROR1, "Eroare de culoare identică! (Culorile nu trebuie să fie identice)"
STRING_COLOR_ERROR2, "Eroare la specificarea culorii" STRING_COLOR_ERROR2, "Eroare la specificarea culorii"
STRING_COLOR_ERROR3, "Culoare %x\n" STRING_COLOR_ERROR3, "Culoare %x\n"
STRING_COLOR_ERROR4, "Eroare de culoare identică!"
STRING_CONSOLE_ERROR, "Eroare necunoscută: %d\n" STRING_CONSOLE_ERROR, "Eroare necunoscută: %d\n"
STRING_COPY_ERROR1, "Eroare: Nu se poate deschide fișierul - «%s»!\n" STRING_COPY_ERROR1, "Eroare: Nu se poate deschide fișierul - «%s»!\n"
STRING_COPY_ERROR2, "Eroare: Nu se poate copia peste el însuși!\n" STRING_COPY_ERROR2, "Eroare: Nu se poate copia peste el însuși!\n"

View file

@ -641,7 +641,6 @@ STRING_CMD_ERROR5, "Запуск cmdexit.bat...\n"
STRING_COLOR_ERROR1, "Одинаковые цвета! (Цвета фона и текста не могут быть одинаковыми)" STRING_COLOR_ERROR1, "Одинаковые цвета! (Цвета фона и текста не могут быть одинаковыми)"
STRING_COLOR_ERROR2, "ошибка в указании цвета" STRING_COLOR_ERROR2, "ошибка в указании цвета"
STRING_COLOR_ERROR3, "Цвет %x\n" STRING_COLOR_ERROR3, "Цвет %x\n"
STRING_COLOR_ERROR4, "Одинаковые цвета!"
STRING_CONSOLE_ERROR, "Неизвестная ошибка: %d\n" STRING_CONSOLE_ERROR, "Неизвестная ошибка: %d\n"
STRING_COPY_ERROR1, "Ошибка: Невозможно открыть источник - %s!\n" STRING_COPY_ERROR1, "Ошибка: Невозможно открыть источник - %s!\n"
STRING_COPY_ERROR2, "Ошибка: Невозможно копировать в себя!\n" STRING_COPY_ERROR2, "Ошибка: Невозможно копировать в себя!\n"

View file

@ -641,7 +641,6 @@ STRING_CMD_ERROR5, "Running cmdexit.bat...\n"
STRING_COLOR_ERROR1, "Same colors error! (Background and foreground can't be the same color)" STRING_COLOR_ERROR1, "Same colors error! (Background and foreground can't be the same color)"
STRING_COLOR_ERROR2, "error in color specification" STRING_COLOR_ERROR2, "error in color specification"
STRING_COLOR_ERROR3, "Color %x\n" STRING_COLOR_ERROR3, "Color %x\n"
STRING_COLOR_ERROR4, "same colors error!"
STRING_CONSOLE_ERROR, "Neznáma chyba: %d\n" STRING_CONSOLE_ERROR, "Neznáma chyba: %d\n"
STRING_COPY_ERROR1, "Chyba: Cannot open source - %s!\n" STRING_COPY_ERROR1, "Chyba: Cannot open source - %s!\n"
STRING_COPY_ERROR2, "Chyba: Can't copy onto itself!\n" STRING_COPY_ERROR2, "Chyba: Can't copy onto itself!\n"

View file

@ -629,7 +629,6 @@ STRING_CMD_ERROR5, "Kör cmdexit.bat...\n"
STRING_COLOR_ERROR1, "Samme farge feil! (Bakgrunn och forgrunn kan inte ha samme farge)" STRING_COLOR_ERROR1, "Samme farge feil! (Bakgrunn och forgrunn kan inte ha samme farge)"
STRING_COLOR_ERROR2, "feil i farge spesifikasjon" STRING_COLOR_ERROR2, "feil i farge spesifikasjon"
STRING_COLOR_ERROR3, "Farge %x\n" STRING_COLOR_ERROR3, "Farge %x\n"
STRING_COLOR_ERROR4, "samme farge feil!"
STRING_CONSOLE_ERROR, "Ukjent feil: %d\n" STRING_CONSOLE_ERROR, "Ukjent feil: %d\n"
STRING_COPY_ERROR1, "Feil: kan inte åpne kilden - %s!\n" STRING_COPY_ERROR1, "Feil: kan inte åpne kilden - %s!\n"
STRING_COPY_ERROR2, "Feil: kan inte kopiere til seg selv!\n" STRING_COPY_ERROR2, "Feil: kan inte kopiere til seg selv!\n"

View file

@ -643,7 +643,6 @@ STRING_CMD_ERROR5, "Запуск cmdexit.bat...\n"
STRING_COLOR_ERROR1, "помилка - однаковi кольори! (тло та текст не можуть бути однакового кольору)" STRING_COLOR_ERROR1, "помилка - однаковi кольори! (тло та текст не можуть бути однакового кольору)"
STRING_COLOR_ERROR2, "помилка при вказаннi кольору" STRING_COLOR_ERROR2, "помилка при вказаннi кольору"
STRING_COLOR_ERROR3, "Колiр %x\n" STRING_COLOR_ERROR3, "Колiр %x\n"
STRING_COLOR_ERROR4, "помилка - однаковi кольори!"
STRING_CONSOLE_ERROR, "Невiдома помилка: %d\n" STRING_CONSOLE_ERROR, "Невiдома помилка: %d\n"
STRING_COPY_ERROR1, "Помилка: Неможливо вiдкрити джерело - %s!\n" STRING_COPY_ERROR1, "Помилка: Неможливо вiдкрити джерело - %s!\n"
STRING_COPY_ERROR2, "Помилка: Неможливо копiювати в себе!\n" STRING_COPY_ERROR2, "Помилка: Неможливо копiювати в себе!\n"

View file

@ -601,7 +601,6 @@ STRING_CMD_ERROR5, "正在运行 cmdexit.bat...\n"
STRING_COLOR_ERROR1, "同样颜色错误! (背景和前景不能同色)" STRING_COLOR_ERROR1, "同样颜色错误! (背景和前景不能同色)"
STRING_COLOR_ERROR2, "颜色指定错误" STRING_COLOR_ERROR2, "颜色指定错误"
STRING_COLOR_ERROR3, "颜色 %x\n" STRING_COLOR_ERROR3, "颜色 %x\n"
STRING_COLOR_ERROR4, "同样颜色错误!"
STRING_CONSOLE_ERROR, "未知错误:%d\n" STRING_CONSOLE_ERROR, "未知错误:%d\n"
STRING_COPY_ERROR1, "错误:无法打开源 - %s\n" STRING_COPY_ERROR1, "错误:无法打开源 - %s\n"
STRING_COPY_ERROR2, "错误:无法复制到自身!\n" STRING_COPY_ERROR2, "错误:无法复制到自身!\n"

View file

@ -34,13 +34,12 @@
#define STRING_COLOR_ERROR1 314 #define STRING_COLOR_ERROR1 314
#define STRING_COLOR_ERROR2 315 #define STRING_COLOR_ERROR2 315
#define STRING_COLOR_ERROR3 316 #define STRING_COLOR_ERROR3 316
#define STRING_COLOR_ERROR4 317 #define STRING_CONSOLE_ERROR 317
#define STRING_CONSOLE_ERROR 318 #define STRING_COPY_ERROR1 320
#define STRING_COPY_ERROR1 319 #define STRING_COPY_ERROR2 321
#define STRING_COPY_ERROR2 320 #define STRING_COPY_ERROR3 322
#define STRING_COPY_ERROR3 321 #define STRING_COPY_ERROR4 323
#define STRING_COPY_ERROR4 322 #define STRING_DATE_ERROR 324
#define STRING_DATE_ERROR 323
#define STRING_DEL_ERROR5 328 #define STRING_DEL_ERROR5 328
#define STRING_DEL_ERROR6 329 #define STRING_DEL_ERROR6 329
#define STRING_DEL_ERROR7 330 #define STRING_DEL_ERROR7 330

View file

@ -10,10 +10,12 @@
* *
*/ */
/*only /*
BOOL StringToColor(LPWORD lpColor, LPTSTR*str) * Only
is to be called * BOOL StringToColor(LPWORD lpColor, LPTSTR*str)
other are internal service functions*/ * has to be called.
* Other are internal service functions.
*/
#include "precomp.h" #include "precomp.h"
@ -23,16 +25,16 @@ other are internal service functions*/
#define _I FOREGROUND_INTENSITY #define _I FOREGROUND_INTENSITY
/*return values for chop_blank*/ /* Return values for chop_blank */
#define CP_OK 0 #define CP_OK 0
#define CP_BLANK_NOT_FOUND 1 #define CP_BLANK_NOT_FOUND 1
#define CP_END_OF_STRING 2 #define CP_END_OF_STRING 2
/* NOTE: See the description for these flags in the StringToColor()'s description */
#define SC_HEX 0x0100 #define SC_HEX 0x0100
#define SC_TXT 0x0200 #define SC_TXT 0x0200
typedef struct _CLRTABLE typedef struct _CLRTABLE
{ {
LPTSTR name; LPTSTR name;
@ -42,58 +44,55 @@ typedef struct _CLRTABLE
CLRTABLE clrtable[] = CLRTABLE clrtable[] =
{ {
{_T("bla") ,0 }, {_T("bla"), 0 },
{_T("blu") ,_B }, {_T("blu"), _B },
{_T("gre") ,_G }, {_T("gre"), _G },
{_T("cya") ,_B|_G }, {_T("cya"), _B|_G },
{_T("red") ,_R }, {_T("red"), _R },
{_T("mag") ,_B|_R }, {_T("mag"), _B|_R },
{_T("yel") ,_R|_G }, {_T("yel"), _R|_G },
{_T("whi") ,_R|_G|_B }, {_T("whi"), _R|_G|_B },
{_T("gra") ,_I }, {_T("gra"), _I },
{_T("0") , 0 },
{_T("2") , _G },
{_T("3") , _B|_G },
{_T("4") , _R },
{_T("5") , _B|_R },
{_T("6") , _R|_G },
{_T("7") , _R|_G|_B },
{_T("0") ,0 }, {_T("8") , _I },
{_T("2") ,_G }, {_T("9") , _I|_B },
{_T("3") ,_B|_G }, {_T("10") , _I|_G },
{_T("4") ,_R }, {_T("11") , _I|_B|_G },
{_T("5") ,_B|_R }, {_T("12") , _I|_R },
{_T("6") ,_R|_G }, {_T("13") , _I|_B|_R },
{_T("7") ,_R|_G|_B }, {_T("14") , _I|_R|_G },
{_T("15") , _I|_R|_G|_B },
{_T("8") ,_I }, /*
{_T("9") ,_I|_B }, * Note that 1 is at the end of list
{_T("10") ,_I|_G }, * to avoid to confuse it with 10-15
{_T("11") ,_I|_B|_G }, */
{_T("12") ,_I|_R }, {_T("1") , _B },
{_T("13") ,_I|_B|_R },
{_T("14") ,_I|_R|_G },
{_T("15") ,_I|_R|_G|_B },
/* note that 1 is at the end of list
to avoid to confuse it with 10-15*/
{_T("1") ,_B },
/*cyan synonimous*/
{_T("aqu") ,_B|_G },
/*magenta synonimous*/
{_T("pur") ,_B|_R },
/* Cyan synonym */
{_T("aqu"), _B|_G },
/* Magenta synonym */
{_T("pur"), _B|_R },
{_T("") ,0}, {_T("") ,0},
}; };
/* /*
move string pointer to next word (skip all spaces) * Move string pointer to next word (skip all spaces).
on erro retunr nonzero value * On error return nonzero value.
*/ */
static static
INT chop_blank(LPTSTR *arg_str) INT chop_blank(LPTSTR *arg_str)
{ {
LPTSTR str; LPTSTR str;
str = _tcschr(*arg_str,_T(' ')); str = _tcschr(*arg_str,_T(' '));
if(!str) if(!str)
@ -104,8 +103,6 @@ INT chop_blank(LPTSTR *arg_str)
return CP_BLANK_NOT_FOUND; return CP_BLANK_NOT_FOUND;
} }
while(_istspace(*str)) while(_istspace(*str))
str++; str++;
@ -121,11 +118,10 @@ INT chop_blank(LPTSTR *arg_str)
} }
/* /*
read a color value in hex (like win nt's cmd syntax) * Read a color value in hex (like win nt's cmd syntax).
if an error occurs return -1 * If an error occurs return -1.
*/ */
static static
WORD hex_clr(LPTSTR str) WORD hex_clr(LPTSTR str)
{ {
@ -146,7 +142,6 @@ WORD hex_clr(LPTSTR str)
return (WORD)-1; return (WORD)-1;
} }
ch = str[0]; ch = str[0];
if(_istdigit(ch)) if(_istdigit(ch))
@ -166,9 +161,9 @@ WORD hex_clr(LPTSTR str)
/* /*
read a color value from a string (like 4nt's syntax) * Read a color value from a string (like 4nt's syntax).
if an error occurs return -1 * If an error occurs return -1.
*/ */
static static
WORD txt_clr(LPTSTR str) WORD txt_clr(LPTSTR str)
{ {
@ -182,8 +177,7 @@ WORD txt_clr(LPTSTR str)
} }
/* Search for "x on y" */
/*search for x on y*/
static static
WORD str_to_color(LPTSTR* arg_str) WORD str_to_color(LPTSTR* arg_str)
{ {
@ -197,8 +191,7 @@ WORD str_to_color(LPTSTR* arg_str)
if (!(*str)) if (!(*str))
return (WORD)-1; return (WORD)-1;
/* foreground */
/*foreground*/
bBri = FALSE; bBri = FALSE;
if (_tcsnicmp(str,_T("bri"),3) == 0) if (_tcsnicmp(str,_T("bri"),3) == 0)
@ -214,13 +207,13 @@ WORD str_to_color(LPTSTR* arg_str)
return (WORD)-1; return (WORD)-1;
} }
/*skip spaces and "on"*/ /* skip spaces and "on" keyword */
if (chop_blank(&str) || chop_blank(&str)) if (chop_blank(&str) || chop_blank(&str))
return (WORD)-1; return (WORD)-1;
ret_clr = tmp_clr | (bBri << 3); ret_clr = tmp_clr | (bBri << 3);
/*background*/ /* background */
bBri = FALSE; bBri = FALSE;
if(_tcsnicmp(str,_T("bri"),3) == 0 ) if(_tcsnicmp(str,_T("bri"),3) == 0 )
@ -231,7 +224,6 @@ WORD str_to_color(LPTSTR* arg_str)
return (WORD)-1; return (WORD)-1;
} }
if( (tmp_clr = txt_clr(str)) == (WORD)-1 ) if( (tmp_clr = txt_clr(str)) == (WORD)-1 )
return (WORD)-1; return (WORD)-1;
@ -239,29 +231,28 @@ WORD str_to_color(LPTSTR* arg_str)
*arg_str = str; *arg_str = str;
return SC_HEX | ret_clr | tmp_clr << 4 | bBri << 7; /* NOTE: See the note on SC_HEX in the StringToColor()'s description */
return /* SC_HEX | */ ret_clr | tmp_clr << 4 | bBri << 7;
} }
/**** Main function ****/
/****main function****/
/* /*
the only parameter is arg_str, a pointer to a string. * The only parameter is arg_str, a pointer to a string.
the string is modified so it will begin to first word after * The string is modified so it will begin to first word after
color specification * color specification
(only the char* is moved, no chars in the string are modfied) * (only the char* is moved, no chars in the string are modfied).
*
* **** NOTE: The following functionality is deactivated ****
it returns the color in the l.o. byte, plus two flags in the * it returns the color in the l.o. byte, plus two flags in the
h.o. byte, they are: * h.o. byte, they are:
SC_HEX win nt's cmd syntax (for exampl a0) * SC_HEX win nt's cmd syntax (for exampl a0)
SC_TXT 4nt's syntax ( "bri gre on bla" or "10 on 0") * SC_TXT 4nt's syntax ( "bri gre on bla" or "10 on 0")
* **********************************************************
if succedes also move the LPTSTR to end of *
string that specify color * If succedes also move the LPTSTR to end of
*/ * string that specify color.
*/
BOOL StringToColor(LPWORD lpColor, LPTSTR*str) BOOL StringToColor(LPWORD lpColor, LPTSTR*str)
{ {
WORD wRet; WORD wRet;