adapt to windows and bug fixes
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Thu, 3 Oct 2024 11:44:21 +0000 (13:44 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Thu, 3 Oct 2024 11:44:21 +0000 (13:44 +0200)
makefile
ndisplay.c

index f1694f2547a6b6d13752ca98b93885361bf78b73..afdab22e121f93496fe8fed57b8fe22b48b8a1e5 100644 (file)
--- a/makefile
+++ b/makefile
@@ -4,14 +4,13 @@ CC = gcc
 
 #INCLUDES = -I../debug -D__MEMORY_ALLOCATION__
 INCLUDES =
-#OFLAGS  = -O4 -Os
+OFLAGS  = -O4 -Os
 #OFLAGS  = -O4 -ffast-math -finline-functions
 #OFLAGS  = -O4 -finline-functions
 #OFLAGS += -mtune=pentium3 -mmmx -msse -msse2 -m3dnow
 #OFLAGS += -minline-all-stringops -fsingle-precision-constant
 #OFLAGS += -malign-double
 CFLAGS += -W -Wall -Wextra -g
-CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
 CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS)
 LDFLAGS += -g $(LDOPTS) $(OPTIONS)
 
@@ -19,12 +18,15 @@ LDOPT = linker
 MV = mv
 ifneq (, $(findstring linux, $(MAKE_HOST)))
 # Linux
+CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
 else ifneq (, $(findstring mingw, $(MAKE_HOST)))
 # Windows MinGw
+CFLAGS += -DPDC_WIDE
 #LDLIBS += -lws2_32
 LDOPT = winlnk
 else ifneq (, $(findstring cygwin, $(MAKE_HOST)))
 # Windows CygWin
+CFLAGS += -DPDC_WIDE
 LDOPT = winlnk
 else ifneq (, $(findstring msdos, $(MAKE_HOST)))
 # MSDOS
index fae2fddf44564d14d869c3779e81b3f762d062d6..6b42957a4e35e93964f9d92ae1be3da9be34cdfc 100644 (file)
@@ -23,7 +23,7 @@ char *version = "0.1";
 
 int colormap = 2;
 float gf[3] = { 1.0f, 1.0f, 1.0f };
-int mode = 0;
+int mode = 1;
 
 char *help =
     "<i> Move up\n"
@@ -39,9 +39,9 @@ int usage (int ret)
     fprintf (fd, "usage: %s [-g gamma] [-h] [-t|-w] [-v int] <file>\n", progname);
     fprintf (fd, " -g: gamma correction (%.1f:%.1f:%.1f)\n", gf[0], gf[1], gf[2]);
     fprintf (fd, " -h: help message\n");
-    fprintf (fd, " -t: thin mode (%s)\n", (mode == 0) ? "on" : "off");
+    fprintf (fd, " -t: thin mode (%s)\n", (mode == 1) ? "on" : "off");
     fprintf (fd, " -v: verbose level (%d)\n", verbose);
-    fprintf (fd, " -w: wide mode (%s)\n", (mode == 1) ? "on" : "off");
+    fprintf (fd, " -w: wide mode (%s)\n", (mode == 2) ? "on" : "off");
     fprintf (fd, "%s version %s\n", progname, version);
 
     return ret;
@@ -91,7 +91,7 @@ int main (int argc, char *argv[])
             }
             break;
         case 't':
-            mode = 0;
+            mode = 1;
             break;
         case 'v':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
@@ -102,7 +102,7 @@ int main (int argc, char *argv[])
             verbose = atoi (arg);
             break;
         case 'w':
-            mode = 1;
+            mode = 2;
             break;
         case 'h':
         default:
@@ -150,7 +150,7 @@ int main (int argc, char *argv[])
     int stop = 0;
     while (!stop) {
 
-        int width = min (image->width - xcursor, COLS);
+        int width = min (image->width - xcursor, COLS / mode);
         int height = min (image->height - ycursor, LINES);
         int x, y;
         for (y = 0; y < height; y++) {
@@ -161,12 +161,16 @@ int main (int argc, char *argv[])
                 //color_t *color = findcolor (correction (image->red[ind], gf[0]), correction (image->green[ind], gf[1]), correction (image->blue[ind], gf[2]), colormap);
                 attron (COLOR_PAIR (color->code));
                 
-                move (y, x);
+                move (y, x * mode);
                 cchar_t tmp;
                 wchar_t tmp_wchar[2] = {0};
                 tmp_wchar[0] = (wchar_t) ' ';
                 setcchar (&tmp, tmp_wchar, A_NORMAL, 0, NULL);
                 add_wch (&tmp);
+                if (mode == 2) {
+                    move (y, x * mode + 1);
+                    add_wch (&tmp);
+                }
             }
         }
         refresh ();
@@ -175,25 +179,25 @@ int main (int argc, char *argv[])
         switch (getch ()) {
         case KEY_UP:
         case 'i':
-            if (image->height - ycursor > LINES) {
+            if (ycursor > 0) {
                 ycursor--;
             }
             break;
         case KEY_LEFT:
         case 'j':
-            if (image->width - xcursor > COLS) {
+            if (xcursor > 0) {
                 xcursor--;
             }
             break;
         case KEY_DOWN:
         case 'k':
-            if (ycursor < 0) {
+            if (image->height - ycursor > LINES) {
                 ycursor++;
             }
             break;
         case KEY_RIGHT:
         case 'l':
-            if (xcursor < 0) {
+            if (image->width - xcursor > COLS / mode) {
                 xcursor++;
             }
             break;