forked from KolibriOS/kolibrios
source code library
git-svn-id: svn://kolibrios.org@5936 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
698f3bcead
commit
befac9b242
1
programs/develop/libraries/libs_v2/array.bat
Normal file
1
programs/develop/libraries/libs_v2/array.bat
Normal file
@ -0,0 +1 @@
|
||||
build.bat %~n0
|
244
programs/develop/libraries/libs_v2/array.c
Normal file
244
programs/develop/libraries/libs_v2/array.c
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
2015
|
||||
Author: Pavel Yakovlev.
|
||||
*/
|
||||
|
||||
#define LIB_NAME "array"
|
||||
|
||||
#include "coff.h"
|
||||
|
||||
#include <string.c>
|
||||
#include <stdlib.c>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
dword key;
|
||||
dword value;
|
||||
} array;
|
||||
|
||||
char *ARRAY_KEY_STRING = (char *)0;
|
||||
char *ARRAY_VALUE_STRING = (char *)0;
|
||||
array *ARRAY_ADRESS = (dword)0;
|
||||
|
||||
dword hash_binary(char *data,dword size)
|
||||
{
|
||||
byte h1,h2,h3,h4;
|
||||
if(!size) return 0;
|
||||
h1 = *data;
|
||||
if(size==1) return h1<<24;
|
||||
h2 = *++data;
|
||||
if(size==2) return (h1<<24)|(h2<<16);
|
||||
h3 = *++data;
|
||||
if(size==3) return (h1<<24)|(h2<<16)|(h3<<8);
|
||||
h4 = *++data;
|
||||
if(size==4) return (h1<<24)|(h2<<16)|(h3<<8)|(h4);
|
||||
|
||||
size-=4;
|
||||
|
||||
while(size--)
|
||||
{
|
||||
h1^=*data;h2^=*data;h3^=*data;h4^=*data;
|
||||
++data;
|
||||
}
|
||||
|
||||
return (h1<<24)|(h2<<16)|(h3<<8)|(h4);
|
||||
}
|
||||
dword hash_string(char *data)
|
||||
{
|
||||
byte h1,h2,h3,h4;
|
||||
if(!*data) return 0;
|
||||
h1 = *data;
|
||||
if(!*++data) return h1<<24;
|
||||
h2 = *data;
|
||||
if(!*++data) return (h1<<24)|(h2<<16);
|
||||
h3 = *data;
|
||||
if(!*++data) return (h1<<24)|(h2<<16)|(h3<<8);
|
||||
h4 = *data;
|
||||
if(!*++data) return (h1<<24)|(h2<<16)|(h3<<8)|(h4);
|
||||
|
||||
while(*data)
|
||||
{
|
||||
h1^=*data;h2^=*data;h3^=*data;h4^=*data;
|
||||
++data;
|
||||
}
|
||||
|
||||
return (h1<<24)|(h2<<16)|(h3<<8)|(h4);
|
||||
}
|
||||
|
||||
dword hash_integer(dword dec)
|
||||
{
|
||||
dword tmp = dec;
|
||||
tmp <<= 16;
|
||||
tmp ^= 0xFFFFFFFF;
|
||||
dec &= tmp;
|
||||
dec ^= dec>>5;
|
||||
dec += dec<<3;
|
||||
dec ^= dec>>13;
|
||||
tmp = dec<<9;
|
||||
tmp ^= 0xFFFFFFFF;
|
||||
dec += tmp;
|
||||
dec ^= dec>>17;
|
||||
return dec;
|
||||
}
|
||||
|
||||
dword buffer = 0xFF;
|
||||
dword ARRAY_COUNT = 0;
|
||||
dword tmp,tmp1;
|
||||
|
||||
array *key_string_set(dword *ary,char *key,void *data)
|
||||
{
|
||||
//dword *ptr = (dword *)ary;
|
||||
array *m;
|
||||
if(!*ary)
|
||||
{
|
||||
*ary = (dword)malloc(sizeof(array)*(buffer+1));
|
||||
m = (array *)*ary;
|
||||
m[0].value = buffer;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
m = (array *)*ary;
|
||||
if(m[0].value<=m[0].key)
|
||||
{
|
||||
m[0].value += buffer;
|
||||
*ary = (dword)realloc((void*)*ary,sizeof(array)*(m[0].value+1));
|
||||
}
|
||||
}
|
||||
|
||||
++m[0].key;
|
||||
|
||||
dword tmp = hash_string(key)%buffer;
|
||||
tmp+=(m[0].value/buffer)*buffer;
|
||||
++tmp;
|
||||
|
||||
while(m[tmp].key)
|
||||
{
|
||||
if(!strcmp(key,(char*)m[tmp].key))break;
|
||||
++tmp;
|
||||
}
|
||||
m[tmp].key = (dword)key;
|
||||
m[tmp].value = (dword)data;
|
||||
return m;
|
||||
}
|
||||
|
||||
array *key_binary_set(dword *ary,void *key,void *data,dword size)
|
||||
{
|
||||
|
||||
array *m;
|
||||
if(!*ary)
|
||||
{
|
||||
*ary = (dword)malloc(sizeof(array)*(buffer+1));
|
||||
m = (array *)*ary;
|
||||
m[0].value = buffer+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m = (array *)*ary;
|
||||
}
|
||||
|
||||
++m[0].key;
|
||||
|
||||
dword tmp = hash_string(key)%buffer;
|
||||
++tmp;
|
||||
while(m[tmp].key)
|
||||
{
|
||||
if(!strncmp((char*)key,(char*)m[tmp].key,size))break;
|
||||
++tmp;
|
||||
}
|
||||
m[tmp].key = (dword)key;
|
||||
m[tmp].value = (dword)data;
|
||||
return m;
|
||||
}
|
||||
|
||||
array *key_integer_set(dword *ary,dword key,void *data)
|
||||
{
|
||||
|
||||
|
||||
if(!*ary)
|
||||
{
|
||||
//(dword)m[0].value = (dword)buffer;
|
||||
*ary = (dword)malloc(sizeof(array)*(buffer+1));
|
||||
}
|
||||
|
||||
array *m = (array *)*ary;
|
||||
|
||||
dword tmp = hash_integer(key)%buffer;
|
||||
|
||||
while(m[tmp].key)
|
||||
{
|
||||
if(key==m[tmp].key)break;
|
||||
++tmp;
|
||||
}
|
||||
m[tmp].key = (dword)key;
|
||||
m[tmp].value = (dword)data;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
void *key_string_get(dword *ary,char *key)
|
||||
{
|
||||
if(!*ary)return 0;
|
||||
|
||||
array *m = (array *)*ary;
|
||||
|
||||
dword tmp = hash_string(key)%buffer;
|
||||
tmp+=(m[0].value/buffer)*buffer;
|
||||
++tmp;
|
||||
while(m[tmp].key)
|
||||
{
|
||||
if(!strcmp(key,(char*)m[tmp].key))break;
|
||||
++tmp;
|
||||
}
|
||||
return (void *)m[tmp].value;
|
||||
}
|
||||
|
||||
void *key_binary_get(dword *ary,char *key,dword size)
|
||||
{
|
||||
if(!*ary)return 0;
|
||||
|
||||
array *m = (array *)*ary;
|
||||
|
||||
dword tmp = hash_string(key)%buffer;
|
||||
|
||||
while(m[tmp].key)
|
||||
{
|
||||
if(!strncmp(key,(char*)m[tmp].key,size))break;
|
||||
++tmp;
|
||||
}
|
||||
return (void *)m[tmp].value;
|
||||
}
|
||||
|
||||
void *key_integer_get(dword *ary,dword key)
|
||||
{
|
||||
if(!*ary)return 0;
|
||||
|
||||
array *m = (array *)*ary;
|
||||
|
||||
dword tmp = hash_integer(key)%buffer;
|
||||
|
||||
while(m[tmp].key)
|
||||
{
|
||||
if(key==m[tmp].key)break;
|
||||
++tmp;
|
||||
}
|
||||
return (void *)m[tmp].value;
|
||||
}
|
||||
|
||||
|
||||
EXPORT_
|
||||
export(buffer)
|
||||
|
||||
export(hash_string)
|
||||
export(hash_binary)
|
||||
export(hash_integer)
|
||||
|
||||
export(key_string_set)
|
||||
export(key_binary_set)
|
||||
export(key_integer_set)
|
||||
|
||||
export(key_string_get)
|
||||
export(key_binary_get)
|
||||
export(key_integer_get)
|
||||
|
||||
_EXPORT
|
10
programs/develop/libraries/libs_v2/build.bat
Normal file
10
programs/develop/libraries/libs_v2/build.bat
Normal file
@ -0,0 +1,10 @@
|
||||
set FILE_NAME=%1
|
||||
set DIR_LIB=C:\Programs\KlbrInWin\LIB
|
||||
|
||||
del "%FILE_NAME%.obj"
|
||||
gcc -w --target=alpha-coff -nostdlib -I"./include" --prefix=/opt/cross-gcc -c -o "%FILE_NAME%.obj" "%FILE_NAME%.c"
|
||||
kpack %FILE_NAME%.obj
|
||||
@echo off
|
||||
copy "%FILE_NAME%.obj" "%DIR_LIB%\%FILE_NAME%.obj">Nul
|
||||
|
||||
pause
|
45
programs/develop/libraries/libs_v2/coff.h
Normal file
45
programs/develop/libraries/libs_v2/coff.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
2015
|
||||
Author: Pavel Yakovlev.
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *name;
|
||||
void *function;
|
||||
} export_t;
|
||||
|
||||
typedef unsigned long long qword;
|
||||
typedef unsigned int dword;
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned short word;
|
||||
|
||||
#define NULL ((void*)0)
|
||||
|
||||
#define quotess(name) #name
|
||||
|
||||
#ifdef NO_LIBIMPORT_FUNC
|
||||
#define EXPORT_ export_t EXPORTS[]={
|
||||
#else
|
||||
#define EXPORT_ export_t EXPORTS[]={{"lib_pointer_library",&lib_pointer_library},
|
||||
#endif
|
||||
|
||||
|
||||
#define export(name) {LIB_NAME "." quotess(name),&name},
|
||||
#define _EXPORT { NULL, NULL }};
|
||||
|
||||
#ifndef NO_LIBIMPORT_FUNC
|
||||
static struct LIBDLL_STRUCT
|
||||
{
|
||||
int (*load)(char *path);
|
||||
dword (*get)(char *name);
|
||||
};
|
||||
|
||||
static inline struct LIBDLL_STRUCT library;
|
||||
|
||||
static void lib_pointer_library(dword adr1,dword adr2)
|
||||
{
|
||||
library.load = adr1;
|
||||
library.get = adr2;
|
||||
}
|
||||
#endif
|
1
programs/develop/libraries/libs_v2/fs.bat
Normal file
1
programs/develop/libraries/libs_v2/fs.bat
Normal file
@ -0,0 +1 @@
|
||||
build.bat %~n0
|
897
programs/develop/libraries/libs_v2/fs.c
Normal file
897
programs/develop/libraries/libs_v2/fs.c
Normal file
@ -0,0 +1,897 @@
|
||||
/*
|
||||
2015
|
||||
Author: Pavel Yakovlev.
|
||||
*/
|
||||
|
||||
#define LIB_NAME "fs"
|
||||
|
||||
#include "coff.h"
|
||||
#include <kolibri.c>
|
||||
#include <stdlib.c>
|
||||
|
||||
|
||||
//char _PATH_[4096];
|
||||
char *_PATH_;
|
||||
dword *_ADR_ = 32;
|
||||
char *FS_SELF_PATH;
|
||||
char *FS_SELF_DIR=0;
|
||||
|
||||
char TMP1[4096] = {0};
|
||||
char TMP2[4096] = {0};
|
||||
|
||||
static void*(* _stdcall pointer_callback_copy)(void);
|
||||
static void*(* _stdcall pointer_callback_move)(void);
|
||||
static void*(* _stdcall pointer_callback_remove)(void);
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
unsigned p00;
|
||||
unsigned p04;
|
||||
unsigned p08;
|
||||
unsigned p12;
|
||||
unsigned p16;
|
||||
char p20;
|
||||
char *p21;
|
||||
} FS_struct70;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
unsigned p00;
|
||||
char p04;
|
||||
char p05[3];
|
||||
unsigned p08;
|
||||
unsigned p12;
|
||||
unsigned p16;
|
||||
unsigned p20;
|
||||
unsigned p24;
|
||||
unsigned p28;
|
||||
//unsigned p32[2];
|
||||
long long p32;
|
||||
unsigned p40;
|
||||
} FS_struct_BDVK;
|
||||
#pragma pack(pop)
|
||||
|
||||
#define FS_COPY_BUFFER_SET 0x100000
|
||||
static inline char BUF_COPY[FS_COPY_BUFFER_SET] = {0};
|
||||
|
||||
static inline char *string_error_code(char code)
|
||||
{
|
||||
if(!code)return "Successfully!";
|
||||
if(code==1)return "Not defined basis and / or hard disk partition (sub-functions 7, 8 function 21)!";
|
||||
if(code==2)return "Function is not supported for this file system!";
|
||||
if(code==3)return "Unknown file system!";
|
||||
if(code==4)return "Reserved, never returned to the current implementation!";
|
||||
if(code==5)return "File not found!";
|
||||
if(code==6)return "The file is ended!";
|
||||
if(code==7)return "Pointer out the application memory!";
|
||||
if(code==8)return "Disk is full!";
|
||||
if(code==9)return "FAT table is destroyed!";
|
||||
if(code==10)return "Access is denied!";
|
||||
if(code==11)return "Device error!";
|
||||
return "An unexpected error!";
|
||||
}
|
||||
|
||||
static inline dword sprintf(char *mstr,const char *fmt,...)
|
||||
{
|
||||
|
||||
dword *arg = &fmt;
|
||||
char *tmp = 0;
|
||||
char *pos = mstr;
|
||||
--pos;
|
||||
--fmt;
|
||||
while(*++fmt)
|
||||
{
|
||||
char s = *fmt;
|
||||
if(s=='%')
|
||||
{
|
||||
s = *++fmt;
|
||||
if(s=='s')
|
||||
{
|
||||
tmp = *++arg;
|
||||
while(*tmp)*++pos = *tmp++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*++pos='%';
|
||||
--fmt;
|
||||
}
|
||||
}
|
||||
else *++pos=s;
|
||||
}
|
||||
*++pos = 0;
|
||||
return pos-mstr;
|
||||
}
|
||||
|
||||
static inline int FS_file_70(FS_struct70 *k)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(70), "b"(k));
|
||||
}
|
||||
|
||||
FS_struct_BDVK ret_struct;
|
||||
static inline char get_bdvk(char *path)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 5;
|
||||
file_read_struct.p04 = 0;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = 0;
|
||||
file_read_struct.p16 = (unsigned)&ret_struct;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
return FS_file_70(&file_read_struct);
|
||||
//return (FS_struct_BDVK*)&ret_struct;
|
||||
}
|
||||
|
||||
static inline char set_bdvk(char *path,FS_struct_BDVK *bdvk)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 6;
|
||||
file_read_struct.p04 = 0;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = 0;
|
||||
file_read_struct.p16 = bdvk;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
return FS_file_70(&file_read_struct);
|
||||
}
|
||||
|
||||
static inline long long file_size(char *path)
|
||||
{
|
||||
FS_struct_BDVK *data = get_bdvk(path);
|
||||
return data->p32;
|
||||
}
|
||||
|
||||
static inline byte file_isdir(char *path)
|
||||
{
|
||||
FS_struct_BDVK *data = get_bdvk(path);
|
||||
if(data->p00&0b10000)return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline byte file_ismetka(char *path)
|
||||
{
|
||||
FS_struct_BDVK *data = get_bdvk(path);
|
||||
if(data->p00&0b1000)return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline byte file_isfile()
|
||||
{
|
||||
//FS_struct_BDVK *data = get_bdvk(path);
|
||||
if(ret_struct.p00&0b11000)return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int file_run(char *path,char *arg)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 7;
|
||||
file_read_struct.p04 = 0;
|
||||
file_read_struct.p08 = arg;
|
||||
file_read_struct.p12 = 0;
|
||||
file_read_struct.p16 = 0;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
return FS_file_70(&file_read_struct);
|
||||
|
||||
}
|
||||
|
||||
static inline int file_read_binary(char *path,unsigned pos,unsigned size,void *adr)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 0;
|
||||
file_read_struct.p04 = pos;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = size;
|
||||
file_read_struct.p16 = (unsigned)adr;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
char c = FS_file_70(&file_read_struct);
|
||||
if(c)
|
||||
{
|
||||
sprintf(&BUF_COPY,"'Error read file (%s) file: %s.'E",string_error_code(c),path);
|
||||
file_run("/sys/@notify",&BUF_COPY);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline int file_delete(char *path)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 8;
|
||||
file_read_struct.p04 = 0;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = 0;
|
||||
file_read_struct.p16 = 0;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
char c = FS_file_70(&file_read_struct);
|
||||
if(c)
|
||||
{
|
||||
sprintf(&BUF_COPY,"'Error delete file: %s. Info: %s'E",string_error_code(c),path);
|
||||
file_run("/sys/@notify",&BUF_COPY);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline int file_mkdir(char *path)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 9;
|
||||
file_read_struct.p04 = 0;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = 0;
|
||||
file_read_struct.p16 = 0;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
char c = FS_file_70(&file_read_struct);
|
||||
if(c)
|
||||
{
|
||||
sprintf(&BUF_COPY,"'Error make dir: %s. Info: %s.'E",string_error_code(c),path);
|
||||
file_run("/sys/@notify",&BUF_COPY);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline int file_write(char *path,void *ukaz,dword size)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 2;
|
||||
file_read_struct.p04 = 0;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = size;
|
||||
file_read_struct.p16 = ukaz;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
char c = FS_file_70(&file_read_struct);
|
||||
if(c)
|
||||
{
|
||||
sprintf(&BUF_COPY,"'Error write file: %s. Info: %s.'E",string_error_code(c),path);
|
||||
file_run("/sys/@notify",&BUF_COPY);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline int file_rewrite(char *path,dword pos1,dword pos2,void *ukaz,dword size)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 3;
|
||||
file_read_struct.p04 = pos1;
|
||||
file_read_struct.p08 = pos2;
|
||||
file_read_struct.p12 = size;
|
||||
file_read_struct.p16 = ukaz;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
char c = FS_file_70(&file_read_struct);
|
||||
if(c)
|
||||
{
|
||||
sprintf(&BUF_COPY,"'Error rewrite file (%s) file: %s.'E",string_error_code(c),path);
|
||||
file_run("/sys/@notify",&BUF_COPY);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
static inline char file_copy(char *path1,char *path2)
|
||||
{
|
||||
long long size = file_size(path1);
|
||||
if(!size)file_write(path2,&BUF_COPY,0);
|
||||
long long cel = size;
|
||||
cel /= FS_COPY_BUFFER_SET;
|
||||
dword ost = size-cel*FS_COPY_BUFFER_SET;
|
||||
long long i = 0;
|
||||
char err=0;
|
||||
if(cel)
|
||||
{
|
||||
if(file_read_binary(path1,0,FS_COPY_BUFFER_SET,&BUF_COPY))goto ERROR;
|
||||
if(file_write(path2,&BUF_COPY,FS_COPY_BUFFER_SET))goto ERROR;
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(file_read_binary(path1,0,ost,&BUF_COPY))goto ERROR;
|
||||
if(file_write(path2,&BUF_COPY,ost))goto ERROR;
|
||||
return 1;
|
||||
}
|
||||
while(i<cel)
|
||||
{
|
||||
if(file_read_binary(path1,FS_COPY_BUFFER_SET*i,FS_COPY_BUFFER_SET,&BUF_COPY))goto ERROR;
|
||||
if(file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,FS_COPY_BUFFER_SET))goto ERROR;
|
||||
++i;
|
||||
}
|
||||
if(file_read_binary(path1,FS_COPY_BUFFER_SET*i,ost,&BUF_COPY))goto ERROR;
|
||||
if(file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,ost))goto ERROR;
|
||||
return 1;
|
||||
ERROR:
|
||||
|
||||
//asm("":"=a"(err));
|
||||
//sprintf(&BUF_COPY,"Error %s file: %s.",string_error_code(err),path1);
|
||||
//file_run("/sys/@notify",&BUF_COPY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
dword FS_COPY_BUFFER_SET_POINT = 0x100000;
|
||||
dword BUF_COPY_POINT = 0;
|
||||
static inline char file_copy(char *path1,char *path2)
|
||||
{
|
||||
long long size = file_size(path1);
|
||||
if(!size)file_write(path2,BUF_COPY_POINT,0);
|
||||
long long cel = size;
|
||||
cel /= FS_COPY_BUFFER_SET_POINT;
|
||||
dword ost = size-cel*FS_COPY_BUFFER_SET_POINT;
|
||||
long long i = 0;
|
||||
char err=0;
|
||||
if(cel)
|
||||
{
|
||||
if(file_read_binary(path1,0,FS_COPY_BUFFER_SET_POINT,BUF_COPY_POINT))goto ERROR;
|
||||
if(file_write(path2,BUF_COPY_POINT,FS_COPY_BUFFER_SET_POINT))goto ERROR;
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(file_read_binary(path1,0,ost,BUF_COPY_POINT))goto ERROR;
|
||||
if(file_write(path2,BUF_COPY_POINT,ost))goto ERROR;
|
||||
return 1;
|
||||
}
|
||||
while(i<cel)
|
||||
{
|
||||
if(file_read_binary(path1,FS_COPY_BUFFER_SET_POINT*i,FS_COPY_BUFFER_SET_POINT,BUF_COPY_POINT))goto ERROR;
|
||||
if(file_rewrite(path2,FS_COPY_BUFFER_SET_POINT*i,0,BUF_COPY_POINT,FS_COPY_BUFFER_SET_POINT))goto ERROR;
|
||||
++i;
|
||||
}
|
||||
if(file_read_binary(path1,FS_COPY_BUFFER_SET_POINT*i,ost,BUF_COPY_POINT))goto ERROR;
|
||||
if(file_rewrite(path2,FS_COPY_BUFFER_SET_POINT*i,0,BUF_COPY_POINT,ost))goto ERROR;
|
||||
return 1;
|
||||
ERROR:
|
||||
|
||||
//asm("":"=a"(err));
|
||||
//sprintf(BUF_COPY_POINT,"Error %s file: %s.",string_error_code(err),path1);
|
||||
//file_run("/sys/@notify",BUF_COPY_POINT);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
#define FS_COPY_BUFFER_SET 0x100000
|
||||
char BUF_COPY[FS_COPY_BUFFER_SET] = {0};
|
||||
static inline char file_copy(char *path1,char *path2)
|
||||
{
|
||||
long long size = file_size(path1);
|
||||
if(!size)file_write(path2,&BUF_COPY,0);
|
||||
long long cel = size;
|
||||
cel /= FS_COPY_BUFFER_SET;
|
||||
dword ost = size-cel*FS_COPY_BUFFER_SET;
|
||||
long long i = 0;
|
||||
|
||||
if(cel)
|
||||
{
|
||||
file_read_binary(path1,0,FS_COPY_BUFFER_SET,&BUF_COPY);
|
||||
file_write(path2,&BUF_COPY,FS_COPY_BUFFER_SET);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
file_read_binary(path1,0,ost,&BUF_COPY);
|
||||
file_write(path2,&BUF_COPY,ost);
|
||||
return 1;
|
||||
}
|
||||
while(i<cel)
|
||||
{
|
||||
file_read_binary(path1,FS_COPY_BUFFER_SET*i,FS_COPY_BUFFER_SET,&BUF_COPY);
|
||||
file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,FS_COPY_BUFFER_SET);
|
||||
++i;
|
||||
}
|
||||
file_read_binary(path1,FS_COPY_BUFFER_SET*i,ost,&BUF_COPY);
|
||||
file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,ost);
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
long long size_long_file=0;
|
||||
|
||||
static inline void *file_read(char *path)
|
||||
{
|
||||
size_long_file = file_size(path);
|
||||
void *data = malloc(size_long_file+1);
|
||||
|
||||
if(file_read_binary(path,0,size_long_file,data))return 0;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static inline void *file_readKPACK(char *path)
|
||||
{
|
||||
void *data = 0;
|
||||
dword size=0;
|
||||
asm ("int $0x40":"=a"(data),"=d"(size):"a"(68), "b"(27), "c"(path));
|
||||
size_long_file = size;
|
||||
asm volatile(""::"c"(size));
|
||||
return data;
|
||||
}
|
||||
|
||||
static inline int file_read_dir(dword begin,dword file_count,dword read_buffer,char *dir_path)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 1;
|
||||
file_read_struct.p04 = begin;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = file_count;
|
||||
file_read_struct.p16 = read_buffer;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = dir_path;
|
||||
return FS_file_70(&file_read_struct);
|
||||
}
|
||||
|
||||
|
||||
static inline byte strncmp(char *s1,const char *s2, dword n)
|
||||
{
|
||||
while(n)
|
||||
{
|
||||
if(*s1!=*s2)return *s1-*s2;
|
||||
++s1;
|
||||
++s2;
|
||||
--n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *strdup(char *str)
|
||||
{
|
||||
char *r = malloc(strlen(str));
|
||||
strcpy(r,str);
|
||||
return r;
|
||||
}
|
||||
|
||||
char *self_get_dir(void)
|
||||
{
|
||||
if(!FS_SELF_DIR)
|
||||
{
|
||||
FS_SELF_DIR = malloc(4096);
|
||||
//FS_SELF_PATH = malloc(4096);
|
||||
//strcpy(FS_SELF_PATH,*_ADR_);
|
||||
FS_SELF_PATH = *_ADR_;
|
||||
int pos=0;
|
||||
int tmp=0;
|
||||
|
||||
while(FS_SELF_PATH[pos])
|
||||
{
|
||||
FS_SELF_DIR[pos] = FS_SELF_PATH[pos];
|
||||
if(FS_SELF_PATH[pos]=='/')tmp = pos;
|
||||
++pos;
|
||||
}
|
||||
if(tmp)pos=tmp;
|
||||
FS_SELF_DIR[pos]=0;
|
||||
}
|
||||
return FS_SELF_DIR;
|
||||
}
|
||||
|
||||
|
||||
char *get_full_path(char *path)
|
||||
{
|
||||
self_get_dir();
|
||||
if(!path) return FS_SELF_DIR;
|
||||
char *pos = path;
|
||||
if(!_PATH_) _PATH_ = malloc(4096);
|
||||
if(*pos=='/')
|
||||
{
|
||||
++pos;
|
||||
if(!strncmp(pos,"sys/",4)) return path;
|
||||
if(!strncmp(pos,"kolibrios/",10)) return path;
|
||||
if(!strncmp(pos,"rd/",3)) return path;
|
||||
if(!strncmp(pos,"fd/",3)) return path;
|
||||
if(!strncmp(pos,"cd",2)) return path;
|
||||
if(!strncmp(pos,"hd",2)) return path;
|
||||
if(!strncmp(pos,"bd",2)) return path;
|
||||
if(!strncmp(pos,"tmp",3)) return path;
|
||||
if(!strncmp(pos,"usbhd",5)) return path;
|
||||
if(!*pos)return path;
|
||||
strcpy(_PATH_,"/sys");
|
||||
strcpy(_PATH_+4,path);
|
||||
return _PATH_;
|
||||
}
|
||||
if(!strncmp(path,"./",2)) return path;
|
||||
sprintf(_PATH_,"%s/%s",FS_SELF_DIR,path);
|
||||
return _PATH_;
|
||||
}
|
||||
|
||||
long long FS_LENGHT=0;
|
||||
|
||||
dword *__BUF__COUNT__ = 0;
|
||||
int COUNT_FILE = 0;
|
||||
int _get_entries_count(char *path)
|
||||
{
|
||||
//char BUF[32];
|
||||
if(!__BUF__COUNT__)__BUF__COUNT__=malloc(32);
|
||||
if(!file_read_dir(0,0, __BUF__COUNT__, path))
|
||||
{
|
||||
if(strcmp(path,"/"))COUNT_FILE = *(__BUF__COUNT__+2)-2;
|
||||
else COUNT_FILE = *(__BUF__COUNT__+2);
|
||||
return COUNT_FILE;
|
||||
}
|
||||
COUNT_FILE = -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int get_entries_count(char *path)
|
||||
{
|
||||
return _get_entries_count(get_full_path(path));
|
||||
}
|
||||
|
||||
dword _get_dir_info(char *path)
|
||||
{
|
||||
_get_entries_count(path);
|
||||
if(!strcmp(path,"/"))
|
||||
{
|
||||
if(COUNT_FILE==-1)return 0;
|
||||
dword buffer = malloc(304*COUNT_FILE+72);
|
||||
file_read_dir(0,COUNT_FILE,buffer,path);
|
||||
return buffer;
|
||||
}
|
||||
if(COUNT_FILE==-1)return 0;
|
||||
dword buffer = malloc(304*COUNT_FILE+72);
|
||||
file_read_dir(2,COUNT_FILE+2,buffer,path);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
dword get_dir_info(char *path)
|
||||
{
|
||||
return _get_dir_info(get_full_path(path));
|
||||
}
|
||||
|
||||
dword get_dir_position(dword a,dword i)
|
||||
{
|
||||
return i*344+32+a;
|
||||
}
|
||||
|
||||
char *get_file_name(void *args)
|
||||
{
|
||||
return args+40;
|
||||
}
|
||||
|
||||
char BUF_HEADER[5]={0};
|
||||
dword read(char *path)
|
||||
{
|
||||
dword *adr = &BUF_HEADER;
|
||||
path = get_full_path(path);
|
||||
file_read_binary(path,0,4,adr);
|
||||
if(*adr=='KCPK') return file_readKPACK(path);
|
||||
dword ret = file_read(path);
|
||||
//FS_LENGHT = size_long_file;
|
||||
asm volatile(""::"c"((long)size_long_file));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
dword quantity_dir = 0,quantity_file = 0;
|
||||
long long fs_size_global = 0;
|
||||
long long LOOP_SIZE(char *path)
|
||||
{
|
||||
dword tmp_len = file_size(path);
|
||||
if(ret_struct.p00&0b10000)
|
||||
{
|
||||
++quantity_dir;
|
||||
dword tmp_buf = get_dir_info(path);
|
||||
if(COUNT_FILE<1) return 0;
|
||||
|
||||
char *new_path_file = malloc(4096);
|
||||
int tmp_count = COUNT_FILE;
|
||||
int i = 0;
|
||||
fs_size_global = 0;
|
||||
while(i<tmp_count)
|
||||
{
|
||||
sprintf(new_path_file,"%s/%s",path,304*i+tmp_buf+72);
|
||||
fs_size_global += LOOP_SIZE(new_path_file);
|
||||
++i;
|
||||
}
|
||||
free(tmp_buf);
|
||||
free(new_path_file);
|
||||
return fs_size_global;
|
||||
}
|
||||
++quantity_file;
|
||||
return tmp_len;
|
||||
}
|
||||
|
||||
dword get_size(char *path)
|
||||
{
|
||||
quantity_dir = 0;
|
||||
quantity_file = 0;
|
||||
long long size = LOOP_SIZE(get_full_path(path));
|
||||
if(quantity_dir>0)--quantity_dir;
|
||||
asm volatile(""::"c"(quantity_dir),"d"(quantity_file));
|
||||
return (dword)size;
|
||||
}
|
||||
|
||||
/*
|
||||
char set_attributes_loop(char *path,dword strucs)
|
||||
{
|
||||
if(get_bdvk(path))return 0;
|
||||
dword tmp = (ret_struct.p00^strucs)&0b111;
|
||||
ret_struct.p00=(tmp^ret_struct.p00)^0xFFFFFFFF;
|
||||
if(ret_struct.p00&0b10000)
|
||||
{
|
||||
dword tmp_buf = _get_dir_info(path);
|
||||
if(!COUNT_FILE) goto END;
|
||||
|
||||
char *new_path_file = malloc(4096);
|
||||
int tmp_count = COUNT_FILE;
|
||||
int i = 0;
|
||||
char *position = tmp_buf+72;
|
||||
while(i<tmp_count)
|
||||
{
|
||||
sprintf(new_path_file,"%s/%s",path,position);
|
||||
position+=304;
|
||||
if(!set_attributes_loop(new_path_file,strucs))
|
||||
{
|
||||
free(tmp_buf);
|
||||
free(new_path_file);
|
||||
return 0;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
free(new_path_file);
|
||||
END:
|
||||
free(tmp_buf);
|
||||
}
|
||||
if(set_bdvk(path,&ret_struct))return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char set_attributes(char *path,dword strucs,char cmd)
|
||||
{
|
||||
if(cmd)return set_attributes_loop(get_full_path(path),strucs);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
char remove_loop(char *path)
|
||||
{
|
||||
if(get_bdvk(path))return 0;
|
||||
if(ret_struct.p00&0b10000)
|
||||
{
|
||||
dword tmp_buf = _get_dir_info(path);
|
||||
if(!COUNT_FILE) goto END;
|
||||
|
||||
char *new_path_file = malloc(4096);
|
||||
int tmp_count = COUNT_FILE;
|
||||
int i = 0;
|
||||
char *position = tmp_buf+72;
|
||||
while(i<tmp_count)
|
||||
{
|
||||
sprintf(new_path_file,"%s/%s",path,position);
|
||||
position+=304;
|
||||
if(!remove_loop(new_path_file))
|
||||
{
|
||||
free(tmp_buf);
|
||||
free(new_path_file);
|
||||
return 0;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
free(new_path_file);
|
||||
END:
|
||||
free(tmp_buf);
|
||||
}
|
||||
if(file_delete(path))return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char remove(char *path)
|
||||
{
|
||||
return remove_loop(get_full_path(path));
|
||||
}
|
||||
|
||||
int make_dir(char *path)
|
||||
{
|
||||
return file_mkdir(get_full_path(path));
|
||||
}
|
||||
|
||||
char copy_loop(char *path1,char *path2)
|
||||
{
|
||||
if(get_bdvk(path1))return 0;
|
||||
if(ret_struct.p00&0b10000)
|
||||
{
|
||||
file_mkdir(path2);
|
||||
set_bdvk(path2,&ret_struct);
|
||||
dword tmp_buf = _get_dir_info(path1);
|
||||
if(!COUNT_FILE) goto END;
|
||||
|
||||
char *new_path_file1 = malloc(4096);
|
||||
char *new_path_file2 = malloc(4096);
|
||||
int tmp_count = COUNT_FILE;
|
||||
int i = 0;
|
||||
dword position = tmp_buf+72;
|
||||
while(i<tmp_count)
|
||||
{
|
||||
sprintf(new_path_file1,"%s/%s",path1,position);
|
||||
sprintf(new_path_file2,"%s/%s",path2,position);
|
||||
if(pointer_callback_copy)
|
||||
{
|
||||
asm volatile(""::"c"(new_path_file1),"d"(new_path_file2));
|
||||
pointer_callback_copy();
|
||||
}
|
||||
position+=304;
|
||||
if(!copy_loop(new_path_file1,new_path_file2))
|
||||
{
|
||||
free(tmp_buf);
|
||||
free(new_path_file1);
|
||||
free(new_path_file2);
|
||||
return 0;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
free(new_path_file1);
|
||||
free(new_path_file2);
|
||||
END:
|
||||
free(tmp_buf);
|
||||
return 1;
|
||||
}
|
||||
char r = file_copy(path1,path2);
|
||||
set_bdvk(path2,&ret_struct);
|
||||
return r;
|
||||
}
|
||||
|
||||
char copy(char *path1,char *path2)
|
||||
{
|
||||
char *tmp = get_full_path(path1);
|
||||
path1 = malloc(4096);
|
||||
strcpy(path1,tmp);
|
||||
|
||||
char *r=copy_loop(path1,get_full_path(path2));
|
||||
|
||||
free(path1);
|
||||
return r;
|
||||
}
|
||||
|
||||
char move_loop(char *path1,char *path2)
|
||||
{
|
||||
if(get_bdvk(path1))return 0;
|
||||
if(ret_struct.p00&0b10000)
|
||||
{
|
||||
file_mkdir(path2);
|
||||
set_bdvk(path2,&ret_struct);
|
||||
dword tmp_buf = _get_dir_info(path1);
|
||||
if(!COUNT_FILE) goto END;
|
||||
|
||||
char *new_path_file1 = malloc(4096);
|
||||
char *new_path_file2 = malloc(4096);
|
||||
int tmp_count = COUNT_FILE;
|
||||
int i = 0;
|
||||
dword position = tmp_buf+72;
|
||||
while(i<tmp_count)
|
||||
{
|
||||
sprintf(new_path_file1,"%s/%s",path1,position);
|
||||
sprintf(new_path_file2,"%s/%s",path2,position);
|
||||
if(pointer_callback_move)
|
||||
{
|
||||
asm volatile(""::"c"(new_path_file1),"d"(new_path_file2));
|
||||
pointer_callback_copy();
|
||||
}
|
||||
position+=304;
|
||||
if(!move_loop(new_path_file1,new_path_file2))
|
||||
{
|
||||
free(tmp_buf);
|
||||
free(new_path_file1);
|
||||
free(new_path_file2);
|
||||
return 0;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
free(new_path_file1);
|
||||
free(new_path_file2);
|
||||
END:
|
||||
free(tmp_buf);
|
||||
if(file_delete(path1)) return 0;
|
||||
return 1;
|
||||
}
|
||||
char r = 0;
|
||||
if(file_copy(path1,path2)) if(!file_delete(path1))r=1;
|
||||
if(r)set_bdvk(path2,&ret_struct);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
char move(char *path1,char *path2)
|
||||
{
|
||||
char *tmp = get_full_path(path1);
|
||||
path1 = malloc(4096);
|
||||
strcpy(path1,tmp);
|
||||
|
||||
char *r=move_loop(path1,get_full_path(path2));
|
||||
|
||||
free(path1);
|
||||
return r;
|
||||
}
|
||||
|
||||
char write(char *path,void *data,dword size)
|
||||
{
|
||||
if(file_write(get_full_path(path),data,size))return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
dword execute(char *path,char *arg)
|
||||
{
|
||||
return file_run(get_full_path(path),arg);
|
||||
}
|
||||
|
||||
dword open(char *path)
|
||||
{
|
||||
return file_run("/sys/@open",get_full_path(path));
|
||||
}
|
||||
|
||||
char rename(char *path,char *new_name)
|
||||
{
|
||||
if(!strcmp(path,new_name))return 0;
|
||||
char *pos = path;
|
||||
char *pos1 = &TMP1;
|
||||
char *tmp = 0;
|
||||
while(*pos)
|
||||
{
|
||||
*pos1=*pos;
|
||||
if(*pos=='/')
|
||||
{
|
||||
if(*++pos)tmp = pos1;
|
||||
}
|
||||
else ++pos;
|
||||
++pos1;
|
||||
}
|
||||
if(tmp)
|
||||
{
|
||||
while(*new_name)*++tmp = *new_name++;
|
||||
*++tmp = 0;
|
||||
return move(path,&TMP1);
|
||||
}
|
||||
return move(path,new_name);
|
||||
}
|
||||
|
||||
char callback_copy(char *path1,char *path2,dword func)
|
||||
{
|
||||
pointer_callback_copy = func;
|
||||
return copy(path1,path2);
|
||||
}
|
||||
|
||||
char callback_move(char *path1,char *path2,dword func)
|
||||
{
|
||||
pointer_callback_move = func;
|
||||
return move(path1,path2);
|
||||
}
|
||||
|
||||
char callback_remove(char *path,dword func)
|
||||
{
|
||||
pointer_callback_remove = func;
|
||||
return remove(path);
|
||||
}
|
||||
|
||||
char *version = "Ver. 1.3, Author:Pavel Yakovlev, http://vk.com/pavelyakov39";
|
||||
|
||||
EXPORT_
|
||||
export(execute)
|
||||
export(open)
|
||||
export(read)
|
||||
export(write)
|
||||
export(copy)
|
||||
export(move)
|
||||
export(remove)
|
||||
export(rename)
|
||||
export(get_size)
|
||||
//export(set_attributes)
|
||||
export(get_entries_count)
|
||||
export(get_dir_info)
|
||||
export(get_dir_position)
|
||||
export(get_file_name)
|
||||
|
||||
export(get_full_path)
|
||||
|
||||
export(make_dir)
|
||||
|
||||
export(callback_copy)
|
||||
export(callback_move)
|
||||
export(callback_remove)
|
||||
|
||||
export(pointer_callback_copy)
|
||||
export(pointer_callback_move)
|
||||
export(pointer_callback_remove)
|
||||
|
||||
export(version)
|
||||
_EXPORT
|
18
programs/develop/libraries/libs_v2/include/all.h
Normal file
18
programs/develop/libraries/libs_v2/include/all.h
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
/// ===========================================================
|
||||
|
||||
#ifndef AUTOBUILD
|
||||
// autobuild does not create lang.h, but defines LANG_{RUS,ENG} directly
|
||||
|
||||
#endif
|
||||
|
||||
#include "boolean.c"
|
||||
#include "kolibri.c"
|
||||
#include "stdlib.c"
|
||||
#include "string.c"
|
||||
#include "ctype.c"
|
||||
|
||||
#include "console.c"
|
||||
|
||||
|
||||
/// ===========================================================
|
24
programs/develop/libraries/libs_v2/include/array.h
Normal file
24
programs/develop/libraries/libs_v2/include/array.h
Normal file
@ -0,0 +1,24 @@
|
||||
typedef struct
|
||||
{
|
||||
dword key;
|
||||
dword value;
|
||||
} array_data;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
array_data *(* key_string_set)(char *);
|
||||
void *(* key_string_get)(char *,array_data *);
|
||||
} ARRAY;
|
||||
|
||||
|
||||
ARRAY array;
|
||||
|
||||
char _init_array_ = 0;
|
||||
void init_array(void)
|
||||
{
|
||||
if(_init_array_) return;
|
||||
library.load("/sys/lib/array.obj");
|
||||
array.key_string_set = library.get("array.key_string_set");
|
||||
array.key_string_get = library.get("array.key_string_get");
|
||||
_init_array_ = 1;
|
||||
}
|
3
programs/develop/libraries/libs_v2/include/boolean.c
Normal file
3
programs/develop/libraries/libs_v2/include/boolean.c
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
117
programs/develop/libraries/libs_v2/include/console.c
Normal file
117
programs/develop/libraries/libs_v2/include/console.c
Normal file
@ -0,0 +1,117 @@
|
||||
|
||||
///===========================
|
||||
|
||||
#define CON_COLOR_BLUE 1
|
||||
#define CON_COLOR_GREEN 2
|
||||
#define CON_COLOR_RED 4
|
||||
#define CON_COLOR_BRIGHT 8
|
||||
/* öâåò ôîíà */
|
||||
#define CON_BGR_BLUE 0x10
|
||||
#define CON_BGR_GREEN 0x20
|
||||
#define CON_BGR_RED 0x40
|
||||
#define CON_BGR_BRIGHT 0x80
|
||||
|
||||
///===========================
|
||||
char console_init_command = FALSE;
|
||||
static inline void (* _stdcall con_init)(unsigned w_w, unsigned w_h, unsigned s_w, unsigned s_h, const char* t);
|
||||
static inline void (* _cdecl _printf)(const char* format,...);
|
||||
static inline void (* _stdcall _print)(const char* text);
|
||||
static inline void (* _stdcall _exit)(char bCloseWindow);
|
||||
static inline void (* __stdcall _gets)(char* str, int n);
|
||||
static inline int (* __stdcall _getch)(void);
|
||||
static inline int (* __stdcall con_get_font_height)(void);
|
||||
static inline int (* __stdcall con_set_cursor_height)(int new_height);
|
||||
unsigned (*__stdcall con_get_flags)(void);
|
||||
unsigned (*__stdcall con_set_flags)(unsigned new_flags);
|
||||
static inline void (*__stdcall con_cls)(void);
|
||||
|
||||
///===========================
|
||||
|
||||
static inline void print(const char *text)
|
||||
{
|
||||
_print(text);
|
||||
}
|
||||
|
||||
char _buf_gets[255];
|
||||
static inline char *gets(void)
|
||||
{
|
||||
CONSOLE_INIT("console");
|
||||
_gets(&_buf_gets,255);
|
||||
return &_buf_gets;
|
||||
}
|
||||
static inline char getch(void)
|
||||
{
|
||||
CONSOLE_INIT("console");
|
||||
_getch();
|
||||
}
|
||||
|
||||
static inline void CONSOLE_INIT(char title[])
|
||||
{
|
||||
|
||||
if(console_init_command)return;
|
||||
|
||||
struct_import *imp;
|
||||
|
||||
imp = cofflib_load("/sys/lib/console.obj");
|
||||
if (imp == NULL)
|
||||
exit();
|
||||
|
||||
con_init = ( _stdcall void (*)(unsigned, unsigned, unsigned, unsigned, const char*))
|
||||
cofflib_procload (imp, "con_init");
|
||||
if (con_init == NULL)
|
||||
exit();
|
||||
|
||||
_printf = ( _cdecl void (*)(const char*,...))
|
||||
cofflib_procload (imp, "con_printf");
|
||||
if (_printf == NULL)
|
||||
exit();
|
||||
|
||||
_print = ( _cdecl void (*)(const char*))
|
||||
cofflib_procload (imp, "con_write_asciiz");
|
||||
if (_printf == NULL)
|
||||
exit();
|
||||
|
||||
_exit = ( _stdcall void (*)(char))
|
||||
cofflib_procload (imp, "con_exit");
|
||||
if (_exit == NULL)
|
||||
exit();
|
||||
|
||||
_gets = ( _stdcall void (*)(char*, int))
|
||||
cofflib_procload (imp, "con_gets");
|
||||
if (_gets == NULL)
|
||||
exit();
|
||||
|
||||
_getch = ( _stdcall int (*)(void))
|
||||
cofflib_procload (imp, "con_getch2");
|
||||
if (_getch == NULL)
|
||||
exit();
|
||||
|
||||
con_get_font_height = ( _stdcall int (*)(void))
|
||||
cofflib_procload (imp, "con_get_font_height");
|
||||
if (con_get_font_height == NULL)
|
||||
exit();
|
||||
|
||||
con_set_cursor_height = ( _stdcall int (*)(int))
|
||||
cofflib_procload (imp, "con_set_cursor_height");
|
||||
if (con_set_cursor_height == NULL)
|
||||
exit();
|
||||
|
||||
con_get_flags = ( _stdcall unsigned (*)(void))
|
||||
cofflib_procload (imp, "con_get_flags");
|
||||
if (con_get_flags == NULL)
|
||||
exit();
|
||||
|
||||
con_set_flags = ( _stdcall unsigned (*)(unsigned))
|
||||
cofflib_procload (imp, "con_set_flags");
|
||||
if (con_set_flags == NULL)
|
||||
exit();
|
||||
|
||||
con_cls = ( _stdcall void (*)(void))
|
||||
cofflib_procload (imp, "con_cls");
|
||||
if (con_cls == NULL)
|
||||
exit();
|
||||
|
||||
con_init(-1, -1, -1, -1, title);
|
||||
|
||||
console_init_command = TRUE;
|
||||
}
|
39
programs/develop/libraries/libs_v2/include/ctype.c
Normal file
39
programs/develop/libraries/libs_v2/include/ctype.c
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
#include "ctype.h"
|
||||
|
||||
static inline int toupper(int c)
|
||||
{
|
||||
|
||||
if ( (c >= 97) && (c <= 122) )
|
||||
return c-32 ;
|
||||
|
||||
if ( (c >= 160) && (c <= 175) )
|
||||
return c-32 ;
|
||||
|
||||
if ( (c >= 224) && (c <= 239) )
|
||||
return c-80 ;
|
||||
|
||||
if ( (c == 241) || (c == 243) || (c == 245) || (c == 247) )
|
||||
return c-1;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline int tolower(int c)
|
||||
{
|
||||
|
||||
if ( (c >= 65) && (c <= 90) )
|
||||
return c+32 ;
|
||||
|
||||
if ( (c >= 128) && (c <= 143) )
|
||||
return c+32 ;
|
||||
|
||||
if ( (c >= 144) && (c <= 159) )
|
||||
return c+80 ;
|
||||
|
||||
if ( (c == 240) || (c == 242) || (c == 244) || (c == 246) )
|
||||
return c+1;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
13
programs/develop/libraries/libs_v2/include/font.h
Normal file
13
programs/develop/libraries/libs_v2/include/font.h
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
:typedef struct
|
||||
{
|
||||
char (*load)(char *path);
|
||||
} _FONT_;
|
||||
_FONT_ font;
|
||||
|
||||
static inline font_lib_init(void)
|
||||
{
|
||||
if(font.load)return;
|
||||
library.load("/sys/lib/font.obj");
|
||||
font.load = library.get("font.load");
|
||||
}
|
394
programs/develop/libraries/libs_v2/include/fs.c
Normal file
394
programs/develop/libraries/libs_v2/include/fs.c
Normal file
@ -0,0 +1,394 @@
|
||||
#ifndef FS_C_INCLUDE
|
||||
#define FS_C_INCLUDE
|
||||
|
||||
#include "stdlib.c"
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
unsigned p00;
|
||||
unsigned p04;
|
||||
unsigned p08;
|
||||
unsigned p12;
|
||||
unsigned p16;
|
||||
char p20;
|
||||
char *p21;
|
||||
} FS_struct70;
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
unsigned p00;
|
||||
char p04;
|
||||
char p05[3];
|
||||
unsigned p08;
|
||||
unsigned p12;
|
||||
unsigned p16;
|
||||
unsigned p20;
|
||||
unsigned p24;
|
||||
unsigned p28;
|
||||
//unsigned p32[2];
|
||||
long long p32;
|
||||
unsigned p40;
|
||||
} FS_struct_BDVK;
|
||||
#pragma pack(pop)
|
||||
|
||||
#define FS_COPY_BUFFER_SET 0x100000
|
||||
static inline char BUF_COPY[FS_COPY_BUFFER_SET] = {0};
|
||||
|
||||
static inline char *string_error_code(char code)
|
||||
{
|
||||
if(!code)return "Successfully!";
|
||||
if(code==1)return "Not defined basis and / or hard disk partition (sub-functions 7, 8 function 21)!";
|
||||
if(code==2)return "Function is not supported for this file system!";
|
||||
if(code==3)return "Unknown file system!";
|
||||
if(code==4)return "Reserved, never returned to the current implementation!";
|
||||
if(code==5)return "File not found!";
|
||||
if(code==6)return "The file is ended!";
|
||||
if(code==7)return "Pointer out the application memory!";
|
||||
if(code==8)return "Disk is full!";
|
||||
if(code==9)return "FAT table is destroyed!";
|
||||
if(code==10)return "Access is denied!";
|
||||
if(code==11)return "Device error!";
|
||||
return "An unexpected error!";
|
||||
}
|
||||
|
||||
static inline dword sprintf(char *mstr,const char *fmt,...)
|
||||
{
|
||||
|
||||
dword *arg = &fmt;
|
||||
char *tmp = 0;
|
||||
char *pos = mstr;
|
||||
--pos;
|
||||
--fmt;
|
||||
while(*++fmt)
|
||||
{
|
||||
char s = *fmt;
|
||||
if(s=='%')
|
||||
{
|
||||
s = *++fmt;
|
||||
if(s=='s')
|
||||
{
|
||||
tmp = *++arg;
|
||||
while(*tmp)*++pos = *tmp++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*++pos='%';
|
||||
--fmt;
|
||||
}
|
||||
}
|
||||
else *++pos=s;
|
||||
}
|
||||
*++pos = 0;
|
||||
return pos-mstr;
|
||||
}
|
||||
|
||||
static inline int FS_file_70(FS_struct70 *k)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(70), "b"(k));
|
||||
}
|
||||
|
||||
FS_struct_BDVK ret_struct;
|
||||
static inline FS_struct_BDVK* get_bdvk(char *path)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 5;
|
||||
file_read_struct.p04 = 0;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = 0;
|
||||
file_read_struct.p16 = (unsigned)&ret_struct;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
FS_file_70(&file_read_struct);
|
||||
return (FS_struct_BDVK*)&ret_struct;
|
||||
}
|
||||
|
||||
static inline long long file_size(char *path)
|
||||
{
|
||||
FS_struct_BDVK *data = get_bdvk(path);
|
||||
return data->p32;
|
||||
}
|
||||
|
||||
static inline byte file_isdir(char *path)
|
||||
{
|
||||
FS_struct_BDVK *data = get_bdvk(path);
|
||||
if(data->p00&0b10000)return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline byte file_ismetka(char *path)
|
||||
{
|
||||
FS_struct_BDVK *data = get_bdvk(path);
|
||||
if(data->p00&0b1000)return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline byte file_isfile()
|
||||
{
|
||||
//FS_struct_BDVK *data = get_bdvk(path);
|
||||
if(ret_struct.p00&0b11000)return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int file_run(char *path,char *arg)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 7;
|
||||
file_read_struct.p04 = 0;
|
||||
file_read_struct.p08 = arg;
|
||||
file_read_struct.p12 = 0;
|
||||
file_read_struct.p16 = 0;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
return FS_file_70(&file_read_struct);
|
||||
|
||||
}
|
||||
|
||||
static inline int file_read_binary(char *path,unsigned pos,unsigned size,void *adr)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 0;
|
||||
file_read_struct.p04 = pos;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = size;
|
||||
file_read_struct.p16 = (unsigned)adr;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
char c = FS_file_70(&file_read_struct);
|
||||
if(c)
|
||||
{
|
||||
sprintf(&BUF_COPY,"'Error read file (%s) file: %s.'E",string_error_code(c),path);
|
||||
file_run("/sys/@notify",&BUF_COPY);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline int file_delete(char *path)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 8;
|
||||
file_read_struct.p04 = 0;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = 0;
|
||||
file_read_struct.p16 = 0;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
char c = FS_file_70(&file_read_struct);
|
||||
if(c)
|
||||
{
|
||||
sprintf(&BUF_COPY,"'Error delete file: %s. Info: %s'E",string_error_code(c),path);
|
||||
file_run("/sys/@notify",&BUF_COPY);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline int file_mkdir(char *path)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 9;
|
||||
file_read_struct.p04 = 0;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = 0;
|
||||
file_read_struct.p16 = 0;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
char c = FS_file_70(&file_read_struct);
|
||||
if(c)
|
||||
{
|
||||
sprintf(&BUF_COPY,"'Error make dir: %s. Info: %s.'E",string_error_code(c),path);
|
||||
file_run("/sys/@notify",&BUF_COPY);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline int file_write(char *path,void *ukaz,dword size)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 2;
|
||||
file_read_struct.p04 = 0;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = size;
|
||||
file_read_struct.p16 = ukaz;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
char c = FS_file_70(&file_read_struct);
|
||||
if(c)
|
||||
{
|
||||
sprintf(&BUF_COPY,"'Error write file: %s. Info: %s.'E",string_error_code(c),path);
|
||||
file_run("/sys/@notify",&BUF_COPY);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline int file_rewrite(char *path,dword pos1,dword pos2,void *ukaz,dword size)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 3;
|
||||
file_read_struct.p04 = pos1;
|
||||
file_read_struct.p08 = pos2;
|
||||
file_read_struct.p12 = size;
|
||||
file_read_struct.p16 = ukaz;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = path;
|
||||
char c = FS_file_70(&file_read_struct);
|
||||
if(c)
|
||||
{
|
||||
sprintf(&BUF_COPY,"'Error rewrite file (%s) file: %s.'E",string_error_code(c),path);
|
||||
file_run("/sys/@notify",&BUF_COPY);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
static inline char file_copy(char *path1,char *path2)
|
||||
{
|
||||
long long size = file_size(path1);
|
||||
if(!size)file_write(path2,&BUF_COPY,0);
|
||||
long long cel = size;
|
||||
cel /= FS_COPY_BUFFER_SET;
|
||||
dword ost = size-cel*FS_COPY_BUFFER_SET;
|
||||
long long i = 0;
|
||||
char err=0;
|
||||
if(cel)
|
||||
{
|
||||
if(file_read_binary(path1,0,FS_COPY_BUFFER_SET,&BUF_COPY))goto ERROR;
|
||||
if(file_write(path2,&BUF_COPY,FS_COPY_BUFFER_SET))goto ERROR;
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(file_read_binary(path1,0,ost,&BUF_COPY))goto ERROR;
|
||||
if(file_write(path2,&BUF_COPY,ost))goto ERROR;
|
||||
return 1;
|
||||
}
|
||||
while(i<cel)
|
||||
{
|
||||
if(file_read_binary(path1,FS_COPY_BUFFER_SET*i,FS_COPY_BUFFER_SET,&BUF_COPY))goto ERROR;
|
||||
if(file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,FS_COPY_BUFFER_SET))goto ERROR;
|
||||
++i;
|
||||
}
|
||||
if(file_read_binary(path1,FS_COPY_BUFFER_SET*i,ost,&BUF_COPY))goto ERROR;
|
||||
if(file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,ost))goto ERROR;
|
||||
return 1;
|
||||
ERROR:
|
||||
|
||||
//asm("":"=a"(err));
|
||||
//sprintf(&BUF_COPY,"Error %s file: %s.",string_error_code(err),path1);
|
||||
//file_run("/sys/@notify",&BUF_COPY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
dword FS_COPY_BUFFER_SET_POINT = 0x100000;
|
||||
dword BUF_COPY_POINT = 0;
|
||||
static inline char file_copy(char *path1,char *path2)
|
||||
{
|
||||
long long size = file_size(path1);
|
||||
if(!size)file_write(path2,BUF_COPY_POINT,0);
|
||||
long long cel = size;
|
||||
cel /= FS_COPY_BUFFER_SET_POINT;
|
||||
dword ost = size-cel*FS_COPY_BUFFER_SET_POINT;
|
||||
long long i = 0;
|
||||
char err=0;
|
||||
if(cel)
|
||||
{
|
||||
if(file_read_binary(path1,0,FS_COPY_BUFFER_SET_POINT,BUF_COPY_POINT))goto ERROR;
|
||||
if(file_write(path2,BUF_COPY_POINT,FS_COPY_BUFFER_SET_POINT))goto ERROR;
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(file_read_binary(path1,0,ost,BUF_COPY_POINT))goto ERROR;
|
||||
if(file_write(path2,BUF_COPY_POINT,ost))goto ERROR;
|
||||
return 1;
|
||||
}
|
||||
while(i<cel)
|
||||
{
|
||||
if(file_read_binary(path1,FS_COPY_BUFFER_SET_POINT*i,FS_COPY_BUFFER_SET_POINT,BUF_COPY_POINT))goto ERROR;
|
||||
if(file_rewrite(path2,FS_COPY_BUFFER_SET_POINT*i,0,BUF_COPY_POINT,FS_COPY_BUFFER_SET_POINT))goto ERROR;
|
||||
++i;
|
||||
}
|
||||
if(file_read_binary(path1,FS_COPY_BUFFER_SET_POINT*i,ost,BUF_COPY_POINT))goto ERROR;
|
||||
if(file_rewrite(path2,FS_COPY_BUFFER_SET_POINT*i,0,BUF_COPY_POINT,ost))goto ERROR;
|
||||
return 1;
|
||||
ERROR:
|
||||
|
||||
//asm("":"=a"(err));
|
||||
//sprintf(BUF_COPY_POINT,"Error %s file: %s.",string_error_code(err),path1);
|
||||
//file_run("/sys/@notify",BUF_COPY_POINT);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
#define FS_COPY_BUFFER_SET 0x100000
|
||||
char BUF_COPY[FS_COPY_BUFFER_SET] = {0};
|
||||
static inline char file_copy(char *path1,char *path2)
|
||||
{
|
||||
long long size = file_size(path1);
|
||||
if(!size)file_write(path2,&BUF_COPY,0);
|
||||
long long cel = size;
|
||||
cel /= FS_COPY_BUFFER_SET;
|
||||
dword ost = size-cel*FS_COPY_BUFFER_SET;
|
||||
long long i = 0;
|
||||
|
||||
if(cel)
|
||||
{
|
||||
file_read_binary(path1,0,FS_COPY_BUFFER_SET,&BUF_COPY);
|
||||
file_write(path2,&BUF_COPY,FS_COPY_BUFFER_SET);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
file_read_binary(path1,0,ost,&BUF_COPY);
|
||||
file_write(path2,&BUF_COPY,ost);
|
||||
return 1;
|
||||
}
|
||||
while(i<cel)
|
||||
{
|
||||
file_read_binary(path1,FS_COPY_BUFFER_SET*i,FS_COPY_BUFFER_SET,&BUF_COPY);
|
||||
file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,FS_COPY_BUFFER_SET);
|
||||
++i;
|
||||
}
|
||||
file_read_binary(path1,FS_COPY_BUFFER_SET*i,ost,&BUF_COPY);
|
||||
file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,ost);
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
long long size_long_file=0;
|
||||
|
||||
static inline void *file_read(char *path)
|
||||
{
|
||||
size_long_file = file_size(path);
|
||||
void *data = malloc(size_long_file+1);
|
||||
|
||||
if(file_read_binary(path,0,size_long_file,data))return 0;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static inline void *file_readKPACK(char *path)
|
||||
{
|
||||
void *data = 0;
|
||||
dword size=0;
|
||||
asm ("int $0x40":"=a"(data),"=d"(size):"a"(68), "b"(27), "c"(path));
|
||||
size_long_file = size;
|
||||
asm volatile(""::"c"(size));
|
||||
return data;
|
||||
}
|
||||
|
||||
static inline int file_read_dir(dword begin,dword file_count,dword read_buffer,char *dir_path)
|
||||
{
|
||||
FS_struct70 file_read_struct;
|
||||
file_read_struct.p00 = 1;
|
||||
file_read_struct.p04 = begin;
|
||||
file_read_struct.p08 = 0;
|
||||
file_read_struct.p12 = file_count;
|
||||
file_read_struct.p16 = read_buffer;
|
||||
file_read_struct.p20 = 0;
|
||||
file_read_struct.p21 = dir_path;
|
||||
return FS_file_70(&file_read_struct);
|
||||
}
|
||||
|
||||
#endif
|
23
programs/develop/libraries/libs_v2/include/fs.h
Normal file
23
programs/develop/libraries/libs_v2/include/fs.h
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
static struct FS
|
||||
{
|
||||
void *(*read)(char *path);
|
||||
};
|
||||
|
||||
|
||||
void *(* _stdcall _ptr_fs_read_)(char *path);
|
||||
|
||||
char _init_fs_ = 0;
|
||||
void init_fs(void)
|
||||
{
|
||||
if(_init_fs_) return;
|
||||
library.load("/sys/lib/fs.obj");
|
||||
_ptr_fs_read_ = library.get("fs.read");
|
||||
_init_fs_ = 1;
|
||||
}
|
||||
|
||||
static inline dword _FS__READ_(char *name)
|
||||
{
|
||||
return _ptr_fs_read_(name);
|
||||
}
|
||||
struct FS fs = {&_FS__READ_};
|
525
programs/develop/libraries/libs_v2/include/kolibri.c
Normal file
525
programs/develop/libraries/libs_v2/include/kolibri.c
Normal file
@ -0,0 +1,525 @@
|
||||
#ifndef KOLIBRI_INCLUDE
|
||||
#define KOLIBRI_INCLUDE
|
||||
|
||||
#define NULL ((void*)0)
|
||||
|
||||
#define SHM_OPEN 0
|
||||
#define SHM_OPEN_ALWAYS 0x04
|
||||
#define SHM_CREATE 0x08
|
||||
#define SHM_READ 0x00
|
||||
#define SHM_WRITE 0x01
|
||||
|
||||
#define E_NOTFOUND 5
|
||||
#define E_ACCESS 10
|
||||
#define E_NOMEM 30
|
||||
#define E_PARAM 33
|
||||
|
||||
#define evReDraw 1
|
||||
#define evKey 2
|
||||
#define evButton 3
|
||||
#define evDesktop 5
|
||||
#define evMouse 6
|
||||
#define evIPC 7
|
||||
#define evNetwork 8
|
||||
#define evDebug 9
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
unsigned p00;
|
||||
unsigned p04;
|
||||
unsigned p08;
|
||||
unsigned p12;
|
||||
unsigned p16;
|
||||
char p20;
|
||||
char *p21;
|
||||
} struct70;
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
unsigned p00;
|
||||
char p04;
|
||||
char p05[3];
|
||||
unsigned p08;
|
||||
unsigned p12;
|
||||
unsigned p16;
|
||||
unsigned p20;
|
||||
unsigned p24;
|
||||
unsigned p28;
|
||||
unsigned p32[2];
|
||||
unsigned p40;
|
||||
} struct_BDVK;
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
char *name;
|
||||
void *data;
|
||||
} struct_import;
|
||||
#pragma pack(pop)
|
||||
|
||||
#include "string.c"
|
||||
|
||||
|
||||
extern char PATH[256];
|
||||
extern char PARAM[256];
|
||||
extern char DIR[256];
|
||||
|
||||
|
||||
static inline void exit()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(-1));
|
||||
}
|
||||
|
||||
static inline dword get_pixel(unsigned x,unsigned y,unsigned size)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(35), "b"((y*size+x)));
|
||||
}
|
||||
|
||||
static inline void sleep(unsigned d)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(5), "b"(d));
|
||||
}
|
||||
|
||||
static inline void GetRGB(unsigned x,unsigned y, unsigned w, unsigned h,unsigned d)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(36), "b"(d), "c"((w<<16)|h), "d"((x<<16)|y));
|
||||
}
|
||||
|
||||
// define a window
|
||||
// x, y - position; w, h - size; cs - color and style; c - caption; b - boder
|
||||
static inline void wnd_define(unsigned x, unsigned y, unsigned w, unsigned h)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(0), "b"(x*65536+w), "c"(y*65536+h), "d"(0x43000000));
|
||||
}
|
||||
|
||||
|
||||
static inline void wnd_move(unsigned x, unsigned y)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(67), "b"(x), "c"(y), "d"(-1), "S"(-1));
|
||||
}
|
||||
|
||||
|
||||
static inline void event_mask(unsigned e)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(40), "b"(e));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned event_wait()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(10));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned event_wait_time(unsigned time)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(23), "b"(time));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned event_check()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(11));
|
||||
}
|
||||
|
||||
|
||||
static inline void __attribute__((__always_inline__)) paint_start()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(12), "b"(1));
|
||||
}
|
||||
|
||||
|
||||
static inline void __attribute__((__always_inline__)) paint_end()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(12), "b"(2));
|
||||
}
|
||||
|
||||
|
||||
static inline void paint_pixel(unsigned x, unsigned y, unsigned c)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(1), "b"(x), "c"(y), "d"(c));
|
||||
}
|
||||
|
||||
|
||||
static inline void paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(13), "b"(x*65536+w), "c"(y*65536+h), "d"(c));
|
||||
}
|
||||
|
||||
|
||||
static inline void paint_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned c)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(38), "b"(x1*65536+x2), "c"(y1*65536+y2), "d"(c));
|
||||
}
|
||||
|
||||
|
||||
static inline void paint_string(unsigned x, unsigned y, char *s, unsigned c)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(4), "b"(x*65536+y), "c"(c), "d"(s));
|
||||
}
|
||||
|
||||
|
||||
static inline void paint_image(unsigned x, unsigned y, unsigned w, unsigned h, char *d)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(7), "c"(w*65536+h), "d"(x*65536+y), "b"(d));
|
||||
}
|
||||
|
||||
|
||||
static inline void paint_image_pal(unsigned x, unsigned y, unsigned w, unsigned h, char *d, unsigned *palette)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(65), "b"(d), "c"(w*65536+h), "d"(x*65536+y), "D"(palette), "S"(8));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned key_get()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(2));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned key_control()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(66), "b"(3));
|
||||
}
|
||||
|
||||
|
||||
static inline void key_lang_set(unsigned lang)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(21), "b"(2), "c"(9), "d"(lang));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned key_lang_get()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(26), "b"(2), "c"(9));
|
||||
}
|
||||
|
||||
|
||||
static inline void key_mode_set(unsigned mode)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(66), "b"(1), "c"(mode));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned key_mode_get()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(66), "b"(2));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned btn_get()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(17));
|
||||
}
|
||||
|
||||
|
||||
static inline void btn_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned d, unsigned c)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(8), "b"(x*65536+w), "c"(y*65536+h), "d"(d), "S"(c));
|
||||
}
|
||||
|
||||
|
||||
static inline void btn_type(unsigned t)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(48), "b"(1), "c"(t));
|
||||
}
|
||||
|
||||
|
||||
static inline void wnd_caption(char *s)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(71), "b"(1), "c"(s));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned mouse_pos()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(37), "b"(0));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned mouse_posw()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(37), "b"(1));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned mouse_btn()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(37), "b"(2));
|
||||
}
|
||||
|
||||
|
||||
static inline void board_putc(char c)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(c));
|
||||
}
|
||||
|
||||
|
||||
static inline void board_puts(char *s)
|
||||
{
|
||||
unsigned i;
|
||||
i = 0;
|
||||
while (*(s+i))
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i)));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline void board_puti(int n)
|
||||
{
|
||||
char c;
|
||||
|
||||
if ( n > 1 )
|
||||
board_puti(n / 10);
|
||||
|
||||
c = n % 10 + '0';
|
||||
asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(c));
|
||||
|
||||
}
|
||||
|
||||
|
||||
static inline int file_70(struct70 *k)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(70), "b"(k));
|
||||
}
|
||||
|
||||
|
||||
static inline struct_import* cofflib_load(char *name)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(68), "b"(19), "c"(name));
|
||||
}
|
||||
|
||||
|
||||
static inline void* cofflib_procload (struct_import *imp, char *name)
|
||||
{
|
||||
int i;
|
||||
for (i=0;;i++)
|
||||
if ( NULL == ((imp+i) -> name))
|
||||
break;
|
||||
else
|
||||
if ( 0 == strcmp(name, (imp+i)->name) )
|
||||
return (imp+i)->data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned cofflib_procnum (struct_import *imp)
|
||||
{
|
||||
unsigned i, n;
|
||||
|
||||
for (i=n=0;;i++)
|
||||
if ( NULL == ((imp+i) -> name))
|
||||
break;
|
||||
else
|
||||
n++;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
static inline void cofflib_procname (struct_import *imp, char *name, unsigned n)
|
||||
{
|
||||
unsigned i;
|
||||
*name = 0;
|
||||
|
||||
for (i=0;;i++)
|
||||
if ( NULL == ((imp+i) -> name))
|
||||
break;
|
||||
else
|
||||
if ( i == n )
|
||||
{
|
||||
strcpy(name, ((imp+i)->name));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned system_cpufreq()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(18), "b"(5));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned system_mem()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(18), "b"(17));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned system_memfree()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(18), "b"(16));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned system_time_get()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(3));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned system_date_get()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(29));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned system_end(unsigned param)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(18), "b"(9), "c"(param));
|
||||
}
|
||||
|
||||
static inline unsigned win_min()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(18), "b"(10));
|
||||
}
|
||||
|
||||
|
||||
static inline void path_file2dir(char *dir, char *fname)
|
||||
{
|
||||
unsigned i;
|
||||
strcpy (dir, fname);
|
||||
for ( i = strlen(dir);; --i)
|
||||
if ( '/' == dir[i])
|
||||
{
|
||||
dir[i] = '\0';
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline void path_full(char *full, char *fname)
|
||||
{
|
||||
char temp[256];
|
||||
|
||||
switch (*fname)
|
||||
{
|
||||
|
||||
case '/':
|
||||
strncpy(temp, fname+1, 2);
|
||||
temp[2]=0;
|
||||
if ( (!strcmp("rd", temp)) || (!strcmp("hd", temp)) || (!strcmp("cd", temp)) )
|
||||
strcpy (full, fname);
|
||||
break;
|
||||
|
||||
case '.':
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline void __attribute__((__always_inline__)) screen_wait_rr()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(18), "b"(14));
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline void screen_get_size(unsigned *w, unsigned *h)
|
||||
{
|
||||
unsigned size;
|
||||
asm volatile ("int $0x40":"=a"(size):"a"(14));
|
||||
*h = size&0xFFFF;
|
||||
*w = size>>16;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned skin_height()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(48), "b"(4));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned thread_start(unsigned start, unsigned stack)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(51), "b"(1), "c"(start), "d"(stack));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned time_tick()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(26), "b"(9));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned sound_speaker(char data[])
|
||||
{
|
||||
asm volatile ("movl %0, %%esi"::"a"(data));
|
||||
asm volatile ("int $0x40"::"a"(55), "b"(55));
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned process_info(signed slot, char buf1k[])
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(9), "b"(buf1k), "c"(slot));
|
||||
}
|
||||
|
||||
|
||||
static inline int process_kill_pid(unsigned process)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(18), "b"(18), "c"(process));
|
||||
}
|
||||
|
||||
static inline int kill_process(unsigned process)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(18), "b"(2), "c"(process));
|
||||
}
|
||||
|
||||
static inline void get_kernel_ver(char buff16b[])
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(18), "b"(13), "c"(buff16b));
|
||||
}
|
||||
|
||||
static inline long GetFreeRam(void)
|
||||
{
|
||||
asm ("int $0x40"::"a"(18), "b"(16));
|
||||
}
|
||||
|
||||
static inline long WaitBlanking(void)
|
||||
{
|
||||
asm ("int $0x40"::"a"(18), "b"(14));
|
||||
}
|
||||
|
||||
static inline int buffer_open(char name[], int mode, int size, char **buf)
|
||||
{
|
||||
int error;
|
||||
asm volatile ("int $0x40":"=a"(*buf), "=d"(error):"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode));
|
||||
return error;
|
||||
}
|
||||
|
||||
static inline void buffer_close(char name[])
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(name));
|
||||
}
|
||||
|
||||
static inline int clip_num()
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(54), "b"(0));
|
||||
}
|
||||
|
||||
static inline char* clip_get(int n)
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(54), "b"(1), "c"(n));
|
||||
}
|
||||
|
||||
static inline int clip_set(int n, char buffer[])
|
||||
{
|
||||
asm volatile ("int $0x40"::"a"(54), "b"(2), "c"(n), "d"(buffer));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
1
programs/develop/libraries/libs_v2/include/lexer.h
Normal file
1
programs/develop/libraries/libs_v2/include/lexer.h
Normal file
@ -0,0 +1 @@
|
||||
|
51
programs/develop/libraries/libs_v2/include/library.h
Normal file
51
programs/develop/libraries/libs_v2/include/library.h
Normal file
@ -0,0 +1,51 @@
|
||||
#ifndef LIBRARY_H
|
||||
#define LIBRARY_H
|
||||
|
||||
#pragma pack(push,1)
|
||||
typedef struct
|
||||
{
|
||||
char *name;
|
||||
void *data;
|
||||
} struct_import_lib_init;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int (*load)(char *path);
|
||||
unsigned int (*get)(char *name);
|
||||
} OBJECT_LIBRARY;
|
||||
|
||||
static char init_load_obj = 0;
|
||||
|
||||
static int (* _stdcall _ptr_load_dll_)(char *path);
|
||||
static unsigned int (* _stdcall _ptr_get_dll_)(char *path);
|
||||
|
||||
static inline int _OBJECT__LOAD_(char *path)
|
||||
{
|
||||
struct_import_lib_init *imp;
|
||||
if(!init_load_obj)
|
||||
{
|
||||
asm("int $0x40":"=a"(imp):"a"(68), "b"(19), "c"("/sys/lib/library.obj"));
|
||||
_ptr_load_dll_ = imp[0].data;
|
||||
_ptr_get_dll_ = imp[1].data;
|
||||
init_load_obj = 1;
|
||||
}
|
||||
return _ptr_load_dll_(path);
|
||||
}
|
||||
|
||||
static inline unsigned int _OBJECT__GET_(char *name)
|
||||
{
|
||||
return _ptr_get_dll_(name);
|
||||
}
|
||||
|
||||
static inline OBJECT_LIBRARY library = {&_OBJECT__LOAD_,&_OBJECT__GET_};
|
||||
|
||||
/*
|
||||
Example:
|
||||
void*(* stdcall name_func)(...);
|
||||
library.load("/sys/lib/... .obj");
|
||||
name_func = library.get("name_function");
|
||||
name_func(...);
|
||||
*/
|
||||
|
||||
#endif
|
76
programs/develop/libraries/libs_v2/include/math.c
Normal file
76
programs/develop/libraries/libs_v2/include/math.c
Normal file
@ -0,0 +1,76 @@
|
||||
//IO library
|
||||
#ifndef INCLUDE_MATH_C
|
||||
#define INCLUDE_MATH_C
|
||||
|
||||
static inline signed math_round(float x)
|
||||
{
|
||||
x+=0.6;
|
||||
return x;
|
||||
}
|
||||
static inline signed math_ceil(float x)
|
||||
{
|
||||
long z = (long)x;
|
||||
if(z<x) return ++z;
|
||||
return z;
|
||||
}
|
||||
static inline float math_floor(float x)
|
||||
{
|
||||
signed long z = x;
|
||||
if(z==x)return x;
|
||||
if(z<0) return --z;
|
||||
return z;
|
||||
}
|
||||
static inline float math_abs(float x)
|
||||
{
|
||||
if(x<0)return -x;
|
||||
return x;
|
||||
}
|
||||
|
||||
/*
|
||||
static inline float math_cos(float x)
|
||||
{
|
||||
float r;
|
||||
asm
|
||||
{
|
||||
fld x
|
||||
fcos
|
||||
fstp r
|
||||
}
|
||||
return r;
|
||||
}
|
||||
static inline float math_sin(float x)
|
||||
{
|
||||
float r;
|
||||
asm
|
||||
{
|
||||
fld x
|
||||
fsin
|
||||
fstp r
|
||||
}
|
||||
return r;
|
||||
}
|
||||
static inline float math_sqrt(float x)
|
||||
{
|
||||
float r;
|
||||
asm
|
||||
{
|
||||
fld x
|
||||
fsqrt
|
||||
fstp r
|
||||
}
|
||||
return r;
|
||||
}
|
||||
static inline float math_tan(float x)
|
||||
{
|
||||
float r;
|
||||
asm
|
||||
{
|
||||
fld x
|
||||
fld1
|
||||
fpatan
|
||||
fstp r
|
||||
}
|
||||
return r;
|
||||
}
|
||||
*/
|
||||
#endif
|
49
programs/develop/libraries/libs_v2/include/stdlib.c
Normal file
49
programs/develop/libraries/libs_v2/include/stdlib.c
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef STDLIB_C_INCLUDE
|
||||
#define STDLIB_C_INCLUDE
|
||||
|
||||
#define RAND_MAX 0x7FFFU
|
||||
|
||||
#define isspace(c) ((c)==' ')
|
||||
#define abs(i) (((i)<0)?(-(i)):(i))
|
||||
|
||||
#define random(num) ((rand()*(num))/((RAND_MAX+1)))
|
||||
|
||||
static unsigned int seed_o = 0x45168297;
|
||||
|
||||
|
||||
static inline void srand (unsigned seed)
|
||||
{
|
||||
seed_o = seed;
|
||||
}
|
||||
|
||||
|
||||
static inline int rand (void)
|
||||
{
|
||||
seed_o = seed_o * 0x15a4e35 + 1;
|
||||
return(seed_o >> 16);
|
||||
}
|
||||
|
||||
|
||||
static inline void* malloc(unsigned s)
|
||||
{
|
||||
asm ("int $0x40"::"a"(68), "b"(12), "c"(s) );
|
||||
}
|
||||
|
||||
|
||||
static inline void free(void *p)
|
||||
{
|
||||
asm ("int $0x40"::"a"(68), "b"(13), "c"(p) );
|
||||
}
|
||||
|
||||
static inline void *realloc(void *data, long size)
|
||||
{
|
||||
void *r = malloc(size);
|
||||
byte *p = (byte *)r;
|
||||
byte *pd = (byte *)data;
|
||||
while(size--) *p++=*pd++;
|
||||
free(data);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
197
programs/develop/libraries/libs_v2/include/string.c
Normal file
197
programs/develop/libraries/libs_v2/include/string.c
Normal file
@ -0,0 +1,197 @@
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
static inline void* memset(void *mem, int c, unsigned size)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for ( i = 0; i < size; i++ )
|
||||
*((char *)mem+i) = (char) c;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static inline void* memcpy(void *dst, const void *src, unsigned size)
|
||||
{
|
||||
|
||||
unsigned i;
|
||||
|
||||
for ( i = 0; i < size; i++)
|
||||
*(char *)(dst+i) = *(char *)(src+i);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static inline int memcmp(const void* buf1, const void* buf2, int count)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<count;i++)
|
||||
{
|
||||
if (*(unsigned char*)buf1<*(unsigned char*)buf2)
|
||||
return -1;
|
||||
if (*(unsigned char*)buf1>*(unsigned char*)buf2)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline char *strcat(char strDest[], char strSource[])
|
||||
{
|
||||
int i, j;
|
||||
i = j = 0;
|
||||
while (strDest[i] != '\0') i++;
|
||||
while ((strDest[i++] = strSource[j++]) != '\0');
|
||||
return strDest;
|
||||
}
|
||||
|
||||
|
||||
static inline int strcmp(char* string1,char* string2)
|
||||
{
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (*string1<*string2)
|
||||
return -1;
|
||||
if (*string1>*string2)
|
||||
return 1;
|
||||
|
||||
if (*string1=='\0')
|
||||
return 0;
|
||||
|
||||
string1++;
|
||||
string2++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static inline char *strcpy(char strDest[], const char strSource[])
|
||||
{
|
||||
unsigned i;
|
||||
i = 0;
|
||||
while ((strDest[i] = strSource[i]) != '\0') i++;
|
||||
return strDest;
|
||||
}
|
||||
|
||||
|
||||
char* strncpy(char *strDest, const char *strSource, unsigned n)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
if (! n )
|
||||
return strDest;
|
||||
|
||||
i = 0;
|
||||
while ((strDest[i] = strSource[i]) != '\0')
|
||||
if ( (n-1) == i )
|
||||
break;
|
||||
else
|
||||
i++;
|
||||
|
||||
return strDest;
|
||||
}
|
||||
|
||||
|
||||
static inline int strlen(const char* string)
|
||||
{
|
||||
int i;
|
||||
|
||||
i=0;
|
||||
while (*string++) i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline char* strchr(const char* string, int c)
|
||||
{
|
||||
while (*string)
|
||||
{
|
||||
if (*string==c)
|
||||
return (char*)string;
|
||||
string++;
|
||||
}
|
||||
return (char*)0;
|
||||
}
|
||||
|
||||
|
||||
static inline char* strrchr(const char* string, int c)
|
||||
{
|
||||
char* last_found;
|
||||
while (*string)
|
||||
{
|
||||
if (*string==c)
|
||||
{
|
||||
last_found = (char*)string;
|
||||
}
|
||||
string++;
|
||||
}
|
||||
return last_found;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline void _itoa(int i, char *s)
|
||||
{
|
||||
int a, b, c, d;
|
||||
a = (i - i%1000)/1000;
|
||||
b = (i - i%100)/100 - a*10;
|
||||
c = (i - i%10)/10 - a*100 - b*10;
|
||||
d = i%10;
|
||||
s[0] = a + '0';
|
||||
s[1] = b + '0';
|
||||
s[2] = c + '0';
|
||||
s[3] = d + '0';
|
||||
s[4] = 0;
|
||||
}
|
||||
|
||||
|
||||
/* reverse: ïåðåâîðà÷èâàåì ñòðîêó s íà ìåñòå */
|
||||
static inline void reverse(char s[])
|
||||
{
|
||||
int i, j;
|
||||
char c;
|
||||
|
||||
for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
|
||||
c = s[i];
|
||||
s[i] = s[j];
|
||||
s[j] = c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* itoa: êîíâåðòèðóåì n â ñèìâîëû â s */
|
||||
static inline void itoa(int n, char s[])
|
||||
{
|
||||
int i, sign;
|
||||
|
||||
if ((sign = n) < 0)
|
||||
n = -n;
|
||||
i = 0;
|
||||
do {
|
||||
s[i++] = n % 10 + '0';
|
||||
} while ((n /= 10) > 0);
|
||||
if (sign < 0)
|
||||
s[i++] = '-';
|
||||
s[i] = '\0';
|
||||
reverse(s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline int atoi ( char *s )
|
||||
{
|
||||
int i, n;
|
||||
|
||||
n = 0;
|
||||
for ( i = 0; s[i]!= '\0'; ++i)
|
||||
if ((s[i]<'0') || (s[i]>'9'))
|
||||
return 0;
|
||||
else
|
||||
n = 10 * n + s[i] - '0';
|
||||
|
||||
return n;
|
||||
}
|
1
programs/develop/libraries/libs_v2/library.bat
Normal file
1
programs/develop/libraries/libs_v2/library.bat
Normal file
@ -0,0 +1 @@
|
||||
build.bat library
|
151
programs/develop/libraries/libs_v2/library.c
Normal file
151
programs/develop/libraries/libs_v2/library.c
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
2015
|
||||
Author: Pavel Yakovlev.
|
||||
*/
|
||||
|
||||
#define LIB_NAME "library"
|
||||
#define NO_LIBIMPORT_FUNC
|
||||
|
||||
#include "coff.h"
|
||||
|
||||
#include <kolibri.c>
|
||||
#include <stdlib.c>
|
||||
|
||||
struct_import *array_list_func;
|
||||
dword ADR_FUNC_LIST=0;
|
||||
dword ADR_LIB_LIST=0;
|
||||
|
||||
dword init_list_function_adr();
|
||||
|
||||
typedef struct
|
||||
{
|
||||
dword key;
|
||||
dword value;
|
||||
} array;
|
||||
|
||||
void strtolower(char *text)
|
||||
{
|
||||
--text;
|
||||
while(*++text)if((*text>='A')&&(*text<='Z'))*text+='a'-'A';
|
||||
}
|
||||
|
||||
static array*(* _stdcall array_set_key_string)(array *ary,char *key,void *data);
|
||||
static void*(* _stdcall array_get_key_string)(array *ary,char *key);
|
||||
|
||||
static char*(* _stdcall get_full_path)(char *path);
|
||||
byte init_check_fs = 0;
|
||||
byte init_fs()
|
||||
{
|
||||
if(init_check_fs)return 1;
|
||||
char *name = "/sys/lib/fs.obj";
|
||||
array_list_func = cofflib_load(name);
|
||||
if (!array_list_func) exit();
|
||||
|
||||
get_full_path = (void *)cofflib_procload (array_list_func, "fs.get_full_path");
|
||||
if (!get_full_path) exit();
|
||||
|
||||
init_check_fs = 1;
|
||||
|
||||
array_set_key_string(&ADR_LIB_LIST,name,array_list_func);
|
||||
return init_list_function_adr();
|
||||
}
|
||||
|
||||
byte init_check_array = 0;
|
||||
byte init_array()
|
||||
{
|
||||
if(init_check_array)return 1;
|
||||
|
||||
char *name = "/sys/lib/array.obj";
|
||||
array_list_func = cofflib_load(name);
|
||||
if (!array_list_func) exit();
|
||||
|
||||
array_set_key_string = (void *)cofflib_procload (array_list_func, "array.key_string_set");
|
||||
if (!array_set_key_string) exit();
|
||||
|
||||
array_get_key_string = (void *)cofflib_procload (array_list_func, "array.key_string_get");
|
||||
if (!array_get_key_string) exit();
|
||||
|
||||
init_check_array = 1;
|
||||
|
||||
array_set_key_string(&ADR_LIB_LIST,name,array_list_func);
|
||||
init_list_function_adr();
|
||||
return init_fs();
|
||||
}
|
||||
|
||||
int load_dll2(dword dllname,struct_import* import_table, byte need_init)
|
||||
{
|
||||
struct_import* import_table1 = cofflib_load(dllname);
|
||||
if(import_table1)return -1;
|
||||
|
||||
dword i=0,ii=0;
|
||||
dword name = import_table1[i].name;
|
||||
dword name1 = import_table[ii].name;
|
||||
while(name)
|
||||
{
|
||||
if(!strcmp(name,name1))
|
||||
{
|
||||
import_table[ii].data=import_table1[i].data;
|
||||
name1 = import_table[++ii].name;
|
||||
}
|
||||
name = import_table1[++i].name;
|
||||
}
|
||||
if(need_init) dll_init(import_table1[0].data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void (* lib_init_eval)(dword,dword,dword,dword);
|
||||
|
||||
void dll_init(dword data)
|
||||
{
|
||||
lib_init_eval = data;
|
||||
lib_init_eval(&malloc,&free,&realloc,&load_dll2);
|
||||
}
|
||||
|
||||
byte first_load = 0;
|
||||
|
||||
dword load(char *name)
|
||||
{
|
||||
init_array();
|
||||
name = get_full_path(name);
|
||||
strtolower(name);
|
||||
if(array_get_key_string(&ADR_LIB_LIST,name))return 1;
|
||||
array_list_func = cofflib_load(name);
|
||||
if(!array_list_func) return 0;
|
||||
array_set_key_string(&ADR_LIB_LIST,name,array_list_func);
|
||||
return init_list_function_adr();
|
||||
}
|
||||
|
||||
dword get(char *name)
|
||||
{
|
||||
return (dword)array_get_key_string(&ADR_FUNC_LIST,name);
|
||||
}
|
||||
|
||||
static void (* _stdcall eval_set_pointer)(dword,dword);
|
||||
|
||||
dword init_list_function_adr()
|
||||
{
|
||||
dword i=0,data;
|
||||
char *name = 0;
|
||||
LOOP:
|
||||
name = array_list_func[i].name;
|
||||
if(!name) return 1;
|
||||
data = array_list_func[i++].data;
|
||||
if(!strcmp("lib_init",name))
|
||||
{
|
||||
dll_init(data);
|
||||
goto LOOP;
|
||||
}
|
||||
if(!strcmp("lib_pointer_library",name))
|
||||
{
|
||||
eval_set_pointer = data;
|
||||
eval_set_pointer(&load,&get);
|
||||
goto LOOP;
|
||||
}
|
||||
array_set_key_string(&ADR_FUNC_LIST,name,data);
|
||||
goto LOOP;
|
||||
}
|
||||
|
||||
EXPORT_
|
||||
export(load)
|
||||
export(get)
|
||||
_EXPORT
|
Loading…
Reference in New Issue
Block a user