Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
0.23.3
Browse files Browse the repository at this point in the history
Variable list defragmentation
DEL can now delete multiple variables at a time
  • Loading branch information
PQCraft committed Oct 6, 2021
1 parent 2e6e605 commit 03da8b0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 30 deletions.
39 changes: 17 additions & 22 deletions clibasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@
#define swap(a, b) {__typeof__(a) c = a; a = b; b = c;}

/* Free & set to NULL combo */
#define nfree(ptr) free(ptr); ptr = NULL
#define nfree(ptr) {free(ptr); ptr = NULL;}

// Base defines

char VER[] = "0.23.2";
char VER[] = "0.23.3";

#if defined(__linux__)
char OSVER[] = "Linux";
Expand Down Expand Up @@ -167,14 +167,14 @@ int progLine = 1;
int varmaxct = 0;

typedef struct {
int32_t size;
bool inuse;
char* name;
uint8_t type;
int32_t size;
char** data;
} cb_var;

char** varname = NULL;
cb_var* vardata = NULL;
bool* varinuse = NULL;

char gpbuf[CB_BUF_SIZE];

Expand Down Expand Up @@ -1834,7 +1834,7 @@ uint8_t getVar(char* vn, char* varout) {
}
int v = -1;
for (register int i = 0; i < varmaxct; ++i) {
if (varinuse[i]) {if (!strcmp(vn, varname[i])) {v = i; break;}}
if (vardata[i].inuse) {if (!strcmp(vn, vardata[i].name)) {v = i; break;}}
}
if (v == -1) {
if (isArray) {
Expand Down Expand Up @@ -1912,28 +1912,25 @@ bool setVar(char* vn, char* val, uint8_t t, int32_t s) {
}
int v = -1;
for (register int i = 0; i < varmaxct; ++i) {
if (!strcmp(vn, varname[i])) {v = i; break;}
if (!strcmp(vn, vardata[i].name)) {v = i; break;}
}
if (v == -1) {
bool incmaxct = true;
if (isArray) {
cerr = 23;
seterrstr(vn);
return false;
}
for (register int i = 0; i < varmaxct; ++i) {
if (!varinuse[i]) {v = i; incmaxct = false; break;}
if (!vardata[i].inuse) {v = i; break;}
}
if (v == -1) v = varmaxct;
if (incmaxct) {
if (v == -1) {
v = varmaxct;
varmaxct++;
varname = (char**)realloc(varname, varmaxct * sizeof(char*));
vardata = (cb_var*)realloc(vardata, varmaxct * sizeof(cb_var));
varinuse = (bool*)realloc(varinuse, varmaxct * sizeof(bool));
}
varinuse[v] = true;
varname[v] = (char*)malloc(vnlen + 1);
copyStr(vn, varname[v]);
vardata[v].inuse = true;
vardata[v].name = (char*)malloc(vnlen + 1);
copyStr(vn, vardata[v].name);
vardata[v].size = s;
vardata[v].type = t;
if (s == -1) s = 0;
Expand Down Expand Up @@ -1982,20 +1979,18 @@ bool delVar(char* vn) {
}
int v = -1;
for (register int i = 0; i < varmaxct; ++i) {
if (!strcmp(vn, varname[i])) {v = i; break;}
if (!strcmp(vn, vardata[i].name)) {v = i; break;}
}
if (v != -1) {
varinuse[v] = false;
free(varname[v]);
vardata[v].inuse = false;
free(vardata[v].name);
for (int32_t i = 0; i <= vardata[v].size; ++i) {
free(vardata[v].data[i]);
}
free(vardata[v].data);
if (v == varmaxct - 1) {
while (!varinuse[v] && v >= 0) {varmaxct--; v--;}
varname = (char**)realloc(varname, varmaxct * sizeof(char*));
while (!vardata[v].inuse && v >= 0) {varmaxct--; v--;}
vardata = (cb_var*)realloc(vardata, varmaxct * sizeof(cb_var));
varinuse = (bool*)realloc(varinuse, varmaxct * sizeof(bool));
}
}
return true;
Expand Down
35 changes: 33 additions & 2 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,39 @@ if (chkCmd(1, "DIM")) {
}
if (chkCmd(1, "DEL")) {
cerr = 0;
if (argct != 1) {cerr = 3; goto cmderr;}
if (!delVar(tmpargs[1])) goto cmderr;
if (argct < 1) {cerr = 3; goto cmderr;}
for (int i = 1; i <= argct; ++i) {
if (!delVar(tmpargs[i])) goto cmderr;
}
goto noerr;
}
if (chkCmd(1, "DEFRAG")) {
cerr = 0;
if (argct > 0) {cerr = 3; goto cmderr;}
int vo = 0;
printf("OLD VARTABLE: [%d]\n", varmaxct);
for (register int i = 0; i < varmaxct; ++i) {
if (vardata[i].inuse) {
printf("[%d]: [%d],{%s},[%d],[%d],{0:{%s}}\n",\
i, vardata[i].inuse, vardata[i].name, vardata[i].type, vardata[i].size, vardata[i].data[0]);
} else {
printf("[%d]: [0]\n", i);
}
}
for (register int i = 0; i < varmaxct;) {
if (!vardata[i].inuse) {++vo; --varmaxct;}
else {++i;}
if (vo) {vardata[i] = vardata[i + vo];}
}
printf("NEW VARTABLE: [%d]\n", varmaxct);
for (register int i = 0; i < varmaxct; ++i) {
if (vardata[i].inuse) {
printf("[%d]: [%d],{%s},[%d],[%d],{0:{%s}}\n",\
i, vardata[i].inuse, vardata[i].name, vardata[i].type, vardata[i].size, vardata[i].data[0]);
} else {
printf("[%d]: [0]\n", i);
}
}
goto noerr;
}
if (chkCmd(1, "COLOR")) {
Expand Down
4 changes: 2 additions & 2 deletions commit.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
rel="Beta"
rev="Beta"
#-----
shopt -s extglob

Expand Down Expand Up @@ -45,7 +45,7 @@ echo "Pushing..."
git push

echo "Making release..."
gh release create "$ver" --notes "$(./release-text.sh)" *.zip
gh release create "$ver" --title "$rev $ver" --notes "$(./release-text.sh)" *.zip

echo "Updating AUR packages..."
cd .aur/
Expand Down
2 changes: 1 addition & 1 deletion docs
8 changes: 5 additions & 3 deletions examples/marquee.bas
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ direction$="L"
inplace=1
padding=8
delayms=95
colors=1
colors=0
bg=0
# ------------

if _argc()=0
ostr$=input$("Text: ")
locate ,-1
Expand All @@ -14,7 +14,7 @@ else
endif
_txtlock
if colors<>0
_txtattrib "truecolor",1
_txtattrib "truecolor"
oc=fgc()
r=cint(rand(255)):g=cint(rand(255)):b=cint(rand(255))
x=2:y=rand(0.5, 1):x=x-y:z=rand(0.5,1):x=x-z
Expand All @@ -35,7 +35,9 @@ do
resettimer
if colors<>0
color rgb(limit(r,0,255),limit(g,0,255),limit(b,0,255))
if bg<>0:_txtattrib "bgc":color ,rgb(255-limit(r,0,255),255-limit(g,0,255),255-limit(b,0,255)):endif
print "\r";snip$(str$,0,w);
if bg<>0:_txtattrib "bgc",0:endif
color oc
print
r=r+x
Expand Down

0 comments on commit 03da8b0

Please sign in to comment.