Super Mario 64 Source
A Super Mario 64 decompilation, brought to you by a bunch of clever folks.
Data Structures | Macros | Functions | Variables
utils.h File Reference
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  dir_list
 

Macros

#define SIZE_T_FORMAT   "%zu"
 
#define KB   1024
 
#define MB   (1024 * KB)
 
#define DIM(S_ARR_)   (sizeof(S_ARR_) / sizeof(S_ARR_[0]))
 
#define MIN(A_, B_)   ((A_) < (B_) ? (A_) : (B_))
 
#define MAX(A_, B_)   ((A_) > (B_) ? (A_) : (B_))
 
#define ALIGN(VAL_, ALIGNMENT_)   (((VAL_) + ((ALIGNMENT_) - 1)) & ~((ALIGNMENT_) - 1))
 
#define read_u32_be(buf)   (unsigned int)(((buf)[0] << 24) + ((buf)[1] << 16) + ((buf)[2] << 8) + ((buf)[3]))
 
#define read_u32_le(buf)   (unsigned int)(((buf)[1] << 24) + ((buf)[0] << 16) + ((buf)[3] << 8) + ((buf)[2]))
 
#define write_u32_be(buf, val)
 
#define read_u16_be(buf)   (((buf)[0] << 8) + ((buf)[1]))
 
#define write_u16_be(buf, val)
 
#define fprint_nibble(FP, NIB_)   fputc((NIB_) < 10 ? ('0' + (NIB_)) : ('A' + (NIB_) - 0xA), FP)
 
#define fprint_byte(FP, BYTE_)
 
#define print_nibble(NIB_)   fprint_nibble(stdout, NIB_)
 
#define print_byte(BYTE_)   fprint_byte(stdout, BYTE_)
 
#define MAX_DIR_FILES   128
 
#define ERROR(...)   fprintf(stderr, __VA_ARGS__)
 
#define INFO(...)   if (g_verbosity) printf(__VA_ARGS__)
 
#define INFO_HEX(...)   if (g_verbosity) print_hex(__VA_ARGS__)
 

Functions

int read_s16_be (unsigned char *buf)
 
float read_f32_be (unsigned char *buf)
 
int is_power2 (unsigned int val)
 
void fprint_hex (FILE *fp, const unsigned char *buf, int length)
 
void fprint_hex_source (FILE *fp, const unsigned char *buf, int length)
 
void print_hex (const unsigned char *buf, int length)
 
void swap_bytes (unsigned char *data, long length)
 
void reverse_endian (unsigned char *data, long length)
 
long filesize (const char *file_name)
 
void touch_file (const char *filename)
 
long read_file (const char *file_name, unsigned char **data)
 
long write_file (const char *file_name, unsigned char *data, long length)
 
void generate_filename (const char *in_name, char *out_name, char *extension)
 
charbasename (const char *name)
 
void make_dir (const char *dir_name)
 
long copy_file (const char *src_name, const char *dst_name)
 
void dir_list_ext (const char *dir, const char *extension, dir_list *list)
 
void dir_list_free (dir_list *list)
 
int str_ends_with (const char *str, const char *suffix)
 

Variables

int g_verbosity
 

Macro Definition Documentation

◆ ALIGN

#define ALIGN (   VAL_,
  ALIGNMENT_ 
)    (((VAL_) + ((ALIGNMENT_) - 1)) & ~((ALIGNMENT_) - 1))

◆ DIM

#define DIM (   S_ARR_)    (sizeof(S_ARR_) / sizeof(S_ARR_[0]))

◆ ERROR

#define ERROR (   ...)    fprintf(stderr, __VA_ARGS__)

◆ fprint_byte

#define fprint_byte (   FP,
  BYTE_ 
)
Value:
do { \
fprint_nibble(FP, (BYTE_) >> 4); \
fprint_nibble(FP, (BYTE_) & 0x0F); \
} while(0)

