Back to index

radiance  4R0+20100331
Classes | Defines | Functions | Variables
header.c File Reference
#include "copyright.h"
#include <ctype.h>
#include "rtio.h"
#include "resolu.h"

Go to the source code of this file.

Classes

struct  check

Defines

#define MAXLINE   2048

Functions

void newheader (char *s, FILE *fp)
int headidval (char *r, char *s)
int dateval (time_t *tloc, char *s)
int gmtval (time_t *tloc, char *s)
void fputdate (time_t tv, FILE *fp)
void fputnow (FILE *fp)
void printargs (int ac, char **av, FILE *fp)
int formatval (char *r, char *s)
void fputformat (char *s, FILE *fp)
int getheader (FILE *fp, gethfunc *f, void *p)
static int mycheck (char *s, void *cp)
int globmatch (char *p, char *s)
int checkheader (FILE *fin, char *fmt, FILE *fout)

Variables

static const char RCSid [] = "$Id: header.c,v 2.25 2009/05/21 18:08:43 greg Exp $"
const char HDRSTR [] = "#?"
const char FMTSTR [] = "FORMAT="
const char TMSTR [] = "CAPDATE="
const char GMTSTR [] = "GMT="
static gethfunc mycheck

Class Documentation

struct check

Definition at line 230 of file header.c.

Class Members
FILE * fp
char fs

Define Documentation

#define MAXLINE   2048

Definition at line 32 of file header.c.


Function Documentation

int checkheader ( FILE *  fin,
char *  fmt,
FILE *  fout 
)

Definition at line 319 of file header.c.

{
       struct check  cdat;
       char   *cp;

       cdat.fp = fout;
       cdat.fs[0] = '\0';
       if (getheader(fin, mycheck, &cdat) < 0)
              return(-1);
       if (!cdat.fs[0])
              return(0);
       for (cp = fmt; *cp; cp++)          /* check for globbing */
              if ((*cp == '?') | (*cp == '*')) {
                     if (globmatch(fmt, cdat.fs)) {
                            strcpy(fmt, cdat.fs);
                            return(1);
                     } else
                            return(-1);
              }
       return(strcmp(fmt, cdat.fs) ? -1 : 1);    /* literal match */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dateval ( time_t *  tloc,
char *  s 
)

Definition at line 73 of file header.c.

{
       struct tm     tms;
       const char    *cp = TMSTR;

       while (*cp) if (*cp++ != *s++) return(0);
       while (isspace(*s)) s++;
       if (!*s) return(0);
       if (sscanf(s, "%d:%d:%d %d:%d:%d",
                     &tms.tm_year, &tms.tm_mon, &tms.tm_mday,
                     &tms.tm_hour, &tms.tm_min, &tms.tm_sec) != 6)
              return(0);
       if (tloc == NULL)
              return(1);
       tms.tm_mon--;
       tms.tm_year -= 1900;
       tms.tm_isdst = -1;   /* ask mktime() to figure out DST */
       *tloc = mktime(&tms);
       return(1);
}
int formatval ( char *  r,
char *  s 
)

Definition at line 170 of file header.c.

{
       const char  *cp = FMTSTR;

       while (*cp) if (*cp++ != *s++) return(0);
       while (isspace(*s)) s++;
       if (!*s) return(0);
       if (r == NULL) return(1);
       do
              *r++ = *s++;
       while(*s && !isspace(*s));
       *r = '\0';
       return(1);
}

Here is the caller graph for this function:

void fputdate ( time_t  tv,
FILE *  fp 
)

Definition at line 124 of file header.c.

{
       struct tm     *tms;

       tms = localtime(&tv);
       if (tms != NULL)
              fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", TMSTR,
                            tms->tm_year+1900, tms->tm_mon+1, tms->tm_mday,
                            tms->tm_hour, tms->tm_min, tms->tm_sec);
       tms = gmtime(&tv);
       if (tms != NULL)
              fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", GMTSTR,
                            tms->tm_year+1900, tms->tm_mon+1, tms->tm_mday,
                            tms->tm_hour, tms->tm_min, tms->tm_sec);
}

Here is the caller graph for this function:

void fputformat ( char *  s,
FILE *  fp 
)

Definition at line 190 of file header.c.

{
       fputs(FMTSTR, fp);
       fputs(s, fp);
       putc('\n', fp);
}

Here is the caller graph for this function:

void fputnow ( FILE *  fp)

Definition at line 145 of file header.c.

