Fixed a regression due to a change in MsvcLibX's version of BreakArgLine(): Remove C escape sequences, like \n \t \xXX, from the string.

--- C/SRC/msgbox.c
+++ C/SRC/msgbox.c
@@ -29,15 +29,17 @@
 *    2017-06-28 JFL Fixed the link warning. No functional code change.	      *
 *    2019-04-19 JFL Use the version strings from the new stversion.h.         *
 *    2019-06-12 JFL Added PROGRAM_DESCRIPTION definition.		      *
+*    2020-01-14 JFL Fixed a regression due to a change in MsvcLibX's version  *
+*		    of BreakArgLine():					      *
+*                   Remove C escape sequences, like \n \xXX, from the string. *
 *                                                                             *
 *          Copyright 2016 Hewlett Packard Enterprise Development LP          *
 * Licensed under the Apache 2.0 license - www.apache.org/licenses/LICENSE-2.0 *
 \*****************************************************************************/

-#define PROGRAM_DESCRIPTION "Display a Message Box and return the user choice"
+#define PROGRAM_DESCRIPTION "Display a Message Box and return the user's choice"
 #define PROGRAM_NAME    "msgbox"
-#define PROGRAM_VERSION "2019.06.12"
-#define PROGRAM_DATE    "2019-06-12"
+#define PROGRAM_VERSION "2020-01-14"

 #define _CRT_SECURE_NO_WARNINGS 1 /* Avoid Visual C++ 2005 security warnings */

@@ -73,10 +75,9 @@

 #define NARGS 20

-HINSTANCE ThisInstance(void)
-    {
-    return GetModuleHandle(NULL);
-    }
+HINSTANCE ThisInstance(void) {
+  return GetModuleHandle(NULL);
+}

 /* Debug */

@@ -87,20 +88,19 @@

 #include "MsgNames.h"

-void _cdecl OutputDebugF(const char *pszFormat, ...)
-    {
-    char szLine[1024];
-    va_list pArgs;
-    int n;
-
-    va_start(pArgs, pszFormat);
-    n = wvsprintf(szLine, pszFormat, pArgs);	// Non-portable. pArgs not guarantied to point to the next argument.
-    va_end(pArgs);
-
-    OutputDebugString(szLine);
-
-    return;
-    }
+void _cdecl OutputDebugF(const char *pszFormat, ...) {
+  char szLine[1024];
+  va_list pArgs;
+  int n;
+
+  va_start(pArgs, pszFormat);
+  n = wvsprintf(szLine, pszFormat, pArgs);	// Non-portable. pArgs not guarantied to point to the next argument.
+  va_end(pArgs);
+
+  OutputDebugString(szLine);
+
+  return;
+}
 #else
 #define DEBUG_VERSION
 #endif // defined(_DEBUG)
@@ -124,6 +124,7 @@
 int messagefxEnd(HWND *phWnd);
 #endif // defined(USEHIDDENWINDOW)
 int PromptWindow(const char *pszTitle, const char *pszPrompt, char *pszBuffer, int iLength);
+int unescape(char *pszString);

 /*---------------------------------------------------------------------------*\
 *                                                                             *
@@ -150,16 +151,15 @@
 #define main main_ // Avoid having a main label, to make sure we're a Windows app.
 int main(int argc, char *argv[]);

-int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int iCmdShow)
-    {
-    char *argv[NARGS];
-    int argc;
-
-    // Break the argument line
-    argc = BreakArgLine(lpszCmdLine, argv, NARGS);
-
-    return main(argc, argv);
-    }
+int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int iCmdShow) {
+  char *argv[NARGS];
+  int argc;
+
+  // Break the argument line
+  argc = BreakArgLine(lpszCmdLine, argv, NARGS);
+
+  return main(argc, argv);
+}

 #endif // WINMAIN_NEEDED

@@ -186,263 +186,237 @@

 HWND hWndHidden;	    // The hidden window that solves our problems

-void __cdecl CleanupHiddenWindow(void)
+void __cdecl CleanupHiddenWindow(void) {
+  if (hWndHidden) messagefxEnd(&hWndHidden);    // Destroy the hidden window.
+}
+
+#endif // defined(USEHIDDENWINDOW)
+
+int main(int argc, char *argv[]) {
+  int i;
+  int iFormat = 0;
+  char *pszFormat = NULL;
+  char *pszTitle = "";
+  UINT uiStyle = MB_OK | MB_TOPMOST | MB_TASKMODAL;
+  int iRet;
+  char *pszOpenFile = NULL;	// If not NULL, display open file dialog box, and store result in given output file.
+  char *pszBatch = "MBResult.bat";
+  char *pszPrompt = NULL;
+  char szBatch[MAX_PATH];
+  HANDLE hf;
+
+  /* Process arguments */
+
+  for (i=1; i<argc; i++) {
+    char *arg = argv[i];
+    if (IsSwitch(arg)) {		    /* It's a switch */
+      char *opt = arg+1;
+      if (streq(opt, "?")) {			/* -?: Help */
+	usage();
+	return 0;
+      }
+      if (streq(opt, "b") || streq(opt, "batch")) {
+	if (((i+1) < argc) && !IsSwitch(argv[i+1])) {
+	  pszBatch = argv[++i];
+	}
+	continue;
+      }
+      if (streq(opt, "c") || streq(opt, "cancel")) {
+	uiStyle |= MB_OKCANCEL;
+	continue;
+      }
+#ifdef _DEBUG
+      if (streq(opt, "d") || streq(opt, "debug")) {
+	iDebug = TRUE;
+	continue;
+      }
+#endif
+      if (streq(opt, "e") || streq(opt, "edit")) {
+	if (((i+1) < argc) && !IsSwitch(argv[i+1]))
+	  pszPrompt = argv[++i];
+	else
+	  pszPrompt = "";
+	continue;
+      }
+      if (streq(opt, "i") || streq(opt, "information")) {
+	uiStyle |= MB_ICONINFORMATION;
+	continue;
+      }
+      if (streq(opt, "o") || streq(opt, "openfile")) {
+	if (((i+1) < argc) && !IsSwitch(argv[i+1]))
+	  pszOpenFile = argv[++i];
+	else
+	  pszOpenFile = "C:\\";
+	continue;
+      }
+      if (streq(opt, "q") || streq(opt, "question")) {
+	uiStyle |= MB_ICONQUESTION;
+	continue;
+      }
+      if (streq(opt, "s") || streq(opt, "stop")) {
+	uiStyle |= MB_ICONSTOP;
+	continue;
+      }
+      if (streq(opt, "t") || streq(opt, "title")) {
+	if (((i+1) < argc) && !IsSwitch(argv[i+1])) pszTitle = argv[++i];
+	continue;
+      }
+      if (streq(opt, "V") || streq(opt, "title")) {
+	puts(DETAILED_VERSION);
+	return 0;
+      }
+      if (streq(opt, "x") || streq(opt, "exclamation")) {
+	uiStyle |= MB_ICONEXCLAMATION;
+	continue;
+      }
+      // Unsupported switch!
+      // Fall through
+    }
+    iFormat = i;
+    pszFormat = argv[i];
+    unescape(pszFormat);	// Remove C escape sequences, like \n \xXX
+    break;			// All following arguments to be displayed
+  }
+
+  // Convert relative names to absolute before GetOpenFileName() changes the current directory.
+  GetFullPathName(pszBatch, sizeof(szBatch), szBatch, NULL);
+
+#if defined(USEHIDDENWINDOW)
+  // Create a hidden window. Its only reason for being is that its very existence
+  // forces MessageBox() to wait for the closure of the message box before returning!
+  // ~~JFL 2001-09-25 This does not seem necessary if the application is a console app instead of a Windows app.
+  hWndHidden = messagefx(NULL, "MsgBox.exe helper window", SW_HIDE, "You should not see this...");
+  atexit(CleanupHiddenWindow);
+#endif // defined(USEHIDDENWINDOW)
+
+  /* Case of OpenFile request */
+
+  if (pszOpenFile) {
+    char szSelected[MAX_PATH+13] = "SET MBRESULT=";
+    OPENFILENAME ofn = {
+      sizeof(OPENFILENAME),	//  DWORD         lStructSize;
+      NULL,			//  HWND          hwndOwner;
+      ThisInstance(),		//  HINSTANCE     hInstance;
+      NULL,			//  LPCTSTR       lpstrFilter;
+      NULL,			//  LPTSTR        lpstrCustomFilter;
+      0,			//  DWORD         nMaxCustFilter;
+      0,			//  DWORD         nFilterIndex;
+      szSelected+13,		//  LPTSTR        lpstrFile;
+      sizeof(szSelected)-13,	//  DWORD         nMaxFile;
+      NULL,			//  LPTSTR        lpstrFileTitle;
+      0,			//  DWORD         nMaxFileTitle;
+      pszOpenFile,		//  LPCTSTR       lpstrInitialDir;
+      pszTitle,			//  LPCTSTR       lpstrTitle;
+      OFN_LONGNAMES,		//  DWORD         Flags;
+      0,			//  WORD          nFileOffset;
+      0,			//  WORD          nFileExtension;
+      NULL,			//  LPCTSTR       lpstrDefExt;
+      0,			//  LPARAM        lCustData;
+      NULL,			//  LPOFNHOOKPROC lpfnHook;
+      NULL,			//  LPCTSTR       lpTemplateName;
+    };
+    BOOL bResult;
+
+    // Launch the Open File dialog box.
+    bResult = GetOpenFileName(&ofn);	// Open the standard dialog box for finding files.
+    if (!bResult) {
+      DWORD dwErr = CommDlgExtendedError();
+      MessageBoxF("MsgBox.exe debug error", MB_OK | MB_TOPMOST, "Returned err 0x%x.\n", dwErr);
+      exit(252);
+    }
+    // MessageBoxF("MsgBox.exe debug", MB_OK | MB_TOPMOST, "Returned 0x%x for File %s\n", bResult, szSelected);
+
+    // Output the result into a batch file to call as a subroutine of the parent batch.
+    hf = CreateFile(szBatch,	// file name
+		    GENERIC_READ | GENERIC_WRITE,    // access mode
+		    0,              // share mode
+		    NULL,		// SD
+		    CREATE_ALWAYS,  // how to create: Erase if already existing.
+		    FILE_ATTRIBUTE_NORMAL,	// file attributes
+		    NULL);          // handle to template file
+    if (hf != INVALID_HANDLE_VALUE) {
+      DWORD dw;
+      WriteFile(hf, szSelected, strlen(szSelected), &dw, NULL);
+      WriteFile(hf, "\r\n", 2, &dw, NULL);
+      CloseHandle(hf);
+    } else {
+      MessageBoxF("MsgBox.exe error", MB_OK | MB_TOPMOST, "Cannot open file %s\n", szBatch);
+    }
+
+    exit(0);
+  }
+
+  // Other cases require a message string/
+
+  if (!pszFormat) {
+    usage();
+    return 255;
+  }
+
+  /* Case of Prompt Window */
+
+  if (pszPrompt) {
+    char szBuf[256] = "SET MBRESULT=";
+    int iStart = strlen(szBuf);
+    strcat(szBuf, pszPrompt);
+
+    iRet = PromptWindow(pszTitle, pszFormat, szBuf+iStart, sizeof(szBuf)-iStart);
+
+    // Output the result into a batch file to call as a subroutine of the parent batch.
+    hf = CreateFile(szBatch,	// file name
+		    GENERIC_READ | GENERIC_WRITE,    // access mode
+		    0,              // share mode
+		    NULL,		// SD
+		    CREATE_ALWAYS,  // how to create: Erase if already existing.
+		    FILE_ATTRIBUTE_NORMAL,	// file attributes
+		    NULL);          // handle to template file
+    if (hf != INVALID_HANDLE_VALUE) {
+      DWORD dw;
+      WriteFile(hf, szBuf, strlen(szBuf), &dw, NULL);
+      WriteFile(hf, "\r\n", 2, &dw, NULL);
+      CloseHandle(hf);
+    } else {
+      MessageBoxF("MsgBox.exe error", MB_OK | MB_TOPMOST, "Cannot open file %s\n", szBatch);
+    }
+
+    exit(iRet);
+  }
+
+  /* Default: Standard message box */
+
+  if (pszFormat[0] == '@') {
+    long lSize;
+    HFILE hFile;
+
+    hFile = _lopen(pszFormat+1, OF_READ);
+    if (hFile == HFILE_ERROR) {
+      MessageBoxF("MsgBox.exe Error", MB_OK | MB_TOPMOST, "Cannot open file %s.\n", pszFormat+1);
+      return 254;
+    }
+    // Get the file size.
     {
-    if (hWndHidden) messagefxEnd(&hWndHidden);    // Destroy the hidden window.
+    long lPos = _llseek(hFile, 0, FILE_CURRENT);	// Current position
+    lSize = _llseek(hFile, 0, FILE_END);		// Find the position of the end
+    _llseek(hFile, lPos, FILE_BEGIN);		// Return to the initial position
     }

-#endif // defined(USEHIDDENWINDOW)
-
-int main(int argc, char *argv[])
-    {
-    int i;
-    int iFormat = 0;
-    char *pszFormat = NULL;
-    char *pszTitle = "";
-    UINT uiStyle = MB_OK | MB_TOPMOST | MB_TASKMODAL;
-    int iRet;
-    char *pszOpenFile = NULL;	// If not NULL, display open file dialog box, and store result in given output file.
-    char *pszBatch = "MBResult.bat";
-    char *pszPrompt = NULL;
-    char szBatch[MAX_PATH];
-    HANDLE hf;
-
-    /* Process arguments */
-
-    for (i=1; i<argc; i++)
-        {
-	if (IsSwitch(argv[i]))		    /* It's a switch */
-            {
-	    if (streq(argv[i]+1, "?"))		/* -?: Help */
-                {
-		usage();
-                return 0;
-		}
-	    if (streq(argv[i]+1, "b") || streq(argv[i]+1, "batch"))
-                {
-		if (((i+1) < argc) && !IsSwitch(argv[i+1]))
-		    {
-		    pszBatch = argv[++i];
-		    }
-                continue;
-		}
-	    if (streq(argv[i]+1, "c") || streq(argv[i]+1, "cancel"))
-                {
-		uiStyle |= MB_OKCANCEL;
-                continue;
-		}
-	    if (streq(argv[i]+1, "debug"))
-                {
-		iDebug = TRUE;
-                continue;
-		}
-	    if (streq(argv[i]+1, "e") || streq(argv[i]+1, "edit"))
-                {
-		if (((i+1) < argc) && !IsSwitch(argv[i+1]))
-		    pszPrompt = argv[++i];
-		else
-		    pszPrompt = "";
-                continue;
-		}
-	    if (streq(argv[i]+1, "i") || streq(argv[i]+1, "information"))
-                {
-		uiStyle |= MB_ICONINFORMATION;
-                continue;
-		}
-	    if (streq(argv[i]+1, "o") || streq(argv[i]+1, "openfile"))
-                {
-		if (((i+1) < argc) && !IsSwitch(argv[i+1]))
-		    pszOpenFile = argv[++i];
-		else
-		    pszOpenFile = "C:\\";
-                continue;
-		}
-	    if (streq(argv[i]+1, "q") || streq(argv[i]+1, "question"))
-                {
-		uiStyle |= MB_ICONQUESTION;
-                continue;
-		}
-	    if (streq(argv[i]+1, "s") || streq(argv[i]+1, "stop"))
-                {
-		uiStyle |= MB_ICONSTOP;
-                continue;
-		}
-	    if (streq(argv[i]+1, "t") || streq(argv[i]+1, "title"))
-                {
-		if (((i+1) < argc) && !IsSwitch(argv[i+1])) pszTitle = argv[++i];
-                continue;
-		}
-	    if (streq(argv[i]+1, "V") || streq(argv[i]+1, "title"))
-                {
-		puts(DETAILED_VERSION);
-		return 0;
-                }
-	    if (streq(argv[i]+1, "x") || streq(argv[i]+1, "exclamation"))
-                {
-		uiStyle |= MB_ICONEXCLAMATION;
-                continue;
-		}
-	    // Unsupported switch!
-	    // Fall through
-            }
-	iFormat = i;
-	pszFormat = argv[i];
-	break;		// All following arguments to be displayed
-	}
-
-    // Convert relative names to absolute before GetOpenFileName() changes the current directory.
-    GetFullPathName(pszBatch, sizeof(szBatch), szBatch, NULL);
-
-#if defined(USEHIDDENWINDOW)
-    // Create a hidden window. Its only reason for being is that its very existence
-    // forces MessageBox() to wait for the closure of the message box before returning!
-    // ~~JFL 2001-09-25 This does not seem necessary if the application is a console app instead of a Windows app.
-    hWndHidden = messagefx(NULL, "MsgBox.exe helper window", SW_HIDE, "You should not see this...");
-    atexit(CleanupHiddenWindow);
-#endif // defined(USEHIDDENWINDOW)
-
-    /* Case of OpenFile request */
-
-    if (pszOpenFile)
-	{
-	char szSelected[MAX_PATH+13] = "SET MBRESULT=";
-	OPENFILENAME ofn =
-	    {
-	    sizeof(OPENFILENAME),	//  DWORD         lStructSize;
-	    NULL,			//  HWND          hwndOwner;
-	    ThisInstance(),		//  HINSTANCE     hInstance;
-	    NULL,			//  LPCTSTR       lpstrFilter;
-	    NULL,			//  LPTSTR        lpstrCustomFilter;
-	    0,				//  DWORD         nMaxCustFilter;
-	    0,				//  DWORD         nFilterIndex;
-	    szSelected+13,		//  LPTSTR        lpstrFile;
-	    sizeof(szSelected)-13,	//  DWORD         nMaxFile;
-	    NULL,			//  LPTSTR        lpstrFileTitle;
-	    0,				//  DWORD         nMaxFileTitle;
-	    pszOpenFile,		//  LPCTSTR       lpstrInitialDir;
-	    pszTitle,			//  LPCTSTR       lpstrTitle;
-	    OFN_LONGNAMES,		//  DWORD         Flags;
-	    0,				//  WORD          nFileOffset;
-	    0,				//  WORD          nFileExtension;
-	    NULL,			//  LPCTSTR       lpstrDefExt;
-	    0,				//  LPARAM        lCustData;
-	    NULL,			//  LPOFNHOOKPROC lpfnHook;
-	    NULL,			// LPCTSTR       lpTemplateName;
-	    };
-	BOOL bResult;
-
-	// Launch the Open File dialog box.
-	bResult = GetOpenFileName(&ofn);	// Open the standard dialog box for finding files.
-	if (!bResult)
-	    {
-	    DWORD dwErr = CommDlgExtendedError();
-	    MessageBoxF("MsgBox.exe debug error", MB_OK | MB_TOPMOST, "Returned err 0x%x.\n", dwErr);
-	    exit(252);
-	    }
-	// MessageBoxF("MsgBox.exe debug", MB_OK | MB_TOPMOST, "Returned 0x%x for File %s\n", bResult, szSelected);
-
-	// Output the result into a batch file to call as a subroutine of the parent batch.
-	hf = CreateFile(szBatch,	// file name
-			GENERIC_READ | GENERIC_WRITE,    // access mode
-			0,              // share mode
-			NULL,		// SD
-			CREATE_ALWAYS,  // how to create: Erase if already existing.
-			FILE_ATTRIBUTE_NORMAL,	// file attributes
-			NULL);          // handle to template file
-	if (hf != INVALID_HANDLE_VALUE)
-	    {
-	    DWORD dw;
-	    WriteFile(hf, szSelected, strlen(szSelected), &dw, NULL);
-	    WriteFile(hf, "\r\n", 2, &dw, NULL);
-	    CloseHandle(hf);
-	    }
-	else
-	    {
-	    MessageBoxF("MsgBox.exe error", MB_OK | MB_TOPMOST, "Cannot open file %s\n", szBatch);
-	    }
-
-	exit(0);
-	}
-
-    // Other cases require a message string/
-
-    if (!pszFormat)
-	{
-	usage();
-	return 255;
-	}
-
-    /* Case of Prompt Window */
-
-    if (pszPrompt)
-	{
-	char szBuf[256] = "SET MBRESULT=";
-	int iStart = strlen(szBuf);
-	strcat(szBuf, pszPrompt);
-
-	iRet = PromptWindow(pszTitle, pszFormat, szBuf+iStart, sizeof(szBuf)-iStart);
-
-	// Output the result into a batch file to call as a subroutine of the parent batch.
-	hf = CreateFile(szBatch,	// file name
-			GENERIC_READ | GENERIC_WRITE,    // access mode
-			0,              // share mode
-			NULL,		// SD
-			CREATE_ALWAYS,  // how to create: Erase if already existing.
-			FILE_ATTRIBUTE_NORMAL,	// file attributes
-			NULL);          // handle to template file
-	if (hf != INVALID_HANDLE_VALUE)
-	    {
-	    DWORD dw;
-	    WriteFile(hf, szBuf, strlen(szBuf), &dw, NULL);
-	    WriteFile(hf, "\r\n", 2, &dw, NULL);
-	    CloseHandle(hf);
-	    }
-	else
-	    {
-	    MessageBoxF("MsgBox.exe error", MB_OK | MB_TOPMOST, "Cannot open file %s\n", szBatch);
-	    }
-
-	exit(iRet);
-	}
-
-    /* Default: Standard message box */
-
-    if (pszFormat[0] == '@')
-	{
-	long lSize;
-	HFILE hFile;
-
-	hFile = _lopen(pszFormat+1, OF_READ);
-	if (hFile == HFILE_ERROR)
-	    {
-	    MessageBoxF("MsgBox.exe Error", MB_OK | MB_TOPMOST, "Cannot open file %s.\n", pszFormat+1);
-	    return 254;
-	    }
-	// Get the file size.
-	{
-	long lPos = _llseek(hFile, 0, FILE_CURRENT);	// Current position
-	lSize = _llseek(hFile, 0, FILE_END);		// Find the position of the end
-	_llseek(hFile, lPos, FILE_BEGIN);		// Return to the initial position
-	}
-
-	pszFormat = malloc(lSize);
-	if (!pszFormat)
-	    {
-	    MessageBoxF("MsgBox.exe Error", MB_OK | MB_TOPMOST, "Not enough memory.\n");
-	    return 253;
-	    }
-	_lread(hFile, pszFormat, lSize);
-	_lclose(hFile);
-	}
-
-    i = iFormat;
-    iRet = MessageBoxF(pszTitle, uiStyle, pszFormat, argv[i+1], argv[i+2], argv[i+3], argv[i+4], argv[i+5], argv[i+6], argv[i+7], argv[i+8], argv[i+9]);
-    iRet -= 1;	// Change from 1-based to 0-based. 0=OK.
-
-    /* Terminate, reporting success */
-
-    return iRet;
+    pszFormat = malloc(lSize);
+    if (!pszFormat) {
+      MessageBoxF("MsgBox.exe Error", MB_OK | MB_TOPMOST, "Not enough memory.\n");
+      return 253;
     }
+    _lread(hFile, pszFormat, lSize);
+    _lclose(hFile);
+  }
+
+  i = iFormat;
+  iRet = MessageBoxF(pszTitle, uiStyle, pszFormat, argv[i+1], argv[i+2], argv[i+3], argv[i+4], argv[i+5], argv[i+6], argv[i+7], argv[i+8], argv[i+9]);
+  iRet -= 1;	// Change from 1-based to 0-based. 0=OK.
+
+  /* Terminate, reporting success */
+
+  return iRet;
+}

 /*---------------------------------------------------------------------------*\
 *                                                                             *
@@ -459,12 +433,11 @@
 *									      *
 \*---------------------------------------------------------------------------*/

