Commit Graph

71 Commits

Author SHA1 Message Date
David E. O'Brien
65e9eb0701 Look in getlocalbase() for the calendar-data package data
Fix d20d655018 where getlocalbase()
wasn't used to fill out the printf(3) format of _PATH_INCLUDE_LOCAL.

Differential Revision:	https://reviews.freebsd.org/D38975
Reviewed by:	imp
2023-03-12 18:40:07 -07:00
Stefan Eßer
35b8fd0b69 usr.bin/calendar: do not treat // in text as comment
The C++-style comment marker "//" has been added with the rewrite of
the preprocessor features. Since this character sequence occurs	in
ULRS, the reminder of the URL was considered a comment and stripped
from the calendar line.

Change parsing of "//" to only start a comment at the begin of a line
or when	preceeded by a white-space character.

PR:		256455
Reported by:	Philippe Michel (philippe.michel7 at free.fr)
MFC after:	3 days
2021-06-07 15:55:23 +02:00
Stefan Eßer
e163cae76e Make calendarhome buffer static
the value may be used in error messages after leaving this function.
2020-12-30 13:44:33 +01:00
Stefan Eßer
6f139d796f Use getlocalbase() instead of compiled in LOCALBASE to locate calendars 2020-12-12 11:51:29 +00:00
Stefan Eßer
0357fa2632 Restrict locale settings to the file they occur in
This prevents LANG= in an included file from affecting the interpretation
of month and day names in the including file.

Make the internal pre-processor accept white space between the "#" at
the start of the line and the keyword for better compatibility with cpp.

Add support for the cpp keywords #warning and #error.

MFC after:	3 days
2020-11-05 08:58:21 +00:00
Stefan Eßer
2ceb17a8be Add regression tests for conditions and comments
Fix one case where #else was not corerctly processed and simplify the
conditions logic.

Fix parsing of day and month names in the locale specified in the calendar
file. The previous version would expect those names to match the locale of
the user.

Mention that comments are now correctly processed and that // is supported
in addition to /* ... */.

MFC after:	3 days
2020-11-04 22:29:01 +00:00
Stefan Eßer
f1560bd080 Consistently print calendar dates in the locale of the user
Calendar files that specify LANG=... to specify their character encoding did
also set the date format defined for that locale, resulting in output like:

Nov  4 	Gabriel Faure dies from pneumonia in Paris, France, 1924
 4 nov. 	N'oubliez pas les Charles !

After this commit the output is always printed in a consistent format
according to the user's current locale, e.g.:

Nov  4 	Gabriel Faure dies from pneumonia in Paris, France, 1924
Nov  4 	N'oubliez pas les Charles !

I'll open a review asking for opinions whether this format change should
be merged to -STABLE.

Relnotes:	yes
2020-11-03 12:15:08 +00:00
Stefan Eßer
cc9fbfafbe Check that #ifdef, #ifndef, and #undef are used with a single name
This restores the parameter validation that has been peformed by cpp
for defining and testing of names used in conditions.

MFC after:	3 days
2020-11-03 11:37:19 +00:00
Stefan Eßer
ab34af0746 Fix psoition reporting for calendar data file in system directory
MFC after:	3 days
2020-11-01 20:38:35 +00:00
Stefan Eßer
8e8c5da47f Improve calendar file parsing and consistency tests
Add line number information to more warning and error messages.
Detect #else and #endif without corresponing #ifdef/#ifndef as error.
Detect missing #endif at end of file and print warning but continue.

Support for #undef has been added to reverse the effect of a prior #define.
It is no error if the argument value has not been defined before.

