-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #567 from QB64-Phoenix-Edition/pcflags-tostr-refactor
Pcflags tostr refactor
- Loading branch information
Showing
733 changed files
with
230,063 additions
and
228,867 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
|
||
#include "libqb-common.h" | ||
|
||
#include <inttypes.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "error_handle.h" | ||
#include "qbs.h" | ||
|
||
// modern _TOSTR() functions (no leading space and no QB4.5 compatible rounding) | ||
// signed integers | ||
qbs *qbs__tostr(int64_t value, int32_t digits, int32_t passed) { | ||
qbs *tqbs = qbs_new(32, 1); | ||
tqbs->len = snprintf((char *)tqbs->chr, 32, "%" PRId64, value); | ||
if (tqbs->len < 0 || tqbs->len >= 32) { | ||
error(QB_ERROR_INTERNAL_ERROR); | ||
tqbs->len = 0; | ||
} | ||
return tqbs; | ||
} | ||
qbs *qbs__tostr(int32_t value, int32_t digits, int32_t passed) { | ||
qbs *tqbs = qbs_new(32, 1); | ||
tqbs->len = snprintf((char *)tqbs->chr, 32, "%i", value); | ||
if (tqbs->len < 0 || tqbs->len >= 32) { | ||
error(QB_ERROR_INTERNAL_ERROR); | ||
tqbs->len = 0; | ||
} | ||
return tqbs; | ||
} | ||
qbs *qbs__tostr(int16_t value, int32_t digits, int32_t passed) { | ||
qbs *tqbs = qbs_new(32, 1); | ||
tqbs->len = snprintf((char *)tqbs->chr, 32, "%i", value); | ||
if (tqbs->len < 0 || tqbs->len >= 32) { | ||
error(QB_ERROR_INTERNAL_ERROR); | ||
tqbs->len = 0; | ||
} | ||
return tqbs; | ||
} | ||
qbs *qbs__tostr(int8_t value, int32_t digits, int32_t passed) { | ||
qbs *tqbs = qbs_new(32, 1); | ||
tqbs->len = snprintf((char *)tqbs->chr, 32, "%i", value); | ||
if (tqbs->len < 0 || tqbs->len >= 32) { | ||
error(QB_ERROR_INTERNAL_ERROR); | ||
tqbs->len = 0; | ||
} | ||
return tqbs; | ||
} | ||
// unsigned integers | ||
qbs *qbs__tostr(uint64_t value, int32_t digits, int32_t passed) { | ||
qbs *tqbs = qbs_new(32, 1); | ||
tqbs->len = snprintf((char *)tqbs->chr, 32, "%" PRIu64, value); | ||
if (tqbs->len < 0 || tqbs->len >= 32) { | ||
error(QB_ERROR_INTERNAL_ERROR); | ||
tqbs->len = 0; | ||
} | ||
return tqbs; | ||
} | ||
qbs *qbs__tostr(uint32_t value, int32_t digits, int32_t passed) { | ||
qbs *tqbs = qbs_new(32, 1); | ||
tqbs->len = snprintf((char *)tqbs->chr, 32, "%u", value); | ||
if (tqbs->len < 0 || tqbs->len >= 32) { | ||
error(QB_ERROR_INTERNAL_ERROR); | ||
tqbs->len = 0; | ||
} | ||
return tqbs; | ||
} | ||
qbs *qbs__tostr(uint16_t value, int32_t digits, int32_t passed) { | ||
qbs *tqbs = qbs_new(32, 1); | ||
tqbs->len = snprintf((char *)tqbs->chr, 32, "%u", value); | ||
if (tqbs->len < 0 || tqbs->len >= 32) { | ||
error(QB_ERROR_INTERNAL_ERROR); | ||
tqbs->len = 0; | ||
} | ||
return tqbs; | ||
} | ||
qbs *qbs__tostr(uint8_t value, int32_t digits, int32_t passed) { | ||
qbs *tqbs = qbs_new(32, 1); | ||
tqbs->len = snprintf((char *)tqbs->chr, 32, "%u", value); | ||
if (tqbs->len < 0 || tqbs->len >= 32) { | ||
error(QB_ERROR_INTERNAL_ERROR); | ||
tqbs->len = 0; | ||
} | ||
return tqbs; | ||
} | ||
// floating points | ||
qbs *qbs__tostr(float value, int32_t digits, int32_t passed) { | ||
if (passed) { | ||
if (digits < 0) { | ||
error(QB_ERROR_ILLEGAL_FUNCTION_CALL); | ||
return qbs_new_txt(""); | ||
} | ||
if (digits < 1) digits = 1; | ||
if (digits > 7) digits = 7; | ||
} else { | ||
digits = 7; | ||
} | ||
qbs *tqbs = qbs_new(32, 1); | ||
tqbs->len = snprintf((char *)tqbs->chr, 32, "%.*G", digits, value); | ||
if (tqbs->len < 0 || tqbs->len >= 32) { | ||
error(QB_ERROR_INTERNAL_ERROR); | ||
tqbs->len = 0; | ||
} | ||
return tqbs; | ||
} | ||
qbs *qbs__tostr(double value, int32_t digits, int32_t passed) { | ||
if (passed) { | ||
if (digits < 0) { | ||
error(QB_ERROR_ILLEGAL_FUNCTION_CALL); | ||
return qbs_new_txt(""); | ||
} | ||
if (digits < 1) digits = 1; | ||
if (digits > 16) digits = 16; | ||
} else { | ||
digits = 16; | ||
} | ||
qbs *tqbs = qbs_new(32, 1); | ||
tqbs->len = snprintf((char *)tqbs->chr, 32, "%.*G", digits, value); | ||
if (tqbs->len < 0 || tqbs->len >= 32) { | ||
error(QB_ERROR_INTERNAL_ERROR); | ||
tqbs->len = 0; | ||
} else { | ||
char *ex = strrchr((char*)tqbs->chr, (int)'E'); | ||
if (ex != NULL) ex[0] = 'D'; | ||
} | ||
return tqbs; | ||
} | ||
qbs *qbs__tostr(long double value, int32_t digits, int32_t passed) { | ||
if (passed) { | ||
if (digits < 0) { | ||
error(QB_ERROR_ILLEGAL_FUNCTION_CALL); | ||
return qbs_new_txt(""); | ||
} | ||
if (digits < 1) digits = 1; | ||
if (digits > 19) digits = 19; | ||
} else { | ||
digits = 19; | ||
} | ||
qbs *tqbs = qbs_new(32, 1); | ||
#ifdef QB64_MINGW | ||
tqbs->len = __mingw_snprintf((char *)tqbs->chr, 32, "%.*LG", digits, value); | ||
#else | ||
tqbs->len = snprintf((char *)tqbs->chr, 32, "%.*LG", digits, value); | ||
#endif | ||
if (tqbs->len < 0 || tqbs->len >= 32) { | ||
error(QB_ERROR_INTERNAL_ERROR); | ||
tqbs->len = 0; | ||
} else { | ||
char *ex = strrchr((char*)tqbs->chr, (int)'E'); | ||
if (ex != NULL) ex[0] = 'F'; | ||
} | ||
return tqbs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
qbs *_FUNC_GETPREVELEMENT_STRING_GETPREVELEMENT=NULL; | ||
if (!_FUNC_GETPREVELEMENT_STRING_GETPREVELEMENT)_FUNC_GETPREVELEMENT_STRING_GETPREVELEMENT=qbs_new(0,0); | ||
qbs*oldstr3709=NULL; | ||
qbs*oldstr3714=NULL; | ||
if(_FUNC_GETPREVELEMENT_STRING_A->tmp||_FUNC_GETPREVELEMENT_STRING_A->fixed||_FUNC_GETPREVELEMENT_STRING_A->readonly){ | ||
oldstr3709=_FUNC_GETPREVELEMENT_STRING_A; | ||
if (oldstr3709->cmem_descriptor){ | ||
_FUNC_GETPREVELEMENT_STRING_A=qbs_new_cmem(oldstr3709->len,0); | ||
oldstr3714=_FUNC_GETPREVELEMENT_STRING_A; | ||
if (oldstr3714->cmem_descriptor){ | ||
_FUNC_GETPREVELEMENT_STRING_A=qbs_new_cmem(oldstr3714->len,0); | ||
}else{ | ||
_FUNC_GETPREVELEMENT_STRING_A=qbs_new(oldstr3709->len,0); | ||
_FUNC_GETPREVELEMENT_STRING_A=qbs_new(oldstr3714->len,0); | ||
} | ||
memcpy(_FUNC_GETPREVELEMENT_STRING_A->chr,oldstr3709->chr,oldstr3709->len); | ||
memcpy(_FUNC_GETPREVELEMENT_STRING_A->chr,oldstr3714->chr,oldstr3714->len); | ||
} | ||
int32 *_FUNC_GETPREVELEMENT_LONG_I=NULL; | ||
if(_FUNC_GETPREVELEMENT_LONG_I==NULL){ | ||
_FUNC_GETPREVELEMENT_LONG_I=(int32*)mem_static_malloc(4); | ||
*_FUNC_GETPREVELEMENT_LONG_I=0; | ||
} | ||
byte_element_struct *byte_element_3710=NULL; | ||
if (!byte_element_3710){ | ||
if ((mem_static_pointer+=12)<mem_static_limit) byte_element_3710=(byte_element_struct*)(mem_static_pointer-12); else byte_element_3710=(byte_element_struct*)mem_static_malloc(12); | ||
byte_element_struct *byte_element_3715=NULL; | ||
if (!byte_element_3715){ | ||
if ((mem_static_pointer+=12)<mem_static_limit) byte_element_3715=(byte_element_struct*)(mem_static_pointer-12); else byte_element_3715=(byte_element_struct*)mem_static_malloc(12); | ||
} |
Oops, something went wrong.