Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pcflags tostr refactor #567

Merged
merged 12 commits into from
Nov 18, 2024
Merged
  •  
  •  
  •  
1 change: 1 addition & 0 deletions internal/c/libqb/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ libqb-objs-y += $(PATH_LIBQB)/src/math.o
libqb-objs-y += $(PATH_LIBQB)/src/shell.o
libqb-objs-y += $(PATH_LIBQB)/src/qbs.o
libqb-objs-y += $(PATH_LIBQB)/src/qbs_str.o
libqb-objs-y += $(PATH_LIBQB)/src/qbs__tostr.o
libqb-objs-y += $(PATH_LIBQB)/src/qbs_cmem.o
libqb-objs-y += $(PATH_LIBQB)/src/qbs_mk_cv.o
libqb-objs-y += $(PATH_LIBQB)/src/string_functions.o
Expand Down
14 changes: 14 additions & 0 deletions internal/c/libqb/include/qbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ qbs *qbs_set(qbs *, qbs *);

void qbs_free(qbs *str);

// legacy STR$ function prototypes
qbs *qbs_str(int64_t value);
qbs *qbs_str(int32_t value);
qbs *qbs_str(int16_t value);
Expand All @@ -52,6 +53,19 @@ qbs *qbs_str(float value);
qbs *qbs_str(double value);
qbs *qbs_str(long double value);

// modern _TOSTR$ function prototypes
qbs *qbs__tostr(int64_t value, int32_t digits, int32_t passed);
qbs *qbs__tostr(int32_t value, int32_t digits, int32_t passed);
qbs *qbs__tostr(int16_t value, int32_t digits, int32_t passed);
qbs *qbs__tostr(int8_t value, int32_t digits, int32_t passed);
qbs *qbs__tostr(uint64_t value, int32_t digits, int32_t passed);
qbs *qbs__tostr(uint32_t value, int32_t digits, int32_t passed);
qbs *qbs__tostr(uint16_t value, int32_t digits, int32_t passed);
qbs *qbs__tostr(uint8_t value, int32_t digits, int32_t passed);
qbs *qbs__tostr(float value, int32_t digits, int32_t passed);
qbs *qbs__tostr(double value, int32_t digits, int32_t passed);
qbs *qbs__tostr(long double value, int32_t digits, int32_t passed);

qbs *func_chr(int32_t value);

