Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.0 KiB

  1. /* File: C:\WACKER\xfer\cmprs0.c
  2. * created from HAWIN sources
  3. * cmprs0.c -- Functions common to compression and decompression
  4. *
  5. * Copyright 1989,1994 by Hilgraeve Inc. -- Monroe, MI
  6. * All rights reserved
  7. *
  8. * $Revision: 1 $
  9. * $Date: 10/05/98 1:16p $
  10. */
  11. #include <windows.h>
  12. #include <tdll\stdtyp.h>
  13. #include <tdll\mc.h>
  14. #if !defined(BYTE)
  15. #define BYTE unsigned char
  16. #endif
  17. #include "cmprs.h"
  18. #include "cmprs.hh"
  19. // debug_init(__FILE__)
  20. /* Routines to handle overall compression enable and disable. */
  21. void *compress_tblspace;
  22. /* These variables are shared by the compression and decompression routines */
  23. unsigned long ulHoldReg;
  24. int sBitsLeft;
  25. int sCodeBits;
  26. unsigned int usMaxCode;
  27. unsigned int usFreeCode;
  28. unsigned int usxCmprsStatus = COMPRESS_IDLE;
  29. int fxLastBuildGood = FALSE;
  30. int fFlushable = FALSE; // True if compression stream can
  31. // flushed and resumed
  32. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  33. * compress_enable
  34. *
  35. * DESCRIPTION:
  36. * Called to determine whether compression is feasible, and if it is to
  37. * allocate the necessary memory to do so.
  38. *
  39. * ARGUMENTS:
  40. * none
  41. *
  42. * RETURNS:
  43. * If compression was already enabled, returns TRUE.
  44. * If compression was not previously enabled, or if it was disabled,
  45. * returns TRUE if memory is available for compression, FALSE otherwise.
  46. */
  47. int compress_enable(void)
  48. {
  49. #if defined(DOS_HOST)
  50. static struct s_cmprs_node tbl[MAXNODES+2];
  51. compress_tblspace = (void *)&tbl;
  52. return TRUE;
  53. #else
  54. if (compress_tblspace != (void *)0)
  55. return(TRUE);
  56. else
  57. {
  58. compress_tblspace = malloc(sizeof(struct s_cmprs_node)*(MAXNODES+2));
  59. return(compress_tblspace != (void *)0);
  60. }
  61. #endif
  62. }
  63. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  64. * compress_disable
  65. *
  66. * DESCRIPTION
  67. * Disables file compression and released memory used for compression tables.
  68. * Has no effect if compression was not enabled.
  69. *
  70. * ARGUMENTS:
  71. * none
  72. *
  73. * RETURNS:
  74. * nothing
  75. */
  76. void compress_disable(void)
  77. {
  78. #if !defined(DOS_HOST)
  79. if (compress_tblspace != (void *)0)
  80. free(compress_tblspace);
  81. compress_tblspace = (void *)0;
  82. #endif
  83. usxCmprsStatus = COMPRESS_IDLE;
  84. }
  85. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  86. * compress_status
  87. *
  88. * DESCRIPTION:
  89. * Returns current status of compression -- whether idle, active, or shutdown.
  90. * Applies to both compression and decompression.
  91. *
  92. * ARGUMENTS:
  93. * none
  94. *
  95. * RETURNS:
  96. * COMPRESS_IDLE if compression has not been activated or has been stopped
  97. * normally
  98. * COMPRESS_ACTIVE if compression is currently active.
  99. * COMPRESS_SHUTDOWN if compression has been activated but shut itself down
  100. * upon determining that the compression is not effective
  101. * on the current file.
  102. */
  103. unsigned int compress_status(void)
  104. {
  105. return usxCmprsStatus;
  106. }
  107. /* end of cmprs0.c */