home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / DOSCALLS.E < prev    next >
Text File  |  1995-01-16  |  33KB  |  786 lines

  1. ; The following contains examples of a number of DYNALINK calls to
  2. ; the OS/2 functions in DOSCALLS and DOSCALL1.  Extract and use in
  3. ; your own routines.
  4.  
  5. ; By Larry Margolis
  6.  
  7. /*        [\toolktxx\c\include\doscalls.h]
  8. Function Name                   Ordinal Value
  9. -------------                   -------------
  10. DBGETKVAR                           109
  11. DBGETOWNER                          117
  12. DBMEMFREE                           116
  13. DBMEMLOCK                           112
  14. DBMEMREALLOC                        115
  15. DBMEMUNLOCK                         113
  16. DBPHYSINFO                          118
  17. DBSEGALLOC                          114
  18. DOSALLOCHUGE                         40
  19. DOSALLOCSEG                          34
  20. DOSALLOCSHRSEG                       35
  21. DOSBEEP                              50
  22. DOSBUFRESET                          56
  23. DOSCALLBACK                         157
  24. DOSCHDIR                             57
  25. DOSCHGFILEPTR                        58
  26. DOSCLIACCESS                         51
  27. DOSCLOSE                             59
  28. DOSCLOSESEM                          23
  29. DOSCREATECSALIAS                     43
  30. DOSCREATESEM                         24
  31. DOSCWAIT                              2
  32. DOSDELETE                            60
  33. DOSDEVCONFIG                         52
  34. DOSDEVIOCTL                          53
  35. DOSDEVIOCTL2                         99
  36. DOSDUPHANDLE                         61
  37. DOSENTERCRITSEC                       3
  38. DOSENUMATTRIBUTE                    204
  39. DOSERROR                            120
  40. DOSEXIT                               5
  41. DOSEXITCRITSEC                        6
  42. DOSEXITLIST                           7
  43. DOSFILELOCKS                         62
  44. DOSFINDCLOSE                         63
  45. DOSFINDFIRST                         64
  46. DOSFINDNEXT                          65
  47. DOSFLAGPROCESS                       15
  48. DOSFREEMODULE                        46
  49. DOSFREESEG                           39
  50. DOSGETCP                            130
  51. DOSGETDATETIME                       33
  52. DOSGETENV                            91
  53. DOSGETHUGESHIFT                      41
  54. DOSGETINFOSEG                         8
  55. DOSGETMACHINEMODE                    49
  56. DOSGETMODHANDLE                      47
  57. DOSGETMODNAME                        48
  58. DOSGETPID                            94
  59. DOSGETPROCADDR                       45
  60. DOSGETPRTY                            9
  61. DOSGETSEG                           121
  62. DOSGETSHRSEG                         36
  63. DOSGETSTDA                          119
  64. DOSGETVERSION                        92
  65. DOSGIVESEG                           37
  66. DOSGLOBALSEG                        132
  67. DOSHOLDSIGNAL                        13
  68. DOSHUGEINCR                         136
  69. DOSHUGESHIFT                        135
  70. DOSICANONICALIZE                    100
  71. DOSICREATETHREAD                      1
  72. DOSIEXECPGM                           4
  73. DOSIRAMSEMWAKE                      125
  74. DOSIREAD                             79
  75. DOSISEMREQUEST                       18
  76. DOSISEMWAIT                          21
  77. DOSISETCP                           131
  78. DOSISYSSEMCLEAR                      17
  79. DOSISYSSEMSET                        19
  80. DOSIWRITE                            87
  81. DOSKILLPROCESS                       10
  82. DOSLIBINIT                           96
  83. DOSLOADMODULE                        44
  84. DOSLOCKSEG                          122
  85. DOSMAKEPIPE                          16
  86. DOSMEMAVAIL                         127
  87. DOSMKDIR                             66
  88. DOSMOVE                              67
  89. DOSMUXSEMWAIT                        22
  90. DOSNEWSIZE                           68
  91. DOSOPEN                              70
  92. DOSOPEN2                             95
  93. DOSOPENSEM                           25
  94. DOSPHYSICALDISK                     129
  95. DOSQPATHINFO                         98
  96. DOSSETPATHINFO                      104
  97. DOSPOKETESTDAEMON                   104
  98. DOSPORTACCESS                        69
  99. DOSPROFILE                          133
  100. DOSPTRACE                            12
  101. DOSQCURDIR                           71
  102. DOSQCURDISK                          72
  103. DOSQFHANDSTATE                       73
  104. DOSQFILEINFO                         74
  105. DOSQFILEMODE                         75
  106. DOSQFSINFO                           76
  107. DOSQHANDTYPE                         77
  108. DOSQPROCSTATUS                      154
  109. DOSQTRACEINFO                        93
  110. DOSQVERIFY                           78
  111. DOSREADPHYS                         103
  112. DOSREALLOCHUGE                       42
  113. DOSREALLOCSEG                        38
  114. DOSRESUMETHREAD                      26
  115. DOSRMDIR                             80
  116. DOSSELECTDISK                        81
  117. DOSSEMSETWAIT                        20
  118. DOSSENDSIGNAL                       134
  119. DOSSETCP                            153
  120. DOSSETDATETIME                       28
  121. DOSSETFGND                          101
  122. DOSSETFHANDSTATE                     82
  123. DOSSETFILEINFO                       83
  124. DOSSETFILEMODE                       84
  125. DOSSETFSINFO                         97
  126. DOSSETINFOSEG                       128
  127. DOSSETMAXFH                          85
  128. DOSSETPRTY                           11
  129. DOSSETSIGHANDLER                     14
  130. DOSSETVEC                            89
  131. DOSSETVERIFY                         86
  132. DOSSGSWITCH                          54
  133. DOSSGSWITCHME                        55
  134. DOSSGSWITCHPROC                     124
  135. DOSSICG                              95
  136. DOSSIZESEG                          126
  137. DOSSLEEP                             32
  138. DOSSUSPENDTHREAD                     27
  139. DOSSWAPTASKINIT                     102
  140. DOSSYSTEMSERVICE                     88
  141. DOSSYSTRACE                          90
  142. DOSTIMERASYNC                        29
  143. DOSTIMERSTART                        30
  144. DOSTIMERSTOP                         31
  145. DOSUNLOCKSEG                        123
  146. GETADDR                             111
  147. GETHEADERS                          108
  148. GETSELADDR                          110
  149. PANICWRITE                          105
  150. STRUCHECK                           106
  151. STRURESUPDATE                       107
  152. UNUSEDA                              98
  153. UNUSEDB                              99
  154.  
  155. The following Operating System entry points are defined in the library
  156. DOSCALL1. In this case, the procedures must be called by name rather than
  157. ordinal value.
  158.  
  159. DOSREAD
  160. DOSWRITE
  161. DOSERRCLASS
  162. DOSSEMREQUEST
  163. DOSSEMCLEAR
  164. DOSSEMWAIT
  165. DOSSEMSET
  166. DOSEXECPGM
  167. DOSCREATETHREAD
  168. DOSSUBSET
  169. DOSSUBALLOC
  170. DOSSUBFREE
  171. DOSREADASYNC
  172. DOSWRITEASYNC
  173. DOSSEARCHPATH
  174. DOSSCANENV
  175. */
  176.  
  177.  
  178. /* Routines defined in this file:  *******************************************
  179.      DosCalls #8:   DosGetInfoSeg
  180.      DosCalls #20:  DosSemSetWait
  181.      DosCalls #23:  DosCloseSem
  182.      DosCalls #24:  DosCreateSem
  183.      DosCalls #25:  DosOpenSem
  184.      DosCalls #29:  DosTimerAsynch
  185.      DosCalls #31:  DosTimerStop
  186.      DosCalls #32:  DosSleep
  187.      DosCalls #33:  DosGetDateTime
  188.      DosCalls #34:  DosAllocSeg
  189.      DosCalls #39:  DosFreeSeg
  190.      DosCalls #44:  DosLoadModule
  191.      DosCalls #46:  DosFreeModule
  192.      DosCalls #50:  DosBeep
  193.      DosCalls #58:  DosChgFilePtr
  194.      DosCalls #59:  DosClose
  195.      DosCalls #60:  DosDelete
  196.      DosCalls #63:  DosFindClose
  197.      DosCalls #64:  DosFindFirst
  198.      DosCalls #65:  DosFindNext
  199.      DosCalls #66:  DosMkDir
  200.      DosCalls #67:  DosMove
  201.      DosCalls #70:  DosOpen
  202.      DosCalls #71:  DosQCurDir
  203.      DosCalls #75:  DosQFileMode
  204.      DosCalls #91:  DosGetEnv
  205.      DosCalls #92:  DosGetVersion
  206.      DosCalls #98:  DosQPathInfo
  207.      DosCalls #121: DosGetSeg
  208.      DosCalls #126: DosSizeSeg
  209.      DosCalls #127: DosMemAvail
  210.      DosCalls #166: DosQSysInfo
  211.      DosCalls #201: DosCopy        (OS/2 1.2)
  212.      DosCall1       DosSemClear
  213.      DosCall1       DosSemSet
  214.      DosCall1       DosSemWait
  215.      DosCall1       DosScanEnv
  216.      DosCall1       DosSearchPath
  217. *****************************************************************************/
  218.  
  219.  
  220. ; DosCalls #8:   DosGetInfoSeg
  221. defc globalseg
  222.    globalseg = 12
  223.    localseg = 12
  224.  
  225.    call dynalink('DOSCALLS',             -- dynamic link library name
  226.                  '#8',                   -- ordinal value for DosGetInfoSeg
  227.                  selector(globalseg) ||  -- string selector
  228.                  offset(globalseg)   ||  -- string offset
  229.                  selector(localseg)  ||  -- string selector
  230.                  offset(localseg) )      -- string offset
  231.  
  232.    globalseg=itoa(globalseg,10)
  233.    start_t = peek(globalseg,4,4)
  234. ;  localseg=itoa(localseg,10)
  235.    globinfo = peek(globalseg, 0, 24)
  236. ;  insertline '; 'globinfo,.last+1
  237.  
  238.    time      = ltoa(substr(globinfo, 1,4), 10)
  239.    millisecs = ltoa(substr(globinfo, 5,4), 10)
  240.    hours     = asc(substr(globinfo, 9,1))
  241.    minute    = asc(substr(globinfo,10,1))
  242.    seconds   = asc(substr(globinfo,11,1))
  243.    hundredsec= asc(substr(globinfo,12,1))
  244.    timezone  = itoa(substr(globinfo,13,2), 10)
  245.    interval  = ltoa(substr(globinfo,15,2)\0\0, 10)
  246.    day       = asc(substr(globinfo,17,1))
  247.    month     = asc(substr(globinfo,18,1))
  248.    year      = itoa(substr(globinfo,19,2), 10)
  249.    weekday   = asc(substr(globinfo,21,1))
  250.    major     = asc(substr(globinfo,22,1))
  251.    minor     = asc(substr(globinfo,23,1))
  252.    revision  = asc(substr(globinfo,24,1))
  253. ;  weekday = substr('SunMonTueWedThuFriSat',weekday*3+1,3)
  254.    Weekday = strip(substr('Sunday    Monday    Tuesday   Wednesday ' ||
  255.              'Thursday  Friday    Saturday  Sunday    ',Weekday*10+1,10))
  256.    if timezone = -1 then timezone = '(No timezone set)'; endif
  257.    sayerror time millisecs'  'hours':'minute':'seconds'.'hundredsec'  'timezone interval'  'weekday year'/'month'/'day'  OS/2 'major'.'minor'.'revision
  258.  
  259.  
  260. ; DosCalls #20:  DosSemSetWait
  261. ;   call DosSemSetWait(mail_sem, timeout)         -- set sem and wait til cleared
  262.     result = dynalink('DOSCALLS',  -- rc 0 (false) if sem. is clear
  263.                       '#20',
  264.                       selector(mail_sem)||  /* Semaphore handle */
  265.                       offset(mail_sem)||
  266.                       long(timeout))        /* Timeout          */
  267.     if result then
  268.        sayerror 'Error' result 'trying to set semaphore.'
  269.     endif
  270.  
  271.  
  272. ; DosCalls #23:  DosCloseSem
  273.    if poll_sem/=='' then          -- If it was successfully created, then
  274. ;     call DosCloseSem(poll_sem)  -- Close the semaphore
  275.       result=dynalink('DOSCALLS',
  276.                       '#23',
  277.                       poll_sem)     /* Semaphore handle    */
  278.       poll_sem = ''
  279.  
  280.  
  281. ; DosCalls #24:  DosCreateSem
  282.    semname='\SEM\MYNAME.EOS'\0  -- Pick a unique name.  Note trailing x'0'
  283.    poll_sem='1234'                                    -- reserve 4 bytes
  284. ;  call DosCreateSem(Exclusive, @poll_sem, @semname)  -- Create semaphore
  285.    result=dynalink('DOSCALLS',
  286.                    '#24',
  287.                    atoi(1)||               /* non-Exclusive semaphore */
  288.                    selector(poll_sem)||    /* Semaphore handle    */
  289.                    offset(poll_sem)||
  290.                    selector(semname)||     /* Semaphore name      */
  291.                    offset(semname))
  292.    if result then
  293.       messageNwait('Error' result 'trying to create semaphore.  Polling inhibited.')
  294.       poll_sem=''                          -- set to null
  295.    else
  296.       poll_sem=substr(poll_sem,3,2) || substr(poll_sem,1,2)  -- reverse words
  297.    endif
  298. ; We reversed the words of the returned semaphore handle, so that all the other calls
  299. ; can pass it directly to the dynalink.
  300.  
  301.  
  302.  
  303. ; DosCalls #25:  DosOpenSem
  304. ;     call DosOpenSem(@poll_sem, @semname)  -- Open semaphore
  305.       result=dynalink('DOSCALLS',
  306.                       '#25',
  307.                       selector(poll_sem)||    /* Semaphore handle    */
  308.                       offset(poll_sem)||
  309.                       selector(semname)||     /* Semaphore name      */
  310.                       offset(semname))
  311.       if result then
  312.          messageNwait('Error' result 'trying to open semaphore.  Press a key...')
  313.          return
  314.       endif
  315.    endif
  316.    poll_sem=substr(poll_sem,3,2) || substr(poll_sem,1,2)  -- reverse words
  317.  
  318.  
  319. ; DosCalls #29:  DosTimerAsynch
  320. ;  call DosTimerAsynch(30000, poll_sem, @timer_handle)  -- Start timer
  321.    result=dynalink('DOSCALLS',
  322.                    '#29',
  323.                    long(30000)||             /* Delay in millisec.s */
  324.                    poll_sem ||               /* Semaphore handle    */
  325.                    selector(timer_handle)||  /* Semaphore name      */
  326.                    offset(timer_handle))
  327.    if result then
  328.       sayerror 'Error' result 'trying to start timer.'
  329.    endif
  330.  
  331.  
  332. ; DosCalls #31:  DosTimerStop
  333. ;        call DosTimerStop(timer_handle)         -- stop the timer
  334.          result=dynalink('DOSCALLS',
  335.                          '#31',
  336.                          timer_handle)
  337.          if result then
  338.             sayerror 'Error' result 'trying to stop timer.'
  339.          endif
  340.  
  341.  
  342. ; DosCalls #32:  DosSleep
  343.    delay=atol(1000)                  -- 1 second DOSSLEEP
  344.    call dynalink('DOSCALLS', '#32', substr(delay,3,2) || substr(delay,1,2))
  345.  
  346.  
  347.  
  348. ; DosCalls #33:  DosGetDateTime
  349.    datetime='12345678901234567890'
  350.    call dynalink('DOSCALLS',      /* dynamic link library name       */
  351.                  '#33',           /* ordinal value for DOSGETDATETIME*/
  352.                  selector(datetime)|| /* string selector             */
  353.                  offset(datetime))  /* string offset                 */
  354.    return dec_to_string(datetime)
  355.    --> Hour24 Minutes Seconds Hund Day MonthNum Year0 Year1 TZ0 TZ1 WeekdayNum
  356.  
  357.  
  358. ; DosCalls #34:  DosAllocSeg
  359.       filesbuffer = "??"                  -- initialize string pointer
  360.       r =  dynalink('DOSCALLS',           -- dynamic link library name
  361.                '#34',                     -- DosAllocSeg
  362.                atoi(min(len+1,65535)) ||  -- Number of Bytes requested
  363.                selector(filesbuffer)  ||  -- string selector
  364.                offset(filesbuffer)    ||  -- string offset
  365.                atoi(0))                   -- Share information
  366.  
  367.       if r then sayerror 'Error 'r' allocating memory segment; command halted.'; stop; endif
  368.  
  369.  
  370. ; DosCalls #39:  DosFreeSeg
  371.    if free_the_buffer then
  372.       call dynalink('DOSCALLS',         -- dynamic link library name
  373.                '#39',                   -- DosFreeSeg
  374.                filesbuffer)
  375.  
  376.  
  377. ; DosCalls #44:  DosLoadModule
  378.       ObjNameBuf = copies(\0,255)
  379.       ModuleName = "LEXAM"\0               -- ASCIIZ string
  380.       ModuleHandle = "??"                  -- initialize string pointer
  381.       r =  dynalink('DOSCALLS',            -- dynamic link library name
  382.                '#44',                      -- DosLoadModule
  383.                selector(ObjNameBuf)   ||   -- string selector
  384.                offset(ObjNameBuf)     ||   -- string offset
  385.                atoi(255)              ||   -- buffer length
  386.                selector(ModuleName)   ||   -- string selector
  387.                offset(ModuleName)     ||   -- string offset
  388.                selector(ModuleHandle) ||   -- string selector
  389.                offset(ModuleHandle) )      -- string offset
  390.  
  391.       if r then
  392.          parse value ObjNameBuf with ObjName \0
  393.          sayerror 'Error' r 'from DosLoadModule; ObjName="'ObjName'"'
  394.       endif
  395.  
  396.  
  397. ; DosCalls #46:  DosFreeModule
  398.       call dynalink('DOSCALLS',         -- dynamic link library name
  399.                '#46',                   -- DosFreeModule
  400.                ModuleHandle)
  401.  
  402.  
  403. ; DosCalls #50:  DosBeep
  404.       call dynalink('DOSCALLS',      /* dynamic link library name       */
  405.                     '#50',           /* ordinal value for DOSBEEP       */
  406.                     atoi(pitch)||    /* Hertz (25H-7FFFH) */
  407.                     atoi(duration))  /* Length of sound  in ms */
  408.  
  409.  
  410. ; DosCalls #58:  DosChgFilePtr
  411.    newpointer = 1234  -- Reserve 4 bytes for a long
  412.    result = dynalink('DOSCALLS',
  413.                      '#58',                -- DosChgFilePtr
  414.                      filehandle           ||  -- Binary file handle
  415.                      atol_swap(0)         ||  -- Distance (offset to move)
  416.                      atoi(2)              ||  -- MoveType:  relative to:  0=beginning of file; 1=current pointer; 2=end of file
  417.                      selector(newpointer) ||  -- Address of the new pointer location (output)
  418.                      offset(newpointer) )
  419.  
  420. ; DosCalls #59:  DosClose
  421.    result = dynalink('DOSCALLS',
  422.                      '#59',                    /* dosclose */
  423.                      atoi(fileid.lockhandle))
  424.  
  425.  
  426.  
  427. ; DosCalls #60:  DosDelete
  428.       return dynalink('DOSCALLS',          /* dynamic link library name */
  429.                       '#60',               /* ordinal value for DOSDELETE */
  430.                       selector(asciiz) ||  /* string selector           */
  431.                       offset(asciiz)   ||  /* string offset             */
  432.                       atoi(0)||            /* reserved                  */
  433.                       atoi(0))             /* reserved                  */
  434.  
  435.  
  436. ; DosCalls #63:  DosFindClose
  437.    result=dynalink('DOSCALLS',             -- dynamic link library name
  438.                    '#63',                  -- ordinal value for DOSFINDCLOSE
  439.                    dirhandle)              -- Directory handle, returned by DosFindFirst(2)
  440.  
  441.  
  442. ; DosCalls #64:  DosFindFirst
  443. defc findfirst
  444.    parse arg filename .
  445.    filename = filename\0 -- ASCIIZ
  446.    DirHandle = atoi(1)   -- To use the common handle
  447. ;; dirhandle = \xff\xff  -- Ask system to assign us a handle
  448.    attribute = atoi(0)  -- 0=normal; no subdirectories, hidden or system
  449.    resultbuf = copies(\0,255)  -- Can be bigger in EPM 5.60 or above; use a buffer in earlier versions if more space is needed.
  450.    searchcnt = atoi(1)   -- Search count; we're only asking for 1 file at a time here.
  451.  
  452.    rc = dynalink('DOSCALLS',               -- dynamic link library name
  453.                  '#64',                    -- ordinal value for DosFindFirst
  454.                  selector(filename)    ||  -- string selector
  455.                  offset(filename)      ||  -- string offset
  456.                  selector(DirHandle)   ||  -- string selector
  457.                  offset(DirHandle)     ||  -- string offset
  458.                  attribute             ||
  459.                  selector(resultbuf)   ||  -- string selector
  460.                  offset(resultbuf)     ||  -- string offset
  461.                  atoi(length(resultbuf)) ||
  462.                  selector(searchcount) ||  -- Pointer to the count; system updates
  463.                  offset(searchcount)   ||
  464.                  atol(0))                  -- reserved
  465.  
  466.        if rc = 0   then msg = 'NO_ERROR'
  467.    elseif rc = 2   then msg = 'ERROR_FILE_NOT_FOUND'
  468.    elseif rc = 3   then msg = 'ERROR_PATH_NOT_FOUND'
  469.    elseif rc = 6   then msg = 'ERROR_INVALID_HANDLE'
  470.    elseif rc = 18  then msg = 'ERROR_NO_MORE_FILES'
  471.    elseif rc = 26  then msg = 'ERROR_NOT_DOS_DISK'
  472.    elseif rc = 87  then msg = 'ERROR_INVALID_PARAMETER'
  473.    elseif rc = 108 then msg = 'ERROR_DRIVE_LOCKED'
  474.    elseif rc = 111 then msg = 'ERROR_BUFFER_OVERFLOW'
  475.    elseif rc = 113 then msg = 'ERROR_NO_MORE_SEARCH_HANDLES'
  476.    elseif rc = 206 then msg = 'ERROR_FILENAME_EXCED_RANGE'
  477.    endif
  478.    if rc then
  479.       sayerror 'Error' rc 'from DosFindFirst -' msg
  480.       return
  481.    endif
  482.    s = ''
  483.    do i=0 to 2
  484.       datetime = substr(resultbuf,4*i+1,4)
  485.       date = ltoa(substr(datetime,1,2)\0\0,10); time = ltoa(substr(datetime,3,2)\0\0,10)
  486.       year = date % 512; date = date // 512
  487.       month = date % 32; day = date // 32 % 1     -- %1 to drop fraction.
  488.       date = year+80'/'month'/'day
  489.       hour = time % 2048; time = time // 2048
  490.       min = time % 32; sec = time // 32 * 2 % 1
  491.       time = hour':'min':'sec
  492.       s = s date time
  493.    enddo
  494.    file_size = ltoa(substr(resultbuf,13,4),10)
  495.    filealloc = ltoa(substr(resultbuf,17,4),10)
  496.    fileattrib = itoa(substr(resultbuf,21,2),16)
  497.    namelen = asc(substr(resultbuf,23,1))
  498.    name = substr(resultbuf,24,namelen)
  499.    sayerror 'Create, access, write timestamps =' s
  500.    sayerror 'filesize='file_size', allocated size='filealloc', attributes='fileattrib', namelen='namelen', count='itoa(searchcount,10)
  501.    sayerror 'filename = "'name'"'
  502.  
  503.  
  504. ; DosCalls #65:  DosFindNext
  505.    resultbuf = copies(\0, 300)  -- Might need to allocate a buffer if < EPM 5.60
  506.    searchcnt = atoi(1)   -- Search count; we're only asking for 1 file at a time here.
  507.    result=dynalink('DOSCALLS',             -- dynamic link library name
  508.                    '#65',                  -- ordinal value for DOSFINDNEXT
  509.                    dirhandle           ||  -- Directory handle, returned by DosFindFirst(2)
  510.                    selector(resultbuf) ||  -- string selector
  511.                    offset(resultbuf)   ||  -- string offset
  512.                    atoi(length(resultbuf)) ||
  513.                    selector(searchcnt) ||  -- Pointer to the count; system updates
  514.                    offset(searchcnt) )
  515.  
  516.        if result = 0   then msg = 'NO_ERROR'
  517.    elseif result = 6   then msg = 'ERROR_INVALID_HANDLE'
  518.    elseif result = 18  then msg = 'ERROR_NO_MORE_FILES'
  519.    elseif result = 26  then msg = 'ERROR_NOT_DOS_DISK'
  520.    elseif result = 87  then msg = 'ERROR_INVALID_PARAMETER'
  521.    elseif result = 111 then msg = 'ERROR_BUFFER_OVERFLOW'
  522.    elseif result = 275 then msg = 'ERROR_EAS_DIDNT_FIT'
  523.    endif
  524.  
  525.  
  526. ; DosCalls #66:  DosMkDir
  527.       result=dynalink('DOSCALLS',            -- dynamic link library name
  528.                       '#66',                 -- ordinal value for DOSMKDIR
  529.                       selector(filename) ||  -- string selector
  530.                       offset(filename)   ||  -- string offset
  531.                       atol(0))               -- reserved
  532.  
  533.  
  534. ; DosCalls #67:  DosMove
  535.          rc=dynalink('DOSCALLS',          /* dynamic link library name */
  536.                      '#67',               /* DosMove - move a file     */
  537.                      selector(oldfilez)||
  538.                      offset(oldfilez)  ||
  539.                      selector(newfilez)||
  540.                      offset(newfilez)  ||
  541.                      atol(0))             /* Reserved; must be 0       */
  542.  
  543.  
  544. ; DosCalls #70:  DosOpen
  545.    newhandle='??'
  546.    actiontaken=atoi(1)
  547.    file=file\0
  548.    result = dynalink('DOSCALLS',
  549.                      '#70',                     /* dosopen          */
  550.                      selector(file)||
  551.                      offset(file)||
  552.                      selector( newhandle )||
  553.                      offset( newhandle )||
  554.                      selector( actiontaken )||
  555.                      offset( actiontaken )||
  556.                      atol(0)||  -- File size
  557.                      atoi(0)||  -- File attribute
  558.                      atoi(17)||  -- Open flag (create if new; open if exists)
  559.                      atoi(146)||  -- Open mode (private; deny read/write; get read/write access)
  560.                      atol(0))  -- Reserved
  561.  
  562.  
  563. ; DosCalls #71:  DosQCurDir
  564.    string =  atoi(80) || substr('',1,80)  /* create input strings for  */
  565.    stringlen = substr('',1,4)             /* DOSQCURDIR                */
  566.    result=dynalink('DOSCALLS',
  567.                    '#71',
  568.                    atoi(0)||               /* Drive number - 1=A, etc */
  569.                    selector(string)||      /* Directory path buffer */
  570.                    offset(string)||
  571.                    selector(stringlen)||   /* Directory path buffer length */
  572.                    offset(stringlen))
  573.    sayerror  'len = ' hex_to_string(stringlen) 'current dir = ' string
  574.  
  575.  
  576.  
  577. ; DosCalls #75:  DosQFileMode
  578.       attrib='  '
  579.       cflag=dynalink('DOSCALLS',            -- dynamic link library name
  580.                      '#75',                 -- ordinal value for DOSQFILEMODE
  581.                      selector(filename) ||  -- string selector
  582.                      offset(filename)   ||  -- string offset
  583.                      selector(attrib)   ||  -- string selector
  584.                      offset(attrib)     ||  -- string offset
  585.                      atol(0))               -- reserved
  586.  
  587.  
  588. ; DosCalls #76:  DosQFsInfo
  589.       infobuf=substr('',1,255)
  590.       rc = dynalink('DOSCALLS',            -- dynamic link library name
  591.                     '#76',                 -- ordinal value for DOSQFSINFO
  592.                     atoi(drive_no)     ||  -- drive #; 0=default; 1=A, ...
  593.                     atoi(infolevel)    ||  -- info level requested
  594.                     selector(infobuf)  ||  -- string selector
  595.                     offset(infobuf)    ||  -- string offset
  596.                     atoi(length(infobuf))) -- length of buffer
  597.  
  598.  
  599. ; DosCalls #91:  DosGetEnv
  600.       seg_ptr = 1234                /* 4-byte place to put a far pointer */
  601.       cmd_ptr = 1234
  602.       call dynalink('DOSCALLS',           /* dynamic link library name   */
  603.                     '#91',                /* ordinal value for DOSGETENV */
  604.                     selector(seg_ptr) ||  /* pointer to env. segment     */
  605.                     offset(seg_ptr)   ||
  606.                     selector(cmd_ptr) ||  /* pointer to offset after     */
  607.                     offset(cmd_ptr)     ) /*    COMSPEC; we don't need   */
  608.       env_seg=itoa(seg_ptr,10)
  609.  
  610.  
  611. ; DosCalls #92:  DosGetVersion
  612.       verbuf = 'nn'
  613.       res= dynalink('DOSCALLS',          /* dynamic link library name */
  614.                     '#92',               /* ordinal for DOSGETVERSION */
  615.                     selector(verbuf) ||  /* string selector           */
  616.                     offset(verbuf))      /* string offset             */
  617. ;     major = asc(substr(verbuf,2,1))
  618. ;     minor = asc(substr(verbuf,1,1))
  619.  
  620.  
  621. ; DosCalls #98:  DosQPathInfo
  622.    pathname = 'H:\'\0
  623.    if arg(1) then pathname=arg(1)\0; endif
  624.    pathinfobuf = copies(\0,255)
  625.    pathinfobufsize = 255
  626.    PathInfoLevel = 5
  627.    ca = dynalink('DOSCALLS',      /* dynamic link library name       */
  628.                  '#98',           /* ordinal value for DOSQPATHINFO  */
  629.                  selector(pathname)        ||  -- pathname to be queried
  630.                  offset(pathname)          ||
  631.                  atoi(PathInfoLevel)       ||  -- PathInfoLevel
  632.                  selector(pathinfobuf)     ||  -- buffer where info is to be returned
  633.                  offset(pathinfobuf)       ||
  634.                  atoi(pathinfobufsize)     ||  -- size of buffer
  635.                  atol(0) )                     -- (reserved)
  636.  
  637.    sayerror 'result =' ca'; size='pathinfobufsize'; buf="'pathinfobuf'"'
  638. ;  For level 1:  (binary fields; convert as needed)
  639.    create_date = substr(pathinfobuf,  1, 2)  -- bits 15-9 = year; 8-5 = month; 4-0 = day
  640.    create_time = substr(pathinfobuf,  3, 2)  -- bits 15-11 = hour; 10-5 = minute; 4-0 = seconds
  641.    access_date = substr(pathinfobuf,  5, 2)  -- like create_
  642.    access_time = substr(pathinfobuf,  7, 2)
  643.    update_date = substr(pathinfobuf,  9, 2)  -- like create_
  644.    update_time = substr(pathinfobuf, 11, 2)
  645.    filesize    = substr(pathinfobuf, 13, 4)
  646.    allocsize   = substr(pathinfobuf, 17, 4)
  647.    fileattrib  = substr(pathinfobuf, 21, 2)
  648.  
  649. ; DosCalls #121:  DosGetSeg
  650.       res= dynalink('DOSCALLS',          /* dynamic link library name */
  651.                     '#121',              /* ordinal for DOSGETSEG     */
  652.                     atoi(bufhndl))
  653.  
  654. ; DosCalls #126: DosSizeSeg
  655.    size_out = '0000'                     -- result buffer
  656.    result=dynalink('DOSCALLS',           -- dynamic link library name
  657.                    '#126',               -- ordinal value for DosSizeSeg
  658.                    rightstr(ea_long,2),  -- segment
  659.                    selector(size_out) || -- string selector
  660.                    offset(size_out))     -- string offset
  661.    sayerror 'rc = ' rc'; size = ' ltoa(size_out,10)
  662.  
  663.  
  664. ; DosCalls #127: DosMemAvail
  665.    string =  '?????'                /* result buffer                   */
  666.    result=dynalink('DOSCALLS',      /* dynamic link library name       */
  667.                    '#127',          /* ordinal value for DOSMEMAVAIL   */
  668.                    selector(string)|| /* string selector               */
  669.                    offset(string))    /* string offset                 */
  670.    sayerror 'memavail = ' string 'itoa(hex) = ' itoa(string,16)
  671.  
  672.  
  673.  
  674. ; DosCalls #166: DosQSysInfo
  675.  
  676.    index = 0
  677.    databuf =  '??'                                -- result buffer
  678.    rc = '[not set]'
  679.    result=dynalink('DOSCALLS',                    -- dynamic link library name
  680.                    '#166',                        -- ordinal value for DOSQSYSINFO
  681.                    atoi(index)  ||
  682.                    selector(databuf) ||            -- string selector
  683.                    offset(databuf)   ||            -- string offset
  684.                    atoi(2) )                       -- buffer length
  685.    sayerror 'max path length =' itoa(databuf,10) 'result='result 'rc='rc
  686.  
  687. ; OS/2 2.0 version (but don't know how to access it)
  688.    startindex = 5
  689.    endindex = 13
  690.    databuf_len = (endindex - startindex + 1) * 4  -- Reserve this many double-words
  691.    databuf =  copies(\0, databuf_len)             -- result buffer
  692.    result=dynalink('DOSCALLS',                    -- dynamic link library name
  693. ??                 '#166',                        -- ordinal value for DOSQSYSINFO
  694.                    atol(startindex)  ||
  695.                    atol(endindex)    ||
  696.                    selector(databuf) ||            -- string selector
  697.                    offset(databuf)   ||            -- string offset
  698.                    atol(databuf_len) )             -- buffer length
  699.    sayerror 'Boot drive =' substr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', ltoa(leftstr(databuf,4),10),1)
  700.  
  701.  
  702.  
  703. ; DosCalls #201: DosCopy        (OS/2 1.2)
  704.       elseif dos_version() >= 1020 then  -- DOSCOPY is new in 1.2
  705.          rc=dynalink('DOSCALLS',          /* dynamic link library name */
  706.                      '#201',              /* DosCopy - Copy a file     */
  707.                      selector(oldfilez)||
  708.                      offset(oldfilez)  ||
  709.                      selector(newfilez)||
  710.                      offset(newfilez)  ||
  711.                      atoi(0)           || /* Mode                      */
  712.                      atol(0))             /* Reserved; must be 0       */
  713.  
  714.  
  715.  
  716. ; DosCall1       DosSemClear
  717.    res=dynalink('DOSCALL1',
  718.                 'DOSSEMCLEAR',
  719.                 poll_sem)                 /* Semaphore handle    */
  720.  
  721.  
  722. ; DosCall1       DosSemSet
  723. ;     call DosSemSet(poll_sem)  -- Set semaphore; cleared by timer pop.
  724.       result=dynalink('DOSCALL1',
  725.                       'DOSSEMSET',
  726.                       poll_sem)                 /* Semaphore handle    */
  727.       if result then
  728.          sayerror 'Error' result 'trying to set semaphore.'
  729.       endif
  730.  
  731.  
  732. ; DosCall1       DosSemWait
  733.    rc = dynalink('DOSCALL1',  -- rc 0 (false) if sem. is clear
  734.                  'DOSSEMWAIT',
  735.                  poll_sem||                /* Semaphore handle */
  736.                  long(1))                  /* Timeout          */
  737.  
  738. ; DosCall1       DosScanEnv
  739.    varname = upcase(varname)\0   -- (see Get_env in DOSUTIL.E for a complete example)
  740.    result_ptr = 1234                -- 4-byte place to put a far pointer
  741.    rc = dynalink('DOSCALL1',        -- rc 0 (false) if found
  742.                  'DOSSCANENV',
  743.                  selector(varname)    ||
  744.                  offset(varname)      ||
  745.                  selector(result_ptr) || -- string selector
  746.                  offset(result_ptr))     -- string offset
  747.  
  748. ; DosCall1       DosSearchPath
  749. defc try =
  750.    pathz = 'DPATH'\0
  751.    filenamez = arg(1)\0
  752.    result_str = substr('',1,255)
  753.    rc = dynalink('DOSCALL1',        -- rc 0 (false) if found
  754.                  'DOSSEARCHPATH',
  755.                  atoi(4)              ||
  756.                  selector(pathz)      ||
  757.                  offset(pathz)        ||
  758.                  selector(filenamez)  || -- string selector
  759.                  offset(filenamez)    || -- string offset
  760.                  selector(result_str) || -- string selector
  761.                  offset(result_str)   || -- string offset
  762.                  atoi(255) )             -- buffer length
  763.    if rc then
  764.       sayerror 'RC='rc
  765.    else
  766.       parse value result_str with result_str \0
  767.       sayerror '"'result_str'"'
  768.    endif
  769.  
  770. ; DosCall1       DosSearchPath
  771.    -- Assume filehandle is set from previous DosOpen
  772.    strng = 'Test output'\13\10'End of test.'\13\10  -- End lines with CR/LF
  773.    bytes_written = 00  -- Reserve two bytes
  774.    rc = dynalink('DOSCALL1',
  775.                  'DOSWRITE',
  776.                  filehandle               ||  -- Binary file handle
  777.                  selector(strng)          ||  -- Buffer to write to file
  778.                  offset(strng)            ||
  779.                  atoi(length(strng))      ||  -- Number of bytes to write.
  780.                  selector(bytes_written)  ||  -- string selector
  781.                  offset(bytes_written) )      -- string offset
  782.    if rc then
  783.       sayerror 'DosWrite error; RC='rc
  784.    elseif length(strng)<>itoa(bytes_written,10) then
  785.       sayerror 'Only'itoa(bytes_written,10) 'bytes were written out!'
  786.    endif