[631] in Zephyr_Bugs

home help back first fref pref prev next nref lref last post

added functions in zwgc

daemon@ATHENA.MIT.EDU (Derrick J Brashear)
Wed Jul 12 20:45:46 1995

Date: Wed, 12 Jul 1995 20:45:41 -0400 (EDT)
From: Derrick J Brashear <shadow@DEMENTIA.ORG>
To: bug-zephyr@MIT.EDU

The following patch adds 2 functions to zwgc: add and stylestrip
add is obvious. here's a small blurb on stylestrip:
     stylestrip(expr)
       Removes all @ commands from expr, including font, italic, beep, etc.

Enjoy.

-D

*** lexer.c.orig	Wed Jul 12 19:48:33 1995
--- lexer.c	Wed Jul 12 20:29:33 1995
***************
*** 164,171 ****
  		   { "upcase", UPCASE },
  		   { "while", WHILE },
  		   { "verbatim", VERBATIM },
! 		   { "zvar", ZVAR } };
! 
  /*
   * lex_open - this routine [re]initializes the lexer & prepares it to lex
   *            a file.  Resets current line # to 1.
--- 164,172 ----
  		   { "upcase", UPCASE },
  		   { "while", WHILE },
  		   { "verbatim", VERBATIM },
! 		   { "zvar", ZVAR },
!                    { "stylestrip", STYLESTRIP },
!                    { "add", ADD } };
  /*
   * lex_open - this routine [re]initializes the lexer & prepares it to lex
   *            a file.  Resets current line # to 1.
*** eval.c.orig	Wed Jul 12 19:44:13 1995
--- eval.c	Wed Jul 12 20:26:57 1995
***************
*** 146,151 ****
--- 146,152 ----
        case DOWNCASE_OPCODE:
        case ZVAR_OPCODE:
        case GET_OPCODE:
+       case STYLESTRIP_OPCODE:
  	first = eval_expr(expr->d.nodes.first);
  
  	switch (opcode) {
***************
*** 164,169 ****
--- 165,173 ----
  	  case VERBATIM_OPCODE:
  	    return(verbatim(first,0));
  
+           case STYLESTRIP_OPCODE:
+             return(stylestrip(first));
+ 
  	  case GETENV_OPCODE:
  	    result = getenv(first);
  	    if (!result)
***************
*** 203,208 ****
--- 207,213 ----
        case NEQ_OPCODE:
        case REGEQ_OPCODE:
        case REGNEQ_OPCODE:
+       case ADD_OPCODE:
  	first = eval_expr(expr->d.nodes.first);
  	second = eval_expr(expr->d.nodes.second);
  
***************
*** 236,241 ****
--- 241,257 ----
  	  case REGNEQ_OPCODE:
  	    bool_result = !ed_regexp_match_p(first, second);
  	    break;
+ 
+           case ADD_OPCODE:
+             {
+                 char buf[16]; /* big enuf for int */
+ 
+                 sprintf(buf, "%d", atoi(first) + atoi(second));
+                 result = string_Copy(buf);
+                 free(first);
+                 free(second);
+                 return(result);
+             }
  	}
  	free(first);
  	free(second);
*** node.h.orig	Wed Jul 12 19:50:08 1995
--- node.h	Wed Jul 12 20:23:44 1995
***************
*** 52,91 ****
  #define  RBREAK_OPCODE                  23
  #define  LSPAN_OPCODE                   24
  #define  RSPAN_OPCODE                   25
  
! #define  LAST_EXPR_OPCODE               25
  
! #define  NOOP_OPCODE                    26
! #define  SET_OPCODE                     27
! #define  FIELDS_OPCODE                  28
  
! #define  PRINT_OPCODE                   29
! #define  CLEARBUF_OPCODE                30
  
! #define  APPENDPORT_OPCODE              31
! #define  EXECPORT_OPCODE                32
! #define  INPUTPORT_OPCODE               33
! #define  OUTPUTPORT_OPCODE              34
! #define  PUT_OPCODE                     35
! #define  CLOSEINPUT_OPCODE              36
! #define  CLOSEOUTPUT_OPCODE             37
! #define  CLOSEPORT_OPCODE               38
  
! #define  EXEC_OPCODE                    39
  
! #define  IF_STMT_OPCODE                 40
! #define  CASE_OPCODE                    41
! #define  WHILE_OPCODE                   42
! #define  BREAK_OPCODE                   43
! #define  EXIT_OPCODE                    44
  
! #define  IF_OPCODE                      45
! #define  ELSEIF_OPCODE                  46
! #define  ELSE_OPCODE                    47
! #define  MATCHLIST_OPCODE               48
! #define  DEFAULT_OPCODE                 49
  
