utils.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*\
  2. *
  3. * COPYRIGHT 1990
  4. * DIGITAL EQUIPMENT CORPORATION
  5. * MAYNARD, MASSACHUSETTS
  6. * ALL RIGHTS RESERVED.
  7. *
  8. * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
  9. * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
  10. * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE
  11. * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED
  12. * WARRANTY.
  13. *
  14. * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
  15. * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
  16. * ADDITION TO THAT SET FORTH ABOVE.
  17. *
  18. * Permission to use, copy, modify, and distribute this software and its
  19. * documentation for any purpose and without fee is hereby granted, provided
  20. * that the above copyright notice appear in all copies and that both that
  21. * copyright notice and this permission notice appear in supporting
  22. * documentation, and that the name of Digital Equipment Corporation not be
  23. * used in advertising or publicity pertaining to distribution of the
  24. * software without specific, written prior permission.
  25. \*/
  26. #include "utils.h"
  27. #include <ctype.h>
  28. #include <stdlib.h>
  29. /***====================================================================***/
  30. static FILE *errorFile = NULL;
  31. Boolean
  32. uSetErrorFile(const char *name)
  33. {
  34. if ((errorFile != NULL) && (errorFile != stderr)) {
  35. fprintf(errorFile, "switching to %s\n", name ? name : "stderr");
  36. fclose(errorFile);
  37. }
  38. if (name != NullString)
  39. errorFile = fopen(name, "w");
  40. else
  41. errorFile = stderr;
  42. if (errorFile == NULL) {
  43. errorFile = stderr;
  44. return (False);
  45. }
  46. return (True);
  47. }
  48. void
  49. uInformation(const char *s, ...)
  50. {
  51. va_list ap;
  52. va_start(ap, s);
  53. vfprintf(errorFile, s, ap);
  54. fflush(errorFile);
  55. va_end(ap);
  56. return;
  57. }
  58. /***====================================================================***/
  59. void
  60. uAction(const char *s, ...)
  61. {
  62. va_list ap;
  63. va_start(ap, s);
  64. fprintf(errorFile, " ");
  65. vfprintf(errorFile, s, ap);
  66. fflush(errorFile);
  67. va_end(ap);
  68. return;
  69. }
  70. /***====================================================================***/
  71. void
  72. uWarning(const char *s, ...)
  73. {
  74. va_list ap;
  75. va_start(ap, s);
  76. fprintf(errorFile, "Warning: ");
  77. vfprintf(errorFile, s, ap);
  78. fflush(errorFile);
  79. va_end(ap);
  80. return;
  81. }
  82. /***====================================================================***/
  83. void
  84. uError(const char *s, ...)
  85. {
  86. va_list ap;
  87. va_start(ap, s);
  88. fprintf(errorFile, "Error: ");
  89. vfprintf(errorFile, s, ap);
  90. fflush(errorFile);
  91. va_end(ap);
  92. return;
  93. }
  94. /***====================================================================***/
  95. void
  96. uInternalError(const char *s, ...)
  97. {
  98. va_list ap;
  99. va_start(ap, s);
  100. fprintf(errorFile, "Internal error: ");
  101. vfprintf(errorFile, s, ap);
  102. fflush(errorFile);
  103. va_end(ap);
  104. return;
  105. }
  106. /***====================================================================***/
  107. #ifndef HAVE_STRCASECMP
  108. int
  109. uStrCaseCmp(const char *str1, const char *str2)
  110. {
  111. char buf1[512], buf2[512];
  112. char c, *s;
  113. register int n;
  114. for (n = 0, s = buf1; (c = *str1++); n++) {
  115. if (isupper(c))
  116. c = tolower(c);
  117. if (n > 510)
  118. break;
  119. *s++ = c;
  120. }
  121. *s = '\0';
  122. for (n = 0, s = buf2; (c = *str2++); n++) {
  123. if (isupper(c))
  124. c = tolower(c);
  125. if (n > 510)
  126. break;
  127. *s++ = c;
  128. }
  129. *s = '\0';
  130. return (strcmp(buf1, buf2));
  131. }
  132. #endif