From owner-svn-src-head@freebsd.org Sat Oct 31 13:32:10 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 315E044C17E; Sat, 31 Oct 2020 13:32:10 +0000 (UTC) (envelope-from se@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CNg894mssz4SpQ; Sat, 31 Oct 2020 13:32:09 +0000 (UTC) (envelope-from se@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 257A9846D; Sat, 31 Oct 2020 13:32:09 +0000 (UTC) (envelope-from se@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09VDW83Q026692; Sat, 31 Oct 2020 13:32:09 GMT (envelope-from se@FreeBSD.org) Received: (from se@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09VDW8HQ026691; Sat, 31 Oct 2020 13:32:08 GMT (envelope-from se@FreeBSD.org) Message-Id: <202010311332.09VDW8HQ026691@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: se set sender to se@FreeBSD.org using -f From: =?UTF-8?Q?Stefan_E=c3=9fer?= Date: Sat, 31 Oct 2020 13:32:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367203 - head/usr.bin/calendar X-SVN-Group: head X-SVN-Commit-Author: se X-SVN-Commit-Paths: head/usr.bin/calendar X-SVN-Commit-Revision: 367203 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Oct 2020 13:32:10 -0000 Author: se Date: Sat Oct 31 13:32:08 2020 New Revision: 367203 URL: https://svnweb.freebsd.org/changeset/base/367203 Log: 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 Modified: head/usr.bin/calendar/io.c head/usr.bin/calendar/parsedata.c Modified: head/usr.bin/calendar/io.c ============================================================================== --- head/usr.bin/calendar/io.c Sat Oct 31 12:39:22 2020 (r367202) +++ head/usr.bin/calendar/io.c Sat Oct 31 13:32:08 2020 (r367203) @@ -75,6 +75,10 @@ static const char *calendarHomes[] = {".calendar", _PA static const char *calendarNoMail = "nomail";/* don't sent mail if file exist */ static char path[MAXPATHLEN]; +static const char *cal_home; +static const char *cal_dir; +static const char *cal_file; +static int cal_line; struct fixs neaster, npaskha, ncny, nfullmoon, nnewmoon; struct fixs nmarequinox, nsepequinox, njunsolstice, ndecsolstice; @@ -118,7 +122,7 @@ cal_fopen(const char *file) } if (chdir(home) != 0) { - warnx("Cannot enter home directory"); + warnx("Cannot enter home directory \"%s\"", home); return (NULL); } @@ -126,8 +130,12 @@ cal_fopen(const char *file) if (chdir(calendarHomes[i]) != 0) continue; - if ((fp = fopen(file, "r")) != NULL) + if ((fp = fopen(file, "r")) != NULL) { + cal_home = home; + cal_dir = calendarHomes[i]; + cal_file = file; return (fp); + } } warnx("can't open calendar file \"%s\"", file); @@ -139,10 +147,19 @@ cal_fopen(const char *file) return (NULL); } +#define WARN0(format) \ + warnx(format " in %s/%s/%s line %d", cal_home, cal_dir, cal_file, cal_line) +#define WARN1(format, arg1) \ + warnx(format " in %s/%s/%s line %d", arg1, cal_home, cal_dir, cal_file, cal_line) + static int token(char *line, FILE *out, int *skip) { char *walk, c, a; + const char *this_cal_home; + const char *this_cal_dir; + const char *this_cal_file; + int this_cal_line; if (strncmp(line, "endif", 5) == 0) { if (*skip > 0) @@ -155,7 +172,7 @@ token(char *line, FILE *out, int *skip) trimlr(&walk); if (*walk == '\0') { - warnx("Expecting arguments after #ifdef"); + WARN0("Expecting arguments after #ifdef"); return (T_ERR); } @@ -170,7 +187,7 @@ token(char *line, FILE *out, int *skip) trimlr(&walk); if (*walk == '\0') { - warnx("Expecting arguments after #ifndef"); + WARN0("Expecting arguments after #ifndef"); return (T_ERR); } @@ -185,7 +202,7 @@ token(char *line, FILE *out, int *skip) trimlr(&walk); if (*walk != '\0') { - warnx("Expecting no arguments after #else"); + WARN0("Expecting no arguments after #else"); return (T_ERR); } @@ -206,12 +223,12 @@ token(char *line, FILE *out, int *skip) trimlr(&walk); if (*walk == '\0') { - warnx("Expecting arguments after #include"); + WARN0("Expecting arguments after #include"); return (T_ERR); } if (*walk != '<' && *walk != '\"') { - warnx("Excecting '<' or '\"' after #include"); + WARN0("Excecting '<' or '\"' after #include"); return (T_ERR); } @@ -220,13 +237,21 @@ token(char *line, FILE *out, int *skip) c = walk[strlen(walk) - 1]; if (a != c) { - warnx("Unterminated include expecting '%c'", a); + WARN1("Unterminated include expecting '%c'", a); return (T_ERR); } walk[strlen(walk) - 1] = '\0'; + this_cal_home = cal_home; + this_cal_dir = cal_dir; + this_cal_file = cal_file; + this_cal_line = cal_line; if (cal_parse(cal_fopen(walk), out)) return (T_ERR); + cal_home = this_cal_home; + cal_dir = this_cal_dir; + cal_file = this_cal_file; + cal_line = this_cal_line; return (T_OK); } @@ -238,7 +263,7 @@ token(char *line, FILE *out, int *skip) trimlr(&walk); if (*walk == '\0') { - warnx("Expecting arguments after #define"); + WARN0("Expecting arguments after #define"); return (T_ERR); } @@ -290,7 +315,9 @@ cal_parse(FILE *in, FILE *out) if (in == NULL) return (1); + cal_line = 0; while ((linelen = getline(&line, &linecap, in)) > 0) { + cal_line++; buf = line; if (buf[linelen - 1] == '\n') buf[--linelen] = '\0'; Modified: head/usr.bin/calendar/parsedata.c ============================================================================== --- head/usr.bin/calendar/parsedata.c Sat Oct 31 12:39:22 2020 (r367202) +++ head/usr.bin/calendar/parsedata.c Sat Oct 31 13:32:08 2020 (r367203) @@ -312,10 +312,7 @@ allfine: } -void -remember(int *rememberindex, int *y, int *m, int *d, char **ed, int yy, int mm, - int dd, char *extra); -void +static void remember(int *rememberindex, int *y, int *m, int *d, char **ed, int yy, int mm, int dd, char *extra) {