jack-compiler/util.h

33 lines
718 B
C
Raw Normal View History

2020-12-20 13:58:10 -05:00
#ifndef UTIL_H
#define UTIL_H
#include <stdio.h>
2020-12-21 13:05:49 -05:00
/* util
* Random utilities. */
2020-12-20 13:58:10 -05:00
2020-12-21 16:11:23 -05:00
// Macros
#define eprintf(...) fprintf (stderr, __VA_ARGS__)
#define count(array, type) ((sizeof(array)) / (sizeof(type)))
#define strcount(array) count(array, char*)
2020-12-21 13:05:49 -05:00
typedef struct stringlist {
2020-12-21 19:50:55 -05:00
const char* content;
2020-12-21 13:05:49 -05:00
struct stringlist* next;
} STRINGLIST;
2020-12-20 13:58:10 -05:00
2020-12-21 19:50:55 -05:00
typedef struct {
const char** items;
const int size;
} STRINGARRAY;
char* heapstr(const char* str, int len);
char* ezheapstr(const char* str);
2020-12-21 13:05:49 -05:00
int countplaces(int n);
2020-12-20 13:58:10 -05:00
char* itoa(int i);
2020-12-21 19:50:55 -05:00
void* copy(void* v, int size);
2020-12-21 13:05:49 -05:00
2020-12-21 19:50:55 -05:00
STRINGLIST* initstrlist(const char** strs, int count);
2020-12-21 13:05:49 -05:00
void printstrlist(STRINGLIST* strlist, FILE* stream);
void freestrlist(STRINGLIST* strlist);
2020-12-20 13:58:10 -05:00
#endif