forked from KolibriOS/kolibrios
C-- basic Collections support (lib/collection.h)
git-svn-id: svn://kolibrios.org@5959 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
3e7a7a7eb9
commit
a950d94c01
@ -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
|
@ -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")
|
17
programs/cmm/examples/collections.c
Normal file
17
programs/cmm/examples/collections.c
Normal 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));
|
||||
}
|
11
programs/cmm/examples/compile.bat
Normal file
11
programs/cmm/examples/compile.bat
Normal 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
|
45
programs/cmm/lib/collection.h
Normal file
45
programs/cmm/lib/collection.h
Normal 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
|
@ -3,4 +3,4 @@ C-- "textreader.c"
|
||||
@rename "textreader.com" "textreader"
|
||||
@del warning.txt
|
||||
@pause
|
||||
rem kpack textreader
|
||||
kpack textreader
|
Loading…
Reference in New Issue
Block a user