{
       time_t tv;
       time(&tv);
       fputdate(tv, fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int getheader ( FILE *  fp,
gethfunc f,
void *  p 
)

Definition at line 202 of file header.c.

{
       char  buf[MAXLINE];

       for ( ; ; ) {
              buf[MAXLINE-2] = '\n';
              if (fgets(buf, MAXLINE, fp) == NULL)
                     return(-1);
              if (buf[0] == '\n')
                     return(0);
#ifdef MSDOS
              if (buf[0] == '\r' && buf[1] == '\n')
                     return(0);
#endif
              if (buf[MAXLINE-2] != '\n') {
                     ungetc(buf[MAXLINE-2], fp); /* prevent false end */
                     buf[MAXLINE-2] = '\0';
              }
              if (f != NULL && (*f)(buf, p) < 0)
                     return(-1);
       }
}

Here is the caller graph for this function:

int globmatch ( char *  p,
char *  s 
)

Definition at line 251 of file header.c.

{
       int    setmatch;

       do {
              switch (*p) {
              case '?':                   /* match any character */
                     if (!*s++)
                            return(0);
                     break;
              case '*':                   /* match any string */
                     while (p[1] == '*') p++;
                     do
                            if ( (p[1]=='?' || p[1]==*s) &&
                                          globmatch(p+1,s) )
                                   return(1);
                     while (*s++);
                     return(0);
              case '[':                   /* character set */
                     setmatch = *s == *++p;
                     if (!*p)
                            return(0);
                     while (*++p != ']') {
                            if (!*p)
                                   return(0);
                            if (*p == '-') {
                                   setmatch += p[-1] <= *s && *s <= p[1];
                                   if (!*++p)
                                          break;
                            } else
                                   setmatch += *p == *s;
                     }
                     if (!setmatch)
                            return(0);
                     s++;
                     break;
              case '\\':                  /* literal next */
                     p++;
              /* fall through */
              default:                    /* normal character */
                     if (*p != *s)
                            return(0);
                     s++;
                     break;
              }
       } while (*p++);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gmtval ( time_t *  tloc,
char *  s 
)

Definition at line 99 of file header.c.

{
       struct tm     tms;
       const char    *cp = GMTSTR;

       while (*cp) if (*cp++ != *s++) return(0);
       while (isspace(*s)) s++;
       if (!*s) return(0);
       if (sscanf(s, "%d:%d:%d %d:%d:%d",
                     &tms.tm_year, &tms.tm_mon, &tms.tm_mday,
                     &tms.tm_hour, &tms.tm_min, &tms.tm_sec) != 6)
              return(0);
       if (tloc == NULL)
              return(1);
       tms.tm_mon--;
       tms.tm_year -= 1900;
       *tloc = timegm(&tms);
       return(1);
}
int headidval ( char *  r,
char *  s 
)

Definition at line 57 of file header.c.

{
       const char  *cp = HDRSTR;

       while (*cp) if (*cp++ != *s++) return(0);
       if (r == NULL) return(1);
       while (*s && !isspace(*s)) *r++ = *s++;
       *r = '\0';
       return(1);
}
static int mycheck ( char *  s,
void *  cp 
) [static]

Definition at line 237 of file header.c.

{
       if (!formatval(((struct check*)cp)->fs, s)
                     && ((struct check*)cp)->fp != NULL) {
              fputs(s, ((struct check*)cp)->fp);
       }
       return(0);
}

Here is the call graph for this function:

void newheader ( char *  s,
FILE *  fp 
)

Definition at line 45 of file header.c.

{
       fputs(HDRSTR, fp);
       fputs(s, fp);
       putc('\n', fp);
}

Here is the caller graph for this function:

void printargs ( int  ac,
char **  av,
FILE *  fp 
)

Definition at line 156 of file header.c.

{
       while (ac-- > 0) {
              fputword(*av++, fp);
              fputc(ac ? ' ' : '\n', fp);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char FMTSTR[] = "FORMAT="

Definition at line 36 of file header.c.

const char GMTSTR[] = "GMT="

Definition at line 39 of file header.c.

const char HDRSTR[] = "#?"

Definition at line 34 of file header.c.

gethfunc mycheck [static]

Definition at line 41 of file header.c.

const char RCSid[] = "$Id: header.c,v 2.25 2009/05/21 18:08:43 greg Exp $" [static]

Definition at line 2 of file header.c.

const char TMSTR[] = "CAPDATE="

Definition at line 38 of file header.c.