Start allowing spaces in month and day names (convert to _ on -p output)

This commit is contained in:
Dianne Skoll
2022-01-30 12:00:57 -05:00
parent 654fd78ee7
commit 3aee12073e
4 changed files with 30 additions and 2 deletions

View File

@@ -232,12 +232,17 @@ sub parse_input
chomp($line);
($Month, $Year, $Numdays, $Firstwkday, $Mondayfirst) = split(' ', $line);
$Month =~ s/_/ /g;
# Day names
$line = <STDIN>;
return 0 unless $line;
chomp($line);
@Daynames = split(' ', $line);
for (my $i=0; $i<7; $i++) {
$Daynames[$i] =~ s/_/ /g;
}
# Prevmon prevlen
$line = <STDIN>;
return 0 unless $line;

View File

@@ -120,6 +120,7 @@ sub read_one_month
# Month Year Days FirstWkday MondayFirst
if ($line =~ /^(\S+) (\d+) (\d+) (\d+) (\d+)/) {
$self->{monthname} = $1;
$self->{monthname} =~ s/_/ /g;
$self->{year} = $2;
$self->{daysinmonth} = $3;
$self->{firstwkday} = $4;
@@ -132,7 +133,7 @@ sub read_one_month
$line = $in->getline();
chomp($line);
if ($line =~ /^\S+ \S+ \S+ \S+ \S+ \S+ \S+$/) {
@{$self->{daynames}} = split(/ /, $line);
@{$self->{daynames}} = map { s/_/ /g; $_; } (split(/ /, $line));
} else {
return (undef, "Cannot interpret line: $line");
}

View File

@@ -964,9 +964,14 @@ proc FillCalWindow {} {
gets $file line
regexp {^([^ ]*) ([0-9][0-9][0-9][0-9]) ([0-9][0-9]?) ([0-9]) ([0-9])} $line dummy monthName year daysInMonth firstWkday mondayFirst
set monthName [regsub -all {_} $monthName " "]
# Get the day names
gets $file line
set DayNames $line
set DayNames {}
foreach day $line {
set day [regsub -all {_} $day " "];
lappend DayNames $day
}
ConfigureCalWindow $monthName $year $firstWkday $daysInMonth

View File

@@ -383,6 +383,7 @@ void DoPsCal(void)
int firstcol;
DynamicBuffer buf;
CalEntry *c, *d, *p;
char *s;
/* Read the month and year name, followed by # days in month and 1st day of
month */
@@ -391,12 +392,28 @@ void DoPsCal(void)
sscanf(DBufValue(&buf), "%s %s %d %d %d", month, year, &days, &wkday,
&MondayFirst);
/* Replace underscores in month name with spaces */
s = month;
while(*s) {
if (*s == '_') *s = ' ';
s++;
}
/* Get day names */
DBufGets(&buf, stdin);
sscanf(DBufValue(&buf), "%32s %32s %32s %32s %32s %32s %32s",
DayName[0], DayName[1], DayName[2], DayName[3],
DayName[4], DayName[5], DayName[6]);
/* Replace underscores in day names with spaces */
for (i=0; i<7; i++) {
s = DayName[i];
while(*s) {
if (*s == '_') *s = ' ';
s++;
}
}
/* We write the prolog here because it's only at this point that
MondayFirst is set correctly. */
if (validfile == 1) {