home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_BAS / DNALIB59.ZIP / DOS.BAS < prev    next >
BASIC Source File  |  1994-01-25  |  2KB  |  53 lines

  1. FUNCTION GetProgramName$ PUBLIC
  2.  
  3.   LOCAL PSPAddr%, Offset%, EndPoint%, Temp$
  4.  
  5.   PSPAddr% = GetPSP%          ' call the GetPSP% function to locate the segment of the PSP
  6.   DEF SEG = PSPAddr%
  7.   DEF SEG = PEEKI(44)         ' location of the environment is at offset 44 in the PSP
  8.   DO                          ' search the environment for the start of the file name
  9.     IF PEEK(Offset%) = 0 THEN        ' the start of the executable file name is marked with 2 nulls
  10.       IF PEEK(Offset% + 1) = 0 THEN
  11.        INCR Offset%, 4
  12.        EXIT LOOP
  13.       END IF
  14.     END IF
  15.     INCR Offset%
  16.   LOOP
  17.   EndPoint% = Offset%
  18.   DO                          ' search for the end of the file name
  19.     IF PEEK(EndPoint%) = 0 THEN EXIT LOOP
  20.     INCR EndPoint%
  21.   LOOP
  22.   Temp$ = PEEK$(Offset%, (EndPoint% - Offset% + 1))
  23.   DEF SEG                     ' restore default data segment
  24.  
  25.   GetProgramName$ = Temp$
  26.  
  27. END FUNCTION
  28. '----------------------------------------------------------------------------
  29. FUNCTION GetPSP% LOCAL PUBLIC
  30.  
  31.   REG 1, &H62 * 256   ' set AH to 62h
  32.   CALL INTERRUPT &H21 ' call DOS services
  33.   GetPSP% = REG(2)    ' PSP segment is returned in BX
  34.  
  35. END FUNCTION
  36. '----------------------------------------------------------------------------
  37. SUB SplitPath(FilePath$, Path$, FileName$) PUBLIC
  38.  
  39.   LOCAL StartPos%, c%
  40.  
  41.   StartPos% = 0
  42.   FOR c% = LEN(FilePath$) TO 1 STEP -1
  43.     IF MID$(FilePath$, c%, 1) = "\" OR MID$(FilePath$, c%, 1) = ":" THEN
  44.       StartPos% = c%
  45.       EXIT FOR
  46.     END IF
  47.   NEXT c%
  48.  
  49.   FileName$ = RIGHT$(FilePath$, (LEN(FilePath$) - StartPos%))
  50.   Path$ = LEFT$(FilePath$, StartPos%)
  51.  
  52. END SUB
  53.