These changes may cause error aborts on malformed input files (e.g. with
spurious #else or #endif), but no such errors exist in the calendar files
in the FreeBSD base system and the calendar-data port and all tests pass.

More tests will be added in a follow-up commit to detect regressions that
might affect the newly added features.

This commit ends a series of updates that enhance the pre-processor and
make it behave much more like prior versions of the calendar progarm that
called cpp to pre-process the data files.

MFC after:	3 days
Relnotes:	yes
2020-10-31 15:11:24 +00:00
Stefan Eßer
6688708624 Add file names and line numbers to debug messages
MFC after:	3 days
2020-10-31 13:55:10 +00:00
Stefan Eßer
1462201cd5 Add file names and line numbers to calendar format error messages
Without file name and line number it is very cumbersum to identify the
locations of errors in calendar files.

MFC after:	3 days
2020-10-31 13:32:08 +00:00
Stefan Eßer
6bdb89a898 Fix length calculation in memmove
MFC after:	3 days
2020-10-30 14:32:13 +00:00
Stefan Eßer
0f352f4e25 Re-implement comment parsing missing in the internal pre-processor
The internal pre-processor ignored lines that did not parse a calendar
entries, but did not support multi-line comments in the way the external
cpp did.

The calendar files distributed with the base system (now in a port) do
use comments, though.

Implement comment processing for single-line (//) and multi-line comments
(/* */) with same semantics as in a standard C pre-processor.

All tests pass with this version, but there are no tests that specifically
verify comment processing.

Reported by:	jhs@berklix.com (Julian H. Stacey)
MFC after:	3 days
2020-10-30 10:44:46 +00:00
Stefan Eßer
ac04cf18bb Simplify test for closing delimiter of #include argument (no functional
change).

While here: Fix invalid parameters of a commented-out debug printf() found
when testing with this code enabled.

MFC after:	3 days
2020-10-29 08:31:47 +00:00
Stefan Eßer
19b5c30754 Add support for nested conditionals
The previous behavior was to support nested #ifdef and #ifndef, but to
return to unconditional parsing after the next #endif, independently of
the number of previously parsed conditions.

E.g. after "#ifdef A / #ifdef B / #endif" the following lines were
unconditially parsed again, independently of A and/or B being defined.

The new behavior is to count the level of false conditions and to only
restart parsing of calendar entries when the corresponding number of
#endif tokens have been seen.

In addition to the above, an #else directive has been added, to toggle
between parsing and ignoring of the following lines.

No validation of the correct use of the condition directives is made.
#endif without prior #define or #ifndef is ignored and #else toggles
between parsing and skipping of entries.

The MFC period has been set to 1 month to allow for a review of the
changes and for a discussion, whether these modifications should not
be merged at all.

No correct input file is parsed differently than before, but if calendar
data files are published that use these new features, those data files
will not parse correctly on prior versions of this program.

MFC after:	1 month
2020-10-28 14:48:58 +00:00
Stefan Eßer
e0e29f9425 Fix off-by-one error in processing of #ifdef lines
The convention in this program is to parse the line immediately starting
after the token (e.g. #defineA and #ifdefA define respectively look-up "A"),
and this commit restores this behavior instead of skipping an assumed
white-space character following #ifdef.

Reported by:	kevans
MFC after:	3 days
2020-10-28 13:30:24 +00:00
Stefan Eßer
2939897921 Fix parsing of #ifdef in calendar files
There was code to process an #ifndef tokens, but none for #ifdef.
The #ifdef token was mentioned as unsupported in the BUGS section,
but no reason was given and I do not see why it should stay omitted.

Misleading information in The BUGS section of the man-page regarding
the maximum number of #define and #include statements supported has
been removed. These limits might have applied to a prior version of
this program, but do not seem to apply to the current implementation.

I have not tried to test for the existence of the limits, but the
include file processing just recursively calls the parser (without
counting the recursion depth) and the stringlist functions do not
impose a limit on the number of entries.

Reported by:	jhs@berklix.com
MFC after:	3 days
2020-10-28 13:06:39 +00:00
Warner Losh
d20d655018 calendar: remove all datafiles except freebsd one
Move all the data files for the calendar(1) program, except
calendar.freebsd to the calendar-data package. When a file
can't be found, and /usr/local/share/calendar doesn't exist
provide a helpful hint to install this package.

Reviewed by: se@
Differential Revision:  https://reviews.freebsd.org/D26926
2020-10-26 03:26:18 +00:00
Stefan Eßer
34b38e1245 Add search of LOCALBASE/share/calendar for calendars supplied by a port.
Calendar files in LOCALBASE override similarily named ones in the base
system. This could easily be changed if the base system calendars should
have precedence, but it could lead to a violation of POLA since then the
port's files were ignored unless those in base have been deleted.

There was no definition of _PATH_LOCALBASE in paths.h, but verbatim uses
of /usr/local existed for _PATH_DEFPATH. Use _PATH_LOCALBASE here to ease
a consistent modification of this prefix.

Reviewed by:	imp, pfg
Differential Revision:	https://reviews.freebsd.org/D26882
2020-10-23 09:22:23 +00:00
Conrad Meyer
fd1efedc79 Add extremely useful calendar(1) application to FreeBSD
It does extremely useful things like execute sendmail and spew dubiously
accurate factoids.

From the feedback, it seems like it is an essential utility in a modern unix
and not at all a useless bikeshed.  How do those Linux people live without it?
Reverts r358561.
2020-03-03 00:20:08 +00:00
Conrad Meyer
3c565de33f Fix typo in r278616
FreeBSD isn't an encyclopedia.
2020-03-02 23:37:47 +00:00
Gleb Smirnoff
e67975d331 Fix 'calendar -a' in several ways.
o Do not run any iconv() processing in -a. The locale of root user is not
  what is desired by most of the users who receive their calendar mail.
  Just assume that users store their calendars in a format that is readable
  to them. This fixes regression from r344340.
o fork() and setusercontext(LOGIN_SETALL) for every user. This makes LANG
  set inside a calendar file mostly excessive, as we will pick up user's
  login class LANG.
o This also executes complex function cal() that parses user owned files
  with appropriate user privileges.
  Previously it was run with privileges dropped only temporary for execution
  of cal(), and fully dropped only before invoking sendmail (see r22473).

Reviewed by:	bapt (older version of patch)
2019-09-10 04:21:48 +00:00
Baptiste Daroussin
adedf5ee31 calendar: use iconv to respect the output encoding
calendar(1) can have input in various encoding, specifying
LANG=<locale_name> to enable calendar(1) to determine which one to use.

The problem is the content of the calendar itself is exposed as is making it
unreadable in many cases. For example french calendar which is encoded
ISO8859-1 is rendered badly in a fr_FR.UTF-8 environment.

Using iconv allows to solve this issue.
This will also allow to keep only 1 encoding in base for those files without
breaking user existing setup

Reported by:	many
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D19221
2019-02-20 06:40:52 +00:00
Eitan Adler
a92970d8ae calendar: add missing header file
time.h is required for strftime and struct tm

Reviewed by:	edje
2017-12-23 21:04:32 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Marcelo Araujo
09a47cc7e6 Use nitems() from sys/param.h.
Sponsored by:	gandi.net (BSD Day Taiwan)
MFC after: 	2 weeks.
2016-07-30 06:35:49 +00:00
Baptiste Daroussin
a43d43d574 Remove usage of _WITH_GETLINE from usr.bin 2016-07-30 01:07:47 +00:00
Pedro F. Giffuni
80c7cc1c8f Cleanup unnecessary semicolons from utilities we all love. 2016-04-15 22:31:22 +00:00
Baptiste Daroussin
cbc9c8d8d3 Fix trimming spaces writing at index -1 if an empty string is passed
Submitted by:	Gennady Proskurin <gprspb@mail.ru>
2015-07-15 18:49:15 +00:00
Eitan Adler
e4c6d6e268 calendar: remove useless check
lineline checked for 0 in the while loop condition.  There is no need to
	check for it additionally in the body.

CID:	1288959
MFC After:	1 week
2015-04-19 04:27:50 +00:00
Baptiste Daroussin
e061f95e7b Rework calendar(1) parser
Support includes surrounded by '"' or '<' '>'
Print warnings about bad syntax
Correctly navigate through include directories to find calendar files
Correctly support multiple includes

Tested by:	gjb
MFC after:	1 week
2015-03-04 20:04:23 +00:00
Diane Bruce
5d32a8713c - calendar uses cpp internally, this diff removes this usage and
substitutes a limited subset cpp processor internally.

PR:		src/178463
Approved by:	re (gjb)
2013-09-19 20:17:50 +00:00
Greg Lehey
90c72ba909 Handle some expression regressions.
Explicitly use GNU cpp for preprocessing.
Remove explicit debugging code.
Change some variable names to be less confusing.
Improve some comments.
Improve indentation.

PR:		162211
		168785
MFC after:	2 weeks
2013-06-12 07:52:49 +00:00
Ed Schouten
bf70becee6 More -Wmissing-variable-declarations fixes.
In addition to adding `static' where possible:

- bin/date: Move `retval' into extern.h to make it visible to date.c.
- bin/ed: Move globally used variables into ed.h.
- sbin/camcontrol: Move `verbose' into camcontrol.h and fix shadow warnings.
- usr.bin/calendar: Remove unneeded variables.
- usr.bin/chat: Make `line' local instead of global.
- usr.bin/elfdump: Comment out unneeded function.
- usr.bin/rlogin: Use _Noreturn instead of __dead2.
- usr.bin/tset: Pull `Ospeed' into extern.h.
- usr.sbin/mfiutil: Put global variables in mfiutil.h.
- usr.sbin/pkg: Remove unused `os_corres'.
- usr.sbin/quotaon, usr.sbin/repquota: Remove unused `qfname'.
2012-10-19 14:49:42 +00:00
Greg Lehey
415f031163 Tidy up command line processing:
- Add ? option to optstring.
  - Sort options alphabetically.
  - Vertical space.

Tidy up usage() function.

Bring man page in sync with source.

Ensure that debug code is only executed with the -d option.

Submitted by: Christiane Yeardley
2011-11-09 01:40:46 +00:00
Jaakko Heinonen
0aa7541b66 Pass correct size to write(2).
PR:		bin/155915
Submitted by:	John Levine
MFC after:	2 weeks
2011-06-06 13:50:29 +00:00
Edwin Groothuis
7e63c265da Fix memory-leak at the processing of multiple calendars.
Found with:   Coverity Prevent(tm)
CID:          7085
2010-06-05 11:12:35 +00:00
Edwin Groothuis
78c6c39d48 Properly check the return value of chdir, even if it is a "this
should not happen" case.

Found with:   Coverity Prevent(tm)
CID:          4932
2010-06-05 11:06:56 +00:00
Andrey A. Chernov
e86a8937dc While I am here, add more missing (unsigned char) casts to ctype() macros 2010-05-06 16:54:46 +00:00
Andrey A. Chernov
b277fb56f9 Fix recent space skipping:
1) add missing (unsigned char) cast to ctype() macro
2) fix off-by-one error causing last letter always doubled
2010-05-06 16:37:50 +00:00
Edwin Groothuis
bb06482c77 On request of joel@:
- Remove the 3rd clause of the UC Berkeley copyrighted files.
- For the files added copyrighted by me, move the "All rights
  reserved" to the next line.
2010-03-30 06:42:01 +00:00
Edwin Groothuis
2b84020d5c Long awaited update to the calendar system:
- Repeating events which span multiple years (because of -A, -B or
  just the three days before the end of the year).

- Support for lunar events (full moon, new moon) and solar events
  (equinox and solstice, chinese new year). Because of this, the
  options -U (UTC offset) and -l (longitude) are available to
  compensate if reality doesn't match the calculated values.

MFC after:	1 month
2010-03-29 06:49:20 +00:00
Ralf S. Engelschall
a752c19301 rewind(3) is already declared to return 'void', so no need for an explicit cast 2009-12-17 08:42:44 +00:00
Edwin Groothuis
0d724b8765 Move functions which are only locally used into their C files and
make them static.

usage() in calendar.c
event_*() in io.c

PR:		bin/118644
Approved by:	bde@ (mentor)
2008-08-05 08:16:37 +00:00
Edwin Groothuis
35304a1641 style(9)ify usr.bin/calendar
PR:		bin/118644
Approved by:	bde@ (mentor)
MFC after:	1 week
2008-08-05 08:11:54 +00:00
Greg Lehey
8ddfe1c32c style(9) 2007-12-30 22:04:04 +00:00
Greg Lehey
cd59b2cd17 If we can't open a calendar file, don't guess why. Check the error
return and print a useful message.

Prior to this commit, access problems could give rise to messages that
the file didn't exist.
2007-12-30 22:02:50 +00:00
Kevin Lo
0f10497bce Never use getenv("HOME") without checking for NULL and non-zero
Obtained from: OpenBSD
2007-10-30 03:44:10 +00:00