Branch: Tag:

2008-02-07

2008-02-07 01:39:53 by Martin Stjernholm <mast@lysator.liu.se>

Fixes to make it possible to write a compat wrapper for this module: Did
away with all .Foo style identifiers since they _always_ result in a lookup
in the same directory as the current file, even when it's included from
somewhere else.

So if e.g. lib/modules/Calendar.pmod/Time.pmod is #include'd from
lib/7.6/modules/Calendar.pmod/Time.pmod (which we must do to compile it
all in #pike 7.6 mode), and the included Time.pmod contains a reference
.Ruleset, that reference will be resolved in lib/modules/Calendar.pmod.
That's odd and probably buggy, since one would reasonably expect cpp stuff
like #include to be completely transparent for the resolver.

Rev: lib/modules/Calendar.pmod/Austrian.pmod:1.7
Rev: lib/modules/Calendar.pmod/Badi.pmod:1.7
Rev: lib/modules/Calendar.pmod/Calendar.pike:1.7
Rev: lib/modules/Calendar.pmod/Coptic.pmod:1.7
Rev: lib/modules/Calendar.pmod/Discordian.pmod:1.11
Rev: lib/modules/Calendar.pmod/Event.pmod:1.23
Rev: lib/modules/Calendar.pmod/Gregorian.pmod:1.10
Rev: lib/modules/Calendar.pmod/ISO.pmod:1.9
Rev: lib/modules/Calendar.pmod/Islamic.pmod:1.10
Rev: lib/modules/Calendar.pmod/Julian.pmod:1.10
Rev: lib/modules/Calendar.pmod/Language.pmod:1.24
Rev: lib/modules/Calendar.pmod/Ruleset.pike:1.15
Rev: lib/modules/Calendar.pmod/Stardate.pmod:1.16
Rev: lib/modules/Calendar.pmod/Swedish.pmod:1.8
Rev: lib/modules/Calendar.pmod/Time.pmod:1.41
Rev: lib/modules/Calendar.pmod/TimeRanges.pmod:1.34
Rev: lib/modules/Calendar.pmod/Timezone.pmod:1.40
Rev: lib/modules/Calendar.pmod/YMD.pike:1.29

7:   static constant M_NAME="---JanFebMarAprMayJunJulAugSepOctNovDec"/3;   static constant WD_NAME="---MonTueWedThuFriSatSun"/3;    - static function(mixed...:.TimeRanges.TimeRange) std_day=Calendar.Day; - static function(mixed...:.TimeRanges.TimeRange) std_second=Calendar.Second; + static function(mixed...:Calendar.TimeRanges.TimeRange) std_day= +  Calendar.Day; + static function(mixed...:Calendar.TimeRanges.TimeRange) std_second= +  Calendar.Second;      // ----------------------------------------------------------------   // base classes
32:    //! It returns zero if there is no next event.    //!    //! These methods are virtual in the base class. -  .TimeRanges.TimeRange next(void|.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange next(void|Calendar.TimeRanges.TimeRange from,    void|int(0..1) including); -  .TimeRanges.TimeRange previous(void|.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange previous(void|Calendar.TimeRanges.TimeRange from,    void|int(0..1) including);       //! This calculates the eventual events that is contained or
50:    //!    //! This method must use @tt{in->calendar_object->@}@i{type@}    //! to create the returned timeranges, and must keep the ruleset. -  array(.TimeRanges.TimeRange) scan(.TimeRanges.TimeRange in) +  array(Calendar.TimeRanges.TimeRange) scan(Calendar.TimeRanges.TimeRange in)    {    array res=({}); -  .TimeRanges.TimeRange t=next(in,1); +  Calendar.TimeRanges.TimeRange t=next(in,1);    for (;;)    {    if (!t || !t->overlaps(in)) return res;
63:    }       //! Returns a mapping with time ranges mapped to events. -  mapping(.TimeRanges.TimeRange:Event) scan_events(.TimeRanges.TimeRange in) +  mapping(Calendar.TimeRanges.TimeRange:Event) +  scan_events(Calendar.TimeRanges.TimeRange in)    {    array r=scan(in);    return mkmapping(r,allocate(sizeof(r),this));
113:    name=s;    }    -  .TimeRanges.TimeRange next(void|.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange next(void|Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    {    return 0;    }    -  .TimeRanges.TimeRange previous(void|.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange previous(void|Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    {    return 0;
141:       int nd=1;    -  //! @decl int scan_jd(.Calendar realm, int jd,@ +  //! @decl int scan_jd(Calendar.Calendar realm, int jd,@    //! int(-1..-1)|int(1..1) direction)    //! These methods has to be defined, and is what    //! really does some work. It should return the next or previos
156:    //! Backward (previous).    //! @endint    -  int scan_jd(.Calendar realm,int jd,int(1..1)|int(-1..-1) direction); +  int scan_jd(Calendar.Calendar realm,int jd,int(1..1)|int(-1..-1) direction);       //! Uses the virtual method @[scan_jd].    //! @seealso    //! @[Event.next] -  .TimeRanges.TimeRange next(void|.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange next(void|Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    {    if (!from) from=std_day();
175:    //! Uses the virtual method @[scan_jd].    //! @seealso    //! @[Event.previous] -  .TimeRanges.TimeRange previous(void|.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange previous(void|Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    {    if (!from) from=std_day();
208:    jd=_jd;    }    -  int scan_jd(.Calendar realm,int sjd,int(1..1)|int(-1..-1) direction) +  int scan_jd(Calendar.Calendar realm,int sjd,int(1..1)|int(-1..-1) direction)    {    if (direction==1) return sjd<=jd?jd:NODAY;    else return sjd>=jd?jd:NODAY;
251:       //! Gives back an array of names that occur during    //! the time period, in no particular order. -  array(string) names(.TimeRanges.TimeRange t) +  array(string) names(Calendar.TimeRanges.TimeRange t)    {    // optimize this?    return predef::`|(({}),@values(namedays(t)));
260:    //! Gives back an table of days with names that occur during    //! the time period. Note that days without names will not    //! appear in the returned mapping. -  mapping(.TimeRanges.TimeRange:array(string)) -  namedays(.TimeRanges.TimeRange t) +  mapping(Calendar.TimeRanges.TimeRange:array(string)) +  namedays(Calendar.TimeRanges.TimeRange t)    {    int jd=t->julian_day();    mapping res=([]); -  function(mixed...:.TimeRanges.TimeRange) day=t->calendar()->Day; -  .Ruleset rules=t->ruleset(); +  function(mixed...:Calendar.TimeRanges.TimeRange) day=t->calendar()->Day; +  Calendar.Ruleset rules=t->ruleset();    [int y,int yjd,int leap]=gregorian_yjd(jd);    if (first_year!=-1 && y<first_year)    [y,yjd,leap]=gregorian_year(first_year),jd=yjd;
277:       for (;;)    { -  .TimeRanges.TimeRange td=day("julian_r",jd,rules); +  Calendar.TimeRanges.TimeRange td=day("julian_r",jd,rules);    if (!td->overlaps(t)) return res;       if (jd>=yjd+365+leap) // next year
304:    }    }    -  mapping(.TimeRanges.TimeRange:Event) scan_events(.TimeRanges.TimeRange in) +  mapping(Calendar.TimeRanges.TimeRange:Event) +  scan_events(Calendar.TimeRanges.TimeRange in)    {    mapping res=([]); -  foreach ((array)namedays(in),[.TimeRanges.TimeRange t,array(string) s]) +  foreach ((array)namedays(in), +  [Calendar.TimeRanges.TimeRange t,array(string) s])    res[t]=predef::`|(@map(s,Nameday,t->julian_day()));    return res;    }    -  array(.TimeRanges.TimeRange) scan(.TimeRanges.TimeRange in) +  array(Calendar.TimeRanges.TimeRange) scan(Calendar.TimeRanges.TimeRange in)    {    return indices(namedays(in));    }    -  static .TimeRanges.TimeRange _find(.TimeRanges.TimeRange t, +  static Calendar.TimeRanges.TimeRange _find(Calendar.TimeRanges.TimeRange t,    int including, int direction)    {    int jd=(int)t->julian_day();
362:    }    }    -  .TimeRanges.TimeRange next(.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange next(Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    {    return _find(from,including,1);    }    -  .TimeRanges.TimeRange previous(.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange previous(Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    {    return _find(from,including,-1);
429:    return "Namedays";    }    -  array(.TimeRanges.TimeRange) scan(.TimeRanges.TimeRange in) +  array(Calendar.TimeRanges.TimeRange) scan(Calendar.TimeRanges.TimeRange in)    {    return indices(namedays(in));    }    -  mapping(.TimeRanges.TimeRange:Event) scan_events(.TimeRanges.TimeRange in) +  mapping(Calendar.TimeRanges.TimeRange:Event) +  scan_events(Calendar.TimeRanges.TimeRange in)    {    return predef::`|(@map(namedayss,"scan_events",in));    }    -  .TimeRanges.TimeRange next(.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange next(Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    { -  array(.TimeRanges.TimeRange) a=map(namedayss,"next", +  array(Calendar.TimeRanges.TimeRange) a=map(namedayss,"next",    from,including)-({0});    switch (sizeof(a))    {
452:    }    }    -  .TimeRanges.TimeRange previous(.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange previous(Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    { -  array(.TimeRanges.TimeRange) a=map(namedayss,"previous", +  array(Calendar.TimeRanges.TimeRange) a=map(namedayss,"previous",    from,including)-({0});    switch (sizeof(a))    {
465:    }    }    -  mapping(.TimeRanges.TimeRange:array(string)) -  namedays(.TimeRanges.TimeRange t) +  mapping(Calendar.TimeRanges.TimeRange:array(string)) +  namedays(Calendar.TimeRanges.TimeRange t)    {    return predef::`|(@map(namedayss,"namedays",t));    }    -  array(string) names(.TimeRanges.TimeRange t) +  array(string) names(Calendar.TimeRanges.TimeRange t)    {    return predef::`|(@map(namedayss,"names",t));    }
576:    if (sizeof(_n)) nd=_n[0];    }    -  int scan_jd(.Calendar realm,int jd,int(-1..1) direction) +  int scan_jd(Calendar.Calendar realm,int jd,int(-1..1) direction)    {    [int y,int yjd,int leap]=gregorian_yjd(jd);    int njd;
618:    //! This constant may be used to identify @[Julian_Fixed] objects.    constant is_julian_fixed=1;    -  int scan_jd(.Calendar realm,int jd,int(-1..1) direction) +  int scan_jd(Calendar.Calendar realm,int jd,int(-1..1) direction)    {    [int y,int yjd,int leap]=julian_yjd(jd);    int njd;
671:    yd=M_YD[mn]+md;    }    -  int scan_jd(.Calendar realm,int jd,int(-1..1) direction) +  int scan_jd(Calendar.Calendar realm,int jd,int(-1..1) direction)    {    [int y,int yjd,int leap]=gregorian_yjd(jd);    for (;;)
728:    jd_wd=(wd+6)%7;    }    -  int scan_jd(.Calendar realm,int jd,int(-1..1) direction) +  int scan_jd(Calendar.Calendar realm,int jd,int(-1..1) direction)    {    if (md<1) return 0;    [int y,int yjd,int leap]=gregorian_yjd(jd);
781:    jd_wd=(wd+6)%7;    }    -  int scan_jd(.Calendar realm,int jd,int(-1..1) direction) +  int scan_jd(Calendar.Calendar realm,int jd,int(-1..1) direction)    {    if (md>31 || md<1) return 0;    [int y,int yjd,int leap]=gregorian_yjd(jd);
842:    if (!id) id=name; else id=_id;    }    -  int scan_jd(.Calendar realm,int jd,int(-1..1) direction) +  int scan_jd(Calendar.Calendar realm,int jd,int(-1..1) direction)    {    if (direction==-1) return jd-(jd-jd_wd)%7;    return jd+(7-(jd-jd_wd))%7;
918:    return gregorian_year(y);    }    -  int scan_jd(.Calendar realm,int jd,int(-1..1) direction) +  int scan_jd(Calendar.Calendar realm,int jd,int(-1..1) direction)    {    int y,yjd,leap,ejd;   
965:    offset=_offset;    }    -  int scan_jd(.Calendar realm,int jd,int(-1..1) direction) +  int scan_jd(Calendar.Calendar realm,int jd,int(-1..1) direction)    {    return offset+::scan_jd(realm,jd-direction*offset,direction);    }
1030:    wd=_wd;    }    -  int scan_jd(.Calendar realm,int jd,int(-1..1) direction) +  int scan_jd(Calendar.Calendar realm,int jd,int(-1..1) direction)    {    [int y,int yjd,int leap]=gregorian_yjd(jd-offset);    for (;;)
1136:    SuperEvent holidays() { return filter_flag("h"); }    SuperEvent flagdays() { return filter_flag("f"); }    -  mapping(.TimeRanges.TimeRange:Event) scan_events(.TimeRanges.TimeRange in) +  mapping(Calendar.TimeRanges.TimeRange:Event) +  scan_events(Calendar.TimeRanges.TimeRange in)    {    mapping res=([]);    foreach (events,Event e)    {    mapping er=e->scan_events(in); -  foreach ((array)er,[.TimeRanges.TimeRange t,Event e]) +  foreach ((array)er,[Calendar.TimeRanges.TimeRange t,Event e])    if (res[t]) res[t]|=e; // join    else res[t]=e;    }    return res;    }    -  array(.TimeRanges.TimeRange) scan(.TimeRanges.TimeRange in) +  array(Calendar.TimeRanges.TimeRange) scan(Calendar.TimeRanges.TimeRange in)    {    return indices(scan_events(in));    }    -  .TimeRanges.TimeRange next(.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange next(Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    { -  .TimeRanges.TimeRange best=0; +  Calendar.TimeRanges.TimeRange best=0;    foreach (events,Event e)    { -  .TimeRanges.TimeRange y=e->next(from,including); +  Calendar.TimeRanges.TimeRange y=e->next(from,including);    if (!best || y->preceeds(best)) best=y;    else if (y->starts_with(best)) best|=y;    }    return best;    }    -  .TimeRanges.TimeRange previous(.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange previous(Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    { -  .TimeRanges.TimeRange best=0; +  Calendar.TimeRanges.TimeRange best=0;    foreach (events,Event e)    { -  .TimeRanges.TimeRange y=e->previous(from,including); +  Calendar.TimeRanges.TimeRange y=e->previous(from,including);    if (!best || best->preceeds(y)) best=y;    else if (y->ends_with(best)) best|=y;    }
1244:       constant is_tzshift_event=1;    -  .Rule.Timezone timezone; +  Calendar.Rule.Timezone timezone;    -  void create(void|.Rule.Timezone _tz) +  void create(void|Calendar.Rule.Timezone _tz)    {    timezone=_tz;    }    -  .TimeRanges.TimeRange next(void|.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange next(void|Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    {    if (!from) from=std_second();    return scan_shift(timezone||from->timezone(),    from,1,including);    } -  .TimeRanges.TimeRange previous(void|.TimeRanges.TimeRange from, +  Calendar.TimeRanges.TimeRange previous(void|Calendar.TimeRanges.TimeRange from,    void|int(0..1) including)    {    if (!from) from=std_second();
1267:    }       //! -  static .TimeRanges.TimeRange scan_shift(.Rule.Timezone tz, -  .TimeRanges.TimeRange from, +  static Calendar.TimeRanges.TimeRange +  scan_shift(Calendar.Rule.Timezone tz, +  Calendar.TimeRanges.TimeRange from,    int direction,int including)    {    if (tz->whatrule)
1277:    }       //! -  static .TimeRanges.TimeRange scan_history(.Rule.Timezone tz, -  .TimeRanges.TimeRange from, +  static Calendar.TimeRanges.TimeRange +  scan_history(Calendar.Rule.Timezone tz, +  Calendar.TimeRanges.TimeRange from,    int direction,int(0..1) including)    {    int ux;
1298:    foreach (reverse(tz->shifts),int z)    if (z<=ux) { nextshift=z; break; }    -  .TimeRanges.TimeRange btr=0; +  Calendar.TimeRanges.TimeRange btr=0;    if (nextshift!=-1)    btr=from->calendar()->Second("unix_r",nextshift,from->ruleset());    -  .TimeRanges.TimeRange atr=from; +  Calendar.TimeRanges.TimeRange atr=from;    for (;;)    { -  .Rule.Timezone atz=tz->whatrule(ux); +  Calendar.Rule.Timezone atz=tz->whatrule(ux);    atr=scan_rule(atz,atr,direction,including);    if (!atr) break;    if (direction==1)
1325:    }       //! -  static .TimeRanges.TimeRange scan_rule(.Rule.Timezone tz, -  .TimeRanges.TimeRange from, +  static Calendar.TimeRanges.TimeRange +  scan_rule(Calendar.Rule.Timezone tz, +  Calendar.TimeRanges.TimeRange from,    int direction,int including)    {    if (!tz->jd_year_periods)
1353:    foreach (per[1..],array shift)    if (shift[0]>=jd)    { -  .TimeRanges.TimeRange atr=from->calendar() +  Calendar.TimeRanges.TimeRange atr=from->calendar()    ->Second("unix_r",(shift[0]-2440588)*86400+shift[1],    from->ruleset());    if (atr>=from) return atr;
1364:    foreach (reverse(per[1..]),array shift)    if (shift[0]<=jd)    { -  .TimeRanges.TimeRange atr=from->calendar() +  Calendar.TimeRanges.TimeRange atr=from->calendar()    ->Second("unix_r",(shift[0]-2440588)*86400+shift[1],    from->ruleset());    if (atr<=from) return atr;