Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 7910 → Rev 7911

/programs/cmm/notify/notify.c
File deleted
/programs/cmm/notify/compile_en.bat
File deleted
/programs/cmm/notify/compile_ru.bat
File deleted
/programs/cmm/notify/Tupfile.lua
File deleted
/programs/cmm/notify
Property changes:
Deleted: tsvn:logminsize
-5
\ No newline at end of property
/programs/cmm/easyshot/compile_en.bat
File deleted
/programs/cmm/easyshot/easyshot.c
File deleted
/programs/cmm/easyshot/compile_ru.bat
File deleted
/programs/cmm/easyshot/Tupfile.lua
File deleted
/programs/cmm/easyshot
Property changes:
Deleted: tsvn:logminsize
-5
\ No newline at end of property
/programs/cmm/pipet/pipet.c
File deleted
\ No newline at end of file
/programs/cmm/pipet/Tupfile.lua
File deleted
/programs/cmm/pipet/compile_en.bat
File deleted
\ No newline at end of file
/programs/cmm/Calypte/compile_en.bat
File deleted
/programs/cmm/Calypte/Calypte.c
File deleted
/programs/cmm/Calypte/Tupfile.lua
File deleted
/programs/cmm/Calypte
Property changes:
Deleted: tsvn:logminsize
-5
\ No newline at end of property
/programs/cmm/mblocks/Tupfile.lua
File deleted
/programs/cmm/mblocks/mblocks.c
File deleted
/programs/cmm/mblocks/compile_en.bat
File deleted
\ No newline at end of file
/programs/cmm/python/examples/dectohex.py
File deleted
\ No newline at end of file
/programs/cmm/python/examples/example.py
File deleted
\ No newline at end of file
/programs/cmm/python/static/head.h
File deleted
/programs/cmm/python/static/init.h
File deleted
\ No newline at end of file
/programs/cmm/python/static/function.h
File deleted
\ No newline at end of file
/programs/cmm/python/static/lib.h
File deleted
\ No newline at end of file
/programs/cmm/python/static/opcode.h
File deleted
\ No newline at end of file
/programs/cmm/python/static/array.h
File deleted
\ No newline at end of file
/programs/cmm/software_widget/compile.bat
File deleted
/programs/cmm/software_widget/software_widget.c
File deleted
/programs/cmm/software_widget/Tupfile.lua
File deleted
/programs/cmm/software_widget
Property changes:
Deleted: tsvn:logminsize
-5
\ No newline at end of property
/programs/cmm/kolibrin/Tupfile.lua
File deleted
/programs/cmm/kolibrin/kolibrin.c
File deleted
/programs/cmm/kolibrin/compile.bat
File deleted
/programs/cmm/kolibrin
Property changes:
Deleted: tsvn:logminsize
-5
\ No newline at end of property
/programs/cmm/experimental/python/static/array.h
0,0 → 1,266
:dword arrayInit(dword len)
{
dword alloc = 0;
dword position = 0;
alloc = malloc(len*4+MEMBUF);
position = alloc;
DSDWORD[position] = 0;
position+=4;
DSDWORD[position] = len;
return alloc;
}
:dword ReallocArray(dword array,nMem)
{
dword NEW = 0;
dword OLD = 0;
dword FLEN = 0;
dword LEN = 0;
//test2("relloc",0);
OLD = array;
FLEN = nMem*4+8;
LEN = DSDWORD[array];
NEW = arrayInit(nMem);
array+=8;
while(LEN)
{
A = DSDWORD[array];
IF(A)
{
arraySet(#NEW,DSDWORD[A],DSDWORD[A+4]);
free(A);
}
LEN--;
array+=4;
}
free(OLD);
 
return NEW;
}
 
:byte arraySet(dword array,key,value)
{
dword NEW = 0;
dword LEN = 0;
dword FLEN = 0;
dword POSITION = 0;
dword VKEY = 0;
dword FULL = 0;
dword OST = 0;
dword BEGIN = 0;
dword gArray = 0;
gArray = DSDWORD[array];
IF(gArray)
{
LEN = DSDWORD[gArray];
OST = DSDWORD[gArray+4];
}
ELSE
{
LEN = 0;
OST = 8;
}
 
IF(LEN)
{
IF(!(LEN%OST))
{
gArray = ReallocArray(gArray,OST<<1);
DSDWORD[array] = gArray;
}
}
ELSE
{
gArray = arrayInit(OST);
DSDWORD[array] = gArray;
}
BEGIN = gArray;
gArray+=4;
FLEN = DSDWORD[gArray];
gArray+=4;
POSITION = key%FLEN*4+gArray;
FULL = FLEN*4+gArray;
 
LOOP_COL2:
VKEY = DSDWORD[POSITION];
IF(!VKEY)
{
NEW = malloc(8);
DSDWORD[NEW] = key;
DSDWORD[NEW+4] = value;
DSDWORD[POSITION] = NEW;
DSDWORD[BEGIN] = DSDWORD[BEGIN]+1;
return 1;
}
IF(DSDWORD[VKEY] == key)
{
DSDWORD[VKEY+4] = value;
return 2;
}
// collision
POSITION+=4;
IF(POSITION>FULL) POSITION = gArray+8;
goto LOOP_COL2;
return 3;
}
 
:dword arrayGet(dword array,key)
{
dword NEW = 0;
dword LEN = 0;
dword MEMLEN = 0;
dword POSITION = 0;
dword VKEY = 0;
dword FULL = 0;
LEN = DSDWORD[array];
array+=4;
MEMLEN = DSDWORD[array];
array+=4;
POSITION = key%MEMLEN*4+array;
FULL = LEN*4+array;
Z = 2;
LOOP_COL1:
VKEY = DSDWORD[POSITION];
 
IF(!VKEY) return 0;
IF(DSDWORD[VKEY] == key) return DSDWORD[VKEY+4];
// collision
POSITION+=4;
IF(POSITION>FULL)
{
POSITION = array+8;
Z--;
IF(!Z) return 0;
}
goto LOOP_COL1;
}
 
:dword arrayDelete(dword array,key)
{
dword NEW = 0;
dword LEN = 0;
dword MEMLEN = 0;
dword POSITION = 0;
dword VKEY = 0;
dword FULL = 0;
dword TMP = 0;
LEN = DSDWORD[array];
array+=4;
MEMLEN = DSDWORD[array];
array+=4;
POSITION = key%MEMLEN*4+array;
FULL = LEN*4+array;
Z = 2;
LOOP_COL1:
VKEY = DSDWORD[POSITION];
 
IF(!VKEY) return 0;
IF(DSDWORD[VKEY] == key)
{
TMP = DSDWORD[VKEY+4];
free(VKEY);
DSDWORD[POSITION] = 0;
DSDWORD[array] = DSDWORD[array]-1;
return TMP;
}
// collision
POSITION+=4;
IF(POSITION>FULL)
{
POSITION = array+8;
Z--;
IF(!Z) return 0;
}
goto LOOP_COL1;
}
 
// dict
 
:dword hash(dword str)
{
byte S = 0;
dword s1 = 0;
dword s2 = 0;
S = DSBYTE[str];
WHILE(S)
{
s1 += S;
s2 += s1;
S = DSBYTE[str];
str++;
}
s1<<=16;
RETURN s1|s2;
}
 
:byte dictSet(dword array,key,data)
{
RETURN arraySet(array,hash(key),data);
}
 
:byte dictDel(dword array,key)
{
RETURN arrayDelete(array,hash(key));
}
 
:dword dictGet(dword array,key)
{
RETURN arrayGet(array,hash(key));
}
 
 
// list
:void listAppend(dword position,data) // TODO Fixed!!
{
dword len = 0;
dword flen = 0;
dword news = 0;
dword array = 0;
dword i = 0;
array = DSDWORD[position];
len = DSDWORD[array];
flen = DSDWORD[array+4];
IF(len>=flen)
{
news = malloc(flen<<3+8);
DSDWORD[position] = news;
i = flen<<1+2;
while(i)
{
DSDWORD[news] = DSDWORD[array];
news+=4;
array+=4;
i--;
}
array = news;
}
DSDWORD[len*4+array+8] = data;
DSDWORD[array] = DSDWORD[array]+1;
}
:dword listGet(dword array,key)
{
return DSDWORD[key*4+array+8];
}
/programs/cmm/experimental/python/static/function.h
0,0 → 1,114
 
 
:void copyVariable(dword x)
{
load_const(DSDWORD[x],DSBYTE[x+4],DSDWORD[x+5]);
}
 
 
:dword LenStdout = 0;
:void _stdout(dword txt)
{
dword addr = txt;
WHILE(DSBYTE[addr]) addr++;
IF(!LenStdout)
{
LenStdout = addr-txt;
CreateFile(LenStdout,txt,"/sys/stdout");
}
ELSE
{
AddFile(LenStdout,addr-txt,txt,"/sys/stdout");
LenStdout+=addr-txt;
}
}
:dword std__stdStr(dword count)
{
return _str(popFast());
}
:dword stdcall std__stdout(dword count)
{
std__str(count);
popStack();
_stdout(DSDWORD[EAX]);
}
:dword stdcall std__len(dword c)
{
popFast();
load_const(DSDWORD[EAX+5],PY_INT,0);
RETURN 0;
}
 
:dword stdcall std__INT40(dword c)
{
X = popFast();
Y = DSDWORD[X+5];
X = DSDWORD[X];
X = DSDWORD[X];
X = DSDWORD[X];
test(X,1);
RETURN 0;
}
 
:void hexAddress(dword x,y)
{
dword i = 0;
i = 8;
WHILE(i)
{
DSBYTE[x] = DSBYTE[y&0xF+#arraySymbolHEX];
y>>=4;
x--;
i--;
}
}
#define rSize DSBYTE[#RDATA+5]
#define rData DSBYTE[#RDATA]
#define rType DSBYTE[#RDATA+4]
 
:dword stdcall std__str(dword c)
{
dword n = 0;
dword m = 0;
dword l = 0;
dword v = 0;
dword f = "<function a at 0x00000000>";
dword t = 0;
dword o = 0;
v = popFast();
IF(DSBYTE[v+4] == PY_STR)
{
copyVariable(v);
return 0;
}
 
switch(DSBYTE[v+4])
{
case PY_BOOL:
if(DSDWORD[v])
{
load_const("True",PY_STR,4);
return 0;
}
load_const("False",PY_STR,5);
return 0;
break;
case PY_INT:
m = malloc(MEMBUF);
l = itoa(DSDWORD[v],m);
load_const(m,PY_STR,l);
return 0;
break;
case PY_NONE:
load_const("None",PY_STR,4);
return 0;
break;
case PY_FNC:
hexAddress(f+24,v);
load_const(f,PY_STR,26);
return 0;
break;
}
}
/programs/cmm/experimental/python/static/gui.h
--- experimental/python/static/head.h (nonexistent)
+++ experimental/python/static/head.h (revision 7911)
@@ -0,0 +1,100 @@
+#pragma option OST
+#pragma option ON
+#pragma option cri-
+#pragma option -CPA
+#initallvar 0
+#jumptomain FALSE
+
+#startaddress 65536
+
+#code32 TRUE
+
+#define PY_NONE 0
+#define PY_BOOL 1
+#define PY_INT 2
+#define PY_FLT 3
+#define PY_STR 4
+#define PY_FNC 6
+#define PY_CPL 7
+#define PY_LST 8
+#define PY_TPL 9
+#define PY_RNG 10
+#define PY_BTS 11
+#define PY_BTA 12
+#define PY_MVW 13
+#define PY_SET 14
+#define PY_FST 15
+#define PY_DCT 16
+#define PY_CLS 17
+#define PY_MDL 18
+
+#define PY_STD_FNC 30
+
+#define PY_NA_STR 32
+#define PY_SYM_STR 33
+
+
+#define PY_ADD 0
+#define PY_POW 1
+#define PY_MUL 2
+#define PY_SUB 3
+#define PY_DIV 4
+#define PY_MOD 5
+#define PY_XOR 6
+#define PY_AND 7
+#define PY__OR 8
+#define PY_LSH 9
+#define PY_RSH 10
+#define PY_FDV 11
+#define PY_TDV 12
+
+#define MEMBUF 0xF
+#define MEMARR 0xF
+
+char os_name[8] = {'M','E','N','U','E','T','0','1'};
+dword os_version = 0x00000001;
+dword start_addr = #______INIT______;
+dword final_addr = #______STOP______+32;
+dword alloc_mem = 160000;
+dword x86esp_reg = 160000;
+dword I_Param = #param;
+dword I_Path = #program_path;
+char param[4096]={0};
+char program_path[4096]={0};
+
+:dword arraySymbolHEX = "0123456789ABCDEF";
+:dword libPath = "/sys/lib/";
+:dword HASH = 0;
+:dword TEMP = 0;
+:dword RDATA[30] = {0};
+
+// global variable
+:dword X = 0;
+:dword Y = 0;
+:dword Z = 0;
+:dword A = 0;
+:dword B = 0;
+:dword C = 0;
+:dword D = 0;
+:dword E = 0;
+:dword F = 0;
+
+:dword beginStack = 0;
+
+:dword COUNT_CONST = 0;
+
+:byte std__STRING = 0;
+:byte std__INTEGER = 1;
+
+:byte S = 0;
+//--------------
+
+:struct f70{
+ dword func;
+ dword param1;
+ dword param2;
+ dword param3;
+ dword param4;
+ char rezerv;
+ dword name;
+};
/programs/cmm/experimental/python/static/init.h
0,0 → 1,375
:void ExitProcess()
{
EAX = -1;
$int 0x40
}
 
:f70 write_file_70;
:int CreateFile(dword data_size, buffer, file_path)
{
write_file_70.func = 2;
write_file_70.param1 = 0;
write_file_70.param2 = 0;
write_file_70.param3 = data_size;
write_file_70.param4 = buffer;
write_file_70.rezerv = 0;
write_file_70.name = file_path;
$mov eax,70
$mov ebx,#write_file_70.func
$int 0x40
}
 
:int AddFile(dword begin,data_size, buffer, file_path)
{
write_file_70.func = 3;
write_file_70.param1 = begin;
write_file_70.param2 = 0;
write_file_70.param3 = data_size;
write_file_70.param4 = buffer;
write_file_70.rezerv = 0;
write_file_70.name = file_path;
$mov eax,70
$mov ebx,#write_file_70.func
$int 0x40
}
 
dword malloc(dword size)
{
$push ebx
$push ecx
 
$mov eax, 68
$mov ebx, 12
$mov ecx, size
$int 0x40
$pop ecx
$pop ebx
return EAX;
}
dword free(dword mptr)
{
$push ebx
$push ecx
$mov eax, 68
$mov ebx, 13
$mov ecx, mptr
$test ecx, ecx
$jz end0
$int 0x40
@end0:
$pop ecx
$pop ebx
return 0;
}
stdcall dword realloc(dword mptr, size)
{
$push ebx
$push ecx
$push edx
$mov eax, 68
$mov ebx, 20
$mov ecx, size
$mov edx, mptr
$int 0x40
$pop edx
$pop ecx
$pop ebx
return EAX;
}
 
:void memcpy(dword x,y,size)
{
dword ost = 0;
dword del = 0;
del = size/4;
ost = size%4;
WHILE(del)
{
DSDWORD[x] = DSDWORD[y];
del--;
x+=4;
y+=4;
}
IF(ost>1)
{
DSWORD[x] = DSWORD[y];
x+=2;
y+=2;
ost-=2;
}
IF(ost==1) DSBYTE[x] = DSBYTE[y];
}
 
:dword sleep(dword x)
{
EAX = 5;
EBX = x;
$int 0x40
}
:dword memInit()
{
$push ebx
$mov eax, 68
$mov ebx, 11
$int 0x40
$pop ebx
return EAX;
}
 
 
:dword itoa(signed long number,dword p)
{
dword ret=0;
byte cmd=0;
long mask=0;
long tmp=0;
IF(!number)
{
DSBYTE[p] = '0';
p++;
DSBYTE[p] = 0;
return 1;
}
mask = 1000000000;
cmd = 1;
if(!number){
ESBYTE[p] = '0';
ESBYTE[p+1] = 0;
return p;
}
ret = p;
if(number<0)
{
$neg number
ESBYTE[p] = '-';
$inc p
}
while(mask)
{
tmp = number / mask;
tmp = tmp%10;
if(cmd){
if(tmp){
ESBYTE[p] = tmp + '0';
$inc p
cmd = 0;
}
}
else {
ESBYTE[p] = tmp + '0';
$inc p
}
mask /= 10;
}
ESBYTE[p] = 0;
return p - ret;
}
 
:dword strcpy(dword s1,s2)
{
X = s1;
WHILE(DSBYTE[s2])
{
DSBYTE[s1] = DSBYTE[s2];
s1++;
s2++;
}
RETURN s1-X;
}
:dword strlcpy(dword s1,s2,l)
{
X = l;
WHILE(l)
{
DSBYTE[s1] = DSBYTE[s2];
s1++;
s2++;
l--;
}
RETURN X;
}
 
:dword _str(dword v)
{
SWITCH(DSBYTE[v+4])
{
CASE PY_STR:
RETURN DSDWORD[v];
CASE PY_BOOL:
IF(DSDWORD[v]) RETURN "True";
RETURN "False";
}
}
 
:dword stack = 0;
:dword popStack()
{
stack-=4;
RETURN DSDWORD[stack];
}
:void pushStack(dword x)
{
dword tmp = 0;
IF(!DSDWORD[stack]) tmp = malloc(30);
ELSE tmp = DSDWORD[stack];
IF(x) memcpy(tmp,x,30);
DSDWORD[stack] = tmp;
stack+=4;
}
 
:dword stackFast = 0;
:dword beginStackFast = 0;
:dword popFast()
{
stackFast-=4;
RETURN DSDWORD[stackFast];
}
:void pushFast(dword x)
{
dword tmp = 0;
IF(!DSDWORD[stackFast]) tmp = malloc(30);
ELSE tmp = DSDWORD[stackFast];
IF(x) memcpy(tmp,x,30);
DSDWORD[stackFast] = tmp;
stackFast+=4;
}
 
:dword stackLoop = 0;
:dword popLoop()
{
stackLoop-=4;
RETURN DSDWORD[stackLoop];
}
:void pushLoop(dword x)
{
DSDWORD[stackLoop] = x;
stackLoop+=4;
}
 
:void checkType(dword x,y)
{
IF(DSBYTE[x+4]!=DSBYTE[y+4])
{
_stdout("Error type!");
ExitProcess();
}
}
 
:void sprintf(dword str, ...)
{
//S = DSBYTE[format];
X = DSDWORD[ESP]-ESP-8;
X += ESP;
A = DSDWORD[X];
X-=4;
B = DSDWORD[X];
S = DSBYTE[B];
while(S)
{
if(S=='%')
{
B++;
S = DSBYTE[B];
IF(S=='s')
{
X-=4;
strcpy(A,DSDWORD[X]);
A+=EAX;
B++;
S = DSBYTE[B];
continue;
}
IF(S=='c')
{
X-=4;
EAX = DSDWORD[X];
test(EAX,1);
A++;
B++;
S = DSBYTE[B];
continue;
}
ELSE IF(S=='d')
{
}
ELSE
{
DSBYTE[A] = S;
A++;
}
}
else
{
DSBYTE[A] = S;
A++;
}
B++;
S = DSBYTE[B];
}
}
 
:byte BUFTST[15] = {0};
:void test1(dword x,y)
{
 
IF(y)
{
itoa(x,#BUFTST);
_stdout(#BUFTST);
}
ELSE _stdout(x);
EAX = -1;
$int 0x40;
}
 
:void test2(dword x,y)
{
_stdout("[");
IF(y)
{
itoa(x,#BUFTST);
_stdout(#BUFTST);
}
ELSE _stdout(x);
_stdout("]");
}
 
 
 
:void ______INIT______()
{
dword o = 0;
dword o2 = 0;
memInit();
 
stack = malloc(1000);
beginStack = stack;
stackFast = malloc(1000);
beginStackFast = stackFast;
stackLoop = malloc(1000);
TEMP = malloc(500);
//o = malloc(16*4);
//memcpy(o,"test123456789",9);
 
//test(123);
//sprintf(TEMP,"asd%sa=%c123","ok",123);
//test(TEMP,0);
//importLibrary("console");
main();
ExitProcess();
}
 
:void ______STOP______()
{
ExitProcess();
}
/programs/cmm/experimental/python/static/lib.h
0,0 → 1,201
:dword strcmp(dword str1,str2)
{
LOOPCMP:
IF(DSBYTE[str1]!=DSBYTE[str2]) RETURN DSBYTE[str1]-DSBYTE[str2];
IF(!DSBYTE[str1]) RETURN DSBYTE[str1]-DSBYTE[str2];
IF(!DSBYTE[str2]) RETURN DSBYTE[str1]-DSBYTE[str2];
str1++;
str2++;
GOTO LOOPCMP;
}
/*
void dll_Load() {
asm {
push ebp
mov ebp, esp
mov esi, SSDWORD[EBP+8]
@next_lib:
mov edx, DSDWORD[ESI]
or edx, edx
jz exit
push esi
mov esi, DSDWORD[ESI+4]
mov edi, #libPath
add edi,9
@loc01:
lodsb
stosb
or al, al
jnz loc01
mov eax, 68
mov ebx, 19
mov ecx, #libPath
int 0x40
or eax, eax
jz fail
push edx
push eax
call dll_Link
push eax
mov eax, DSDWORD[eax]
cmp DSDWORD[EAX], '_bil' // somehow this needs to be reversed..
pop eax
jnz loc02
push DSDWORD[EAX+4]
call dll_Init
@loc02:
pop esi
add esi, 8
jmp next_lib
@exit:
xor eax, eax
leave
ret 4
@fail:
add esp, 4
xor eax, eax
inc eax
leave
ret 4
}
}
void dll_GetProcAddress(){
asm {
push ebp
mov ebp, esp
mov edx, CSDWORD[EBP+8]
xor eax, eax
@next:
or edx, edx
jz end
cmp CSDWORD[edx], 0
jz end
push CSDWORD[EBP+12]
push CSDWORD[EDX]
call dll_StrCmp
test eax, eax
jz ok
add edx, 8
jmp next
@ok:
mov eax, DSDWORD[EDX+4]
@end:
leave
ret 8
}
}
void dll_StrCmp() {
asm {
push ebp
mov ebp, esp
push esi
push edi
mov esi, CSDWORD[EBP+8]
mov edi, CSDWORD[EBP+12]
xor eax, eax
@label1:
lodsb
scasb
jne fail
or al, al
jnz label1
jmp label_ok
@fail:
or eax, -1
@label_ok:
pop edi
pop esi
leave
ret 8
}
}
void dll_Link() {
asm {
push ebp
mov ebp, esp
push eax
mov esi, SSDWORD[EBP+12]
test esi, esi
jz done
@next:
lodsd
test eax, eax
jz done
push eax
push SSDWORD[EBP+8]
call dll_GetProcAddress
or eax, eax
jz loc03
mov DSDWORD[esi-4], eax
jmp next
@loc03:
mov SSDWORD[esp], 0
@done:
pop eax
leave
ret 8
}
}
void dll_Init() {
asm {
push ebp
mov ebp, esp
pushad
mov eax, #malloc
mov ebx, #free;
mov ecx, #realloc;
mov edx, #dll_Load;
call SSDWORD[EBP+8]
popad
leave
ret 4
}
}
*/
:dword importLibrary(dword name)
{
dword l = 0;
dword i = 0;
dword list = 0;
dword key = 0;
dword data = 0;
dword ret = 0;
i = malloc(1000);
l = strcpy(TEMP,#libPath);
l += strcpy(TEMP+l,name);
memcpy(TEMP+l,".obj",5);
EAX = 68;
EBX = 19;
ECX = TEMP;
$int 0x40;
list = EAX;
while(DSDWORD[list])
{
test2(DSDWORD[list],0);
IF(!strcmp(DSDWORD[list],"con_init"))
{
//dll_Init(DSDWORD[list+4]);
}
ELSE dictSet(ret,DSDWORD[list],DSDWORD[list+4]);
list+=8;
}
EAX = DSDWORD[i+92];
i = malloc(10);
strcpy(i,"test");
i = realloc(i,19);
test1(i,0);
}
/programs/cmm/experimental/python/static/opcode.h
0,0 → 1,717
#define buffer 1024
 
:struct VAR
{
dword data;
byte type;
dword length;
dword stack;
};
 
 
:dword build_map(dword count)
{
dword o = 0;
dword a1 = 0;
dword a2 = 0;
IF(count>8) o = arrayInit(count);
ELSE o = arrayInit(8);
WHILE(count)
{
a1 = popStack();
a2 = popStack();
SWITCH(DSBYTE[a2+4])
{
CASE PY_STR:
dictSet(#o,DSDWORD[a2],a1);
BREAK;
CASE PY_INT:
arraySet(#o,1,a1);
BREAK;
}
count--;
}
load_const(o,PY_DCT,0);
}
 
:void load_const(dword data,type,length)
{
DSDWORD[#RDATA] = data;
DSBYTE[#RDATA+4] = type;
DSDWORD[#RDATA+5] = length;
DSDWORD[#RDATA+9] = 0;
pushStack(#RDATA);
}
 
:void compare_op(byte cmd)
{
dword n = 0;
dword y = popStack();
dword x = popStack();
dword dx = 0;
dword dy = 0;
dword i = 0;
checkType(x,y);
IF(DSBYTE[x+4] == PY_STR)
{
IF(DSDWORD[x+5] == DSDWORD[y+5])
{
dx = DSDWORD[x];
dy = DSDWORD[y];
i = DSDWORD[x+5];
WHILE(i)
{
IF(DSBYTE[dx]!=DSBYTE[dy]) BREAK;
dx++;
dy++;
i--;
}
IF(!i) load_const(1,PY_BOOL,0);
ELSE load_const(0,PY_BOOL,0);
}
return;
}
IF(!cmd)IF(DSDWORD[x] == DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
IF(cmd==1)IF(DSDWORD[x] != DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
IF(cmd==2)IF(DSDWORD[x] >= DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
IF(cmd==3)IF(DSDWORD[x] <= DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
IF(cmd==4)IF(DSDWORD[x] > DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
IF(cmd==5)IF(DSDWORD[x] < DSDWORD[y])
{
load_const(1,PY_BOOL,0);
return;
}
load_const(0,PY_BOOL,0);
}
:byte pop_jump_if(byte cmd)
{
dword x = 0;
 
x = popStack();
//test(DSDWORD[x+4],1);
SWITCH(DSBYTE[x+4])
{
CASE PY_INT:
CASE PY_BOOL:
IF(cmd){ IF (DSDWORD[x]) RETURN 1;}
IF(!cmd){ IF (!DSDWORD[x]) RETURN 1;}
BREAK;
CASE PY_STR:
IF(cmd){ IF (DSDWORD[x+5]) RETURN 1;}
IF(!cmd){ IF (!DSDWORD[x+5]) RETURN 1;}
BREAK;
}
RETURN 0;
}
:void pop_block()
{
stackLoop-=4;
}
:void unary_invert()
{
dword x = 0;
x = DSDWORD[stack-4];
EAX = DSDWORD[x];
$not eax;
DSDWORD[x] = EAX;
}
:void inplace(byte cmd)
{
dword buffer = 0;
dword length = 0;
Y = popStack();
X = DSDWORD[stack-4];
IF(cmd==PY_ADD) checkType(X,Y);
E = DSBYTE[X+4];
if(E==PY_STR)
{
A = DSDWORD[X+5];
IF(cmd==PY_ADD) B = DSDWORD[Y+5];
ELSE
{
C = DSDWORD[Y];
B = C*A;
}
length = A+B;
buffer = length+MEMBUF;
D = malloc(buffer);
 
IF(cmd==PY_ADD)
{
memcpy(D,DSDWORD[X],A);
memcpy(D+A,DSDWORD[Y],B);
}
ELSE IF(cmd==PY_MUL)
{
B = D;
E = DSDWORD[X];
WHILE(C)
{
memcpy(B,E,A);
B+=4;
C--;
}
}
 
DSDWORD[#RDATA] = D;
DSBYTE[#RDATA+4] = PY_STR;
DSDWORD[#RDATA+5] = length;
DSDWORD[#RDATA+9] = buffer;
pushStack(#RDATA);
return;
}
if(E==PY_INT)
{
switch(cmd)
{
case PY_ADD:
DSDWORD[X] += DSDWORD[Y];
break;
case PY_POW:
length = DSDWORD[Y];
D = DSDWORD[X];
DSDWORD[X] = 1;
WHILE(length) {DSDWORD[X]*=D; length--;}
break;
case PY_SUB:
DSDWORD[X] -= DSDWORD[Y];
break;
case PY_MUL:
DSDWORD[X] *= DSDWORD[Y];
break;
case PY_MOD:
DSDWORD[X] = DSDWORD[X]%DSDWORD[Y];
break;
case PY_XOR:
DSDWORD[X] ^= DSDWORD[Y];
break;
case PY_AND:
DSDWORD[X] &= DSDWORD[Y];
break;
case PY__OR:
DSDWORD[X] |= DSDWORD[Y];
break;
case PY_LSH:
DSDWORD[X] <<= DSDWORD[Y];
break;
case PY_RSH:
DSDWORD[X] >>= DSDWORD[Y];
break;
case PY_FDV:
DSDWORD[X] /= DSDWORD[Y];
break;
case PY_TDV:
DSDWORD[X] /= DSDWORD[Y];
break;
}
}
}
:void binary(byte cmd)
{
dword buffer = 0;
dword length = 0;
Y = popStack();
X = popStack();
IF(cmd==PY_ADD) checkType(X,Y);
E = DSBYTE[X+4];
if(E==PY_STR)
{
A = DSDWORD[X+5];
IF(cmd==PY_ADD) B = DSDWORD[Y+5];
ELSE
{
C = DSDWORD[Y];
B = C*A;
}
length = A+B;
buffer = length+MEMBUF;
D = malloc(buffer);
 
IF(cmd==PY_ADD)
{
memcpy(D,DSDWORD[X],A);
memcpy(D+A,DSDWORD[Y],B);
}
ELSE IF(cmd==PY_MUL)
{
B = D;
E = DSDWORD[X];
WHILE(C)
{
memcpy(B,E,A);
B+=4;
C--;
}
}
 
DSDWORD[#RDATA] = D;
DSBYTE[#RDATA+4] = PY_STR;
DSDWORD[#RDATA+5] = length;
DSDWORD[#RDATA+9] = buffer;
pushStack(#RDATA);
return;
}
if(E==PY_INT)
{
switch(cmd)
{
case PY_ADD:
A = DSDWORD[X] + DSDWORD[Y];
break;
case PY_POW:
length = DSDWORD[Y];
D = DSDWORD[X];
DSDWORD[Z] = 1;
WHILE(length) {A*=D; length--;}
break;
case PY_SUB:
A = DSDWORD[X] - DSDWORD[Y];
break;
case PY_MUL:
A = DSDWORD[X] * DSDWORD[Y];
break;
case PY_MOD:
A = DSDWORD[X] % DSDWORD[Y];
break;
case PY_XOR:
A = DSDWORD[X] ^ DSDWORD[Y];
break;
case PY_AND:
A = DSDWORD[X] & DSDWORD[Y];
break;
case PY__OR:
A = DSDWORD[X] | DSDWORD[Y];
break;
case PY_LSH:
A = DSDWORD[X] << DSDWORD[Y];
break;
case PY_RSH:
A = DSDWORD[X] >> DSDWORD[Y];
break;
case PY_FDV:
A = DSDWORD[X] / DSDWORD[Y];
break;
case PY_TDV:
A = DSDWORD[X] / DSDWORD[Y];
break;
}
load_const(A,PY_INT,0);
}
}
 
:byte del(dword v)
{
dword x = 0;
x = DSDWORD[v];
IF(x)
{
IF(DSDWORD[x+9]) free(DSDWORD[x]);
free(x);
DSDWORD[v] = 0;
RETURN 1;
}
RETURN 0;
}
:void build_class(dword count)
{
dword name = 0;
dword func = 0;
func = popFast();
name = popFast();
load_const(func,PY_CLS,0);
}
:void load_build_class()
{
load_const(#build_class,PY_FNC,0);
}
:void make_function()
{
stack-=4;
}
:void store_name(dword x)
{
dword tmp = 0;
dword stk = 0;
stk = popStack();
IF(!DSDWORD[x])
{
tmp = malloc(30);
memcpy(tmp,stk,30);
DSDWORD[x] = tmp;
return;
}
memcpy(DSDWORD[x],stk,30);
}
:void rot(dword x,y)
{
EAX = DSDWORD[stack-8];
DSDWORD[stack-8] = DSDWORD[stack-4];
DSDWORD[stack-4] = EAX;
}
:void build_tuple(dword len)
{
dword tuple = 0;
dword buf = 0;
dword l = 0;
l = len;
tuple = malloc(4*len+MEMBUF);
buf = tuple;
WHILE(len)
{
DSDWORD[buf] = popStack();
buf+=4;
len--;
}
load_const(tuple,PY_TPL,l);
}
:void unpack_sequence(dword len)
{
dword tuple = 0;
dword x = 0;
popStack();
tuple = DSDWORD[EAX];
 
WHILE(len)
{
pushStack(DSDWORD[tuple]);
tuple+=4;
len--;
}
}
:void rot_two()
{
rot(DSDWORD[stack-8],DSDWORD[stack-4]);
}
:void rot_three()
{
rot(DSDWORD[stack-12],DSDWORD[stack-4]);
rot(DSDWORD[stack-8],DSDWORD[stack-4]);
}
:void load_name(dword addr)
{
pushStack(addr);
}
:void load_global(dword addr)
{
pushStack(addr);
}
:dword strlen(dword txt)
{
dword i = 0;
i = txt;
WHILE(DSBYTE[i]) i++;
RETURN i - txt;
}
:dword hashString(dword x)
{
dword l = 0;
dword h = 0;
l = x;
WHILE(DSBYTE[x])
{
h+=DSBYTE[x];
h<<=1;
x++;
h/=x-l;
}
return h;
}
 
 
:void pop_top()
{
stack-=4;
}
:void load_fast(dword addr)
{
dword x = 0;
IF(!DSDWORD[addr])
{
x = popFast();
DSDWORD[addr] = x;
}
ELSE x = DSDWORD[addr];
pushStack(x);
}
:void call_function(dword arg)
{
dword count = 0;
dword func = 0;
byte type = 0;
dword stackRet = 0;
count = arg;
WHILE(count)
{
pushFast(popStack());
count--;
}
func = popStack();
//IF(DSBYTE[Z+4]!=PY_FNC) test("No function!",0);
type = DSBYTE[func+4];
func = DSDWORD[func];
IF(!func)
{
test1("Null function!",0);
pushStack(0);
return;
}
IF(type==PY_FNC)
{
stackRet = stack;
func(arg);
IF(stackRet == stack) load_const(0,PY_NONE,0);
}
ELSE IF(type==PY_CLS)
{
stackRet = stack;
func(arg);
IF(stackRet == stack) load_const(0,PY_NONE,0);
}
stackFast = beginStackFast;
}
:void call_method(dword arg)
{
dword count = 0;
dword func = 0;
byte type = 0;
dword stackRet = 0;
count = arg;
WHILE(count)
{
pushFast(popStack());
count--;
}
func = popStack();
//IF(DSBYTE[Z+4]!=PY_FNC) test("No function!",0);
type = DSBYTE[func+4];
func = DSDWORD[func];
IF(!func)
{
test1("Null function!",0);
pushStack(0);
return;
}
IF(type==PY_FNC)
{
stackRet = stack;
func(arg);
IF(stackRet == stack) load_const(0,PY_NONE,0);
}
ELSE IF(type==PY_CLS)
{
func(arg);
pushStack(EAX);
}
stackFast = beginStackFast;
}
:void load_method(dword name)
{
dword x = 0;
dword data = 0;
dword get = 0;
x = popStack();
data = DSDWORD[x];
get = dictGet(DSDWORD[data],name);
pushStack(get);
}
:void append(dword count)
{
dword x = 0;
dword y = 0;
x = popFast();
y = popFast();
test1(DSBYTE[x+4],1);
}
:void build_list(dword count)
{
dword n = 0;
dword mem = 0;
dword i = 0;
dword tmp = 0;
dword method = 0;
 
mem = malloc(count*4+MEMBUF);
i = count;
n = i*4+mem+4;
load_const(#append,PY_FNC,0);
dictSet(#method,"append",popStack());
DSDWORD[mem] = method;
WHILE(i)
{
n-=4;
tmp = malloc(30);
memcpy(tmp,popStack(),30);
DSDWORD[n] = tmp;
i--;
}
load_const(mem,PY_LST,count);
}
:dword store_fast()
{
return popStack();
}
 
:void binary_subscr()
{
dword x = 0;
dword y = 0;
dword l1 = 0;
dword l2 = 0;
dword tmp = 0;
dword ret = 0;
byte t = 0;
x = popStack();
y = popStack();
//IF(DSBYTE[x+4]!=PY_INT) error type;
 
l1 = DSDWORD[y+5];
t = DSBYTE[y+4];
IF(t==PY_LST)
{
IF(l1<=x) test1("error max list",0);
IF(0>l1) test1("error min list",0);
y = DSDWORD[y];
pushStack(DSDWORD[x*4+y]);
return;
}
IF(t==PY_DCT)
{
y = DSDWORD[y]; // data object
SWITCH(DSBYTE[x+4])
{
CASE PY_INT:
test1(DSDWORD[y],1);
x = arrayGet(DSDWORD[y],DSDWORD[x]);
BREAK;
CASE PY_STR:
x = dictGet(DSDWORD[y],DSDWORD[x]);
BREAK;
}
pushStack(x);
//test1(DSBYTE[x+4],1);
return;
}
IF(t==PY_STR)
{
x = DSDWORD[x];
IF (l1<=x)||(l1<0) test1("IndexError: string index out of range",0);
y = DSDWORD[y];
tmp = malloc(MEMBUF);
ret = malloc(30);
DSBYTE[tmp] = DSBYTE[x+y];
DSDWORD[ret] = tmp;
DSBYTE[ret+4] = PY_STR;
DSDWORD[ret+5] = 1;
DSDWORD[ret+9] = MEMBUF;
pushStack(ret);
 
return;
}
}
:void build_slice(dword count)
{
}
/*
 
:void call_function(dword arg)
{
dword x = 0;
 
dword c = arg;
dword o = 0;
dword v = 0;
WHILE(c)
{
o+=4;
popStack();
$push eax
c--;
}
$push arg
v = popStack();
IF(DSBYTE[v+4]!=PY_FNC) test("No function!",0);
v = DSDWORD[v];
IF(!v)
{
test(1,1);
pushStack(0);
return;
}
$call v
ESP+=o;
pushStack(EAX);
}
*/
/programs/cmm/experimental/python/examples/example.py
0,0 → 1,3
text1 = "Hello"
text2 = "World!"
stdout(text1+' '+text2)
/programs/cmm/experimental/python/examples/dectohex.py
0,0 → 1,10
def test(x):
f = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
txt = ""
while x:
txt = f[x&0xF]+txt
x = x>>4
return txt
stdout(test(0x123454))
/programs/cmm/misc/Tupfile.lua
0,0 → 1,13
if tup.getconfig("NO_CMM") ~= "" then return end
if tup.getconfig("LANG") == "ru"
then C_LANG = "LANG_RUS"
else C_LANG = "LANG_ENG" -- this includes default case without config
end
tup.rule("easyshot.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "easyshot.com")
tup.rule("calypte.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "calypte.com")
tup.rule("kolibrin.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "kolibrin.com")
tup.rule("mblocks.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "mblocks.com")
tup.rule("notify.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "notify.com")
tup.rule("pipet.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "pipet.com")
tup.rule("software_widget.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "software_widget.com")
 
/programs/cmm/misc/build.bat
0,0 → 1,13
@echo off
 
del *.kex
 
For /R %%i In (*.c) Do c-- "%%i"
 
rename *.com *.kex
mkdir bin
move *.kex bin\
 
del warning.txt
 
pause
/programs/cmm/misc/calypte.c
0,0 → 1,492
//Calypte 0.35 - Leency
//Calypte 0.15 - Punk Joker
 
/*
TODO
- word wrap
- draw by line
- text selection
*/
 
#define MEMSIZE 1024*200
 
#ifndef AUTOBUILD
#include "lang.h--"
#endif
 
//===================================================//
// //
// LIB //
// //
//===================================================//
 
#include "../lib/kolibri.h"
#include "../lib/fs.h"
#include "../lib/gui.h"
#include "../lib/list_box.h"
#include "../lib/collection.h"
 
#include "../lib/obj/iconv.h"
#include "../lib/obj/box_lib.h"
#include "../lib/obj/libio.h"
#include "../lib/obj/proc_lib.h"
#include "../lib/obj/librasterworks.h"
 
#include "../lib/patterns/simple_open_dialog.h"
 
//===================================================//
// //
// DATA //
// //
//===================================================//
 
char default_dir[] = "/rd/1";
od_filter filter2 = { 8, "TXT\0\0" };
 
/*========= MENU ==========*/
?define MENU1 "File"
?define MENU2 "Encoding"
?define MENU3 "Reopen"
 
char menu_file_list[] =
"Open|Ctrl+O
Close
Properties
Exit";
 
char menu_encoding_list[] =
"UTF-8
KOI8-RU
CP1251
CP1252
ISO8859-5
CP866";
 
char menu_reopen_list[] =
"Tinypad
TextEdit
TextRead
WebView
FB2Read
HexView";
 
enum
{
MENU_ID_FILE=10,
FILE_SUBMENU_ID_OPEN=10,
FILE_SUBMENU_ID_CLOSE,
FILE_SUBMENU_ID_PROPERTIES,
FILE_SUBMENU_ID_EXIT,
 
MENU_ID_ENCODING=20,
 
MENU_ID_REOPEN=30,
FILE_SUBMENU_ID_TINYPAD=30,
FILE_SUBMENU_ID_TEXTEDIT,
FILE_SUBMENU_ID_TEXTREAD,
FILE_SUBMENU_ID_WEBVIEW,
FILE_SUBMENU_ID_FB2READ,
FILE_SUBMENU_ID_HEXVIEW
};
 
int menu_file_x = 6;
int menu_encoding_x = NULL;
int menu_reopen_x = NULL;
/*======== MENU END ==========*/
 
#define TITLE "Calypte v0.38 dev"
char win_title[4096] = TITLE;
 
#define TOPPANELH 23
#define BOTPANELH 10
#define WIN_W 750
#define WIN_H 550
#define SCROLL_SIZE 15
 
proc_info Form;
llist rows;
 
int encoding;
dword old_width,old_height;
 
dword bufpointer;
dword bufsize;
 
scroll_bar scroll_v = { SCROLL_SIZE,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
scroll_bar scroll_h = { SCROLL_SIZE,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
 
collection s;
 
//===================================================//
// //
// CODE //
// //
//===================================================//
 
void main()
{
int id;
 
load_dll(boxlib, #box_lib_init, 0);
load_dll(libio, #libio_init, 1);
//load_dll(libini, #lib_init, 1);
load_dll(iconv_lib, #iconv_open, 0);
load_dll(Proc_lib, #OpenDialog_init,0);
load_dll(librasterworks, #rasterworks_drawText,0);
OpenDialog_init stdcall (#o_dialog);
 
if (param)
{
draw_window();
OpenFile(#param);
Prepare();
DrawText();
}
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
 
loop()
{
switch(WaitEvent())
{
case evMouse:
mouse.get();
rows.wheel_size = 3;
if (rows.MouseScroll(mouse.vert))
{
DrawText();
}
break;
case evButton:
id=GetButtonID();
if (id==1)
{
ExitProcess();
}
if (id==MENU_ID_FILE)
{
EventShowMenu(menu_file_x, #menu_file_list, MENU_ID_FILE, NULL);
}
if (id==MENU_ID_ENCODING)
{
EventShowMenu(menu_encoding_x, #menu_encoding_list, MENU_ID_ENCODING, encoding+1);
}
if (id==MENU_ID_REOPEN)
{
EventShowMenu(menu_reopen_x, #menu_reopen_list, MENU_ID_REOPEN, NULL);
}
break;
case evKey:
GetKeys();
if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL)
{
if (key_scancode == SCAN_CODE_KEY_O)
{
EventOpenFile();
}
break;
}
if (rows.ProcessKey(key_scancode))
{
DrawText();
}
break;
case evReDraw:
if (CheckActiveProcess(Form.ID)) EventMenuClick();
draw_window();
break;
}
}
}
 
int DrawMenuButton(dword x,y,id,text)
{
int textlen = strlen(text)*8;
int padding = 12;
DefineHiddenButton(x, y, textlen+padding+padding, TOPPANELH-2, id);
WriteText(x+padding,y+4, 0x90, MixColors(sc.work, sc.work_text, 70), text);
return textlen+padding+padding;
}
 
void draw_window()
{
sc.get();
DefineAndDrawWindow(screen.width-WIN_W/2,screen.height-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title,0);
GetProcessInfo(#Form, SelfInfo);
DrawBar(0, 0, Form.cwidth, TOPPANELH-1, sc.work);
DrawBar(0, TOPPANELH-1, Form.cwidth, 1, sc.work_dark);
DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, sc.work);
menu_encoding_x = menu_file_x + DrawMenuButton(menu_file_x, 0, MENU_ID_FILE, MENU1);
menu_reopen_x = menu_encoding_x + DrawMenuButton(menu_encoding_x, 0, MENU_ID_ENCODING, MENU2);
DrawMenuButton(menu_reopen_x, 0, MENU_ID_REOPEN, MENU3);
 
if (old_width!=Form.width) || (old_height!=Form.height)
{
old_width = Form.width;
old_height = Form.height;
rows.no_selection = true;
rows.SetFont(8, 14, 0x90);
rows.SetSizes(0, TOPPANELH, Form.cwidth - SCROLL_SIZE, Form.cheight - TOPPANELH - BOTPANELH, 20);
rows.column_max = rows.w / rows.font_w;
 
if (bufpointer)
{
Prepare();
}
rows.CheckDoesValuesOkey();
}
DrawRectangle(rows.x+rows.w-1, rows.y, SCROLL_SIZE, rows.h-1, 0xEEEeee);
DrawText();
}
 
void OpenFile(dword _path)
{
strcpy(#param, _path);
sprintf(#win_title, "%s - %s", TITLE, #param);
rows.KeyHome();
file_size stdcall (#param);
bufsize = EBX;
if (bufsize)
{
bufpointer = mem_Free(bufpointer);
bufpointer = mem_Alloc(bufsize);
if (ReadFile(0, bufsize, bufpointer, #param) != 0)
{
bufpointer = 0;
notify("'Error opening file'-E");
return;
}
}
if (encoding!=CH_CP866)
{
ChangeCharset(encoding, "CP866", bufpointer);
}
}
 
enum
{
PARSE_CALCULATE_ROWS_COUNT,
PARSE_DRAW_PREPARE,
};
 
void Parse(int mode)
{
int pos=0;
int sub_pos=0;
int len_str = 0;
bool do_eof = false;
word bukva[2];
 
while(1)
{
while(1)
{
bukva = DSBYTE[bufpointer+pos+len_str];
if (bukva=='\0')
{
do_eof = true;
break;
}
if (bukva==0x0a)
{
break;
}
else
{
len_str++;
}
}
if (len_str<=rows.column_max)
{
if (mode==PARSE_DRAW_PREPARE)
{
s.addn(bufpointer+pos, len_str);
}
pos += len_str+1;
}
else
{
if (mode==PARSE_DRAW_PREPARE)
{
s.addn(bufpointer+pos, rows.column_max);
}
pos += rows.column_max;
}
sub_pos++;
if (mode==PARSE_CALCULATE_ROWS_COUNT) && (do_eof)
{
break;
}
if (mode==PARSE_DRAW_PREPARE) && (pos>=bufsize-1)
{
break;
}
len_str = 0;
}
if (mode == PARSE_CALCULATE_ROWS_COUNT)
{
rows.count = sub_pos;
Parse(PARSE_DRAW_PREPARE);
}
}
 
void Prepare()
{
Parse(PARSE_CALCULATE_ROWS_COUNT);
}
 
void DrawText()
{
int i=0, top;
 
if (rows.count<rows.visible)
{
top = rows.count;
}
else
{
if (rows.count-rows.first<=rows.visible)
{
top = rows.count-rows.first-1;
}
else
{
top = rows.visible;
}
}
 
if (bufpointer)
{
for (i=0; i<top; i++)
{
DrawBar(0, i*rows.item_h+TOPPANELH, rows.w, rows.item_h, 0xFFFFFF);
WriteText(2, i*rows.item_h+TOPPANELH, 0x90, 0x000000, s.get(i+rows.first));
}
}
DrawBar(0, i*rows.item_h+rows.y, rows.w, -i*rows.item_h + rows.h, 0xFFFfff);
DrawVerticalScroll();
}
 
void DrawVerticalScroll()
{
scroll_v.max_area = rows.count;
scroll_v.cur_area = rows.visible;
scroll_v.position = rows.first;
scroll_v.start_y = rows.y;
scroll_v.size_y = rows.h;
scroll_v.start_x = rows.w + rows.x -1;
scroll_v.all_redraw = 0;
scrollbar_v_draw(#scroll_v);
}
 
//===================================================//
// //
// EVENTS //
// //
//===================================================//
dword menu_id;
void EventMenuClick()
{
dword click_id = get_menu_click();
if (click_id) switch(click_id + menu_id - 1)
{
//File
case FILE_SUBMENU_ID_OPEN:
EventOpenFile();
break;
case FILE_SUBMENU_ID_CLOSE:
EventCloseFile();
break;
case FILE_SUBMENU_ID_PROPERTIES:
EventShowFileProperties();
break;
case FILE_SUBMENU_ID_EXIT:
ExitProcess();
break;
//Encoding
case MENU_ID_ENCODING...MENU_ID_ENCODING+9:
EventChangeEncoding(click_id-1);
break;
//Reopen
case FILE_SUBMENU_ID_TINYPAD:
EventOpenFileInAnotherProgram("/sys/tinypad");
break;
case FILE_SUBMENU_ID_TEXTEDIT:
EventOpenFileInAnotherProgram("/sys/develop/t_edit");
break;
case FILE_SUBMENU_ID_TEXTREAD:
EventOpenFileInAnotherProgram("/sys/txtread");
break;
case FILE_SUBMENU_ID_WEBVIEW:
EventOpenFileInAnotherProgram("/sys/network/webview");
break;
case FILE_SUBMENU_ID_FB2READ:
EventOpenFileInAnotherProgram("/sys/fb2read");
break;
case FILE_SUBMENU_ID_HEXVIEW:
EventOpenFileInAnotherProgram("/sys/develop/heed");
break;
}
}
 
void EventShowMenu(dword _menu_item_x, _menu_list, _id, _selected)
{
open_lmenu(Form.left+5 + _menu_item_x, Form.top+skin_height + TOPPANELH,
MENU_ALIGN_TOP_LEFT, _selected, _menu_list);
menu_id = _id;
}
 
void EventOpenFile()
{
OpenDialog_start stdcall (#o_dialog);
if (o_dialog.status)
{
OpenFile(#openfile_path);
Prepare();
draw_window();
}
}
 
void EventCloseFile()
{
if (bufpointer)
{
s.drop();
bufpointer = mem_Free(bufpointer);
strcpy(#win_title, TITLE);
draw_window();
}
}
 
void EventShowFileProperties()
{
char ss_param[4096];
if (bufpointer)
{
sprintf(#ss_param, "-p %s", #param);
RunProgram("/sys/File managers/Eolite", #ss_param);
}
}
 
void EventChangeEncoding(dword id)
{
encoding = id;
OpenFile(#openfile_path);
Prepare();
draw_window();
}
 
void EventOpenFileInAnotherProgram(dword _app)
{
RunProgram(_app, #param);
}
 
 
 
stop:
/programs/cmm/misc/easyshot.c
0,0 → 1,189
#define MEMSIZE 1024 * 50
#include "../lib/kolibri.h"
#include "../lib/strings.h"
#include "../lib/mem.h"
#include "../lib/gui.h"
 
#include "../lib/obj/libimg.h"
#include "../lib/obj/box_lib.h"
#include "../lib/obj/proc_lib.h"
 
#ifndef AUTOBUILD
#include "lang.h--"
#endif
 
/* === TRANSLATIONS === */
 
#ifdef LANG_RUS
?define T_TAKE_SCREENSHOT "‘¤¥« âì áªà¨­è®â"
?define T_SETTINGS " áâனª¨"
?define T_EDITBOX_FRAME "ãâì á®åà ­¥­¨ï áªà¨­è®â "
?define T_DELAY "‡ ¤¥à¦ª  ¢ ᥪ㭤 å"
?define T_NO_DIR "' ¯ª  ­¥ áãé¥áâ¢ã¥â!' -E"
#else
?define T_TAKE_SCREENSHOT "Take a screenshot"
?define T_SETTINGS "Settings"
?define T_EDITBOX_FRAME "Save path"
?define T_DELAY "Delay in seconds"
?define T_NO_DIR "'Directory does not exists!' -E"
#endif
 
/* === DATA === */
 
proc_info Form;
 
enum {
BTN_MAKE_SCREENSHOT=10,
BTN_SETTINGS,
BTN_CHOOSE_SAVING_PATH
};
 
#define PD 18 //padding
#define SETTINGS_Y PD+PD+30+10
 
char save_path[4096];
char open_dir[4096];
 
more_less_box delay = { 1, 0, SETTINGS_Y, T_DELAY };
edit_box edit_save = {260,PD,SETTINGS_Y+50,0xffffff,0x94AECE,0xFFFfff,0xffffff,
0x10000000,sizeof(save_path)-2,#save_path,0, 0b};
 
bool show_settings = false;
 
opendialog open_folder_dialog =
{
2, //0-file, 2-save, 3-select folder
#Form,
#communication_area_name,
0,
0, //dword opendir_path,
#open_dir, //dword dir_default_path,
#open_dialog_path,
#DrawWindow,
0,
#open_dir, //dword openfile_path,
0, //dword filename_area,
0, //dword filter_area,
420,
NULL,
320,
NULL
};
 
/* === CODE === */
 
void init_libraries()
{
load_dll(libio, #libio_init, 1);
load_dll(libimg, #libimg_init, 1);
load_dll(boxlib, #box_lib_init,0);
load_dll(Proc_lib, #OpenDialog_init,0);
OpenDialog_init stdcall (#open_folder_dialog);
}
 
void main()
{
int id;
 
init_libraries();
 
strcpy(#save_path, "/tmp0/1");
EditBox_UpdateText(#edit_save, 0);
 
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
loop() switch(WaitEvent())
{
case evMouse:
edit_box_mouse stdcall (#edit_save);
break;
 
case evButton:
id = GetButtonID();
switch(id){
case CLOSE_BTN: ExitProcess();
case BTN_MAKE_SCREENSHOT: EventTakeScreenshot(); break;
case BTN_SETTINGS: EventClickSettings(); break;
case BTN_CHOOSE_SAVING_PATH: EventChooseSavePath(); break;
default: delay.click(id);
}
break;
 
case evKey:
GetKeys();
if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot();
if (SCAN_CODE_ESC == key_scancode) ExitProcess();
EAX = key_editbox;
edit_box_key stdcall (#edit_save);
break;
case evReDraw:
DrawWindow();
}
}
 
 
void DrawWindow()
{
int i;
 
sc.get();
DefineAndDrawWindow(screen.width-400, screen.height/3, 270,
skin_height + 30+PD+PD, 0x34, sc.work, "EasyShot",0);
GetProcessInfo(#Form, SelfInfo);
 
DrawCaptButton(PD, PD, 170, 28, BTN_MAKE_SCREENSHOT, 0x0090B8, 0xFFFfff, T_TAKE_SCREENSHOT);
DefineButton(PD+170+20, PD, 35, 28, BTN_SETTINGS, sc.button);
for (i=0; i<=2; i++) DrawBar(PD+170+30, i*5+PD+9, 15, 2, sc.button_text);
delay.draw(PD, SETTINGS_Y);
DrawFileBox(#edit_save, T_EDITBOX_FRAME, BTN_CHOOSE_SAVING_PATH);
}
 
 
void EventChooseSavePath()
{
OpenDialog_start stdcall (#open_folder_dialog);
if (open_folder_dialog.status) {
strcpy(#save_path, open_folder_dialog.opendir_path);
EditBox_UpdateText(#edit_save, 0);
}
}
 
 
void EventClickSettings()
{
show_settings ^= 1;
MoveSize(OLD, OLD, show_settings*75 + 270,
show_settings*110 + skin_height + PD+PD+30);
}
 
 
void EventTakeScreenshot()
{
int i=0;
char save_file_name[4096];
static dword screenshot;
 
if (!screenshot) screenshot = malloc(screen.width * screen.height * 3);
 
do {
i++;
//sprintf(, "%s/screen_%i.png", #save_path, i);
strcpy(#save_file_name, #save_path);
if (save_file_name[strlen(#save_file_name)-1]!='/') chrcat(#save_file_name, '/');
strcat(#save_file_name, "screen_");
strcat(#save_file_name, itoa(i));
strcat(#save_file_name, ".png");
} while (file_exists(#save_file_name));
 
if (!dir_exists(#save_path)) {
notify(T_NO_DIR);
return;
}
 
MinimizeWindow();
pause(delay.value*100);
CopyScreen(screenshot, 0, 0, screen.width, screen.height);
save_image(screenshot, screen.width, screen.height, #save_file_name);
ActivateWindow(GetProcessSlot(Form.ID));
}
 
/programs/cmm/misc/mblocks.c
0,0 → 1,206
/*
Memory Blocks for KolibriOS v1.11
Leency&Veliant Edition
2008-2019
*/
 
#define MEMSIZE 4096 * 15
#include "..\lib\gui.h"
#include "..\lib\random.h"
 
#include "..\lib\obj\libio.h"
#include "..\lib\obj\libimg.h"
 
proc_info Form;
 
#ifndef AUTOBUILD
#include "lang.h--"
#endif
 
#define COLOR_CELL_BG 0xFFFfff
#define COLOR_CELL_BORDER 0x94AECE
#define CELL_SIZE 43
#define PANEL_Y CELL_SIZE+4*6 + 4
#define PANEL_H 36
 
#define strok 6 //cell count x
#define stolbcov 10 //cell count y
 
#ifdef LANG_RUS
#define LABEL_NEW_GAME "®¢ ï ¨£à  (F2)";
#else
#define LABEL_NEW_GAME "New game (F2)";
#endif
 
int bitstat[60], bitpict[60];
dword butonsx[60], butonsy[60];
dword firstbit, secondbit;
int count;
 
 
void main()
{
dword id;
load_dll(libio, #libio_init,1);
load_dll(libimg, #libimg_init,1);
 
Libimg_LoadImage(#skin, "/sys/icons32.png");
Libimg_FillTransparent(skin.image, skin.w, skin.h, COLOR_CELL_BG);
 
NewGame();
 
loop() switch(WaitEvent())
{
case evKey:
GetKeys();
if (key_scancode==60) NewGame();
break;
 
case evButton:
id = GetButtonID();
if (id==1) ExitProcess();
else if (id==5) NewGame();
else {
if (bitstat[id-100] == 0)
{
if (firstbit <> 0x0BAD)
{
if (secondbit <> 0x0BAD)
{
if (bitpict[firstbit-100] == bitpict[secondbit-100])
bitstat[firstbit-100] = bitstat[secondbit-100] = 2;
else
bitstat[firstbit-100] = bitstat[secondbit-100] = 0;
ReDraw_Game_Button(firstbit - 100);
ReDraw_Game_Button(secondbit - 100);
secondbit = 0x0BAD;
firstbit = id;
bitstat[id-100] = 1;
ReDraw_Game_Button(id - 100);
count++;
}
else if (firstbit<>id)
{
secondbit = id;
bitstat[id-100] = 1;
ReDraw_Game_Button(id - 100);
count++;
}
}
else
{
firstbit = id;
bitstat[id-100] = 1;
ReDraw_Game_Button(id - 100);
count++;
}
}
Draw_Count();
}
break;
 
case evReDraw:
sc.get();
DefineAndDrawWindow(215,100,CELL_SIZE+4*10 + 4 + 9,PANEL_Y+4+PANEL_H+skin_height,
0x34,0xC0C0C0,"Memory Blocks",0);
GetProcessInfo(#Form, SelfInfo);
Draw_Panel();
Draw_Game_Pole();
break;
}
}
 
void NewGame()
{
int off;
int i;
 
FOR (i = 0; i < 60; i++)
{
bitstat[i] = 0;
bitpict[i] = 0;
}
 
count = 0;
firstbit = secondbit = 0x0BAD;
FOR (i = 0; i < 30; i++)
{
do off = random(60); while (bitpict[off] != 0);
bitpict[off] = i;
do off = random(60); while (bitpict[off] != 0);
bitpict[off] = i;
}
Draw_Game_Pole();
Draw_Panel();
}
 
void ReDraw_Game_Button(int id)
{
DefineButton(butonsx[id], butonsy[id], CELL_SIZE, CELL_SIZE, 100 + id + BT_HIDE, 0);
switch (bitstat[id])
{
case 0:
Draw_Block(butonsx[id], butonsy[id]);
break;
case 1:
Draw_Pressed_Block(butonsx[id], butonsy[id]);
img_draw stdcall(skin.image, butonsx[id]+6, butonsy[id]+6, 32, 32, 0, bitpict[id]*32);
BREAK;
case 2:
Draw_Open_Block(butonsx[id], butonsy[id]);
img_draw stdcall(skin.image, butonsx[id]+6, butonsy[id]+6, 32, 32, 0, bitpict[id]*32);
BREAK;
}
}
 
void Draw_Game_Pole()
{
int i;
byte j;
for (j = 0; j < stolbcov; j++) for (i = 0; i < strok; i++)
{
butonsx[j*strok+i] = CELL_SIZE+4 * j + 4; //save coordinates to avoid
butonsy[j*strok+i] = CELL_SIZE+4 * i + 4; //their recalculation after
ReDraw_Game_Button(j*strok + i);
}
}
 
void Draw_Block(dword x, y)
{
DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border
DrawRectangle3D(x + 1, y + 1, CELL_SIZE-2, CELL_SIZE-2, 0xFFFFFF, 0xDEDEDE);//bump
DrawBar(x + 2, y + 2, CELL_SIZE-3, CELL_SIZE-3, 0xBDC7D6);//background
}
 
void Draw_Open_Block(dword x, y)
{
DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border
DrawBar(x + 1, y + 1, CELL_SIZE-1, CELL_SIZE-1, COLOR_CELL_BG);//background
}
 
void Draw_Pressed_Block(dword x, y)
{
DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border
DrawWideRectangle(x + 1, y + 1, CELL_SIZE-1, CELL_SIZE-1, 2, 0x94DB00);//border green
DrawBar(x + 3, y + 3, CELL_SIZE-5, CELL_SIZE-5, COLOR_CELL_BG);//background
}
 
void Draw_Panel()
{
DrawBar(0, PANEL_Y, Form.cwidth, 1, sc.work_dark);
DrawBar(0, PANEL_Y+1, Form.cwidth, 1, sc.work_light);
DrawBar(0, PANEL_Y+2, Form.cwidth, PANEL_H-2, sc.work);
DrawStandartCaptButton(9, PANEL_Y+5, 5, LABEL_NEW_GAME);
Draw_Count();
}
 
void Draw_Count()
{
DrawBar(Form.cwidth-32,PANEL_Y + 12,30,12,sc.work);
WriteNumber(Form.cwidth-32, PANEL_Y + 12, 0x90, sc.work_text, 3, count);
}
 
 
 
 
stop:
/programs/cmm/misc/notify.c
0,0 → 1,150
//notify 0.8
//SoUrcerer 2010, Leency 2012-2013, GNU GPLv2
 
#define MEMSIZE 0x2F00
#include "..\lib\kolibri.h"
#include "..\lib\strings.h"
#include "..\lib\mem.h"
#include "..\lib\gui.h"
 
dword shadow_buf_24, shadow_buf_32, lighter_pixel1, lighter_pixel2;
 
?define PADDING 15;
 
int SCREEN_SIZE_X,
SCREEN_SIZE_Y;
 
int WIN_X,
WIN_Y,
WIN_SIZE_X=256,
WIN_SIZE_Y=28;
 
int TEXT_X=PADDING,
TEXT_Y;
 
int delay = 400;
 
#ifdef LANG_RUS
?define DEFAULT_TEXT "â  ¯à®£à ¬¬  ¯®ª §ë¢ ¥â 㢥¤®¬«¥­¨ï.";
#else
?define DEFAULT_TEXT "This program shows notices. Open it with params.";
#endif
 
void PutText(dword x, y) {
WriteBufText(x,y, 0x88, 0, #param, shadow_buf_32);
}
 
void Text()
{
PutText(TEXT_X-1,TEXT_Y+1);
PutText(TEXT_X-1,TEXT_Y-1);
PutText(TEXT_X-1,TEXT_Y );
PutText(TEXT_X+1,TEXT_Y-1);
PutText(TEXT_X+1,TEXT_Y );
PutText(TEXT_X+1,TEXT_Y+1);
PutText(TEXT_X, TEXT_Y+1);
PutText(TEXT_X, TEXT_Y-1);
WriteBufText(TEXT_X, TEXT_Y, 0x88, 0xFFFfff, #param, shadow_buf_32);
}
 
void from24to32(ESI, EDI, EAX, EBX) //src,dst,w,h
{
conv24to32:
$mul ebx
$mov ecx, eax
$xor al, al
_next:
$movsw
$movsb
$stosb
$loop _next
}
 
void DrawBackground()
{
PutPaletteImage(shadow_buf_32+8,WIN_SIZE_X,WIN_SIZE_Y,0,0,32,0);
PutPixel(0,0,ESDWORD[lighter_pixel1]);
PutPixel(0,WIN_SIZE_Y-1,ESDWORD[lighter_pixel2]);
}
 
void GetBackground()
{
int i;
static int was_once;
 
if (was_once)
{
DrawBackground();
return;
}
for (i=1; i<=6; i++)
{
was_once = 1;
ShadowImage(shadow_buf_24, WIN_SIZE_X, WIN_SIZE_Y, 1);
if (i%2 == 0) ShadowImage(lighter_pixel1, 1, 1, 1);
if (i%2 == 0) ShadowImage(lighter_pixel2, 1, 1, 1);
from24to32(shadow_buf_24, shadow_buf_32+8, WIN_SIZE_X, WIN_SIZE_Y);
Text();
DrawBackground();
pause(5);
}
}
 
void Exit()
{
ExitProcess();
}
 
 
void main()
{
if (!param) strcpy(#param, DEFAULT_TEXT);
if (strlen(#param)*6>WIN_SIZE_X)
{
WIN_SIZE_X=strlen(#param)*6+PADDING;
delay = strlen(#param)*10;
}
 
SCREEN_SIZE_X=GetScreenWidth()+1;
WIN_X = SCREEN_SIZE_X-WIN_SIZE_X-1;
WIN_Y = GetClientTop();
TEXT_X = -6*strlen(#param)+WIN_SIZE_X/2+1;
TEXT_Y = WIN_SIZE_Y/2-4;
//emulate multithread :)
while (GetPixelColorFromScreen(SCREEN_SIZE_X-1, WIN_Y)==0x333333) WIN_Y+=WIN_SIZE_Y+17;
 
shadow_buf_24 = malloc(WIN_SIZE_X*WIN_SIZE_Y*3);
shadow_buf_32 = malloc(WIN_SIZE_X*WIN_SIZE_Y*4+8);
lighter_pixel1 = malloc(3);
lighter_pixel2 = malloc(3);
CopyScreen(shadow_buf_24, WIN_X, WIN_Y, WIN_SIZE_X, WIN_SIZE_Y);
CopyScreen(lighter_pixel1, WIN_X, WIN_Y, 1, 1);
CopyScreen(lighter_pixel2, WIN_X, WIN_Y+WIN_SIZE_Y, 1, 1);
ESDWORD[shadow_buf_32] = WIN_SIZE_X;
ESDWORD[shadow_buf_32+4] = WIN_SIZE_Y;
 
loop()
{
WaitEventTimeout(delay);
switch(EAX & 0xFF)
{
case evButton:
Exit();
break;
case evReDraw:
DefineAndDrawWindow(WIN_X+1,WIN_Y,WIN_SIZE_X, WIN_SIZE_Y-1, 0x01, 0, 0, 0x01fffFFF);
DrawBar(WIN_SIZE_X,0, 1, WIN_SIZE_Y, 0x333333);
DefineButton(0,0, WIN_SIZE_X, WIN_SIZE_Y, 1+BT_HIDE+BT_NOFRAME, 0);
GetBackground();
break;
 
default:
Exit();
}
}
}
 
 
stop:
/programs/cmm/misc/pipet.c
0,0 → 1,126
#define MEMSIZE 1024*20
 
#include "../lib/gui.h"
#include "../lib/clipboard.h"
#include "../lib/patterns/rgb.h"
 
//===================================================//
// //
// DATA //
// //
//===================================================//
 
dword pick_active = true;
dword picked_color = 0;
char picked_color_string[11];
#define FORM_W 167
#define FORM_H 60
#define COLOR_BLOCK_SIZE 42
#define COLOR_BLOCK_PADDING FORM_H - COLOR_BLOCK_SIZE / 2
#define COLOR_BLOCK_X FORM_W - COLOR_BLOCK_SIZE - COLOR_BLOCK_PADDING
#define BUTTON_ID_CLOSE 1
#define BUTTON_ID_COPY 2
#define BUTTON_ID_PICK 3
 
//===================================================//
// //
// CODE //
// //
//===================================================//
 
void main()
{
int btn;
proc_info Form;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE);
SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP);
loop() switch(WaitEvent())
{
case evMouse:
mouse.get();
if (mouse.x>0) && (mouse.x<FORM_W) && (mouse.y>0) && (mouse.y<FORM_H) {
EventDragWindow();
} else if (pick_active) {
picked_color = GetPixelColorFromScreen(mouse.x + Form.left, mouse.y + Form.top);
EventUpdateWindowContent();
if (mouse.down) && (mouse.key&MOUSE_LEFT) pick_active = false;
}
break;
 
case evButton:
btn = GetButtonID();
if (btn == BUTTON_ID_CLOSE) ExitProcess();
if (btn == BUTTON_ID_COPY) EventCopyHex();
if (btn == BUTTON_ID_PICK) pick_active = true;
break;
 
case evKey:
GetKeys();
if (key_scancode == SCAN_CODE_ESC) ExitProcess();
if (key_scancode == SCAN_CODE_KEY_C) EventCopyHex();
break;
case evReDraw:
DefineUnDragableWindow(215, 100, FORM_W, FORM_H);
GetProcessInfo(#Form, SelfInfo);
draw_window();
break;
}
}
 
void draw_window()
{
DrawRectangle3D(0, 0, FORM_W, FORM_H, 0xCCCccc, 0x888888);
DrawRectangle3D(1, 1, FORM_W-2, FORM_H-2, 0xCCCccc, 0x888888);
DrawBar(2,2,FORM_W-3,FORM_H-3,0xFFFfff);
 
DrawRectangle(COLOR_BLOCK_X-2, COLOR_BLOCK_PADDING-2, COLOR_BLOCK_SIZE+3, COLOR_BLOCK_SIZE+3, 0xCBC6C5);
DefineHiddenButton(COLOR_BLOCK_X-1, COLOR_BLOCK_PADDING-1, COLOR_BLOCK_SIZE+1, COLOR_BLOCK_SIZE+1, BUTTON_ID_PICK);
 
DrawCopyButton(67, 11, 35, 14);
 
EventUpdateWindowContent();
}
 
//copy of sprintf() => %A
void str2col(dword buf, number)
{
byte s;
strlcpy(buf,"0x00000000",10);
buf+=10;
while(number)
{
$dec buf
s=number&0xF;
if(s>9)DSBYTE[buf]='A'+s-10;
else DSBYTE[buf]='0'+s;
number>>=4;
}
}
 
void EventUpdateWindowContent()
{
//sprintf(#picked_color_string, "%A", picked_color);
str2col(#picked_color_string, picked_color);
rgb.DwordToRgb(picked_color);
WriteTextWithBg(12,12, 0xD0, 0x000111, #picked_color_string+4, 0xFFFfff);
WriteNumber(12,33, 0xD0, 0xff0000, 3, rgb.r);
WriteNumber(44,33, 0xD0, 0x008000, 3, rgb.g);
WriteNumber(75,33, 0xD0, 0x0000ff, 3, rgb.b);
 
DrawBar(COLOR_BLOCK_X, COLOR_BLOCK_PADDING, COLOR_BLOCK_SIZE, COLOR_BLOCK_SIZE, picked_color);
}
 
void DrawCopyButton(dword _x, _y, _w, _h)
{
DefineHiddenButton(_x+1, _y+1, _w-2, _h-2, BUTTON_ID_COPY);
DrawRectangle(_x, _y, _w, _h, 0x777777);
WriteText(_x+6, _h-8/2 + _y, 0x80, 0x555555, "Copy");
}
 
void EventCopyHex()
{
Clipboard__CopyText(#picked_color_string+4);
}
/programs/cmm/misc/software_widget.c
0,0 → 1,295
/*
SOFTWARE CENTER v2.86
*/
 
#define MEMSIZE 4096 * 15
#include "..\lib\strings.h"
#include "..\lib\mem.h"
#include "..\lib\io.h"
#include "..\lib\gui.h"
 
#include "..\lib\obj\libio.h"
#include "..\lib\obj\libimg.h"
#include "..\lib\obj\libini.h"
#include "..\lib\kfont.h"
#include "..\lib\list_box.h"
#include "..\lib\collection.h"
 
proc_info Form;
llist list;
collection app_path_collection;
bool kolibrios_mounted;
 
int window_width,
window_height;
 
int list_pos,
row,
col,
default_icon;
 
char window_title[128],
settings_ini_path[256];
 
bool small_screen = false;
 
struct SW_COLORS
{
dword list_bg;
dword text;
dword graph;
dword dark;
dword light;
} swc;
 
block selection[128];
 
void load_ini_config(dword _ini_path)
{
_ini ini;
ini.path = _ini_path;
ini.section = "Config";
ini.GetString("title", #window_title, sizeof(window_title), "Software widget");
window_width = ini.GetInt("win_width", 690);
list.item_w = ini.GetInt("cell_w", 73);
list.item_h = ini.GetInt("cell_h", 71);
default_icon = ini.GetInt("default_icon", 2);
}
 
void main()
{
dword id;
kfont.init(DEFAULT_FONT);
load_dll(libio, #libio_init,1);
load_dll(libimg, #libimg_init,1);
load_dll(libini, #lib_init,1);
 
kolibrios_mounted = dir_exists("/kolibrios");
 
if (param) {
strcpy(#settings_ini_path, #param);
} else {
strcpy(#settings_ini_path, "/sys/settings/");
strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/'));
strcat(#settings_ini_path, ".ini");
}
load_ini_config(#settings_ini_path);
list.cur_y = -1;
list.y = 32;
 
DrawList();
window_height = row+1*list.item_h + list_pos + skin_height + 15;
if (window_height>screen.height) {
window_width = screen.width;
list.item_h -= 5;
window_height = row+1*list.item_h + list_pos + skin_height + 15;
small_screen = true;
}
 
loop() switch(WaitEvent())
{
case evKey:
GetKeys();
if (SCAN_CODE_LEFT == key_scancode) key_scancode = SCAN_CODE_UP;
if (SCAN_CODE_RIGHT == key_scancode) key_scancode = SCAN_CODE_DOWN;
if (list.ProcessKey(key_scancode)) DrawSelection();
if (SCAN_CODE_ENTER == key_scancode) EventIconClick(list.cur_y);
break;
 
case evButton:
id=GetButtonID();
if (id==1) ExitProcess();
if (id>=100) EventIconClick(id-100);
break;
 
case evReDraw:
SetAppColors();
DefineAndDrawWindow(screen.width-window_width/2,screen.height-window_height/2,window_width,window_height,0x74,sc.work,"",0);
GetProcessInfo(#Form, SelfInfo);
if (Form.status_window>2) {
DrawTitle(#window_title);
break;
}
if (small_screen) {
DrawTitle(#window_title);
list.y = 0;
} else {
DrawTitle(NULL);
DrawTopBar();
}
DrawList();
DrawBar(0, row +1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, swc.list_bg);
DrawSelection();
}
}
 
void SetAppColors()
{
dword bg_col, old_list_bg_color;
sc.get();
old_list_bg_color = swc.list_bg;
bg_col = sc.work;
if (skin_is_dark())
{
//dark colors
swc.list_bg = sc.work;
swc.text = sc.work_text;
swc.dark = sc.work_dark;
swc.light = sc.work_light;
} else {
//light colors
swc.list_bg = 0xF3F3F3;
swc.text = 0x000000;
swc.dark = 0xDCDCDC;
swc.light = 0xFCFCFC;
}
 
if (swc.list_bg != old_list_bg_color)
{
Libimg_LoadImage(#skin, "/sys/icons32.png");
Libimg_FillTransparent(skin.image, skin.w, skin.h, swc.list_bg);
}
}
 
 
void DrawList() {
list.count = 0;
row = -1;
app_path_collection.drop();
list_pos = list.y;
list.column_max = window_width - 10 / list.item_w;
ini_enum_sections stdcall (#settings_ini_path, #process_sections);
list.visible = list.count;
}
 
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
{
int icon_id = default_icon,
icon_char_pos;
int space_pos;
 
dword icon_x, icon_y, text_x, text_y;
 
//do not show items located in /kolibrios/ if this directory not mounted
if (!strncmp(key_value, "/kolibrios/", 11)) || (!strncmp(key_value, "/k/", 3))
if (!kolibrios_mounted) return true;
 
if (col==list.column_max) {
row++;
col=0;
}
 
if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, swc.list_bg);
DefineButton(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-3,list.count + 100 + BT_HIDE,0);
 
icon_char_pos = strchr(key_value, ',');
icon_x = col*list.item_w+calc(list.item_w/2)-10;
icon_y = row*list.item_h+5 + list_pos;
selection[list.count].x = icon_x-2;
selection[list.count].y = icon_y-2;
if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string
app_path_collection.add(key_value);
 
text_x = col*list.item_w+5;
text_y = list.item_h - 40 / 2;
if (!strchr(key_name, ' ')) {//|| (kfont.getsize(key_name)+30<list.item_w) <== too slow
kfont.WriteIntoWindowCenter(text_x, row*list.item_h+46 + list_pos, list.item_w,0, swc.list_bg, swc.text, 12, key_name);
//WriteTextCenter(text_x, row*list.item_h+46 + list_pos+3, list.item_w, swc.text, key_name);
} else {
space_pos = strrchr(key_name, ' ');
ESBYTE[key_name+space_pos-1] = '\0';
kfont.WriteIntoWindowCenter(text_x, row*list.item_h+46 + list_pos - 2, list.item_w,0, swc.list_bg, swc.text, 12, key_name);
kfont.WriteIntoWindowCenter(text_x, row*list.item_h+46 + list_pos + 13, list.item_w,0, swc.list_bg, swc.text, 12, key_name+space_pos);
//WriteTextCenter(text_x, row*list.item_h+46 + list_pos, list.item_w, swc.text, key_name);
//WriteTextCenter(text_x, row*list.item_h+46 + list_pos + 10, list.item_w, swc.text, key_name+space_pos);
}
if (icon_char_pos) icon_id = atoi(icon_char_pos+1);
img_draw stdcall(skin.image, icon_x, icon_y, 32, 32, 0, icon_id*32);
list.count++;
col++;
return true;
}
 
 
int old_row; //to detect empty sections
byte process_sections(dword sec_name, f_name)
{
int text_len;
if (!strcmp(sec_name, "Config")) return true;
 
if ((col==0) && (row==old_row))
{
list_pos -= 28;
}
else
{
row++;
}
col = 0;
old_row = row;
 
if (!small_screen) {
DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, swc.list_bg);
text_len = kfont.WriteIntoWindow(10, row * list.item_h + 10 + list_pos, swc.list_bg, swc.text, 15, sec_name);
DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, swc.dark);
DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, swc.light);
list_pos += 29;
}
ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
return true;
}
 
void DrawTopBar()
{
DrawBar(0,0,Form.cwidth, list.y-2, sc.work);
DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(sc.work, sc.work_graph, 180));
DrawBar(0,list.y-1, Form.cwidth, 1, sc.work_graph);
kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, sc.work, sc.work_text, 16, #window_title);
}
 
void EventIconClick(dword appid)
{
char run_app_path[4096]=0;
dword app_path = app_path_collection.get(appid);
dword param_pos = strchr(app_path, '|');
if (param_pos) {
ESBYTE[param_pos] = NULL;
param_pos++;
}
 
// the next block is created to save some space in ramdisk{
//
// convert relative path to absolute "calc" => "/sys/calc"
// convert short kolibrios path to full "/k/calc" => "/kolibrios/calc"
// other copy => as is
if (ESBYTE[app_path]!='/') {
strcpy(#run_app_path, "/sys/");
}
else if (!strncmp(app_path, "/k/",3)) {
strcpy(#run_app_path, "/kolibrios/");
app_path+=3;
}
strcat(#run_app_path, app_path);
// }end
 
if (file_exists(#run_app_path)) {
io.run(#run_app_path, param_pos); //0 or offset
if (param_pos) ESBYTE[param_pos - 1] = '|';
} else {
notify("'Application not found' -E");
}
}
 
void DrawSelection()
{
int i;
dword col;
for (i=0; i<list.count; i++) {
if (i==list.cur_y) col=0x0080FF; else col=swc.list_bg;
DrawWideRectangle(selection[i].x, selection[i].y, 36, 36, 2, col);
}
}
 
 
stop: