about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2018-03-02 00:39:46 +0000
committerThomas E. Dickey <dickey@invisible-island.net>2018-03-02 00:39:46 +0000
commit952761081f2a2a9631352a3edf2f410e0e36c9be (patch)
treed24fc92a22e284bedc1b1626b1a871bc75850fac /src
parentb518192561f738e5249e4f1e38ed0cdc2f059e0f (diff)
downloadlynx-snapshots-952761081f2a2a9631352a3edf2f410e0e36c9be.tar.gz
snapshot of project "lynx", label v2-8-9dev_16k
Diffstat (limited to 'src')
-rw-r--r--src/GridText.c4
-rw-r--r--src/HTFWriter.c8
-rw-r--r--src/LYCurses.c92
-rw-r--r--src/LYMain.c10
-rw-r--r--src/LYMainLoop.c7
-rw-r--r--src/LYUtils.c22
-rw-r--r--src/LYUtils.h3
7 files changed, 78 insertions, 68 deletions
diff --git a/src/GridText.c b/src/GridText.c
index 48e7459b..82596e8e 100644
--- a/src/GridText.c
+++ b/src/GridText.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: GridText.c,v 1.306 2018/02/19 23:03:00 tom Exp $
+ * $LynxId: GridText.c,v 1.307 2018/03/01 22:23:53 Takeshi.Hataguchi Exp $
  *
  *		Character grid hypertext object
  *		===============================
