langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
51
Task/Calendar/PL-I/calendar.pli
Normal file
51
Task/Calendar/PL-I/calendar.pli
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
calendar: procedure (year) options (main);
|
||||
declare year character (4) varying;
|
||||
declare (a, b, c) (0:5,0:6) character (3);
|
||||
declare name_month(12) static character (9) varying initial (
|
||||
'JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE',
|
||||
'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER');
|
||||
declare i fixed;
|
||||
declare (mm, mmp1, mmp2) pic '99';
|
||||
|
||||
put edit (center('CALENDAR FOR ' || YEAR, 67)) (a);
|
||||
put skip (2);
|
||||
|
||||
do mm = 1 to 12 by 3;
|
||||
mmp1 = mm + 1; mmp2 = mm + 2;
|
||||
call prepare_month('01' || mm || YEAR, a);
|
||||
call prepare_month('01' || mmp1 || YEAR, b);
|
||||
call prepare_month('01' || mmp2 || YEAR, c);
|
||||
|
||||
put skip edit (center(name_month(mm), 23),
|
||||
center(name_month(mmp1), 23),
|
||||
center(name_month(mmp2), 23) ) (a);
|
||||
put skip edit ((3)' M T W T F S S ') (a);
|
||||
do i = 0 to 5;
|
||||
put skip edit (a(i,*), b(i,*), c(i,*)) (7 a, x(2));
|
||||
end;
|
||||
end;
|
||||
|
||||
prepare_month: procedure (start, month);
|
||||
declare month(0:5,0:6) character (3);
|
||||
declare start character (8);
|
||||
declare i pic 'ZZ9';
|
||||
declare offset fixed;
|
||||
declare (j, day) fixed binary (31);
|
||||
declare (this_month, next_month, k) fixed binary;
|
||||
|
||||
day = days(start, 'DDMMYYYY');
|
||||
offset = weekday(day) - 1;
|
||||
if offset = 0 then offset = 7;
|
||||
month = '';
|
||||
do j = day by 1;
|
||||
this_month = substr(daystodate(j, 'DDMMYYYY'), 3, 2);
|
||||
next_month = substr(daystodate(j+1, 'DDMMYYYY'), 3, 2);
|
||||
if this_month^= next_month then leave;
|
||||
end;
|
||||
i = 1;
|
||||
do k = offset-1 to offset+j-day-1;
|
||||
month(k/7, mod(k,7)) = i; i = i + 1;
|
||||
end;
|
||||
end prepare_month;
|
||||
|
||||
end calendar;
|
||||
55
Task/Calendar/Perl-6/calendar.pl6
Normal file
55
Task/Calendar/Perl-6/calendar.pl6
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
my $months-per-col = 3;
|
||||
my @week-day-names = <Mo Tu We Th Fr Sa Su>;
|
||||
my @month-names = <Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec>;
|
||||
|
||||
my Int $year = +(@*ARGS.shift || 1969);
|
||||
|
||||
say fmt-year($year);
|
||||
exit;
|
||||
|
||||
sub fmt-year ($year) {
|
||||
|
||||
my $str = (' ' x 30) ~ $year ~ "\n";
|
||||
|
||||
my @month-strs;
|
||||
@month-strs[$_] = fmt-month($year, $_).lines for 1 .. 12;
|
||||
|
||||
loop ( my $month = 1; $month <= 12; $month += $months-per-col ) {
|
||||
while @month-strs[$month] {
|
||||
for ^$months-per-col {
|
||||
next unless @month-strs[$month+$_];
|
||||
$str ~= @month-strs[$month+$_].shift;
|
||||
$str ~= " " x 3;
|
||||
}
|
||||
$str ~= "\n";
|
||||
}
|
||||
$str ~= "\n";
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
sub fmt-month ($year, $month) {
|
||||
my $str = sprintf "%-20s\n", @month-names[$month-1];
|
||||
$str ~= @week-day-names~"\n";
|
||||
my $date = DateTime.new(year => $year, month => $month);
|
||||
my $week-day = $date.day-of-week;
|
||||
|
||||
$str ~= (" " xx $week-day-1).join(" ");
|
||||
|
||||
for $date.day .. $date.days-in-month -> $day {
|
||||
|
||||
$date = DateTime.new(year => $year, month => $month, day => $day);
|
||||
|
||||
$str ~= " " if 1 < $week-day < 8;
|
||||
if $week-day == 8 {
|
||||
$str ~= "\n";
|
||||
$week-day = 1;
|
||||
}
|
||||
$str ~= sprintf "%2d", $day;
|
||||
|
||||
$week-day++;
|
||||
}
|
||||
$str ~= " " if $week-day < 8;
|
||||
$str ~= (" " xx 8-$week-day).join(" ");
|
||||
$str ~= "\n";
|
||||
return $str;
|
||||
}
|
||||
118
Task/Calendar/Pike/calendar.pike
Normal file
118
Task/Calendar/Pike/calendar.pike
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
#!/bin/env pike
|
||||
|
||||
int main(int argc, array(string) argv)
|
||||
{
|
||||
object cal = Calendar;
|
||||
object year;
|
||||
string region = "us";
|
||||
|
||||
array date = argv[1..];
|
||||
if (sizeof(date) && objectp(Calendar[date[0]]) && Calendar[date[0]]->Day)
|
||||
{
|
||||
cal = Calendar[date[0]];
|
||||
date = Array.shift(date)[1];
|
||||
}
|
||||
|
||||
if (sizeof(date) && (int)date[0])
|
||||
{
|
||||
year = cal.Year((int)date[0]);
|
||||
date = Array.shift(date)[1];
|
||||
}
|
||||
|
||||
if (sizeof(date))
|
||||
region = date[0];
|
||||
|
||||
if (!year)
|
||||
year = cal.Year();
|
||||
|
||||
print_year(year, region);
|
||||
}
|
||||
|
||||
array make_month(object month, int field_width, void|string region)
|
||||
{
|
||||
array out =({});
|
||||
mapping holidays = ([]);
|
||||
object today = Calendar.Day();
|
||||
|
||||
if (region)
|
||||
holidays = Calendar.Events.find_region(region)->scan_events(month);
|
||||
|
||||
array weekday_names = sprintf("%*.*s", field_width, field_width, month->week()->days()->week_day_shortname()[*]);
|
||||
|
||||
out += ({ ({ month->month_name(), month->month_no(), month->year_name() }) });
|
||||
out += ({ weekday_names });
|
||||
out += showday(month->weeks()->days()[*][*], month, today, holidays, field_width);
|
||||
|
||||
out += ({ ({ " "*field_width })*sizeof(weekday_names) });
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
string print_month(object _month, void|int field_width, void|string region)
|
||||
{
|
||||
if (!field_width)
|
||||
field_width = 2;
|
||||
array month = make_month(_month, field_width, region);
|
||||
string out = "";
|
||||
|
||||
out += sprintf("%|*s\n", (field_width+1)*sizeof(month[1])-1, sprintf("%s", month[0][0]));
|
||||
out += sprintf((month[1..][*]*" ")*"\n");
|
||||
return out;
|
||||
}
|
||||
|
||||
string print_year(object year, void|string region)
|
||||
{
|
||||
array output = ({});
|
||||
int day_width = 2;
|
||||
int columns = Stdio.stdout.tcgetattr()->columns;
|
||||
int month_width = sizeof(make_month(year->month(), day_width)[1]) * (day_width+1) - 1;
|
||||
if (columns < month_width)
|
||||
columns = month_width;
|
||||
|
||||
// try to find an optimal good looking solution to spread the months
|
||||
// across the terminal width
|
||||
// for the common calendar of 12 months this is easy but we need to
|
||||
// account for caledars that have more than 12 months
|
||||
float max_width = (float)((columns+2)/(month_width+2));
|
||||
float max_height = ceil(year->number_of_months()/max_width);
|
||||
float w = max_width;
|
||||
|
||||
while(ceil(year->number_of_months()/(w-1)) == max_height)
|
||||
w--;
|
||||
|
||||
foreach(print_month(year->months()[*], day_width, region)/w;; array row)
|
||||
{
|
||||
array rows = row[*]/"\n";
|
||||
int l = max(@sizeof(rows[*]));
|
||||
foreach(rows; int i;)
|
||||
{
|
||||
// the last line of each month is an empty line.
|
||||
// repeat the line as many times as needed to make the months equally long
|
||||
rows[i]+=({ rows[i][-1] })*(l-sizeof(rows[i]));
|
||||
}
|
||||
rows = Array.transpose(rows);
|
||||
output += rows[*]*" ";
|
||||
}
|
||||
write("%*|s\n", sizeof(output[1]), year->format_nice());
|
||||
write(output * "\n");
|
||||
write("\n");
|
||||
}
|
||||
|
||||
string showday(object day, object month, object today, mapping holidays, int field_width)
|
||||
{
|
||||
string dayname;
|
||||
if (day->month() == month)
|
||||
{
|
||||
dayname = (string)day->month_day();
|
||||
dayname = " "*(sizeof((string)month->number_of_days())-sizeof(dayname))+dayname;
|
||||
if (day == today)
|
||||
dayname = sprintf("%|*.*s", field_width, field_width, dayname);
|
||||
else
|
||||
dayname = sprintf("%|*.*s", field_width, field_width, dayname);
|
||||
if (holidays[day])
|
||||
dayname = sprintf("%|s", dayname);
|
||||
}
|
||||
else
|
||||
dayname = " "*field_width;
|
||||
return dayname;
|
||||
}
|
||||
46
Task/Calendar/Run-BASIC/calendar.run
Normal file
46
Task/Calendar/Run-BASIC/calendar.run
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
input "Gimme a year";yr
|
||||
cls ' clear screen
|
||||
mths$ = "January,February,March,April,May,June,July,August,September,October,November,December"
|
||||
|
||||
html "<table border=0 cellpadding=0 cellspacing=5><tr>"
|
||||
html "<td colspan=4 align=center> <h3>Year:";yr;"</td></tr><tr>"
|
||||
|
||||
for mm = 1 to 12
|
||||
gosub [getMonthInfo]
|
||||
x = 0
|
||||
html "<td valign=top><TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0><TR>"
|
||||
html "<TD colspan=7 align=center bgcolor=wheat>"
|
||||
html " ";word$(mths$,mm,",")
|
||||
html "</TD><TR align=center bgcolor=wheat><TD>Sun<TD>Mon<TD>Tue<TD>Wed<TD>Thr<TD>Fri<TD>Sat<TR align=center>"
|
||||
|
||||
for i = 1 to mmDays + dow
|
||||
if i > dow then x = x + 1
|
||||
if x = 0 then html "<td></td>" else html "<TD>";x;"</TD>"
|
||||
if (i mod 7) = 0 then html "</TR><TR align=center>"
|
||||
next i
|
||||
html "</TR></table></td>"
|
||||
|
||||
if mm mod 4 = 0 then html "</tr><tr>" ' 4 months across
|
||||
next mm
|
||||
html "</table>"
|
||||
wait
|
||||
|
||||
[getMonthInfo]
|
||||
' ----------------------------------------
|
||||
' day of week when month begins.
|
||||
' days in a month
|
||||
' ----------------------------------------
|
||||
if yr < 100 then yr = val(date$("yy"))
|
||||
if mm < 1 or mm > 12 then mm = val(date$("mm"))
|
||||
dayOne$ = mm;"-01-";yr
|
||||
n = date$(dayOne$)
|
||||
dow = 1 + (n Mod 7) ' Day of Week month begins
|
||||
m1 = mm
|
||||
n1 = n + 27
|
||||
while m1 = mm
|
||||
n1 = n1 + 1
|
||||
n$ = date$(n1)
|
||||
m1 = val(left$(n$,2))
|
||||
wend
|
||||
mmDays = n1 - n ' Days in Month
|
||||
RETURN
|
||||
53
Task/Calendar/Seed7/calendar.seed7
Normal file
53
Task/Calendar/Seed7/calendar.seed7
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "time.s7i";
|
||||
|
||||
const func string: center (in string: stri, in integer: length) is
|
||||
return ("" lpad (length - length(stri)) div 2 <& stri) rpad length;
|
||||
|
||||
const proc: printCalendar (in integer: year, in integer: cols) is func
|
||||
local
|
||||
var time: date is time.value;
|
||||
var integer: dayOfWeek is 0;
|
||||
const array string: monthNames is [] ("January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December");
|
||||
var array array string: monthTable is 12 times 9 times "";
|
||||
var string: str is "";
|
||||
var integer: month is 0;
|
||||
var integer: position is 0;
|
||||
var integer: row is 0;
|
||||
var integer: column is 0;
|
||||
var integer: line is 0;
|
||||
begin
|
||||
for month range 1 to 12 do
|
||||
monthTable[month][1] := " " & center(monthNames[month], 20);
|
||||
monthTable[month][2] := " Mo Tu We Th Fr Sa Su";
|
||||
date := date(year, month, 1);
|
||||
dayOfWeek := dayOfWeek(date);
|
||||
for position range 1 to 43 do
|
||||
if position >= dayOfWeek and position - dayOfWeek < daysInMonth(date.year, date.month) then
|
||||
str := succ(position - dayOfWeek) lpad 3;
|
||||
else
|
||||
str := "" lpad 3;
|
||||
end if;
|
||||
monthTable[month][3 + pred(position) div 7] &:= str;
|
||||
end for;
|
||||
end for;
|
||||
writeln(center("[Snoopy Picture]", cols * 24 + 4));
|
||||
writeln(center(str(year),cols * 24 + 4));
|
||||
writeln;
|
||||
for row range 1 to succ(11 div cols) do
|
||||
for line range 1 to 9 do
|
||||
for column range 1 to cols do
|
||||
if pred(row) * cols + column <= 12 then
|
||||
write(" " & monthTable[pred(row) * cols + column][line]);
|
||||
end if;
|
||||
end for;
|
||||
writeln;
|
||||
end for;
|
||||
end for;
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
printCalendar(1969, 3);
|
||||
end func;
|
||||
3
Task/Calendar/UNIX-Shell/calendar.sh
Normal file
3
Task/Calendar/UNIX-Shell/calendar.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
echo "Snoopy goes here"
|
||||
cal 1969
|
||||
21
Task/Calendar/Vedit-macro-language/calendar-1.vedit
Normal file
21
Task/Calendar/Vedit-macro-language/calendar-1.vedit
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
Buf_Switch(Buf_Free)
|
||||
Config_Tab(5,30,55)
|
||||
#9 = 1 // first day of week: 0=Su, 1=Mo
|
||||
#3 = 3 // number of months per line
|
||||
#2 = 1969 // year
|
||||
#1 = 1 // starting month
|
||||
Repeat(12/#3) {
|
||||
Repeat (#3) {
|
||||
Buf_Switch(Buf_Free)
|
||||
Call_File(122, "calendar.vdm", "DRAW_CALENDAR")
|
||||
Reg_Copy_Block(10, 1, EOB_Pos, COLSET, 1, 21)
|
||||
Buf_Quit(OK)
|
||||
EOL Ins_Char(9)
|
||||
#5 = Cur_Pos
|
||||
Reg_Ins(10)
|
||||
Goto_Pos(#5)
|
||||
#1++
|
||||
}
|
||||
EOF
|
||||
Ins_Newline(2)
|
||||
}
|
||||
1
Task/Calendar/Vedit-macro-language/calendar-2.vedit
Normal file
1
Task/Calendar/Vedit-macro-language/calendar-2.vedit
Normal file
|
|
@ -0,0 +1 @@
|
|||
Config_Tab(22)
|
||||
59
Task/Calendar/XPL0/calendar.xpl0
Normal file
59
Task/Calendar/XPL0/calendar.xpl0
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
include c:\cxpl\codes; \intrinsic 'code' declarations
|
||||
|
||||
func WeekDay(Year, Month, Day); \Return day of week (0=Sun 1=Mon..6=Sat)
|
||||
int Year, Month, Day; \Works for years from 1583 onward
|
||||
[if Month<=2 then [Month:= Month+12; Year:= Year-1];
|
||||
return rem((Day-1 + (Month+1)*26/10 + Year + Year/4 + Year/100*6 + Year/400)/7);
|
||||
];
|
||||
|
||||
proc Space(N); \Display N space characters
|
||||
int N;
|
||||
while N do [ChOut(0, ^ ); N:= N-1];
|
||||
|
||||
proc Calendar(Year); \Display calendar for specified year
|
||||
int Year;
|
||||
int Month, Col, C, Line, MoName, Days, DayMax, Day(3);
|
||||
[MoName:= [
|
||||
" January ", " February", " March ", " April ", " May ", " June ",
|
||||
" July ", " August ", "September", " October", " November", " December"];
|
||||
Space(35); Text(0, "[Snoopy]"); CrLf(0);
|
||||
Space(37); IntOut(0, Year); CrLf(0);
|
||||
CrLf(0);
|
||||
for Month:= 1 to 12 do
|
||||
[for Col:= 0 to 3-1 do
|
||||
[Space(5); Text(0, MoName(Month+Col-1)); Space(7);
|
||||
if Col<2 then Space(8);
|
||||
];
|
||||
CrLf(0);
|
||||
for Col:= 0 to 3-1 do
|
||||
[Text(0, "Su Mo Tu We Th Fr Sa");
|
||||
if Col<2 then Space(9);
|
||||
];
|
||||
CrLf(0);
|
||||
for Col:= 0 to 3-1 do \day of first Sunday of month (can be negative)
|
||||
Day(Col):= 1 - WeekDay(Year, Month+Col, 1);
|
||||
for Line:= 0 to 6-1 do
|
||||
[for Col:= 0 to 3-1 do
|
||||
[Days:= [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
||||
DayMax:= Days(Month+Col);
|
||||
if Month+Col=2 & (rem(Year/4)=0 & rem(Year/100)#0 ! rem(Year/400)=0) then
|
||||
DayMax:= DayMax+1; \if February and leap year then add a day
|
||||
for C:= 0 to 7-1 do
|
||||
[if Day(Col)>=1 & Day(Col)<=DayMax then
|
||||
[IntOut(0, Day(Col));
|
||||
if Day(Col)<10 then Space(1); \left justify
|
||||
]
|
||||
else Space(2); \suppress out of range days
|
||||
Space(1);
|
||||
Day(Col):= Day(Col)+1;
|
||||
];
|
||||
if Col<2 then Space(8);
|
||||
];
|
||||
CrLf(0);
|
||||
];
|
||||
CrLf(0);
|
||||
Month:= Month+2; \2+1 months per Col(umn)
|
||||
];
|
||||
];
|
||||
|
||||
Calendar(1969)
|
||||
Loading…
Add table
Add a link
Reference in a new issue