source: tol/vbtol/source/vbtol.cpp @ 6d7779d

1941-docker-image-to-testdevel
Last change on this file since 6d7779d was 6d7779d, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

initial import

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/* VBTol.cpp: This file implements a Visual Basic interface to Tol.
2               GNU/tolTcl Library
3
4   Copyright (C) 2001, 2002, 2003 - Bayes Decisión, SL
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19   USA.
20 */
21
22#include <windows.h>
23#include <config.h>
24#include <tol_init.h>
25#include <tol_bout.h>
26#include <tol_list.h>
27
28#include "VButils.h"
29
30class BList;
31
32static BList VB_stack;
33
34/*
35 *  Decompile all Tol objects
36 *
37 *  returns 1 if there was some object to be decompiled, otherwise returns 0
38 */
39//---------------------------------------------------------------------------
40short __declspec(dllexport) CALLBACK TolDecompileAll()
41//---------------------------------------------------------------------------
42{
43  BList *P = VB_stack.Cdr();
44  short ret = P!=NULL;
45 
46  while (P) {
47    BSyntaxObject * so = (BSyntaxObject*)(P->Car());
48        VB_stack.PutCdr(P->Cdr());
49    delete P;
50    DESTROY(so);
51        P = VB_stack.Cdr();
52  }
53  return ret;
54}
55
56/*
57 *  Decompile a Tol object
58 *
59 *  name - string that contains the name of the object
60 *
61 *  returns 1 if an object whith that name was found and decompiled, otherwise returns 0
62 */
63//---------------------------------------------------------------------------
64short __declspec(dllexport) CALLBACK TolDecompile(BSTR name)
65//---------------------------------------------------------------------------
66{
67  LPSTR str_name = (LPSTR)name;
68  BList *P = VB_stack.Cdr(), *prev = &VB_stack;
69  short found = 0;
70 
71  while (!found && P) {
72    BSyntaxObject * so = (BSyntaxObject*)(P->Car());
73    const char* object_name = so->Name().String();
74    if (!strcmp(object_name, str_name)) {
75          prev->PutCdr(P->Cdr());
76      delete P;
77      DESTROY(so);
78      found = 1;
79          break;
80    }
81        prev = P;
82    P = P->Cdr();
83  }
84  return found;
85}
86
87static void VB_concat(BList* head, BList* tail)
88{
89  if (head->Cdr()) {
90    VB_concat(head->Cdr(), tail);
91  }
92  else {
93    head->PutCdr(tail);
94  }
95}
96
97int VBTol_EvalExpr(char * expr, short* nerror, short* nwarning)
98{
99  BList * tol_result;
100
101  BDat& bderror = TOLErrorNumber();
102  BDat& bdwarning = TOLWarningNumber();
103
104  *nerror = (int)(bderror.Value());
105  *nwarning = (int)(bdwarning.Value());
106  tol_result = MultyEvaluate(expr);
107  *nerror = (int)(bderror.Value()) - *nerror;
108  *nwarning = (int)(bdwarning.Value()) - *nwarning;
109  if (tol_result) {
110    VB_concat(&VB_stack, tol_result);
111    return 1;
112  }
113  return 0;
114}
115
116/*
117 *  Evaluates a Tol expresion
118 *
119 *  expr - string that contains the expresion
120 *
121 *  returns 1 if an object was created by the evaluation, otherwise 0
122 */
123//---------------------------------------------------------------------------
124short __declspec(dllexport) CALLBACK TolEval(BSTR expr, short* nerror, short* nwarning)
125//---------------------------------------------------------------------------
126{
127  LPSTR str_expr;
128
129  str_expr = (LPSTR)expr;    // The address is coerced into an LPSTR.
130
131  return VBTol_EvalExpr(str_expr, nerror, nwarning);
132}
133
134void VBTol_InstallHciWriter()
135{
136  BOut::PutHciWriter(VBTol_HciWriter);
137  BOut::PutLogHciWriter(VBTol_HciWriter);
138}
139
140/*
141 * Initialize TOL
142 *
143 * addr - the address of a Visual Basic function that will catch all the Tol output
144 * vmode - VerboseMode
145 */
146//---------------------------------------------------------------------------
147void __declspec(dllexport) CALLBACK TolInit(long addr, BSTR vmode)
148//---------------------------------------------------------------------------
149{
150  VB_Writer = (FN_PTR)addr;
151
152  VBTol_InstallHciWriter();
153
154  Tol_gsl_set_error_handler(&VBTol_gsl_error_handler);
155
156  LPSTR str_vmode;
157  str_vmode = (LPSTR)vmode;
158  InitTolKernel(0, str_vmode);
159
160  LoadInitLibrary(NULL);
161}
162
163// VC++ DLL entry point routine. Called during certain system events.
164
165//---------------------------------------------------------------------------
166BOOL APIENTRY DllMain(HANDLE hModule,
167                      DWORD  ul_reason_for_call,
168                      LPVOID lpReserved
169                                         )
170//---------------------------------------------------------------------------
171{
172  switch(ul_reason_for_call) {
173        case DLL_PROCESS_ATTACH:
174//        ::MessageBox(NULL, "Initializing the DLL.", "C++ DLL", 0);
175          break;
176        case DLL_PROCESS_DETACH:
177//        ::MessageBox(NULL, "Closing down the DLL.", "C++ DLL", 0);
178          break;
179  }
180  return TRUE;
181}
Note: See TracBrowser for help on using the repository browser.