@@ -4322,7 +4322,7 @@ void HText_appendCharacter(HText *text, int ch)
 	      - ctrl_chars_on_this_line);
 
     if ((
-#ifndef USE_SLANG
+#if !defined(USE_SLANG) && !defined(PDCURSES)
 	    (text->permissible_split
 #ifdef USE_CURSES_PADS
 	     || !LYwideLines
diff --git a/src/HTFWriter.c b/src/HTFWriter.c
index 6e729ae1..ee123013 100644
--- a/src/HTFWriter.c
+++ b/src/HTFWriter.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTFWriter.c,v 1.113 2017/07/02 20:42:32 tom Exp $
+ * $LynxId: HTFWriter.c,v 1.114 2018/03/01 22:14:42 Takeshi.Hataguchi Exp $
  *
  *		FILE WRITER				HTFWrite.h
  *		===========
@@ -177,7 +177,7 @@ static void decompress_gzip(HTStream *me)
 		    CAST_off_t (me->anchor->actual_length),
 		    actual));
 	    if (success) {
-		if (rename(copied, in_name) == 0)
+		if (LYRenameFile(copied, in_name) == 0)
 		    me->anchor->actual_length = (off_t) actual;
 		LYRemoveTemp(copied);
 	    }
@@ -200,7 +200,7 @@ static void decompress_gzip(HTStream *me)
 
 		strcpy(expanded, copied);
 		*strrchr(expanded, '.') = '\0';
-		if (rename(expanded, in_name) != 0) {
+		if (LYRenameFile(expanded, in_name) != 0) {
 		    CTRACE((tfp, "rename failed %s to %s\n", expanded, in_name));
 		} else if (stat(in_name, &stat_buf) != 0) {
 		    CTRACE((tfp, "stat failed for %s\n", in_name));
@@ -364,7 +364,7 @@ static void HTFWriter_free(HTStream *me)
 			    new_path[off] = '.';
 			    if (strlen(new_path + off) > 4)
 				new_path[off + 4] = '\0';
-			    if (rename(path, new_path) == 0) {
+			    if (LYRenameFile(path, new_path) == 0) {
 				FREE(path);
 				path = new_path;
 			    } else {
diff --git a/src/LYCurses.c b/src/LYCurses.c
index 28826a62..f28999f7 100644
--- a/src/LYCurses.c
+++ b/src/LYCurses.c
@@ -1,4 +1,4 @@
-/* $LynxId: LYCurses.c,v 1.184 2017/04/30 17:52:12 tom Exp $ */
+/* $LynxId: LYCurses.c,v 1.186 2018/03/02 00:39:46 tom Exp $ */
 #include <HTUtils.h>
 #include <HTAlert.h>
 
@@ -970,6 +970,23 @@ int saved_scrsize_x2 = 0;
 int saved_scrsize_y2 = 0;
 int saved_winpos_x2 = 0;
 int saved_winpos_y2 = 0;
+
+static int LYresize_term(int nlines, int ncols)
+{
+#ifdef _WINDOWS
+    HANDLE hConsole;
+    CONSOLE_SCREEN_BUFFER_INFO csbi;
+    SMALL_RECT srWindowRect;
+
+    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+    GetConsoleScreenBufferInfo(hConsole, &csbi);
+    srWindowRect.Right = min(ncols, csbi.dwSize.X) - 1;
+    srWindowRect.Bottom = min(nlines, csbi.dwSize.Y) - 1;
+    srWindowRect.Left = srWindowRect.Top = (SHORT) 0;
+    SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect);
+#endif
+    return resize_term(nlines, ncols);
+}
 #endif
 
 #ifdef USE_MAXSCREEN_TOGGLE
@@ -1077,64 +1094,35 @@ static void adjustWindowPos(void)
 
 void maxmizeWindowSize(void)
 {
-    int disp_height, disp_width, win_height, win_width;
     RECT winrect;
-    DWORD pid;
-    int font_width, font_height;
+    HANDLE hConsole;
+    COORD coordScreen;
 
     setCurrentWindowHandle();
     if (currentWindowHandle == NULL) {
 	return;
     }
-    GetWindowThreadProcessId(currentWindowHandle, &pid);
-    disp_width = GetSystemMetrics(SM_CXFULLSCREEN);
-    disp_height = GetSystemMetrics(SM_CYFULLSCREEN);
     GetWindowRect(currentWindowHandle, &winrect);
-    win_width = winrect.right - winrect.left;
-    win_height = winrect.bottom - winrect.top;
     saved_winpos_x2 = winrect.left;
     saved_winpos_y2 = winrect.top;
 
-    if ((win_width <= disp_width) && (win_height <= disp_height)) {
-	GetClientRect(currentWindowHandle, &winrect);
-	win_width = winrect.right - winrect.left;
-	win_height = winrect.bottom - winrect.top;
-	CTRACE((tfp, "Current Rect: (%4d,%4d,%3d,%3d), ",
-		(int) winrect.left, (int) winrect.right,
-		(int) winrect.top, (int) winrect.bottom));
-	CTRACE((tfp, "Size: (%4d,%3d)\n", win_width, win_height));
-
-	if (scrsize_x == 0) {
-	    scrsize_x = COLS;
-	    scrsize_y = LINES + 1;
-	}
-	if ((scrsize_x == 0) || (scrsize_y == 0)) {
-	    CTRACE((tfp, "Illegal value: scrsize_x=%d, scrsize_y=%d\n",
-		    scrsize_x, scrsize_y));
-	} else {
-	    font_width = win_width / scrsize_x;
-	    font_height = win_height / scrsize_y;
-	    CTRACE((tfp, "Font Size: (%2d,%2d)\n", font_width, font_height));
-	    if ((font_width == 0) || (font_height == 0)) {
-		CTRACE((tfp, "Illegal font size.\n"));
-	    } else {
-		LYcols = scrsize_x = (disp_width - 4) / font_width;
-		LYlines = scrsize_y = (disp_height - 32) / font_height;
-		LYlines--;
-		CTRACE((tfp, "Request maximum screen size: %dx%d\n",
-			scrsize_y, scrsize_x));
-		resize_term(scrsize_y, scrsize_x);
-		Sleep(100);
-		moveWindowHXY(currentWindowHandle, 0, 0);
-		LYlines = LYscreenHeight();
-		LYcols = LYscreenWidth();
-		CTRACE((tfp, "...actual maximum screen size: %dx%d\n",
-			LYlines, LYcols));
-		LYStatusLine = -1;
-		recent_sizechange = TRUE;
-	    }
-	}
-    }
+    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+    coordScreen = GetLargestConsoleWindowSize(hConsole);
+
+    LYcols = scrsize_x = coordScreen.X - 1;
+    LYlines = scrsize_y = coordScreen.Y - 1;
+    LYlines--;
+    CTRACE((tfp, "Request maximum screen size: %dx%d\n",
+	    scrsize_x, scrsize_y));
+    LYresize_term(scrsize_y, scrsize_x);
+    Sleep(100);
+    moveWindowHXY(currentWindowHandle, 0, 0);
+    LYlines = LYscreenHeight();
+    LYcols = LYscreenWidth();
+    CTRACE((tfp, "...actual maximum screen size: %dx%d\n",
+	    LYcols, LYlines));
+    LYStatusLine = -1;
+    recent_sizechange = TRUE;
 }
 
 void recoverWindowSize(void)
@@ -1146,7 +1134,7 @@ void recoverWindowSize(void)
 	LYStatusLine = -1;
 	wclear(curscr);
 	doupdate();
-	resize_term(scrsize_y, scrsize_x);
+	LYresize_term(scrsize_y, scrsize_x);
 
 	setCurrentWindowHandle();
 	if (currentWindowHandle != NULL) {
@@ -1389,7 +1377,7 @@ void start_curses(void)
 	size_change(0);
 	recent_sizechange = FALSE;	/* prevent mainloop drawing 1st doc twice */
 #endif /* SIGWINCH */
-	CTRACE((tfp, "Screen size is now %d x %d\n", LYlines, LYcols));
+	CTRACE((tfp, "Screen size is now %d x %d\n", LYcols, LYlines));
 
 #ifdef USE_CURSES_PADS
 	if (LYuseCursesPads) {
@@ -1560,7 +1548,7 @@ void start_curses(void)
 	}
 	CTRACE((tfp, "resize_term: x=%d, y=%d\n", scrsize_x, scrsize_y));
 	CTRACE((tfp, "saved terminal size: x=%d, y=%d\n", saved_scrsize_x, saved_scrsize_y));
-	resize_term(scrsize_y, scrsize_x);
+	LYresize_term(scrsize_y, scrsize_x);
 	LYlines = LYscreenHeight();
 	LYcols = LYscreenWidth();
 	LYStatusLine = -1;
diff --git a/src/LYMain.c b/src/LYMain.c
index 38a9a7c9..87f8489e 100644
--- a/src/LYMain.c
+++ b/src/LYMain.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYMain.c,v 1.266 2018/02/19 14:29:30 tom Exp $
+ * $LynxId: LYMain.c,v 1.267 2018/03/01 22:27:37 Takeshi.Hataguchi Exp $
  */
 #include <HTUtils.h>
 #include <HTTP.h>
@@ -3307,11 +3307,11 @@ static int scrsize_fun(char *next_arg)
 	    if ((scrsize_x <= 1) || (scrsize_y <= 1)) {
 		scrsize_x = scrsize_y = 0;
 	    }
-	    if ((scrsize_x > 0) && (scrsize_x < 80)) {
-		scrsize_x = 80;
+	    if ((scrsize_x > 0) && (scrsize_x < 40)) {
+		scrsize_x = 40;
 	    }
-	    if ((scrsize_y > 0) && (scrsize_y < 4)) {
-		scrsize_y = 4;
+	    if ((scrsize_y > 0) && (scrsize_y < 6)) {
+		scrsize_y = 6;
 	    }
 	    CTRACE((tfp, "scrsize: x=%d, y=%d\n", scrsize_x, scrsize_y));
 	}
diff --git a/src/LYMainLoop.c b/src/LYMainLoop.c
index dbf51dd4..eee3d22e 100644
--- a/src/LYMainLoop.c
+++ b/src/LYMainLoop.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYMainLoop.c,v 1.236 2018/02/15 01:53:44 tom Exp $
+ * $LynxId: LYMainLoop.c,v 1.238 2018/03/01 22:20:33 Takeshi.Hataguchi Exp $
  */
 #include <HTUtils.h>
 #include <HTAccess.h>
@@ -2165,7 +2165,8 @@ static int handle_LYK_DOWNLOAD(int *cmd,
 		    }
 		    return 0;
 		}
-		if (isLYNXOPTIONS(links[curdoc.link].l_form->submit_action)) {
+		if (isEmpty(links[curdoc.link].l_form->submit_action) ||
+		    isLYNXOPTIONS(links[curdoc.link].l_form->submit_action)) {
 		    if (*old_c != real_c) {
 			*old_c = real_c;
 			HTUserMsg(NO_DOWNLOAD_SPECIAL);
@@ -6725,7 +6726,7 @@ int mainloop(void)
 		    p = links[curdoc.link].lname;
 		}
 
-		if (strlen(p) < (sizeof(sjis_buff) / 10)) {
+		if (strlen(p) < ((sizeof(sjis_buff) / 2) - 1)) {
 		    strcpy(temp_buff, p);
 		    if (StrChr(temp_buff, '%')) {
 			HTUnEscape(temp_buff);
diff --git a/src/LYUtils.c b/src/LYUtils.c
index 61dc1c5d..7a12ae66 100644
--- a/src/LYUtils.c
+++ b/src/LYUtils.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYUtils.c,v 1.279 2018/02/15 01:54:02 tom Exp $
+ * $LynxId: LYUtils.c,v 1.280 2018/03/01 22:14:57 Takeshi.Hataguchi Exp $
  */
 #include <HTUtils.h>
 #include <HTTCP.h>
@@ -7099,6 +7099,26 @@ void LYAddHtmlSep0(char *path)
 }
 
 /*
+ * Rename a file
+ */
+int LYRenameFile(char *src,
+		 char *dst)
+{
+#ifdef _WINDOWS
+    /* 
+     * If dest_file exists prior to calling rename(), rename() will fail on Windows platforms.
+     * https://www.securecoding.cert.org/confluence/display/c/FIO10-C.+Take+care+when+using+the+rename%28%29+function
+     */
+    struct stat st;
+
+    if (stat(dst, &st) == 0) {
+	unlink(dst);
+    }
+#endif
+    return rename(src, dst);
+}
+
+/*
  * Copy a file
  */
 int LYCopyFile(char *src,
diff --git a/src/LYUtils.h b/src/LYUtils.h
index 173a9940..9e228303 100644
--- a/src/LYUtils.h
+++ b/src/LYUtils.h
@@ -1,4 +1,4 @@
-/* $LynxId: LYUtils.h,v 1.98 2014/07/24 22:10:20 tom Exp $ */
+/* $LynxId: LYUtils.h,v 1.99 2018/03/01 22:14:42 Takeshi.Hataguchi Exp $ */
 #ifndef LYUTILS_H
 #define LYUTILS_H
 
@@ -166,6 +166,7 @@ extern "C" {
     extern const char *wwwName(const char *pathname);
     extern int HTCheckForInterrupt(void);
     extern int LYConsoleInputFD(int need_selectable);
+    extern int LYRenameFile(char *src, char *dst);
     extern int LYCopyFile(char *src, char *dst);
     extern int LYGetHilitePos(int cur, int count);
     extern int LYRemoveTemp(char *name);