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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/Timezone.pmod:79: Inside #if 1
     #if 1    string s;       if ( (s=getenv("TZ")) )    {    tz=`[](s);    if (tz) return tz;    }    +  foreach(({ "/etc/timezone", // Linux +  "/etc/TIMEZONE", // Solaris +  "/etc/sysconfig/clock", // Linux Gentoo +  "/etc/conf.d/clock", // Linux RedHat +  "/etc/localtime", // Linux & BSDs (binary) +  }), string fname) {    // Mapping from file name to variable name. -  foreach(([ "/etc/localtime":0, // Linux & BSDs -  "/etc/sysconfig/clock":"ZONE", // Linux RedHat -  "/etc/TIMEZONE":"TZ", // Solaris -  "/etc/conf.d/clock":"TIMEZONE", // Linux Gentoo -  ]); string fname; string var_name) { +  string var_name = +  ([ "/etc/timezone":"", +  "/etc/TIMEZONE":"TZ", +  "/etc/sysconfig/clock":"ZONE", +  "/etc/conf.d/clock":"TIMEZONE", +  "/etc/localtime":0, +  ])[fname];    catch { -  + #if constant(readlink) +  if (!var_name && Stdio.is_link(fname)) { +  s = readlink(fname); +  if (s) { +  array(string) a = s/"/"; +  // Modern zones usually have two levels. +  // (Eg Europe/Paris) +  tz = Calendar.Timezone[a[<1..]*"/"] || +  // NB: There are some zones that have three levels. +  // (Eg America/Indiana/Indianapolis) +  Calendar.Timezone[a[<2..]*"/"] || +  // Old-style zones have a single level. +  Calendar.Timezone[a[-1]]; +  if (tz) return tz; +  } +  } + #endif    if (Stdio.is_file(fname) && (s = Stdio.read_bytes(fname))) {    if (!var_name) {    if (tz = tz_from_tzfile(s)) return tz;    } else {    foreach(s/"\n", string line) {    line = (line/"#")[0]; // Strip comments. -  if (sscanf(s, "%*s" + var_name + "=%s", s) == 2) { +  if (sscanf(line, "%*s" + var_name + "=%s", s) == 2) {    sscanf(s, "\"%s\"", s); // Strip quotes (if any).    if (tz = `[](s))    {    // werror("=>%O\n",tz);    return tz;    } -  +  } else if ((var_name == "") && sizeof(line)) { +  if (tz = `[](line)) +  { +  // werror("=>%O\n",tz); +  return tz;    }    }    }    } -  +  }    };    }      #ifdef __NT__    // FIXME: Consider getting timezone info from the registry.    // HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet    // \\Control\\TimeZoneInformation:    // ActiveTimeBias REG_DWORD 0xffffffc4    // Bias REG_DWORD 0xffffffc4    // DaylightBias REG_DWORD 0xffffffc4
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:138:   #endif   #endif       // run an expert system try on the localtime() rules,    // default to localtime()    return expert(localtime());   };      Calendar.Rule.Timezone tz_from_tzfile(string tzfile)   { +  /* TZfile format (network byte-order): +  * +  * time_t is int32 +  * +  * off type a[x] name Typical value +  * --------------------------------------------------------------------------- +  * 0x00 char[4] 0 magic "TZif" +  * 0x04 char[1] 1 version "\0" or "2" +  * 0x05 char[15] 1 reserved "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" +  * 0x14 int32 2 isgmtcnt +  * 0x18 int32 3 isstdcnt +  * 0x1c int32 4 leapcnt +  * 0x20 int32 5 timecnt +  * 0x24 int32 6 typecnt +  * 0x28 int32 7 charcnt +  * 0x2c time_t[timecnt] transition_times +  * - char[timecnt] transition_time_types +  * - ttinfo[typecnt] transition_info +  * - char[charcnt] abbreviations +  * - leapinfo[leapcnt] leapseconds +  * - char[isstdcnt] utc_or_local_time +  * - char[isgmtcnt] utc_or_local_time +  * +  * struct ttinfo { +  * time_t gmtoff +  * char isdst +  * char abbrind +  * } +  * struct leapinfo { +  * time_t leap_time +  * int32 num_leapseconds +  * } +  * +  * In version 2 the above is followed by a second header +  * where time_t is int64. +  * +  * The second header is followed by a "\n"-enclosed string +  * describing the active rule after the last transition. +  * (Eg "CET-1CEST,M3.5.0,M10.5.0/3") +  * +  */    array header = array_sscanf(tzfile, "%4s%16s%4c%4c%4c%4c%4c%4c");    if( sizeof(header)<8 ) return 0;    array zoneabbr = tzfile[44+header[5]*4+header[5]+header[6]*6..44+header[5]*4+header[5]+header[6]*6+header[7]-1]/"\0";    if(!expert_tzn)    expert_tzn=master()->resolv("Calendar")["TZnames"];       array validzones = `&(@values(expert_tzn->abbr2zones & mkmultiset(zoneabbr)));    if(sizeof(validzones) == 1)    return `[](validzones[0]);   }
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:433:    case 4: return _magic_timezone("UTC"+a+b[..1]+":"+b[2..]);    case 6:    return _magic_timezone("UTC"+a+b[..1]+":"+b[2..3]+":"+b[4..]);    }    }    else if (a=="+-") return _magic_timezone("-0"+b);       return ::`[](replace(tz,"-/+"/1,"__p"/1));   }    - Calendar.Rule.Timezone `[](string tz) + protected Calendar.Rule.Timezone `[](string tz)   {    mixed p=::`[](tz);    if (!p && tz=="locale") return locale=_locale();       if ((<"make_new_timezone","decode_timeskew">)[tz]) return p;       if (!p) p=_magic_timezone(tz);    if (programp(p) || functionp(p)) return p();    return p;   }
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:555:    }       protected string _sprintf(int t)    {    return t=='O' &&    sprintf("Shift(%s,%d%s,%+d,%O)",    dayrule || "<unset>", time,    timetype || "<unset>", offset, s);    }    -  int `==(Shift other) +  protected int `==(Shift other)    {    return ( dayrule==other->dayrule &&    time==other->time &&    timetype==other->timetype &&    offset==other->offset &&    s==other->s );    }    int __equal (Shift other) {return `== (other);}       constant wday=(["Mon":1,"Tue":2,"Wed":3,"Thu":4,"Fri":5,"Sat":6,"Sun":7]);
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:626:    return "LDAY ("+(nleapy->month(mon)->day(d)->year_day())+    ","+wd+")";       return "LDAYL("+(nleapy->month(mon)->day(d)->year_day())+    ","+wd+")";    }    else    complain("unknown rule method %O\n",rule);    }    -  Shift|array ``+(array|Shift s) +  protected Shift|array ``+(array|Shift s)    {    if (!s) return this;    if (!arrayp(s)) s=({s});    return s+({this});    }       int ldayl_is_fix_l(int d1,int wd,int d2,int yn1,int yn2)    {    return 0;    // object y1=Year(yn1);
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:1262:    map(files,    lambda(string fn)    {    return (master()->master_read_file(base_path+fn) ||    (error("Failed to open file %O\n",base_path+fn), "")) - "\r";    })*"\n";    }       class Dummymodule (function(string:mixed) f)    { -  mixed `[](string s) { return f(s); } +  protected mixed `[](string s) { return f(s); }    }      // #define RTTZC_DEBUG   // #define RTTZC_TIMING       void parse_all_rules()    {    if (!all_rules) all_rules=get_all_rules();   #ifdef RTTZC_TIMING    float t1=time(t);