/* * Skip white space in buf and * initialize a clone xbuf that starts at buf's * current position and ends just before the next '=' or EOB * Used to extract individual obs from reports which contain multiple obs. */ int get_weqxbuf( xbuf *buf, xbuf *clone) { int ch = 0; /* assert(buf != NULL && clone != NULL ); */ if(buf->cnt == 0 ) return EOB; do{ ch = nextc(buf); }while(Wisspace(ch)); unnextc(buf,ch); if(buf->cnt < 5 ) return EOB; clone->base = buf->get; do { ch = nextc(buf); } while(ch != EQ && ch != RECORD_SEP && ch != EOB); clone->bufsiz = buf->get - clone->base; if(clone->bufsiz < 5) return EOB; /* don't bother */ clone->cnt = (ptrdiff_t) clone->bufsiz; clone->get = clone->base; clone->put = clone->base + clone->bufsiz - 1; /* trim whitespace from end */ while((clone->put >= clone->base) && (Wisspace(*clone->put) || *clone->put == EQ)) { clone->put--; clone->bufsiz--; clone->cnt--; } return(ch > 0 ? ch : ETX); }
int whasSTR( xbuf *buf, char *str) { int ch; do{ ch = nextc(buf); }while(Wisspace(ch)); unnextc(buf,ch); return( hasSTR(buf,str) ); }
/* * skip leading white space, get the next numeric token, handle solidus */ int dget_wnum( xbuf *buf, int *num, int maxlen) { int ch; do{ ch = nextc(buf); }while(Wisspace(ch)); unnextc(buf,ch); return( dget_num(buf, num, maxlen) ); }
static const char * faa604_err_ident(xbuf *buf) { static char identbuf[128]; char *cp = identbuf; xbuf clone[1]; int conv; int len; int ch; (void) memset(identbuf, 0, sizeof(identbuf)); clone_xbuf(buf, clone, 0); conv = sprintf(cp, "%8u", (unsigned) clone->cnt); cp += conv; /* seqno */ do { ch = nextc(clone); } while(Wisspace(ch)); if(ch == EOB) goto done; conv = sprintf(cp, " "); cp += conv; if(!isgraph(ch)) *cp++ = ' '; else *cp++ = ch; for(len = 0; len < 2 ; len++ ) { ch = nextc(clone); if(ch == EOB) goto done; if(!isgraph(ch)) *cp++ = ' '; else *cp++ = ch; } conv = sprintf(cp, " "); cp += conv; /* identifier */ for(len = 0; len < 5 ; len++ ) { ch = nextc(clone); if(ch == EOB) goto done; if(!isgraph(ch)) *cp++ = ' '; else *cp++ = ch; } ch = nextc(clone); /* STX */ if(ch == EOB) goto done; do { ch = nextc(clone); } while(Wisspace(ch)); if(ch == EOB) goto done; *cp++ = ' '; if(!isgraph(ch)) *cp++ = ' '; else *cp++ = ch; for(len = 0; len < 5 ; len++ ) { ch = nextc(clone); if(ch == EOB) goto done; if(!isgraph(ch)) *cp++ = ' '; else *cp++ = ch; } done: *cp = 0; return identbuf; }
static int get_faa604_message(xbuf *buf, faa604_message *mess) { xbuf clone[1]; int ch; char *cp; int len; clone_xbuf(buf, clone, 0); init_faa604_message(clone, mess); /* DEBUG */ if(mess->msg == NULL || mess->msg[0] != SOH) { log_debug("new_faa604_message: Missing SOH"); } else if(mess->len < MIN_FAA604_MSG_LEN) { log_debug("new_faa604_message: length %d too short", mess->len); } else if(mess->msg[mess->len-1] != ETX ) { log_debug("new_faa604_message: Missing ETX"); } if( get_wnum(clone, &mess->seqno, 3) == EOB || mess->seqno < 1) { not_faa604++; log_error("Invalid sequence number - %s", faa604_err_ident(buf)); return -1; } /* construct the identifier */ for(len = 0, cp = mess->ident; len < 5 ; len++ ) { ch = nextc(clone); if(!(isascii(ch) && isdigit(ch))) { not_faa604++; log_error("Invalid catalogue number - %s", faa604_err_ident(buf)); return -1; } *cp++ = ch; } ch = nextc(clone); if(ch != STX) { not_faa604++; log_error("Missing header STX - %s", faa604_err_ident(buf)); return -1; } do { ch = nextc(clone); } while(Wisspace(ch)); if(!(isascii(ch) && isdigit(ch))) { not_faa604++; log_error("Invalid date - %s", faa604_err_ident(buf)); return -1; } *cp++ = ' '; *cp++ = ch; for(len = 0; len < 5 ; len++ ) { ch = nextc(clone); if(!(isascii(ch) && isdigit(ch))) { not_faa604++; log_error("Invalid date/time - %s", faa604_err_ident(buf)); return -1; } *cp++ = ch; } *cp = 0; { /* optional */ wmo_header_t wmo_hdr; dtime time; wmo_hdr.time = &time; if(get_wmo_header(clone, &wmo_hdr) != NULL && wmo_hdr.ii != 0 && isupper(wmo_hdr.TT[0]) && isupper(wmo_hdr.TT[1]) && isupper(wmo_hdr.AA[0]) && isupper(wmo_hdr.AA[1]) /* number okay? */ && isupper(wmo_hdr.CCCC[0]) ) { sprintf(cp, " (%s)", s_wmo_header(&wmo_hdr)); } } return 0; }