-void usage(void)
-    {
+void usage(void) {
 #if 0
-    MessageBoxF("Usage", MB_OK | MB_TOPMOST,
+  MessageBoxF("Usage", MB_OK | MB_TOPMOST,
 #else
-    printf(
+  printf(
 PROGRAM_NAME_AND_VERSION " - " PROGRAM_DESCRIPTION "\n\
 \n\
 Usage:\n\
@@ -472,26 +445,31 @@
 "
 #endif
 "\
-[start /b [/w]] MsgBox [switches] {message}\n\
+[start /b [/w]] MsgBox [SWITCHES] MESSAGE [ARGUMENTS]\n\
 \n\
 Optional switches:\n\
-  -b {bat}	Set output batch name for opts -e, -o. Default: MBResult.bat.\n\
-		Content: \"set MBRESULT=string\".\n\
-  -c		Add a cancel button.\n\
-  -e [init]	Add an edit box below the message. Default initial value: \"\".\n\
+  -b BATCH      Set output batch name for opts -e, -o. Default: MBResult.bat\n\
+                Content: \"set MBRESULT=string\"\n\
+  -c            Add a cancel button.\n"
+#ifdef _DEBUG
+"\
+  -d            Enable debug output.\n"
+#endif
+"\
+  -e [INIT]     Add an edit box below the message. Default initial value: \"\"\n\
                 Creates a batch file with the input text. See option -b.\n\
-  -i		Add an (i)nformation icon.\n\
-  -o [init]	Display an Open File dialog box. Default initial path: C:\\.\n\
+  -i            Add an (i)nformation icon.\n\
+  -o [PATH]     Display an Open File dialog box. Default initial path: C:\\\n\
                 Creates a batch file with the selected path. See option -b.\n\
-  -q		Add a question-mark icon.\n\
-  -s		Add a stop-sign icon.\n\
-  -t \"title\"	String to put on the title bar.\n\
-  -x		Add an exclamation-point icon.\n\
+  -q            Add a question-mark icon.\n\
+  -s            Add a stop-sign icon.\n\
+  -t TITLE      String to put on the title bar.\n\
+  -x            Add an exclamation-point icon.\n\
 \n\
 Message:\n\
-  \"a string to display\"	Use \\n or \\xXX for special characters.\n\
-  \"a %%s found\" {string}	%%s replaced by the {string} argument.\n\
-  @inputfile		Display contents from this file.\n\
+  \"a string to display\"   Use \\n or or \\t or \\xXX for special characters.\n\
+  \"a %%s found\" STRING     %%s replaced by the STRING argument.\n\
+  @inputfile              Display contents from this file.\n\
 \n\
 ErrorLevel return value:\n\
   0=OK  1=Cancel  2=Abort  3=Retry  4=Ignore  5=Yes  6=No  7=Close  8=Help\n\
@@ -499,8 +477,8 @@
 Author: Jean-Francois Larvoire - jf.larvoire@hpe.com or jf.larvoire@free.fr\n\
 ");

-    return;
-    }
+  return;
+}

 /*---------------------------------------------------------------------------*\
 *                                                                             *
@@ -519,29 +497,92 @@
 *									      *
 \*---------------------------------------------------------------------------*/

-int IsSwitch(char *pszArg)
-    {
-    switch (*pszArg)
-	{
-	case '-':
-	case '/':
-	    return TRUE;
-	default:
-	    return FALSE;
+int IsSwitch(char *pszArg) {
+  switch (*pszArg) {
+    case '-':
+    case '/':
+      return TRUE;
+    default:
+      return FALSE;
+  }
+}
+
+/*---------------------------------------------------------------------------*\
+*                                                                             *
+|   Function	    unescape						      |
+|									      |
+|   Description	    Remove C escape sequences, like \r \n \xXX		      |
+|									      |
+|   Parameters	    char *pszString	    String to unescape in place       |
+|									      |
+|   Returns	    The new length of the string			      |
+|									      |
+|   Notes	    Necessary since a 2014-03-04 change in the MsvclibX       |
+|		    version of BreakArgLine(), that removed this feature      |
+|		    to be compatible with MS C library.			      |
+|		    							      |
+|		    Can be done in place, as the unescaped string is always   |
+|		    shorter than the original.				      |
+|		    							      |
+|   History								      |
+|    2020-01-14 JFL Created this routine				      |
+*									      *
+\*---------------------------------------------------------------------------*/
+
+int unescape(char *pszString) {
+  char *pszIn;
+  char *pszOut;
+  char c;
+
+#ifdef _DEBUG
+  if (iDebug) printf("unescape(\"%s\")\n", pszString);
+#endif
+
+  for (pszIn = pszOut = pszString; *pszIn; ) {
+    c = *(pszIn++);
+    if (c == '\\') {
+      c = *(pszIn++);
+      switch (c) {
+	case 'n': c = '\n'; break;
+	case 'r': c = '\r'; break;
+	case 't': c = '\t'; break;
+	case 'x': {
+	  char szBuf[3];
+	  char *pszEnd;
+	  szBuf[0] = pszIn[0];
+	  szBuf[1] = pszIn[0] ? pszIn[1] : '\0';
+	  szBuf[2] = '\0';
+	  c = (char)strtoul(szBuf, &pszEnd, 16);
+	  pszIn += (pszEnd - szBuf);
+	  break;
 	}
+	default: break;	// Ignore others, including \ and ".
+      }
     }
+    *(pszOut++) = c;
+  }
+  *pszOut = '\0';
+
+#ifdef _DEBUG
+  if (iDebug) printf("  return %d; // \"%s\"\n", (pszOut - pszString), pszString);
+#endif
+
+  return (int)(pszOut - pszString); // The new string length
+}
+
+#if WINMAIN_NEEDED && !HAS_MSVCLIBX

 /*---------------------------------------------------------------------------*\
 *                                                                             *
 |   Function	    BreakArgLine                                              |
 |                                                                             |
-|   Description	    Break the DOS command line into standard C arguments      |
+|   Description     Break the Windows command line into standard C arguments  |
 |                                                                             |
-|   Parameters	    LPSTR fpParms       NUL-terminated argument line          |
+|   Parameters      LPSTR pszCmdLine    NUL-terminated argument line          |
 |                   char *pszArg[]      Array of arguments pointers           |
 |                   int iMaxArgs        Number of elements in pszArg          |
 |                                                                             |
-|   Returns         int argc            Number of arguments found             |
+|   Returns         int argc            Number of arguments found. -1 = Error |
 |                                                                             |
 |   Notes           This routine does not set argv[0] to the program name.    |
 |                                                                             |
@@ -554,82 +595,74 @@
 |    2001-09-18 JFL Set argv[0] with actual module file name.		      |
 |                   Manage quoted strings as a single argument.               |
 |    2001-09-25 JFL Only process \x inside strings.                           |
+|    2017-02-05 JFL Check memory allocation errors, and if so return -1.      |
+|    2020-01-14 JFL Merged in some changes from MsvcLibx\SRC\main.c.          |
 *                                                                             *
 \*---------------------------------------------------------------------------*/

-int BreakArgLine(LPSTR fpParms, char *ppszArg[], int iMaxArgs)
-    {
-    int i, j;
-    int argc;
-    char c, c0;
-    char *pszCopy;
-    int iString = FALSE;
-    int iQuote = FALSE;
-    static char szModule[MAX_PATH] = {0};
-
-    if (!szModule[0]) GetModuleFileName(NULL, szModule, sizeof(szModule));
-    ppszArg[0] = szModule;
-
-    /* Make a local copy of the argument line */
-    /* Break down the local copy into standard C arguments */
-
-    pszCopy = malloc(lstrlen(fpParms) + 1);
-    // Copy the string, managing quoted characters
-    for (i=0, j=0, iQuote = FALSE, argc=1, c0='\0'; argc<iMaxArgs; i++)
-	{
-	c = fpParms[i];
-	if (!c)		    // End of argument line
-	    {
-	    pszCopy[j++] = c;
-	    break;
-	    }
-	if (iQuote)
-	    {
-	    iQuote = FALSE;
-	    switch (c)
-		{
-		char *pc;
-		case 'n': c = '\n'; break;
-		case 'r': c = '\r'; break;
-		case 'x': c = (char)strtoul(fpParms+i+1, &pc, 16); i = (int)(pc-fpParms); i-=1; break;
-		default: break;	// Ignore others, including \ and ".
-		}
-	    }
-	else
-	    {
-	    if (iString && (c == '\\'))	    // Quoted character in string
-		{
-		iQuote = TRUE;
-		continue;
-		}
-	    if (c == '"')
-		{
-		iString = !iString;
-		if (iString) continue;
-		c = '\0';   // Force end of argument at end of string.
-		if (!c0)    // Case of empty string: Define an empty argument.
-		    {
-		    pszCopy[j] = '\0';
-		    ppszArg[argc] = pszCopy+j;
-		    argc += 1;
-		    j += 1;
-		    continue;
-		    }
-		}
-	    }
-	if ((!iString) && ((c == ' ') || (c == '\t'))) c = '\0';
-	pszCopy[j] = c;
-        if (c && !c0)
-            {
-            ppszArg[argc] = pszCopy+j;
-            argc += 1;
-            }
-        c0 = c;
-	j += 1;
+int BreakArgLine(LPSTR pszCmdLine, char *ppszArg[], int iMaxArgs) {
+  int i, j;
+  int argc = 0;
+  char c, c0;
+  char *pszCopy;
+  int iString = FALSE;	/* TRUE = string mode; FALSE = non-string mode */
+  int iQuote = FALSE;
+  static char szModule[MAX_PATH] = {0};
+
+  if (!szModule[0]) GetModuleFileName(NULL, szModule, sizeof(szModule));
+  ppszArg[0] = szModule;
+
+  /* Make a local copy of the argument line */
+  /* Break down the local copy into standard C arguments */
+
+  pszCopy = malloc(lstrlen(pszCmdLine) + 1);
+  if (!pszCopy) return -1;
+  /* Copy the string, managing quoted characters */
+  for (i=0, j=0, iQuote = FALSE, argc=1, c0='\0'; argc<iMaxArgs; i++) {
+    c = pszCmdLine[i];
+    if (!c) {		    /* End of argument line */
+      pszCopy[j++] = c;
+      break;
+    }
+    if (iQuote) {
+      iQuote = FALSE;
+      switch (c) {
+	char *pc;
+	case 'n': c = '\n'; break;
+	case 'r': c = '\r'; break;
+	case 'x': c = (char)strtoul(pszCmdLine+i+1, &pc, 16); i = (int)(pc-pszCmdLine); i-=1; break;
+	default: break;	// Ignore others, including \ and ".
+      }
+    } else {
+      if (iString && (c == '\\')) {	    // Quoted character in string
+	iQuote = TRUE;
+	continue;
+      }
+      if (c == '"') {
+	iString = !iString;
+	if (iString) continue;
+	c = '\0';   // Force end of argument at end of string.
+	if (!c0) {  // Case of empty string: Define an empty argument.
+	  pszCopy[j] = '\0';
+	  ppszArg[argc] = pszCopy+j;
+	  argc += 1;
+	  j += 1;
+	  continue;
 	}
-
-    return argc;
+      }
     }
+    if ((!iString) && ((c == ' ') || (c == '\t'))) c = '\0';
+    pszCopy[j] = c;
+    if (c && !c0) {
+      ppszArg[argc] = pszCopy+j;
+      argc += 1;
+    }
+    c0 = c;
+    j += 1;
+  }
+
+  return argc;
+}

 /*---------------------------------------------------------------------------*\
 *                                                                             *
@@ -657,19 +690,20 @@

 _CRTIMP extern char *_acmdln;

-int __cdecl _setargv(void)
-    {
-    static char *argv[NARGS];
-
-    // Break the argument line
-    __argc = BreakArgLine(_acmdln, argv, NARGS) - 1;
-    __argv = argv+1;	// _acmdln has a copy of the program name.
-    _pgmptr = argv[0];
-
-    return 0;
-    }
+int __cdecl _setargv(void) {
+  static char *argv[NARGS];
+
+  // Break the argument line
+  __argc = BreakArgLine(_acmdln, argv, NARGS) - 1;
+  __argv = argv+1;	// _acmdln has a copy of the program name.
+  _pgmptr = argv[0];
+
+  return 0;
+}

 #endif
+
+#endif // WINMAIN_NEEDED && !HAS_MSVCLIBX

 /*---------------------------------------------------------------------------*\
 *                                                                             *
@@ -694,18 +728,17 @@
 *									      *
 \*---------------------------------------------------------------------------*/

-int _cdecl MessageBoxF(char *pszTitle, UINT uiStyle, const char *pszFormat, ...)
-    {
-    char szLine[1024];
-    va_list pArgs;
-    int n;
-
-    va_start(pArgs, pszFormat);
-    n = wvsprintf(szLine, pszFormat, pArgs);	// Non-portable. pArgs not guarantied to point to the next argument.
-    va_end(pArgs);
-
-    return MessageBox(NULL, szLine, pszTitle, uiStyle);
-    }
+int _cdecl MessageBoxF(char *pszTitle, UINT uiStyle, const char *pszFormat, ...) {
+  char szLine[1024];
+  va_list pArgs;
+  int n;
+
+  va_start(pArgs, pszFormat);
+  n = wvsprintf(szLine, pszFormat, pArgs);	// Non-portable. pArgs not guarantied to point to the next argument.
+  va_end(pArgs);
+
+  return MessageBox(NULL, szLine, pszTitle, uiStyle);
+}

 #if defined(USEHIDDENWINDOW)

@@ -735,138 +768,128 @@
 *									      *
 \*---------------------------------------------------------------------------*/

-static LRESULT CALLBACK messagefxWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-    {
-    static char szLine[1024];
-    char *pc;
-    char *pc0;
-    int iLen;
-
-    switch (uMsg) {
-	case WM_CREATE:
-	    lstrcpy(szLine, ((LPCREATESTRUCT)lParam)->lpCreateParams);
-	    break;
-
-	case WM_USER:	    // Display another message in the same window.
-	    lstrcpy(szLine, (char *)lParam);
-	    InvalidateRect(hWnd, NULL, TRUE);
-	    UpdateWindow(hWnd);
-	    return 0;
-
-        case WM_PAINT:
-	    {
-	    HDC hDC;			/* display-context variable  */
-	    PAINTSTRUCT ps;		/* paint structure	     */
-	    int x, y;
-	    TEXTMETRIC tm;
-
-	    /* Set up a display context to begin painting */
-	    hDC = BeginPaint (hWnd, &ps);
-	    SetBkColor(hDC, GetSysColor(COLOR_MENU));
-
-	    GetTextMetrics(hDC, &tm);
-	    x = tm.tmMaxCharWidth;
-	    y = tm.tmHeight;
-
-	    for (pc=pc0=szLine; pc; pc0=pc+1)	// For every line
-		{
-		pc = strchr(pc0, '\n'); 	// Search end of line
-		if (pc)
-		    iLen = pc-pc0;
-		else
-		    iLen = lstrlen(pc0);
-		TextOut(hDC, x, y, pc0, iLen);
-		y += tm.tmHeight;
-		}
-
-            /* Tell Windows you are done painting */
-            EndPaint (hWnd,  &ps);
-
-	    return 0;
-	    }
-
-	default:
-	    break;
+static LRESULT CALLBACK messagefxWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+  static char szLine[1024];
+  char *pc;
+  char *pc0;
+  int iLen;
+
+  switch (uMsg) {
+    case WM_CREATE:
+	lstrcpy(szLine, ((LPCREATESTRUCT)lParam)->lpCreateParams);
+	break;
+
+    case WM_USER:	    // Display another message in the same window.
+	lstrcpy(szLine, (char *)lParam);
+	InvalidateRect(hWnd, NULL, TRUE);
+	UpdateWindow(hWnd);
+	return 0;
+
+    case WM_PAINT: {
+      HDC hDC;			/* display-context variable  */
+      PAINTSTRUCT ps;		/* paint structure	     */
+      int x, y;
+      TEXTMETRIC tm;
+
+      /* Set up a display context to begin painting */
+      hDC = BeginPaint (hWnd, &ps);
+      SetBkColor(hDC, GetSysColor(COLOR_MENU));
+
+      GetTextMetrics(hDC, &tm);
+      x = tm.tmMaxCharWidth;
+      y = tm.tmHeight;
+
+      for (pc=pc0=szLine; pc; pc0=pc+1)	{ // For every line
+	pc = strchr(pc0, '\n'); 	  // Search end of line
+	if (pc)
+	    iLen = pc-pc0;
+	else
+	    iLen = lstrlen(pc0);
+	TextOut(hDC, x, y, pc0, iLen);
+	y += tm.tmHeight;
+      }
+
+      /* Tell Windows you are done painting */
+      EndPaint (hWnd,  &ps);
+
+      return 0;
     }
-    return (DefWindowProc(hWnd, uMsg, wParam, lParam));
-}
-
-HWND _cdecl messagefx(HWND hWnd, const char *pszFormat, ...)
-    {
-    char szLine[1024];
-    va_list pArgs;
-    int n;
-    WNDCLASS wc;
-    static BOOL bRegistered = FALSE;
-    int iShow;
-    const char *pszTitle;
-
-    // Create our Window style (To be done only once)
-    if (!bRegistered)
-	{
-	wc.style = 0;
-	wc.lpfnWndProc = messagefxWindowProc;
-	wc.cbClsExtra = 0;
-	wc.cbWndExtra = 0;
-	wc.hInstance = ThisInstance();
-	wc.hIcon = NULL;
-	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
-	wc.hbrBackground = (HBRUSH)(COLOR_MENU+1);
-	wc.lpszMenuName = NULL;
-	wc.lpszClassName = "MfxWindowClass";
-
-	RegisterClass(&wc);
-
-	bRegistered = TRUE;
-	}
-
-    // Extract command line arguments
-    va_start(pArgs, pszFormat);
-    if (!hWnd)
-	{
-	pszTitle = pszFormat;
-	// Extract window creation parameters
-	iShow = va_arg(pArgs, int);
-	pszFormat = va_arg(pArgs, char *);
-	}
-    // Format the line to output
-    n = wvsprintf(szLine, pszFormat, pArgs);	// Non-portable. pArgs not guarantied to point to the next argument.
-    va_end(pArgs);
-
-    // Create a message window
-    if (!hWnd)
-	{
-	hWnd = CreateWindow(
-		"MfxWindowClass",   // pointer to registered class name
-		pszTitle,	    // pointer to window name
-		WS_BORDER | WS_CAPTION | WS_DISABLED | WS_POPUP, // window style
-	        (GetSystemMetrics(SM_CXFULLSCREEN) - 250)/2, // horizontal position of window: Centered
-	        (GetSystemMetrics(SM_CYFULLSCREEN) - 100)/2, // vertical position of window: Centered
-		250,		    // window width
-		100,		    // window height
-		NULL,		    // handle to parent or owner window
-		NULL,		    // handle to menu or child-window identifier
-		ThisInstance(),	    // handle to application instance
-		szLine);	    // pointer to window-creation data
-	ShowWindow(hWnd, iShow);
-	UpdateWindow(hWnd);
-	}
-    else
-	{
-	SendMessage(hWnd, WM_USER, 0, (LPARAM)szLine);
-	}
-
-    return hWnd;
-    }
-
-int messagefxEnd(HWND *phWnd)
-    {
-    int iErr = 0;
-
-    if (*phWnd) iErr = !DestroyWindow(*phWnd);
-    *phWnd = NULL;
-    return iErr;
-    }
+
+    default:
+	break;
+  }
+  return (DefWindowProc(hWnd, uMsg, wParam, lParam));
+}
+
+HWND _cdecl messagefx(HWND hWnd, const char *pszFormat, ...) {
+  char szLine[1024];
+  va_list pArgs;
+  int n;
+  WNDCLASS wc;
+  static BOOL bRegistered = FALSE;
+  int iShow;
+  const char *pszTitle;
+
+  // Create our Window style (To be done only once)
+  if (!bRegistered) {
+    wc.style = 0;
+    wc.lpfnWndProc = messagefxWindowProc;
+    wc.cbClsExtra = 0;
+    wc.cbWndExtra = 0;
+    wc.hInstance = ThisInstance();
+    wc.hIcon = NULL;
+    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+    wc.hbrBackground = (HBRUSH)(COLOR_MENU+1);
+    wc.lpszMenuName = NULL;
+    wc.lpszClassName = "MfxWindowClass";
+
+    RegisterClass(&wc);
+
+    bRegistered = TRUE;
+  }
+
+  // Extract command line arguments
+  va_start(pArgs, pszFormat);
+  if (!hWnd) {
+    pszTitle = pszFormat;
+    // Extract window creation parameters
+    iShow = va_arg(pArgs, int);
+    pszFormat = va_arg(pArgs, char *);
+  }
+  // Format the line to output
+  n = wvsprintf(szLine, pszFormat, pArgs);	// Non-portable. pArgs not guarantied to point to the next argument.
+  va_end(pArgs);
+
+  // Create a message window
+  if (!hWnd) {
+    hWnd = CreateWindow(
+	    "MfxWindowClass",   // pointer to registered class name
+	    pszTitle,	    // pointer to window name
+	    WS_BORDER | WS_CAPTION | WS_DISABLED | WS_POPUP, // window style
+	    (GetSystemMetrics(SM_CXFULLSCREEN) - 250)/2, // horizontal position of window: Centered
+	    (GetSystemMetrics(SM_CYFULLSCREEN) - 100)/2, // vertical position of window: Centered
+	    250,		    // window width
+	    100,		    // window height
+	    NULL,		    // handle to parent or owner window
+	    NULL,		    // handle to menu or child-window identifier
+	    ThisInstance(),	    // handle to application instance
+	    szLine);	    // pointer to window-creation data
+    ShowWindow(hWnd, iShow);
+    UpdateWindow(hWnd);
+  } else {
+    SendMessage(hWnd, WM_USER, 0, (LPARAM)szLine);
+  }
+
+  return hWnd;
+}
+
+int messagefxEnd(HWND *phWnd) {
+  int iErr = 0;
+
+  if (*phWnd) iErr = !DestroyWindow(*phWnd);
+  *phWnd = NULL;
+  return iErr;
+}

 #endif // defined(USEHIDDENWINDOW)

@@ -894,44 +917,42 @@
 *									      *
 \*---------------------------------------------------------------------------*/

-void GetMessageArea(HWND hWnd, char *pszMsg, PSIZE pSize)
-    {
-    HDC hDC;
-    PAINTSTRUCT ps;		/* paint structure	     */
-    int x, y;
-    int xMax;
-    char *pc0;
-    char *pc;
-    TEXTMETRIC tm;
-    int iLen;
-
-    /* Set up a display context to the window */
-    hDC = BeginPaint (hWnd, &ps);
-    GetTextMetrics(hDC, &tm);
-
-    x = 0;
-    y = 0;
-    xMax = 0;
-
-    for (pc=pc0=pszMsg; pc; pc0=pc+1)	// For every line
-	{
-	pc = strchr(pc0, '\n'); 	// Search end of line
-	if (pc)
-	    iLen = (int)(pc-pc0);
-	else
-	    iLen = lstrlen(pc0);
-	x = iLen * tm.tmAveCharWidth;
-	if (x > xMax) xMax = x;
-	y += tm.tmHeight;
-	}
-
-    EndPaint (hWnd,  &ps);
-
-    pSize->cx = xMax;
-    pSize->cy = y;
-
-    return;
-    }
+void GetMessageArea(HWND hWnd, char *pszMsg, PSIZE pSize) {
+  HDC hDC;
+  PAINTSTRUCT ps;		/* paint structure	     */
+  int x, y;
+  int xMax;
+  char *pc0;
+  char *pc;
+  TEXTMETRIC tm;
+  int iLen;
+
+  /* Set up a display context to the window */
+  hDC = BeginPaint (hWnd, &ps);
+  GetTextMetrics(hDC, &tm);
+
+  x = 0;
+  y = 0;
+  xMax = 0;
+
+  for (pc=pc0=pszMsg; pc; pc0=pc+1) {	// For every line
+    pc = strchr(pc0, '\n'); 	// Search end of line
+    if (pc)
+	iLen = (int)(pc-pc0);
+    else
+	iLen = lstrlen(pc0);
+    x = iLen * tm.tmAveCharWidth;
+    if (x > xMax) xMax = x;
+    y += tm.tmHeight;
+  }
+
+  EndPaint (hWnd,  &ps);
+
+  pSize->cx = xMax;
+  pSize->cy = y;
+
+  return;
+}

 /*---------------------------------------------------------------------------*\
 *                                                                             *
@@ -960,13 +981,12 @@
 #define CXBUTTON 77	// OK button width.
 #define CYBUTTON 27	// OK button height.

-typedef struct PromptWindowExtras
-    {
-    LONG_PTR hEdit;	    // Edit control child window
-    LONG_PTR pszOutBuf;	    // Output buffer for the input text
-    long lBufSize;	    // Size of the output buffer
-    int iExitCode;	    // The window exit code
-    } PromptWindowExtras, *PPWE;
+typedef struct PromptWindowExtras {
+  LONG_PTR hEdit;	    // Edit control child window
+  LONG_PTR pszOutBuf;	    // Output buffer for the input text
+  long lBufSize;	    // Size of the output buffer
+  int iExitCode;	    // The window exit code
+} PromptWindowExtras, *PPWE;
 #define PWEOFFSET(item) ((char *)&(((PPWE)NULL)->item) - (char *)&(((PPWE)NULL)->hEdit))

 #define ID_CHILDEDIT 101
@@ -974,236 +994,227 @@

 static LRESULT CALLBACK PromptWindowProc1(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

-static LRESULT CALLBACK PromptWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-    {
+static LRESULT CALLBACK PromptWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
 #ifdef _DEBUG
-    char szMsgName[64];
-    LRESULT lResult;
-    static int iShift = 0;
-
-    if (iDebug) OutputDebugF("PromptWindowProc[%d](0x%x, %s, 0x%x, 0x%x)\n", iShift, hWnd, GetMsgName(uMsg, szMsgName, sizeof(szMsgName)), wParam, lParam);
-
-    iShift++;
-
-    lResult = PromptWindowProc1(hWnd, uMsg, wParam, lParam);
-
-    iShift--;
-
-    if (iDebug) OutputDebugF("PromptWindowProc[%d]() returns 0x%x\n", iShift, lResult);
-
-    return lResult;
+  char szMsgName[64];
+  LRESULT lResult;
+  static int iShift = 0;
+
+  if (iDebug) OutputDebugF("PromptWindowProc[%d](0x%x, %s, 0x%x, 0x%x)\n", iShift, hWnd, GetMsgName(uMsg, szMsgName, sizeof(szMsgName)), wParam, lParam);
+
+  iShift++;
+
+  lResult = PromptWindowProc1(hWnd, uMsg, wParam, lParam);
+
+  iShift--;
+
+  if (iDebug) OutputDebugF("PromptWindowProc[%d]() returns 0x%x\n", iShift, lResult);
+
+  return lResult;
+}
+
+static LRESULT CALLBACK PromptWindowProc1(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+#endif // defined(_DEBUG)
+  static char szLine[1024] = "Le commentaire";
+  char *pc;
+  char *pc0;
+  int iLen;
+  HWND hWndEdit = (HWND)GetWindowLongPtr(hWnd, PWEOFFSET(hEdit));
+  char *pszBuf = (char *)GetWindowLongPtr(hWnd, PWEOFFSET(pszOutBuf));
+  HWND hWndButton;
+  SIZE size;
+  long lyEdit;
+  long lyButton;
+  NONCLIENTMETRICS ncm;
+
+  // char szMsgName[64];
+  // OutputDebugF("PromptWindowProc(%d, %s, 0x%x, 0x%x)\n", hWnd, GetMsgName(uMsg, szMsgName, sizeof(szMsgName)), wParam, lParam);
+
+  switch (uMsg) {
+    case WM_CREATE:
+      lstrcpy(szLine, ((LPCREATESTRUCT)lParam)->lpCreateParams);
+
+      GetMessageArea(hWnd, szLine, &size);
+      ncm.cbSize = sizeof(NONCLIENTMETRICS);
+      SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0);
+
+      size.cx += ncm.iBorderWidth;
+      size.cx += 10;  // 5 pixels margins on both sides
+      size.cx += ncm.iBorderWidth;
+      size.cx += 30;  // ???
+      if (size.cx < PWWIDTH) size.cx = PWWIDTH;
+
+      size.cy += ncm.iBorderWidth;;
+      size.cy += ncm.iCaptionHeight; // Title bar heigth
+      size.cy += 5;
+      lyEdit = size.cy;
+      size.cy += CYEDIT;
+      size.cy += 5;
+      lyButton = size.cy;
+      size.cy += CYBUTTON;
+      size.cy += 5;
+      size.cy += ncm.iBorderWidth;;
+      size.cy += 25;  // ???
+
+      MoveWindow(hWnd,      // handle to window
+		 (GetSystemMetrics(SM_CXFULLSCREEN) - size.cx)/2, // horizontal position of window: Centered
+		 (GetSystemMetrics(SM_CYFULLSCREEN) - size.cy)/2, // vertical position of window: Centered
+		 size.cx,	    // window width
+		 size.cy,	    // window height
+		 FALSE);	    // repaint option: Don't.
+
+      // Create the edit control
+      hWndEdit = CreateWindow(
+	"EDIT",     // predefined class
+	NULL,       // no window title
+	WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
+	5, lyEdit, size.cx-25, CYEDIT, // set size in WM_SIZE message
+	hWnd,       // parent window
+	(HMENU)ID_CHILDEDIT, // edit control ID
+	/* (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), */ /* Not supported by WIN64 */
+	(HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),
+	NULL);                // pointer not needed
+      SetWindowLongPtr(hWnd, PWEOFFSET(hEdit), (LONG_PTR)hWndEdit); // Save the child window handle.
+      // Note: The default content is later set by the main thread.
+
+      // Create the OK button
+      hWndButton = CreateWindow(
+	"BUTTON",   // predefined class
+	"OK",       // button text
+	WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // styles
+	// Size and position values are given explicitly, because
+	// the CW_USEDEFAULT constant gives zero values for buttons.
+	(size.cx - CXBUTTON)/2,         // starting x position: Centered
+	lyButton,         // starting y position
+	CXBUTTON,        // button width
+	CYBUTTON,        // button height
+	hWnd,       // parent window
+	(HMENU)ID_OK,       // No menu
+	/* (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), */ /* Not supported by WIN64 */
+	(HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),
+	NULL);      // pointer not needed
+
+      break;
+
+    case WM_COMMAND:
+      if (wParam == ID_OK) wParam = 1;   // User clicked [OK]. Do as if he pressed Enter.
+      if (   (wParam == 1)        // User pressed Enter
+	  || (wParam == 2)) {	// User pressed ESC
+	SetWindowLong(hWnd, PWEOFFSET(iExitCode), (LONG)wParam-1);	// Update the exit code.
+	*(WORD *)pszBuf = (WORD)GetWindowLong(hWnd, PWEOFFSET(lBufSize));
+	SendDlgItemMessage(hWnd,
+	    ID_CHILDEDIT,
+	    EM_GETLINE,
+	    (WPARAM) 0,       // line 0
+	    (LPARAM) pszBuf);
+	DestroyWindow(hWnd);
+	return wParam;
+      }
+      break;
+
+    case WM_DESTROY:
+      // SetEvent(hEvent);	    // Unblock the main thread
+      PostQuitMessage(GetWindowLong(hWnd, PWEOFFSET(iExitCode)));
+      break;
+
+    case WM_SETFOCUS:
+      SetFocus(hWndEdit);
+      return 0;
+
+    case WM_PAINT: {
+      HDC hDC;			/* display-context variable  */
+      PAINTSTRUCT ps;		/* paint structure	     */
+      int x, y;
+      TEXTMETRIC tm;
+
+      /* Set up a display context to begin painting */
+      hDC = BeginPaint (hWnd, &ps);
+      SetBkColor(hDC, GetSysColor(COLOR_MENU));
+
+      GetTextMetrics(hDC, &tm);
+      x = 5;
+      y = tm.tmHeight / 2;
+
+      for (pc=pc0=szLine; pc; pc0=pc+1)	{ // For every line
+	pc = strchr(pc0, '\n'); 	  // Search end of line
+	if (pc)
+	    iLen = (int)(pc-pc0);
+	else
+	    iLen = lstrlen(pc0);
+	TextOut(hDC, x, y, pc0, iLen);
+	y += tm.tmHeight;
+      }
+
+      /* Tell Windows you are done painting */
+      EndPaint (hWnd,  &ps);
+
+      return 0;
     }

-static LRESULT CALLBACK PromptWindowProc1(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-    {
-#endif // defined(_DEBUG)
-    static char szLine[1024] = "Le commentaire";
-    char *pc;
-    char *pc0;
-    int iLen;
-    HWND hWndEdit = (HWND)GetWindowLongPtr(hWnd, PWEOFFSET(hEdit));
-    char *pszBuf = (char *)GetWindowLongPtr(hWnd, PWEOFFSET(pszOutBuf));
-    HWND hWndButton;
-    SIZE size;
-    long lyEdit;
-    long lyButton;
-    NONCLIENTMETRICS ncm;
-
+    default:
+	break;
+  }
+
+  return DefWindowProc(hWnd, uMsg, wParam, lParam);
+}
+
+int PromptWindow(const char *pszTitle, const char *pszPrompt, char *pszBuffer, int iLength) {
+  WNDCLASS wc;
+  static BOOL bRegistered = FALSE;
+  HWND hWnd;
+  MSG msg;
+
+  // Create our Window style (To be done only once)
+  if (!bRegistered)
+      {
+      wc.style = 0;
+      wc.lpfnWndProc = PromptWindowProc;
+      wc.cbClsExtra = 0;
+      wc.cbWndExtra = sizeof(PromptWindowExtras);
+      wc.hInstance = ThisInstance();
+      wc.hIcon = NULL;
+      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+      wc.hbrBackground = (HBRUSH)(COLOR_MENU+1);
+      wc.lpszMenuName = NULL;
+      wc.lpszClassName = "PromptWindowClass";
+
+      RegisterClass(&wc);
+
+      bRegistered = TRUE;
+      }
+
+  // Create a Prompt window
+  hWnd = CreateWindow(
+	  "PromptWindowClass",   // pointer to registered class name
+	  pszTitle,	    // pointer to window name
+	  WS_BORDER | WS_POPUP | WS_DISABLED | WS_CAPTION, // window style
+	  (GetSystemMetrics(SM_CXFULLSCREEN) - PWWIDTH)/2, // horizontal position of window: Centered
+	  (GetSystemMetrics(SM_CYFULLSCREEN) - PWHEIGHT)/2, // vertical position of window: Centered
+	  PWWIDTH,		    // window width
+	  PWHEIGHT,		    // window height
+	  NULL,		    // handle to parent or owner window
+	  NULL,		    // handle to menu or child-window identifier
+	  ThisInstance(),	    // handle to application instance
+	  (LPVOID)pszPrompt);	    // pointer to window-creation data
+  SetWindowLongPtr(hWnd, PWEOFFSET(pszOutBuf), (LONG_PTR)pszBuffer);
+  SetWindowLong(hWnd, PWEOFFSET(lBufSize), (LONG_PTR)iLength);
+  SetWindowLong(hWnd, PWEOFFSET(iExitCode), 1);   // Assume failure
+  // Add default text to the window.
+  SendDlgItemMessage(hWnd, ID_CHILDEDIT, WM_SETTEXT, 0, (LPARAM)pszBuffer);
+  EnableWindow(hWnd, TRUE);	    // Allow user input
+  ShowWindow(hWnd, SW_SHOW);
+  UpdateWindow(hWnd);
+
+  // Message loop: Forward messages to the dialog box.
+  while (GetMessage(&msg, NULL, 0, 0)) { // Repeat until we receive WM_QUIT...
     // char szMsgName[64];
-    // OutputDebugF("PromptWindowProc(%d, %s, 0x%x, 0x%x)\n", hWnd, GetMsgName(uMsg, szMsgName, sizeof(szMsgName)), wParam, lParam);
-
-    switch (uMsg)
-	{
-	case WM_CREATE:
-	    lstrcpy(szLine, ((LPCREATESTRUCT)lParam)->lpCreateParams);
-
-	    GetMessageArea(hWnd, szLine, &size);
-	    ncm.cbSize = sizeof(NONCLIENTMETRICS);
-	    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0);
-
-	    size.cx += ncm.iBorderWidth;
-	    size.cx += 10;  // 5 pixels margins on both sides
-	    size.cx += ncm.iBorderWidth;
-	    size.cx += 30;  // ???
-	    if (size.cx < PWWIDTH) size.cx = PWWIDTH;
-
-	    size.cy += ncm.iBorderWidth;;
-	    size.cy += ncm.iCaptionHeight; // Title bar heigth
-	    size.cy += 5;
-	    lyEdit = size.cy;
-	    size.cy += CYEDIT;
-	    size.cy += 5;
-	    lyButton = size.cy;
-	    size.cy += CYBUTTON;
-	    size.cy += 5;
-	    size.cy += ncm.iBorderWidth;;
-	    size.cy += 25;  // ???
-
-	    MoveWindow(hWnd,      // handle to window
-		       (GetSystemMetrics(SM_CXFULLSCREEN) - size.cx)/2, // horizontal position of window: Centered
-		       (GetSystemMetrics(SM_CYFULLSCREEN) - size.cy)/2, // vertical position of window: Centered
-		       size.cx,	    // window width
-		       size.cy,	    // window height
-		       FALSE);	    // repaint option: Don't.
-
-	    // Create the edit control
-            hWndEdit = CreateWindow(
-                "EDIT",     // predefined class
-                NULL,       // no window title
-                WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
-                5, lyEdit, size.cx-25, CYEDIT, // set size in WM_SIZE message
-                hWnd,       // parent window
-                (HMENU)ID_CHILDEDIT, // edit control ID
-                /* (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), */ /* Not supported by WIN64 */
-                (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),
-                NULL);                // pointer not needed
-	    SetWindowLongPtr(hWnd, PWEOFFSET(hEdit), (LONG_PTR)hWndEdit); // Save the child window handle.
-	    // Note: The default content is later set by the main thread.
-
-	    // Create the OK button
-	    hWndButton = CreateWindow(
-		"BUTTON",   // predefined class
-		"OK",       // button text
-		WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // styles
- 		// Size and position values are given explicitly, because
-		// the CW_USEDEFAULT constant gives zero values for buttons.
-		(size.cx - CXBUTTON)/2,         // starting x position: Centered
-		lyButton,         // starting y position
-		CXBUTTON,        // button width
-		CYBUTTON,        // button height
-		hWnd,       // parent window
-		(HMENU)ID_OK,       // No menu
-                /* (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), */ /* Not supported by WIN64 */
-                (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),
-		NULL);      // pointer not needed
-
-	    break;
-
-	case WM_COMMAND:
-	    if (wParam == ID_OK) wParam = 1;   // User clicked [OK]. Do as if he pressed Enter.
-	    if (   (wParam == 1)        // User pressed Enter
-		|| (wParam == 2))	// User pressed ESC
-		{
-		SetWindowLong(hWnd, PWEOFFSET(iExitCode), (LONG)wParam-1);	// Update the exit code.
-		*(WORD *)pszBuf = (WORD)GetWindowLong(hWnd, PWEOFFSET(lBufSize));
-		SendDlgItemMessage(hWnd,
-		    ID_CHILDEDIT,
-		    EM_GETLINE,
-		    (WPARAM) 0,       // line 0
-		    (LPARAM) pszBuf);
-		DestroyWindow(hWnd);
-		return wParam;
-		}
-	    break;
-
-	case WM_DESTROY:
-	    // SetEvent(hEvent);	    // Unblock the main thread
-	    PostQuitMessage(GetWindowLong(hWnd, PWEOFFSET(iExitCode)));
-	    break;
-
-        case WM_SETFOCUS:
-            SetFocus(hWndEdit);
-            return 0;
-
-        case WM_PAINT:
-	    {
-	    HDC hDC;			/* display-context variable  */
-	    PAINTSTRUCT ps;		/* paint structure	     */
-	    int x, y;
-	    TEXTMETRIC tm;
-
-	    /* Set up a display context to begin painting */
-	    hDC = BeginPaint (hWnd, &ps);
-	    SetBkColor(hDC, GetSysColor(COLOR_MENU));
-
-	    GetTextMetrics(hDC, &tm);
-	    x = 5;
-	    y = tm.tmHeight / 2;
-
-	    for (pc=pc0=szLine; pc; pc0=pc+1)	// For every line
-		{
-		pc = strchr(pc0, '\n'); 	// Search end of line
-		if (pc)
-		    iLen = (int)(pc-pc0);
-		else
-		    iLen = lstrlen(pc0);
-		TextOut(hDC, x, y, pc0, iLen);
-		y += tm.tmHeight;
-		}
-
-            /* Tell Windows you are done painting */
-            EndPaint (hWnd,  &ps);
-
-	    return 0;
-	    }
-
-	default:
-	    break;
-	}
-
-    return DefWindowProc(hWnd, uMsg, wParam, lParam);
-    }
-
-int PromptWindow(const char *pszTitle, const char *pszPrompt, char *pszBuffer, int iLength)
-    {
-    WNDCLASS wc;
-    static BOOL bRegistered = FALSE;
-    HWND hWnd;
-    MSG msg;
-
-    // Create our Window style (To be done only once)
-    if (!bRegistered)
-	{
-	wc.style = 0;
-	wc.lpfnWndProc = PromptWindowProc;
-	wc.cbClsExtra = 0;
-	wc.cbWndExtra = sizeof(PromptWindowExtras);
-	wc.hInstance = ThisInstance();
-	wc.hIcon = NULL;
-	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
-	wc.hbrBackground = (HBRUSH)(COLOR_MENU+1);
-	wc.lpszMenuName = NULL;
-	wc.lpszClassName = "PromptWindowClass";
-
-	RegisterClass(&wc);
-
-	bRegistered = TRUE;
-	}
-
-    // Create a Prompt window
-    hWnd = CreateWindow(
-	    "PromptWindowClass",   // pointer to registered class name
-	    pszTitle,	    // pointer to window name
-	    WS_BORDER | WS_POPUP | WS_DISABLED | WS_CAPTION, // window style
-	    (GetSystemMetrics(SM_CXFULLSCREEN) - PWWIDTH)/2, // horizontal position of window: Centered
-	    (GetSystemMetrics(SM_CYFULLSCREEN) - PWHEIGHT)/2, // vertical position of window: Centered
-	    PWWIDTH,		    // window width
-	    PWHEIGHT,		    // window height
-	    NULL,		    // handle to parent or owner window
-	    NULL,		    // handle to menu or child-window identifier
-	    ThisInstance(),	    // handle to application instance
-	    (LPVOID)pszPrompt);	    // pointer to window-creation data
-    SetWindowLongPtr(hWnd, PWEOFFSET(pszOutBuf), (LONG_PTR)pszBuffer);
-    SetWindowLong(hWnd, PWEOFFSET(lBufSize), (LONG_PTR)iLength);
-    SetWindowLong(hWnd, PWEOFFSET(iExitCode), 1);   // Assume failure
-    // Add default text to the window.
-    SendDlgItemMessage(hWnd, ID_CHILDEDIT, WM_SETTEXT, 0, (LPARAM)pszBuffer);
-    EnableWindow(hWnd, TRUE);	    // Allow user input
-    ShowWindow(hWnd, SW_SHOW);
-    UpdateWindow(hWnd);
-
-    // Message loop: Forward messages to the dialog box.
-    while (GetMessage(&msg, NULL, 0, 0)) // Repeat until we receive WM_QUIT...
-	{
-        // char szMsgName[64];
-	// OutputDebugF("Message loop: msg = %s\n", GetMsgName(msg.message, szMsgName, sizeof(szMsgName)));
-	if (!IsDialogMessage(hWnd, &msg))
-	    {
-	    TranslateMessage(&msg);
-	    DispatchMessage(&msg);
-	    }
-	}
-
-    return (int)(msg.wParam);	    // Return the exit code from the window (0 to 8)
-    }
-
+    // OutputDebugF("Message loop: msg = %s\n", GetMsgName(msg.message, szMsgName, sizeof(szMsgName)));
+    if (!IsDialogMessage(hWnd, &msg)) {
+      TranslateMessage(&msg);
+      DispatchMessage(&msg);
+    }
+  }
+
+  return (int)(msg.wParam);	    // Return the exit code from the window (0 to 8)
+}
+


Improve documentation for ArrayView

Improve documentation for ArrayView

Review URL: https://codereview.webrtc.org/1468183003

Cr-Commit-Position: 972c6d2dc6dd5efdad1377c0d224e03eb8f276f7@{#10775}

--- webrtc/base/array_view.h
+++ webrtc/base/array_view.h
@@ -15,12 +15,59 @@

 namespace rtc {

-// Keeps track of an array (a pointer and a size) that it doesn't own.
-// ArrayView objects are immutable except for assignment, and small enough to
-// be cheaply passed by value.
+// Many functions read from or write to arrays. The obvious way to do this is
+// to use two arguments, a pointer to the first element and an element count:
 //
-// Note that ArrayView<T> and ArrayView<const T> are distinct types; this is
-// how you would represent mutable and unmutable views of an array.
+//   bool Contains17(const int* arr, size_t size) {
+//     for (size_t i = 0; i < size; ++i) {
+//       if (arr[i] == 17)
+//         return true;
+//     }
+//     return false;
+//   }
+//
+// This is flexible, since it doesn't matter how the array is stored (C array,
+// std::vector, rtc::Buffer, ...), but it's error-prone because the caller has
+// to correctly specify the array length:
+//
+//   Contains17(arr, arraysize(arr));  // C array
+//   Contains17(&arr[0], arr.size());  // std::vector
+//   Contains17(arr, size);            // pointer + size
+//   ...
+//
+// It's also kind of messy to have two separate arguments for what is
+// conceptually a single thing.
+//
+// Enter rtc::ArrayView<T>. It contains a T pointer (to an array it doesn't
+// own) and a count, and supports the basic things you'd expect, such as
+// indexing and iteration. It allows us to write our function like this:
+//
+//   bool Contains17(rtc::ArrayView<const int> arr) {
+//     for (auto e : arr) {
+//       if (e == 17)
+//         return true;
+//     }
+//     return false;
+//   }
+//
+// And even better, because a bunch of things will implicitly convert to
+// ArrayView, we can call it like this:
+//
+//   Contains17(arr);                             // C array
+//   Contains17(arr);                             // std::vector
+//   Contains17(rtc::ArrayView<int>(arr, size));  // pointer + size
+//   ...
+//
+// One important point is that ArrayView<T> and ArrayView<const T> are
+// different types, which allow and don't allow mutation of the array elements,
+// respectively. The implicit conversions work just like you'd hope, so that
+// e.g. vector<int> will convert to either ArrayView<int> or ArrayView<const
+// int>, but const vector<int> will convert only to ArrayView<const int>.
+// (ArrayView itself can be the source type in such conversions, so
+// ArrayView<int> will convert to ArrayView<const int>.)
+//
+// Note: ArrayView is tiny (just a pointer and a count) and trivially copyable,
+// so it's probably cheaper to pass it by value than by const reference.
 template <typename T>
 class ArrayView final {
  public:


drivers: net: xgene: fix: Out of order descriptor bytes read

This patch fixes the following kernel crash,

	WARNING: CPU: 2 PID: 0 at net/ipv4/tcp_input.c:3079 tcp_clean_rtx_queue+0x658/0x80c()
	Call trace:
	[<fffffe0000096b7c>] dump_backtrace+0x0/0x184
	[<fffffe0000096d10>] show_stack+0x10/0x1c
	[<fffffe0000685ea0>] dump_stack+0x74/0x98
	[<fffffe00000b44e0>] warn_slowpath_common+0x88/0xb0
	[<fffffe00000b461c>] warn_slowpath_null+0x14/0x20
	[<fffffe00005b5c1c>] tcp_clean_rtx_queue+0x654/0x80c
	[<fffffe00005b6228>] tcp_ack+0x454/0x688
	[<fffffe00005b6ca8>] tcp_rcv_established+0x4a4/0x62c
	[<fffffe00005bf4b4>] tcp_v4_do_rcv+0x16c/0x350
	[<fffffe00005c225c>] tcp_v4_rcv+0x8e8/0x904
	[<fffffe000059d470>] ip_local_deliver_finish+0x100/0x26c
	[<fffffe000059dad8>] ip_local_deliver+0xac/0xc4
	[<fffffe000059d6c4>] ip_rcv_finish+0xe8/0x328
	[<fffffe000059dd3c>] ip_rcv+0x24c/0x38c
	[<fffffe0000563950>] __netif_receive_skb_core+0x29c/0x7c8
	[<fffffe0000563ea4>] __netif_receive_skb+0x28/0x7c
	[<fffffe0000563f54>] netif_receive_skb_internal+0x5c/0xe0
	[<fffffe0000564810>] napi_gro_receive+0xb4/0x110
	[<fffffe0000482a2c>] xgene_enet_process_ring+0x144/0x338
	[<fffffe0000482d18>] xgene_enet_napi+0x1c/0x50
	[<fffffe0000565454>] net_rx_action+0x154/0x228
	[<fffffe00000b804c>] __do_softirq+0x110/0x28c
	[<fffffe00000b8424>] irq_exit+0x8c/0xc0
	[<fffffe0000093898>] handle_IRQ+0x44/0xa8
	[<fffffe000009032c>] gic_handle_irq+0x38/0x7c
	[...]

Software writes poison data into the descriptor bytes[15:8] and upon
receiving the interrupt, if those bytes are overwritten by the hardware with
the valid data, software also reads bytes[7:0] and executes receive/tx
completion logic.

If the CPU executes the above two reads in out of order fashion, then the
bytes[7:0] will have older data and causing the kernel panic.  We have to
force the order of the reads and thus this patch introduces read memory
barrier between these reads.

Signed-off-by: Iyappan Subramanian <99eec12aaaa1409f8dbbcf313cbe986d130f383c@apm.com>
Signed-off-by: Keyur Chudgar <d60e3ae674f55154e8ec489e41a00759d09b2736@apm.com>
Signed-off-by: David S. Miller <fe08d3c717adf2ae63592e4c9aec6e3e404d8e3e@davemloft.net>

--- drivers/net/ethernet/apm/xgene/xgene_enet_main.c
+++ drivers/net/ethernet/apm/xgene/xgene_enet_main.c
@@ -369,6 +369,8 @@
 		if (unlikely(xgene_enet_is_desc_slot_empty(raw_desc)))
 			break;

+		/* read fpqnum field after dataaddr field */
+		dma_rmb();
 		if (is_rx_desc(raw_desc))
 			ret = xgene_enet_rx_frame(ring, raw_desc);
 		else


refine sc_int_common::wrap()

refine sc_int_common::wrap()

--- systemc-utils/bca-subset/src/sysc/datatypes/int/sc_int.h
+++ systemc-utils/bca-subset/src/sysc/datatypes/int/sc_int.h
@@ -609,16 +609,6 @@

 ////////////////////////////////////////////////////////////////

-template <bool SWIDE, bool DWIDE>
-sc_inline int sc_int_assign_width(const sc_int_ranged<signed,SWIDE>& x, signed) { return x.width(); }
-template <bool SWIDE, bool DWIDE>
-sc_inline int sc_int_assign_width(const sc_int_ranged<signed,SWIDE>& x, unsigned)
-  { return sc_int_ranged<unsigned,(SWIDE||DWIDE)>(x).width(); }
-template <bool SWIDE, bool DWIDE>
-sc_inline int sc_int_assign_width(const sc_int_ranged<unsigned,SWIDE>& x, signed) { return x.width()+1; }
-template <bool SWIDE, bool DWIDE>
-sc_inline int sc_int_assign_width(const sc_int_ranged<unsigned,SWIDE>& x, unsigned) { return x.width(); }
-
 template <typename S, int W>
 struct sc_int_common {
   typedef sc_int_traits<S,W>  traits_type;
@@ -628,9 +618,8 @@
   sc_inline operator value_type() const { return m_value; }
   sc_inline sc_int_common() {}
   template <typename SS, bool WIDE>
-  sc_inline static value_type wrap(const sc_int_ranged<SS,WIDE>& x) {
-    return traits_type::wrap(x, sc_int_assign_width<WIDE,(W>32)>(x,S()));
-  }
+  sc_inline static value_type wrap(const sc_int_ranged<SS,WIDE>& x)
+    { return traits_type::wrap(x, sc_int_ranged<SS,(WIDE||(W>32))>(x).width(S())); }
   sc_inline sc_int_common(bool               x) : m_value(wrap(sc_int_rsi(x))) {}
   sc_inline sc_int_common(signed char        x) : m_value(wrap(sc_int_rsi(x))) {}
   sc_inline sc_int_common(unsigned char      x) : m_value(wrap(sc_int_rsi(x))) {}


Update: First two recursions down.

Update: First two recursions down.

--- hw7recursion.c
+++ hw7recursion.c
@@ -3,12 +3,47 @@
 #include <stdio.h>
 #include <stdlib.h>

+void countdown( unsigned seconds );
+unsigned add( unsigned a, unsigned b );
+unsigned multiply( unsigned a, unsigned b );
+
 int die( const char * msg );

 int main(){
+    countdown(5);
+    printf("\n");
+
+    printf("%u\n", add(3, 7));
+    printf("\n");
+
+    printf("%u\n", multiply(3, 7));
+    printf("\n");

     return 0;
 } //main
+
+void countdown( unsigned seconds ){
+    if (seconds > 0){
+        printf("%u...\n", seconds--);
+        countdown(seconds);
+    } else
+        printf("Blast off!\n");
+}
+unsigned add( unsigned a, unsigned b ){
+    if (a > 0){
+        add(--a, ++b);
+    } else
+        return b;
+}
+unsigned multiply( unsigned a, unsigned b ){
+    static unsigned product = 0;
+
+    // if (a > 0){
+    //     product = add(a, b);
+    //     multiply(--a,)
+    // }
+    return 0;
+}

 int die( const char * msg ){
     printf("Fatal error: %s\n", msg);


Delete mipslabwork.c

Delete mipslabwork.c

--- mipslabwork.c
+++ mipslabwork.c
@@ -1,258 +0,0 @@
-/* mipslabwork.c
-   For copyright and licensing, see file COPYING */
-
-#include <stdint.h>
-#include <pic32mx.h>
-#include "mipslab.h"
-#include <math.h>
-
-#define BASE_FREQUENCY 440
-#define FREQUENCY_SCALING 1.059463094
-
-int calculate_baudrate_divider(int sysclk, int baudrate, int highspeed);
-void timerSetup();
-void pollUart();
-void uartSetup();
-void user_isr();
-void labinit();
-void labwork();
-void display_stuff();
-void update_frequency();
-void handleMIDIInterrupt();
-void handleTimerInterrupt();
-
-
-
-unsigned char message1 = 0;
-unsigned char message2 = 0;
-unsigned char message3 = 0;
-
-char state = 0;
-
-int note = 0;
-int noteOffset = 0;
-int gate = 1;
-double frequency = BASE_FREQUENCY;
-
-/* Interrupt Service Routine */
-void user_isr( void ) {
-	if ((IFS(0) >> 27) & 0x1){	// 0b10000000000000
-		handleMIDIInterrupt();
-	}
-	if ((IFS(0) >> 8) & 0x1) {
-		handleTimerInterrupt();
-	}
-	return;
-}
-
-void handleMIDIInterrupt(){
-
-	switch (state){
-		case 0:
-			message1 = U1RXREG;
-			unsigned char noteOnOff = message1 >> 4;
-			if ((noteOnOff == 9) || (noteOnOff == 10))
-				state = 1;
-			else
-				state = 0;
-			break;
-		case 1:
-			message2 = U1RXREG;
-			state = 2;
-			break;
-		case 2:
-			message3 = U1RXREG;
-			if ((message3 > 0)){
-				gate = 1;
-				note = message2 - 81;
-			}else{
-				gate = 0;
-			}
-			state = 0;
-			break;
-		default:
-			state = 0;
-			gate = 0;
-			break;
-	}
-
-
-
-
-/*	switch (state){*/
-/*		case 0:*/
-/*			message1 = U1RXREG;*/
-/*			if (message1 != 0xfe)*/
-/*				state = 1;*/
-/*			break;*/
-/*		case 1:*/
-/*			message2 = U1RXREG;*/
-/*			if (message2 != 0xfe)*/
-/*				state = 2;*/
-/*			else*/
-/*				state = 0;*/
-/*			break;*/
-/*		case 2:*/
-/*			message3 = U1RXREG;*/
-/*			if (message3 != 0xfe){*/
-/*				unsigned char noteOnOff = message1 >> 4;*/
-/*				if ((noteOnOff == 9) && (message3 > 0)){*/
-/*					gate = 1;*/
-/*					note = message2 - 81;*/
-/*				}else{*/
-/*					gate = 0;*/
-/*				}*/
-/*			}*/
-/*			state = 0;*/
-/*			break;*/
-/*		default:*/
-/*			state = 0;*/
-/*			gate = 0;*/
-/*			break;*/
-/*	}*/
-	IFS(0) &= ~(1 << 27);
-	return;
-}
-void handleTimerInterrupt(){
-	if (gate){
-		PORTE = ~(PORTE);
-		if ((PORTG >> 6) & 0x1)
-			PORTG &= ~(1 << 6);
-		else
-			PORTG |= 1 << 6;
-	}else{
-		PORTE = 0;
-	}
-	IFS(0) &= ~(1 << 8);
-	return;
-}
-
-void timerSetup(){
-	T2CON = 0x70;		// Prescaling för timer pbc = 10mHz -> 10000000 / 245 = 39062 Hz
-	TMR2 = 0;		// Nollställ timer
-	PR2 = 312500;		// Vad timern ska räkna till
-	T2CON |= (1 << 15);	// Starta timer
-}
-
-void init_interrupt(){
-	IEC(0) |= 0x100;
-	IPC(2) = 7 << 2;
-
-	IEC(0) |= (1 << 27);
-	IPC(6) |= 31;
-	timerSetup();
-	enable_interrupt();
-	return;
-}
-
-/* Lab-specific initialization goes here */
-void labinit( void )
-{
-	//pin 13 RG6
-	TRISG &= ~(1 << 6); // Pin 13 till output
-	PORTG &= ~(1 << 6); // Pin 13 till 0
-	TRISD |= (3 << 6);  //BTN 3 & 4 som input
-
-	TRISE = 0;
-	PORTE = 0;
-	uartSetup();
-	init_interrupt();
-
-	return;
-}
-void check_buttons( void ){
-
-	if ((PORTD >> 6) & 1){
-		gate = 1;
-		noteOffset = 0;
-	}else if ((PORTD >> 7) & 1){
-		gate = 1;
-		noteOffset = -12;
-	} else
-		gate = 0;
-
-
-}
-
-/* This function is called repetitively from the main program */
-void main_loop( void ) {
-	//display_stuff();
-	//check_buttons();
-	update_frequency();
-
-	return;
-}
-
-void update_frequency(){
-	int usedNote = note + noteOffset;
-	frequency = BASE_FREQUENCY;
-	double freqScaling = FREQUENCY_SCALING;
-	int i;
-	if (usedNote < 0){
-		int positiveNote = usedNote * -1;
-		for (i = 0; i < positiveNote; i++){
-			frequency = frequency / FREQUENCY_SCALING;
-		}
-	}else{
-		for (i = 0; i < usedNote; i++){
-			frequency = frequency * FREQUENCY_SCALING;
-		}
-	}
-	PR2 = (312500/frequency);
-
-	return;
-}
-
-void display_stuff(){
-	char string1[] = "        ";
-	char string2[] = "        ";
-	//char string3[] = "        ";
-
-	string1[0] = 48 + note;
-	string2[0] = 48 + gate;
-
-	//PORTE = (int)frequency;
-
-	display_string(0, "MIDI");
-	display_string(1, string1);
-	display_string(2, string2);
-	//display_string(3, string3);
-
-
-	display_update();
-	return;
-}
-
-int calculate_baudrate_divider(int sysclk, int baudrate, int highspeed) {
-	int pbclk, uxbrg, divmult;
-	unsigned int pbdiv;
-
-	divmult = (highspeed) ? 4 : 16;
-	/* Periphial Bus Clock is divided by PBDIV in OSCCON */
-	pbdiv = (OSCCON & 0x180000) >> 19;
-	pbclk = sysclk >> pbdiv;
-
-	/* Multiply by two, this way we can round the divider up if needed */
-	uxbrg = ((pbclk * 2) / (divmult * baudrate)) - 2;
-	/* We'll get closer if we round up */
-	if (uxbrg & 1)
-		uxbrg >>= 1, uxbrg++;
-	else
-		uxbrg >>= 1;
-	return uxbrg;
-}
-
-void uartSetup(){
-	U1STA = 0;
-	U1MODE = 0;
-
-	OSCCON &= ~0x180000;
-	OSCCON |= 0x080000;
-	U1BRG = calculate_baudrate_divider(80000000, 31250, 0);
-
-	/* 8-bit data, no parity, 1 stop bit */
-	U1MODE = 0x8000;
-	/* Enable transmit and recieve */
-	U1STASET = 0x1400;
-	return;
-}


[EFL] Persistent_notification_id is an int64_t

Because of commit 583b6174 of s-chromium
(http://165.213.202.130/gerrit/#/c/78593/), last
argument of ClosePersistentNotification needs to be an
int64_t instead of a string

--- runtime/browser/xwalk_platform_notification_service.h
+++ runtime/browser/xwalk_platform_notification_service.h
@@ -5,8 +5,6 @@

 #ifndef XWALK_RUNTIME_BROWSER_XWALK_PLATFORM_NOTIFICATION_SERVICE_H_
 #define XWALK_RUNTIME_BROWSER_XWALK_PLATFORM_NOTIFICATION_SERVICE_H_
-
-#include <string>

 #include "base/memory/singleton.h"
 #include "content/public/browser/platform_notification_service.h"
@@ -51,7 +49,7 @@
       const content::PlatformNotificationData& notification_data) override {}
   void ClosePersistentNotification(
       content::BrowserContext* browser_context,
-      const std::string& persistent_notification_id) override {}
+      int64_t persistent_notification_id) override {}

  private:
   friend struct DefaultSingletonTraits<XWalkPlatformNotificationService>;


Call file_dotlock_touch() once in a while so other process won't override the conversion lock.

--- src/plugins/convert/convert-storage.c
+++ src/plugins/convert/convert-storage.c
@@ -35,7 +35,8 @@
 	return mailbox_sync_deinit(&ctx, &status);
 }

-static int mailbox_copy_mails(struct mailbox *srcbox, struct mailbox *destbox)
+static int mailbox_copy_mails(struct mailbox *srcbox, struct mailbox *destbox,
+			      struct dotlock *dotlock)
 {
 	struct mail_search_context *ctx;
 	struct mailbox_transaction_context *src_trans, *dest_trans;
@@ -62,6 +63,12 @@
 		struct mail_keywords *keywords;
 		const char *const *keywords_list;

+		if ((mail->seq % 100) == 0) {
+			/* touch the lock file so that if there are tons of
+			   mails another process won't override our lock. */
+			(void)file_dotlock_touch(dotlock);
+		}
+
 		keywords_list = mail_get_keywords(mail);
 		keywords = strarray_length(keywords_list) == 0 ? NULL :
 			mailbox_keywords_create(dest_trans, keywords_list);
@@ -93,7 +100,8 @@

 static int mailbox_convert_list_item(struct mail_storage *source_storage,
 				     struct mail_storage *dest_storage,
-				     struct mailbox_list *list)
+				     struct mailbox_list *list,
+				     struct dotlock *dotlock)
 {
 	struct mailbox *srcbox, *destbox;
 	int ret = 0;
@@ -136,7 +144,7 @@
 		return -1;
 	}

-	if (mailbox_copy_mails(srcbox, destbox) < 0) {
+	if (mailbox_copy_mails(srcbox, destbox, dotlock) < 0) {
 		i_error("Mailbox conversion: Couldn't copy mailbox %s",
 			mailbox_get_name(srcbox));
 	}
@@ -147,7 +155,8 @@
 }

 static int mailbox_list_copy(struct mail_storage *source_storage,
-			     struct mail_storage *dest_storage)
+			     struct mail_storage *dest_storage,
+			     struct dotlock *dotlock)
 {
 	struct mailbox_list_context *iter;
 	struct mailbox_list *list;
@@ -157,10 +166,14 @@
                                               MAILBOX_LIST_FAST_FLAGS);
 	while ((list = mail_storage_mailbox_list_next(iter)) != NULL) {
 		if (mailbox_convert_list_item(source_storage, dest_storage,
-					      list) < 0) {
+					      list, dotlock) < 0) {
 			ret = -1;
 			break;
 		}
+
+		/* In case there are lots of mailboxes. Also the other touch
+		   is done only after 100 mails. */
+		(void)file_dotlock_touch(dotlock);
 	}
 	if (mail_storage_mailbox_list_deinit(&iter) < 0)
 		ret = -1;
@@ -211,7 +224,7 @@
 			"storage with data: %s", dest_data);
 		ret = -1;
 	} else {
-		ret = mailbox_list_copy(source_storage, dest_storage);
+		ret = mailbox_list_copy(source_storage, dest_storage, dotlock);
 	}

 	if (ret == 0) {


Fix global initialization to eliminate a link error on Mac OS X.

git-svn-id: 33305d871a58cfd02b407b81d5206d2a785211eb@1424 159cb52c-178a-4f3c-8eb8-d0aff033d058

--- c/src/ta_common/ta_global.c
+++ c/src/ta_common/ta_global.c
@@ -47,21 +47,11 @@
  *  082004 AC   Add TA_SetCandleSettings, TA_RestoreCandleDefaultSettings
  *              and call to TA_RestoreCandleDefaultSettings in TA_Initialize
  *  041106 MF   Add prefix to theGlobals to avoid clash with other libs.
+ *  040707 MF   Change global initialization to eliminate Mac OS X link error.
  */

 /* Description:
  *   Provides initialization / shutdown functionality for all modules.
- *
- *   Since not all module are used/link in the application,
- *   the ta_common simply provides the mechanism for the module
- *   to optionnaly "register" its initialization/shutdown
- *   function.
- *
- *   This whole mechanism helps the initialization of "module globals"
- *   while actually not using true globals. The fact of not having "true"
- *   globals helps to make TA-LIB re-entrant.
- *
- *   This also allows to clearly define the shutdown sequence.
  */

 /**** Headers ****/
@@ -83,7 +73,7 @@
 /**** Global variables definitions.    ****/

 /* The entry point for all globals */
-TA_LibcPriv ta_theGlobals;
+TA_LibcPriv ta_theGlobals = {0};
 TA_LibcPriv *TA_Globals = &ta_theGlobals;

 /**** Local declarations.              ****/
@@ -108,9 +98,6 @@

    /* Set the default value to global variables */
    TA_RestoreCandleDefaultSettings( TA_AllCandleSettings );
-
-   /* Seeds random generator */
-   srand( (unsigned)time( NULL ) );

    return TA_SUCCESS;
 }


fix type declaration of input parameter solution_extrapolation_length

--- header/NSolver/Parameters/TimeSteppingParameters.h
+++ header/NSolver/Parameters/TimeSteppingParameters.h
@@ -104,7 +104,7 @@
        * predicted_solution =  current_solution * (1+solution_extrapolation_length)
        *                      -old_solution * solution_extrapolation_length;
        */
-      bool solution_extrapolation_length;
+      double solution_extrapolation_length;

       /**
        * There is an array defined in NSolver::run() that contains a list of


Increase default badness weight of alert/critical

--- src/opticon-collector/main.c
+++ src/opticon-collector/main.c
@@ -128,10 +128,10 @@
                      make_watcher (w, id, tp, v_warn, 5.0, WATCH_WARN);
                 }
                 if (var_get_count (v_alert)) {
-                     make_watcher (w, id, tp, v_alert, 5.0, WATCH_ALERT);
+                     make_watcher (w, id, tp, v_alert, 8.0, WATCH_ALERT);
                 }
                 if (var_get_count (v_crit)) {
-                    make_watcher (w, id, tp, v_crit, 10.0, WATCH_CRIT);
+                    make_watcher (w, id, tp, v_crit, 12.0, WATCH_CRIT);
                 }
             }
             mdef = mdef->next;


say what next expected action of current player is when showing the table.

--- irc_game.c
+++ irc_game.c
@@ -110,7 +110,13 @@
     snprintf(buf, sizeof(buf), "Cards remaining in draw deck: %d.", num_cards(&board->deck));
     irc_cmd_msg(session, whence, buf);

-    snprintf(buf, sizeof(buf), "It is %s's turn.", board->players[board->player_turn].name);
+    if (DRAW & board->valid_actions)
+        snprintf(buf, sizeof(buf), "It is %s's turn to draw a card.",
+                board->players[board->player_turn].name);
+    else
+        snprintf(buf, sizeof(buf), "It is %s's turn to play or discard.",
+                board->players[board->player_turn].name);
+
     irc_cmd_msg(session, whence, buf);

     return 1;


pins2lts-sym: now also write action labels to transition file

--- src/pins2lts-sym/pins2lts-sym.c
+++ src/pins2lts-sym/pins2lts-sym.c
@@ -4835,6 +4835,18 @@
         /* Call hook */
         vset_post_save(f, domain);

+        /* Now write action labels */
+        int action_count = 0;
+        if (act_label != -1) action_count = pins_chunk_count(model, action_typeno);
+        fwrite(&action_count, sizeof(int), 1, f);
+        for (int i=0; i<action_count; i++) {
+            chunk ch = pins_chunk_get(model, action_typeno, i);
+            uint32_t len = ch.len;
+            char *action = ch.data;
+            fwrite(&len, sizeof(uint32_t), 1, f);
+            fwrite(action, sizeof(char), len, f);
+        }
+
         /* Done! */
         fclose(f);


Update speed in reviving

Update speed in reviving

--- src/core/actor/Phantom.h
+++ src/core/actor/Phantom.h
@@ -25,10 +25,11 @@
   bool IsDead() const {
     return life_ == 0;
   }
-  void Revive(bool tough, const glm::vec2 &pos) {
+  void Revive(bool tough, float speed_scale, const glm::vec2 &pos) {
     life_ = tough ? kLifeMaxOnTough : kLifeMax;
     set_stimulus_effect(tough ? kStimulusEffectOnTough : kStimulusEffect);
     set_stimulus_color(tough ? kStimulusColorOnTough : kStimulusColor);
+    set_walk_speed(kSpeed * speed_scale);
     set_pos(pos);
   }


drqs-142948762: Updates per NGB fourth review.

--- groups/bsl/bslstl/bslstl_boyermoorehorspoolsearcher.h
+++ groups/bsl/bslstl/bslstl_boyermoorehorspoolsearcher.h
@@ -587,6 +587,7 @@

 #include <bslscm_version.h>

+#include <bslstl_array.h>
 #include <bslstl_equalto.h>
 #include <bslstl_hash.h>
 #include <bslstl_iterator.h>
@@ -1231,13 +1232,17 @@
         return;                                                      // RETURN
     }

-    d_table_p = d_allocator_p->allocate((UCHAR_MAX + 1) * d_bytesPerElement);
-
     if (privateUseShortNeedleOptimization()) {
+        d_table_p = new (*d_allocator_p) bsl::array<ShortNeedleSkipType,
+                                                    UCHAR_MAX + 1>;
+
         native_std::memset(d_table_p,
-                           static_cast<unsigned char>(d_needleLength),
+                           static_cast<ShortNeedleSkipType>(d_needleLength),
                            UCHAR_MAX + 1);
     } else {
+        d_table_p = new (*d_allocator_p) bsl::array<LongNeedleSkipType,
+                                                    UCHAR_MAX + 1>;
+
         for (LongNeedleSkipType *ptr  =
                            reinterpret_cast<LongNeedleSkipType *>(d_table_p),
                                   *end  = ptr + (UCHAR_MAX + 1);
@@ -1249,7 +1254,8 @@
     for (RNDACC_ITR_NEEDLE current  = needleFirst,
                            last     = needleLast - 1;
                            last    != current; ++current) {
-        const unsigned char index = static_cast<unsigned char>(*current);
+
+        const unsigned char index     = static_cast<unsigned char>(*current);
         native_std::size_t  skipValue = d_needleLength
                                       - 1
                                       - (current - needleFirst);


caml_array_{*_float => floatarray_*} for * = {get,set,unsafe_get,unsafe_set} (#10075)

--- runtime/array.c
+++ runtime/array.c
@@ -57,43 +57,6 @@
   return Field(array, idx);
 }

-/* [ float array -> int -> float ] */
-static value caml_array_get_float(value array, value index)
-{
-  intnat idx = Long_val(index);
-#ifdef FLAT_FLOAT_ARRAY
-  double d;
-  value res;
-
-  if (idx < 0 || idx >= Wosize_val(array) / Double_wosize)
-    caml_array_bound_error();
-  d = Double_flat_field(array, idx);
-#define Setup_for_gc
-#define Restore_after_gc
-  Alloc_small(res, Double_wosize, Double_tag);
-#undef Setup_for_gc
-#undef Restore_after_gc
-  Store_double_val(res, d);
-  return res;
-#else
-  CAMLassert (Tag_val (array) != Double_array_tag);
-  if (idx < 0 || idx >= Wosize_val(array)) caml_array_bound_error();
-  return Field(array, idx);
-#endif /* FLAT_FLOAT_ARRAY */
-}
-
-/* [ 'a array -> int -> 'a ] */
-CAMLprim value caml_array_get(value array, value index)
-{
-#ifdef FLAT_FLOAT_ARRAY
-  if (Tag_val(array) == Double_array_tag)
-    return caml_array_get_float(array, index);
-#else
-  CAMLassert (Tag_val(array) != Double_array_tag);
-#endif
-  return caml_array_get_addr(array, index);
-}
-
 /* [ floatarray -> int -> float ] */
 CAMLprim value caml_floatarray_get(value array, value index)
 {
@@ -114,6 +77,18 @@
   return res;
 }

+/* [ 'a array -> int -> 'a ] */
+CAMLprim value caml_array_get(value array, value index)
+{
+#ifdef FLAT_FLOAT_ARRAY
+  if (Tag_val(array) == Double_array_tag)
+    return caml_floatarray_get(array, index);
+#else
+  CAMLassert (Tag_val(array) != Double_array_tag);
+#endif
+  return caml_array_get_addr(array, index);
+}
+
 /* [ 'a array -> int -> 'a -> unit ] where 'a != float */
 CAMLprim value caml_array_set_addr(value array, value index, value newval)
 {
@@ -121,35 +96,6 @@
   if (idx < 0 || idx >= Wosize_val(array)) caml_array_bound_error();
   Modify(&Field(array, idx), newval);
   return Val_unit;
-}
-
-/* [ float array -> int -> float -> unit ] */
-static value caml_array_set_float(value array, value index, value newval)
-{
-  intnat idx = Long_val(index);
-#ifdef FLAT_FLOAT_ARRAY
-  double d = Double_val (newval);
-  if (idx < 0 || idx >= Wosize_val(array) / Double_wosize)
-    caml_array_bound_error();
-  Store_double_flat_field(array, idx, d);
-#else
-  CAMLassert (Tag_val (array) != Double_array_tag);
-  if (idx < 0 || idx >= Wosize_val(array)) caml_array_bound_error();
-  Modify(&Field(array, idx), newval);
-#endif
-  return Val_unit;
-}
-
-/* [ 'a array -> int -> 'a -> unit ] */
-CAMLprim value caml_array_set(value array, value index, value newval)
-{
-#ifdef FLAT_FLOAT_ARRAY
-  if (Tag_val(array) == Double_array_tag)
-    return caml_array_set_float(array, index, newval);
-#else
-  CAMLassert (Tag_val(array) != Double_array_tag);
-#endif
-  return caml_array_set_addr(array, index, newval);
 }

 /* [ floatarray -> int -> float -> unit ] */
@@ -164,38 +110,16 @@
   return Val_unit;
 }

-/* [ float array -> int -> float ] */
-static value caml_array_unsafe_get_float(value array, value index)
-{
-  intnat idx = Long_val (index);
-#ifdef FLAT_FLOAT_ARRAY
-  double d;
-  value res;
-
-  d = Double_flat_field(array, idx);
-#define Setup_for_gc
-#define Restore_after_gc
-  Alloc_small(res, Double_wosize, Double_tag);
-#undef Setup_for_gc
-#undef Restore_after_gc
-  Store_double_val(res, d);
-  return res;
-#else /* FLAT_FLOAT_ARRAY */
-  CAMLassert (Tag_val(array) != Double_array_tag);
-  return Field(array, idx);
-#endif /* FLAT_FLOAT_ARRAY */
-}
-
-/* [ 'a array -> int -> 'a ] */
-CAMLprim value caml_array_unsafe_get(value array, value index)
+/* [ 'a array -> int -> 'a -> unit ] */
+CAMLprim value caml_array_set(value array, value index, value newval)
 {
 #ifdef FLAT_FLOAT_ARRAY
   if (Tag_val(array) == Double_array_tag)
-    return caml_array_unsafe_get_float(array, index);
+    return caml_floatarray_set(array, index, newval);
 #else
   CAMLassert (Tag_val(array) != Double_array_tag);
 #endif
-  return Field(array, Long_val(index));
+  return caml_array_set_addr(array, index, newval);
 }

 /* [ floatarray -> int -> float ] */
@@ -216,6 +140,18 @@
   return res;
 }

+/* [ 'a array -> int -> 'a ] */
+CAMLprim value caml_array_unsafe_get(value array, value index)
+{
+#ifdef FLAT_FLOAT_ARRAY
+  if (Tag_val(array) == Double_array_tag)
+    return caml_floatarray_unsafe_get(array, index);
+#else
+  CAMLassert (Tag_val(array) != Double_array_tag);
+#endif
+  return Field(array, Long_val(index));
+}
+
 /* [ 'a array -> int -> 'a -> unit ] where 'a != float */
 static value caml_array_unsafe_set_addr(value array, value index,value newval)
 {
@@ -224,16 +160,12 @@
   return Val_unit;
 }

-/* [ float array -> int -> float -> unit ] */
-static value caml_array_unsafe_set_float(value array,value index,value newval)
-{
-  intnat idx = Long_val(index);
-#ifdef FLAT_FLOAT_ARRAY
+/* [ floatarray -> int -> float -> unit ] */
+CAMLprim value caml_floatarray_unsafe_set(value array, value index,value newval)
+{
+  intnat idx = Long_val(index);
   double d = Double_val (newval);
   Store_double_flat_field(array, idx, d);
-#else
-  Modify(&Field(array, idx), newval);
-#endif
   return Val_unit;
 }

@@ -242,20 +174,11 @@
 {
 #ifdef FLAT_FLOAT_ARRAY
   if (Tag_val(array) == Double_array_tag)
-    return caml_array_unsafe_set_float(array, index, newval);
+    return caml_floatarray_unsafe_set(array, index, newval);
 #else
   CAMLassert (Tag_val(array) != Double_array_tag);
 #endif
   return caml_array_unsafe_set_addr(array, index, newval);
-}
-
-/* [ floatarray -> int -> float -> unit ] */
-CAMLprim value caml_floatarray_unsafe_set(value array, value index,value newval)
-{
-  intnat idx = Long_val(index);
-  double d = Double_val (newval);
-  Store_double_flat_field(array, idx, d);
-  return Val_unit;
 }

 /* [len] is a [value] representing number of floats. */
@@ -408,15 +331,8 @@
   intnat count;

 #ifdef FLAT_FLOAT_ARRAY
-  if (Tag_val(a2) == Double_array_tag) {
-    /* Arrays of floats.  The values being copied are floats, not
-       pointer, so we can do a direct copy.  memmove takes care of
-       potential overlap between the copied areas. */
-    memmove((double *)a2 + Long_val(ofs2),
-            (double *)a1 + Long_val(ofs1),
-            Long_val(n) * sizeof(double));
-    return Val_unit;
-  }
+  if (Tag_val(a2) == Double_array_tag)
+    return caml_floatarray_blit(a1, ofs1, a2, ofs2, n);
 #endif
   CAMLassert (Tag_val(a2) != Double_array_tag);
   if (Is_young(a2)) {


Bluedroid: fix channel map of ext adv params check

--- components/bt/host/bluedroid/api/esp_gap_ble_api.c
+++ components/bt/host/bluedroid/api/esp_gap_ble_api.c
@@ -863,10 +863,10 @@
         ESP_BLE_IS_VALID_PARAM(params->peer_addr_type, BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_RANDOM) &&
         ESP_BLE_IS_VALID_PARAM(params->own_addr_type, BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_RPA_RANDOM) &&
         ESP_BLE_IS_VALID_PARAM(params->filter_policy, ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST) &&
-        (params->interval_min <= params->interval_max) && ((params->channel_map & ADV_CHNL_ALL) == ADV_CHNL_ALL) &&
+        (params->interval_min <= params->interval_max) && (params->channel_map > 0) && (params->channel_map <= ADV_CHNL_ALL) &&
         ((params->primary_phy == ESP_BLE_GAP_PRI_PHY_1M) || (params->primary_phy == ESP_BLE_GAP_PRI_PHY_CODED)) &&
         ((params->secondary_phy == ESP_BLE_GAP_PHY_1M) || (params->secondary_phy == ESP_BLE_GAP_PHY_2M) ||
-        (params->secondary_phy == ESP_BLE_GAP_PHY_CODED)) && (params->channel_map != 0x0)){
+        (params->secondary_phy == ESP_BLE_GAP_PHY_CODED))){
         memcpy(&arg.ext_adv_set_params.params, params, sizeof(esp_ble_gap_ext_adv_params_t));
     } else {
         LOG_ERROR("%s,invalid ext adv params", __func__);


Remove file extension check

Remove file extension check

Data files are often without extension,
and checking osm header is adequate.

--- ext/pbf_parser/pbf_parser.c
+++ ext/pbf_parser/pbf_parser.c
@@ -761,10 +761,6 @@
   // Check that filename is a string
   Check_Type(filename, T_STRING);

-  // Check if the file has a valid extension
-  if(!strcmp(".osm.pbf", StringValuePtr(filename) + RSTRING_LEN(filename)-8) == 0)
-    rb_raise(rb_eArgError, "Not a osm.pbf file");
-
   // Try to open the given file
   if(!(DATA_PTR(obj) = fopen(StringValuePtr(filename), "rb")))
     rb_raise(rb_eIOError, "Unable to open the file");


Fix mp3 vs world sync, welcome to the hackland!

--- mediathread/demuxer_avf.c
+++ mediathread/demuxer_avf.c
@@ -273,7 +273,7 @@
                 props.audio_channels = codec->channels;
                 // Make props an int...
                 props.sample_rate    = codec->sample_rate;
-                props.duration       = (double)1 / props.sample_rate;
+                props.duration       = (double)1 / codec->sample_rate;
                 props.bit_per_sample   = codec->bits_per_sample;
                 snprintf(trackinfo.name, sizeof(trackinfo.name), "%d", i);
                 if (!(track = add_track(r, &trackinfo, &props)))
@@ -326,28 +326,14 @@
 // get a packet
     if(av_read_frame(priv->avfc, &pkt) < 0)
         return EOF; //FIXME
-
-// for each track selected
-#if 0
-    for (sel = g_list_first(r->sel);
-         sel !=NULL;
-         sel = g_list_next(r->sel)) {
-        if (pkt.stream_index == sel->cur->info->id) {
-// push it to the framer
-            stream = priv->avfc->streams[sel->cur->info->id];
-            ret = sel->cur->parser->parse(sel->cur, pkt.data, pkt.size,
-                                    stream->codec->extradata,
-                                    stream->codec->extradata_size);
-            break;
-        }
-    }
-#else
     for (tr = g_list_first(r->tracks);
          tr !=NULL;
          tr = g_list_next(tr)) {
         if (pkt.stream_index == TRACK(tr)->info->id) {
 // push it to the framer
             stream = priv->avfc->streams[TRACK(tr)->info->id];
+            fnc_log(FNC_LOG_DEBUG, "[MT] Parsing track %s\n",
+                    TRACK(tr)->info->name);
             if(pkt.pts != AV_NOPTS_VALUE) {
                 TRACK(tr)->properties->mtime = r->timescaler (r,
                     pkt.pts * av_q2d(stream->time_base));
@@ -356,33 +342,38 @@
             } else {
                 fnc_log(FNC_LOG_DEBUG, "[MT] missing timestamp");
             }
+
             if (pkt.duration) {
                 TRACK(tr)->properties->duration = pkt.duration *
                     av_q2d(stream->time_base);
+            } else { // welcome to the wonderland ehm, hackland...
+                switch (stream->codec->codec_id) {
+                    case CODEC_ID_MP2:
+                    case CODEC_ID_MP3:
+                        TRACK(tr)->properties->duration = 1152.0/
+                                TRACK(tr)->properties->sample_rate;
+                        break;
+                    default: break;
+                }
             }

-            fnc_log(FNC_LOG_DEBUG, "[MT] packet duration %f, bitrate %f\n",
-                TRACK(tr)->properties->duration,
-                TRACK(tr)->properties->bit_rate );
+            fnc_log(FNC_LOG_DEBUG, "[MT] packet duration %f\n",
+                TRACK(tr)->properties->duration);

             ret = TRACK(tr)->parser->parse(TRACK(tr), pkt.data, pkt.size,
                                     stream->codec->extradata,
                                     stream->codec->extradata_size);
-            fnc_log(FNC_LOG_DEBUG, "[MT] Parsing track %s\n",
-                    TRACK(tr)->info->name);
             break;
         }
     }
-#endif

     av_free_packet(&pkt);

     return ret;
 }
-// time_msec has to be in timebase units!
+
 static int seek(Resource * r, double time_sec)
 {
-//XXX check the timebase....
     int flags = 0;
     int64_t time_msec = time_sec * AV_TIME_BASE;
     AVFormatContext *fc = ((lavf_priv_t *)r->private_data)->avfc;


vere: disables sample profiling in the king

--- pkg/urbit/vere/king.c
+++ pkg/urbit/vere/king.c
@@ -704,10 +704,11 @@
   uv_timer_init(u3L, &u3K.tim_u);

   //  start up a "fast-compile" arvo for internal use only
-  //  (with hashboard always disabled)
+  //  (with hashboard and sample-profiling always disabled)
   //
   sag_w = u3C.wag_w;
   u3C.wag_w |= u3o_hashless;
+  u3C.wag_w &= ~u3o_debug_cpu;

   u3m_boot_lite();


Add OSCAP_HIDDEN macros to oscap_buffer.h

--- src/common/oscap_buffer.h
+++ src/common/oscap_buffer.h
@@ -23,6 +23,8 @@
 #ifndef OSCAP_BUFFER_H_
 #define OSCAP_BUFFER_H_
 #include "util.h"
+
+OSCAP_HIDDEN_START;

 struct oscap_buffer;

@@ -86,4 +88,7 @@
  * @return count of stored bytes
  */
 size_t oscap_buffer_get_length(const struct oscap_buffer *s);
+
+OSCAP_HIDDEN_END;
+
 #endif


test2

test2

added "lily's change" to see what happens when two people change things
at the same time


u3: refactors atom reallocation in u3a_take()

--- pkg/urbit/noun/allocate.c
+++ pkg/urbit/noun/allocate.c
@@ -1026,11 +1026,47 @@
   }
 }

+#undef VERBOSE_TAKE
+
+/* _ca_take_atom(): reallocate an indirect atom off the stack.
+*/
+static inline u3_atom
+_ca_take_atom(u3a_atom* old_u)
+{
+  c3_w*     new_w = u3a_walloc(old_u->len_w + c3_wiseof(u3a_atom));
+  u3a_atom* new_u = (u3a_atom*)(void *)new_w;
+  u3_noun     new = u3a_to_pug(u3a_outa(new_u));
+
+#ifdef VERBOSE_TAKE
+  u3l_log("%s: atom %p to %p\r\n", ( c3y == u3a_is_north(u3R) )
+                                   ? "north"
+                                   : "south",
+                                   old_u,
+                                   new_u);
+#endif
+
+  //  XX use memcpy?
+  //
+  new_u->mug_w = old_u->mug_w;
+  new_u->len_w = old_u->len_w;
+  {
+    c3_w i_w;
+
+    for ( i_w=0; i_w < old_u->len_w; i_w++ ) {
+      new_u->buf_w[i_w] = old_u->buf_w[i_w];
+    }
+  }
+
+  //  borrow mug slot to record new destination in [old_u]
+  //
+  old_u->mug_w = new;
+
+  return new;
+}
+
 #define TAKE_ROOT 0
 #define TAKE_HEAD 1
 #define TAKE_TAIL 2
-
-#undef VERBOSE_TAKE

 //  stack frame for recording head vs tail iteration
 //
@@ -1177,34 +1213,7 @@
       }
       else {
         if ( c3y == u3a_is_atom(veb) ) {
-          u3a_atom* old_u = u3a_to_ptr(veb);
-          c3_w*     new_w = u3a_walloc(old_u->len_w + c3_wiseof(u3a_atom));
-          u3a_atom* new_u = (u3a_atom*)(void *)new_w;
-          u3_noun     new = u3a_to_pug(u3a_outa(new_u));
-
-#ifdef VERBOSE_TAKE
-          u3l_log("%s: atom %p to %p\r\n", ( c3y == nor_o )
-                                           ? "north"
-                                           : "south",
-                                           old_u,
-                                           new_u);
-#endif
-
-          new_u->mug_w = old_u->mug_w;
-          new_u->len_w = old_u->len_w;
-          {
-            c3_w i_w;
-
-            for ( i_w=0; i_w < old_u->len_w; i_w++ ) {
-              new_u->buf_w[i_w] = old_u->buf_w[i_w];
-            }
-          }
-
-          //  Borrow mug slot to record new destination in .old_u.
-          //
-          old_u->mug_w = new;
-
-          pro = new;
+          pro = _ca_take_atom((u3a_atom*)veb_u);
           goto retreat;
         }
         else {