#include "config.h" /* Copyright (C) 2002 Brad Jorsch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include "wmweather+.h" #include "forecast.h" #include "getLine.h" #include "convert.h" #include "download.h" #include "diff.h" #include "die.h" #include "sunzenith.h" #include "moon.h" #include "subst.h" /* Important variables */ #define ETA_MAX 21 static time_t eta_time=0; static char *eta_file=NULL; static char *eta_newfile=NULL; static char *eta_req[2]={ NULL, NULL }; static struct forecast forecasts[ETA_MAX]; /********* init functions ************/ static int parse_eta(char *file); static void reset_eta(void){ int i; for(i=0; i=0){ if(S_ISREG(statbuf.st_mode) && statbuf.st_size!=0 && diff(eta_newfile, eta_file) && parse_eta(eta_newfile)){ eta_time=find_next_time(eta_newfile, "MOS GUIDANCE", 720); rename(eta_newfile, eta_file); } else { unlink(eta_newfile); if(!parse_eta(eta_file)) reset_eta(); } } } void eta_cleanup(void){ if(eta_file==NULL) return; unlink(eta_newfile); unlink(eta_file); } void update_eta(int force){ time_t t; if(eta_file==NULL) return; t=time(NULL)/60; if(!force && eta_time>t) return; eta_time=find_next_time(eta_file, "MOS GUIDANCE", 15); download_file(eta_newfile, eta_req[0], eta_req[1], force?DOWNLOAD_KILL_OTHER_REQUESTS:0, eta_callback, NULL); } /********* parse functions ************/ #define NEXT(s) free(s); \ len=getLine(&s, fp); \ if(strstr(s, "")!=NULL) len=0; #define DIE() return (free(s), fclose(fp), 0) #define SPLIT(s) { \ ID[0]=s[0]; \ ID[1]=s[1]; \ ID[2]=s[2]; \ ID[3]='\0'; \ memset(split,'\0',sizeof(split)); \ for(n=0, c=s+4; c12){ c=strchr(c+1, '/'); if(c==NULL) DIE(); for(mon=1; mon<=12; mon++){ if(!strncmp(c+1, monthnames[mon], 3) && isspace(*(c+4))) break; if(!strncmp(c+1, monthnames2[mon], 4) && isspace(*(c+5))){ i=5; break; } } } day=atoi(c+i); if(day<1) DIE(); if(c>s+4) day--; if(mon90) forecasts[n].moon=calc_moon(m, j, z, h*100); } while(1){ NEXT(s); if(len<=10) break; SPLIT(s); if(!strcmp(ID, "X/N")) j=1; else if(!strcmp(ID, "N/X")) j=2; else j=0; if(j!=0){ for(n=0; n>1); for(m=0; m=19) || (forecasts[m].day==k && forecasts[m].hour<19))) forecasts[m].high=i; if((j&1)==0 && ((forecasts[m].day==k-1 && forecasts[m].hour>=8) || (forecasts[m].day==k && forecasts[m].hour<8))) forecasts[m].low=i; } j++; } continue; } if(!strcmp(ID, "TMP")){ ASSIGN(temp); continue; } if(!strcmp(ID, "DPT")){ ASSIGN(dewpt); continue; } if(!strcmp(ID, "WDR")){ for(n=0; n0 && m0 && m