qbs *qbs_ucase(qbs *str);
Expand Down
154 changes: 154 additions & 0 deletions internal/c/libqb/src/qbs__tostr.cpp
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;
}
26 changes: 9 additions & 17 deletions internal/source/clear.txt
Original file line number Diff line number Diff line change
Expand Up @@ -956,21 +956,10 @@ __STRING_IDECUSTOMFONTFILE->len=0;
*__LONG_IDERUNMODE=0;
*__BYTE_IDE_USEFONT8=0;
*__INTEGER_NOEXESAVED=0;
*__LONG_COLORSET=0;
*__LONG_COLORRECOMPILEATTEMPTS=0;
*__LONG_COLORSETDESIRED=0;
*__LONG_VWATCHON=0;
*__LONG_VWATCHRECOMPILEATTEMPTS=0;
*__LONG_VWATCHDESIREDSTATE=0;
__STRING_VWATCHERRORCALL->len=0;
__STRING_VWATCHNEWVARIABLE->len=0;
__STRING_VWATCHVARIABLEEXCLUSIONS->len=0;
__STRING_NATIVEDATATYPES->len=0;
*__LONG_OPEX_RECOMPILEATTEMPTS=0;
*__LONG_OPEX_DESIREDSTATE=0;
*__LONG_OPEX_FORCEDSTATE=0;
*__LONG_OPEXARRAY_RECOMPILEATTEMPTS=0;
*__LONG_OPEXARRAY_DESIREDSTATE=0;
if (__ARRAY_LONG_EVERYCASESET[2]&1){
if (__ARRAY_LONG_EVERYCASESET[2]&2){
memset((void*)(__ARRAY_LONG_EVERYCASESET[0]),0,__ARRAY_LONG_EVERYCASESET[5]*4);
Expand Down Expand Up @@ -1173,10 +1162,15 @@ __STRING_VIPRODUCTNAME->len=0;
__STRING_VIPRODUCTVERSION->len=0;
__STRING_VICOMMENTS->len=0;
__STRING_VIWEB->len=0;
memset((void*)__UDT_COLORSET,0,4);
memset((void*)__UDT_OPTEXPL,0,4);
memset((void*)__UDT_OPTEXPLARR,0,4);
memset((void*)__UDT_ASSERTSON,0,4);
memset((void*)__UDT_CONSOLEON,0,4);
memset((void*)__UDT_VWATCHON,0,4);
memset((void*)__UDT_SOCKDEPON,0,4);
*__LONG_CHECKINGON=0;
*__LONG_CONSOLEON=0;
*__LONG_SCREENHIDEON=0;
*__LONG_ASSERTSON=0;
*__LONG_RESIZEON=0;
*__LONG_RESIZESCALE=0;
*__LONG_OPTMAX=0;
Expand Down Expand Up @@ -1534,9 +1528,7 @@ __STRING_IDERETURN->len=0;
*__LONG_IDEMODE=0;
*__LONG_IDEERRORLINE=0;
__STRING_IDEMESSAGE->len=0;
*__BYTE_OPTIONEXPLICIT=0;
*__BYTE_OPTIONEXPLICITARRAY=0;
*__BYTE_OPTIONEXPLICIT_CMD=0;
*__BYTE_FORCEOPTEXPL=0;
*__LONG_IDESTARTATLINE=0;
*__LONG_ERRORLINEININCLUDE=0;
*__LONG_WARNINGININCLUDE=0;
Expand Down Expand Up @@ -2619,8 +2611,8 @@ __ARRAY_STRING_WARNINGINCFILES[0]=(ptrszint)&nothingstring;
*__LONG_FORMATBUF=0;
*__LONG_GLOBTXTBUF=0;
*__LONG_IDERECOMPILE=0;
__STRING_LINEBACKUP->len=0;
*__LONG_NUL=0;
__STRING_LINEBACKUP->len=0;
__STRING_WHOLESTV->len=0;
__STRING_TEMP->len=0;
*__LONG_TEMP=0;
Expand Down
32 changes: 16 additions & 16 deletions internal/source/data1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ if(_FUNC_PARSECMDLINEARGS_LONG_I==NULL){
_FUNC_PARSECMDLINEARGS_LONG_I=(int32*)mem_static_malloc(4);
*_FUNC_PARSECMDLINEARGS_LONG_I=0;
}
int64 fornext_value2202;
int64 fornext_finalvalue2202;
int64 fornext_step2202;
uint8 fornext_step_negative2202;
int64 fornext_value2206;
int64 fornext_finalvalue2206;
int64 fornext_step2206;
uint8 fornext_step_negative2206;
qbs *_FUNC_PARSECMDLINEARGS_STRING_TOKEN=NULL;
if (!_FUNC_PARSECMDLINEARGS_STRING_TOKEN)_FUNC_PARSECMDLINEARGS_STRING_TOKEN=qbs_new(0,0);
static qbs *sc_2203=qbs_new(0,0);
static qbs *sc_2207=qbs_new(0,0);
int32 *_FUNC_PARSECMDLINEARGS_LONG_CMDLINESWITCH=NULL;
if(_FUNC_PARSECMDLINEARGS_LONG_CMDLINESWITCH==NULL){
_FUNC_PARSECMDLINEARGS_LONG_CMDLINESWITCH=(int32*)mem_static_malloc(4);
Expand All @@ -22,20 +22,20 @@ if(_FUNC_PARSECMDLINEARGS_LONG_SETTINGSMODE==NULL){
_FUNC_PARSECMDLINEARGS_LONG_SETTINGSMODE=(int32*)mem_static_malloc(4);
*_FUNC_PARSECMDLINEARGS_LONG_SETTINGSMODE=0;
}
static qbs *sc_2231=qbs_new(0,0);
static qbs *sc_2235=qbs_new(0,0);
qbs *_FUNC_PARSECMDLINEARGS_STRING_DEBUGINFOINIWARNING=NULL;
if (!_FUNC_PARSECMDLINEARGS_STRING_DEBUGINFOINIWARNING)_FUNC_PARSECMDLINEARGS_STRING_DEBUGINFOINIWARNING=qbs_new(0,0);
int32 pass2247;
int32 pass2249;
int32 pass2255;
static qbs *sc_2256=qbs_new(0,0);
int32 pass2251;
int32 pass2253;
int32 pass2259;
static qbs *sc_2260=qbs_new(0,0);
qbs *_FUNC_PARSECMDLINEARGS_STRING_PASSEDFILENAME=NULL;
if (!_FUNC_PARSECMDLINEARGS_STRING_PASSEDFILENAME)_FUNC_PARSECMDLINEARGS_STRING_PASSEDFILENAME=qbs_new(0,0);
byte_element_struct *byte_element_2257=NULL;
if (!byte_element_2257){
if ((mem_static_pointer+=12)<mem_static_limit) byte_element_2257=(byte_element_struct*)(mem_static_pointer-12); else byte_element_2257=(byte_element_struct*)mem_static_malloc(12);
byte_element_struct *byte_element_2261=NULL;
if (!byte_element_2261){
if ((mem_static_pointer+=12)<mem_static_limit) byte_element_2261=(byte_element_struct*)(mem_static_pointer-12); else byte_element_2261=(byte_element_struct*)mem_static_malloc(12);
}
byte_element_struct *byte_element_2259=NULL;
if (!byte_element_2259){
if ((mem_static_pointer+=12)<mem_static_limit) byte_element_2259=(byte_element_struct*)(mem_static_pointer-12); else byte_element_2259=(byte_element_struct*)mem_static_malloc(12);
byte_element_struct *byte_element_2263=NULL;
if (!byte_element_2263){
if ((mem_static_pointer+=12)<mem_static_limit) byte_element_2263=(byte_element_struct*)(mem_static_pointer-12); else byte_element_2263=(byte_element_struct*)mem_static_malloc(12);
}
28 changes: 14 additions & 14 deletions internal/source/data10.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
qbs*oldstr2383=NULL;
qbs*oldstr2387=NULL;
if(_SUB_ASSIGN_STRING_A->tmp||_SUB_ASSIGN_STRING_A->fixed||_SUB_ASSIGN_STRING_A->readonly){
oldstr2383=_SUB_ASSIGN_STRING_A;
if (oldstr2383->cmem_descriptor){
_SUB_ASSIGN_STRING_A=qbs_new_cmem(oldstr2383->len,0);
oldstr2387=_SUB_ASSIGN_STRING_A;
if (oldstr2387->cmem_descriptor){
_SUB_ASSIGN_STRING_A=qbs_new_cmem(oldstr2387->len,0);
}else{
_SUB_ASSIGN_STRING_A=qbs_new(oldstr2383->len,0);
_SUB_ASSIGN_STRING_A=qbs_new(oldstr2387->len,0);
}
memcpy(_SUB_ASSIGN_STRING_A->chr,oldstr2383->chr,oldstr2383->len);
memcpy(_SUB_ASSIGN_STRING_A->chr,oldstr2387->chr,oldstr2387->len);
}
int32 *_SUB_ASSIGN_LONG_I=NULL;
if(_SUB_ASSIGN_LONG_I==NULL){
_SUB_ASSIGN_LONG_I=(int32*)mem_static_malloc(4);
*_SUB_ASSIGN_LONG_I=0;
}
int64 fornext_value2385;
int64 fornext_finalvalue2385;
int64 fornext_step2385;
uint8 fornext_step_negative2385;
int64 fornext_value2389;
int64 fornext_finalvalue2389;
int64 fornext_step2389;
uint8 fornext_step_negative2389;
int32 *_SUB_ASSIGN_LONG_C=NULL;
if(_SUB_ASSIGN_LONG_C==NULL){
_SUB_ASSIGN_LONG_C=(int32*)mem_static_malloc(4);
Expand All @@ -29,8 +29,8 @@ _SUB_ASSIGN_LONG_B=(int32*)mem_static_malloc(4);
}
qbs *_SUB_ASSIGN_STRING_A2=NULL;
if (!_SUB_ASSIGN_STRING_A2)_SUB_ASSIGN_STRING_A2=qbs_new(0,0);
int32 pass2386;
int32 pass2387;
int32 pass2390;
int32 pass2391;
qbs *_SUB_ASSIGN_STRING_L=NULL;
if (!_SUB_ASSIGN_STRING_L)_SUB_ASSIGN_STRING_L=qbs_new(0,0);
int32 *_SUB_ASSIGN_LONG_TRY=NULL;
Expand All @@ -43,5 +43,5 @@ if(_SUB_ASSIGN_LONG_TYP==NULL){
_SUB_ASSIGN_LONG_TYP=(int32*)mem_static_malloc(4);
*_SUB_ASSIGN_LONG_TYP=0;
}
int32 pass2389;
int32 pass2390;
int32 pass2393;
int32 pass2394;
18 changes: 9 additions & 9 deletions internal/source/data100.txt
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);
}
Loading