Пример #1
0
IO$Posix_t *_posix_new(const Std$Type_t *Type, int Handle) {
	IO$Posix_t *Stream = (IO$Posix_t *)Riva$Memory$alloc_atomic(sizeof(IO$Posix_t));
	Stream->Type = Type;
	Stream->Handle = Handle;
	Riva$Memory$register_finalizer((void *)Stream, (void *)posix_finalize, 0, 0, 0);
	fcntl(Handle, F_SETFD, fcntl(Handle, F_GETFD, 0) | FD_CLOEXEC);
	return Stream;
};
Пример #2
0
static char *extract_chars_rest(buffer_t *Stream) {
	int Length = 0;
	for (node_t *Node = Stream->Head; Node; Node = Node->Next) Length += Node->Length;
	char *Buffer = Riva$Memory$alloc_atomic(Length + 1);
	char *Ptr = Buffer;
	for (node_t *Node = Stream->Head; Node; Node = Node->Next) Ptr = mempcpy(Ptr, Node->Chars, Node->Length);
	Buffer[Length] = 0;
	Stream->Head = Stream->Tail = 0;
	Stream->Position += Length;
	return Buffer;
};
Пример #3
0
char *_flatten(Std$String_t *String) {
	if (String->Count > 1) {
		char *Flat = Riva$Memory$alloc_atomic(String->Length.Value + 1);
		char *P = Flat;
		for (int I = 0; I < String->Count; ++I) {
			memcpy(P, String->Blocks[I].Chars.Value, String->Blocks[I].Length.Value);
			P += String->Blocks[I].Length.Value;
		};
		*P = 0;
		return Flat;
	} else {
		char *Chars = String->Blocks[0].Chars.Value;
		long Length = String->Blocks[0].Length.Value;
		if (Chars[Length] == 0) {
			return Chars;
		} else {
			char *Flat = Riva$Memory$alloc_atomic(Length + 1);
			memcpy(Flat, Chars, Length);
			Flat[Length] = 0;
			return Flat;
		};
	};
};
Пример #4
0
void __init() {
	FILE *MapFile = fopen("Types.map", "r");
	char Buffer[256];
	while (fgets(Buffer, 256, MapFile)) {
		int Length = strlen(Buffer);
		char *Temp = strchr(Buffer, '=');
		if (Temp) {
			int L0 = Temp - Buffer - 1;
			int L1 = Length - L0 - 4;
			char *GtkName = Riva$Memory$alloc_atomic(L0 + 1);
			char *RivaName = Riva$Memory$alloc_atomic(L1 + 1);
			memcpy(GtkName, Buffer, L0);
			GtkName[L0] = 0;
			memcpy(RivaName, Temp + 2, L1);
			RivaName[L1] = 0;
			printf("Adding type: %s -> %s\n", GtkName, RivaName);
			Util$StringTable$put(GTypeModules, GtkName, (void *)RivaName);
		} else {
			printf("Skipping line: %s", Buffer);
		};
	};
	fclose(MapFile);
	FILE *OutFile = fopen("TypeMap.c", "w");
	fprintf(OutFile, "#include <Util/StringTable.h>\n\n");
	fprintf(OutFile, "static Util$StringTable_node __Entries__[%d] = {\n", GTypeModules->Size);
	for (int I = 0; I < GTypeModules->Size; ++I) {
		Util$StringTable_node *Node = GTypeModules->Entries + I;
		if (Node->Key) {
			fprintf(OutFile, "\t{\"%s\", %d, 0x%x, \"%s\"},\n", Node->Key, Node->Length, Node->Hash, Node->Value);
		} else {
			fprintf(OutFile, "\t{0, 0, 0, 0},\n");
		};
	};
	fprintf(OutFile, "};\n\n");
	fprintf(OutFile, "Util$StringTable_t Table[] = {Util$StringTable$T, %d, %d, __Entries__};\n", GTypeModules->Size, GTypeModules->Space);
	fclose(OutFile);
};
Пример #5
0
static int buffer_writec(buffer_t *Stream, char Char) {
	char *Chars = Riva$Memory$alloc_atomic(1);
	Chars[0] = Char;
	node_t *Node = new(node_t);
	Node->Length = 1;
	Node->Chars = Chars;
	lock(Stream);
	if (Stream->Tail) {
		Stream->Tail->Next = Node;
		Stream->Tail = Node;
	} else {
		Stream->Head = Node;
		Stream->Tail = Node;
	};
	broadcast(Stream);
	unlock(Stream);
	return 1;
};
Пример #6
0
static int buffer_write(buffer_t *Stream, const char *Buffer, int Count, int Block) {
	char *Chars = Riva$Memory$alloc_atomic(Count);
	memcpy(Chars, Buffer, Count);
	node_t *Node = new(node_t);
	Node->Length = Count;
	Node->Chars = Chars;
	lock(Stream);
	if (Stream->Tail) {
		Stream->Tail->Next = Node;
		Stream->Tail = Node;
	} else {
		Stream->Head = Node;
		Stream->Tail = Node;
	};
	broadcast(Stream);
	unlock(Stream);
	return Count;
};
Пример #7
0
static int buffer_writes(buffer_t *Stream, const char *Text) {
	int Length = strlen(Text);
	char *Chars = Riva$Memory$alloc_atomic(Length);
	memcpy(Chars, Text, Length);
	node_t *Node = new(node_t);
	Node->Length = Length;
	Node->Chars = Chars;
	lock(Stream);
	if (Stream->Tail) {
		Stream->Tail->Next = Node;
		Stream->Tail = Node;
	} else {
		Stream->Head = Node;
		Stream->Tail = Node;
	};
	broadcast(Stream);
	unlock(Stream);
	return Length;
};
Пример #8
0
static char *extract_chars(buffer_t *Stream, node_t *EndNode, int EndOffset) {
	int Length = EndOffset;
	for (node_t *Node = Stream->Head; Node != EndNode; Node = Node->Next) Length += Node->Length;
	char *Result = Riva$Memory$alloc_atomic(Length + 1);
	Result[Length] = 0;
	char *Ptr = Result;
	for (node_t *Node = Stream->Head; Node != EndNode; Node = Node->Next) {
		memcpy(Ptr, Node->Chars, Node->Length);
		Ptr += Node->Length;
	};
	if (EndOffset) {
		memcpy(Ptr, EndNode->Chars, EndOffset);
		if ((EndNode->Length -= EndOffset) == 0) {
			EndNode = EndNode->Next;
		} else {
			EndNode->Chars += EndOffset;
		};
	};
	Stream->Head = EndNode;
	if (EndNode == 0) Stream->Tail = 0;
	Stream->Position += Length;
	return Result;
};
Пример #9
0
static fast_buffer * restrict alloc_fast_buffer(void) {
	fast_buffer *Buffer = new(fast_buffer);
	Buffer->Chars = Riva$Memory$alloc_atomic(FastBufferSize);
	return Buffer;
};