X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame_sp%2Fvb_lib.c;h=5c1dae75010089def694009c81b8c0c7162ed039;hb=2af2c61f4dde2d22c1dc0e8dfad033b40d81dc6c;hp=c4df2cf3d853ce0493659bcec7a4623251287b6b;hpb=e63e92923fa0196ba7d538d4c8f5a16994e3bee8;p=rocksndiamonds.git diff --git a/src/game_sp/vb_lib.c b/src/game_sp/vb_lib.c index c4df2cf3..5c1dae75 100644 --- a/src/game_sp/vb_lib.c +++ b/src/game_sp/vb_lib.c @@ -9,13 +9,34 @@ #include "main_sp.h" +#include + /* helper functions for constructs not supported by C */ + +#if 1 + +void *REDIM_1D(int data_size, int first_data_pos, int last_data_pos) +{ + /* for a buffer of n elements, first_data_pos is 0 and last_data_pos is n-1 */ + /* a negative value for "first_data_pos" indicates a preceding buffer zone */ + + int data_count = last_data_pos - first_data_pos + 1; + int buffer_size = data_size * data_count; + int buffer_start = data_size * first_data_pos; + + return (checked_calloc(buffer_size) - buffer_start); +} + +#else + void *REDIM_1D(int a, int b, int c) { return checked_calloc(a * (c - b + 1)); } +#endif + void *REDIM_2D(int a, int b, int c, int d, int e) { return 0; @@ -55,16 +76,25 @@ char *INT_TO_STR(int a) boolean STRING_IS_LIKE(char *a, char *b) { - return 0; + if (*b == '*') // something like "*.sp" + { + return (strSuffix(a, &b[1])); + } + else + { + // more sophisticated patterns currently not supported + + return 0; + } } -void FILE_GET(FILE *a, int b, void *c, int d) +void FILE_GET(FILE *file, int offset, void *buffer, int num_bytes) { - fseek(a, b, SEEK_SET); + fseek(file, offset - 1, SEEK_SET); - while (d--) - *(byte *)c++ = fgetc(a); + while (num_bytes--) + *(byte *)buffer++ = fgetc(file); } int FILE_PUT(FILE *a, int b, void *c, int d) @@ -154,12 +184,21 @@ char *Hex(int a) int FileLen(char *a) { - return 0; + struct stat buffer; + + if (stat(a, &buffer) == 0) + { + return buffer.st_size; + } + else + { + return 0; + } } long GetTickCount() { - return 0; + return random_linux_libc(RANDOM_SIMPLE); } int GetAttr(char *a)