rosegondon
C:\DOS, 18.09.2021, 02:50 |
How to compile this program for DOS? (Developers) |
Hello,
Regarding https://www.fourmilab.ch/onetime/otp-1.2.2.tar.gz
Using DJGPP under Windows I was able to compile it for Win32 target without any problems.
Using equivalent DOS DJGPP build on the same source code all I produced was a long screen of compiler rants about various errors, some with suggestions of fixes based on various "-W" directives, but they were not helpful, because program does not compile, even if some of the errors vanished.
So how to compile this code for DOS (32 bit) target? Please note I am not fluent in C. --- echo g=ffff:0|debug>nul |
sezeroz
18.09.2021, 14:47
@ rosegondon
|
How to compile this program for DOS? |
If you patch it like the following, it does compile.
(Not run-tested at all, though.)
--- otp.c~
+++ otp.c
@@ -55,8 +55,12 @@
#ifdef WIN32
#include <windows.h>
#endif
-
-#ifdef unix
+#ifdef __DJGPP
+#define __far
+#define _intdos intdos
+#define _REGS REGS
+#endif
+#if defined(unix) && !defined(__DJGPP)
#include <sys/time.h>
extern int getpid(), getppid(), gethostid();
#endif
@@ -189,7 +193,7 @@
#ifdef MSDOS
union _REGS ri, ro;
#endif
-#ifdef unix
+#if defined(unix) && !defined(__DJGPP)
struct timeval tv;
#endif
@@ -340,7 +344,7 @@
#define OS_KNOWN 1
#endif
-#ifdef unix
+#if defined(unix) && !defined(__DJGPP)
FILE *rf;
size_t ct;
|
rosegondon
C:\DOS, 18.09.2021, 18:37
@ sezeroz
|
How to compile this program for DOS? |
patch.exe from UnxUtils failed, same for patch.exe from Perl for Windows.
Error message:
patching file otp.c
Hunk #2 FAILED at 193.
patch unexpectedly ends in middle of line
Hunk #3 succeeded at 344 with fuzz 2.
1 out of 3 hunks FAILED -- saving rejects to file otp.c.rej
otp.c.rej contents:
***************
*** 189,195 ****
#ifdef MSDOS
union _REGS ri, ro;
#endif
- #ifdef unix
struct timeval tv;
#endif
--- 193,199 ----
#ifdef MSDOS
union _REGS ri, ro;
#endif
+ #if defined(unix) && !defined(__DJGPP)
struct timeval tv;
#endif
> If you patch it like the following, it does compile.
> (Not run-tested at all, though.)
>
>
> --- otp.c~
> +++ otp.c
> @@ -55,8 +55,12 @@
> #ifdef WIN32
> #include <windows.h>
> #endif
> -
> -#ifdef unix
> +#ifdef __DJGPP
> +#define __far
> +#define _intdos intdos
> +#define _REGS REGS
> +#endif
> +#if defined(unix) && !defined(__DJGPP)
> #include <sys/time.h>
> extern int getpid(), getppid(), gethostid();
> #endif
> @@ -189,7 +193,7 @@
> #ifdef MSDOS
> union _REGS ri, ro;
> #endif
> -#ifdef unix
> +#if defined(unix) && !defined(__DJGPP)
> struct timeval tv;
> #endif
>
> @@ -340,7 +344,7 @@
> #define OS_KNOWN 1
> #endif
>
> -#ifdef unix
> +#if defined(unix) && !defined(__DJGPP)
> FILE *rf;
> size_t ct;
> --- echo g=ffff:0|debug>nul |
tkchia
18.09.2021, 21:16
@ rosegondon
|
How to compile this program for DOS? |
Hello rosegondon, hello sezeros,
> patching file otp.c
> Hunk #2 FAILED at 193.
> patch unexpectedly ends in middle of line
> Hunk #3 succeeded at 344 with fuzz 2.
> 1 out of 3 hunks FAILED -- saving rejects to file otp.c.rej
>
Whitespace issue (argh!). There is a tab character after the first #endif in the rejected patch portion --- you will need to edit the patch to add it in (or maybe change spaces into tabs).
Actually I think sezeros's patch throws away a bit too much code. The Unix-specific code (#ifdef unix ... #endif) tries to gather some bits of randomness by calling gettimeofday(...):
#ifdef unix
FILE *rf;
size_t ct;
gettimeofday(&tv, (struct timezone *) NULL);
trash[1] = tv.tv_sec;
trash[2] = tv.tv_usec;
...
#define OS_KNOWN 1
#endif
... and DJGPP does support gettimeofday(...). Unfortunately, the patch will disable the code, which will reduce the amount of randomness the program can use. There is probably a better way...
Thank you! --- https://gitlab.com/tkchia · https://codeberg.org/tkchia · 😴 "MOV AX,0D500H+CMOS_REG_D+NMI" |
tkchia
18.09.2021, 21:31
@ rosegondon
|
How to compile this program for DOS? |
Hello rosegondon,
My proposed modified patch (for now) is as follows:
--- otp.c.orig 2021-09-18 18:49:22.723186562 +0000
+++ otp.c 2021-09-18 19:27:31.893487497 +0000
@@ -57,4 +57,10 @@
#endif
+#ifdef __DJGPP
+#define __far
+#define _intdos intdos
+#define _REGS REGS
+#endif
+
#ifdef unix
#include <sys/time.h>
@@ -311,8 +317,8 @@
ri.h.dl = 0; /* Default drive */
if (_intdos(&ri, &ro) != 0xFFFF) {
- trash[1] = (((int32_t) ro.x.ax) << 16) | ro.x.bx;
- trash[2] = (((int32_t) ro.x.cx) << 16) | ro.x.dx;
+ trash[5] = (((int32_t) ro.x.ax) << 16) | ro.x.bx;
+ trash[6] = (((int32_t) ro.x.cx) << 16) | ro.x.dx;
}
- trash[4] = (int32_t) (char __far *) trash;
+ trash[7] = (int32_t) (char __far *) trash;
#define OS_KNOWN 1
#endif
@@ -353,5 +359,7 @@
trash[4] = getpid();
trash[11] = getppid();
+#ifndef __DJGPP
trash[38] = gethostid();
+#endif
/* If the system implements /dev/random, obtain 16 bytes
of entropy thence. */
Further improvements are probably possible.
Thank you! --- https://gitlab.com/tkchia · https://codeberg.org/tkchia · 😴 "MOV AX,0D500H+CMOS_REG_D+NMI" |
rosegondon
C:\DOS, 19.09.2021, 01:28
@ tkchia
|
How to compile this program for DOS? |
Hi sezeroz & tkchia,
@sezeroz, thank you for your patch, after I applied it, program compiled regardless of patching errors.
@tkchia, your patch triggers whitespace errors too, I will try to
manually apply your modifications in source code. Probably something happens with text when copying&pasting from this forum to patch file.
Thank you for you help, now I will make code changes and tests on my DOS machine and I hope to come back with results soon.
> Hello rosegondon,
>
> My proposed modified patch (for now) is as follows:
>
> --- otp.c.orig 2021-09-18 18:49:22.723186562 +0000
> +++ otp.c 2021-09-18 19:27:31.893487497 +0000
> @@ -57,4 +57,10 @@
> #endif
>
> +#ifdef __DJGPP
> +#define __far
> +#define _intdos intdos
> +#define _REGS REGS
> +#endif
> +
> #ifdef unix
> #include <sys/time.h>
> @@ -311,8 +317,8 @@
> ri.h.dl = 0; /* Default drive */
> if (_intdos(&ri, &ro) != 0xFFFF) {
> - trash[1] = (((int32_t) ro.x.ax) << 16) | ro.x.bx;
> - trash[2] = (((int32_t) ro.x.cx) << 16) | ro.x.dx;
> + trash[5] = (((int32_t) ro.x.ax) << 16) | ro.x.bx;
> + trash[6] = (((int32_t) ro.x.cx) << 16) | ro.x.dx;
> }
> - trash[4] = (int32_t) (char __far *) trash;
> + trash[7] = (int32_t) (char __far *) trash;
> #define OS_KNOWN 1
> #endif
> @@ -353,5 +359,7 @@
> trash[4] = getpid();
> trash[11] = getppid();
> +#ifndef __DJGPP
> trash[38] = gethostid();
> +#endif
> /* If the system implements /dev/random, obtain 16 bytes
> of entropy thence. */
>
> Further improvements are probably possible.
>
> Thank you! --- echo g=ffff:0|debug>nul |
Rugxulo
Usono, 19.09.2021, 06:20
@ rosegondon
|
How to compile this program for DOS? (patch) |
> @tkchia, your patch triggers whitespace errors too, I will try to
> manually apply your modifications in source code. Probably something
> happens with text when copying&pasting from this forum to patch file.
The Linux manual for patch says this (which was what I faintly remembered):
> -l or --ignore-whitespace
> Match patterns loosely, in case tabs or spaces have been
> munged in your files. Any sequence of one or more blanks in
> the patch file matches any sequence in the original file, and
> sequences of blanks at the ends of lines are ignored. Normal
> characters must still match exactly. Each line of the context
> must still match a line in the original file. |
rosegondon
C:\DOS, 19.09.2021, 09:40
@ Rugxulo
|
How to compile this program for DOS? (patch) |
@Rugxulo, thank you! After using this directive patches were applied without errors.
> > @tkchia, your patch triggers whitespace errors too
> > -l or --ignore-whitespace
> > Match patterns loosely, in case tabs or spaces have been
> > munged in your files. --- echo g=ffff:0|debug>nul |