magic icon indicating copy to clipboard operation
magic copied to clipboard

Compilation: Mismatch between `utils/magsgtty.h` and `textio/txInput.c` on v8.3.534

Open tskaar opened this issue 5 months ago • 6 comments

Hi,

When trying to compile the latest tag, there is multiple mismatches due to the major rework done. Specifically there are issues around how the different includes are currently handled between utils/magstty.h and textio/txInput.c.

I believe a significant part of the confusion arises because -DSYSV=1 being set unconditionally in configure for all Linux platforms?:

case $target in
  *-linux*)
    AC_DEFINE(linux)
    AC_DEFINE(SYSV)

(https://github.com/RTimothyEdwards/magic/blob/1ec8b6ee1a30c09debe5ad8a3208d810fdb1219f/scripts/configure.in#L1430C1-L1430C20)

Anyways, I can get the build to work (for me, but probably broke some of the platforms along the way!) with some changes in the macros

magsgtty.h patch
diff --git a/utils/magsgtty.h b/utils/magsgtty.h
index 59e0678a..3f801d2a 100644
--- a/utils/magsgtty.h
+++ b/utils/magsgtty.h
@@ -21,19 +21,6 @@
 #ifndef	_MAGIC__UTILS__MAGSGTTY_H
 #define _MAGIC__UTILS__MAGSGTTY_H
 
-/* maybe this can be #ifndef HAVE_TERMIO_H */
-#if !defined(SYSV) && !defined(CYGWIN)
-
-# ifdef	ALPHA
-# undef MAX
-# undef MIN
-# endif
-
-/* unclear what platform requires this OpenBSD/FreeBSD ? */
-# ifndef COMPAT_43TTY
-# define COMPAT_43TTY
-# endif
-
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
@@ -59,6 +46,4 @@
 #include <termio.h>
 #endif
 
-#endif /* !SYSV && !CYGWIN */
-
 #endif	/* _MAGIC__UTILS__MAGSGTTY_H */

And then reflecting the changes in textio/txInput.c with the patch:

txInput.c patch
diff --git a/textio/txInput.c b/textio/txInput.c
index 1955daf6..71abe4da 100644
--- a/textio/txInput.c
+++ b/textio/txInput.c
@@ -1223,37 +1223,28 @@ TxGetLine(
  * ----------------------------------------------------------------------------
  */
 
-#if defined(SYSV) || defined(CYGWIN)
-
 void
 txGetTermState(
-    struct termio *buf)
+#if defined(HAVE_TERMIOS_H)
+    struct termios *buf
+#elif defined(HAVE_TERMIO_H)
+    struct termio *buf
+#else
+    txTermState *buf
+#endif
+  )
 {
+#if defined(HAVE_SYS_IOCTL_H)
     ioctl( fileno( stdin ), TCGETA, buf);
-}
-
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
-
-void
-txGetTermState(
-    struct termios *buf)
-{
+#elif defined(HAVE_SYS_IOCTL_COMPAT_H) // FIXME
     (void) tcgetattr(fileno(stdin), buf);
-}
-
 #else
-
-void
-txGetTermState(
-    txTermState *buf)
-{
     ASSERT(TxStdinIsatty, "txGetTermState");
     /* save the current terminal characteristics */
     (void) ioctl(fileno(stdin), TIOCGETP, (char *) &(buf->tx_i_sgtty) );
     (void) ioctl(fileno(stdin), TIOCGETC, (char *) &(buf->tx_i_tchars) );
+#endif
 }
-#endif /* SYSV */
-
 
 /*
  * ----------------------------------------------------------------------------
@@ -1271,18 +1262,18 @@ txGetTermState(
 
 void
 txSetTermState(
-#if defined(SYSV) || defined(CYGWIN)
-    struct termio *buf
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
+#if defined(HAVE_TERMIOS_H)
     struct termios *buf
+#elif defined(HAVE_TERMIO_H)
+    struct termio *buf
 #else
     txTermState *buf
-#endif /* SYSV */
+#endif 
     )
 {
-#if defined(SYSV) || defined(CYGWIN)
+#if defined(HAVE_SYS_IOCTL_H)
     ioctl( fileno(stdin), TCSETAF, buf );
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
+#elif defined (HAVE_SYS_IOCTL_COMPAT_H) // FIXME
     (void) tcsetattr( fileno(stdin), TCSANOW, buf );
 #else
     /* set the current terminal characteristics */
@@ -1311,16 +1302,16 @@ txSetTermState(
 
 void
 txInitTermRec(
-#if defined(SYSV) || defined(CYGWIN)
-    struct termio *buf
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
+#if defined(HAVE_TERMIOS_H)
     struct termios *buf
+#elif defined(HAVE_TERMIO_H)
+    struct termio *buf
 #else
     txTermState *buf
-#endif /* SYSV */
+#endif
     )
 {
-#if defined(SYSV) || defined(CYGWIN) || defined(__OpenBSD__) || defined(EMSCRIPTEN)
+#if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H)
     buf->c_lflag = ISIG;    /* raw: no echo and no processing, allow signals */
     buf->c_cc[ VMIN ] = 1;
     buf->c_cc[ VTIME ] = 0;
@@ -1335,13 +1326,13 @@ txInitTermRec(
 
 
 
-#if defined(SYSV) || defined(CYGWIN)
-struct termio closeTermState;
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
-struct termios closeTermState;
+#if defined(HAVE_TERMIOS_H)
+  struct termios closeTermState;
+#elif defined(HAVE_TERMIO_H)
+  struct termio closeTermState;
 #else
-static txTermState closeTermState;
-#endif /* SYSV */
+  static txTermState closeTermState;
+#endif
 
 static bool haveCloseState = FALSE;
 
@@ -1364,14 +1355,14 @@ static bool haveCloseState = FALSE;
 void
 txSaveTerm(void)
 {
-#if defined(SYSV) || defined(CYGWIN)
+  #if defined(HAVE_SYS_IOCTL_H)
     ioctl( fileno( stdin ), TCGETA, &closeTermState);
     txEraseChar = closeTermState.c_cc[VERASE];
     txKillChar =  closeTermState.c_cc[VKILL];
     TxEOFChar = closeTermState.c_cc[VEOF];
     TxInterruptChar = closeTermState.c_cc[VINTR];
     haveCloseState = TRUE;
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
+  #elif defined (__OpenBSD__) || defined(EMSCRIPTEN) // FIXME
     (void) tcgetattr( fileno( stdin ), &closeTermState);
     txEraseChar = closeTermState.c_cc[VERASE];
     txKillChar =  closeTermState.c_cc[VKILL];
@@ -1391,7 +1382,7 @@ txSaveTerm(void)
     TxEOFChar = closeTermState.tx_i_tchars.t_eofc;
     TxInterruptChar = closeTermState.tx_i_tchars.t_intrc;
     haveCloseState = TRUE;
-#endif /* SYSV */
+#endif
 }
 
 
@@ -1412,13 +1403,13 @@ txSaveTerm(void)
 void
 TxSetTerminal(void)
 {
-#if defined(SYSV) || defined(CYGWIN)
-    struct termio buf;
-#elif defined (__OpenBSD__) || defined(EMSCRIPTEN)
+  #if defined(HAVE_TERMIOS_H)
     struct termios buf;
-#else
+  #elif(HAVE_TERMIO_H)
+    struct termio buf;
+  #else
     txTermState buf;
-#endif /* SYSV */
+  #endif
 
 #ifdef MAGIC_WRAPPER
     /* If using Tk console, don't mess with the terminal settings;	  */


Build log excerpt without patches
txInput.c:1230:12: warning: ‘struct termio’ declared inside parameter list will not be visible outside of this definition or declaration
 1230 |     struct termio *buf)
      |            ^~~~~~
txInput.c: In function ‘txGetTermState’:
txInput.c:1232:5: error: implicit declaration of function ‘ioctl’; did you mean ‘iscntrl’? [-Wimplicit-function-declaration]
 1232 |     ioctl( fileno( stdin ), TCGETA, buf);
      |     ^~~~~
      |     iscntrl
txInput.c:1232:29: error: ‘TCGETA’ undeclared (first use in this function)
 1232 |     ioctl( fileno( stdin ), TCGETA, buf);
      |                             ^~~~~~
txInput.c:1232:29: note: each undeclared identifier is reported only once for each function it appears in
txInput.c: At top level:
txInput.c:1275:12: warning: ‘struct termio’ declared inside parameter list will not be visible outside of this definition or declaration
 1275 |     struct termio *buf
      |            ^~~~~~
txInput.c: In function ‘txSetTermState’:
txInput.c:1284:27: error: ‘TCSETAF’ undeclared (first use in this function)
 1284 |     ioctl( fileno(stdin), TCSETAF, buf );
      |                           ^~~~~~~
txInput.c: At top level:
txInput.c:1315:12: warning: ‘struct termio’ declared inside parameter list will not be visible outside of this definition or declaration
 1315 |     struct termio *buf
      |            ^~~~~~
txInput.c: In function ‘txInitTermRec’:
txInput.c:1324:8: error: invalid use of undefined type ‘struct termio’
 1324 |     buf->c_lflag = ISIG;    /* raw: no echo and no processing, allow signals */
      |        ^~
txInput.c:1324:20: error: ‘ISIG’ undeclared (first use in this function)
 1324 |     buf->c_lflag = ISIG;    /* raw: no echo and no processing, allow signals */
      |                    ^~~~
txInput.c:1325:8: error: invalid use of undefined type ‘struct termio’
 1325 |     buf->c_cc[ VMIN ] = 1;
      |        ^~
txInput.c:1325:16: error: ‘VMIN’ undeclared (first use in this function); did you mean ‘MIN’?
 1325 |     buf->c_cc[ VMIN ] = 1;
      |                ^~~~
      |                MIN
txInput.c:1326:8: error: invalid use of undefined type ‘struct termio’
 1326 |     buf->c_cc[ VTIME ] = 0;
      |        ^~
txInput.c:1326:16: error: ‘VTIME’ undeclared (first use in this function); did you mean ‘ETIME’?
 1326 |     buf->c_cc[ VTIME ] = 0;
      |                ^~~~~
      |                ETIME
txInput.c: In function ‘txSaveTerm’:
txInput.c:1368:29: error: ‘TCGETA’ undeclared (first use in this function)
 1368 |     ioctl( fileno( stdin ), TCGETA, &closeTermState);
      |                             ^~~~~~
txInput.c:1369:33: error: invalid use of undefined type ‘struct termio’
 1369 |     txEraseChar = closeTermState.c_cc[VERASE];
      |                                 ^
txInput.c:1369:39: error: ‘VERASE’ undeclared (first use in this function); did you mean ‘ERASE’?
 1369 |     txEraseChar = closeTermState.c_cc[VERASE];
      |                                       ^~~~~~
      |                                       ERASE
txInput.c:1370:33: error: invalid use of undefined type ‘struct termio’
 1370 |     txKillChar =  closeTermState.c_cc[VKILL];
      |                                 ^
txInput.c:1370:39: error: ‘VKILL’ undeclared (first use in this function)
 1370 |     txKillChar =  closeTermState.c_cc[VKILL];
      |                                       ^~~~~
txInput.c:1371:31: error: invalid use of undefined type ‘struct termio’
 1371 |     TxEOFChar = closeTermState.c_cc[VEOF];
      |                               ^
txInput.c:1371:37: error: ‘VEOF’ undeclared (first use in this function); did you mean ‘FEOF’?
 1371 |     TxEOFChar = closeTermState.c_cc[VEOF];
      |                                     ^~~~
      |                                     FEOF
txInput.c:1372:37: error: invalid use of undefined type ‘struct termio’
 1372 |     TxInterruptChar = closeTermState.c_cc[VINTR];
      |                                     ^
txInput.c:1372:43: error: ‘VINTR’ undeclared (first use in this function); did you mean ‘EINTR’?
 1372 |     TxInterruptChar = closeTermState.c_cc[VINTR];
      |                                           ^~~~~
      |                                           EINTR
txInput.c: In function ‘TxSetTerminal’:
txInput.c:1416:19: error: storage size of ‘buf’ isn’t known
 1416 |     struct termio buf;
      |                   ^~~
txInput.c:1432:15: error: ‘closeTermState’ has an incomplete type ‘struct termio’
 1432 |         buf = closeTermState;
      |               ^~~~~~~~~~~~~~
txInput.c: In function ‘TxResetTerminal’:
txInput.c:1466:57: error: passing argument 1 of ‘txSetTermState’ from incompatible pointer type [-Wincompatible-pointer-types]
 1466 |     if (TxStdinIsatty && haveCloseState) txSetTermState(&closeTermState);
      |                                                         ^~~~~~~~~~~~~~~
      |                                                         |
      |                                                         struct termio *
txInput.c:1275:20: note: expected ‘struct termio *’ but argument is of type ‘struct termio *’
 1275 |     struct termio *buf
      |     ~~~~~~~~~~~~~~~^~~
txInput.c: At top level:
txInput.c:1339:15: error: storage size of ‘closeTermState’ isn’t known
 1339 | struct termio closeTermState;
      |               ^~~~~~~~~~~~~~
make[1]: *** [../rules.mak:27: txInput.o] Error 1
make[1]: *** Waiting for unfinished jobs....

Let me know if you need additional information from me (and/or help testing patches etc)

Thanks in advance!

tskaar avatar Jul 30 '25 22:07 tskaar