! #define  NUMBER_OF_OPCODES              50
  
  typedef struct _Node {
      int opcode;                              /* Read-only */
--- 52,93 ----
  #define  RBREAK_OPCODE                  23
  #define  LSPAN_OPCODE                   24
  #define  RSPAN_OPCODE                   25
+ #define  STYLESTRIP_OPCODE              26
+ #define  ADD_OPCODE                     27
  
! #define  LAST_EXPR_OPCODE               27
  
! #define  NOOP_OPCODE                    28
! #define  SET_OPCODE                     29
! #define  FIELDS_OPCODE                  30
  
! #define  PRINT_OPCODE                   31
! #define  CLEARBUF_OPCODE                32
  
! #define  APPENDPORT_OPCODE              33
! #define  EXECPORT_OPCODE                34
! #define  INPUTPORT_OPCODE               35
! #define  OUTPUTPORT_OPCODE              36
! #define  PUT_OPCODE                     37
! #define  CLOSEINPUT_OPCODE              38
! #define  CLOSEOUTPUT_OPCODE             39
! #define  CLOSEPORT_OPCODE               40
  
! #define  EXEC_OPCODE                    41
  
! #define  IF_STMT_OPCODE                 42
! #define  CASE_OPCODE                    43
! #define  WHILE_OPCODE                   44
! #define  BREAK_OPCODE                   45
! #define  EXIT_OPCODE                    46
  
! #define  IF_OPCODE                      47
! #define  ELSEIF_OPCODE                  48
! #define  ELSE_OPCODE                    49
! #define  MATCHLIST_OPCODE               50
! #define  DEFAULT_OPCODE                 51
  
! #define  NUMBER_OF_OPCODES              52
  
  typedef struct _Node {
      int opcode;                              /* Read-only */
*** node.c.orig	Wed Jul 12 19:49:34 1995
--- node.c	Wed Jul 12 19:49:54 1995
***************
*** 280,285 ****
--- 280,286 ----
      "rbreak(%1, %2)",
      "lspan(%1, %2)",
      "rspan(%1, %2)",
+     "stylestrip(%1)",
  
      "noop\n",
      "set %1 = %2\n",
*** exec.c.orig	Wed Jul 12 19:45:53 1995
--- exec.c	Wed Jul 12 20:24:44 1995
***************
*** 380,385 ****
--- 380,387 ----
      { exec_noop },                         /* rbreak */
      { exec_noop },                         /* lspan */
      { exec_noop },                         /* rspan */
+     { exec_noop },                         /* stylestrip */
+     { exec_noop },                         /* add */
  
      { exec_noop },                          /* noop statement */
      { exec_set },
*** formatter.c.orig	Wed Jul 12 19:47:20 1995
--- formatter.c	Wed Jul 12 19:48:19 1995
***************
*** 374,379 ****
--- 374,425 ----
     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;
  {
*** text_operations.h.orig	Wed Jul 12 19:56:10 1995
--- text_operations.h	Wed Jul 12 19:56:30 1995
***************
*** 29,33 ****
--- 29,34 ----
  extern string rany();
  extern string rbreak();
  extern string rspan();
+ extern string stylestrip();
  
  #endif
*** parser.y.orig	Wed Jul 12 19:54:49 1995
--- parser.y	Wed Jul 12 20:30:51 1995
***************
*** 58,64 ****
  %token  ELSE ELSEIF ENDCASE ENDIF ENDWHILE EXEC EXECPORT EXIT
  %token  FIELDS GET GETENV IF INPUTPORT LANY LBREAK LSPAN
  %token  MATCH NOOP NOT OUTPUTPORT PRINT PROTECT VERBATIM PUT RANY RBREAK
! %token  RSPAN SET SUBSTITUTE THEN UPCASE WHILE ZVAR
  
  %type <node> expr varname string
  %type <node> exprlist comma_exprlist varnamelist
--- 58,64 ----
  %token  ELSE ELSEIF ENDCASE ENDIF ENDWHILE EXEC EXECPORT EXIT
  %token  FIELDS GET GETENV IF INPUTPORT LANY LBREAK LSPAN
  %token  MATCH NOOP NOT OUTPUTPORT PRINT PROTECT VERBATIM PUT RANY RBREAK
! %token  RSPAN SET SUBSTITUTE THEN UPCASE WHILE ZVAR STYLESTRIP ADD
  
  %type <node> expr varname string
  %type <node> exprlist comma_exprlist varnamelist
***************
*** 114,119 ****
--- 114,121 ----
          { $$ = node_create_binary(REGEQ_OPCODE, $1, $3); }
       | expr REGNEQ expr
          { $$ = node_create_binary(REGNEQ_OPCODE, $1, $3); }
+      | expr ADD expr
+         { $$ = node_create_binary(ADD_OPCODE, $1, $3); }
  
       | BUFFER '(' ')'
          { $$ = node_create_noary(BUFFER_OPCODE); }
***************
*** 134,139 ****
--- 136,143 ----
          { $$ = node_create_unary(ZVAR_OPCODE, $3); }
       | GET '(' expr ')'
          { $$ = node_create_unary(GET_OPCODE, $3); }
+      | STYLESTRIP '(' expr ')'
+         { $$ = node_create_unary(STYLESTRIP_OPCODE, $3); }
  
       | LANY '(' expr ',' expr ')'
          { $$ = node_create_binary(LANY_OPCODE, $3, $5 ); }


home help back first fref pref prev next nref lref last post