$OpenBSD: patch-src_synctex_parser_utils_c,v 1.1 2019/01/20 11:20:45 edd Exp $

Make texworks build against a newer synctex:
https://github.com/TeXworks/texworks/commit/496cc1785f335f0eb4451005025fe11ae295d3e4

Index: src/synctex_parser_utils.c
--- src/synctex_parser_utils.c.orig
+++ src/synctex_parser_utils.c
@@ -1,42 +1,41 @@
 /* 
-Copyright (c) 2008, 2009, 2010 , 2011 jerome DOT laurens AT u-bourgogne DOT fr
+ Copyright (c) 2008-2017 jerome DOT laurens AT u-bourgogne DOT fr
+ 
+ This file is part of the __SyncTeX__ package.
+ 
+ [//]: # (Latest Revision: Fri Jul 14 16:20:41 UTC 2017)
+ [//]: # (Version: 1.19)
+ 
+ See `synctex_parser_readme.md` for more details
+ 
+ ## License
+ 
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+ 
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE
+ 
+ Except as contained in this notice, the name of the copyright holder
+ shall not be used in advertising or otherwise to promote the sale,
+ use or other dealings in this Software without prior written
+ authorization from the copyright holder.
 
-This file is part of the SyncTeX package.
-
-Latest Revision: Tue Jun 14 08:23:30 UTC 2011
-
-Version: 1.18
-
-See synctex_parser_readme.txt for more details
-
-License:
---------
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE
-
-Except as contained in this notice, the name of the copyright holder  
-shall not be used in advertising or otherwise to promote the sale,  
-use or other dealings in this Software without prior written  
-authorization from the copyright holder.
-
 */
 
 /*  In this file, we find all the functions that may depend on the operating system. */
@@ -61,7 +60,7 @@ authorization from the copyright holder.
 #define SYNCTEX_OS2 1
 #endif
 
-#ifdef _WIN32_WINNT_WINXP
+#if defined(_WIN32)
 #define SYNCTEX_RECENT_WINDOWS 1
 #endif
 
@@ -71,18 +70,25 @@ authorization from the copyright holder.
 #endif
 
 void *_synctex_malloc(size_t size) {
-	void * ptr = malloc(size);
-	if(ptr) {
-/*  There used to be a switch to use bzero because it is more secure. JL */
-		memset(ptr,0, size);
-	}
-	return (void *)ptr;
+    void * ptr = malloc(size);
+    if(ptr) {
+        memset(ptr,0, size);/* ensures null termination of strings */
+    }
+    return (void *)ptr;
 }
 
-int _synctex_error(const char * reason,...) {
-	va_list arg;
+void _synctex_free(void * ptr) {
+    if (ptr) {
+        free(ptr);
+    }
+}
+
+#if !defined(_WIN32)
+#   include <syslog.h>
+#endif
+
+int _synctex_log(int level, const char * prompt, const char * reason,va_list arg) {
 	int result;
-	va_start (arg, reason);
 #	ifdef SYNCTEX_RECENT_WINDOWS
 	{/*	This code is contributed by William Blum.
         As it does not work on some older computers,
@@ -94,23 +100,65 @@ int _synctex_error(const char * reason,...) {
         JL.*/
 		char *buff;
 		size_t len;
-		OutputDebugStringA("SyncTeX ERROR: ");
+		OutputDebugStringA(prompt);
 		len = _vscprintf(reason, arg) + 1;
 		buff = (char*)malloc( len * sizeof(char) );
-		result = vsprintf(buff, reason, arg) +strlen("SyncTeX ERROR: ");
+		result = vsprintf(buff, reason, arg) +strlen(prompt);
 		OutputDebugStringA(buff);
 		OutputDebugStringA("\n");
 		free(buff);
 	}
+#   elif SYNCTEX_USE_SYSLOG
+    char * buffer1 = NULL;
+    char * buffer2 = NULL;
+    openlog ("SyncTeX", LOG_CONS | LOG_PID | LOG_PERROR | LOG_NDELAY, LOG_LOCAL0);
+    if (vasprintf(&buffer1,reason,arg)>=0
+        && asprintf(&buffer2,"%s%s",prompt, buffer1)>=0) {
+        syslog (level, "%s", buffer2);
+        result = (int)strlen(buffer2);
+    } else {
+        syslog (level, "%s",prompt);
+        vsyslog(level,reason,arg);
+        result = (int)strlen(prompt);
+    }
+    free(buffer1);
+    free(buffer2);
+    closelog();
 #   else
-	result = fprintf(stderr,"SyncTeX ERROR: ");
-	result += vfprintf(stderr, reason, arg);
-	result += fprintf(stderr,"\n");
+    FILE * where = level == LOG_ERR? stderr: stdout;
+    result = fputs(prompt,where);
+    result += vfprintf(where, reason, arg);
+    result += fprintf(where,"\n");
 #   endif
-	va_end (arg);
 	return result;
 }
 
+int _synctex_error(const char * reason,...) {
+    va_list arg;
+    int result;
+    va_start (arg, reason);
+#if defined(SYNCTEX_RECENT_WINDOWS) /* LOG_ERR is not used */
+    result = _synctex_log(0, "! SyncTeX Error : ", reason, arg);
+#else
+    result = _synctex_log(LOG_ERR, "! SyncTeX Error : ", reason, arg);
+#endif
+    va_end (arg);
+    return result;
+}
+
+int _synctex_debug(const char * reason,...) {
+    va_list arg;
+    int result;
+    va_start (arg, reason);
+#if defined(SYNCTEX_RECENT_WINDOWS) /* LOG_DEBUG is not used */
+    result = _synctex_log(0, "! SyncTeX Error : ", reason, arg);
+#else
+    result = _synctex_log(LOG_DEBUG, "! SyncTeX Error : ", reason, arg);
+#endif
+    va_end (arg);
+    return result;
+}
+
 /*  strip the last extension of the given string, this string is modified! */
 void _synctex_strip_last_path_extension(char * string) {
 	if(NULL != string){
@@ -250,8 +298,8 @@ const char * _synctex_last_path_component(const char *
 }
 
 int _synctex_copy_with_quoting_last_path_component(const char * src, char ** dest_ref, size_t size) {
-  const char * lpc;
   if(src && dest_ref) {
+      const char * lpc;
 #		define dest (*dest_ref)
 		dest = NULL;	/*	Default behavior: no change and sucess. */
 		lpc = _synctex_last_path_component(src);
@@ -396,7 +444,6 @@ int _synctex_get_name(const char * output, const char 
 				if(NULL == (dir_name = (char *)malloc(size+1))) {
 					_synctex_error("!  _synctex_get_name: Memory problem");
 					free(core_name);
-					dir_name = NULL;
 					return -1;
 				}
 				if(dir_name != strncpy(dir_name,output,size)) {
@@ -497,6 +544,17 @@ int _synctex_get_name(const char * output, const char 
 #			undef CLEAN_AND_REMOVE
             /* set up the returned values */
             * synctex_name_ref = synctex_name;
+            /* synctex_name won't always end in .gz, even when compressed. */
+            FILE * F = fopen(synctex_name, "r");
+            if (F != NULL) {
+                if (!feof(F)
+                && 31 == fgetc(F)
+                && !feof(F)
+                && 139 == fgetc(F)) {
+                    io_mode = synctex_compress_mode_gz;
+                }
+                fclose(F);
+            }
             * io_mode_ref = io_mode;
 			return 0;
 		}
