home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ENUMDL.ZIP / ENUMDL.DOC
Text File  |  1990-04-24  |  5KB  |  139 lines

  1.     A tiny OS/2 program is presented in three different languages --
  2. a programmer's Rosetta Stone.  
  3.  
  4.     All the program does is loop through all possible module handles,
  5. printing out the names of all currently-loaded executables and
  6. dynamic-link libraries in all sessions.  It takes a long time to
  7. run, no matter what language is used.   
  8.  
  9.     The following comparison does not capture the fact that both
  10. UR/Forth and OS2XLISP allow you to run OS/2 programs immediately, 
  11. without having to compile and link them.  In fact, you can use them
  12. as OS/2 "calculators" ("hmmm, what does VioGetFont do?") without
  13. having to write a "program" at all:  you just type in expressions
  14. which are immediately evaluated.
  15.  
  16. ......................................................................
  17. in Forth (using Laboratory Microsystems 80286 UR/Forth 1.1 for OS/2):
  18.  
  19.     CREATE BUF 128 ALLOT                        \ make a buffer
  20.  
  21.     : ENUMDLL                                   \ define a word
  22.         65535 0 DO                              \ for i=0 to 65,535 do
  23.             I 128 DS0 BUF DOSGETMODNAME         \ DosGetModName(i,128,ds:buf)
  24.             0= IF                               \ if no error code
  25.                 CR                              \ carriage return
  26.                 I 5 U.R 3 SPACES                \ display i nicely
  27.                 BUF -ASCIIZ COUNT TYPE          \ display module name
  28.             THEN                                
  29.         LOOP                                    \ next i
  30.     ;                                               
  31.  
  32.     ENUMDLL                                     \ invoke the word
  33.  
  34. ......................................................................
  35. in Lisp (using OS2XLISP, version 1.10):
  36.  
  37.     (define buf (make-string 32 128))           ; string of 128 spaces
  38.     (define dosgetmodname (getprocaddr doscalls "DOSGETMODNAME"))
  39.     
  40.     (dotimes
  41.         (i #xFFFF)
  42.         (if
  43.             (call dosgetmodname (word i) (word 128) buf t)
  44.         ; then
  45.             (format stdout "~A\t~A\n" i buf)))
  46.                 
  47. ......................................................................
  48. in C (using Microsoft C 5.1):
  49.  
  50.     char buf[128];
  51.     register int i;
  52.     
  53.     for (i=0; i<=0xFFFF; i++)
  54.         if (! DosGetModName(i, 128, (char far *)buf))
  55.             printf("%u\t%s\n", i, buf);
  56.         
  57. ......................................................................
  58. sample output:
  59.  
  60.   140   A:\HARDERR.EXE
  61.   220   D:\OS2\DLL\BMSCALLS.DLL
  62.   380   D:\OS2\SYS\SHELL.EXE
  63.   600   E:\XLISP\NEW\OS2XLISP.EXE
  64.   630   A:\SWAPPER.EXE
  65.   750   D:\OS2\DLL\BKSCALLS.DLL
  66.   930   D:\OS2\DLL\ANSICALL.DLL
  67.  1230   D:\OS2\DLL\MOUCALLS.DLL
  68.  1240   D:\OS2\DLL\QUECALLS.DLL
  69.  1330   D:\OS2\DLL\SESMGR.DLL
  70.  1340   D:\OS2\DLL\BVSCALLS.DLL
  71.  1380   D:\OS2\DLL\VIOCALLS.DLL
  72.  1390   D:\OS2\DLL\KBDCALLS.DLL
  73.  1480   D:\OS2\DLL\DOSCALL1.DLL
  74.  1490   D:\OS2\DLL\NLS.DLL
  75.  1550   D:\OS2\DLL\MSG.DLL
  76.  2230   D:\OS2\DLL\CRTLIB.DLL
  77.  3010   D:\URFOS2\FORTH.EXE
  78.  3150   D:\OS2\DLL\MONCALLS.DLL
  79.  3190   D:\OS2\DLL\ALIAS.DLL
  80.  3630   D:\OS2\SYS\CMD.EXE
  81.  
  82. ......................................................................
  83. to time the loop, examine the elapsed-time field of the GDT InfoSeg;
  84. this field is a long at offset 4 in the GDT InfoSeg.
  85.  
  86. in Forth:
  87.  
  88. VARIABLE GDT
  89. VARIABLE LDT
  90.  
  91. DS0 GDT DS0 LDT DOSGETINFOSEG
  92.  
  93. : ELAPSED-TIME   GDT @ 4 2@L SWAP ;   ( --- d )
  94.  
  95.  ELAPSED-TIME   ( leave starting time on the stack)
  96.  ENUMDLL        ( do the operation)
  97.  ELAPSED-TIME   ( leave ending time on the stack)
  98.  2SWAP          ( put them in the right order for D- )
  99.  D- D.          ( find the difference and display it )
  100.  
  101. Incidentally you might want to look at the words @TIMER !TIMER and
  102. TIMER in FORTH.SCR too.
  103.  
  104. ......................................................................
  105. in Lisp:
  106.  
  107. (define gdt 0)
  108. (define ldt 0)
  109. (define dosgetinfoseg (getprocaddr doscalls "DOSGETINFOSEG"))
  110. (call dosgetinfoseg ^gdt ^ldt)
  111.  
  112. (define (elapsed-time)
  113.     (peek (mk-fp gdt 4) 'long))              ; milliseconds since IPL
  114.     
  115. ......................................................................
  116. in C:
  117.  
  118.     unsigned gdt, ldt;
  119.     
  120.     DosGetInfoSeg((unsigned far *) &gdt, (unsigned far *) &ldt);
  121.  
  122. #define MK_FP(a,b)      ((void far*)(((unsigned long)(a) << 16) | (b)))
  123. #define peekl(a,b)      (unsigned long)(*((unsigned long far*)MK_FP((a),(b))))
  124. #define elapsed_time()  (peekl(gdt,4))
  125.  
  126. ......................................................................
  127. presented for your edification and amusement by:
  128.  
  129.     Andrew Schulman
  130.     32 Andrews St.      /* ?! */
  131.     Cambridge MA 02139
  132.     (617) 876-2102
  133.     29 May 1988
  134.  
  135.     revised 10 June 1988:
  136.         fixed "NUXI" problem in UR/Forth ELAPSED-TIME word (actually,
  137. just included Ray Duncan's fix; thanks, Ray!)
  138.  
  139. 9╥ÇröW楠ñ▒Æ