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.

365 lines
7.9 KiB

  1. //
  2. // Copyright (c) 1997-1999 Microsoft Corporation.
  3. //
  4. #include "stdafx.h"
  5. #define LISTDATAMAX 4
  6. #define NIL (void *)0
  7. struct vecdata {
  8. short x, y, atr;
  9. };
  10. struct VDATA {
  11. struct VDATA *next, *prev;
  12. struct vecdata vd;
  13. };
  14. struct VHEAD {
  15. struct VHEAD *next, *prev;
  16. struct VDATA *headp;
  17. int nPoints;
  18. };
  19. struct VCNTL {
  20. struct VHEAD *rootHead;
  21. struct VHEAD *currentHead;
  22. int nCont;
  23. struct VDATA *cvp;
  24. int mendp;
  25. void *memroot;
  26. void *cmem;
  27. };
  28. int VDInit(void);
  29. void VDTerm(void);
  30. void VDNew(int lsthdl);
  31. int VDClose(int lsthdl);
  32. int VDSetData(int lsthdl,struct vecdata *pnt);
  33. int VDGetData(int lsthdl,int contN,int pn,struct vecdata *pnt);
  34. int VDGetHead(int lsthdl,struct VHEAD * *vhd);
  35. static void *getmem(int lsthdl,int siz);
  36. int VDGetNCont(int lstHdl);
  37. int VDReverseList(int lstHdl);
  38. int VDCopy(int srcH,int dstH);
  39. struct VCNTL VCntlTbl[LISTDATAMAX];
  40. #define ALLOCMEMUNIT 2048
  41. static int init=0;
  42. /***********************************************************************
  43. * initialize data
  44. */
  45. /* */ int
  46. /* */ VDInit()
  47. /*
  48. * returns : 0, -1( out of memory)
  49. ***********************************************************************/
  50. {
  51. int lsthdl;
  52. void *mem;
  53. if ( init)
  54. return( 0);
  55. for( lsthdl = 0; lsthdl < LISTDATAMAX; lsthdl++) {
  56. /* Allocate First memory */
  57. mem = (void *)malloc( ALLOCMEMUNIT);
  58. if ( mem==NIL)
  59. return( -1);
  60. *((void **)mem) = NIL;
  61. VCntlTbl[lsthdl].memroot = mem;
  62. VDNew(lsthdl);
  63. }
  64. init = 1;
  65. return( 0);
  66. }
  67. /***********************************************************************
  68. * Terminate
  69. */
  70. /* */ void
  71. /* */ VDTerm()
  72. /*
  73. * returns : none
  74. ***********************************************************************/
  75. {
  76. void *mem, *nextmem;
  77. int lsthdl;
  78. if ( init) {
  79. for( lsthdl = 0; lsthdl < LISTDATAMAX; lsthdl++) {
  80. mem = VCntlTbl[lsthdl].memroot;
  81. do {
  82. nextmem = *((void * *)mem);
  83. free( mem);
  84. mem = nextmem;
  85. } while ( mem!=NIL);
  86. }
  87. init = 0;
  88. }
  89. return;
  90. }
  91. /***********************************************************************
  92. * New Data
  93. */
  94. /* */ void
  95. /* */ VDNew(int lsthdl)
  96. /*
  97. * returns : none
  98. ***********************************************************************/
  99. {
  100. struct VCNTL *vc;
  101. vc = VCntlTbl+lsthdl;
  102. vc->cmem = vc->memroot;
  103. vc->mendp = sizeof( void *);
  104. vc->currentHead = vc->rootHead = (struct VHEAD *)((char *)(vc->cmem)+vc->mendp);
  105. vc->mendp += sizeof( struct VHEAD);
  106. vc->currentHead->prev = (struct VHEAD *)NIL;
  107. vc->currentHead->next = (struct VHEAD *)NIL;
  108. vc->currentHead->headp = (struct VDATA *)NIL;
  109. vc->currentHead->nPoints = 0;
  110. vc->cvp = (struct VDATA *)NIL;
  111. vc->nCont = 0;
  112. }
  113. /***********************************************************************
  114. * Close Contour
  115. */
  116. /* */ int
  117. /* */ VDClose(int lsthdl)
  118. /*
  119. * returns : none
  120. ***********************************************************************/
  121. {
  122. struct VHEAD *vh;
  123. struct VCNTL *vc;
  124. vc = VCntlTbl+lsthdl;
  125. vc->cvp->next = vc->currentHead->headp;
  126. vc->currentHead->headp->prev = vc->cvp;
  127. vh = (struct VHEAD *)getmem( lsthdl, sizeof(struct VHEAD));
  128. if ( vh == NIL) return( -1);
  129. vc->currentHead->next = vh;
  130. vh->prev = vc->currentHead;
  131. vh->next = (struct VHEAD *)NIL;
  132. vh->headp = (struct VDATA *)NIL;
  133. vh->nPoints = 0;
  134. vc->currentHead = vh;
  135. vc->cvp = (struct VDATA *)NIL;
  136. vc->nCont++;
  137. return (0);
  138. }
  139. /***********************************************************************
  140. * Set Data
  141. */
  142. /* */ int
  143. /* */ VDSetData (
  144. /* */ int lsthdl,
  145. /* */ struct vecdata *pnt)
  146. /*
  147. * return : 0, -1 ( no memory)
  148. ***********************************************************************/
  149. {
  150. void *mem;
  151. struct VCNTL *vc;
  152. if (!pnt)
  153. {
  154. return -1;
  155. }
  156. vc = VCntlTbl+lsthdl;
  157. mem = getmem( lsthdl,sizeof( struct VDATA));
  158. if ( mem == NIL) {
  159. return -1;
  160. }
  161. if ( vc->cvp== NIL) { /* Contour First Point*/
  162. vc->cvp = vc->currentHead->headp = (struct VDATA *)mem;
  163. vc->cvp->vd = *pnt;
  164. vc->cvp->next = vc->cvp->prev= (struct VDATA *)NIL;
  165. }
  166. else {
  167. vc->cvp->next = (struct VDATA *)mem;
  168. vc->cvp->next->prev = vc->cvp;
  169. vc->cvp = vc->cvp->next;
  170. vc->cvp->vd = *pnt;
  171. vc->cvp->next =(struct VDATA *) NIL;
  172. }
  173. vc->currentHead->nPoints++;
  174. return 0;
  175. }
  176. /***********************************************************************
  177. * Get Data
  178. */
  179. /* */ int
  180. /* */ VDGetData(
  181. /* */ int lsthdl,
  182. /* */ int contN,
  183. /* */ int pn,
  184. /* */ struct vecdata *pnt)
  185. /*
  186. * returns : 0, -1 ( Illeagal Coontour Number)
  187. ***********************************************************************/
  188. {
  189. struct VHEAD *vhd;
  190. struct VDATA *cvd;
  191. if (!pnt)
  192. {
  193. return -1;
  194. }
  195. if ( lsthdl <0 ||lsthdl >= LISTDATAMAX)
  196. return -1;
  197. if ((vhd = VCntlTbl[lsthdl].rootHead)==NIL)
  198. return -1;
  199. while ( contN-->0)
  200. vhd = vhd->next;
  201. cvd = vhd->headp;
  202. while ( pn-->0)
  203. cvd = cvd->next;
  204. *pnt = cvd->vd;
  205. return 0;
  206. }
  207. /***********************************************************************
  208. * Get Data Head
  209. */
  210. /* */ int
  211. /* */ VDGetHead(
  212. /* */ int lsthdl,
  213. /* */ struct VHEAD **vhd)
  214. /*
  215. * returns : 0, -1
  216. ***********************************************************************/
  217. {
  218. if (!vhd)
  219. {
  220. return -1;
  221. }
  222. if ( lsthdl >= 0 && lsthdl < LISTDATAMAX) {
  223. *vhd = VCntlTbl[lsthdl].rootHead;
  224. return( 0);
  225. }
  226. else
  227. return( -1);
  228. }
  229. /***********************************************************************
  230. * Get Memory
  231. */
  232. /* */ static void *
  233. /* */ getmem( int lsthdl, int siz)
  234. /*
  235. * returns : 0, -1
  236. ***********************************************************************/
  237. {
  238. void *mem;
  239. struct VCNTL *vc;
  240. vc = VCntlTbl+lsthdl;
  241. if ( vc->mendp + siz >= ALLOCMEMUNIT) {
  242. mem = *((void **)vc->cmem);
  243. if ( mem == NIL ) {
  244. mem = (void *)malloc(ALLOCMEMUNIT);
  245. if ( mem == NIL)
  246. return( NIL);
  247. *((void * *)mem) = NIL;
  248. *((void * *)vc->cmem) = mem; /* */
  249. vc->cmem = mem;
  250. }
  251. else
  252. vc->cmem = mem;
  253. vc->mendp = sizeof(void *);
  254. }
  255. mem = (void *)((char *)(vc->cmem) + vc->mendp);
  256. vc->mendp += siz;
  257. return(mem );
  258. }
  259. /***********************************************************************
  260. * Get Number of COntours
  261. */
  262. /* */ int
  263. /* */ VDGetNCont( int lstHdl)
  264. /*
  265. * returns : Number of Contour
  266. ***********************************************************************/
  267. {
  268. if ( lstHdl >= 0 && lstHdl < LISTDATAMAX)
  269. return VCntlTbl[lstHdl].nCont;
  270. else
  271. return( -1);
  272. }
  273. /***********************************************************************
  274. * Reverse List
  275. */
  276. /* */ int
  277. /* */ VDReverseList( int lstHdl)
  278. /*
  279. * returns : 0, -1 ( handle No )
  280. ***********************************************************************/
  281. {
  282. int cont;
  283. int np;
  284. struct VHEAD *vh;
  285. struct VDATA *vp, *nvp;
  286. if ( lstHdl < 0 || lstHdl >= LISTDATAMAX)
  287. return -1;
  288. vh = VCntlTbl[lstHdl].rootHead;
  289. for ( cont = 0; cont < VCntlTbl[lstHdl].nCont; cont++ ) {
  290. vp = vh ->headp;
  291. np = vh->nPoints;
  292. while ( np-->0) {
  293. nvp = vp->next;
  294. vp->next = vp->prev;
  295. vp->prev = nvp;
  296. vp = nvp;
  297. }
  298. vh = vh->next;
  299. }
  300. return 0;
  301. }
  302. /***********************************************************************
  303. * Copy Data
  304. */
  305. /* */ int
  306. /* */ VDCopy( int srcH, int dstH)
  307. /*
  308. * returns : 0, -1(Invalid Handle)
  309. ***********************************************************************/
  310. {
  311. int cont;
  312. int np;
  313. struct VHEAD *vh;
  314. struct VDATA *vp;
  315. if ( srcH < 0 || srcH >= LISTDATAMAX
  316. || dstH < 0 || dstH >= LISTDATAMAX)
  317. return -1;
  318. VDNew( dstH);
  319. vh = VCntlTbl[srcH].rootHead;
  320. for ( cont = 0; cont < VCntlTbl[srcH].nCont; cont++ ) {
  321. vp = vh ->headp;
  322. np = vh->nPoints;
  323. while ( np-->0) {
  324. if ( VDSetData( dstH, &vp->vd))
  325. return -1;
  326. vp = vp->next;
  327. }
  328. vh = vh->next;
  329. VDClose( dstH);
  330. }
  331. return 0;
  332. }
  333. /* EOF */