home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / preproc / perr.c < prev    next >
C/C++ Source or Header  |  2000-07-29  |  3KB  |  158 lines

  1. /*
  2.  * The functions in this file print error messages.
  3.  */
  4. #include "../preproc/preproc.h"
  5. #include "../preproc/pproto.h"
  6. extern char *progname;
  7.  
  8. /*
  9.  * Prototypes for static functions.
  10.  */
  11. static void rm_files (void);
  12.  
  13.  
  14. /*
  15.  * File list.
  16.  */
  17. struct finfo_lst {
  18.    char *name;                  /* file name */
  19.    FILE *file;                  /* file */
  20.    struct finfo_lst *next;      /* next entry in list */
  21.    };
  22.  
  23. static struct finfo_lst *file_lst = NULL;
  24.  
  25. /*
  26.  * errt1 - error message in one string, location indicated by a token.
  27.  */
  28. void errt1(t, s)
  29. struct token *t;
  30. char *s;
  31.    {
  32.    errfl1(t->fname, t->line, s);
  33.    }
  34.  
  35. /*
  36.  * errfl1 - error message in one string, location given by file and line.
  37.  */
  38. void errfl1(f, l, s)
  39. char *f;
  40. int l;
  41. char *s;
  42.    {
  43.    fflush(stdout);
  44.    fprintf(stderr, "%s: File %s; Line %d: %s\n", progname, f, l, s);
  45.    rm_files();
  46.    exit(EXIT_FAILURE);
  47.    }
  48.  
  49. /*
  50.  * err1 - error message in one string, no location given
  51.  */
  52. void err1(s)
  53. char *s;
  54.    {
  55.    fflush(stdout);
  56.    fprintf(stderr, "%s: %s\n", progname, s);
  57.    rm_files();
  58.    exit(EXIT_FAILURE);
  59.    }
  60.  
  61. /*
  62.  * errt2 - error message in two strings, location indicated by a token.
  63.  */
  64. void errt2(t, s1, s2)
  65. struct token *t;
  66. char *s1;
  67. char *s2;
  68.    {
  69.    errfl2(t->fname, t->line, s1, s2);
  70.    }
  71.  
  72. /*
  73.  * errfl2 - error message in two strings, location given by file and line.
  74.  */
  75. void errfl2(f, l, s1, s2)
  76. char *f;
  77. int l;
  78. char *s1;
  79. char *s2;
  80.    {
  81.    fflush(stdout);
  82.    fprintf(stderr, "%s: File %s; Line %d: %s%s\n", progname, f, l, s1, s2);
  83.    rm_files();
  84.    exit(EXIT_FAILURE);
  85.    }
  86.  
  87. /*
  88.  * err2 - error message in two strings, no location given
  89.  */
  90. void err2(s1, s2)
  91. char *s1;
  92. char *s2;
  93.    {
  94.    fflush(stdout);
  95.    fprintf(stderr, "%s: %s%s\n", progname, s1, s2);
  96.    rm_files();
  97.    exit(EXIT_FAILURE);
  98.    }
  99.  
  100. /*
  101.  * errt3 - error message in three strings, location indicated by a token.
  102.  */
  103. void errt3(t, s1, s2, s3)
  104. struct token *t;
  105. char *s1;
  106. char *s2;
  107. char *s3;
  108.    {
  109.    errfl3(t->fname, t->line, s1, s2, s3);
  110.    }
  111.  
  112. /*
  113.  * errfl3 - error message in three strings, location given by file and line.
  114.  */
  115. void errfl3(f, l, s1, s2, s3)
  116. char *f;
  117. int l;
  118. char *s1;
  119. char *s2;
  120. char *s3;
  121.    {
  122.    fflush(stdout);
  123.    fprintf(stderr, "%s: File %s; Line %d: %s%s%s\n", progname, f, l,
  124.        s1, s2, s3);
  125.    rm_files();
  126.    exit(EXIT_FAILURE);
  127.    }
  128.  
  129. /*
  130.  * addrmlst - add a file name to the list of files to be removed if
  131.  *   an error occurs.
  132.  */
  133. void addrmlst(fname, f)
  134. char *fname;
  135. FILE *f;
  136.    {
  137.    struct finfo_lst *id;
  138.  
  139.    id = NewStruct ( finfo_lst );
  140.    id->name = fname;
  141.    id->file = f;
  142.    id->next = file_lst;
  143.    file_lst = id;
  144.    }
  145.  
  146. /*
  147.  * rm_files - remove files that must be cleaned up in the event of an
  148.  *   error.
  149.  */
  150. static void rm_files()
  151.    {
  152.    while (file_lst != NULL) {
  153.       fclose ( file_lst->file );
  154.       remove(file_lst->name);
  155.       file_lst = file_lst->next;
  156.       }
  157.    }
  158.