Source file: /~heha/hs/gputils64-210929.zip/libgputils/gpsystem.h

/* General system functions
   Copyright 2003, 2004, 2005
   Craig Franklin

    Copyright 2015-2016 Molnár Károly
*/

#pragma once

/* Used in disasm. */
#define EXPLANATION_DISTANCE            60
#define TABULATOR_SIZE                  8
#define ARRAY_SIZE(a)                   (sizeof(a) / sizeof((a)[0]))

#define FlagSet(v,f)		((v) |= (f))
#define FlagClr(v,f)		((v) &= ~(f))
#define FlagIsSet(v,f)		!FlagIsClr(v,f)
#define FlagIsClr(v,f)		!((v)&(f))

#define FlagsIsAllSet(v,f)	(((v) & (f)) == (f))
#define FlagsIsNotAllSet(v,f)	(((v) & (f)) != (f))
#define FlagsIsAllClr(v,f)	FlagIsClr(v,f)
#define FlagsIsNotAllClr(v,f)	FlagIsSet(v,f)

EXDATA const char* gp_header_path;
EXDATA const char* gp_lkr_path;
EXDATA const char* gp_lib_path;

FUNC(void) gp_init(void);

extern void gp_fputl16(int Data, FILE* Fp);
extern void gp_fputl32(int Data, FILE* Fp);
extern void gp_fputzero(size_t Number, FILE* Fp);
extern void gp_fputvar(const void* Data, size_t Number, FILE* Fp);

__forceinline uint16_t gp_getu16(const uint8_t *Addr) {
  return *(uint16_t*)Addr;
}

__forceinline int16_t gp_getl16(const uint8_t *Addr) {
  return (int16_t)gp_getu16(Addr);
}

__forceinline uint32_t gp_getu32(const uint8_t *Addr) {
  return *(uint32_t*)Addr;
}

__forceinline int32_t gp_getl32(const uint8_t *Addr) {
  return (int32_t)gp_getu32(Addr);
}

__forceinline void gp_putl16(uint8_t *Addr, unsigned Data) {
  assert(Data<65536);
  *(uint16_t*)Addr = (uint16_t)Data;	// Big-Endian ist ausgestorben!!
}

__forceinline void gp_putl32(uint8_t *Addr, unsigned Data) {
  *(uint32_t*)Addr = (uint32_t)Data;
}

FUNC(int32_t) gp_getb32(const uint8_t* Addr);
EXTERN_C void   gp_putb32(uint8_t* Addr, uint32_t Data);

FUNC(bool) gp_num_range_is_overlapped(int Area_start, int Area_end, int Ref_start, int Ref_end);

FUNC(void) gp_date_string(char* Buffer, size_t Sizeof_buffer);

//FUNC(void*) gp_malloc(size_t Size, const char* File, size_t Line);
//FUNC(void*) gp_calloc(size_t Nmemb, size_t Size, const char* File, size_t Line);
FUNC(void*) gp_realloc(void* Mem, size_t Size, const char* File, size_t Line);
FUNC(char*) gp_strdup(const char *String, const char* File, size_t Line);
FUNC(char*) gp_strndup(const char *String, size_t Length, const char* File, size_t Line);

//#define GP_Malloc(Size)                 gp_malloc(Size, __FILE__, __LINE__)
//#define GP_Calloc(Nmemb, Size)          gp_calloc(Nmemb, Size, __FILE__, __LINE__)
#define GP_Realloc(Mem, Size)           gp_realloc(Mem, Size, __FILE__, __LINE__)
#define GP_Strdup(String)               gp_strdup(String, __FILE__, __LINE__)
#define GP_Strndup(String, Length)      gp_strndup(String, Length, __FILE__, __LINE__)

FUNC(char*) gp_strdup_lower_case(const char* Name);
FUNC(char*) gp_strdup_upper_case(const char* Name);
FUNC(char*) gp_strncpy(char* Dest, const char* Src, size_t Maxlen);
FUNC(char*) gp_arch_strncpy(char* Dest, const char* Src, size_t Maxlen);
FUNC(char*) gp_stptoupper(char* Dest, const char* Src, size_t Maxlen);

FUNC(char*) gp_str_from_Pstr(char* C_str, size_t C_max_size, const uint8_t *Pascal_str, size_t Pascal_max_size,
                              bool* Is_limited_length);

FUNC(size_t) gp_Pstr_from_str(uint8_t* Pascal_str, size_t Pascal_max_size, const char* C_str, bool* Is_limited_length);
FUNC(size_t) gp_strlen_Plimit(const char* C_str, size_t Pascal_max_size, bool* Is_limited_length);

FUNC(size_t) gp_align_text(char* Buffer, size_t Buffer_length, size_t Current_length, size_t Aligned_to_length);
CFUNC(size_t) gp_exclamation(char* Buffer, size_t Buffer_length, size_t Current_length, const char* Format, ...);

FUNC(char*) gp_absolute_path(char* File_name);

FUNC(void) gp_exit_if_arg_an_option(const struct option* Options, int Opt_max_index, int Opt_index,
                                     const char* Opt_string, int Opt_char, const char* Command);
Detected encoding: UTF-80