newline handling
In light of the recent 'bad options' feedback issue where \r messed up message display, try to to make newline handling be more consistent. I'm sure there are lots of places that still handle \n manually, but it's a start.
This commit is contained in:
@@ -835,6 +835,7 @@ E char *FDECL(lcase, (char *));
|
|||||||
E char *FDECL(ucase, (char *));
|
E char *FDECL(ucase, (char *));
|
||||||
E char *FDECL(upstart, (char *));
|
E char *FDECL(upstart, (char *));
|
||||||
E char *FDECL(mungspaces, (char *));
|
E char *FDECL(mungspaces, (char *));
|
||||||
|
E char *FDECL(strip_newline, (char *));
|
||||||
E char *FDECL(eos, (char *));
|
E char *FDECL(eos, (char *));
|
||||||
E boolean FDECL(str_end_is, (const char *, const char *));
|
E boolean FDECL(str_end_is, (const char *, const char *));
|
||||||
E char *FDECL(strkitten, (char *, CHAR_P));
|
E char *FDECL(strkitten, (char *, CHAR_P));
|
||||||
|
|||||||
+4
-15
@@ -2563,7 +2563,7 @@ read_config_file(filename, src)
|
|||||||
const char *filename;
|
const char *filename;
|
||||||
int src;
|
int src;
|
||||||
{
|
{
|
||||||
char buf[4 * BUFSZ], *p;
|
char buf[4 * BUFSZ];
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
boolean rv = TRUE; /* assume successful parse */
|
boolean rv = TRUE; /* assume successful parse */
|
||||||
|
|
||||||
@@ -2581,13 +2581,7 @@ line at this level.
|
|||||||
OR: Forbid multiline stuff for alternate config sources.
|
OR: Forbid multiline stuff for alternate config sources.
|
||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
if ((p = index(buf, '\n')) != 0) {
|
if (!parse_config_line(fp, strip_newline(buf), src)) {
|
||||||
/* in case file has CR+LF format on non-CR+LF platform */
|
|
||||||
if (p > buf && *(p - 1) == '\r')
|
|
||||||
--p;
|
|
||||||
*p = '\0'; /* strip newline */
|
|
||||||
}
|
|
||||||
if (!parse_config_line(fp, buf, src)) {
|
|
||||||
static const char badoptionline[] = "Bad option line: \"%s\"";
|
static const char badoptionline[] = "Bad option line: \"%s\"";
|
||||||
|
|
||||||
/* truncate buffer if it's long; this is actually conservative */
|
/* truncate buffer if it's long; this is actually conservative */
|
||||||
@@ -3505,7 +3499,6 @@ char *nowin_buf;
|
|||||||
unsigned oid; /* book identifier */
|
unsigned oid; /* book identifier */
|
||||||
{
|
{
|
||||||
dlb *fp;
|
dlb *fp;
|
||||||
char *endp;
|
|
||||||
char line[BUFSZ], lastline[BUFSZ];
|
char line[BUFSZ], lastline[BUFSZ];
|
||||||
|
|
||||||
int scope = 0;
|
int scope = 0;
|
||||||
@@ -3556,18 +3549,14 @@ unsigned oid; /* book identifier */
|
|||||||
*line = *lastline = '\0';
|
*line = *lastline = '\0';
|
||||||
while (dlb_fgets(line, sizeof line, fp) != 0) {
|
while (dlb_fgets(line, sizeof line, fp) != 0) {
|
||||||
linect++;
|
linect++;
|
||||||
if ((endp = index(line, '\n')) != 0)
|
(void) strip_newline(line);
|
||||||
*endp = 0;
|
|
||||||
switch (line[0]) {
|
switch (line[0]) {
|
||||||
case '%':
|
case '%':
|
||||||
if (!strncmpi(&line[1], "section ", sizeof("section ") - 1)) {
|
if (!strncmpi(&line[1], "section ", sizeof("section ") - 1)) {
|
||||||
char *st = &line[9]; /* 9 from "%section " */
|
char *st = &line[9]; /* 9 from "%section " */
|
||||||
|
|
||||||
scope = SECTIONSCOPE;
|
scope = SECTIONSCOPE;
|
||||||
if (!strcmpi(st, tribsection))
|
matchedsection = !strcmpi(st, tribsection) ? TRUE : FALSE;
|
||||||
matchedsection = TRUE;
|
|
||||||
else
|
|
||||||
matchedsection = FALSE;
|
|
||||||
} else if (!strncmpi(&line[1], "title ", sizeof("title ") - 1)) {
|
} else if (!strncmpi(&line[1], "title ", sizeof("title ") - 1)) {
|
||||||
char *st = &line[7]; /* 7 from "%title " */
|
char *st = &line[7]; /* 7 from "%title " */
|
||||||
char *p1, *p2;
|
char *p1, *p2;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
char * ucase (char *)
|
char * ucase (char *)
|
||||||
char * upstart (char *)
|
char * upstart (char *)
|
||||||
char * mungspaces (char *)
|
char * mungspaces (char *)
|
||||||
|
char * strip_newline (char *)
|
||||||
char * eos (char *)
|
char * eos (char *)
|
||||||
boolean str_end_is (const char *, const char *)
|
boolean str_end_is (const char *, const char *)
|
||||||
char * strkitten (char *,char)
|
char * strkitten (char *,char)
|
||||||
@@ -158,6 +159,21 @@ char *bp;
|
|||||||
return bp;
|
return bp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* remove \n from end of line; remove \r too if one is there */
|
||||||
|
char *
|
||||||
|
strip_newline(str)
|
||||||
|
char *str;
|
||||||
|
{
|
||||||
|
char *p = index(str, '\n');
|
||||||
|
|
||||||
|
if (p) {
|
||||||
|
if (p > str && *(p - 1) == '\r')
|
||||||
|
--p;
|
||||||
|
*p = '\0';
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
/* return the end of a string (pointing at '\0') */
|
/* return the end of a string (pointing at '\0') */
|
||||||
char *
|
char *
|
||||||
eos(s)
|
eos(s)
|
||||||
|
|||||||
+4
-7
@@ -476,7 +476,7 @@ boolean user_typed_name, without_asking;
|
|||||||
} else if (!skipping_entry) {
|
} else if (!skipping_entry) {
|
||||||
if (!(ep = index(buf, '\n')))
|
if (!(ep = index(buf, '\n')))
|
||||||
goto bad_data_file;
|
goto bad_data_file;
|
||||||
*ep = 0;
|
(void) strip_newline((ep > buf) ? ep - 1 : ep);
|
||||||
/* if we match a key that begins with "~", skip this entry */
|
/* if we match a key that begins with "~", skip this entry */
|
||||||
chk_skip = (*buf == '~') ? 1 : 0;
|
chk_skip = (*buf == '~') ? 1 : 0;
|
||||||
if (pmatch(&buf[chk_skip], dbase_str)
|
if (pmatch(&buf[chk_skip], dbase_str)
|
||||||
@@ -524,8 +524,7 @@ boolean user_typed_name, without_asking;
|
|||||||
for (i = 0; i < entry_count; i++) {
|
for (i = 0; i < entry_count; i++) {
|
||||||
if (!dlb_fgets(buf, BUFSZ, fp))
|
if (!dlb_fgets(buf, BUFSZ, fp))
|
||||||
goto bad_data_file;
|
goto bad_data_file;
|
||||||
if ((ep = index(buf, '\n')) != 0)
|
(void) strip_newline(buf);
|
||||||
*ep = 0;
|
|
||||||
if (index(buf + 1, '\t') != 0)
|
if (index(buf + 1, '\t') != 0)
|
||||||
(void) tabexpand(buf + 1);
|
(void) tabexpand(buf + 1);
|
||||||
putstr(datawin, 0, buf + 1);
|
putstr(datawin, 0, buf + 1);
|
||||||
@@ -1126,7 +1125,7 @@ char *cbuf;
|
|||||||
{
|
{
|
||||||
dlb *fp;
|
dlb *fp;
|
||||||
char bufr[BUFSZ];
|
char bufr[BUFSZ];
|
||||||
register char *buf = &bufr[6], *ep, ctrl, meta;
|
register char *buf = &bufr[6], ctrl, meta;
|
||||||
|
|
||||||
fp = dlb_fopen(CMDHELPFILE, "r");
|
fp = dlb_fopen(CMDHELPFILE, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
@@ -1140,9 +1139,7 @@ char *cbuf;
|
|||||||
if ((ctrl && *buf == '^' && *(buf + 1) == ctrl)
|
if ((ctrl && *buf == '^' && *(buf + 1) == ctrl)
|
||||||
|| (meta && *buf == 'M' && *(buf + 1) == '-'
|
|| (meta && *buf == 'M' && *(buf + 1) == '-'
|
||||||
&& *(buf + 2) == meta) || *buf == q) {
|
&& *(buf + 2) == meta) || *buf == q) {
|
||||||
ep = index(buf, '\n');
|
(void) strip_newline(buf);
|
||||||
if (ep)
|
|
||||||
*ep = 0;
|
|
||||||
if (ctrl && buf[2] == '\t') {
|
if (ctrl && buf[2] == '\t') {
|
||||||
buf = bufr + 1;
|
buf = bufr + 1;
|
||||||
(void) strncpy(buf, "^? ", 8);
|
(void) strncpy(buf, "^? ", 8);
|
||||||
|
|||||||
+2
-5
@@ -57,7 +57,7 @@ int
|
|||||||
doextversion()
|
doextversion()
|
||||||
{
|
{
|
||||||
dlb *f;
|
dlb *f;
|
||||||
char *cr, *pd, buf[BUFSZ];
|
char *pd, buf[BUFSZ];
|
||||||
winid win = create_nhwindow(NHW_TEXT);
|
winid win = create_nhwindow(NHW_TEXT);
|
||||||
boolean rtadded = FALSE;
|
boolean rtadded = FALSE;
|
||||||
|
|
||||||
@@ -94,10 +94,7 @@ doextversion()
|
|||||||
boolean prolog = TRUE; /* to skip indented program name */
|
boolean prolog = TRUE; /* to skip indented program name */
|
||||||
|
|
||||||
while (dlb_fgets(buf, BUFSZ, f)) {
|
while (dlb_fgets(buf, BUFSZ, f)) {
|
||||||
if ((cr = index(buf, '\n')) != 0)
|
(void) strip_newline(buf);
|
||||||
*cr = 0;
|
|
||||||
if ((cr = index(buf, '\r')) != 0)
|
|
||||||
*cr = 0;
|
|
||||||
if (index(buf, '\t') != 0)
|
if (index(buf, '\t') != 0)
|
||||||
(void) tabexpand(buf);
|
(void) tabexpand(buf);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user