Skip to content

Instantly share code, notes, and snippets.

@msmhrt
Created September 5, 2013 12:34
Show Gist options
  • Select an option

  • Save msmhrt/6449507 to your computer and use it in GitHub Desktop.

Select an option

Save msmhrt/6449507 to your computer and use it in GitHub Desktop.
カラー表示でも画面が崩れないUTF-8対応のless.exe ref: http://qiita.com/msmhrt/items/77be4bf01154478abdb8
diff -Naur less-458.orig/Makefile.wnm less-458/Makefile.wnm
--- less-458.orig/Makefile.wnm Fri Apr 5 01:55:07 2013
+++ less-458/Makefile.wnm Thu Sep 5 21:27:07 2013
@@ -6,7 +6,7 @@
CC = cl
# Normal flags
-CFLAGS = /nologo /ML /W3 /GX /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /c
+CFLAGS = /nologo /W3 /EHsc /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D"_CRT_SECURE_NO_WARNINGS" /c
LDFLAGS = /nologo /subsystem:console /incremental:no /machine:I386
# Debugging flags
@@ -14,7 +14,7 @@
#LDFLAGS = /nologo /subsystem:console /incremental:yes /debug /machine:I386
LD = link
-LIBS = user32.lib
+LIBS = user32.lib /nodefaultlib:libc.lib
#### End of system configuration section. ####
diff -Naur less-458.orig/screen.c less-458/screen.c
--- less-458.orig/screen.c Fri Apr 5 01:55:05 2013
+++ less-458/screen.c Thu Sep 5 21:27:07 2013
@@ -2490,7 +2490,29 @@
{
#if MSDOS_COMPILER==WIN32C
DWORD written;
- WriteConsole(con_out, text, len, &written, NULL);
+ extern int utf_mode;
+ if (utf_mode)
+ {
+ DWORD wlen = 0;
+ char *text_prev = text;
+ char *text_end = text + len;
+ wchar_t *wtext = (wchar_t*) malloc(len * sizeof(wchar_t));
+ while (text < text_end && *text)
+ {
+ wtext[wlen++] = (wchar_t) step_char(&text, TRUE, text_end);
+ if (text == text_prev)
+ break;
+ else
+ text_prev = text;
+ }
+
+ if (wlen > 0)
+ WriteConsoleW(con_out, wtext, wlen, &written, NULL);
+ free(wtext);
+ } else
+ {
+ WriteConsole(con_out, text, len, &written, NULL);
+ }
#else
char c = text[len];
text[len] = '\0';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment