Skip to content

Commit 5669c0d

Browse files
committed
added threading pointers back into SupportTable so offsets still line up for other precompiled extensions. error reporting redir to vbStdOut if set, switched to snprintf in debugger.c
1 parent 55ad45b commit 5669c0d

File tree

17 files changed

+127
-50
lines changed

17 files changed

+127
-50
lines changed

Module1.bas

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ Public dbg_cmd As String
3939
Public running As Boolean
4040
Public variables As New Collection 'of CVariable
4141
Public callStack As New Collection 'of CCallStack
42+
Public flatFile As String
43+
Public hadError As Boolean
4244

4345
Public includeDir As String, moduleDir As String
44-
45-
Global fso As New CFileSystem2
4646
Global dlg As New CCmnDlg
47+
Global Const LANG_US = &H409
4748

4849
Enum cb_type
4950
cb_output = 0
5051
cb_dbgout = 1
5152
cb_debugger = 2
5253
cb_engine = 3
54+
cb_error = 4
5355
End Enum
5456

5557
Enum sb_VarTypes
@@ -67,15 +69,16 @@ Function LoadFlatFile() As Boolean
6769
Dim tmp As String
6870
Dim b() As Byte
6971

70-
tmp = fso.GetFreeFileName(Environ("temp"))
72+
tmp = GetFreeFileName(Environ("temp"))
7173
b() = StrConv(tmp & Chr(0), vbFromUnicode)
7274
dbg_WriteFlatSourceFile hDebugObject, b(0)
7375

74-
If fso.FileExists(tmp) Then
76+
If FileExists(tmp) Then
7577
Form1.hasImports = True
7678
Form1.scivb.ReadOnly = False
7779
LoadFlatFile = Form1.scivb.LoadFile(tmp)
7880
Form1.scivb.ReadOnly = True
81+
flatFile = tmp
7982
End If
8083

8184
End Function
@@ -318,8 +321,14 @@ Public Sub vb_stdout(ByVal t As cb_type, ByVal lpMsg As Long, ByVal sz As Long)
318321
Select Case t
319322
Case cb_debugger: HandleDebugMessage msg
320323
Case cb_engine: HandleEngineMessage msg
321-
Case Default:
324+
Case Else:
325+
If t = cb_error Then
326+
msg = "Error: " & IIf(Len(flatFile) > 0, flatFile, "") & vbCrLf & msg
327+
hadError = True
328+
End If
329+
322330
If t = cb_dbgout Then msg = "DBG> " & msg
331+
323332
With Form1.txtOut
324333
.Text = .Text & Replace(msg, vbLf, vbCrLf)
325334
.Refresh
@@ -336,9 +345,14 @@ Private Sub HandleEngineMessage(msg As String)
336345
tmp = Split(msg, ":")
337346
If tmp(0) = "ENGINE_PRECONFIG" Then
338347
hProgram = CLng(tmp(1))
348+
hadError = False
339349
ElseIf tmp(0) = "ENGINE_DESTROY" Then
340350
hProgram = 0
341351
hDebugObject = 0
352+
If Not hadError And FileExists(flatFile) Then
353+
Kill flatFile
354+
flatFile = Empty
355+
End If
342356
End If
343357

344358
End Sub

engine/dllmain.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void __stdcall SetCallBacks(void* lpfnMsgHandler, void* lpfnDbgHandler, void* lp
3636
vbHostResolver = (vbHostResolverCallback)lpfnHostResolver;
3737
}
3838

39-
int __stdcall GetErrorString(int iErrorCode, char* buf, int bufSz){
39+
int __stdcall GetErrorString(unsigned int iErrorCode, char* buf, int bufSz){
4040
#pragma EXPORT
4141
int sz = 0;
4242
if( iErrorCode >= MAX_ERROR_CODE ) iErrorCode = COMMAND_ERROR_EXTENSION_SPECIFIC;
@@ -50,7 +50,7 @@ int __stdcall run_script(char* fPath, int use_debugger)
5050
{
5151
#pragma EXPORT
5252

53-
int iError;
53+
int iError, iErrorCounter;
5454
char* cmdline = "";
5555
pSbProgram pProgram;
5656
char* buf[255];
@@ -62,16 +62,20 @@ int __stdcall run_script(char* fPath, int use_debugger)
6262
iError = scriba_LoadInternalPreprocessorByFunction(pProgram, "vb_dbg", &vb_dbg_preproc);
6363
if(iError != 0) goto cleanup;
6464
}
65-
66-
if( iError = scriba_LoadSourceProgram(pProgram) ) goto cleanup;
65+
66+
//build will call report error if syntax fail, these goto vbStdOut if set..
67+
if(scriba_LoadSourceProgram(pProgram) ) goto cleanup;
6768

6869
if(vbStdOut){
6970
sprintf(buf, "ENGINE_PRECONFIG:%d", pProgram);
7071
vbStdOut(cb_engine, buf, strlen(buf));
7172
}
7273

73-
if( iError = scriba_Run(pProgram,cmdline) ) goto cleanup;
74+
if( iError = scriba_Run(pProgram,cmdline) ){
75+
if( iError > 0 ) report_report(stderr,"",0,iError,REPORT_ERROR,NULL,NULL,NULL);
76+
goto cleanup;
7477

78+
}
7579

7680
cleanup:
7781
scriba_destroy(pProgram);

engine/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void main(int argc, char *argv[]){
3232
pProgram = scriba_new(NULL,NULL);
3333
//scriba_LoadConfiguration(pProgram, cfg); //optional
3434
//scriba_SetFileName(pProgram,"./scripts/hello.sb");
35-
scriba_SetFileName(pProgram,"./scripts/com_voice_test.sb");
35+
scriba_SetFileName(pProgram,"./scripts/hello.sb");
3636

3737
/*
3838
if( scriba_UseCacheFile(pProgram) == SCRIBA_ERROR_SUCCESS ){
@@ -58,8 +58,9 @@ void main(int argc, char *argv[]){
5858

5959
//iError = scriba_LoadInternalPreprocessorByFunction(pProgram, "sdbg", &sdbg_preproc);
6060

61-
if( scriba_LoadSourceProgram(pProgram) ){
61+
if( iError = scriba_LoadSourceProgram(pProgram) ){
6262
printf("failed to load source program!");
63+
report_report(stderr,"",0,iError,REPORT_ERROR,&iErrorCounter,NULL,&fErrorFlags);
6364
getch();
6465
exit(0);
6566
}

engine/preprocessors/vb_dbg/debugger.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ This program implements a simple debugger "preprocessor" for ScriptBasic.
3333
#include "debugger.h"
3434
#include "vb.h"
3535

36+
#define snprintf _snprintf
37+
3638
int LineNumberForNode(pDebuggerObject pDO, int node)
3739
{
3840
if( node < 1 || node > pDO->cNodes ) return 0;
@@ -46,31 +48,31 @@ void __stdcall dbg_EnumCallStack(pDebuggerObject pDO)
4648
pDebugCallStack_t p;
4749
pDebugCallStack_t np;
4850
pUserFunction_t uf;
49-
char buf[1024];
51+
char buf[1025];
5052
long i;
5153

5254
if( pDO == NULL )return;
5355

54-
sprintf(buf, "Call-Stack:%d:%s", LineNumberForNode(pDO,pDO->lPC), "CurrentLine");
56+
snprintf(buf, 1024, "Call-Stack:%d:%s", LineNumberForNode(pDO,pDO->lPC), "CurrentLine");
5557
vbStdOut(cb_debugger,buf,strlen(buf));
5658

5759
if( pDO->StackListPointer == NULL )return;
5860

5961
p = pDO->StackListPointer;
6062
if(p->pUF && p->pUF->pszFunctionName ){
61-
sprintf(buf, "Call-Stack:%d:%s", LineNumberForNode(pDO,p->Node), p->pUF->pszFunctionName);
63+
snprintf(buf, 1024, "Call-Stack:%d:%s", LineNumberForNode(pDO,p->Node), p->pUF->pszFunctionName);
6264
}else{
63-
sprintf(buf, "Call-Stack:%d:Unknown", LineNumberForNode(pDO,p->Node) );
65+
snprintf(buf, 1024, "Call-Stack:%d:Unknown", LineNumberForNode(pDO,p->Node) );
6466
}
6567
vbStdOut(cb_debugger,buf,strlen(buf));
6668

6769
for(i=0; i < pDO->CallStackDepth; i++){
6870
if(p->up == NULL) return;
6971
p = p->up;
7072
if(p->pUF && p->pUF->pszFunctionName ){
71-
sprintf(buf, "Call-Stack:%d:%s", LineNumberForNode(pDO,p->Node) , p->pUF->pszFunctionName);
73+
snprintf(buf, 1024, "Call-Stack:%d:%s", LineNumberForNode(pDO,p->Node) , p->pUF->pszFunctionName);
7274
}else{
73-
sprintf(buf, "Call-Stack:%d:Unknown", LineNumberForNode(pDO,p->Node));
75+
snprintf(buf, 1024, "Call-Stack:%d:Unknown", LineNumberForNode(pDO,p->Node));
7476
}
7577
vbStdOut(cb_debugger,buf,strlen(buf));
7678
}
@@ -235,12 +237,12 @@ CUT*/
235237
return 0;
236238
}
237239

238-
if( TYPE(v) == VTYPE_STRING ){
240+
if( TYPE(v) == VTYPE_STRING ){ //<-- it would be nice if this didnt err on to long string but just appended with ... to show more..
239241
/* calculate the printed size */
240242
r = v->Value.pValue;
241243
slen = 2; /* starting and ending " */
242244
i = 0;
243-
while( i < STRLEN(v) ){
245+
while( i < STRLEN(v) ){
244246
if( *r < 0x20 || *r > 0x7F ){
245247
slen += 4 ; /* \xXX */
246248
i++;
@@ -889,8 +891,6 @@ void __stdcall dbg_WriteFlatSourceFile(pDebuggerObject pDO, char* path)
889891
#pragma EXPORT
890892

891893
long j;
892-
char cBuffer[1024];
893-
int cbBuffer;
894894

895895
FILE *f = fopen(path, "wb");
896896
if(f==NULL) return;
@@ -915,9 +915,9 @@ command was executed successfully or that the command failed and why.
915915
*/
916916
void scomm_Message(pDebuggerObject pDO, char *pszMessage)
917917
{
918-
char cBuffer[200];
918+
char cBuffer[1025];
919919
int cbBuffer;
920-
sprintf(cBuffer,"Message: %s\r\n",pszMessage);
920+
snprintf(cBuffer,1024,"Message: %s\r\n",pszMessage);
921921
vbStdOut(cb_debugger, cBuffer, strlen(cBuffer));
922922
}
923923

@@ -1069,7 +1069,7 @@ void __stdcall dbg_EnumAryVarsByPointer(pDebuggerObject pDO, VARIABLE v)
10691069
VARIABLE v2=NULL;
10701070
int low, high, i;
10711071
unsigned long sz;
1072-
char cBuffer[2050];
1072+
char cBuffer[1111];
10731073
char buf[1025];
10741074

10751075
if(v==NULL) return;
@@ -1083,7 +1083,7 @@ void __stdcall dbg_EnumAryVarsByPointer(pDebuggerObject pDO, VARIABLE v)
10831083
if(v2 != NULL){
10841084
sz = 1024;
10851085
SPrintVariable(pDO, v2, buf, &sz);
1086-
sprintf(cBuffer,"Array-Variable:%d:%d:%s", i, TYPE(v2), buf);
1086+
snprintf(cBuffer,1110, "Array-Variable:%d:%d:%s", i, TYPE(v2), buf);
10871087
vbStdOut(cb_debugger, cBuffer, strlen(cBuffer));
10881088
}
10891089
}
@@ -1092,12 +1092,7 @@ void __stdcall dbg_EnumAryVarsByPointer(pDebuggerObject pDO, VARIABLE v)
10921092
void __stdcall dbg_EnumAryVarsByName(pDebuggerObject pDO, char* varName)
10931093
{
10941094
#pragma EXPORT
1095-
VARIABLE v, v2=NULL;
1096-
int low, high, i;
1097-
unsigned long sz;
1098-
char cBuffer[2050];
1099-
char buf[1025];
1100-
1095+
VARIABLE v;
11011096
v = dbg_VariableFromName(pDO, varName);
11021097
dbg_EnumAryVarsByPointer(pDO, v);
11031098
}
@@ -1115,7 +1110,7 @@ void __stdcall dbg_EnumVars(pDebuggerObject pDO)
11151110
for(i=0 ; i < pDO->cGlobalVariables ; i++ )
11161111
{
11171112
if( NULL == pDO->ppszGlobalVariables[i] )break;
1118-
sprintf(cBuffer,"Global-Variable-Name:%s",pDO->ppszGlobalVariables[i]);
1113+
snprintf(cBuffer,1024,"Global-Variable-Name:%s",pDO->ppszGlobalVariables[i]);
11191114
vbStdOut(cb_debugger, cBuffer, strlen(cBuffer));
11201115
}
11211116

@@ -1138,7 +1133,7 @@ void __stdcall dbg_EnumVars(pDebuggerObject pDO)
11381133
if( StackListPointer->LocalVariables ){
11391134
for(i=StackListPointer->LocalVariables->ArrayLowLimit ; i <= StackListPointer->LocalVariables->ArrayHighLimit ; i++ )
11401135
{
1141-
sprintf(cBuffer,"Local-Variable-Name:%s",pUF->ppszLocalVariables[i-1]);
1136+
snprintf(cBuffer,1024,"Local-Variable-Name:%s",pUF->ppszLocalVariables[i-1]);
11421137
vbStdOut(cb_debugger, cBuffer, strlen(cBuffer));
11431138
}
11441139
}

engine/sb/include/basext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ typedef struct _SupportTable {
478478
#define besMatchSize(P1,P2,P3,P4,P5)\
479479
(pSt->match_size((P1),(P2),(P3),(P4),(P5)))
480480

481+
void* thread_CreateThread; //these were readded to keep struct layout the same they are null though..
482+
void* thread_ExitThread;
483+
481484
void (*thread_InitMutex)(PMUTEX pMutex);
482485
#define besInitMutex(X) (pSt->thread_InitMutex(X))
483486

engine/sb/include/vb.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ typedef enum{
99
cb_output=0,
1010
cb_dbgout = 1,
1111
cb_debugger = 2,
12-
cb_engine = 3
12+
cb_engine = 3,
13+
cb_error = 4
1314
} cb_type;
1415

1516
//Public Sub vb_stdout(ByVal t As cb_type, ByVal lpMsg As Long, ByVal sz As Long)

engine/sb/modumana.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ CUT*/
218218
pEo->pST->match_parameter = match_parameter;
219219
pEo->pST->match_size = match_size;
220220

221+
pEo->pST->thread_CreateThread = NULL;
222+
pEo->pST->thread_ExitThread = NULL;
221223
pEo->pST->thread_InitMutex = thread_InitMutex;
222224
pEo->pST->thread_FinishMutex = thread_FinishMutex;
223225
pEo->pST->thread_LockMutex = thread_LockMutex;

engine/sb/report.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ enum {
5353

5454
#include "report.h"
5555
#include "errcodes.h"
56+
#include "vb.h"
57+
58+
#define snprintf _snprintf
5659

5760
/*POD
5861
@@ -119,26 +122,32 @@ Other bits are reserved for later use.
119122
=noitemize
120123
CUT*/
121124

122-
if( ((*fFlags) & REPORT_F_CGI) && !((*fFlags) & REPORT_F_FRST) ){
125+
char tmp[524]={0};
126+
127+
/*if( ((*fFlags) & REPORT_F_CGI) && !((*fFlags) & REPORT_F_FRST) ){
123128
fprintf((FILE *)filepointer,"Status: 200 OK\nContent-Type: text/html\n\n"
124129
"<HTML><HEAD>\n"
125130
"<title>Error page, syntax error</title>\n"
126131
"</HEAD><BODY>\n"
127132
"<H1>Error has happened in the code</H1>"
128133
"<pre>\n");
129-
}
134+
}*/
130135

131136
if( szErrorString && strlen(szErrorString) > 80 )szErrorString[79] = (char)0;
132-
133137
if( iErrorSeverity >= REPORT_ERROR && piErrorCounter )(*piErrorCounter)++;
134-
135-
if( FileName )fprintf((FILE*)filepointer,"%s(%ld):",FileName,LineNumber);
136-
fprintf((FILE *)filepointer,(iErrorCode < MAX_ERROR_CODE ? " error &H%x:" : " error 0x%08x:"),iErrorCode);
138+
if( FileName && strlen(FileName) > 0) snprintf(tmp, 300, "File: %s\n",FileName);
139+
if( LineNumber > 0) snprintf(tmp+strlen(tmp), 320, "Line: %d",LineNumber);
140+
141+
snprintf(tmp+strlen(tmp), 400, (iErrorCode < MAX_ERROR_CODE ? " error &H%x: " : " error 0x%08x: "),iErrorCode);
137142
if( iErrorCode >= MAX_ERROR_CODE )iErrorCode = COMMAND_ERROR_EXTENSION_SPECIFIC;
138143
if( szErrorString ){
139-
fprintf((FILE*)filepointer,en_error_messages[iErrorCode],szErrorString);
140-
fprintf((FILE*)filepointer,"\n");
141-
}else
142-
fprintf((FILE *)filepointer,"%s\n",en_error_messages[iErrorCode]);
143-
*fFlags |= REPORT_F_FRST;
144+
snprintf(tmp+strlen(tmp), 500, en_error_messages[iErrorCode], szErrorString);
145+
strcat(tmp,"\n");
144146
}
147+
else snprintf(tmp+strlen(tmp), 500, "%s\n",en_error_messages[iErrorCode]);
148+
149+
if(vbStdOut != NULL) vbStdOut(cb_error, tmp, strlen(tmp));
150+
else fprintf((FILE*)filepointer,"%s",tmp);
151+
152+
*fFlags |= REPORT_F_FRST;
153+
}

engine/sb_engine.dll

512 Bytes
Binary file not shown.

engine/scripts/hello.sb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare sub trial alias "trial" lib "test.exe"
1+
'declare sub trial alias "trial" lib "test.exe"
22

33
a = 1
44
b = 2

0 commit comments

Comments
 (0)