first commit from linux
This commit is contained in:
6
DtsodC/src/DtsodV24.c
Normal file
6
DtsodC/src/DtsodV24.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#if COSMOPOLITAN
|
||||
#include "../cosmopolitan/cosmopolitan.h"
|
||||
#else
|
||||
#include "stdio.h"
|
||||
#endif
|
||||
|
||||
6
DtsodC/src/DtsodV24.h
Normal file
6
DtsodC/src/DtsodV24.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#if COSMOPOLITAN
|
||||
#include "../cosmopolitan/cosmopolitan.h"
|
||||
#else
|
||||
#include "stdio.h"
|
||||
#endif
|
||||
|
||||
60
DtsodC/src/autosize_array/Autoarr.c
Normal file
60
DtsodC/src/autosize_array/Autoarr.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#ifndef STDLIB
|
||||
#include "../../cosmopolitan/cosmopolitan.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#endif
|
||||
#include "Autoarr.h"
|
||||
|
||||
|
||||
Autoarr* Autoarr_create(uint16 max_block_count, uint16 max_block_length, strict_type type){
|
||||
Autoarr* rezult=malloc(sizeof(Autoarr));
|
||||
rezult->type=type;
|
||||
rezult->max_block_length=max_block_length;
|
||||
rezult->curr_block_length=0;
|
||||
rezult->max_block_count=max_block_count;
|
||||
rezult->block_count=0;
|
||||
rezult->values=malloc(rezult->max_block_count*GetTypeSize(type));
|
||||
return rezult;
|
||||
}
|
||||
|
||||
uint32 Autoarr_length(Autoarr *a){
|
||||
return (uint32)((a->block_count-1)*a->max_block_length+a->curr_block_length);
|
||||
}
|
||||
uint32 Autoarr_max_length(Autoarr *a){
|
||||
return a->max_block_count*a->max_block_length;
|
||||
}
|
||||
|
||||
void __Autoarr_add_block(Autoarr *autoarr){
|
||||
if (autoarr->block_count>=autoarr->max_block_count)
|
||||
throwerr(ERR_MAXLENGTH);
|
||||
if (autoarr->curr_block_length==(autoarr->max_block_length|0))
|
||||
autoarr->curr_block_length=0;
|
||||
else if (autoarr->curr_block_length>0)
|
||||
throwerr(ERR_NOTFULL);
|
||||
*(autoarr->values+autoarr->block_count)=malloc(autoarr->max_block_length*GetTypeSize(autoarr->type));
|
||||
autoarr->block_count++;
|
||||
}
|
||||
|
||||
void Autoarr_add(Autoarr *autoarr, void *element){
|
||||
if(Autoarr_length(autoarr)<Autoarr_max_length(autoarr))
|
||||
throwerr(ERR_MAXLENGTH);
|
||||
if (autoarr->curr_block_length==autoarr->max_block_length)
|
||||
__Autoarr_add_block(autoarr);
|
||||
AssignVoidToVoid((autoarr->values+autoarr->block_count-1)+autoarr->curr_block_length, element, autoarr->type);
|
||||
}
|
||||
|
||||
void Autoarr_set(Autoarr *autoarr, uint32 index, void *element){
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Autoarr_remove(Autoarr *autoarr, uint32 index){
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Autoarr_removeRange(Autoarr *autoarr, uint32 startIndex, uint32 length){
|
||||
|
||||
}
|
||||
40
DtsodC/src/autosize_array/Autoarr.h
Normal file
40
DtsodC/src/autosize_array/Autoarr.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef STDLIB
|
||||
#include "../../cosmopolitan/cosmopolitan.h"
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#include "../strict_types.h"
|
||||
#include "../err_t.h"
|
||||
|
||||
typedef struct Autoarr{
|
||||
void** values;
|
||||
strict_type type;
|
||||
uint16 max_block_length;
|
||||
uint16 curr_block_length;
|
||||
uint16 block_count;
|
||||
uint16 max_block_count;
|
||||
} Autoarr;
|
||||
typedef Autoarr Autoarr;
|
||||
|
||||
|
||||
Autoarr* Autoarr_create(uint16 max_length, uint16 max_block_length, strict_type type);
|
||||
|
||||
uint32 Autoarr_length(Autoarr *a);
|
||||
uint32 Autoarr_max_length(Autoarr *a);
|
||||
|
||||
void Autoarr_add(Autoarr *autoarr, void *element);
|
||||
|
||||
void Autoarr_set(Autoarr *autoarr, uint32 index, void *element);
|
||||
|
||||
void Autoarr_remove(Autoarr *autoarr, uint32 index);
|
||||
|
||||
void Autoarr_removeRange(Autoarr *autoarr, uint32 startIndex, uint32 length);
|
||||
|
||||
int8 Autoarr_get_int8(Autoarr *autoarr, uint32 index);
|
||||
uint8 Autoarr_get_uint8(Autoarr *autoarr, uint32 index);
|
||||
int16 Autoarr_get_int16(Autoarr *autoarr, uint32 index);
|
||||
uint16 Autoarr_get_uint16(Autoarr *autoarr, uint32 index);
|
||||
int32 Autoarr_get_int32(Autoarr *autoarr, uint32 index);
|
||||
uint32 Autoarr_get_uint32(Autoarr *autoarr, uint32 index);
|
||||
int64 Autoarr_get_int64(Autoarr *autoarr, uint32 index);
|
||||
uint64 Autoarr_get_uint64(Autoarr *autoarr, uint32 index);
|
||||
9
DtsodC/src/err_t.h
Normal file
9
DtsodC/src/err_t.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef __ERR_AUTOARR_DEFINED
|
||||
#define __ERR_AUTOARR_DEFINED
|
||||
typedef enum err_t {
|
||||
SUCCESS, ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX, ERR_NOTFULL
|
||||
} err_t;
|
||||
|
||||
void throwstr(const char* errmesg);
|
||||
void throwerr(err_t err);
|
||||
#endif
|
||||
39
DtsodC/src/strict_types.c
Normal file
39
DtsodC/src/strict_types.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef STDLIB
|
||||
#include "../cosmopolitan/cosmopolitan.h"
|
||||
#else
|
||||
#include "stdint.h"
|
||||
#endif
|
||||
#include "strict_types.h"
|
||||
#include "err_t.h"
|
||||
|
||||
int8 GetTypeSize(strict_type type){
|
||||
int8 type_size=0;
|
||||
switch (type)
|
||||
{
|
||||
case Int8: type_size=8; break;
|
||||
case Uint8: type_size=8; break;
|
||||
case Int16: type_size=16; break;
|
||||
case Uint16: type_size=16; break;
|
||||
case Int32: type_size=32; break;
|
||||
case Uint32: type_size=32; break;
|
||||
case Int64: type_size=64; break;
|
||||
case Uint64: type_size=64; break;
|
||||
default: throwerr(ERR_WRONGTYPE);
|
||||
}
|
||||
return type_size;
|
||||
}
|
||||
|
||||
void AssignVoidToVoid(void* a, void*b, strict_type type){
|
||||
switch (type)
|
||||
{
|
||||
case Int8: *((int8*)a)=*((int8*)b); break;
|
||||
case Uint8: *((uint8*)a)=*((uint8*)b); break;
|
||||
case Int16: *((int16*)a)=*((int16*)b); break;
|
||||
case Uint16: *((uint16*)a)=*((uint16*)b); break;
|
||||
case Int32: *((int32*)a)=*((int32*)b); break;
|
||||
case Uint32: *((uint32*)a)=*((uint32*)b); break;
|
||||
case Int64: *((int64*)a)=*((int64*)b); break;
|
||||
case Uint64: *((uint64*)a)=*((uint64*)b); break;
|
||||
default: throwerr(ERR_WRONGTYPE);
|
||||
}
|
||||
}
|
||||
26
DtsodC/src/strict_types.h
Normal file
26
DtsodC/src/strict_types.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef STDLIB
|
||||
#include "../cosmopolitan/cosmopolitan.h"
|
||||
#else
|
||||
#include "stdint.h"
|
||||
#endif
|
||||
#include "err_t.h"
|
||||
|
||||
typedef int8_t int8;
|
||||
typedef uint8_t uint8;
|
||||
typedef int16_t int16;
|
||||
typedef uint16_t uint16;
|
||||
typedef int32_t int32;
|
||||
typedef uint32_t uint32;
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
|
||||
#ifndef __STRICT_TYPES_DEFINED
|
||||
#define __STRICT_TYPES_DEFINED
|
||||
typedef enum strict_type{
|
||||
Int8, Int16, Int32, Int64, Uint8, Uint16, Uint32, Uint64
|
||||
} strict_type;
|
||||
|
||||
int8 GetTypeSize(strict_type type);
|
||||
|
||||
void AssignVoidToVoid(void* a, void*b, strict_type type);
|
||||
#endif
|
||||
45
DtsodC/src/test.c
Normal file
45
DtsodC/src/test.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef STDLIB
|
||||
#include "../cosmopolitan/cosmopolitan.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <locale.h>
|
||||
#include <uchar.h>
|
||||
#include <wchar.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#endif
|
||||
#include "strict_types.h"
|
||||
#include "autosize_array/Autoarr.h"
|
||||
void nsleep(long miliseconds) {
|
||||
struct timespec ts = {10, miliseconds * 1000000L};
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
int8 main(){
|
||||
printf("\e[32mdtsod parser in c language!\n");
|
||||
dsleep(0.5);
|
||||
//Autoarr* ar=Autoarr_create(100,10,Int8);
|
||||
//Autoarr_add_int8(&ar,-1);
|
||||
//printf("ar[0]==%d",Autoarr_get_int8(&ar,0));
|
||||
//free(ar);
|
||||
//setlocale(LC_ALL, "en-US.Unicode");
|
||||
/*struct stat st;
|
||||
FILE* f1 = fopen("1.gui","r");
|
||||
FILE* f2 = fopen("2.gui","r");
|
||||
fstat(fileno(f1), &st);
|
||||
size_t size = st.st_size;
|
||||
char page1[size];
|
||||
fread(page1, 8, size, f1);
|
||||
char page2[size];
|
||||
fread(page2, 8, size, f2);
|
||||
printf("\e[31m\n");
|
||||
for (int64 i = 0; i<100000; i++){
|
||||
nsleep(10000L);
|
||||
if(i%2==0) printf("%s", page1);
|
||||
else printf("%s", page2);
|
||||
}*/
|
||||
printf("\e[32m\n");
|
||||
//getc(stdin);
|
||||
return 0;
|
||||
}
|
||||
17
DtsodC/src/throw.c
Normal file
17
DtsodC/src/throw.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef STDLIB
|
||||
#include "../cosmopolitan/cosmopolitan.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include "err_t.h"
|
||||
|
||||
void throwstr(const char* errmesg){
|
||||
printf("\e[31mthrowed error: %s\e[0m\n",errmesg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void throwerr(err_t err){
|
||||
printf("\e[31mthrowed error: err_t:%d\e[0m\n",err);
|
||||
exit(err);
|
||||
}
|
||||
Reference in New Issue
Block a user