From a950d94c0183e5bb9af6ba7582f63d63e85fce2b Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Sun, 13 Dec 2015 13:28:06 +0000 Subject: [PATCH] C-- basic Collections support (lib/collection.h) git-svn-id: svn://kolibrios.org@5959 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/example/compile.bat | 10 ----- .../cmm/{example => examples}/Tupfile.lua | 1 + programs/cmm/examples/collections.c | 17 +++++++ programs/cmm/examples/compile.bat | 11 +++++ programs/cmm/{example => examples}/example.c | 0 programs/cmm/lib/collection.h | 45 +++++++++++++++++++ programs/cmm/textreader/compile.bat | 2 +- 7 files changed, 75 insertions(+), 11 deletions(-) delete mode 100644 programs/cmm/example/compile.bat rename programs/cmm/{example => examples}/Tupfile.lua (70%) create mode 100644 programs/cmm/examples/collections.c create mode 100644 programs/cmm/examples/compile.bat rename programs/cmm/{example => examples}/example.c (100%) create mode 100644 programs/cmm/lib/collection.h diff --git a/programs/cmm/example/compile.bat b/programs/cmm/example/compile.bat deleted file mode 100644 index fb404a7356..0000000000 --- a/programs/cmm/example/compile.bat +++ /dev/null @@ -1,10 +0,0 @@ -C-- example.c -@del example -@rename example.com example -kpack example -@del warning.txt -@pause -@rem ====== Automatically add binnary to kolibri.img and then run QEMU ===== -@rem"C:\Program Files (x86)\WinImage\WINIMAGE.exe" D:\Kolibri\work\QEMU\kolibri.img /I /H/Q C:\Users\Leency\Dropbox\CMM\example\example -@rem @cd /d C:\Work\QEMU -@rem C:\Work\QEMU\kolibri_qumu.bat \ No newline at end of file diff --git a/programs/cmm/example/Tupfile.lua b/programs/cmm/examples/Tupfile.lua similarity index 70% rename from programs/cmm/example/Tupfile.lua rename to programs/cmm/examples/Tupfile.lua index 2b4e8cf7ea..72dd104241 100644 --- a/programs/cmm/example/Tupfile.lua +++ b/programs/cmm/examples/Tupfile.lua @@ -4,3 +4,4 @@ then C_LANG = "LANG_RUS" else C_LANG = "LANG_ENG" -- this includes default case without config end tup.rule("example.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "example.com") +tup.rule("collections.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "collections.com") diff --git a/programs/cmm/examples/collections.c b/programs/cmm/examples/collections.c new file mode 100644 index 0000000000..f732be07bc --- /dev/null +++ b/programs/cmm/examples/collections.c @@ -0,0 +1,17 @@ +#define MEMSIZE 4096*10 + +#include "../lib/io.h" +#include "../lib/collection.h" + +void main() +{ + collection s; + io.run("/sys/develop/board", ""); + s.init(4096); + s.add("lorem"); + s.add("ipsum"); + s.add("1234566"); + debugln(s.get(0)); + debugln(s.get(1)); + debugln(s.get(2)); +} \ No newline at end of file diff --git a/programs/cmm/examples/compile.bat b/programs/cmm/examples/compile.bat new file mode 100644 index 0000000000..8912325202 --- /dev/null +++ b/programs/cmm/examples/compile.bat @@ -0,0 +1,11 @@ +c-- example.c +c-- collections.c + +@del @@example +@del @@collections + +@rename example.com @@example +@rename collections.com @@collections + +@del warning.txt +@pause \ No newline at end of file diff --git a/programs/cmm/example/example.c b/programs/cmm/examples/example.c similarity index 100% rename from programs/cmm/example/example.c rename to programs/cmm/examples/example.c diff --git a/programs/cmm/lib/collection.h b/programs/cmm/lib/collection.h new file mode 100644 index 0000000000..0d98a43699 --- /dev/null +++ b/programs/cmm/lib/collection.h @@ -0,0 +1,45 @@ +#ifndef INCLUDE_COLLECTION_H +#define INCLUDE_COLLECTION_H +#print "[include ]\n" + +struct collection +{ + int count; + dword element_offset[4096]; + dword data_size; + dword string_data_start; + dword string_data_cur_pos; + void add(); + dword get(); + void drop(); + void init(); + +}; + +void collection::init(dword size) { + if (data_size) drop(); + data_size = data_size + size; + string_data_cur_pos = string_data_start = malloc(data_size); + count = 0; +} + +void collection::add(dword in) { + strcpy(string_data_cur_pos, in); + element_offset[count] = string_data_cur_pos; + string_data_cur_pos += strlen(in) + 1; + count++; +} + +dword collection::get(dword pos) { + return element_offset[pos]; +} + +void collection::drop() { + if (string_data_start) free(string_data_start); + data_size = + string_data_start = + string_data_cur_pos = + count = 0; +} + +#endif \ No newline at end of file diff --git a/programs/cmm/textreader/compile.bat b/programs/cmm/textreader/compile.bat index c8d4886acb..b83277026f 100644 --- a/programs/cmm/textreader/compile.bat +++ b/programs/cmm/textreader/compile.bat @@ -3,4 +3,4 @@ C-- "textreader.c" @rename "textreader.com" "textreader" @del warning.txt @pause -rem kpack textreader \ No newline at end of file +kpack textreader \ No newline at end of file