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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/mkrules.pike:18:   object nleapy=Year(1999);      object tzrules; // needed to make timezones, compiled below      mapping rules=([]);   mapping zones=([]);   mapping links=([]);   array arules=({});   array azones=({});    - mapping(string:mapping(int:array(string))) abbr2zones = ([ -  "DFT":([ 0x7fffffff:({ "Europe/Oslo", "Europe/Paris" }), ]), -  "NFT":([ 0x7fffffff:({ "Europe/Oslo", "Europe/Paris" }), ]), + mapping(string:array(string)) abbr2zones = ([ +  "DFT":({ "Europe/Oslo", "Europe/Paris" }), +  "NFT":({ "Europe/Oslo", "Europe/Paris" }),   ]);      #define FIXED(D) (yjd+((D)-1))   #define FIX_L(D) (yjd+leap+((D)-1))   #define LDAY(D,W) (yjd+((D)-1)-( (yjd+((D)+(8-W)-1)) % 7))   #define LDAYL(D,W) (yjd+((D)-1)+leap-( (yjd+leap+((D)+(8-W)-1)) % 7))      #define FIXID(id) replace(id,"/-+"/1,"__p"/1)    - void add_abbr(string abbr, string zone, int until) + void add_abbr(string abbr, string zone)   { -  mapping(int:array(string)) zones = abbr2zones[abbr]; -  if (!zones) abbr2zones[abbr] = zones = ([]); -  zones[until] += ({ zone }); +  abbr2zones[abbr] += ({ zone });   }      int parse_offset(string t)   {    int h,m,s;    string res;       if (t=="0") return 0;       res="";
pike.git/lib/modules/Calendar.pmod/mkrules.pike:477:       a=({parse_offset(a[0]), // offset    a[1], // rule or added offset    a[2], // string    a[3],    0, 0, "tz", 0}); // until    a[5]=rule_shift(a);    a[4]=clone_rule(a);       if (sizeof(a[2])) { -  int until = (a[5] == "forever")?0x7fffffff:(int)a[5]; +     foreach(a[2]/"/", string fmt) {    MyRule rule = global::rules[a[1]];    if (rule) {    foreach(indices(rule->symbols), string sym) {    if ((sizeof(sym) > 2) && (fmt != "%s")) continue; -  add_abbr(sprintf(fmt, sym), id, until); +  add_abbr(sprintf(fmt, sym), id);    }    } else if (a[1] == "Romania") {    // Kludge for forward reference in tzdata2012c/europe    // for Europe/Chisinau to the Romania rule.    foreach(({ "", "S" }), string sym) { -  add_abbr(sprintf(fmt, sym), id, until); +  add_abbr(sprintf(fmt, sym), id);    }    } else { -  add_abbr(fmt, id, until); +  add_abbr(fmt, id);    }    }    }       rules+=({a});    }       string clone_rule(array a)    {    int h,m,s,roff=-17;
pike.git/lib/modules/Calendar.pmod/mkrules.pike:659:   }      void complain(string fmt,mixed ... args)   {    throw( sprintf(fmt,@args) );   }      void collect_rules(string file)   {    int n=0; -  werror("reading %O...\n",file); +  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())); +  // NB: This file is often used with the system Pike, so +  // it can't use %m yet. +  werror("%s:-: Failed to open file: %s.\n", file, strerror(errno()));    return;    }    -  +  // Current (2017) tzdata files are in UTF-8. +  catch { +  s = utf8_to_string(s); +  }; +     Zone lastz;    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)
pike.git/lib/modules/Calendar.pmod/mkrules.pike:718:    else    throw(err);    }   }      int main(int ac,array(string) am)   {    array(string) files = am[1..];    if (!sizeof(files))    { -  werror("defaulting to reading zonefiles from %s...", -  combine_path(__FILE__, "../tzdata")); -  files = get_dir(combine_path(__FILE__, "../tzdata")); +  werror("Defaulting to reading zonefiles from %s...\n", +  combine_path(__DIR__, "tzdata")); +  files = get_dir(combine_path(__DIR__, "tzdata"));    files = map(sort(files),    lambda(string fname) { -  if ((< "factory", "leapseconds", >)[fname] || +  if ((< ".gitignore", "Makefile", "Theory", "calendars", +  "leapseconds", "version", >)[fname] || +  (upper_case(fname) == fname) ||    has_prefix(fname, "solar") || -  +  has_suffix(fname, ".awk") || +  has_suffix(fname, ".html") || +  has_suffix(fname, ".list") || +  has_suffix(fname, ".pl") ||    has_suffix(fname, ".sh") ||    has_suffix(fname, ".tab")) return 0; -  return combine_path(__FILE__, "../tzdata", fname); +  return combine_path(__DIR__, "tzdata", fname);    }) - ({ 0 });    }    map(files, collect_rules);    -  write("thinking...\n"); +  write("Thinking...\n");    -  string t=TZrules_base; +  string t= "#charset utf-8\n" +  "#pike __REAL_VERSION__\n\n" + TZrules_base;       foreach (arules,MyRule r)    t+=r->dump();       tzrules=compile_string(t)();       mv("TZrules.pmod","TZrules.pmod~"); -  werror("writing TZrules.pmod (%d bytes)...",sizeof(t)); +  t = string_to_utf8(t); +  werror("Writing TZrules.pmod (%d bytes)...",sizeof(t));    Stdio.File("TZrules.pmod","wtc")->write(t);    werror("\n");    -  t="// ----------------------------------------------------------------\n" +  t= "#charset utf-8\n" +  "#pike __REAL_VERSION__\n" +  "// ----------------------------------------------------------------\n"    "// Timezones\n"    "//\n" -  "// NOTE: this file is generated by mkrules.pike;\n" +  "// NOTE: This file is generated by mkrules.pike;\n"    "// please do not edit manually /Mirar\n"    "// ----------------------------------------------------------------\n"    "\n"    "import \".\";\n\n";       t+=("// "+"-"*70+"\n"    "// Timezones\n"    "// "+"-"*70+"\n\n");       mixed err=catch {
pike.git/lib/modules/Calendar.pmod/mkrules.pike:796:    FIXID(z->id)+";\n";    t+="\n";    }    };    if (err) if (stringp(err)) error(err); else throw(err);       t+=("\n"    "// "+"-"*70+"\n");       mv("TZs.h","TZs.h~"); -  werror("writing TZs.h (%d bytes)...",sizeof(t)); +  t = string_to_utf8(t); +  werror("Writing TZs.h (%d bytes)...",sizeof(t));    Stdio.File("TZs.h","wtc")->write(t);    werror("\n");       mapping zs=([]);    foreach (azones,Zone z)    if (sscanf(z->id,"%s/%s",string s,string t)==2)    zs[s]=(zs[s]||({}))+({t});       // Read and parse the original TZnames.pmod file.    string orig_names = Stdio.read_bytes("TZnames.pmod"); -  +  catch { +  orig_names = utf8_to_string(orig_names); +  };    array(string) fragments = orig_names/" zones=";    if (sizeof(fragments) == 1) fragments = orig_names/" zones =";    if (sizeof(fragments) > 2)    fragments = ({ fragments[0], fragments[1..] * " zones =" });    fragments[1] = (fragments[1]/"]);\n\n")[1..]*"]);\n\n";       t = fragments[0] + " zones =\n"    "([\n";       multiset(string) zone_names = (multiset)indices(zs);       zone_names->SystemV = 0;    zone_names->Etc = 0;       // Historical ordering...    foreach (({"America", "Pacific", "Antarctica", "Atlantic", "Indian",    "Europe", "Africa", "Asia", "Australia" }), string co) {    t +=    sprintf(" %-13s({%-=60s\n",    sprintf("%O:",co), -  map(zs[co],lambda(string s) { return sprintf("%O",s); }) +  map(sort(zs[co]),lambda(string s) { return sprintf("%O",s); })    *", "+"}),");    zone_names[co] = 0;    }    // Take care of any remaining zones (probably none).    foreach (sort(indices(zone_names)),string co) {    t +=    sprintf(" %-13s({%-=60s\n",    sprintf("%O:",co), -  map(zs[co],lambda(string s) { return sprintf("%O",s); }) +  map(sort(zs[co]),lambda(string s) { return sprintf("%O",s); })    *", "+"}),");    }    t += "]);\n\n" +    fragments[1];       // Update the abbreviation table as well.    fragments = t/" abbr2zones=";    if (sizeof(fragments) == 1) fragments = t/" abbr2zones =";    if (sizeof(fragments) > 2)    fragments = ({ fragments[0], fragments[1..] * " abbr2zones =" });    fragments[1] = (fragments[1]/"]);\n\n")[1..]*"]);\n\n";       t = fragments[0] + " abbr2zones =\n"    "([\n";       foreach(sort(indices(abbr2zones)), string abbr) { -  string line = sprintf(" %q: ({", abbr); -  -  mapping(int:array(string)) info = abbr2zones[abbr]; -  array(string) zones = ({}); -  array(int) until = ({}); -  foreach(info; int us; array(string) zs) { -  zones += zs; -  until += allocate(sizeof(zs), -us); +  t += sprintf(" %q: ({\n", abbr); +  array(string) zones = abbr2zones[abbr]; +  foreach(Array.uniq(sort(zones)); int i; string zone) +  t += sprintf("%*s%q,\n", 5, "", zone); +  t += " }),\n";    } -  // Sort so that the most recent use comes first, -  // and secondarily on the zone name. -  sort(zones, until); -  sort(until, zones); -  foreach(Array.uniq(zones); int i; string zone) { -  string seg = sprintf("%s%q", i?", ":"", zone); -  if (sizeof(line) + sizeof(seg) < 77) { -  line += seg; -  continue; -  } -  t += line + ",\n"; -  line = sprintf(" %q", zone); -  } -  t += line + "}),\n"; -  } +        t += "]);\n\n" +    fragments[1];       // Cleanup white-space at end of line.    string t2 = t;    while ((t = replace(t2,    ({ " \n",    " \n",    " \n",    " \n",    " \n",    " \n",    " \n",    " \n", }), ({ "\n" })*8)) != t2) {    t2 = t;    }       mv("TZnames.pmod","TZnames.pmod~"); -  werror("writing TZnames.pmod (%d bytes)...",sizeof(t)); +  t = string_to_utf8(t); +  werror("Writing TZnames.pmod (%d bytes)...",sizeof(t));    Stdio.File("TZnames.pmod","wtc")->write(t);    werror("\n");       return 0;   }         string TZrules_base=   #"// ---------------------------------------------------------------- - // Daylight savings and war time rules + // Daylight-saving and war time rules   //   // NOTE: this file is generated by mkrules.pike;   // please do not edit manually /Mirar   // ----------------------------------------------------------------      // ----------------------------------------------------------------   // all rules are based on the gregorian calendar, so   // this is the gregorian rule:   // ----------------------------------------------------------------