home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / editor / epmtools / epmsmp / doscalls.e < prev    next >
Text File  |  1993-02-23  |  33KB  |  780 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 #126: DosSizeSeg
  208.      DosCalls #127: DosMemAvail
  209.      DosCalls #166: DosQSysInfo
  210.      DosCalls #201: DosCopy        (OS/2 1.2)
  211.      DosCall1       DosSemClear
  212.      DosCall1       DosSemSet
  213.      DosCall1       DosSemWait
  214.      DosCall1       DosScanEnv
  215.      DosCall1       DosSearchPath
  216. *****************************************************************************/
  217.  
  218.  
  219. ; DosCalls #8:   DosGetInfoSeg
  220. defc globalseg
  221.    globalseg = 12
  222.    localseg = 12
  223.  
  224.    call dynalink('DOSCALLS',             -- dynamic link library name
  225.                  '#8',                   -- ordinal value for DosGetInfoSeg
  226.                  selector(globalseg) ||  -- string selector
  227.                  offset(globalseg)   ||  -- string offset
  228.                  selector(localseg)  ||  -- string selector
  229.                  offset(localseg) )      -- string offset
  230.  
  231.    globalseg=itoa(globalseg,10)
  232.    start_t = peek(globalseg,4,4)
  233. ;  localseg=itoa(localseg,10)
  234.    globinfo = peek(globalseg, 0, 24)
  235. ;  insertline '; 'globinfo,.last+1
  236.  
  237.    time      = ltoa(substr(globinfo, 1,4), 10)
  238.    millisecs = ltoa(substr(globinfo, 5,4), 10)
  239.    hours     = asc(substr(globinfo, 9,1))
  240.    minute    = asc(substr(globinfo,10,1))
  241.    seconds   = asc(substr(globinfo,11,1))
  242.    hundredsec= asc(substr(globinfo,12,1))
  243.    timezone  = itoa(substr(globinfo,13,2), 10)
  244.    interval  = ltoa(substr(globinfo,15,2)\0\0, 10)
  245.    day       = asc(substr(globinfo,17,1))
  246.    month     = asc(substr(globinfo,18,1))
  247.    year      = itoa(substr(globinfo,19,2), 10)
  248.    weekday   = asc(substr(globinfo,21,1))
  249.    major     = asc(substr(globinfo,22,1))
  250.    minor     = asc(substr(globinfo,23,1))
  251.    revision  = asc(substr(globinfo,24,1))
  252. ;  weekday = substr('SunMonTueWedThuFriSat',weekday*3+1,3)
  253.    Weekday = strip(substr('Sunday    Monday    Tuesday   Wednesday ' ||
  254.              'Thursday  Friday    Saturday  Sunday    ',Weekday*10+1,10))
  255.    if timezone = -1 then timezone = '(No timezone set)'; endif
  256.    sayerror time millisecs'  'hours':'minute':'seconds'.'hundredsec'  'timezone interval'  'weekday year'/'month'/'day'  OS/2 'major'.'minor'.'revision
  257.  
  258.  
  259. ; DosCalls #20:  DosSemSetWait
  260. ;   call DosSemSetWait(mail_sem, timeout)         -- set sem and wait til cleared
  261.     result = dynalink('DOSCALLS',  -- rc 0 (false) if sem. is clear
  262.                       '#20',
  263.                       selector(mail_sem)||  /* Semaphore handle */
  264.                       offset(mail_sem)||
  265.                       long(timeout))        /* Timeout          */
  266.     if result then
  267.        sayerror 'Error' result 'trying to set semaphore.'
  268.     endif
  269.  
  270.  
  271. ; DosCalls #23:  DosCloseSem
  272.    if poll_sem/=='' then          -- If it was successfully created, then
  273. ;     call DosCloseSem(poll_sem)  -- Close the semaphore
  274.       result=dynalink('DOSCALLS',
  275.                       '#23',
  276.                       poll_sem)     /* Semaphore handle    */
  277.       poll_sem = ''
  278.  
  279.  
  280. ; DosCalls #24:  DosCreateSem
  281.    semname='\SEM\MYNAME.EOS'\0  -- Pick a unique name.  Note trailing x'0'
  282.    poll_sem='1234'                                    -- reserve 4 bytes
  283. ;  call DosCreateSem(Exclusive, @poll_sem, @semname)  -- Create semaphore
  284.    result=dynalink('DOSCALLS',
  285.                    '#24',
  286.                    atoi(1)||               /* non-Exclusive semaphore */
  287.                    selector(poll_sem)||    /* Semaphore handle    */
  288.                    offset(poll_sem)||
  289.                    selector(semname)||     /* Semaphore name      */
  290.                    offset(semname))
  291.    if result then
  292.       messageNwait('Error' result 'trying to create semaphore.  Polling inhibited.')
  293.       poll_sem=''                          -- set to null
  294.    else
  295.       poll_sem=substr(poll_sem,3,2) || substr(poll_sem,1,2)  -- reverse words
  296.    endif
  297. ; We reversed the words of the returned semaphore handle, so that all the other calls
  298. ; can pass it directly to the dynalink.
  299.  
  300.  
  301.  
  302. ; DosCalls #25:  DosOpenSem
  303. ;     call DosOpenSem(@poll_sem, @semname)  -- Open semaphore
  304.       result=dynalink('DOSCALLS',
  305.                       '#25',
  306.                       selector(poll_sem)||    /* Semaphore handle    */
  307.                       offset(poll_sem)||
  308.                       selector(semname)||     /* Semaphore name      */
  309.                       offset(semname))
  310.       if result then
  311.          messageNwait('Error' result 'trying to open semaphore.  Press a key...')
  312.          return
  313.       endif
  314.    endif
  315.    poll_sem=substr(poll_sem,3,2) || substr(poll_sem,1,2)  -- reverse words
  316.  
  317.  
  318. ; DosCalls #29:  DosTimerAsynch
  319. ;  call DosTimerAsynch(30000, poll_sem, @timer_handle)  -- Start timer
  320.    result=dynalink('DOSCALLS',
  321.                    '#29',
  322.                    long(30000)||             /* Delay in millisec.s */
  323.                    poll_sem ||               /* Semaphore handle    */
  324.                    selector(timer_handle)||  /* Semaphore name      */
  325.                    offset(timer_handle))
  326.    if result then
  327.       sayerror 'Error' result 'trying to start timer.'
  328.    endif
  329.  
  330.  
  331. ; DosCalls #31:  DosTimerStop
  332. ;        call DosTimerStop(timer_handle)         -- stop the timer
  333.          result=dynalink('DOSCALLS',
  334.                          '#31',
  335.                          timer_handle)
  336.          if result then
  337.             sayerror 'Error' result 'trying to stop timer.'
  338.          endif
  339.  
  340.  
  341. ; DosCalls #32:  DosSleep
  342.    delay=atol(1000)                  -- 1 second DOSSLEEP
  343.    call dynalink('DOSCALLS', '#32', substr(delay,3,2) || substr(delay,1,2))
  344.  
  345.  
  346.  
  347. ; DosCalls #33:  DosGetDateTime
  348.    datetime='12345678901234567890'
  349.    call dynalink('DOSCALLS',      /* dynamic link library name       */
  350.                  '#33',           /* ordinal value for DOSGETDATETIME*/
  351.                  selector(datetime)|| /* string selector             */
  352.                  offset(datetime))  /* string offset                 */
  353.    return dec_to_string(datetime)
  354.    --> Hour24 Minutes Seconds Hund Day MonthNum Year0 Year1 TZ0 TZ1 WeekdayNum
  355.  
  356.  
  357. ; DosCalls #34:  DosAllocSeg
  358.       filesbuffer = "??"                  -- initialize string pointer
  359.       r =  dynalink('DOSCALLS',           -- dynamic link library name
  360.                '#34',                     -- DosAllocSeg
  361.                atoi(min(len+1,65535)) ||  -- Number of Bytes requested
  362.                selector(filesbuffer)  ||  -- string selector
  363.                offset(filesbuffer)    ||  -- string offset
  364.                atoi(0))                   -- Share information
  365.  
  366.       if r then sayerror 'Error 'r' allocating memory segment; command halted.'; stop; endif
  367.  
  368.  
  369. ; DosCalls #39:  DosFreeSeg
  370.    if free_the_buffer then
  371.       call dynalink('DOSCALLS',         -- dynamic link library name
  372.                '#39',                   -- DosFreeSeg
  373.                filesbuffer)
  374.  
  375.  
  376. ; DosCalls #44:  DosLoadModule
  377.       ObjNameBuf = copies(\0,255)
  378.       ModuleName = "LEXAM"\0               -- ASCIIZ string
  379.       ModuleHandle = "??"                  -- initialize string pointer
  380.       r =  dynalink('DOSCALLS',            -- dynamic link library name
  381.                '#44',                      -- DosLoadModule
  382.                selector(ObjNameBuf)   ||   -- string selector
  383.                offset(ObjNameBuf)     ||   -- string offset
  384.                atoi(255)              ||   -- buffer length
  385.                selector(ModuleName)   ||   -- string selector
  386.                offset(ModuleName)     ||   -- string offset
  387.                selector(ModuleHandle) ||   -- string selector
  388.                offset(ModuleHandle) )      -- string offset
  389.  
  390.       if r then
  391.          parse value ObjNameBuf with ObjName \0
  392.          sayerror 'Error' r 'from DosLoadModule; ObjName="'ObjName'"'
  393.       endif
  394.  
  395.  
  396. ; DosCalls #46:  DosFreeModule
  397.       call dynalink('DOSCALLS',         -- dynamic link library name
  398.                '#46',                   -- DosFreeModule
  399.                ModuleHandle)
  400.  
  401.  
  402. ; DosCalls #50:  DosBeep
  403.       call dynalink('DOSCALLS',      /* dynamic link library name       */
  404.                     '#50',           /* ordinal value for DOSBEEP       */
  405.                     atoi(pitch)||    /* Hertz (25H-7FFFH) */
  406.                     atoi(duration))  /* Length of sound  in ms */
  407.  
  408.  
  409. ; DosCalls #58:  DosChgFilePtr
  410.    newpointer = 1234  -- Reserve 4 bytes for a long
  411.    result = dynalink('DOSCALLS',
  412.                      '#58',                -- DosChgFilePtr
  413.                      filehandle           ||  -- Binary file handle
  414.                      atol_swap(0)         ||  -- Distance (offset to move)
  415.                      atoi(2)              ||  -- MoveType:  relative to:  0=beginning of file; 1=current pointer; 2=end of file
  416.                      selector(newpointer) ||  -- Address of the new pointer location (output)
  417.                      offset(newpointer) )
  418.  
  419. ; DosCalls #59:  DosClose
  420.    result = dynalink('DOSCALLS',
  421.                      '#59',                    /* dosclose */
  422.                      atoi(fileid.lockhandle))
  423.  
  424.  
  425.  
  426. ; DosCalls #60:  DosDelete
  427.       return dynalink('DOSCALLS',          /* dynamic link library name */
  428.                       '#60',               /* ordinal value for DOSDELETE */
  429.                       selector(asciiz) ||  /* string selector           */
  430.                       offset(asciiz)   ||  /* string offset             */
  431.                       atoi(0)||            /* reserved                  */
  432.                       atoi(0))             /* reserved                  */
  433.  
  434.  
  435. ; DosCalls #63:  DosFindClose
  436.    result=dynalink('DOSCALLS',             -- dynamic link library name
  437.                    '#63',                  -- ordinal value for DOSFINDCLOSE
  438.                    dirhandle)              -- Directory handle, returned by DosFindFirst(2)
  439.  
  440.  
  441. ; DosCalls #64:  DosFindFirst
  442. defc findfirst
  443.    parse arg filename .
  444.    filename = filename\0 -- ASCIIZ
  445.    DirHandle = atoi(1)   -- To use the common handle
  446. ;; dirhandle = \xff\xff  -- Ask system to assign us a handle
  447.    attribute = atoi(0)  -- 0=normal; no subdirectories, hidden or system
  448.    resultbuf = copies(\0,255)  -- Can be bigger in EPM 5.60 or above; use a buffer in earlier versions if more space is needed.
  449.    searchcnt = atoi(1)   -- Search count; we're only asking for 1 file at a time here.
  450.  
  451.    rc = dynalink('DOSCALLS',               -- dynamic link library name
  452.                  '#64',                    -- ordinal value for DosFindFirst
  453.                  selector(filename)    ||  -- string selector
  454.                  offset(filename)      ||  -- string offset
  455.                  selector(DirHandle)   ||  -- string selector
  456.                  offset(DirHandle)     ||  -- string offset
  457.                  attribute             ||
  458.                  selector(resultbuf)   ||  -- string selector
  459.                  offset(resultbuf)     ||  -- string offset
  460.                  atoi(length(resultbuf)) ||
  461.                  selector(searchcount) ||  -- Pointer to the count; system updates
  462.                  offset(searchcount)   ||
  463.                  atol(0))                  -- reserved
  464.  
  465.        if rc = 0   then msg = 'NO_ERROR'
  466.    elseif rc = 2   then msg = 'ERROR_FILE_NOT_FOUND'
  467.    elseif rc = 3   then msg = 'ERROR_PATH_NOT_FOUND'
  468.    elseif rc = 6   then msg = 'ERROR_INVALID_HANDLE'
  469.    elseif rc = 18  then msg = 'ERROR_NO_MORE_FILES'
  470.    elseif rc = 26  then msg = 'ERROR_NOT_DOS_DISK'
  471.    elseif rc = 87  then msg = 'ERROR_INVALID_PARAMETER'
  472.    elseif rc = 108 then msg = 'ERROR_DRIVE_LOCKED'
  473.    elseif rc = 111 then msg = 'ERROR_BUFFER_OVERFLOW'
  474.    elseif rc = 113 then msg = 'ERROR_NO_MORE_SEARCH_HANDLES'
  475.    elseif rc = 206 then msg = 'ERROR_FILENAME_EXCED_RANGE'
  476.    endif
  477.    if rc then
  478.       sayerror 'Error' rc 'from DosFindFirst -' msg
  479.       return
  480.    endif
  481.    s = ''
  482.    do i=0 to 2
  483.       datetime = substr(resultbuf,4*i+1,4)
  484.       date = ltoa(substr(datetime,1,2)\0\0,10); time = ltoa(substr(datetime,3,2)\0\0,10)
  485.       year = date % 512; date = date // 512
  486.       month = date % 32; day = date // 32 % 1     -- %1 to drop fraction.
  487.       date = year+80'/'month'/'day
  488.       hour = time % 2048; time = time // 2048
  489.       min = time % 32; sec = time // 32 * 2 % 1
  490.       time = hour':'min':'sec
  491.       s = s date time
  492.    enddo
  493.    file_size = ltoa(substr(resultbuf,13,4),10)
  494.    filealloc = ltoa(substr(resultbuf,17,4),10)
  495.    fileattrib = itoa(substr(resultbuf,21,2),16)
  496.    namelen = asc(substr(resultbuf,23,1))
  497.    name = substr(resultbuf,24,namelen)
  498.    sayerror 'Create, access, write timestamps =' s
  499.    sayerror 'filesize='file_size', allocated size='filealloc', attributes='fileattrib', namelen='namelen', count='itoa(searchcount,10)
  500.    sayerror 'filename = "'name'"'
  501.  
  502.  
  503. ; DosCalls #65:  DosFindNext
  504.    resultbuf = copies(\0, 300)  -- Might need to allocate a buffer if < EPM 5.60
  505.    searchcnt = atoi(1)   -- Search count; we're only asking for 1 file at a time here.
  506.    result=dynalink('DOSCALLS',             -- dynamic link library name
  507.                    '#65',                  -- ordinal value for DOSFINDNEXT
  508.                    dirhandle           ||  -- Directory handle, returned by DosFindFirst(2)
  509.                    selector(resultbuf) ||  -- string selector
  510.                    offset(resultbuf)   ||  -- string offset
  511.                    atoi(length(resultbuf)) ||
  512.                    selector(searchcnt) ||  -- Pointer to the count; system updates
  513.                    offset(searchcnt) )
  514.  
  515.        if result = 0   then msg = 'NO_ERROR'
  516.    elseif result = 6   then msg = 'ERROR_INVALID_HANDLE'
  517.    elseif result = 18  then msg = 'ERROR_NO_MORE_FILES'
  518.    elseif result = 26  then msg = 'ERROR_NOT_DOS_DISK'
  519.    elseif result = 87  then msg = 'ERROR_INVALID_PARAMETER'
  520.    elseif result = 111 then msg = 'ERROR_BUFFER_OVERFLOW'
  521.    elseif result = 275 then msg = 'ERROR_EAS_DIDNT_FIT'
  522.    endif
  523.  
  524.  
  525. ; DosCalls #66:  DosMkDir
  526.       result=dynalink('DOSCALLS',            -- dynamic link library name
  527.                       '#66',                 -- ordinal value for DOSMKDIR
  528.                       selector(filename) ||  -- string selector
  529.                       offset(filename)   ||  -- string offset
  530.                       atol(0))               -- reserved
  531.  
  532.  
  533. ; DosCalls #67:  DosMove
  534.          rc=dynalink('DOSCALLS',          /* dynamic link library name */
  535.                      '#67',               /* DosMove - move a file     */
  536.                      selector(oldfilez)||
  537.                      offset(oldfilez)  ||
  538.                      selector(newfilez)||
  539.                      offset(newfilez)  ||
  540.                      atol(0))             /* Reserved; must be 0       */
  541.  
  542.  
  543. ; DosCalls #70:  DosOpen
  544.    newhandle='??'
  545.    actiontaken=atoi(1)
  546.    file=file\0
  547.    result = dynalink('DOSCALLS',
  548.                      '#70',                     /* dosopen          */
  549.                      selector(file)||
  550.                      offset(file)||
  551.                      selector( newhandle )||
  552.                      offset( newhandle )||
  553.                      selector( actiontaken )||
  554.                      offset( actiontaken )||
  555.                      atol(0)||  -- File size
  556.                      atoi(0)||  -- File attribute
  557.                      atoi(17)||  -- Open flag (create if new; open if exists)
  558.                      atoi(146)||  -- Open mode (private; deny read/write; get read/write access)
  559.                      atol(0))  -- Reserved
  560.  
  561.  
  562. ; DosCalls #71:  DosQCurDir
  563.    string =  atoi(80) || substr('',1,80)  /* create input strings for  */
  564.    stringlen = substr('',1,4)             /* DOSQCURDIR                */
  565.    result=dynalink('DOSCALLS',
  566.                    '#71',
  567.                    atoi(0)||               /* Drive number - 1=A, etc */
  568.                    selector(string)||      /* Directory path buffer */
  569.                    offset(string)||
  570.                    selector(stringlen)||   /* Directory path buffer length */
  571.                    offset(stringlen))
  572.    sayerror  'len = ' hex_to_string(stringlen) 'current dir = ' string
  573.  
  574.  
  575.  
  576. ; DosCalls #75:  DosQFileMode
  577.       attrib='  '
  578.       cflag=dynalink('DOSCALLS',            -- dynamic link library name
  579.                      '#75',                 -- ordinal value for DOSQFILEMODE
  580.                      selector(filename) ||  -- string selector
  581.                      offset(filename)   ||  -- string offset
  582.                      selector(attrib)   ||  -- string selector
  583.                      offset(attrib)     ||  -- string offset
  584.                      atol(0))               -- reserved
  585.  
  586.  
  587. ; DosCalls #76:  DosQFsInfo
  588.       infobuf=substr('',1,255)
  589.       rc = dynalink('DOSCALLS',            -- dynamic link library name
  590.                     '#76',                 -- ordinal value for DOSQFSINFO
  591.                     atoi(drive_no)     ||  -- drive #; 0=default; 1=A, ...
  592.                     atoi(infolevel)    ||  -- info level requested
  593.                     selector(infobuf)  ||  -- string selector
  594.                     offset(infobuf)    ||  -- string offset
  595.                     atoi(length(infobuf))) -- length of buffer
  596.  
  597.  
  598. ; DosCalls #91:  DosGetEnv
  599.       seg_ptr = 1234                /* 4-byte place to put a far pointer */
  600.       cmd_ptr = 1234
  601.       call dynalink('DOSCALLS',           /* dynamic link library name   */
  602.                     '#91',                /* ordinal value for DOSGETENV */
  603.                     selector(seg_ptr) ||  /* pointer to env. segment     */
  604.                     offset(seg_ptr)   ||
  605.                     selector(cmd_ptr) ||  /* pointer to offset after     */
  606.                     offset(cmd_ptr)     ) /*    COMSPEC; we don't need   */
  607.       env_seg=itoa(seg_ptr,10)
  608.  
  609.  
  610. ; DosCalls #92:  DosGetVersion
  611.       verbuf = 'nn'
  612.       res= dynalink('DOSCALLS',          /* dynamic link library name */
  613.                     '#92',               /* ordinal for DOSGETVERSION */
  614.                     selector(verbuf) ||  /* string selector           */
  615.                     offset(verbuf))      /* string offset             */
  616. ;     major = asc(substr(verbuf,2,1))
  617. ;     minor = asc(substr(verbuf,1,1))
  618.  
  619.  
  620. ; DosCalls #98:  DosQPathInfo
  621.    pathname = 'H:\'\0
  622.    if arg(1) then pathname=arg(1)\0; endif
  623.    pathinfobuf = copies(\0,255)
  624.    pathinfobufsize = 255
  625.    PathInfoLevel = 5
  626.    ca = dynalink('DOSCALLS',      /* dynamic link library name       */
  627.                  '#98',           /* ordinal value for DOSQPATHINFO  */
  628.                  selector(pathname)        ||  -- pathname to be queried
  629.                  offset(pathname)          ||
  630.                  atoi(PathInfoLevel)       ||  -- PathInfoLevel
  631.                  selector(pathinfobuf)     ||  -- buffer where info is to be returned
  632.                  offset(pathinfobuf)       ||
  633.                  atoi(pathinfobufsize)     ||  -- size of buffer
  634.                  atol(0) )                     -- (reserved)
  635.  
  636.    sayerror 'result =' ca'; size='pathinfobufsize'; buf="'pathinfobuf'"'
  637. ;  For level 1:  (binary fields; convert as needed)
  638.    create_date = substr(pathinfobuf,  1, 2)  -- bits 15-9 = year; 8-5 = month; 4-0 = day
  639.    create_time = substr(pathinfobuf,  3, 2)  -- bits 15-11 = hour; 10-5 = minute; 4-0 = seconds
  640.    access_date = substr(pathinfobuf,  5, 2)  -- like create_
  641.    access_time = substr(pathinfobuf,  7, 2)
  642.    update_date = substr(pathinfobuf,  9, 2)  -- like create_
  643.    update_time = substr(pathinfobuf, 11, 2)
  644.    filesize    = substr(pathinfobuf, 13, 4)
  645.    allocsize   = substr(pathinfobuf, 17, 4)
  646.    fileattrib  = substr(pathinfobuf, 21, 2)
  647.  
  648. ; DosCalls #126: DosSizeSeg
  649.    size_out = '0000'                     -- result buffer
  650.    result=dynalink('DOSCALLS',           -- dynamic link library name
  651.                    '#126',               -- ordinal value for DosSizeSeg
  652.                    rightstr(ea_long,2),  -- segment
  653.                    selector(size_out) || -- string selector
  654.                    offset(size_out))     -- string offset
  655.    sayerror 'rc = ' rc'; size = ' ltoa(size_out,10)
  656.  
  657.  
  658. ; DosCalls #127: DosMemAvail
  659.    string =  '?????'                /* result buffer                   */
  660.    result=dynalink('DOSCALLS',      /* dynamic link library name       */
  661.                    '#127',          /* ordinal value for DOSMEMAVAIL   */
  662.                    selector(string)|| /* string selector               */
  663.                    offset(string))    /* string offset                 */
  664.    sayerror 'memavail = ' string 'itoa(hex) = ' itoa(string,16)
  665.  
  666.  
  667.  
  668. ; DosCalls #166: DosQSysInfo
  669.  
  670.    index = 0
  671.    databuf =  '??'                                -- result buffer
  672.    rc = '[not set]'
  673.    result=dynalink('DOSCALLS',                    -- dynamic link library name
  674.                    '#166',                        -- ordinal value for DOSQSYSINFO
  675.                    atoi(index)  ||
  676.                    selector(databuf) ||            -- string selector
  677.                    offset(databuf)   ||            -- string offset
  678.                    atoi(2) )                       -- buffer length
  679.    sayerror 'max path length =' itoa(databuf,10) 'result='result 'rc='rc
  680.  
  681. ; OS/2 2.0 version (but don't know how to access it)
  682.    startindex = 5
  683.    endindex = 13
  684.    databuf_len = (endindex - startindex + 1) * 4  -- Reserve this many double-words
  685.    databuf =  copies(\0, databuf_len)             -- result buffer
  686.    result=dynalink('DOSCALLS',                    -- dynamic link library name
  687. ??                 '#166',                        -- ordinal value for DOSQSYSINFO
  688.                    atol(startindex)  ||
  689.                    atol(endindex)    ||
  690.                    selector(databuf) ||            -- string selector
  691.                    offset(databuf)   ||            -- string offset
  692.                    atol(databuf_len) )             -- buffer length
  693.    sayerror 'Boot drive =' substr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', ltoa(leftstr(databuf,4),10),1)
  694.  
  695.  
  696.  
  697. ; DosCalls #201: DosCopy        (OS/2 1.2)
  698.       elseif dos_version() >= 1020 then  -- DOSCOPY is new in 1.2
  699.          rc=dynalink('DOSCALLS',          /* dynamic link library name */
  700.                      '#201',              /* DosCopy - Copy a file     */
  701.                      selector(oldfilez)||
  702.                      offset(oldfilez)  ||
  703.                      selector(newfilez)||
  704.                      offset(newfilez)  ||
  705.                      atoi(0)           || /* Mode                      */
  706.                      atol(0))             /* Reserved; must be 0       */
  707.  
  708.  
  709.  
  710. ; DosCall1       DosSemClear
  711.    res=dynalink('DOSCALL1',
  712.                 'DOSSEMCLEAR',
  713.                 poll_sem)                 /* Semaphore handle    */
  714.  
  715.  
  716. ; DosCall1       DosSemSet
  717. ;     call DosSemSet(poll_sem)  -- Set semaphore; cleared by timer pop.
  718.       result=dynalink('DOSCALL1',
  719.                       'DOSSEMSET',
  720.                       poll_sem)                 /* Semaphore handle    */
  721.       if result then
  722.          sayerror 'Error' result 'trying to set semaphore.'
  723.       endif
  724.  
  725.  
  726. ; DosCall1       DosSemWait
  727.    rc = dynalink('DOSCALL1',  -- rc 0 (false) if sem. is clear
  728.                  'DOSSEMWAIT',
  729.                  poll_sem||                /* Semaphore handle */
  730.                  long(1))                  /* Timeout          */
  731.  
  732. ; DosCall1       DosScanEnv
  733.    varname = upcase(varname)\0   -- (see Get_env in DOSUTIL.E for a complete example)
  734.    result_ptr = 1234                -- 4-byte place to put a far pointer
  735.    rc = dynalink('DOSCALL1',        -- rc 0 (false) if found
  736.                  'DOSSCANENV',
  737.                  selector(varname)    ||
  738.                  offset(varname)      ||
  739.                  selector(result_ptr) || -- string selector
  740.                  offset(result_ptr))     -- string offset
  741.  
  742. ; DosCall1       DosSearchPath
  743. defc try =
  744.    pathz = 'DPATH'\0
  745.    filenamez = arg(1)\0
  746.    result_str = substr('',1,255)
  747.    rc = dynalink('DOSCALL1',        -- rc 0 (false) if found
  748.                  'DOSSEARCHPATH',
  749.                  atoi(4)              ||
  750.                  selector(pathz)      ||
  751.                  offset(pathz)        ||
  752.                  selector(filenamez)  || -- string selector
  753.                  offset(filenamez)    || -- string offset
  754.                  selector(result_str) || -- string selector
  755.                  offset(result_str)   || -- string offset
  756.                  atoi(255) )             -- buffer length
  757.    if rc then
  758.       sayerror 'RC='rc
  759.    else
  760.       parse value result_str with result_str \0
  761.       sayerror '"'result_str'"'
  762.    endif
  763.  
  764. ; DosCall1       DosSearchPath
  765.    -- Assume filehandle is set from previous DosOpen
  766.    strng = 'Test output'\13\10'End of test.'\13\10  -- End lines with CR/LF
  767.    bytes_written = 00  -- Reserve two bytes
  768.    rc = dynalink('DOSCALL1',
  769.                  'DOSWRITE',
  770.                  filehandle               ||  -- Binary file handle
  771.                  selector(strng)          ||  -- Buffer to write to file
  772.                  offset(strng)            ||
  773.                  atoi(length(strng))      ||  -- Number of bytes to write.
  774.                  selector(bytes_written)  ||  -- string selector
  775.                  offset(bytes_written) )      -- string offset
  776.    if rc then
  777.       sayerror 'DosWrite error; RC='rc
  778.    elseif length(strng)<>itoa(bytes_written,10) then
  779.       sayerror 'Only'itoa(bytes_written,10) 'bytes were written out!'
  780.    endif