summaryrefslogtreecommitdiffstats
path: root/src/CBot/old TstCBot/TstCBotView.cpp
diff options
context:
space:
mode:
authoradiblol <adiblol@1tbps.org>2012-03-08 19:32:05 +0100
committeradiblol <adiblol@1tbps.org>2012-03-08 19:32:05 +0100
commita4c804b49ec872b71bd5a0167c3ad45704a3cc30 (patch)
tree8c931235247d662ca46a99695beb328fdfc8e8a8 /src/CBot/old TstCBot/TstCBotView.cpp
downloadcolobot-a4c804b49ec872b71bd5a0167c3ad45704a3cc30.tar.gz
colobot-a4c804b49ec872b71bd5a0167c3ad45704a3cc30.tar.bz2
colobot-a4c804b49ec872b71bd5a0167c3ad45704a3cc30.zip
Initial commit, Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
Diffstat (limited to 'src/CBot/old TstCBot/TstCBotView.cpp')
-rw-r--r--src/CBot/old TstCBot/TstCBotView.cpp291
1 files changed, 291 insertions, 0 deletions
diff --git a/src/CBot/old TstCBot/TstCBotView.cpp b/src/CBot/old TstCBot/TstCBotView.cpp
new file mode 100644
index 0000000..3ee9094
--- /dev/null
+++ b/src/CBot/old TstCBot/TstCBotView.cpp
@@ -0,0 +1,291 @@
+// TstCBotView.cpp : implementation of the CTstCBotView class
+//
+
+#include "stdafx.h"
+#include "TstCBot.h"
+
+#include "TstCBotDoc.h"
+#include "TstCBotView.h"
+#include "BotConsoleDlg.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CTstCBotView
+
+IMPLEMENT_DYNCREATE(CTstCBotView, CView)
+
+BEGIN_MESSAGE_MAP(CTstCBotView, CView)
+ //{{AFX_MSG_MAP(CTstCBotView)
+ ON_WM_SIZE()
+ ON_COMMAND(ID_CP1, OnCp1)
+ ON_COMMAND(ID_EXE, OnExe)
+ ON_COMMAND(ID_FILE_SAVE, OnFileSave)
+ ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
+ //}}AFX_MSG_MAP
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CTstCBotView construction/destruction
+
+CTstCBotView::CTstCBotView()
+{
+ // TODO: add construction code here
+ m_pEdit = NULL;
+ m_pProg = NULL;
+}
+
+CTstCBotView::~CTstCBotView()
+{
+}
+
+BOOL CTstCBotView::PreCreateWindow(CREATESTRUCT& cs)
+{
+ // TODO: Modify the Window class or styles here by modifying
+ // the CREATESTRUCT cs
+
+ return CView::PreCreateWindow(cs);
+}
+
+void CTstCBotView::OnActivateView( BOOL bActivate, CView* pActivateView, CView* pDeactiveView )
+{
+ if ( m_pEdit == NULL)
+ {
+ m_pEdit = new CEdit();
+ CRect rect;
+ GetClientRect( rect );
+
+ m_pEdit->Create( WS_VISIBLE|WS_BORDER|WS_TABSTOP|ES_MULTILINE|ES_WANTRETURN|ES_NOHIDESEL|ES_AUTOVSCROLL,
+ rect, this, IDC_EDIT1 );
+ m_pEdit->SetTabStops(12);
+ LoadEdition("CBotTest.txt");
+ m_pEdit->SetFocus();
+ }
+}
+
+
+/////////////////////////////////////////////////////////////////////////////
+// CTstCBotView drawing
+
+void CTstCBotView::OnDraw(CDC* pDC)
+{
+ CTstCBotDoc* pDoc = GetDocument();
+ ASSERT_VALID(pDoc);
+
+ // TODO: add draw code for native data here
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// CTstCBotView diagnostics
+
+#ifdef _DEBUG
+void CTstCBotView::AssertValid() const
+{
+ CView::AssertValid();
+}
+
+void CTstCBotView::Dump(CDumpContext& dc) const
+{
+ CView::Dump(dc);
+}
+
+CTstCBotDoc* CTstCBotView::GetDocument() // non-debug version is inline
+{
+ ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTstCBotDoc)));
+ return (CTstCBotDoc*)m_pDocument;
+}
+#endif //_DEBUG
+
+/////////////////////////////////////////////////////////////////////////////
+// CTstCBotView message handlers
+
+void CTstCBotView::OnSize(UINT nType, int cx, int cy)
+{
+ CView::OnSize(nType, cx, cy);
+
+ if ( m_pEdit != NULL )
+ {
+ CRect rect;
+ GetClientRect( rect );
+ m_pEdit->MoveWindow( rect );
+ m_pEdit->SetFocus();
+ }
+}
+
+void CTstCBotView::SaveEdition(const char* filename)
+{
+ CString program;
+
+ m_pEdit->GetWindowText(program);
+
+ FILE* pf = fopen(filename, "wb");
+ if (pf==NULL) return;
+
+ fputs (program, pf);
+ fclose(pf);
+}
+
+void CTstCBotView::LoadEdition(const char* filename)
+{
+ CString program("{ int x = 10000; while (x > 0) x = x-1; }");
+
+ FILE* pf = fopen(filename, "r");
+ if (pf!=NULL)
+ {
+ char buffer[10000];
+ program.Empty();
+
+ while (NULL != fgets (buffer, 100000, pf))
+ {
+ program += buffer;
+ program = program.Left(program.GetLength()-1) + "\r\n";
+ }
+
+ fclose(pf);
+ }
+
+ m_pEdit->SetWindowText(program);
+}
+
+
+
+// compile le programme
+#include <stdio.h>
+
+void CTstCBotView::OnCp1()
+{
+ CString program;
+
+ SaveEdition("CBotTest.txt");
+
+ m_pEdit->GetWindowText(program);
+
+ CString TextError;
+ int code, start, end;
+
+ if ( m_pProg == NULL ) m_pProg = new CBotProgram();
+
+ CTstCBotApp* pApp = (CTstCBotApp*)AfxGetApp();
+
+ if (m_pProg->Compile(program, pApp->m_Liste))
+ {
+ CString done = "Compilation sans erreur.\nLes fonctions suivantes sont externes:\n";
+
+ for ( int i = 0; i < pApp->m_Liste.RetSize(); i++)
+ {
+ done += CString(pApp->m_Liste[i]) + "\n";
+ }
+
+ AfxMessageBox( done );
+ }
+ else
+ {
+ m_pProg->GetError(code, start, end);
+ delete m_pProg;
+ m_pProg = NULL;
+
+ m_pEdit->SetSel( start, end );
+ m_pEdit->SetFocus(); // met en évidence la partie avec problème
+
+ TextError.LoadString( code );
+ if (TextError.IsEmpty())
+ {
+ char buf[100];
+ sprintf(buf, "Erreur numéro %d.", code);
+ TextError = buf;
+ }
+ AfxMessageBox( TextError );
+ }
+
+ m_pEdit->SetFocus();
+}
+
+
+//////////////////////////////////////////////////////
+
+
+void CTstCBotView::OnExe()
+{
+ CTstCBotApp* pApp = (CTstCBotApp*)AfxGetApp();
+
+ if( m_pProg == NULL)
+ {
+ AfxMessageBox("Pas de programme compilé !");
+ return;
+ }
+
+ if( pApp->m_Liste.RetSize() == 0 )
+ {
+ AfxMessageBox("Aucune fonction marquée \"extern\" !");
+ return;
+ }
+
+
+
+ CBotConsoleDlg dlg;
+ dlg.DoModal(); // dialogue pour faire la console
+
+ if ( dlg.m_code>0 )
+ {
+ CString TextError;
+
+ m_pEdit->SetSel( dlg.m_start, dlg.m_end );
+ m_pEdit->SetFocus(); // met en évidence la partie avec problème
+
+ TextError.LoadString( dlg.m_code );
+ if (TextError.IsEmpty())
+ {
+ char buf[100];
+ sprintf(buf, "Erreur numéro %d.", dlg.m_code);
+ TextError = buf;
+ }
+// AfxMessageBox( TextError );
+ }
+
+ m_pEdit->SetFocus();
+
+ return;
+}
+
+
+
+void CTstCBotView::OnFileSave()
+{
+ // TODO: Add your command handler code here
+ SaveEdition("CBotTest.txt");
+}
+
+void CTstCBotView::OnFileSaveAs()
+{
+ CFileDialog *pDlg;
+ CString s;
+
+ pDlg = new CFileDialog(FALSE, "TXT", NULL,
+ OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY,
+ "cboxtest|*.txt", this);
+ if ( pDlg == NULL ) return;
+
+ if ( pDlg->DoModal() == IDOK ) // choix du fichier ...
+ {
+ SaveEdition(pDlg->GetPathName());
+ }
+
+ delete pDlg;
+}
+
+#if 0
+void test()
+{
+ int y,z;
+
+ for (;;);
+ for (x = 0; y = 1; z = 3) int q = 6;
+ for (int x = 0; int y = 1; int z = 3) int q = 6;
+ // pour voir
+}
+#endif
+