From e264b650c4f4a003953706b4a61e66e335338a31 Mon Sep 17 00:00:00 2001 From: Michael Hampton Date: Sun, 1 Dec 2002 11:02:57 +0000 Subject: [PATCH] * New experimental message formatter - try it, you'll like it! --- citadel/ChangeLog | 4 +- citadel/citadel_ipc.c | 3 +- citadel/commands.c | 154 +++++++++++++++++++++++++++++++++++++++++- citadel/configure.ac | 38 ++++++++++- citadel/messages.c | 2 +- 5 files changed, 195 insertions(+), 6 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 83333b5f9..6184af632 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $Log$ + Revision 601.80 2002/12/01 11:02:57 error + * New experimental message formatter - try it, you'll like it! + Revision 601.79 2002/12/01 04:48:24 ajc * The code to check for sending invitations needs to happen *after* save @@ -4267,4 +4270,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/citadel_ipc.c b/citadel/citadel_ipc.c index 3e9da9289..825917ef2 100644 --- a/citadel/citadel_ipc.c +++ b/citadel/citadel_ipc.c @@ -566,12 +566,13 @@ int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime, } remove_token(bbb, 0, '\n'); } while ((bbb[0] != 0) && (bbb[0] != '\n')); + /*ooga*/ remove_token(bbb, 0, '\n'); } } if (strlen(bbb)) { - /* Strip trailing whitespace */ + /* FIXME: Strip trailing whitespace */ bbb = (char *)realloc(bbb, (size_t)(strlen(bbb) + 1)); } else { bbb = (char *)realloc(bbb, 1); diff --git a/citadel/commands.c b/citadel/commands.c index cfb6b9761..fc6322170 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -1344,8 +1344,17 @@ FMTA: while ((eof_flag == 0) && (strlen(buffer) < 126)) { if (a <= 0) goto FMTEND; - if (((a == 13) || (a == 10)) && (old != 13) && (old != 10)) - a = 32; + /* + if (a == 10) scr_printf(""); + if (a == 13) scr_printf(""); + */ + + if ((a == 13) || (a == 10)) { + if ((old != 13) && (old != 10)) + a = 32; + if ((old == 13) || (old == 10)) + a = 0; + } if (((old == 13) || (old == 10)) && (isspace(real))) { if (fpout) { fprintf(fpout, "\n"); @@ -1424,6 +1433,147 @@ FMTEND: } +/* + * fmout() - Citadel text formatter and paginator + */ +int fmout2( + int width, /* screen width to use */ + FILE *fpin, /* file to read from, or NULL to format given text */ + char *text, /* text to be formatted (when fpin is NULL */ + FILE *fpout, /* file to write to, or NULL to write to screen */ + char pagin, /* nonzero if we should use the paginator */ + int height, /* screen height to use */ + int starting_lp,/* starting value for lines_printed, -1 for global */ + int subst) /* nonzero if we should use hypertext mode */ +{ + char *buffer = NULL; /* The current message */ + char *word = NULL; /* What we are about to actually print */ + char *e; /* Pointer to position in text */ + char old = 0; /* The previous character */ + int column = 0; /* Current column */ + size_t i; /* Generic counter */ + + word = (char *)calloc(1, width); + if (!word) { + err_printf("Can't alloc memory to print message: %s!\n", + strerror(errno)); + logoff(NULL, 3); + } + + if (fpin) { + size_t got = 0; + + rewind(fpin); + i = ftell(fpin); + buffer = (char *)calloc(1, i + 1); + if (!buffer) { + err_printf("Can't alloc memory for message: %s!\n", + strerror(errno)); + logoff(NULL, 3); + } + while (got < i) { + size_t g = 0; + + g = fread(buffer + got, i - got, 1, fpin); + if (g < 1) { /* error reading or eof */ + i = got; + break; + } + got += g; + } + buffer[i] = 0; + } else { + buffer = text; + } + + if (starting_lp >= 0) + lines_printed = starting_lp; + + e = buffer; + + while (*e) { + /* First, are we looking at a newline? */ + if (*e == '\n') { + e++; + if (*e == ' ') { + if (fpout) { + fprintf(fpout, "\n"); + } else { + scr_printf("\n"); + ++lines_printed; + lines_printed = checkpagin(lines_printed, pagin, height); + } + column = 0; + } else if (old != ' ') { + if (fpout) { + fprintf(fpout, " "); + } else { + scr_printf(" "); + } + column++; + } + } + old = *e; + /* Or are we looking at a space? */ + if (*e == ' ') { + e++; + if (column >= width - 1) { + if (fpout) { + fprintf(fpout, "\n"); + } else { + scr_printf("\n"); + ++lines_printed; + lines_printed = checkpagin(lines_printed, pagin, height); + } + column = 0; + } else if (!(column == 0 && old == ' ')) { + if (fpout) { + fprintf(fpout, " "); + } else { + scr_printf(" "); + } + column++; + } + continue; + } + + /* Read a word and decide what to do with it */ + i = 0; + while (*e) { + if (isspace(e[i])) + break; + i++; + } + if (i >= width) /* Break up really long words */ + i = width - 1; + strncpy(word, e, i); + word[i] = 0; + if (column + i >= width) { + if (fpout) { + fprintf(fpout, "\n"); + } else { + scr_printf("\n"); + ++lines_printed; + lines_printed = checkpagin(lines_printed, pagin, height); + } + column = 0; + } + if (fpout) { + fprintf(fpout, "%s", word); + } else { + scr_printf("%s", word); + } + column += i; + e += i; + } + + free(word); + if (fpin) + free(buffer); + return 0; +} + + /* * support ANSI color if defined */ diff --git a/citadel/configure.ac b/citadel/configure.ac index f8dd6eb38..1250be7ee 100644 --- a/citadel/configure.ac +++ b/citadel/configure.ac @@ -1,7 +1,7 @@ dnl Process this file with autoconf to produce a configure script. dnl $Id$ AC_PREREQ(2.52) -AC_INIT([Citadel/UX], [5.91], [http://uncensored.citadel.org/]) +AC_INIT([Citadel/UX], [6.02], [http://uncensored.citadel.org/]) AC_REVISION([$Revision$]) AC_CONFIG_SRCDIR([citserver.c]) AC_PREFIX_DEFAULT(/usr/local/citadel) @@ -511,6 +511,42 @@ fi AC_REPLACE_FUNCS(snprintf getutline) +# AC_CACHE_CHECK([the weather], ac_cv_weather, [ +# sleep 1 +# echo $ECHO_N "opening your window... $ECHO_C" >&6 +# sleep 2 +# month=`date | cut -f 2 -d ' '` +# case $month in +# Dec | Jan | Feb) +# ac_cv_weather="it's cold!" +# ;; +# Mar | Apr) +# ac_cv_weather="it's wet!" +# ;; +# Jul | Aug) +# ac_cv_weather="it's hot!" +# ;; +# Oct | Nov) +# ac_cv_weather="it's cool" +# ;; +# May | Jun | Sep | *) +# ac_cv_weather="it's fine" +# ;; +# esac +# ]) + +AC_CACHE_CHECK([under the bed], ac_cv_under_the_bed, [ + number=`date | cut -c 19` + case $number in + 7) + ac_cv_under_the_bed="lunatics and monsters found" + ;; + *) + ac_cv_under_the_bed="dust bunnies found" + ;; + esac + ]) + dnl Done! Now write the Makefile and sysdep.h AC_SUBST(AUTH) AC_SUBST(CHKPWD) diff --git a/citadel/messages.c b/citadel/messages.c index f89c55aca..71b5bbc8d 100644 --- a/citadel/messages.c +++ b/citadel/messages.c @@ -581,7 +581,7 @@ int read_message(CtdlIPC *ipc, * Here we go */ if (format_type == 0) { - fr = fmout(screenwidth, NULL, message->text, dest, + fr = fmout2(screenwidth, NULL, message->text, dest, ((pagin == 1) ? 1 : 0), screenheight, (-1), 1); } else { char *msgtext; -- 2.39.2