{"id":1220,"date":"2001-05-11T00:00:00","date_gmt":"2001-05-11T00:00:00","guid":{"rendered":"https:\/\/seegras.discordia.ch\/Blog\/?p=1220"},"modified":"2019-01-21T08:57:02","modified_gmt":"2019-01-21T07:57:02","slug":"issues-on-porting","status":"publish","type":"post","link":"https:\/\/seegras.discordia.ch\/Blog\/issues-on-porting\/","title":{"rendered":"Issues on Porting"},"content":{"rendered":"<div id=\"fortune\"><i><br \/>\nDOS not make sense<\/i><\/div>\n<div id=\"container\">\n<ul>\n<li><b>Fileformat:<\/b> Normally these things use CR\/LF, and sometimes<br \/>\nuse braindead ibmpc-character encoding. I use &#8220;recode ibmpc:utf8mb4&#8221;<br \/>\nto make umlauts meaningful and &#8220;pt -u&#8221; to convert CR\/LF&#8217;s. Makefiles<br \/>\nare mostly broken as well; and sources may contain some weird character<br \/>\nat the end of file.<\/li>\n<li><b>Filenames:<\/b> Normally crippled to 8.3 characters. I happened to<br \/>\ncome upon some filename which was sometimes written to disk uninitalized<br \/>\nresulting is a fopen()-failure on DOS but working on Unix. Thus, on<br \/>\nUnix you&#8217;d get a long string of garbled characters as filename..<\/li>\n<li><b>Memory Model:<\/b> DOS-programs come in different flavours of memory<br \/>\nmodels like &#8220;huge&#8221; or &#8220;small&#8221;, which is, of course, bogus. Delete it,<br \/>\nincluding &#8220;far&#8221;, &#8220;near&#8221; and &#8220;register&#8221;.<\/li>\n<li><b>Types:<\/b> On DOS, &#8220;int&#8221; normally is only 16bit, but is 32bit on<br \/>\nUnix. Depending on memory-models, pointers may also 16bit on DOS<br \/>\n(and of course are normally 32bit on Unix).<\/li>\n<li><b>Strings:<\/b> There are some naming differences on string-comparison<br \/>\nfunctions:<\/p>\n<pre>    <b>DOS:\t\tUnix:<\/b>\n    stricmp()\t\tstrcasecmp()\n    strnicmp()\t\tstrncasecmp()\n<\/pre>\n<\/li>\n<li><b>Language:<\/b> C and C++ generally work when used in Character-mode,<br \/>\ni.e. if no graphics are used. Pascal can be a bit harder to get to work,<br \/>\nthere are at least two pascal to C converters available. One is p2c of<br \/>\nthe FSF and another <a href=\"https:\/\/web.archive.org\/web\/20070622053204\/http:\/\/www.garret.ru:80\/~knizhnik\/sal.html\">ptoc<\/a>.<br \/>\nI have ported some application from pascal to C using p2c and correcting<br \/>\nbogus manually (see below). Of course, using gpc (GNU pascal compiler)<br \/>\nor fpc (<a href=\"https:\/\/www.freepascal.org\">free pascal compiler<\/a>)<br \/>\nyou can compile pascal natively. For Basic, there&#8217;s<br \/>\n<a href=\"https:\/\/web.archive.org\/web\/20030622163613\/http:\/\/random.com.hr:80\/products\/qb2c\/qb2c.html\">qb2c<\/a>, which<br \/>\ncan handle various basic-dialects through its preprocessor, but the<br \/>\nfree version doesn&#8217;t understand dynamic memory allocation (DIM-command)<br \/>\nwhich makes it pretty useless.<\/p>\n<pre>    <b>Pascal:\t\t\t\tC:<\/b>\n    assign FilePointer=Filename;\tFilePointer=fopen(Filename, \"w\");\n    _randint(15L);\t\t\t(rand()%15);\n    _randomize();\t\t\tsrand((unsigned int)time());\n<\/pre>\n<p>For the crippled dialect of Microsoft C for DOS, I wrote a very basic<br \/>\n<a href=\"\/Programs\/msc2bcc\">conversion-script<\/a> to Borland C (see libgrx).<\/li>\n<li><b>Character-Screen:<\/b> Normally, DOS-Programs either use conio.h<br \/>\nor Turbo Vision. There&#8217;s a Linux-Version of conio.h, but I don&#8217;t<br \/>\nlike it. You can easily replace conio with ncurses. There&#8217;s also<br \/>\n<a href=\"https:\/\/web.archive.org\/web\/20010616124614\/https:\/\/members.nbci.com\/stropea\/tvision.html\"><br \/>\nTurbo Vision for Unix<\/a>, though I don&#8217;t know whether it works correctly.<br \/>\nThe biggest nuisance with DOS-Programs is the stupid assumption of<br \/>\nits programmers that the screensize is 80&#215;25. I wasn&#8217;t able to handle<br \/>\nother screensizes with the linux-conio, so I replaced every occurence<br \/>\nof conio-commands with their ncurses-equivalents.<\/p>\n<pre>    <b>DOS:\t\tUNIX (curses):<\/b>\n    clrsrc();\t\tclear();\n    gotoxy(Col, Row)\tmove(Row, Col); refresh();\n    getch()\t\tgetchar();\n    printf(\"string\");\twprintw(window,\"string\");\t#to avoid 80x25 issues\n    cprintf(\"string\");  wprintw(window,\"string\");\n    window(a,b,c,d);    window = newwin(lines,cols,begin_y,begin_x);\n<\/pre>\n<p>Currently I&#8217;m working on some perl-scripts to automate this.<\/p>\n<p>Alternatively it makes sense just to replace getch(), like this:<\/p>\n<pre>    <b>DOS:\t\tUNIX (curses):<\/b>\n    getch()\t\tint ch, charactr;\n\t\t\twhile ((ch=getchar()) != 'n') {\n\t\t\tcharactr=ch;\n\t\t\t}\n<\/pre>\n<p>Perhaps it is most easy to use my <a href=\"\/Programs\/getch.c\">getch.c<\/a>-function<br \/>\nto subsitute this. All you&#8217;ve got to do is to include it in the source.<\/li>\n<li><b>Graphics:<\/b> There&#8217;s a<br \/>\n<a href=\"https:\/\/www.boutell.com\/lsm\/lsmbyid.cgi\/000534\">BGI-Library<\/a> for Linux, which doesn&#8217;t seem to work (a.out, no source<br \/>\navailable). Another possibility seems to be<br \/>\n<a href=\"ftp:\/\/sunsite.unc.edu\/pub\/Linux\/libs\/graphics\/\"><br \/>\nlibgrx<\/a>, along with <a href=\"https:\/\/github.com\/msikma\/grx249\/\">bcc2grx<\/a>, but libgrx seems to be seriously broken, and has problems with<br \/>\nmice and Keyboard on modern (glibc) systems.<br \/>\nThen <a href=\"https:\/\/en.wikipedia.org\/wiki\/Free_Pascal\">FPK Free Pascal<\/a>, a Pascal-compiler which can do Delphi II can handle SVGA-Graphics<br \/>\nas well, but not X. <a href=\"https:\/\/web.archive.org\/web\/20030622163613\/http:\/\/random.com.hr:80\/products\/qb2c\/qb2c.html\">qb2c<\/a><br \/>\nin contrast appears to be able to do graphics on X.<\/p>\n<p>On a related note, there&#8217;s a <a href=\"https:\/\/web.archive.org\/web\/20050524080250\/https:\/\/home.i1.net\/~naken\/vb2c\/\"><br \/>\nVisual Basic to C\/GTK-converter<\/a>, but I haven&#8217;t tried it yet.<\/li>\n<li><b>Function-Keys:<\/b> Handling of Function-keys, including DOWN, UP,<br \/>\nPGUP and PGDN seems to be mostly messy. I haven&#8217;t soled this right<br \/>\nnow. It also seems that the conio.h getch() behaves different from<br \/>\nthe ncurses getchar(). Plus there&#8217;s the issue of kbhit() which is<br \/>\npolling(!) the keyboard, which is an unbelievable stupidity and has<br \/>\nto be replaced with select() or something.<\/li>\n<li><b>Random Numbers:<\/b> Most DOS-programs can&#8217;t do these correctly and<br \/>\nthey break on Unix, either resulting in always the same numbers given<br \/>\nback, or numbers of completely different length.<\/p>\n<pre>    <b>DOS:\t\tUNIX:<\/b>\n    randomize();\tsrand((unsigned int)time());\n    random(number);\trand()%number;\n<\/pre>\n<\/li>\n<li>There&#8217;s also another essay on this called<br \/>\n<a href=\"https:\/\/web.archive.org\/web\/20011201183715\/http:\/\/roadrunner.swansea.uk.linux.org\/dosport.html\">Porting<br \/>\nDOS applications to Linux<\/a> by Alan Cox.<br \/>\nAlso, there&#8217;s short writeup on porting DOS-programs which play with<br \/>\nhardware, it&#8217;s <a href=\"http:\/\/uw714doc.sco.com\/en\/HDK_concepts\/unixdos_inb.html\">Porting DOS inb and outb functionality<\/a> by someone at SCO.<\/p>\n<p>In the meantime, some other related articles have appeared:<br \/>\n<a href=\"https:\/\/www.linuxjournal.com\/article\/2279\">Porting MS-DOS Graphics Applications<\/a> in Linux Journal 53.<br \/>\n<a href=\"http:\/\/www.tldp.org\/LDP\/LG\/issue58\/taylor.html\">Easily Porting MS-DOS Diagnostics to Linux<\/a> in LinuxGazette 58.<br \/>\n<a href=\"https:\/\/web.archive.org\/web\/20030415012028\/https:\/\/www.cs.berkeley.edu\/~mdw\/linux\/porting-linux\/html\/paper.html\">Porting Applications to Linux<\/a> from Matt Welsh.<br \/>\nRelated: <a href=\"https:\/\/www.linuxjournal.com\/article\/3007\">Porting SGI Audio Applications to Linux<\/a>, again, fom Linux Journal 53.<br \/>\n<a href=\"https:\/\/www.freelabs.com\/~whitis\/linux\/porting_windows.html\"><br \/>\nPorting Windows Applications to Linux<\/a> from Mark Whitis.<br \/>\n<a href=\"https:\/\/www.ibm.com\/developerworks\/library\/l-portsolaris\/index.html\">Solaris-to-Linux Porting Guide<\/a> from Ulrich Drepper.<br \/>\n<a href=\"https:\/\/web.archive.org\/web\/20021216072727\/https:\/\/www.p-nand-q.com\/linux.htm\">Porting Win32 Applications To Linux<\/a> from Gerson Kurz.<br \/>\n<a href=\"https:\/\/www-106.ibm.com\/developerworks\/linux\/library\/l-mfc\/\"><br \/>\nPorting MFC applications to Linux<\/a> from Markus Neifer.<br \/>\n<a href=\"https:\/\/www.icculus.org\/~icculus\/writing\/linux.com\/mfc_to_gtk.txt\"><br \/>\nPorting MFC to GTK+<\/a> by Ryan C. Gordon.<br \/>\n<a href=\"https:\/\/www-106.ibm.com\/developerworks\/linux\/library\/l-osmig1.html\"><br \/>\nMigrate your apps from OS\/2 to Linux<\/a> IBM.<\/li>\n<\/ul>\n<p>Peter Keel,<\/p>\n<div id=\"date\">2001-05-11<\/div>\n<p>last update (links) 03.09.2004<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>DOS not make sense Fileformat: Normally these things use CR\/LF, and sometimes use braindead ibmpc-character encoding. I use &#8220;recode ibmpc:utf8mb4&#8221; to make umlauts meaningful and &#8220;pt -u&#8221; to convert CR\/LF&#8217;s. Makefiles are mostly broken as well; and sources may contain some weird character at the end of file. Filenames: Normally crippled to 8.3 characters. I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1220","post","type-post","status-publish","format-standard","hentry","category-computers"],"_links":{"self":[{"href":"https:\/\/seegras.discordia.ch\/Blog\/wp-json\/wp\/v2\/posts\/1220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seegras.discordia.ch\/Blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seegras.discordia.ch\/Blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seegras.discordia.ch\/Blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seegras.discordia.ch\/Blog\/wp-json\/wp\/v2\/comments?post=1220"}],"version-history":[{"count":12,"href":"https:\/\/seegras.discordia.ch\/Blog\/wp-json\/wp\/v2\/posts\/1220\/revisions"}],"predecessor-version":[{"id":1328,"href":"https:\/\/seegras.discordia.ch\/Blog\/wp-json\/wp\/v2\/posts\/1220\/revisions\/1328"}],"wp:attachment":[{"href":"https:\/\/seegras.discordia.ch\/Blog\/wp-json\/wp\/v2\/media?parent=1220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seegras.discordia.ch\/Blog\/wp-json\/wp\/v2\/categories?post=1220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seegras.discordia.ch\/Blog\/wp-json\/wp\/v2\/tags?post=1220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}