home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / p / perl4036.zip / os2 / README.OLD < prev    next >
Text File  |  1992-10-05  |  10KB  |  275 lines

  1.            Notes on the OS/2 Perl port
  2.  
  3.             Raymond Chen
  4.          (rjc@math.princeton.edu)
  5.  
  6. -1.  Background.
  7.  
  8. This port was based on the MS-DOS port by Diomidis Spinellis.
  9.  
  10. 0.  Set-up.
  11.  
  12. First copy the files in the os2 directory into the parent
  13. directory.  Also install the file msdos/dir.h in your include
  14. directory.
  15.  
  16. 1.  Compiling.
  17.  
  18. Perl has been compiled under MS-DOS using the Microsoft C compiler
  19. version 6.0.  Before compiling install dir.h as <sys/dir.h>.  You will
  20. need a Unix-like make program and something like yacc (e.g. bison).  I
  21. just ran yacc on my UNIX box and downloaded the resulting y.tab.[ch]
  22. files.  Compilation takes 45 minutes on a 16MHz 386 machine running
  23. no jobs other than the compiler, so you will probably need something to
  24. do in the meantime.  Like, say, lunch.  (Compilation time does not
  25. include formatting the manual.)  If you compile with optimization
  26. turned off, it takes about half as long.
  27.  
  28. The executable is 270k (perlsym.exe is 473k; if you compile
  29. without optimization, the sizes are 329K/531K), and the top level
  30. directory needs 800K for sources, 550K for object code, and 800K for the
  31. executables, assuming you want to build both perl.exe and perlsym.exe
  32. with full optimization.
  33.  
  34. The makefile will compile glob for you which you will need to place
  35. somewhere in your path so that perl globbing will work correctly.  All
  36. the tests were run, although some modifications were necessary because
  37. OS/2 isn't UNIX. The tests that failed failed because of limitations of
  38. the operating system and aren't the fault of the compiler.  a2p and s2p
  39. were not tested.
  40.  
  41. In the eg directory you will find the syscalls.pl header file,
  42. and a sample program that demonstrates some of the improvements
  43. of the OS/2 version over the MS-DOS version and some of the
  44. system calls.
  45.  
  46. 2.  Using OS/2 Perl
  47.  
  48. The OS/2 version of perl has much of the functionality of the Unix
  49. version.  Here are some things that don't work:  sockets, password
  50. functions, [gs]et[eug]id, dbm functions, fork.
  51.  
  52. One thing that doesn't work is "split" with no arguments.  Somehow,
  53. yylval.arg is empty ...  [[ Wait, sorry, I fixed that. --rjc ]]
  54.  
  55. Care has been taken to implement the rest, although the implementation
  56. might not be the best possible.  Here are short notes on the tricky
  57. bits:
  58.  
  59. 2.1.  In-place editing.
  60.  
  61. Files currently can be edited in-place provided you are creating a
  62. backup.  Considerable effort is made to ensure that a reasonable
  63. name for the backup is selected, while still remaining within
  64. the 8.3 contraints of the FAT filesystem.  (HPFS users have nothing
  65. to worry about, since HPFS doesn't have the stupid 8.3 rule.)
  66.  
  67. The rules for how OS/2 perl combines your filename with the suffix
  68. (the thing passed to "-i") are rather complicated, but the basic
  69. idea is that the "obvious" name is chosen.
  70.  
  71. Here are the rules:
  72.  
  73. Style 0:  Append the suffix exactly as UNIX perl would do it.
  74.           If the filesystem likes it, use it.  (HPFS will always
  75.           swallow it.  FAT will rarely accept it.)
  76.  
  77. Style 1:  If the suffix begins with a '.', change the file extension
  78.       to whatever you supplied.  If the name matches the original
  79.       name, use the fallback method.
  80.  
  81. Style 2:  If the suffix is a single character, not a '.', try to add the
  82.           suffix to the following places, using the first one that works.
  83.               [1] Append to extension.
  84.               [2] Append to filename,
  85.               [3] Replace end of extension,
  86.               [4] Replace end of filename.
  87.           If the name matches the original name, use the fallback method.
  88.  
  89. Style 3:  Any other case:  Ignore the suffix completely and use the
  90.           fallback method.
  91.  
  92. Fallback method:  Change the extension to ".$$$".  If that matches the
  93.           original name, then change the extension to ".~~~".
  94.  
  95. If filename is more than 1000 characters long, we die a horrible
  96. death.  Sorry.
  97.  
  98. Examples, assuming style 0 failed.
  99.  
  100. suffix = ".bak" (style 1)
  101.                foo.bar => foo.bak
  102.                foo.bak => foo.$$$    (fallback)
  103.                foo.$$$ => foo.~~~    (fallback)
  104.                makefile => makefile.bak
  105.  
  106. suffix = "~" (style 2)
  107.                foo.c => foo.c~
  108.                foo.c~ => foo.c~~
  109.                foo.c~~ => foo~.c~~
  110.                foo~.c~~ => foo~~.c~~
  111.                foo~~~~~.c~~ => foo~~~~~.$$$ (fallback)
  112.  
  113.                foo.pas => foo~.pas
  114.                makefile => makefile.~
  115.                longname.fil => longname.fi~
  116.                longname.fi~ => longnam~.fi~
  117.                longnam~.fi~ => longnam~.$$$
  118.  
  119. 2.2.  Directory access.
  120.  
  121. Are implemented, but in order to support telldir() and seekdir(),
  122. they operate by reading in the entire directory at opendir(),
  123. then handing out pieces of it each time you do a readdir().
  124.  
  125. 2.3.  Pipes and redirection.
  126.  
  127. Pipes and redirection are supported.  Although OS/2 does not
  128. terminate programs which try to write to closed pipes, perl will
  129. kill them for you if you do it like this:
  130.  
  131.     open(I, "long-running-program|");
  132.     ... process a few lines ...
  133.     close(I);    # discard the rest ...
  134.  
  135. The killing works like this:  We wait until the child program either
  136. closes its stdout or tries to write to it.  If it writes to its stdout,
  137. we kill it.  Otherwise, we cwait for it.  This is pretty much what UNIX
  138. does by default.
  139.  
  140. All pipe commands are given to cmd.exe (or your COMSPEC) for execution as
  141.  
  142.     CMD /c your-command-line
  143.  
  144. so you can go ahead and load it up with any goofy things you want,
  145. like 2>1 redirection, more pipes, && || etc.
  146.  
  147. The pipe() function is also supported, so you can go ahead and
  148. make your own funky file descriptor connections before piping off
  149. a process.  However, you have to mark the descriptor you are
  150. retaining as NOINHERIT before spawning, else you are in deadlock city.
  151. Unfortunately, there's no way to mark the handle as NOINHERIT yet.
  152. It's on my wish list.
  153.  
  154. 2.4.  Syscall and Ioctl
  155.  
  156. IOCtl is not supported because the API is very different from the
  157. UNIX API.  Instead, IOCtl is supported as a syscall.  Here are
  158. the syscalls I've written so far:
  159.  
  160.     $OS2_GetVersion = 0;
  161.     $OS2_Shutdown = 1;
  162.     $OS2_Beep = 2;
  163.     $OS2_PhysicalDisk = 3;
  164.     $OS2_Config = 4;
  165.     $OS2_IOCtl = 5;
  166.     $OS2_QCurDisk = 6;
  167.     $OS2_SelectDisk = 7;
  168.     $OS2_SetMaxFH = 8;
  169.     $OS2_Sleep = 9;
  170.     $OS2_StartSession = 10;
  171.     $OS2_StopSession = 11;
  172.     $OS2_SelectSession = 12;
  173.  
  174. The arguments you pass are handed off to OS/2 without interpretation,
  175. and the return value is returned straight to you.  However, you don't
  176. have to supply arguments for the ones whose descriptions are "must be
  177. zero"; perl will supply the mandatory zeros for you.
  178.  
  179. 2.5.  Binary file access
  180.  
  181. Files are opened in text mode by default.  This means that CR LF pairs
  182. are translated to LF. If binary access is needed the `binarymode'
  183. function should be used.  There is currently no way to reverse the
  184. effect of the binary function.  If that is needed close and reopen the
  185. file.
  186.  
  187. 2.6.  Priority
  188.  
  189. The getpriority and setpriority functions are implemented, but since
  190. OS/2 priorities are different from UNIX priorities, the arguments aren't
  191. the same.  Basically, the arguments you pass are handed directly to
  192. OS/2. The only exception is the last argument to setpriority.  To make
  193. it easier to make delta priorities, if the priority class is 0xff, it
  194. is changed to 0.  That way, you can write
  195.  
  196.     setpriority(0,0,-2)
  197.  
  198. instead of
  199.  
  200.     setpriority(0,0,0xfe)
  201.  
  202. to decrease the delta by 2.
  203.  
  204. 2.7.  Interpreter startup.
  205.  
  206. The effect of the Unix #!/bin/perl interpreter startup can be obtained
  207. under OS/2 by giving the script a .cmd extension and beginning the script
  208. with the line
  209.  
  210.     extproc C:\binp\perl.exe -S
  211.  
  212. You should provide the appropriate path to your executable, and
  213. the -S option is necessary so that perl can find your script.
  214.  
  215. 2.8.  The kill function.
  216.  
  217. UNIX and OS/2 have different ideas about the kill function.  I've
  218. done a pretty feeble job of taking perl's UNIXish approach and
  219. trying to jam it into the OS/2 way.  No doubt you'll find that
  220. your kill()s aren't working.  My apologies in advance.
  221.  
  222. 3.  Bug reports.
  223.  
  224. I don't normally have access to an OS/2 machine, so if you find
  225. a bug, you can go ahead and tell me about it, but the odds that
  226. I'd be able to fix it are slim.
  227.  
  228. 4.  Wish list.
  229.  
  230. 4.1.  OS/2.
  231.  
  232. Make ENOPIPE a fatal error.
  233.  
  234. Permit linking of files.  (Allegedly, they're working on this.)
  235.  
  236. Get a fork.
  237.  
  238. Make CMD.EXE pass through the return code of its child.
  239.  
  240. 4.2 perl.
  241.  
  242. Provide a nice way to add new functions to perl without having
  243. to understand the innards of perl.  Not being fluent in perl
  244. innards hacking, I added my extra functions via syscall.
  245.  
  246. 4.3. My port.
  247.  
  248. 4.3.1.  In-place editing.
  249.  
  250. Make more idiot-proof.
  251.  
  252. Allow in-place editing without backup.  (How?)
  253.  
  254. 4.3.2.  Spawning and piping.
  255.  
  256. Make popen() cleverer.  Currently, it blindly hands everything
  257. off to CMD.EXE.  This wastes an exec if the command line didn't
  258. have any shell metacharacters and if the program being run
  259. is not a batch file.
  260.  
  261. Clever spawning is carried out by do_spawn.  We should try
  262. to make popen() do much of the same sort of preprocessing
  263. as do_spawn does (which means, of course, that we probably
  264. should yank out code to be dished off into a subroutine).
  265.  
  266. In do_spawn(), use DosExecPgm instead of spawnl in order to get more
  267. precise reasons why the child terminated (RESULTCODES).
  268.  
  269.  
  270.                 July 1990
  271.  
  272.                 Raymond Chen <rjc@math.princeton.edu>
  273.                 1817 Oxford St. Apt 6
  274.                 Berkeley, CA 94709-1828 USA
  275.