utils.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef COMMON_UTILS_H
  4. #define COMMON_UTILS_H
  5. #ifndef NULL
  6. #define NULL (void *)0
  7. #endif
  8. #define LOWER(c) (((c)>='A' && (c) <= 'Z') ? ((c)+('a'-'A')) : (c))
  9. #define UPPER(c) (((c)>='a' && (c) <= 'z') ? ((c)+('A'-'a')) : (c) )
  10. /* strcasecmp -> stricmp -> str_cmp */
  11. #if defined(_WIN32) && !defined(MINGW)
  12. int strcasecmp(const char *arg1, const char *arg2);
  13. int strncasecmp(const char *arg1, const char *arg2, size_t n);
  14. void str_upper(char *name);
  15. void str_lower(char *name);
  16. char *rindex(char *str, char c);
  17. #endif
  18. void dump(unsigned char *buffer, int num);
  19. int newt_sqrt(int value); //Newton aproximation for getting a fast sqrt.
  20. struct StringBuf {
  21. char *buf_;
  22. char *ptr_;
  23. unsigned int max_;
  24. };
  25. struct StringBuf * StringBuf_Malloc(void);
  26. void StringBuf_Init(struct StringBuf *);
  27. int StringBuf_Printf(struct StringBuf *,const char *,...);
  28. int StringBuf_Append(struct StringBuf *,const struct StringBuf *);
  29. char * StringBuf_Value(struct StringBuf *);
  30. void StringBuf_Destroy(struct StringBuf *);
  31. void StringBuf_Free(struct StringBuf *);
  32. void findfile(const char *p, const char *pat, void (func)(const char*));
  33. //////////////////////////////////////////////////////////////////////////
  34. // byte word dword access [Shinomori]
  35. //////////////////////////////////////////////////////////////////////////
  36. extern unsigned char GetByte(unsigned long val, size_t num);
  37. extern unsigned short GetWord(unsigned long val, size_t num);
  38. extern unsigned short MakeWord(unsigned char byte0, unsigned char byte1);
  39. extern unsigned long MakeDWord(unsigned short word0, unsigned short word1);
  40. #endif