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.

97 lines
1.8 KiB

  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <memory.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <ctype.h>
  7. #include "opprec.h"
  8. void ReadMat(FILE *fh, int *pMat, char **pStr, int cEnt)
  9. {
  10. register int i, j;
  11. int ind = 0;
  12. char str[200];
  13. char *p, *q;
  14. for (i = 0 ; i < cEnt ; ++i) {
  15. if ((pStr[i] = malloc(8)) == NULL) {
  16. printf("insufficient memory\n");
  17. exit(2);
  18. }
  19. if ((p = SkipBlank (fh, str, 200)) == NULL) {
  20. printf ("EOF reached\n");
  21. exit (1);
  22. }
  23. while (isspace (*p))
  24. p++;
  25. if ((q = strpbrk (p, " \t")) == NULL) {
  26. printf ("Bad format (%s)\n", str);
  27. exit (1);
  28. }
  29. *q = 0;
  30. strcpy (pStr[i], p);
  31. p = q + 1;
  32. for (j = 0; j < cEnt; j++, ind++) {
  33. // read group and matrix values
  34. while (isspace (*p))
  35. p++;
  36. if ((*p == 0) || ((*p != '0') && (*p != '1'))) {
  37. printf ("Bad format (%s)\n", str);
  38. exit (1);
  39. }
  40. pMat[ind] = *p++ - '0';
  41. }
  42. }
  43. }
  44. void DumpMat(int *pMat, int cEnt)
  45. {
  46. register int i;
  47. register int j;
  48. for (i=0 ; i<cEnt ; ++i)
  49. {
  50. for (j=0 ; j<cEnt ; ++j)
  51. printf("%d ", pMat[i * cEnt + j]);
  52. printf("\n");
  53. }
  54. }
  55. void AddClosure(int *pMat, int cEnt)
  56. {
  57. int d;
  58. int e, f;
  59. int i;
  60. register int j;
  61. register int k;
  62. int n;
  63. int *pMatTmp;
  64. pMatTmp = malloc(cEnt * cEnt * sizeof(int));
  65. if (!pMatTmp) {
  66. return;
  67. }
  68. for (n = 0; n < cEnt; ++n) {
  69. for (i = 0; i < cEnt; ++i) {
  70. for (j = 0; j < cEnt; ++j) {
  71. d = pMat[i * cEnt + j];
  72. for (k = 0; k < cEnt; ++k) {
  73. e = pMat[i * cEnt + k];
  74. f = pMat[k * cEnt + j];
  75. if ((e != 0) && (f != 0))
  76. if (e + f > d)
  77. d = e + f;
  78. }
  79. pMatTmp[i * cEnt + j] = d;
  80. }
  81. }
  82. memcpy (pMat, pMatTmp, cEnt * cEnt * sizeof (int));
  83. }
  84. }