/* * Author: Pierangelo Masarati * E-mail: masarati@aero.polimi.it * Date: August, 1999 * Version: 1.0 * Description: * LDAP client to build a BibTeX database out of * a Directory Server, with migration tools. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by Pierangelo Masarati. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ %{ #define YYSTYPE char * #define YYDEBUG 1 #include #include #include #include #include #include "l2b_utils.h" #include "bibtex2ldif.h" extern int yylex(void); char *utf8; char *authors; char *tmp; %} %token E_START %token E_LCUBR %token E_RCUBR %token E_SEP %token E_SEP_AUTHOR %right E_ASSIGN %token E_ENTRY_TYPE %token E_ATTR_NAME %token E_ENTRY_TAG %token E_TEXT_STRING %token E_ATTR_URL %token E_ATTR_AUTHOR %token E_TEXT_URL %token E_ATTR_UNKNOWN %token E_TEXT_A %token E_COMMENT %token E_STRING %% input: /* */ | input entry ; entry: E_START E_COMMENT E_LCUBR comment_text E_RCUBR { fprintf(stderr, "comment: %s\n", $4); free($4); } | E_START E_STRING E_LCUBR E_ENTRY_TAG E_ASSIGN value_list E_RCUBR { fprintf(fd_out, dn_form, $4); fprintf(fd_out, "objectClass: top\n"); fprintf(fd_out, "objectClass: %s\n", bibtex_oc); fprintf(fd_out, "objectClass: bibtexStringEntry\n"); fprintf(fd_out, "cn: %s\n", $4); fprintf(fd_out, "bibtexString: %s\n\n", $6); free($4); free($6); } | E_START E_ENTRY_TYPE E_LCUBR E_ENTRY_TAG E_SEP attr_list E_RCUBR { fprintf(fd_out, dn_form, $4); fprintf(fd_out, "objectClass: top\n"); fprintf(fd_out, "objectClass: %s\n", bibtex_oc); fprintf(fd_out, "objectClass: bibtex%s\n", strcapitalizefirst($2)); fprintf(fd_out, "cn: %s\n", $4); fprintf(fd_out, "%s\n\n", $6); free($2); free($4); free($6); } | E_START E_ENTRY_TYPE E_LCUBR E_ENTRY_TAG E_SEP attr_list E_SEP E_RCUBR { fprintf(fd_out, dn_form, $4); fprintf(fd_out, "objectClass: top\n"); fprintf(fd_out, "objectClass: %s\n", bibtex_oc); fprintf(fd_out, "objectClass: bibtex%s\n", strcapitalizefirst($2)); fprintf(fd_out, "cn: %s\n", $4); fprintf(fd_out, "%s\n\n", $6); free($2); free($4); free($6); } ; e_type: E_ENTRY_TYPE { $$ = $1; } ; attr_list: attr { $$ = $1; } | attr_list E_SEP attr { if ($3 == NULL) { $$ = $1; } else if ($1 == NULL) { $$ = $3; } else { $$ = malloc(strlen($1)+strlen($3)+1+1); sprintf($$, "%s\n%s", $1, $3); free($1); free($3); } } ; attr: E_ATTR_URL E_ASSIGN url_list { $$ = $3; } | E_ATTR_NAME E_ASSIGN value_list { if ( strchr( $3, '{' ) == NULL ) { $$ = malloc(6+strlen($1)+strlen($3)+2+1); sprintf($$, "bibtex%s: %s", strcapitalizefirst($1), $3); } else { utf8 = tex2utf8( $3 ); $$ = malloc(6+strlen($1)+11+2+strlen($3)+1+6+strlen($1)+2+strlen(utf8)+1); sprintf($$, "bibtex%s;lang-x-tex: %s\nbibtex%s: %s", strcapitalizefirst($1), $3, strcapitalizefirst($1), utf8 ); free( utf8 ); } free($1); free($3); } | E_ATTR_AUTHOR E_ASSIGN value_list { $$ = malloc( 14+strlen($3)+1 ); sprintf($$, "bibtexAuthor: %s", $3); free($3); } | E_ATTR_AUTHOR E_ASSIGN author_list { $$ = malloc( 25+strlen($3)+2+1+strlen(authors) ); sprintf($$, "bibtexAuthor;lang-x-tex: %s\n%s", $3, authors); free(authors); free($3); } | E_ATTR_UNKNOWN E_ASSIGN value_list { fprintf( stderr, "unknown attribute type: %s\n", $1 ); $$ = NULL; free($3); } ; comment_text: E_TEXT_A { $$ = $1; } ; tag: E_ENTRY_TAG { $$ = $1; } ; value_list: value { $$ = $1; } | value_list value { $$ = malloc(strlen($1)+strlen($2)+1+1); sprintf($$, "%s %s", $1, $2); free($1); free($2); } ; value: E_TEXT_A { $$ = $1; } | E_TEXT_STRING { $$ = $1; } ; url_list: url { $$ = $1 } | url_list url { $$ = malloc(strlen($1)+strlen($2)+2); sprintf($$, "%s\n%s", $1, $2); free($1); free($2); } ; url: E_TEXT_URL { $$ = malloc(12+strlen($1)+1); sprintf($$, "labeledUri: %s", $1); free($1); } ; author_list: value_list { authors = malloc( 15 + strlen($1) ); sprintf(authors, "bibtexAuthor: %s", $1); $$ = $1 } | author_list E_SEP_AUTHOR value_list { tmp = malloc( strlen(authors)+strlen($3)+14+2); sprintf( tmp, "%s\nbibtexAuthor: %s", authors, $3); free(authors); authors = tmp; $$ = malloc(strlen($1)+strlen($3)+6); sprintf($$, "%s and %s", $1, $3); free($1); free($3); } ; %% int yyerror(char* s) { printf("error: %s encountered at line number:%d\n", s, yylineno); exit(EXIT_FAILURE); }