Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [modules/] [basext/] [parseurl.asm] - Diff between revs 371 and 380

Show entire file | Details | Blame | View Log

Rev 371 Rev 380
Line 17... Line 17...
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;THE SOFTWARE.
;THE SOFTWARE.
 
.include        "defs.inc"
 
.include        "sysvars.inc"
 
.text
; Parse URLs for mounting filesystems.
; Parse URLs for mounting filesystems.
 
 
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
; F_parseurl: Break up incoming string into null-terminated strings.
; F_parseurl: Break up incoming string into null-terminated strings.
; Parameters: IX - points to memory where the mount structure will be held
; Parameters: IX - points to memory where the mount structure will be held
;             HL - pointer to string
;             HL - pointer to string
F_parseurl
.globl F_parseurl
 
F_parseurl:
        call F_findfstype       ; if there's an fs type token
        call F_findfstype       ; if there's an fs type token
        jr nc, .continue        ; then continue
        jr nc, .continue1       ; then continue
        push hl                 ; otherwise
        push hl                 ; otherwise
        ld hl, STR_defaulttype  ; make a copy of the default fs
        ld hl, STR_defaulttype  ; make a copy of the default fs
        ld de, v_workspace      ; type token in memory that's not
        ld de, v_workspace      ; type token in memory that's not
        ld bc, deftypelen       ; going to get paged out.
        ld bc, deftypelen       ; going to get paged out.
        ldir
        ldir
        pop hl
        pop hl
        ld (ix+0), v_workspace%256
        ld (ix+0), v_workspace%256
        ld (ix+1), v_workspace/256
        ld (ix+1), v_workspace/256
        jr .finduser
        jr .finduser1
.continue
.continue1:
        ld (ix+0), e            ; set the host arg
        ld (ix+0), e            ; set the host arg
        ld (ix+1), d
        ld (ix+1), d
.finduser
.finduser1:
        call F_finduser         ; User specified in the string?
        call F_finduser         ; User specified in the string?
        jr c, .findhost
        jr c, .findhost1
        ld (ix+6), e
        ld (ix+6), e
        ld (ix+7), d
        ld (ix+7), d
        call F_findpasswd       ; Is there a password?
        call F_findpasswd       ; Is there a password?
        jr c, .findhost
        jr c, .findhost1
        ld (ix+8), e
        ld (ix+8), e
        ld (ix+9), d
        ld (ix+9), d
.findhost
.findhost1:
        call F_findhost         ; There *must* be a host.
        call F_findhost         ; There *must* be a host.
        ret c
        ret c
        ld (ix+2), e
        ld (ix+2), e
        ld (ix+3), d
        ld (ix+3), d
.path                           ; The remainder is the path - just
.path1:                         ; The remainder is the path - just
        ld (ix+4), l            ; set the next argument to the current
        ld (ix+4), l            ; set the next argument to the current
        ld (ix+5), h            ; value of HL and return.
        ld (ix+5), h            ; value of HL and return.
        ret
        ret
 
 
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
; Find the filesystem type token if there is one. If there is, return
; Find the filesystem type token if there is one. If there is, return
; with carry reset, DE pointing at the start address, and HL pointing
; with carry reset, DE pointing at the start address, and HL pointing
; at the start of the  next bit of the string to parse.
; at the start of the  next bit of the string to parse.
; If not return with carry set and HL set to its original value.
; If not return with carry set and HL set to its original value.
F_findfstype
.globl F_findfstype
 
F_findfstype:
        push hl
        push hl
.loop
.loop2:
        ld a, (hl)
        ld a, (hl)
        and a
        and a
        jr z, J_notfound
        jr z, J_notfound
        cp ':'                  ; look for colon token followed by...
        cp ':'                  ; look for colon token followed by...
        inc hl
        inc hl
        jr nz, .loop            ; Not found, next...
        jr nz, .loop2           ; Not found, next...
        ld a, (hl)              ; See if we have an "/"
        ld a, (hl)              ; See if we have an "/"
        cp '/'
        cp '/'
        jr z, .found
        jr z, .found2
        inc hl
        inc hl
        jr .loop                ; no, continue
        jr .loop2               ; no, continue
