From b6c51edde16b14141f324f947370c37caebdfb03 Mon Sep 17 00:00:00 2001 From: IgorA Date: Sat, 14 Nov 2020 12:39:58 +0000 Subject: [PATCH] add file_open example git-svn-id: svn://kolibrios.org@8190 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/bcc32/examples/file_open/1.txt | 12 ++ programs/bcc32/examples/file_open/2.txt | 19 ++++ programs/bcc32/examples/file_open/Makefile | 19 ++++ .../bcc32/examples/file_open/file_open.cpp | 105 ++++++++++++++++++ .../examples/file_open/file_open_cpp.bat | 16 +++ 5 files changed, 171 insertions(+) create mode 100644 programs/bcc32/examples/file_open/1.txt create mode 100644 programs/bcc32/examples/file_open/2.txt create mode 100644 programs/bcc32/examples/file_open/Makefile create mode 100644 programs/bcc32/examples/file_open/file_open.cpp create mode 100644 programs/bcc32/examples/file_open/file_open_cpp.bat diff --git a/programs/bcc32/examples/file_open/1.txt b/programs/bcc32/examples/file_open/1.txt new file mode 100644 index 0000000000..5bb4989769 --- /dev/null +++ b/programs/bcc32/examples/file_open/1.txt @@ -0,0 +1,12 @@ + /\__/\ +| - - | +* ^--^ * + x=--=x + | | +| | +| | | | . +| |__| |\___// + vv vv *---* + +Keeka: Simply the best cat in the Universe. + \ No newline at end of file diff --git a/programs/bcc32/examples/file_open/2.txt b/programs/bcc32/examples/file_open/2.txt new file mode 100644 index 0000000000..3447f632fe --- /dev/null +++ b/programs/bcc32/examples/file_open/2.txt @@ -0,0 +1,19 @@ + @@@@@@@@@@@@ @@@@@@@@ + @............@ @........@ +@..............@ @..........@ +@.......@@@.....@ @......@.....@ +@.......@ @.....@@@@@@......@@......@ +@......@ @.................@@.......@ + @....@ @.....@@......@@....@.......@ + @..@ @.........@.........@......@ + @@ @...................@@....@ + @.......@@@.......@ @..@ + @...............@ @@ + @...............@ + @.................@ + @...................@ + @.....................@ + @.......@@......@@......@ @@ + @......@....@..@....@.....@@..@ + @......@....@..@....@.........@ + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ diff --git a/programs/bcc32/examples/file_open/Makefile b/programs/bcc32/examples/file_open/Makefile new file mode 100644 index 0000000000..fbc205a0dd --- /dev/null +++ b/programs/bcc32/examples/file_open/Makefile @@ -0,0 +1,19 @@ +# Path to /programs +SVN_PROGR:=../../.. + +# Path to /programs/bcc32 +SVN_BCC32:=$(SVN_PROGR)/bcc32 + +# Path to t2fasm +T2FASM:=$(SVN_BCC32)/t2fasm + +# Path to include +INCLUDE:=$(SVN_BCC32)/include + +# Path to Bin folder +KOS32_BCC:=/home/autobuild/borlandcpp/bin + +# Filename without .cpp +FILENAME:=file_open + +include $(SVN_BCC32)/Makefile_app diff --git a/programs/bcc32/examples/file_open/file_open.cpp b/programs/bcc32/examples/file_open/file_open.cpp new file mode 100644 index 0000000000..815e4b2800 --- /dev/null +++ b/programs/bcc32/examples/file_open/file_open.cpp @@ -0,0 +1,105 @@ +#include +#include +#include + +using namespace Kolibri; + +const char header[] = "File open"; +unsigned char* f_data = 0; + +bool KolibriOnStart(TStartData &kos_start, TThreadData /*th*/) +{ + kos_start.Left = 10; + kos_start.Top = 40; + kos_start.Width = 300; + kos_start.Height = 220; + kos_start.WinData.WindowColor = 0xFFFFFF; + kos_start.WinData.WindowType = 0x34; // 0x34 - fixed, 0x33 - not fixed + kos_start.WinData.Title = header; + + return true; +} + +void KolibriOnPaint(void) +{ + // If button have ID 1, this is close button + DrawButton(2,0xf0f0f0, 10,10,50,20); + DrawText(20,16,0,"1.txt"); + DrawButton(3,0xf0f0f0, 70,10,50,20); + DrawText(80,16,0,"2.txt"); + + if (f_data){ + long i=0, j, y=0; + char buf[300]; + do{ + j=0; + while(f_data[i] && f_data[i]!=13 && f_data[i]!=10){ + buf[j]=f_data[i]; + i++; + j++; + }; + buf[j]=0; + DrawText(10,45+9*y,0,buf); + y++; + while(f_data[i]==13 || f_data[i]==10) i++; + }while(f_data[i]); + } +} + +void KolibriOnButton(long id, TThreadData /*th*/) +{ + FileInfoBlock* file; + long int k; + + switch(id){ + case 2: + file = FileOpen("1.txt"); + if (!file){ + SetWindowCaption("Error open file '1.txt'"); + break; + } + k = FileGetLength(file); + if (k > 0){ + if(f_data) Free(f_data); + f_data = (unsigned char*)Alloc(k); + if (f_data){ + if (FileRead(file, f_data, k) != k){ + Free(f_data); f_data = 0; + } + else{ + SetWindowCaption("1.txt"); + Redraw(1); + } + } + } + FileClose(file); + break; + case 3: + file = FileOpen("2.txt"); + if (!file){ + SetWindowCaption("Error open file '2.txt'"); + break; + } + k = FileGetLength(file); + if (k > 0){ + if(f_data) Free(f_data); + f_data = (unsigned char*)Alloc(k); + if (f_data){ + if (FileRead(file, f_data, k) != k){ + Free(f_data); f_data = 0; + } + else{ + SetWindowCaption("2.txt"); + Redraw(1); + } + } + } + FileClose(file); + //break; + }; +} + +bool KolibriOnClose(TThreadData /*th*/) { + if(f_data) {Free(f_data); f_data = 0;} + return true; +} \ No newline at end of file diff --git a/programs/bcc32/examples/file_open/file_open_cpp.bat b/programs/bcc32/examples/file_open/file_open_cpp.bat new file mode 100644 index 0000000000..cbdfdf2637 --- /dev/null +++ b/programs/bcc32/examples/file_open/file_open_cpp.bat @@ -0,0 +1,16 @@ +Set NAME=file_open +Set BCC_DIR=..\..\..\bcc32 +kos32-bcc -S -v- -R- -6 -a4 -O2 -Og -Oi -Ov -OS -k- -D__KOLIBRI__ -I..\..\..\bcc32\include %NAME%.cpp + +echo STACKSIZE equ 102400> kos_make.inc +echo HEAPSIZE equ 102400>> kos_make.inc +echo include "%BCC_DIR%\include\kos_start.inc">> kos_make.inc +echo include "%BCC_DIR%\include\kos_func.inc">> kos_make.inc +echo include "%BCC_DIR%\include\kos_heap.inc">> kos_make.inc + +echo include "kos_make.inc" > f_%NAME%.asm +t2fasm < %NAME%.asm >> f_%NAME%.asm +fasm f_%NAME%.asm %NAME%.kex +if exist %NAME%.kex kpack %NAME%.kex +if exist %NAME%.kex del kos_make.inc +pause