Added FORMAT$ command to runtime
This commit is contained in:
parent
2315c249d5
commit
48c363f47b
4
demo.cpp
4
demo.cpp
@ -71,6 +71,10 @@ MAIN
|
|||||||
PRINT ( "SAVEFILE()" );
|
PRINT ( "SAVEFILE()" );
|
||||||
SAVEFILE(fileContents,"output.txt");
|
SAVEFILE(fileContents,"output.txt");
|
||||||
PRINT ( "Contents saved to 'output.txt'");
|
PRINT ( "Contents saved to 'output.txt'");
|
||||||
|
PRINT ();
|
||||||
|
|
||||||
|
PRINT ( "FORMAT$(\"%d %s\", 10, \"TEN\")" );
|
||||||
|
PRINT ( FORMAT$("%d %s",10, "TEN") );
|
||||||
|
|
||||||
|
|
||||||
ENDMAIN
|
ENDMAIN
|
||||||
|
23
runtime.inc
23
runtime.inc
@ -14,10 +14,33 @@ DECLARE FUNCTION CSTRING ENC$ (CSTRING,INT=34,INT=34);
|
|||||||
DECLARE FUNCTION CSTRING REVERSE$ (CSTRING);
|
DECLARE FUNCTION CSTRING REVERSE$ (CSTRING);
|
||||||
DECLARE FUNCTION CSTRING REPLACE$ (CSTRING subject, CONSTANT CSTRING& search, CONSTANT CSTRING& replace);
|
DECLARE FUNCTION CSTRING REPLACE$ (CSTRING subject, CONSTANT CSTRING& search, CONSTANT CSTRING& replace);
|
||||||
DECLARE FUNCTION INT VAL (CSTRING);
|
DECLARE FUNCTION INT VAL (CSTRING);
|
||||||
|
DECLARE FUNCTION CSTRING FORMAT$ (CONSTANT CSTRING &fmt, ...);
|
||||||
DECLARE SUB PRINT (CSTRING);
|
DECLARE SUB PRINT (CSTRING);
|
||||||
DECLARE SUB SAVEFILE(CSTRING src, CSTRING fname);
|
DECLARE SUB SAVEFILE(CSTRING src, CSTRING fname);
|
||||||
|
|
||||||
|
|
||||||
|
FUNCTION CSTRING FORMAT$ (CONSTANT CSTRING &fmt, ...) BEGIN
|
||||||
|
DIM AS VECTOR<char> str(100,'\0');
|
||||||
|
DIM AS va_list ap;
|
||||||
|
DIM AS INT n;
|
||||||
|
|
||||||
|
WHILE (TRUE) {
|
||||||
|
va_start(ap, fmt);
|
||||||
|
n = vsnprintf(str.data(), str.size(), fmt.c_str(), ap);
|
||||||
|
va_end(ap);
|
||||||
|
IF ((n > -1) AND (size_t(n) < str.size())) THEN
|
||||||
|
RETURN str.data();
|
||||||
|
ENDIF
|
||||||
|
IF (n > -1) THEN
|
||||||
|
str.resize( n + 1 );
|
||||||
|
ELSE
|
||||||
|
str.resize( str.size() * 2);
|
||||||
|
ENDIF
|
||||||
|
WEND
|
||||||
|
|
||||||
|
RETURN str.data();
|
||||||
|
ENDFUNCTION
|
||||||
|
|
||||||
FUNCTION CSTRING REVERSE$ (CSTRING src) BEGIN
|
FUNCTION CSTRING REVERSE$ (CSTRING src) BEGIN
|
||||||
RETURN CSTRING( src.rbegin(),src.rend() );
|
RETURN CSTRING( src.rbegin(),src.rend() );
|
||||||
ENDFUNCTION
|
ENDFUNCTION
|
||||||
|
Loading…
Reference in New Issue
Block a user