home *** CD-ROM | disk | FTP | other *** search
/ Software Collection (I) / TOOLS.iso / b04 / 18.img / NET / UTILS.AS_ / UTILS.AS
Encoding:
Text File  |  1991-04-19  |  10.8 KB  |  436 lines

  1. page        60, 132
  2. title        Various Utility Functions
  3. ;===============================================================================
  4. ;        Filename    UTILS.ASM
  5. ;        Copyright    (C) 1989 by Research Machines
  6. ;                (C) 1989-1990 Microsoft Corp
  7. ;===============================================================================
  8. ; REVISIONS:    24/02/1989    Initial version
  9. ;        15/03/1989    Bug fix UTLToUpper ( remove AX from autosave list )
  10. ;        15/03/1989    Add UTLRemoveTrailingColon
  11. ;        16/03/1989    Change to STANDARD procedures (save si, di, es)
  12. ;        16/03/1989    UTLLocalAlloc returns long pointer to heap
  13. ;        16/03/1989    Add UTLAppendTrailingColon
  14. ;        22/03/1989    Tidy up functions
  15. ;        23/03/1989    Change to segment name
  16. ;        29/03/1989    Add UTLIsNetworkPath
  17. ;        31/03/1989    Tidied up comments
  18. ;        ever since    Make it work for real
  19. ;===============================================================================
  20.  
  21.         memM    equ    1        ; Middle memory model
  22.         ?WIN    =    1        ; Windows prolog/epilog
  23.         ?PLM    =    1        ; Pascal calling convention
  24.  
  25.         .xlist
  26. include     cmacros.inc
  27. include     windows.inc
  28. include     wnet.inc
  29.         .list
  30.  
  31.         .sall
  32.  
  33. externFP    lstrlen
  34. externFP    lstrcpy
  35.  
  36. ;===============================================================================
  37. ; ============= DATA SEGMENT ===================================================
  38. ;===============================================================================
  39.  
  40. sBegin        DATA
  41.  
  42. ;
  43. ;    Flags used in WNETPOLL.ASM (address returned by UTLIsSerialDevice()
  44. ;
  45. externW     rgfWatch
  46.  
  47. CPORTS        equ 4        ; number of LPT ports
  48.  
  49. rgchPort    db  'LPT'    ; used for compare
  50. CCHPREFIX    equ 3        ; length thereof
  51.  
  52. sEnd        DATA
  53.  
  54. ;===============================================================================
  55. ; ============= CODE SEGMENT ===================================================
  56. ;===============================================================================
  57.  
  58. sBegin        CODE
  59.         assumes CS, CODE
  60.         assumes DS, DATA
  61.  
  62. ;===============================================================================
  63. ; ============= PUBLIC FUNTIONS ================================================
  64. ;===============================================================================
  65.  
  66.  
  67. ;===============================================================================
  68. subttl        UTLMemMove
  69. page
  70. ;===============================================================================
  71.  
  72. cProc        UTLMemMove, <FAR, PUBLIC>, <si, di>
  73.  
  74.         parmD    lpDest
  75.         parmD    lpSource
  76.         parmW    nCount
  77. cBegin
  78.         lds    si, ( lpSource )
  79.         les    di, ( lpDest )
  80.         mov    cx, ( nCount )
  81.  
  82.         mov    ax, word ptr ( lpSource + 2 )        ; ds
  83.         cmp    ax, word ptr ( lpDest + 2 )        ; es
  84.         jne    MoveForward
  85.  
  86.         mov    ax, word ptr ( lpSource + 0 )        ; si
  87.         cmp    ax, word ptr ( lpDest + 0 )        ; di
  88.         ja    MoveForward
  89.  
  90.         add    si, cx
  91.         dec    si
  92.         add    di, cx
  93.         dec    di
  94.         std
  95.         rep movsb
  96.         cld
  97.         jmp    short Moved
  98.  
  99. MoveForward:    cld
  100.         rep movsb
  101.  
  102. Moved:
  103.  
  104. cEnd
  105.  
  106. ;===============================================================================
  107. subttl        UTLRemoveTrailingSpaces
  108. page
  109. ;===============================================================================
  110.  
  111. cProc        UTLRemoveTrailingSpaces, <FAR, PUBLIC>, <si, di>
  112.  
  113.         parmD    lpString
  114.         parmW    nSize
  115. cBegin
  116.         les    di, ( lpString )
  117.         mov    cx, ( nSize )
  118.         jcxz    Removed
  119.  
  120.         add    di, cx
  121.         dec    di
  122.  
  123.         std
  124.         mov    al, ' '
  125.         repe    scasb
  126.         cld
  127.         mov    byte ptr es:[di+2],0
  128. Removed:
  129. cEnd
  130.  
  131. ;===============================================================================
  132. subttl        UTLRemoveTrailingColon
  133. page
  134. ;===============================================================================
  135.  
  136. cProc        UTLRemoveTrailingColon, <FAR, PUBLIC>, <si, di>
  137.  
  138.         parmD    lpszString
  139. cBegin
  140.         Arg    lpszString
  141.         cCall    LStrlen
  142.         cmp    ax, 0
  143.         je    RTCExit
  144.  
  145.         mov    bx, ax
  146.         les    di, ( lpszString )
  147.         cmp    byte ptr es: [ di + bx - 1 ], ':'
  148.         jne    RTCExit
  149.  
  150.         mov    byte ptr es: [ di + bx - 1 ], NULL
  151.  
  152. RTCExit:    mov    ax, WN_SUCCESS
  153.  
  154. cEnd
  155.  
  156. ;===============================================================================
  157. subttl        UTLAppendTrailingColon
  158. page
  159. ;===============================================================================
  160.  
  161. cProc        UTLAppendTrailingColon, <FAR, PUBLIC>, <si, di>
  162.  
  163.         parmD    lpszString
  164. cBegin
  165.         Arg    lpszString
  166.         cCall    LStrlen
  167.         cmp    ax, 0
  168.         je    ATCExit
  169.  
  170.         mov    bx, ax
  171.         les    di, ( lpszString )
  172.         cmp    byte ptr es: [ di + bx - 1 ], ':'
  173.         je    ATCExit
  174.  
  175.         mov    byte ptr es: [ di + bx ], ':'
  176.         mov    byte ptr es: [ di + bx + 1 ], NULL
  177.  
  178. ATCExit:    mov    ax, WN_SUCCESS
  179.  
  180. cEnd
  181.  
  182. ;===============================================================================
  183. subttl        UTLToUpper
  184. page
  185. ;===============================================================================
  186.  
  187. cProc        UTLToUpper, <FAR, PUBLIC>, <si, di>
  188.  
  189.         parmW    nCharacter
  190. cBegin
  191.         mov    ax, ( nCharacter )
  192.  
  193.         cmp    ax, 'a'
  194.         jb    ToUpperExit
  195.         cmp    ax, 'z'
  196.         ja    ToUpperExit
  197.  
  198.         sub    ax, 'a'
  199.         add    ax, 'A'
  200.  
  201. ToUpperExit:
  202.  
  203. cEnd
  204.  
  205. ;===============================================================================
  206. subttl        UTLStricmpColon
  207. page
  208. ;===============================================================================
  209. ;
  210. ; DESCRIPTION . Compare strings without reguard for case, ignoring colons.
  211. ; ENTRY .......
  212. ; EXIT ........
  213. ; COMMENTS ....
  214. ;
  215. ;===============================================================================
  216.  
  217. cProc        UTLStricmpColon, <FAR, PUBLIC>, <si, di>
  218.  
  219.         parmD    lpszString1
  220.         parmD    lpszString2
  221. cBegin
  222.         lds    si, lpszString1
  223.         les    di, lpszString2
  224.  
  225. StricmpCChar1:    mov    al, ds: [ si ]                ; Char from string1
  226.         inc    si                    ;
  227.         cmp    al, ':'                 ;
  228.         je    StricmpCChar1                ;
  229. StricmpCChar2:    mov    ah, es: [ di ]                ; Char from string2
  230.         inc    di                    ;
  231.         cmp    ah, ':'                 ;
  232.         je    StricmpCChar2                ;
  233.  
  234.         cmp    ax, 0                    ; Reached end of both?
  235.         je    UTLStricmpColonExit            ; Must be equal
  236.  
  237.         mov    bl, ah                    ; make AX = char1
  238.         mov    ah, 0                    ; make BX = char2
  239.         mov    bh, 0                    ;
  240.  
  241. ;---------------------------------------------------------------
  242. ; Convert characters to upper case
  243. ;---------------------------------------------------------------
  244.  
  245.         push    es
  246.         Arg    ax
  247.         cCall    UTLToUpper
  248.         xchg    ax, bx
  249.         Arg    ax
  250.         cCall    UTLToUpper
  251.         xchg    ax, bx
  252.         pop    es
  253.  
  254. ;---------------------------------------------------------------
  255. ; Compare
  256. ;---------------------------------------------------------------
  257.  
  258.         sub    ax, bx                    ; Chars equal?
  259.         jz    StricmpCChar1                ; yep, try next
  260.  
  261. UTLStricmpColonExit:
  262.  
  263. cEnd
  264.  
  265. ;===============================================================================
  266. subttl        UTLIsSerialDevice
  267. page
  268. ;===============================================================================
  269. ;
  270. ; DESCRIPTION . If szName != "LPT1:" .. "LPT4:", return NULL
  271. ;        For valid LPT's, points to a structure containing the
  272. ;        task handle of the task with the port open and the window
  273. ;        handle of the window watching the queue.
  274. ;
  275. ; ENTRY ....... lpszName points to local port
  276. ; EXIT ........ Returns non-zero iff device is a local port
  277. ;
  278. ;===============================================================================
  279.  
  280. cProc        UTLIsSerialDevice, <FAR, PUBLIC>, <si, di>
  281.  
  282.     parmD   lpszLocal
  283.  
  284. cBegin
  285.  
  286.     les     di,lpszLocal
  287.     lea     si,rgchPort
  288.     mov     cx,CCHPREFIX
  289.     repe    cmpsb        ; does it start with LPT? (BUG: Case sensitive)
  290.     jnz     isd_invalid
  291.  
  292.     mov     al,es:[di]        ; ok, which port?
  293.     inc     di
  294.     sub     al,'1'
  295.     cmp     al,CPORTS-1     ; must be 1, 2, 3, or 4
  296.     ja        isd_invalid
  297.     cbw
  298.     xchg    ax,bx        ; save number away in bx
  299.     mov     al,es:[di]        ; must end with \0 or :\0
  300.     or        al,al
  301.     jz        isd_valid
  302.     cmp     al,':'        ; second not colon?
  303.     jnz     isd_invalid     ; invalid
  304.     cmp     byte ptr es:[di+1],0
  305.     jnz     isd_invalid
  306.  
  307. isd_valid:
  308.     mov     ax, size WatchEntry
  309.     mul     bx
  310.     add     ax, dataoffset rgfWatch
  311.  
  312.     jmp     short isd_exit
  313.  
  314. isd_invalid:
  315.     sub     ax,ax        ; return NULL
  316.  
  317. isd_exit:
  318. cEnd
  319.  
  320. ;===============================================================================
  321. subttl        UTLIsNetworkPath
  322. page
  323. ;===============================================================================
  324. ;        If szName starts with '\\' return TRUE
  325. ;===============================================================================
  326.  
  327. cProc        UTLIsNetworkPath, <FAR, PUBLIC, NODATA>
  328.  
  329.         parmD    lpszName
  330. cBegin
  331.         les    bx, ( lpszName )
  332.         mov    ax, TRUE
  333.         cmp    word ptr es: [ bx ], '\\'
  334.         je    UTLIsNetworkPathExit
  335.         mov    ax, FALSE
  336.  
  337. UTLIsNetworkPathExit:
  338.  
  339. cEnd
  340.  
  341. ;===============================================================================
  342.  
  343. ;===============================================================================
  344. subttl        UTLYearMonthDayToSeconds
  345. page
  346. ;===============================================================================
  347.  
  348. daysafterfeb    dw  31                ; mar
  349.         dw  31+30            ; apr
  350.         dw  31+30+31            ; may
  351.         dw  31+30+31+30         ; jun
  352.         dw  31+30+31+30+31        ; jul
  353.         dw  31+30+31+30+31+31        ; aug
  354.         dw  31+30+31+30+31+31+30    ; sep
  355.         dw  31+30+31+30+31+31+30+31    ; oct
  356.         dw  31+30+31+30+31+31+30+31+30    ; nov
  357.  
  358. cProc        UTLYearMonthDayToSeconds, <FAR, PUBLIC, NODATA>
  359.  
  360.         parmW    nYear
  361.         parmW    nMonth
  362.         parmW    nDay
  363. cBegin
  364.  
  365.     sub     ax, ax
  366.     sub     dx, dx
  367.     mov     cx, nYear
  368.     mov     bx, 28            ; number of days in Feb
  369.     test    cx, 3            ; this year a leaper?
  370.     jnz     ymd_yearloop        ; nope, skip
  371.  
  372.     inc     bx                ; extra day in feb
  373.  
  374. ymd_yearloop:
  375.     add     ax, 365            ; 365 days in a year
  376.     test    dx, 3            ; not divisible by four
  377.     jnz     ymd_notleap         ; damn the solar system anyway
  378.     inc     ax                ; leap year... 366 days
  379. ymd_notleap:
  380.     inc     dx
  381.     loop    ymd_yearloop
  382.  
  383.     mov     cx, nMonth
  384.  
  385.     jcxz    ymd_nowdodays        ; jan
  386.     add     ax, 31
  387.     dec     cx
  388.     jz        ymd_nowdodays        ; feb
  389.     add     ax, bx            ; account for that DAMN leap day
  390.     dec     cx
  391.     jz        ymd_nowdodays        ; now march
  392.  
  393.     dec     cx
  394.     shl     cx, 1
  395.     mov     bx, cx
  396.     add     ax, cs:daysafterfeb[bx] ; look it up
  397.  
  398. ymd_nowdodays:
  399.     add     ax, nDay
  400.  
  401.     shl     ax, 1            ; convert to seconds... days*2
  402.     mov     cx, 12*60*60        ; 12 = hours, *60*60 = secs
  403.     mul     cx
  404.  
  405. cEnd
  406.  
  407. ;===============================================================================
  408. subttl        UTLHourMinuteSecondToSeconds
  409. page
  410. ;===============================================================================
  411.  
  412. cProc        UTLHourMinuteSecondToSeconds, <FAR, PUBLIC, NODATA>
  413.  
  414.         parmW    nHour
  415.         parmW    nMinute
  416.         parmW    nSecond
  417. cBegin
  418.         mov    cx, 60
  419.  
  420.         mov    ax, ( nHour )            ; Hours -> minutes
  421.         mul    cl                ; 0 to 1380
  422.  
  423.         add    ax, ( nMinute )         ; Minutes -> seconds
  424.         mul    cx                ; 0 to 86340
  425.  
  426.         add    ax, ( nSecond )         ; Seconds -> seconds
  427.         adc    dx, 0                ; 0 to 86399
  428. cEnd
  429.  
  430. ;===============================================================================
  431. ; ============= END OF UTILS ===================================================
  432. ;===============================================================================
  433.  
  434. sEnd        CODE
  435.         end
  436.