pike.git / lib / modules / Calendar.pmod / mkrules.pike

version» Context lines:

pike.git/lib/modules/Calendar.pmod/mkrules.pike:3:   // ftp://elsie.nci.nih.gov/pub/   // (timezone mailing list: tz@elsie.nci.nih.gov)   //   // source datafile are usually found somewhere around zic(8),   // if they exist in the system.   //   // Most systems only have compiled files, just like pike,   // and zic(8) is the usual compiler.      // pike mkrules.pike ../data/{africa,antarctica,asia,australasia,backward,etcetera,europe,northamerica,pacificnew,southamerica,systemv} - // $Id: mkrules.pike,v 1.7 2003/01/20 17:44:00 nilsson Exp $ + // $Id: mkrules.pike,v 1.8 2003/03/12 19:44:37 nilsson Exp $      #pike __REAL_VERSION__      object cal=Calendar.ISO->set_timezone("UTC");   function Year=cal->Year;   object nleapy=Year(1999);      object tzrules; // needed to make timezones, compiled below      mapping rules=([]);
pike.git/lib/modules/Calendar.pmod/mkrules.pike:257:    int d,w;    if (sscanf(r,"FIX_L(%d)",d)) r=sprintf("FIXED(%d)",d+l);    else if (sscanf(r,"LDAYL(%d,%d)",d,w)==2)    r=sprintf("LDAY (%d,%d)",d+l,w);    }    return sprintf("({%-12s,%-10s,%-5d,%-6O}), %s",    r,t,offset,s,comment!=""?"// "+comment:"");    }   }    - class Rule + class MyRule   {    string id;       mapping rules=([]);       int amt=0;       void create(string _id) { id=_id; }       void add(string line)
pike.git/lib/modules/Calendar.pmod/mkrules.pike:484:    else if (sscanf(a[1],"%d:%d:%d",h,m,s)==3) roff=h*3600+m*60+s;    else if (sscanf(a[1],"-%d:%d",h,m)==2) roff=h*3600+m*60;    else if (sscanf(a[1],"%d:%d",h,m)==2) roff=h*3600+m*60;       if (roff==-17) // based on DST rule    return sprintf(    "TZrules.%s(%d,%O)",    FIXID(a[1]),-a[0],a[2]);    else // simple timezone    return sprintf( -  "Ruleset.Timezone(%d,%O)", +  "Rule.Timezone(%d,%O)",    -(roff+a[0]),a[2]);    }       string rule_shift(array a)    {    if (a[3]=="" || a[3][0]=='#') return "forever";       string in=a[3];    sscanf(in,"until %s",in);    sscanf(in,"%s#",in);
pike.git/lib/modules/Calendar.pmod/mkrules.pike:567:    string res="";       if (!sizeof(rules))    {    res+=("// skipped %O due to errors\n",id);    return res;    }       if (sizeof(rules)==1) // simple zone    { -  res+=("Ruleset.Timezone "+cid+"="+ +  res+=("Rule.Timezone "+cid+"="+    rules[0][4]+";\n");    return res;    }       mapping rname=([]);    int n=1;       foreach (rules,array a)    if (rname[a[4]]) a[6]=rname[a[4]];    else a[6]=rname[a[4]]="tz"+n++;       res+=("class "+cid+"\n"    "{\n"    " inherit TZHistory;\n" -  " Ruleset.Timezone "+ +  " Rule.Timezone "+    sort(values(rname))*","+";\n" -  " Ruleset.Timezone whatrule(int ux)\n" +  " Rule.Timezone whatrule(int ux)\n"    " {\n"    );       foreach (rules,array a)    {    if (!a[5]) a[5]=rule_shift(a);       string s="";    sscanf(a[3],"%s#%*[ \t]%s",a[3],s);    a[3]="from "+reverse(array_sscanf(reverse(a[3]),"%*[ \t]%s")[0]);
pike.git/lib/modules/Calendar.pmod/mkrules.pike:637:    int n=0;    werror("reading %O...\n",file);    string s=Stdio.read_bytes(file),t;    if (!s)    {    werror("%s:-: Failed to open file: %s\n",file,strerror(errno()));    return;    }       Zone lastz; -  Rule lastr; +  MyRule lastr;       foreach (s/"\n",string line)    {    n++;    mixed err=catch    {    if (line[..0]!="#")    if (sscanf(line,"Zone%*[ \t]%[^ \t]%*[ \t]%s",s,t)==4)    {    if (zones[s]) lastz=zones[s]->add(t);    else (lastz=zones[s]=Zone(s))->add(t),azones+=({lastz});    }    else if (sscanf(line,"Rule%*[ \t]%[^ \t]%*[ \t]%s",s,t)==4)    {    if (rules[s]) rules[s]->add(t); -  else (lastr=rules[s]=Rule(s))->add(t),arules+=({lastr}); +  else (lastr=rules[s]=MyRule(s))->add(t),arules+=({lastr});    lastz=0;    }    else if (sscanf(line,"Link%*[ \t]%[^ \t]%*[ \t]%[^ \t]",s,t)==4)    {    // link t to s    if (links[s]) links[s]+=({t});    else links[s]=({t});    }    else if (sscanf(line,"%*[ \t]%[-0-9]%s",s,t)==3 && sizeof(s))    {
pike.git/lib/modules/Calendar.pmod/mkrules.pike:695:    {    werror("USAGE: %s datafile [datafile ...]\n",am[0]);    return 1;    }    map(am[1..],collect_rules);       write("thinking...\n");       string t=TZrules_base;    -  foreach (arules,Rule r) +  foreach (arules,MyRule r)    t+=r->dump();       tzrules=compile_string(t)();       mv("TZrules.pmod","TZrules.pmod~");    werror("writing TZrules.pmod (%d bytes)...",sizeof(t));    Stdio.File("TZrules.pmod","wtc")->write(t);    werror("\n");       t="// ----------------------------------------------------------------\n"
pike.git/lib/modules/Calendar.pmod/mkrules.pike:725:    "// Timezones\n"    "// "+"-"*70+"\n\n");       mixed err=catch {    foreach (azones,Zone z)    if (sizeof(z->rules)==1)    {    t+=z->dump();    if (links[z->id])    foreach(links[z->id],string s) -  t+="Ruleset.Timezone "+FIXID(s)+"="+ +  t+="Rule.Timezone "+FIXID(s)+"="+    FIXID(z->id)+";\n";    }    };    if (err) if (stringp(err)) error(err); else throw(err);       t+=("\n"    "// "+"-"*70+"\n"    "// Timezones with an attitude\n"    "// "+"-"*70+"\n"    "\n");