lib.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef LIB_H
  2. #define LIB_H
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <assert.h>
  7. // 基本常數
  8. #define FALSE 0
  9. #define TRUE 1
  10. #define BYTE unsigned char
  11. #define BOOL unsigned char
  12. #define INT32 int
  13. #define INT16 short
  14. #define INT8 char
  15. #define UINT32 unsigned int
  16. #define UINT16 unsigned short
  17. #define UINT8 unsigned char
  18. #define MAX_LEN 512
  19. // 基本函數
  20. #define min(x,y) (x < y?x:y)
  21. #define max(x,y) (x > y?x:y)
  22. #define ASSERT(cond) assert(cond)
  23. #define ObjNew(type, count) newMemory(count*sizeof(type))
  24. #define ObjFree freeMemory
  25. #define strFree freeMemory
  26. void* newMemory(int size);
  27. void freeMemory(void *ptr);
  28. void checkMemory();
  29. char *newStr(char *str);
  30. char *newSubstr(char *str, int i, int len);
  31. BYTE* newFileBytes(char *fileName, int *sizePtr);
  32. char* newFileStr(char *fileName);
  33. // 字串函數
  34. #define strEqual(str1, str2) (strcmp(str1, str2)==0)
  35. #define strMember(ch, set) (strchr(set, ch) != NULL)
  36. void strSubstr(char *substr, char *str, int i, int len);
  37. void strReplace(char *str, char *from, char to);
  38. void strTrim(char *trimStr, char *str, char *set);
  39. char *strSpaces(int len);
  40. void strToUpper(char *str);
  41. BOOL strPartOf(char *token, char *set);
  42. void strPrint(void *data);
  43. void strPrintln(void *data);
  44. // 函數指標 (用於ArrayEach(), HashTableEach()中)
  45. typedef void (*FuncPtr1) (void *);
  46. typedef int (*FuncPtr2) (void *, void *);
  47. extern char SPLITER[];
  48. extern char SPACE[];
  49. extern char ALPHA[];
  50. extern char DIGIT[];
  51. #endif