* patch: calendar look ahead
@ 2020-07-02 14:19 sirjofri
2020-07-04 10:01 ` [9front] " sirjofri
2020-07-21 4:19 ` [9front] patch: calendar look ahead ori
0 siblings, 2 replies; 11+ messages in thread
From: sirjofri @ 2020-07-02 14:19 UTC (permalink / raw)
To: 9front
[-- Attachment #1: Type: text/plain, Size: 532 bytes --]
Hey 9front.
finally I hope this mail arrives...
The following patch changes calendar behaviour.
Today is the first. If I call calendar with -p 5 it looks at the 1,2,6
and misses my dates on 3-5. That doesn't really make sense and is not
how I understand the man page.
This patch changes it's behavior to look at all dates between today
and today+5, so in the example above it looks at 1,2,6,5,4,3 (in that
order).
(/sys/src/cmd/calendar.c)
74c74
< if(ahead){
---
> while(ahead > 1){
78a79
> ahead--;
[-- Attachment #2: Type: text/plain, Size: 4286 bytes --]
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <regexp.h>
#include <ctype.h>
typedef struct Date Date;
struct Date {
Reprog *p; /* an RE to match this date */
Date *next; /* pointer to next in list */
};
enum{
Secondsperday = 24*60*60
};
Date *Base = nil;
Biobuf in;
int debug, matchyear;
void dates(Tm*);
void upper2lower(char*, char*, int);
void *emalloc(unsigned int);
void
usage(void)
{
fprint(2, "usage: calendar [-dy] [-p days] [files ...]\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
int i, fd, ahead;
long now;
char *line;
Tm *tm;
Date *d;
char buf[1024];
ahead = 0;
ARGBEGIN{
case 'y':
matchyear = 1;
break;
case 'd':
debug = 1;
break;
case 'p':
ahead = atoi(EARGF(usage()));
break;
default:
usage();
}ARGEND;
/* make a list of dates */
now = time(0);
tm = localtime(now);
dates(tm);
now += Secondsperday;
tm = localtime(now);
dates(tm);
if(tm->wday == 6){
now += Secondsperday;
tm = localtime(now);
dates(tm);
}
if(tm->wday == 0){
now += Secondsperday;
tm = localtime(now);
dates(tm);
}
while(ahead > 1){
now = time(0);
now += ahead * Secondsperday;
tm = localtime(now);
dates(tm);
ahead--;
}
for(i=0; i<argc || (i==0 && argc==0); i++){
if(i==0 && argc==0)
snprint(buf, sizeof buf,
"/usr/%s/lib/calendar", getuser());
else
strecpy(buf, buf+sizeof buf, argv[i]);
fd = open(buf, OREAD);
if(fd<0 || Binit(&in, fd, OREAD)<0){
fprint(2, "calendar: can't open %s: %r\n", buf);
exits("open");
}
/* go through the file */
while(line = Brdline(&in, '\n')){
line[Blinelen(&in) - 1] = 0;
upper2lower(buf, line, sizeof buf);
for(d=Base; d; d=d->next)
if(regexec(d->p, buf, 0, 0)){
print("%s\n", line);
break;
}
}
close(fd);
}
exits("");
}
char *months[] =
{
"january",
"february",
"march",
"april",
"may",
"june",
"july",
"august",
"september",
"october",
"november",
"december"
};
char *nth[] = {
"first",
"second",
"third",
"fourth",
"fifth"
};
char *days[] = {
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"
};
/*
* Generate two Date structures. First has month followed by day;
* second has day followed by month. Link them into list after
* last, and return the first.
*/
void
dates(Tm *tm)
{
Date *nd;
char mo[128], day[128], buf[128];
if(utflen(days[tm->wday]) > 3)
snprint(day, sizeof day, "%3.3s(%s)?",
days[tm->wday], days[tm->wday]+3);
else
snprint(day, sizeof day, "%3.3s", days[tm->wday]);
if(utflen(months[tm->mon]) > 3)
snprint(mo, sizeof mo, "%3.3s(%s)?",
months[tm->mon], months[tm->mon]+3);
else
snprint(mo, sizeof mo, "%3.3s", months[tm->mon]);
if (matchyear)
snprint(buf, sizeof buf,
"^[\t ]*((%s( |\t)+)|(%d/))%d( |\t|$)(((%d|%d|%02d)( |\t|$))|[^0-9]|([0-9]+[^0-9 \t]))",
mo, tm->mon+1, tm->mday, tm->year+1900, tm->year%100, tm->year%100);
else
snprint(buf, sizeof buf,
"^[\t ]*((%s( |\t)+)|(%d/))%d( |\t|$)",
mo, tm->mon+1, tm->mday);
if(debug)
print("%s\n", buf);
nd = emalloc(sizeof(Date));
nd->p = regcomp(buf);
nd->next = Base;
Base = nd;
if (matchyear)
snprint(buf, sizeof buf,
"^[\t ]*%d( |\t)+(%s)( |\t|$)(((%d|%d|%02d)( |\t|$))|[^0-9]|([0-9]+[^0-9 \t]))",
tm->mday, mo, tm->year+1900, tm->year%100, tm->year%100);
else
snprint(buf, sizeof buf,
"^[\t ]*%d( |\t)+(%s)( |\t|$)",
tm->mday, mo);
if(debug)
print("%s\n", buf);
nd = emalloc(sizeof(Date));
nd->p = regcomp(buf);
nd->next = Base;
Base = nd;
snprint(buf, sizeof buf, "^[\t ]*every[ \t]+%s", day);
if(debug)
print("%s\n", buf);
nd = emalloc(sizeof(Date));
nd->p = regcomp(buf);
nd->next = Base;
Base = nd;
snprint(buf, sizeof buf, "[\t ]*the[\t ]+%s[\t ]+%s", nth[(tm->mday-1)/7], day);
if(debug)
print("%s\n", buf);
nd = emalloc(sizeof(Date));
nd->p = regcomp(buf);
nd->next = Base;
Base = nd;
}
/*
* Copy 'from' to 'to', converting to lower case
*/
void
upper2lower(char *to, char *from, int len)
{
while(--len>0 && *from!='\0')
*to++ = tolower(*from++);
*to = 0;
}
/*
* Call malloc and check for errors
*/
void*
emalloc(unsigned int n)
{
void *p;
p = malloc(n);
if(p == 0){
fprint(2, "calendar: malloc failed: %r\n");
exits("malloc");
}
return p;
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9front] patch: calendar look ahead
2020-07-02 14:19 patch: calendar look ahead sirjofri
@ 2020-07-04 10:01 ` sirjofri
2020-07-04 11:05 ` hiro
` (2 more replies)
2020-07-21 4:19 ` [9front] patch: calendar look ahead ori
1 sibling, 3 replies; 11+ messages in thread
From: sirjofri @ 2020-07-04 10:01 UTC (permalink / raw)
To: 9front
[-- Attachment #1: Type: text/plain, Size: 429 bytes --]
Hello again,
I totally forgot to include some more details. I had to send that mail like 3 times because of my mail configuration. Also it seems like 9front ML doesn't accept gmail plain text messages sent with other addresses anymore?
What is the intended behavior of calendar(1) -p days? Is the attached patch an improvement for calendar(1)?
These are the questions I wanted to open the disussion with.
Thank you
sirjofri
[-- Attachment #2: Type: message/rfc822, Size: 9132 bytes --]
[-- Attachment #2.1.1: Type: text/plain, Size: 532 bytes --]
Hey 9front.
finally I hope this mail arrives...
The following patch changes calendar behaviour.
Today is the first. If I call calendar with -p 5 it looks at the 1,2,6
and misses my dates on 3-5. That doesn't really make sense and is not
how I understand the man page.
This patch changes it's behavior to look at all dates between today
and today+5, so in the example above it looks at 1,2,6,5,4,3 (in that
order).
(/sys/src/cmd/calendar.c)
74c74
< if(ahead){
---
> while(ahead > 1){
78a79
> ahead--;
[-- Attachment #2.1.2: Type: text/plain, Size: 4286 bytes --]
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <regexp.h>
#include <ctype.h>
typedef struct Date Date;
struct Date {
Reprog *p; /* an RE to match this date */
Date *next; /* pointer to next in list */
};
enum{
Secondsperday = 24*60*60
};
Date *Base = nil;
Biobuf in;
int debug, matchyear;
void dates(Tm*);
void upper2lower(char*, char*, int);
void *emalloc(unsigned int);
void
usage(void)
{
fprint(2, "usage: calendar [-dy] [-p days] [files ...]\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
int i, fd, ahead;
long now;
char *line;
Tm *tm;
Date *d;
char buf[1024];
ahead = 0;
ARGBEGIN{
case 'y':
matchyear = 1;
break;
case 'd':
debug = 1;
break;
case 'p':
ahead = atoi(EARGF(usage()));
break;
default:
usage();
}ARGEND;
/* make a list of dates */
now = time(0);
tm = localtime(now);
dates(tm);
now += Secondsperday;
tm = localtime(now);
dates(tm);
if(tm->wday == 6){
now += Secondsperday;
tm = localtime(now);
dates(tm);
}
if(tm->wday == 0){
now += Secondsperday;
tm = localtime(now);
dates(tm);
}
while(ahead > 1){
now = time(0);
now += ahead * Secondsperday;
tm = localtime(now);
dates(tm);
ahead--;
}
for(i=0; i<argc || (i==0 && argc==0); i++){
if(i==0 && argc==0)
snprint(buf, sizeof buf,
"/usr/%s/lib/calendar", getuser());
else
strecpy(buf, buf+sizeof buf, argv[i]);
fd = open(buf, OREAD);
if(fd<0 || Binit(&in, fd, OREAD)<0){
fprint(2, "calendar: can't open %s: %r\n", buf);
exits("open");
}
/* go through the file */
while(line = Brdline(&in, '\n')){
line[Blinelen(&in) - 1] = 0;
upper2lower(buf, line, sizeof buf);
for(d=Base; d; d=d->next)
if(regexec(d->p, buf, 0, 0)){
print("%s\n", line);
break;
}
}
close(fd);
}
exits("");
}
char *months[] =
{
"january",
"february",
"march",
"april",
"may",
"june",
"july",
"august",
"september",
"october",
"november",
"december"
};
char *nth[] = {
"first",
"second",
"third",
"fourth",
"fifth"
};
char *days[] = {
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"
};
/*
* Generate two Date structures. First has month followed by day;
* second has day followed by month. Link them into list after
* last, and return the first.
*/
void
dates(Tm *tm)
{
Date *nd;
char mo[128], day[128], buf[128];
if(utflen(days[tm->wday]) > 3)
snprint(day, sizeof day, "%3.3s(%s)?",
days[tm->wday], days[tm->wday]+3);
else
snprint(day, sizeof day, "%3.3s", days[tm->wday]);
if(utflen(months[tm->mon]) > 3)
snprint(mo, sizeof mo, "%3.3s(%s)?",
months[tm->mon], months[tm->mon]+3);
else
snprint(mo, sizeof mo, "%3.3s", months[tm->mon]);
if (matchyear)
snprint(buf, sizeof buf,
"^[\t ]*((%s( |\t)+)|(%d/))%d( |\t|$)(((%d|%d|%02d)( |\t|$))|[^0-9]|([0-9]+[^0-9 \t]))",
mo, tm->mon+1, tm->mday, tm->year+1900, tm->year%100, tm->year%100);
else
snprint(buf, sizeof buf,
"^[\t ]*((%s( |\t)+)|(%d/))%d( |\t|$)",
mo, tm->mon+1, tm->mday);
if(debug)
print("%s\n", buf);
nd = emalloc(sizeof(Date));
nd->p = regcomp(buf);
nd->next = Base;
Base = nd;
if (matchyear)
snprint(buf, sizeof buf,
"^[\t ]*%d( |\t)+(%s)( |\t|$)(((%d|%d|%02d)( |\t|$))|[^0-9]|([0-9]+[^0-9 \t]))",
tm->mday, mo, tm->year+1900, tm->year%100, tm->year%100);
else
snprint(buf, sizeof buf,
"^[\t ]*%d( |\t)+(%s)( |\t|$)",
tm->mday, mo);
if(debug)
print("%s\n", buf);
nd = emalloc(sizeof(Date));
nd->p = regcomp(buf);
nd->next = Base;
Base = nd;
snprint(buf, sizeof buf, "^[\t ]*every[ \t]+%s", day);
if(debug)
print("%s\n", buf);
nd = emalloc(sizeof(Date));
nd->p = regcomp(buf);
nd->next = Base;
Base = nd;
snprint(buf, sizeof buf, "[\t ]*the[\t ]+%s[\t ]+%s", nth[(tm->mday-1)/7], day);
if(debug)
print("%s\n", buf);
nd = emalloc(sizeof(Date));
nd->p = regcomp(buf);
nd->next = Base;
Base = nd;
}
/*
* Copy 'from' to 'to', converting to lower case
*/
void
upper2lower(char *to, char *from, int len)
{
while(--len>0 && *from!='\0')
*to++ = tolower(*from++);
*to = 0;
}
/*
* Call malloc and check for errors
*/
void*
emalloc(unsigned int n)
{
void *p;
p = malloc(n);
if(p == 0){
fprint(2, "calendar: malloc failed: %r\n");
exits("malloc");
}
return p;
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9front] patch: calendar look ahead
2020-07-04 10:01 ` [9front] " sirjofri
@ 2020-07-04 11:05 ` hiro
2020-07-04 14:25 ` Stanley Lieber
2020-07-10 5:31 ` ori
2 siblings, 0 replies; 11+ messages in thread
From: hiro @ 2020-07-04 11:05 UTC (permalink / raw)
To: 9front
gmail "plaintext" might not be plaintext. not sure...
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9front] patch: calendar look ahead
2020-07-04 10:01 ` [9front] " sirjofri
2020-07-04 11:05 ` hiro
@ 2020-07-04 14:25 ` Stanley Lieber
2020-07-10 5:31 ` ori
2 siblings, 0 replies; 11+ messages in thread
From: Stanley Lieber @ 2020-07-04 14:25 UTC (permalink / raw)
To: 9front
On July 4, 2020 6:01:44 AM EDT, sirjofri@sirjofri.de wrote:
>Hello again,
>
>I totally forgot to include some more details. I had to send that mail
>like 3 times because of my mail configuration. Also it seems like
>9front ML doesn't accept gmail plain text messages sent with other
>addresses anymore?
>
>What is the intended behavior of calendar(1) -p days? Is the attached
>patch an improvement for calendar(1)?
>
>These are the questions I wanted to open the disussion with.
>
>Thank you
>
>sirjofri
fwiw, I received the original message to the list.
sl
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9front] patch: calendar look ahead
2020-07-04 10:01 ` [9front] " sirjofri
2020-07-04 11:05 ` hiro
2020-07-04 14:25 ` Stanley Lieber
@ 2020-07-10 5:31 ` ori
2020-07-10 7:14 ` Steve Simon
` (2 more replies)
2 siblings, 3 replies; 11+ messages in thread
From: ori @ 2020-07-10 5:31 UTC (permalink / raw)
To: sirjofri, 9front
> Hello again,
>
> I totally forgot to include some more details. I had to send that mail like 3 times because of my mail configuration. Also it seems like 9front ML doesn't accept gmail plain text messages sent with other addresses anymore?
>
> What is the intended behavior of calendar(1) -p days? Is the attached patch an improvement for calendar(1)?
>
> These are the questions I wanted to open the disussion with.
>
> Thank you
>
> sirjofri
The change makes sense to me, but at the moment I don't really use calendar(1),
so I don't have strong opinions.
(Wishlist item: a utility program to sync between lib/calendar and Google Calendar,)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9front] patch: calendar look ahead
2020-07-10 5:31 ` ori
@ 2020-07-10 7:14 ` Steve Simon
2020-07-13 3:58 ` ori
2020-07-10 7:15 ` sirjofri
2020-07-10 7:20 ` Steve Simon
2 siblings, 1 reply; 11+ messages in thread
From: Steve Simon @ 2020-07-10 7:14 UTC (permalink / raw)
To: 9front
i have a crude ical parser which i used to build calendar entries from meeting invites i emails.
my plan was to write calendarfs which would read any ical source and present a directory if events to a simple calendar prog (probably a script) but timezone handling was always the problem.
i am happy to share the crude translator i have.
-Steve
> On 10 Jul 2020, at 7:32 am, ori@eigenstate.org wrote:
>
>
>>
>> Hello again,
>>
>> I totally forgot to include some more details. I had to send that mail like 3 times because of my mail configuration. Also it seems like 9front ML doesn't accept gmail plain text messages sent with other addresses anymore?
>>
>> What is the intended behavior of calendar(1) -p days? Is the attached patch an improvement for calendar(1)?
>>
>> These are the questions I wanted to open the disussion with.
>>
>> Thank you
>>
>> sirjofri
>
> The change makes sense to me, but at the moment I don't really use calendar(1),
> so I don't have strong opinions.
>
> (Wishlist item: a utility program to sync between lib/calendar and Google Calendar,)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9front] patch: calendar look ahead
2020-07-10 7:14 ` Steve Simon
@ 2020-07-13 3:58 ` ori
0 siblings, 0 replies; 11+ messages in thread
From: ori @ 2020-07-13 3:58 UTC (permalink / raw)
To: steve, 9front
> i have a crude ical parser which i used to build calendar entries from meeting invites i emails.
>
> my plan was to write calendarfs which would read any ical source and present a directory if events to a simple calendar prog (probably a script) but timezone handling was always the problem.
>
> i am happy to share the crude translator i have.
>
> -Steve
I'd be interested in taking a look.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9front] patch: calendar look ahead
2020-07-10 5:31 ` ori
2020-07-10 7:14 ` Steve Simon
@ 2020-07-10 7:15 ` sirjofri
2020-07-10 7:20 ` Steve Simon
2 siblings, 0 replies; 11+ messages in thread
From: sirjofri @ 2020-07-10 7:15 UTC (permalink / raw)
To: ori; +Cc: 9front
Hey,
10.07.2020 09:31:57 ori@eigenstate.org:
>
> The change makes sense to me, but at the moment I don't really use calendar(1),
> so I don't have strong opinions.
>
> (Wishlist item: a utility program to sync between lib/calendar and Google Calendar,)
>
Google calendar can work with ics calendar files. I started to look into that format and design a "middleware" for simple calendar entries that can output calendar(1) format (and provide its own filesystem). Calendar has not the capabilities of ics, so it will only support a subset, and it might be necessary to add new entries via that filesystem (which provides a proper calendar file and ics file then).
Through the power of namespaces you can bind that calendar file over your lib/calendar and the ics file inside a http shared directory (which google calendar can read). I don't think you can add entries via google directly, but an ics import feature is planned.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9front] patch: calendar look ahead
2020-07-10 5:31 ` ori
2020-07-10 7:14 ` Steve Simon
2020-07-10 7:15 ` sirjofri
@ 2020-07-10 7:20 ` Steve Simon
2020-07-10 9:40 ` [9front] ical calendar (was: calendar look ahead) sirjofri
2 siblings, 1 reply; 11+ messages in thread
From: Steve Simon @ 2020-07-10 7:20 UTC (permalink / raw)
To: 9front
another offering - i added support for recurrent calendar entries if the form:
weekly meetings:
every wed <meeting description>
the same day every month:
the first wed <meeting description>
happy to share if anyone wants.
-Steve
> On 10 Jul 2020, at 7:32 am, ori@eigenstate.org wrote:
>
>
>>
>> Hello again,
>>
>> I totally forgot to include some more details. I had to send that mail like 3 times because of my mail configuration. Also it seems like 9front ML doesn't accept gmail plain text messages sent with other addresses anymore?
>>
>> What is the intended behavior of calendar(1) -p days? Is the attached patch an improvement for calendar(1)?
>>
>> These are the questions I wanted to open the disussion with.
>>
>> Thank you
>>
>> sirjofri
>
> The change makes sense to me, but at the moment I don't really use calendar(1),
> so I don't have strong opinions.
>
> (Wishlist item: a utility program to sync between lib/calendar and Google Calendar,)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9front] ical calendar (was: calendar look ahead)
2020-07-10 7:20 ` Steve Simon
@ 2020-07-10 9:40 ` sirjofri
0 siblings, 0 replies; 11+ messages in thread
From: sirjofri @ 2020-07-10 9:40 UTC (permalink / raw)
To: Steve Simon; +Cc: 9front
Hey all,
10.07.2020 11:20:49 Steve Simon <steve@quintile.net>:
> another offering - i added support for recurrent calendar entries if the form:
>
> weekly meetings:
> every wed <meeting description>
>
> the same day every month:
> the first wed <meeting description>
>
> happy to share if anyone wants.
9front calendar(1) already has support for weekly events. At least I use it and it works (see man page). I'm not sure about the more complex "every first thursday" dates.
About your ical stuff: I guess we could also start a open source project for that.
I thought about reading and writing a ical database for the user, which is the source and then a filesystem with a proper abstraction of the data (events as directories, ...). Of course a calendar file for calendar(1), so we can use standard plan9 tools as well. The filesystem would provide a user-writeable interface for creating new entries (new/desc, new/start) and a file for importing new events from an ical file (new.ical).
Iirc ori was improving date functions? I don't know if they are finally in main, there were some problems, I think? This might help with timezones and date parsing in general.
sirjofri
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9front] patch: calendar look ahead
2020-07-02 14:19 patch: calendar look ahead sirjofri
2020-07-04 10:01 ` [9front] " sirjofri
@ 2020-07-21 4:19 ` ori
1 sibling, 0 replies; 11+ messages in thread
From: ori @ 2020-07-21 4:19 UTC (permalink / raw)
To: sirjofri, 9front
> Hey 9front.
>
> finally I hope this mail arrives...
>
> The following patch changes calendar behaviour.
>
> Today is the first. If I call calendar with -p 5 it looks at the 1,2,6
> and misses my dates on 3-5. That doesn't really make sense and is not
> how I understand the man page.
>
> This patch changes it's behavior to look at all dates between today
> and today+5, so in the example above it looks at 1,2,6,5,4,3 (in that
> order).
>
> (/sys/src/cmd/calendar.c)
>
> 74c74
> < if(ahead){
> ---
>> while(ahead > 1){
> 78a79
>> ahead--;
Since I derailed the thread with talk of syncing, I guess
I should be the one to prod it: Did anyone have any opinions
for or against this?
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2020-07-21 4:19 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-02 14:19 patch: calendar look ahead sirjofri
2020-07-04 10:01 ` [9front] " sirjofri
2020-07-04 11:05 ` hiro
2020-07-04 14:25 ` Stanley Lieber
2020-07-10 5:31 ` ori
2020-07-10 7:14 ` Steve Simon
2020-07-13 3:58 ` ori
2020-07-10 7:15 ` sirjofri
2020-07-10 7:20 ` Steve Simon
2020-07-10 9:40 ` [9front] ical calendar (was: calendar look ahead) sirjofri
2020-07-21 4:19 ` [9front] patch: calendar look ahead ori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).