home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / cexpress / files / seeksubd.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  3.0 KB  |  103 lines

  1. ;unsigned short  seek_subdirectory(dir_name,st_element,tree_array);
  2. ;  char  *tree_array,*dir_name;
  3. ;  unsigned short  st_element;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.     EXTRN  _tree_array_size:word
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME CS:_TEXT
  11.     PUBLIC _seek_subdirectory
  12. _seek_subdirectory proc near
  13.     push bp            ;
  14.     mov  bp,sp        ;
  15.     push di            ;
  16.     push si            ;
  17.     cmp  _memory_model,0    ;near or far?
  18.     jle  begin        ;jump if near
  19.     inc  bp            ;else add 2 to BP
  20.     inc  bp            ;
  21. begin:    push ds            ;
  22.     mov  _error_code,3    ;3 = DirName wrong size
  23.     cmp  _memory_model,2    ;data near or far?
  24.     jb   L0            ;
  25.     les  di,dword ptr[bp+4] ;ES:DI pts to DirName
  26.     inc  bp            ;add 2 to BP since dword ptr
  27.     inc  bp            ;
  28.     jmp  short L00        ;
  29. L0:    mov  ax,ds        ;ES = DS
  30.     mov  es,ax        ;
  31.     mov  di,[bp+4]        ;NEAR case
  32. L00:    sub  cx,cx        ;
  33.     push di            ;find string length...
  34. L000:    cmp  byte ptr es:[di],0    ;end of string?
  35.     je   L1            ;
  36.     inc  di            ;forward ptr
  37.     inc  cx            ;inc strg length counter
  38.     jmp  short L000        ;
  39. L1:    pop  di            ;back to start of string
  40.     jcxz L8            ;quit if string is null
  41.     cmp  cl,12        ;longer than 12 chars?
  42.     ja   L8            ;quit if so
  43.     mov  si,di        ;keep a copy of startpoint
  44.     inc  cx            ;last byte (null) must match too
  45.     mov  dx,cx        ;copy of DirName length
  46.     dec  _error_code    ;2 = StElement out of range
  47. L2:    cmp  byte ptr es:[di],97 ;compare to 'a'
  48.     jb   L3            ;jump ahead if below
  49.     cmp  byte ptr es:[di],122 ;compare to 'z'
  50.     ja   L3            ;jump ahead if above
  51.     sub byte ptr es:[di],32 ;make upper case
  52. L3:    inc  di            ;forward pointer
  53.     loop L2            ;go do next char
  54.     mov  di,si        ;point ES:DI back to string descriptor
  55.     mov  ax,[bp+6]        ;fetch StartElement
  56.     or   ax,ax        ;test for 0
  57.     jz   L8            ;quit if zero
  58.     mov  bx,_tree_array_size ;getch _tree_array_size
  59.     cmp  ax,bx        ;in range?
  60.     ja   L8            ;quit if not
  61.     dec  _error_code    ;1 = no match found
  62.     dec  ax            ;count from 0 to figure offset
  63.     sub  bx,ax        ;number elements to check
  64.     mov  cl,21        ;bytes per record
  65.     mul  cl            ;figure offset
  66.     cmp  _memory_model,2    ;data near or far?
  67.     jb   L4            ;
  68.     lds  si,dword ptr[bp+8] ;DS:SI pts to array
  69.     jmp  short L5        ;
  70. L4:    mov  si,[bp+8]        ;
  71. L5:    add  si,21        ;start from first array element
  72.     add  si,ax        ;now DS:SI pts to element
  73.     cld            ;direction forward
  74. L6:    push di            ;save pointer start points
  75.     push si            ;
  76.     mov  cx,dx        ;DirName length
  77.     repe cmpsb        ;compare the strings
  78.     pop  si            ;restore start points
  79.     pop  di            ;
  80.     jz   L7            ;match found
  81.     dec  bx            ;dec element counter
  82.     jz   L8            ;quit if all elements compared
  83.     add  si,21        ;forward to next element name
  84.     jmp  short L6        ;loop
  85. L7:    pop  ds            ;found it
  86.     mov  _error_code,0    ;0 = match found
  87.     mov  ax,_tree_array_size ;calculate match offset
  88.     sub  ax,bx        ;
  89.     inc  ax            ;
  90.     jmp  short L9        ;go quit
  91. L8:    pop  ds            ;out of elements, didn't find
  92.     sub  ax,ax        ;return 0 as position
  93. L9:    pop  si            ;
  94.     pop  di            ;
  95.     pop  bp            ;
  96.     cmp  _memory_model,0    ;quit
  97.     jle  quit        ;
  98.     db   0CBh        ;RET far
  99. quit:    ret            ;RET near
  100. _seek_subdirectory endp
  101. _TEXT    ENDS
  102.     END
  103.