Mapper
error_log.c
Go to the documentation of this file.
1 
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <time.h>
5 #include <string.h>
6 
7 
8 int error_log(char *pname,FILE *fp_log,int pflag,int eflag,
9  char *s1,char *s2,char *s3,char *s4,char *s5)
10 
11 
12 {
13 
14 
15  unsigned char mon_name[12][4] = {
16  {"Jan"}, {"Feb"}, {"Mar"}, {"Apr"}, {"May"}, {"Jun"},
17  {"Jul"}, {"Aug"}, {"Sep"}, {"Oct"}, {"Nov"}, {"Dec"}
18  };
19 
20  char buf[6][80],emsg[80];
21  time_t now;
22  struct tm *tp;
23  signed long offset;
24  int i;
25 
26 
27 /*
28  if ( fp_log == NULL )
29  return(1);
30 */
31  /* Get time of error message */
32 
33  now = time(NULL);
34  tp = gmtime(&now);
35 
36  for ( i=0; i < 6; i++)
37  buf[i][0]=0;
38 
39  if(s1 != NULL)
40  strncpy(buf[0],s1,sizeof(buf[0]));
41 
42 
43  if(s2 != NULL)
44 
45  strncpy(buf[1],s2,sizeof(buf[1]));
46 
47 
48  if(s3 != NULL)
49 
50  strncpy(buf[2],s3,sizeof(buf[2]));
51 
52 
53 
54  if(s4 != NULL)
55 
56  strncpy(buf[3],s4,sizeof(buf[3]));
57 
58 
59  if(s5 != NULL)
60 
61  strncpy(buf[4],s5,sizeof(buf[4]));
62 
63 
64 
65  /* Format error message */
66 
67  sprintf(emsg, "\n\n%3s %2d %2d %2d:%02d program:%-16s",
68  mon_name[tp->tm_mon], tp->tm_mday, tp->tm_year,
69  tp->tm_hour, tp->tm_min, pname);
70 
71 
72  /* write to standard error device if true */
73  if ( pflag == 1 )
74  {
75  fprintf(stdout,"\n%s",emsg);
76 
77  i = 0;
78  while ( buf[i][0] != 0 )
79  {
80  fprintf(stdout,"\n %s",buf[i]);
81  i++;
82  }
83  }
84 
85  /* write to log if you have a file pointer */
86  if ( fp_log != NULL )
87  {
88  fprintf(fp_log,"\n%s",emsg);
89 
90  i = 0;
91  while ( buf[i][0] != 0 )
92  {
93  fprintf(fp_log,"\n %s",buf[i]);
94  i++;
95  }
96 
97  }
98 
99 
100  if ( eflag )
101  {
102  if ( fp_log )
103  fclose(fp_log);
104  exit(1);
105  }
106 
107  return (1);
108 
109 }
static int i
int error_log(char *pname, FILE *fp_log, int pflag, int eflag, char *s1, char *s2, char *s3, char *s4, char *s5)
Definition: error_log.c:8
struct stat buf
Definition: is_file_closed.c:8
fclose(fp)
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
fprintf(fp,"%d %d %d %d 1\n", iminx, iminy, maxi, maxj)
char * pname
Definition: shef_structs.h:264