diff options
author | Greg Hudson <ghudson@mit.edu> | 1997-09-14 18:12:16 +0000 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 1997-09-14 18:12:16 +0000 |
commit | ce6018836c422c86a729ba39fe5433ec11b87b02 (patch) | |
tree | cc2e6601489384fcf41e0565e8906822897b46c8 /zwgc/formatter.c | |
parent | ac16f380e349fa39ec7e26bccb5456cb300006a5 (diff) |
Pull in sources from zephyr locker. See /mit/zephyr/repository for
detailed change information.
Diffstat (limited to 'zwgc/formatter.c')
-rw-r--r-- | zwgc/formatter.c | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/zwgc/formatter.c b/zwgc/formatter.c index 03ee3d0..c74bc7d 100644 --- a/zwgc/formatter.c +++ b/zwgc/formatter.c @@ -12,16 +12,15 @@ * "mit-copyright.h". */ +#include <sysdep.h> + #if (!defined(lint) && !defined(SABER)) -static char rcsid_formatter_c[] = "$Id$"; +static const char rcsid_formatter_c[] = "$Id$"; #endif #include <zephyr/mit-copyright.h> #include <zephyr/zephyr.h> -#include <stdio.h> -#include <ctype.h> -#include <string.h> #include "new_memory.h" #include "char_stack.h" #include "string_dictionary.h" @@ -375,6 +374,51 @@ string protect(str) return(temp); } +/* str points to a string. return value is another string + which is the original with all styles removed. */ +string stylestrip(str) + string str; +{ + int templen = 0, otherchar; + char *temp = (char *) malloc(string_Length(str) + 1); + char_stack chs; + string ostr = str; + + chs = char_stack_create(); + + while (*str) { + if (*str == '@') { + int len = env_length(str + 1); + if (len != -1) { + otherchar = 0; + if ((len == 4 && !strncasecmp(str + 1, "font", 4)) + || (len == 5 && !strncasecmp(str + 1, "color", 5))) + otherchar = 0x80; + otherchar |= otherside(str[len + 1]); + char_stack_push(chs, otherchar); + str += len + 2; + continue; + } + } + if (!char_stack_empty(chs) && *str == (char_stack_top(chs) & 0x7f)) { + char_stack_pop(chs); + str++; + continue; + } + if (!char_stack_empty(chs) && (char_stack_top(chs) & 0x80)) + str++; + else + temp[templen++] = *str++; + } + temp[templen] = 0; + + while (!char_stack_empty(chs)) + char_stack_pop(chs); + free(ostr); + + return(temp); +} + void free_desc(desc) desctype *desc; { |