"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "petidomo-4.0b6/librfc822/address.y" of archive petidomo-4.0b6.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /*
    2    $Source: /e/ossp/cvs/ossp-pkg/petidomo/librfc822/address.y,v $
    3    $Revision: 1.4 $
    4 
    5    Copyright (C) 2000 by CyberSolutions GmbH, Germany.
    6 
    7    This file is part of OpenPetidomo.
    8 
    9    OpenPetidomo is free software; you can redistribute it and/or modify
   10    it under the terms of the GNU General Public License as published by
   11    the Free Software Foundation; either version 2, or (at your option)
   12    any later version.
   13 
   14    OpenPetidomo is distributed in the hope that it will be useful, but
   15    WITHOUT ANY WARRANTY; without even the implied warranty of
   16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   17    General Public License for more details.
   18 */
   19 
   20 %{
   21     /* Definitions we need in the parser. */
   22 
   23 #define YYSTYPE char *
   24 
   25 #include <string.h>
   26 #include <errno.h>
   27 #ifdef DEBUG_DMALLOC
   28 #  include <dmalloc.h>
   29 #endif
   30 
   31 #include "../libmpools/mpools.h"
   32 #define yytext rfc822_text
   33 #define yyley rfc822_lex
   34 
   35     /* Variables in our lexer. */
   36 
   37 extern char *   rfc822_address_buffer;
   38 extern int      rfc822_address_buffer_pos;
   39 extern char *   yytext;
   40 
   41     /* Our static/global variables. */
   42 
   43 static int     no_memory_flag;
   44 static char *  poolname,
   45             *  result_hostpart,
   46             *  result_localpart,
   47 	    *  result_address;
   48 
   49     /* Prototypes for internal functions. */
   50 
   51 static int     yyparse(void);
   52 static int     yyerror(char *);
   53 static char *  pool_strdup(char *);
   54 static char *  pool_strjoin(char *, char *);
   55 int            yylex(void);
   56 
   57     /* These macros call the routines we define later in a fail safe
   58        way. */
   59 
   60 #define str_dup(target,a) { \
   61     target = (YYSTYPE) pool_strdup((char *) a); \
   62     if (target == NULL) { \
   63         no_memory_flag++; \
   64         YYABORT; \
   65     } \
   66 }
   67 
   68 #define str_join(target,a,b) { \
   69     target = (YYSTYPE) pool_strjoin((char *) a, (char *) b); \
   70     if (target == NULL) { \
   71         no_memory_flag++; \
   72         YYABORT; \
   73     } \
   74 }
   75 
   76 %}
   77 %token TOK_ATOM TOK_ILLEGAL
   78 %left ':'
   79 %left '@'
   80 %%
   81 
   82 address:   local			{
   83 					  result_localpart = (char *)$1;
   84 					  str_dup($$,$1);
   85 					  result_address = (char *)$$;
   86 					}
   87 	 | local at domain		{
   88 					  result_localpart = (char *)$1;
   89 					  result_hostpart = (char *)$3;
   90 					  str_join($$,$1,$2); str_join($$,$$,$3);
   91 					  result_address = (char *)$$;
   92 					}
   93 	 | at domain colon sourceroutings local {
   94 					  result_hostpart = (char *)$2;
   95 					  str_join($$,$4,$5);
   96 					  result_localpart = (char *)$$;
   97 					  str_join($$,$3,$$); str_join($$,$2,$$);
   98 					  str_join($$,$1,$$);
   99 					  result_address = (char *)$$;
  100 					}
  101 	 | at domain colon sourceroutings local at domain {
  102 					  result_hostpart = (char *)$2;
  103 					  str_join($$,$4,$5); str_join($$,$$,$6);
  104 					  str_join($$,$$,$7);
  105 					  result_localpart = (char *)$$;
  106 					  str_join($$,$3,$$); str_join($$,$2,$$);
  107 					  str_join($$,$1,$$);
  108 					  result_address = (char *)$$;
  109 					}
  110 ;
  111 
  112 sourceroutings:	  /* empty */		{ $$ = (YYSTYPE) NULL; }
  113 		| at domain colon sourceroutings {
  114 					  str_join($$,$1,$2); str_join($$,$$,$3);
  115 					  str_join($$,$$,$4);
  116 					}
  117 
  118 local:   atom				{ $$ = $1; }
  119        | atom local			{ str_join($$,$1,$2); }
  120        | dot				{ $$ = $1; }
  121        | dot local			{ str_join($$,$1,$2); }
  122 ;
  123 
  124 domain:   atom				{ $$ = $1; }
  125 	| atom dot domain		{ str_join($$,$2,$3); str_join($$,$1,$$); }
  126 ;
  127 
  128 atom:	  TOK_ATOM			{ str_dup($$,yytext); }
  129 dot:	  '.'				{ $$ = (YYSTYPE) "."; }
  130 at:	  '@'				{ $$ = (YYSTYPE) "@"; }
  131 colon:	  ':'				{ $$ = (YYSTYPE) ":"; }
  132 
  133 %%
  134 /***** internal routines *****/
  135 
  136 static int
  137 yyerror(char * string)
  138 {
  139     return 0;
  140 }
  141 
  142 /* Do the same as strdup(3) but use the memory pool to allocate the
  143    memory, so that we don't lose memory. */
  144 
  145 static char *
  146 pool_strdup(char * string)
  147 {
  148     char *   p;
  149 
  150     if (string == NULL)
  151       return NULL;
  152 
  153     p = mp_malloc(poolname, strlen(string) + 1);
  154     if (p == NULL)
  155       return NULL;
  156 
  157     strcpy(p, string);
  158     return p;
  159 }
  160 
  161 /* Allocate a new buffer (using the memory pool) and join the strings
  162    'a' and 'b' into it. */
  163 
  164 static char *
  165 pool_strjoin(char * a, char * b)
  166 {
  167     char *   p;
  168     int      length = 0;
  169 
  170     if (a != NULL)
  171       length += strlen(a);
  172     if (b != NULL)
  173       length += strlen(b);
  174     if (length == 0)
  175       return NULL;
  176 
  177     p = mp_malloc(poolname, length + 2);
  178     if (p == NULL)
  179       return NULL;
  180     else
  181       *p = '\0';
  182 
  183     if (a)
  184       strcpy(p, a);
  185     if (b)
  186       strcpy(&(p[strlen(p)]), b);
  187 
  188     return p;
  189 }
  190 
  191 /****** public routines ******/
  192 
  193 #include "parse_address.c"