MISC.H 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Header for misc.c.
  3. */
  4. #ifndef PUTTY_MISC_H
  5. #define PUTTY_MISC_H
  6. #include "puttymem.h"
  7. #include <stdio.h> /* for FILE * */
  8. #include <stdarg.h> /* for va_list */
  9. #include <time.h> /* for struct tm */
  10. #ifndef FALSE
  11. #define FALSE 0
  12. #endif
  13. #ifndef TRUE
  14. #define TRUE 1
  15. #endif
  16. typedef struct Filename Filename;
  17. typedef struct FontSpec FontSpec;
  18. #ifdef MPEXT
  19. __int64 parse_blocksize64(const char *bs);
  20. #endif
  21. unsigned long parse_blocksize(const char *bs);
  22. char ctrlparse(char *s, char **next);
  23. char *dupstr(const char *s);
  24. char *dupcat(const char *s1, ...);
  25. char *dupprintf(const char *fmt, ...);
  26. char *dupvprintf(const char *fmt, va_list ap);
  27. void burnstr(char *string);
  28. int toint(unsigned);
  29. char *fgetline(FILE *fp);
  30. void base64_encode_atom(unsigned char *data, int n, char *out);
  31. struct bufchain_granule;
  32. typedef struct bufchain_tag {
  33. struct bufchain_granule *head, *tail;
  34. int buffersize; /* current amount of buffered data */
  35. } bufchain;
  36. void bufchain_init(bufchain *ch);
  37. void bufchain_clear(bufchain *ch);
  38. int bufchain_size(bufchain *ch);
  39. void bufchain_add(bufchain *ch, const void *data, int len);
  40. void bufchain_prefix(bufchain *ch, void **data, int *len);
  41. void bufchain_consume(bufchain *ch, int len);
  42. void bufchain_fetch(bufchain *ch, void *data, int len);
  43. struct tm ltime(void);
  44. void smemclr(void *b, size_t len);
  45. /*
  46. * Debugging functions.
  47. *
  48. * Output goes to debug.log
  49. *
  50. * debug(()) (note the double brackets) is like printf().
  51. *
  52. * dmemdump() and dmemdumpl() both do memory dumps. The difference
  53. * is that dmemdumpl() is more suited for when the memory address is
  54. * important (say because you'll be recording pointer values later
  55. * on). dmemdump() is more concise.
  56. */
  57. #ifdef DEBUG
  58. void debug_printf(char *fmt, ...);
  59. void debug_memdump(void *buf, int len, int L);
  60. #define debug(x) (debug_printf x)
  61. #define dmemdump(buf,len) debug_memdump (buf, len, 0);
  62. #define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
  63. #else
  64. #define debug(x)
  65. #define dmemdump(buf,len)
  66. #define dmemdumpl(buf,len)
  67. #endif
  68. #ifndef lenof
  69. #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
  70. #endif
  71. #ifndef min
  72. #define min(x,y) ( (x) < (y) ? (x) : (y) )
  73. #endif
  74. #ifndef max
  75. #define max(x,y) ( (x) > (y) ? (x) : (y) )
  76. #endif
  77. #define GET_32BIT_LSB_FIRST(cp) \
  78. (((unsigned long)(unsigned char)(cp)[0]) | \
  79. ((unsigned long)(unsigned char)(cp)[1] << 8) | \
  80. ((unsigned long)(unsigned char)(cp)[2] << 16) | \
  81. ((unsigned long)(unsigned char)(cp)[3] << 24))
  82. #define PUT_32BIT_LSB_FIRST(cp, value) ( \
  83. (cp)[0] = (unsigned char)(value), \
  84. (cp)[1] = (unsigned char)((value) >> 8), \
  85. (cp)[2] = (unsigned char)((value) >> 16), \
  86. (cp)[3] = (unsigned char)((value) >> 24) )
  87. #define GET_16BIT_LSB_FIRST(cp) \
  88. (((unsigned long)(unsigned char)(cp)[0]) | \
  89. ((unsigned long)(unsigned char)(cp)[1] << 8))
  90. #define PUT_16BIT_LSB_FIRST(cp, value) ( \
  91. (cp)[0] = (unsigned char)(value), \
  92. (cp)[1] = (unsigned char)((value) >> 8) )
  93. #define GET_32BIT_MSB_FIRST(cp) \
  94. (((unsigned long)(unsigned char)(cp)[0] << 24) | \
  95. ((unsigned long)(unsigned char)(cp)[1] << 16) | \
  96. ((unsigned long)(unsigned char)(cp)[2] << 8) | \
  97. ((unsigned long)(unsigned char)(cp)[3]))
  98. #define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp)
  99. #define PUT_32BIT_MSB_FIRST(cp, value) ( \
  100. (cp)[0] = (unsigned char)((value) >> 24), \
  101. (cp)[1] = (unsigned char)((value) >> 16), \
  102. (cp)[2] = (unsigned char)((value) >> 8), \
  103. (cp)[3] = (unsigned char)(value) )
  104. #define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value)
  105. #define GET_16BIT_MSB_FIRST(cp) \
  106. (((unsigned long)(unsigned char)(cp)[0] << 8) | \
  107. ((unsigned long)(unsigned char)(cp)[1]))
  108. #define PUT_16BIT_MSB_FIRST(cp, value) ( \
  109. (cp)[0] = (unsigned char)((value) >> 8), \
  110. (cp)[1] = (unsigned char)(value) )
  111. #endif