home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / fonts / server / MacFS / MacFontUIError.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-29  |  5.0 KB  |  221 lines

  1. /* $XConsortium$ */
  2. /***********************************************************************
  3. Copyright 1991 by Apple Computer, Inc, Cupertino, California
  4.             All Rights Reserved
  5.  
  6. Permission to use, copy, modify, and distribute this software
  7. for any purpose and without fee is hereby granted, provided
  8. that the above copyright notice appear in all copies.
  9.  
  10. APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS,
  11. OR IMPLIED, WITH RESPECT TO THIS SOFTWARE, ITS QUALITY,
  12. PERFORMANCE, MERCHANABILITY, OR FITNESS FOR A PARTICULAR
  13. PURPOSE. AS A RESULT, THIS SOFTWARE IS PROVIDED "AS IS,"
  14. AND YOU THE USER ARE ASSUMING THE ENTIRE RISK AS TO ITS
  15. QUALITY AND PERFORMANCE. IN NO EVENT WILL APPLE BE LIABLE 
  16. FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  17. DAMAGES RESULTING FROM ANY DEFECT IN THE SOFTWARE.
  18.  
  19. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE
  20. AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR
  21. IMPLIED.
  22.  
  23. ***********************************************************************/
  24. /*
  25.  * error message handling
  26.  */
  27. /*
  28.  * Copyright 1991 Network Computing Devices;
  29.  * Portions Copyright 1987 by Digital Equipment Corporation and the
  30.  * Massachusetts Institute of Technology
  31.  *
  32.  * Permission to use, copy, modify, and distribute this protoype software
  33.  * and its documentation to Members and Affiliates of the MIT X Consortium
  34.  * any purpose and without fee is hereby granted, provided
  35.  * that the above copyright notice appear in all copies and that both that
  36.  * copyright notice and this permission notice appear in supporting
  37.  * documentation, and that the names of Network Computing Devices, Digital or
  38.  * MIT not be used in advertising or publicity pertaining to distribution of
  39.  * the software without specific, written prior permission.
  40.  *
  41.  * NETWORK COMPUTING DEVICES, DIGITAL AND MIT DISCLAIM ALL WARRANTIES WITH
  42.  * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  43.  * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, DIGITAL OR MIT BE
  44.  * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  45.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  46.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  47.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  48.  *
  49.  * $NCDId: @(#)error.c,v 4.1 1991/07/08 18:22:51 lemke Exp $
  50.  *
  51.  */
  52.  
  53. #include    <stdio.h>
  54. #include    <X11/Xos.h>
  55. #include    <sys/param.h>
  56.  
  57. #ifdef USE_SYSLOG
  58. #include    <syslog.h>
  59. #endif
  60.  
  61. #include    "misc.h"
  62.  
  63. #include "MacFontUI.h"
  64. extern int initDone;
  65.  
  66. Bool        UseSyslog;
  67. char        ErrorFile[MAXPATHLEN];
  68.  
  69. static Bool log_open;
  70.  
  71. static void
  72. abort_server()
  73. {
  74.     if (initDone)
  75.         EventLoop();
  76.     else {
  77.         fflush(stderr);
  78.         abort();
  79.     }
  80. }
  81.  
  82. void
  83. InitErrors()
  84. {
  85.     int         i;
  86.  
  87. #ifdef USE_SYSLOG
  88.     if (UseSyslog && !log_open) {
  89.     openlog("Font Server", LOG_PID, LOG_LOCAL0);
  90.     log_open = TRUE;
  91.     return;
  92.     }
  93. #endif
  94.  
  95.     if (ErrorFile[0]) {
  96.     i = creat(ErrorFile, 0666);
  97.     if (i != -1) {
  98.         dup2(i, 2);
  99.         close(i);
  100.     } else {
  101.         ErrorF("Can't open error file \"%s\"\n", ErrorFile);
  102.     }
  103.     }
  104. }
  105.  
  106. void
  107. CloseErrors()
  108. {
  109.  
  110. #ifdef USE_SYSLOG
  111.     if (UseSyslog) {
  112.     closelog();
  113.     log_open = FALSE;
  114.     return;
  115.     }
  116. #endif
  117.  
  118.     fflush(stderr);
  119.     fclose(stderr);
  120. }
  121.  
  122. void
  123. Error(str)
  124.     char       *str;
  125. {
  126.     MacFontPerror(str);
  127. }
  128.  
  129. /*
  130.  * used for informational messages
  131.  */
  132. /* VARARGS1 */
  133. void
  134. NoticeF(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9)    /* limit of 10 args */
  135.     char       *f;
  136.     char       *s0,
  137.                *s1,
  138.                *s2,
  139.                *s3,
  140.                *s4,
  141.                *s5,
  142.                *s6,
  143.                *s7,
  144.                *s8,
  145.                *s9;
  146. {
  147.  
  148. #ifdef USE_SYSLOG
  149.     if (UseSyslog) {
  150.     syslog(LOG_NOTICE, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  151.     return;
  152.     }
  153. #endif
  154.  
  155.     char buf[256];
  156.  
  157.     sprintf(buf, "Notice: ");
  158.     sprintf(buf + strlen("Notice: "),f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  159.     sprintf(buf + strlen(buf),"\r");
  160.  
  161.     MacFontLogNotice(buf);
  162. }
  163.  
  164. /*
  165.  * used for non-fatal error messages
  166.  */
  167. /* VARARGS1 */
  168. void
  169. ErrorF(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9)    /* limit of 10 args */
  170.     char       *f;
  171.     char       *s0,
  172.                *s1,
  173.                *s2,
  174.                *s3,
  175.                *s4,
  176.                *s5,
  177.                *s6,
  178.                *s7,
  179.                *s8,
  180.                *s9;
  181. {
  182.  
  183. #ifdef USE_SYSLOG
  184.     if (UseSyslog) {
  185.     syslog(LOG_ERR, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  186.     return;
  187.     }
  188. #endif
  189.  
  190.     char buf[256];
  191.  
  192.     sprintf(buf, "Error: ");
  193.     sprintf(buf + strlen("Error: "), f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  194.     sprintf(buf + strlen(buf),"\r");
  195.  
  196.     MacFontLogError(buf);
  197. }
  198.  
  199. /* VARARGS1 */
  200. void
  201. FatalError(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9)    /* limit of 10 args */
  202.     char       *f;
  203.     char       *s0,
  204.                *s1,
  205.                *s2,
  206.                *s3,
  207.                *s4,
  208.                *s5,
  209.                *s6,
  210.                *s7,
  211.                *s8,
  212.                *s9;
  213. {
  214.     ErrorF("Fatal server error!\n");
  215.     ErrorF(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  216.     ErrorF("\n");
  217.     AlertUser(eFatalError);
  218.     abort_server();
  219.     /* NOTREACHED */
  220. }
  221.