mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-07-06 03:30:23 +00:00
Move some file-related functions into utilities/file.bas
This commit is contained in:
parent
18c4fc5e5e
commit
0930d51b9c
|
@ -13638,28 +13638,6 @@ FUNCTION Type2MemTypeValue (t1)
|
||||||
Type2MemTypeValue = t
|
Type2MemTypeValue = t
|
||||||
END FUNCTION
|
END FUNCTION
|
||||||
|
|
||||||
FUNCTION FileHasExtension (f$)
|
|
||||||
FOR i = LEN(f$) TO 1 STEP -1
|
|
||||||
a = ASC(f$, i)
|
|
||||||
IF a = 47 OR a = 92 THEN EXIT FOR
|
|
||||||
IF a = 46 THEN FileHasExtension = -1: EXIT FUNCTION
|
|
||||||
NEXT
|
|
||||||
END FUNCTION
|
|
||||||
|
|
||||||
FUNCTION RemoveFileExtension$ (f$) 'returns f$ without extension
|
|
||||||
FOR i = LEN(f$) TO 1 STEP -1
|
|
||||||
a = ASC(f$, i)
|
|
||||||
IF a = 47 OR a = 92 THEN EXIT FOR
|
|
||||||
IF a = 46 THEN RemoveFileExtension$ = LEFT$(f$, i - 1): EXIT FUNCTION
|
|
||||||
NEXT
|
|
||||||
RemoveFileExtension$ = f$
|
|
||||||
END FUNCTION
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'udt is non-zero if this is an array of udt's, to allow examining each udt element
|
'udt is non-zero if this is an array of udt's, to allow examining each udt element
|
||||||
FUNCTION allocarray (n2$, elements$, elementsize, udt)
|
FUNCTION allocarray (n2$, elements$, elementsize, udt)
|
||||||
dimsharedlast = dimshared: dimshared = 0
|
dimsharedlast = dimshared: dimshared = 0
|
||||||
|
@ -24334,17 +24312,6 @@ FUNCTION lineinput3$
|
||||||
END IF
|
END IF
|
||||||
END FUNCTION
|
END FUNCTION
|
||||||
|
|
||||||
FUNCTION getfilepath$ (f$)
|
|
||||||
FOR i = LEN(f$) TO 1 STEP -1
|
|
||||||
a$ = MID$(f$, i, 1)
|
|
||||||
IF a$ = "/" OR a$ = "\" THEN
|
|
||||||
getfilepath$ = LEFT$(f$, i)
|
|
||||||
EXIT FUNCTION
|
|
||||||
END IF
|
|
||||||
NEXT
|
|
||||||
getfilepath$ = ""
|
|
||||||
END FUNCTION
|
|
||||||
|
|
||||||
FUNCTION eleucase$ (a$)
|
FUNCTION eleucase$ (a$)
|
||||||
'this function upper-cases all elements except for quoted strings
|
'this function upper-cases all elements except for quoted strings
|
||||||
'check first element
|
'check first element
|
||||||
|
@ -24447,19 +24414,6 @@ FUNCTION GDB_Fix$ (g_command$) 'edit a gcc/g++ command line to include debugging
|
||||||
GDB_Fix$ = c$
|
GDB_Fix$ = c$
|
||||||
END FUNCTION
|
END FUNCTION
|
||||||
|
|
||||||
|
|
||||||
SUB PATH_SLASH_CORRECT (a$)
|
|
||||||
IF os$ = "WIN" THEN
|
|
||||||
FOR x = 1 TO LEN(a$)
|
|
||||||
IF ASC(a$, x) = 47 THEN ASC(a$, x) = 92
|
|
||||||
NEXT
|
|
||||||
ELSE
|
|
||||||
FOR x = 1 TO LEN(a$)
|
|
||||||
IF ASC(a$, x) = 92 THEN ASC(a$, x) = 47
|
|
||||||
NEXT
|
|
||||||
END IF
|
|
||||||
END SUB
|
|
||||||
|
|
||||||
'Steve Subs/Functins for _MATH support with CONST
|
'Steve Subs/Functins for _MATH support with CONST
|
||||||
FUNCTION Evaluate_Expression$ (e$)
|
FUNCTION Evaluate_Expression$ (e$)
|
||||||
t$ = e$ 'So we preserve our original data, we parse a temp copy of it
|
t$ = e$ 'So we preserve our original data, we parse a temp copy of it
|
||||||
|
|
|
@ -30,3 +30,58 @@ errorCleanup:
|
||||||
|
|
||||||
CopyFile& = E
|
CopyFile& = E
|
||||||
END FUNCTION
|
END FUNCTION
|
||||||
|
|
||||||
|
'
|
||||||
|
' Splits the filename from its path, and returns the path
|
||||||
|
'
|
||||||
|
' Returns: The path, or empty if no path
|
||||||
|
FUNCTION getfilepath$ (f$)
|
||||||
|
FOR i = LEN(f$) TO 1 STEP -1
|
||||||
|
a$ = MID$(f$, i, 1)
|
||||||
|
IF a$ = "/" OR a$ = "\" THEN
|
||||||
|
getfilepath$ = LEFT$(f$, i)
|
||||||
|
EXIT FUNCTION
|
||||||
|
END IF
|
||||||
|
NEXT
|
||||||
|
getfilepath$ = ""
|
||||||
|
END FUNCTION
|
||||||
|
|
||||||
|
'
|
||||||
|
' Checks if a filename has an extension on the end
|
||||||
|
'
|
||||||
|
' Returns: True if provided filename has an extension
|
||||||
|
FUNCTION FileHasExtension (f$)
|
||||||
|
FOR i = LEN(f$) TO 1 STEP -1
|
||||||
|
a = ASC(f$, i)
|
||||||
|
IF a = 47 OR a = 92 THEN EXIT FOR
|
||||||
|
IF a = 46 THEN FileHasExtension = -1: EXIT FUNCTION
|
||||||
|
NEXT
|
||||||
|
END FUNCTION
|
||||||
|
|
||||||
|
'
|
||||||
|
' Strips the extension off of a filename
|
||||||
|
'
|
||||||
|
' Returns: Provided filename without extension on the end
|
||||||
|
FUNCTION RemoveFileExtension$ (f$)
|
||||||
|
FOR i = LEN(f$) TO 1 STEP -1
|
||||||
|
a = ASC(f$, i)
|
||||||
|
IF a = 47 OR a = 92 THEN EXIT FOR
|
||||||
|
IF a = 46 THEN RemoveFileExtension$ = LEFT$(f$, i - 1): EXIT FUNCTION
|
||||||
|
NEXT
|
||||||
|
RemoveFileExtension$ = f$
|
||||||
|
END FUNCTION
|
||||||
|
|
||||||
|
'
|
||||||
|
' Fixes the provided filename and path to use the correct path separator
|
||||||
|
'
|
||||||
|
SUB PATH_SLASH_CORRECT (a$)
|
||||||
|
IF os$ = "WIN" THEN
|
||||||
|
FOR x = 1 TO LEN(a$)
|
||||||
|
IF ASC(a$, x) = 47 THEN ASC(a$, x) = 92
|
||||||
|
NEXT
|
||||||
|
ELSE
|
||||||
|
FOR x = 1 TO LEN(a$)
|
||||||
|
IF ASC(a$, x) = 92 THEN ASC(a$, x) = 47
|
||||||
|
NEXT
|
||||||
|
END IF
|
||||||
|
END SUB
|
||||||
|
|
Loading…
Reference in a new issue