C-- basic Collections support (lib/collection.h)

git-svn-id: svn://kolibrios.org@5959 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2015-12-13 13:28:06 +00:00
parent 3e7a7a7eb9
commit a950d94c01
7 changed files with 75 additions and 11 deletions

View File

@ -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

View File

@ -4,3 +4,4 @@ then C_LANG = "LANG_RUS"
else C_LANG = "LANG_ENG" -- this includes default case without config else C_LANG = "LANG_ENG" -- this includes default case without config
end end
tup.rule("example.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "example.com") 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")

View File

@ -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));
}

View File

@ -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

View File

@ -0,0 +1,45 @@
#ifndef INCLUDE_COLLECTION_H
#define INCLUDE_COLLECTION_H
#print "[include <collection.h>]\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

View File

@ -3,4 +3,4 @@ C-- "textreader.c"
@rename "textreader.com" "textreader" @rename "textreader.com" "textreader"
@del warning.txt @del warning.txt
@pause @pause
rem kpack textreader kpack textreader