◆ fprint_nibble

#define fprint_nibble (   FP,
  NIB_ 
)    fputc((NIB_) < 10 ? ('0' + (NIB_)) : ('A' + (NIB_) - 0xA), FP)

◆ INFO

#define INFO (   ...)    if (g_verbosity) printf(__VA_ARGS__)

◆ INFO_HEX

#define INFO_HEX (   ...)    if (g_verbosity) print_hex(__VA_ARGS__)

◆ KB

#define KB   1024

◆ MAX

#define MAX (   A_,
  B_ 
)    ((A_) > (B_) ? (A_) : (B_))

◆ MAX_DIR_FILES

#define MAX_DIR_FILES   128

◆ MB

#define MB   (1024 * KB)

◆ MIN

#define MIN (   A_,
  B_ 
)    ((A_) < (B_) ? (A_) : (B_))

◆ print_byte

#define print_byte (   BYTE_)    fprint_byte(stdout, BYTE_)

◆ print_nibble

#define print_nibble (   NIB_)    fprint_nibble(stdout, NIB_)

◆ read_u16_be

#define read_u16_be (   buf)    (((buf)[0] << 8) + ((buf)[1]))

◆ read_u32_be

#define read_u32_be (   buf)    (unsigned int)(((buf)[0] << 24) + ((buf)[1] << 16) + ((buf)[2] << 8) + ((buf)[3]))

◆ read_u32_le

#define read_u32_le (   buf)    (unsigned int)(((buf)[1] << 24) + ((buf)[0] << 16) + ((buf)[3] << 8) + ((buf)[2]))

◆ SIZE_T_FORMAT

#define SIZE_T_FORMAT   "%zu"

◆ write_u16_be

#define write_u16_be (   buf,
  val 
)
Value:
do { \
(buf)[0] = ((val) >> 8) & 0xFF; \
(buf)[1] = ((val)) & 0xFF; \
} while(0)

◆ write_u32_be

#define write_u32_be (   buf,
  val 
)
Value:
do { \
(buf)[0] = ((val) >> 24) & 0xFF; \
(buf)[1] = ((val) >> 16) & 0xFF; \
(buf)[2] = ((val) >> 8) & 0xFF; \
(buf)[3] = (val) & 0xFF; \
} while(0)

Function Documentation

◆ basename()

char* basename ( const char name)

◆ copy_file()

long copy_file ( const char src_name,
const char dst_name 
)

◆ dir_list_ext()

void dir_list_ext ( const char dir,
const char extension,
dir_list list 
)

◆ dir_list_free()

void dir_list_free ( dir_list list)

◆ filesize()

long filesize ( const char file_name)

◆ fprint_hex()

void fprint_hex ( FILE *  fp,
const unsigned char buf,
int  length 
)

◆ fprint_hex_source()

void fprint_hex_source ( FILE *  fp,
const unsigned char buf,
int  length 
)

◆ generate_filename()

void generate_filename ( const char in_name,
char out_name,
char extension 
)

◆ is_power2()

int is_power2 ( unsigned int  val)

◆ make_dir()

void make_dir ( const char dir_name)

◆ print_hex()

void print_hex ( const unsigned char buf,
int  length 
)

◆ read_f32_be()

float read_f32_be ( unsigned char buf)

◆ read_file()

long read_file ( const char file_name,
unsigned char **  data 
)

◆ read_s16_be()

int read_s16_be ( unsigned char buf)

◆ reverse_endian()

void reverse_endian ( unsigned char data,
long  length 
)

◆ str_ends_with()

int str_ends_with ( const char str,
const char suffix 
)

◆ swap_bytes()

void swap_bytes ( unsigned char data,
long  length 
)

◆ touch_file()

void touch_file ( const char filename)

◆ write_file()

long write_file ( const char file_name,
unsigned char data,
long  length 
)

Variable Documentation

◆ g_verbosity

int g_verbosity