.found
.found2:
        dec hl                  ; convert tokens to nulls
        dec hl                  ; convert tokens to nulls
        xor a
        xor a
        ld (hl), a              ; delete the colon
        ld (hl), a              ; delete the colon
        inc hl
        inc hl
        ld (hl), a              ; delete the slash
        ld (hl), a              ; delete the slash
        inc hl
        inc hl
        ld (hl), a              ; delete the second slash
        ld (hl), a              ; delete the second slash
        inc hl
        inc hl
        pop de                  ; return start address in DE
        pop de                  ; return start address in DE
        ret
        ret
J_notfound
J_notfound:
        pop hl                  ; restore HL
        pop hl                  ; restore HL
        scf                     ; indicate "no fstype found"
        scf                     ; indicate "no fstype found"
        ret
        ret
 
 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; See if there's a user. The hostname part of the string can be
; See if there's a user. The hostname part of the string can be
; user@host, user:pw@host or just host.
; user@host, user:pw@host or just host.
F_finduser
.globl F_finduser
 
F_finduser:
        push hl
        push hl
.loop
.loop3:
        ld a, (hl)
        ld a, (hl)
        and a                   ; end of string
        and a                   ; end of string
        jr z, J_notfound
        jr z, J_notfound
        cp '/'                  ; we've hit the first bit of the path...
        cp '/'                  ; we've hit the first bit of the path...
        jr z, J_notfound
        jr z, J_notfound
        cp ':'
        cp ':'
        jr z, J_found           ; password separator found
        jr z, J_found           ; password separator found
        cp '@'                  ; host separator?
        cp '@'                  ; host separator?
        jr z, J_found
        jr z, J_found
        inc hl
        inc hl
        jr .loop                ; no - check the next char
        jr .loop3               ; no - check the next char
J_found
J_found:
        pop de                  ; DE = start of string
        pop de                  ; DE = start of string
        ld a, d                 ; make sure the arg is at least 1 char
        ld a, d                 ; make sure the arg is at least 1 char
        cp h
        cp h
        jr nz, .done
        jr nz, .done3
        ld a, e
        ld a, e
        cp l
        cp l
        jr nz, .done
        jr nz, .done3
        ex de, hl               ; oops - reset HL to the start of the string
        ex de, hl               ; oops - reset HL to the start of the string
        scf                     ; indicate not found
        scf                     ; indicate not found
        ret
        ret
.done
.done3:
        xor a
        xor a
        ld (hl), a
        ld (hl), a
        inc hl
        inc hl
        ret
        ret
 
 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; See if there's a password.
; See if there's a password.
F_findpasswd
.globl F_findpasswd
 
F_findpasswd:
        push hl
        push hl
.loop
.loop4:
        ld a, (hl)
        ld a, (hl)
        and a
        and a
        jr z, J_notfound
        jr z, J_notfound
        cp '/'
        cp '/'
        jr z, J_notfound
        jr z, J_notfound
        cp '@'
        cp '@'
        jr z, J_found
        jr z, J_found
        inc hl
        inc hl
        jr .loop
        jr .loop4
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; Find the hostname
; Find the hostname
F_findhost
.globl F_findhost
 
F_findhost:
        push hl
        push hl
.loop
.loop5:
        ld a, (hl)
        ld a, (hl)
        and a
        and a
        jr z, .addpath
        jr z, .addpath5
        cp '/'
        cp '/'
        jr z, J_found
        jr z, J_found
        inc hl
        inc hl
        jr .loop
        jr .loop5
 
 
        ; if we hit the end of the string while parsing the hostname
        ; if we hit the end of the string while parsing the hostname
        ; we can assume the user wants to mount the root.
        ; we can assume the user wants to mount the root.
.addpath
.addpath5:
        inc hl
        inc hl
        ld (hl), '/'
        ld (hl), '/'
        inc hl
        inc hl
        ld (hl), 0
        ld (hl), 0
        pop de
        pop de
        ret
        ret
 
.data
STR_defaulttype
STR_defaulttype:
        defb "tnfs",0
        defb "tnfs",0
deftypelen equ 5
deftypelen: equ 5
deftypelen: equ 5
deftypelen: equ 5