E char *FDECL(ucase, (char *));
E char *FDECL(upstart, (char *));
E char *FDECL(mungspaces, (char *));
+E char *FDECL(strip_newline, (char *));
E char *FDECL(eos, (char *));
E boolean FDECL(str_end_is, (const char *, const char *));
E char *FDECL(strkitten, (char *, CHAR_P));
const char *filename;
int src;
{
- char buf[4 * BUFSZ], *p;
+ char buf[4 * BUFSZ];
FILE *fp;
boolean rv = TRUE; /* assume successful parse */
OR: Forbid multiline stuff for alternate config sources.
*/
#endif
- if ((p = index(buf, '\n')) != 0) {
- /* 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)) {
+ if (!parse_config_line(fp, strip_newline(buf), src)) {
static const char badoptionline[] = "Bad option line: \"%s\"";
/* truncate buffer if it's long; this is actually conservative */
unsigned oid; /* book identifier */
{
dlb *fp;
- char *endp;
char line[BUFSZ], lastline[BUFSZ];
int scope = 0;
*line = *lastline = '\0';
while (dlb_fgets(line, sizeof line, fp) != 0) {
linect++;
- if ((endp = index(line, '\n')) != 0)
- *endp = 0;
+ (void) strip_newline(line);
switch (line[0]) {
case '%':
if (!strncmpi(&line[1], "section ", sizeof("section ") - 1)) {
char *st = &line[9]; /* 9 from "%section " */
scope = SECTIONSCOPE;
- if (!strcmpi(st, tribsection))
- matchedsection = TRUE;
- else
- matchedsection = FALSE;
+ matchedsection = !strcmpi(st, tribsection) ? TRUE : FALSE;
} else if (!strncmpi(&line[1], "title ", sizeof("title ") - 1)) {
char *st = &line[7]; /* 7 from "%title " */
char *p1, *p2;
char * ucase (char *)
char * upstart (char *)
char * mungspaces (char *)
+ char * strip_newline (char *)
char * eos (char *)
boolean str_end_is (const char *, const char *)
char * strkitten (char *,char)
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') */
char *
eos(s)
} else if (!skipping_entry) {
if (!(ep = index(buf, '\n')))
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 */
chk_skip = (*buf == '~') ? 1 : 0;
if (pmatch(&buf[chk_skip], dbase_str)
for (i = 0; i < entry_count; i++) {
if (!dlb_fgets(buf, BUFSZ, fp))
goto bad_data_file;
- if ((ep = index(buf, '\n')) != 0)
- *ep = 0;
+ (void) strip_newline(buf);
if (index(buf + 1, '\t') != 0)
(void) tabexpand(buf + 1);
putstr(datawin, 0, buf + 1);
{
dlb *fp;
char bufr[BUFSZ];
- register char *buf = &bufr[6], *ep, ctrl, meta;
+ register char *buf = &bufr[6], ctrl, meta;
fp = dlb_fopen(CMDHELPFILE, "r");
if (!fp) {
if ((ctrl && *buf == '^' && *(buf + 1) == ctrl)
|| (meta && *buf == 'M' && *(buf + 1) == '-'
&& *(buf + 2) == meta) || *buf == q) {
- ep = index(buf, '\n');
- if (ep)
- *ep = 0;
+ (void) strip_newline(buf);
if (ctrl && buf[2] == '\t') {
buf = bufr + 1;
(void) strncpy(buf, "^? ", 8);
doextversion()
{
dlb *f;
- char *cr, *pd, buf[BUFSZ];
+ char *pd, buf[BUFSZ];
winid win = create_nhwindow(NHW_TEXT);
boolean rtadded = FALSE;
boolean prolog = TRUE; /* to skip indented program name */
while (dlb_fgets(buf, BUFSZ, f)) {
- if ((cr = index(buf, '\n')) != 0)
- *cr = 0;
- if ((cr = index(buf, '\r')) != 0)
- *cr = 0;
+ (void) strip_newline(buf);
if (index(buf, '\t') != 0)
(void) tabexpand(buf);