Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is probably a stupid question, but I was just wondering if the following is doable: If I should just forget about it and go the VM/ full GNU-Linux OS route, that's fine.

After mucking about with the source code for fortune and fortune-mod (available from ibiblio) and getting nowhere with attempts to replace Linux‑specific code with Windows‑specific code (possibly due to severe noobishness when it comes to C), I'm asking it anyway.

Does anyone have a command-line/ console window version of the BSD fortune/ fortune-mod program that will compile (and preferably run) either on a DOS machine or in a windows console/ command-prompt window (without cygwin, if possible)? Is it possible to compile fortune on a GNU/Linux machine, using GNU-Linux header files, but target it for a DOS/ Windows machine or is that a naïve question?

[EDIT] Should I rather ask this on stackoverflow?

share|improve this question
    
Have you tried compiling with mingw? –  Szymon Szydełko Dec 2 '13 at 20:56
1  
@SzymonSzydełko MinGW uses the Microsoft Visual C Runtime (msvcrt) C library, which does not support many of the symbols relied upon by fortune. It would require some porting work to get it to compile, let alone run properly. –  allquixotic Dec 2 '13 at 22:00

1 Answer 1

up vote 2 down vote accepted

From examining the source code of fortune.c from fortune-mod, it seems like significant porting effort would be required to make this compile natively on Windows. Cygwin is probably your best bet; all you'll have to do is ship the Cygwin runtime DLLs alongside the built EXE, and you won't have to run it inside a Cygwin terminal if you don't want to. Cygwin should provide 99% of the POSIX interop layer required to get it compiled. Failing that, there's a rewrite of Fortune in Python that will readily run on any platform.

You're welcome to try and port it yourself, but it won't compile with Visual Studio or MinGW unless you get rid of things like #include <sys/*.h> and fcntl.h from the source. These are POSIX-specific things that Windows does not natively support. See here -- file descriptors and sockets are treated very differently in Windows than on BSD/UNIX/Linux.

Cygwin, on the other hand, is designed to support exactly this type of thing, and it translates it under the hood into the equivalent Win32 calls. When compiling on Cygwin you may encounter some compile-time errors, but the severity and difficulty of these errors will be very minor compared to the difficulties encountered in porting it to compile on Visual Studio or MinGW.

Also, the cmd.exe shell environment for Microsoft Windows (at least on Windows NT and later) is not in any way related to DOS. I don't know why you would want to run anything on DOS unless it was absolutely necessary, and in this case, running DOS would make things harder, not easier.


Update:

Here are instructions for compiling on Cygwin:

  1. Install Cygwin
  2. Install the libpcreposix0, gcc-core, make, and libpcre-devel packages
  3. Unpack the fortune-mod-9708.tar.gz to a folder
  4. Edit Makefile with your favorite text editor
  5. Change line 49 to read: REGEXDEFS=-DHAVE_REGEX_H -DPOSIX_REGEX
  6. Change line 55 to read: REGEXLIBS=-lpcreposix
  7. Run make in the fortune-mod-9708 folder
  8. Wait
  9. Now you should have a compiled fortune.exe binary. The following binaries should exist:

    ./fortune/fortune.exe
    ./util/rot.exe
    ./util/strfile.exe
    ./util/unstr.exe

Now you can run make install and it'll put everything in /usr/local subdirectories. Or you can tweak the Makefile to install anywhere you want.

If you want to copy this tool to somewhere else, put the files /bin/cyg*.dll in /usr/local/games, then take the entire /usr/local folder, zip it up (or copy it somewhere), and run the games/fortune.exe as desired. You may need some additional DLLs from the cygwin bin directory; if you get errors when starting it, that's why. Put them in the same directory as fortune.exe to get it working.


My response to your mention of DOS:

no

share|improve this answer
    
Thank you for that answer. It is most comprehensive. I think I'll try the python route. Failing that, I'll try Cygwin. I'm not against Cygwin as a tool for migrating from Windows to GNU/Linux or BSD, but if I'm going to use a POSIX environment, I might as well do it with boots on and install GNU/Linux or BSD (no half measures). As for running things on DOS ; I have a perverse sense of fun, I guess. –  Agi Hammerthief Dec 25 '13 at 22:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.