17c478bd9Sstevel@tonic-gate %{ 27c478bd9Sstevel@tonic-gate /* 37c478bd9Sstevel@tonic-gate * CDDL HEADER START 47c478bd9Sstevel@tonic-gate * 57c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 67c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 77c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 87c478bd9Sstevel@tonic-gate * with the License. 97c478bd9Sstevel@tonic-gate * 107c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 117c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 127c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 137c478bd9Sstevel@tonic-gate * and limitations under the License. 147c478bd9Sstevel@tonic-gate * 157c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 167c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 177c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 187c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 197c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 207c478bd9Sstevel@tonic-gate * 217c478bd9Sstevel@tonic-gate * CDDL HEADER END 227c478bd9Sstevel@tonic-gate * 237c478bd9Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc. 247c478bd9Sstevel@tonic-gate * All rights reserved. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include "gnu_msgfmt.h" 287c478bd9Sstevel@tonic-gate #include "gnu_lex.h" 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate static int plural_index; 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate %} 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate %union { 357c478bd9Sstevel@tonic-gate char *str; 367c478bd9Sstevel@tonic-gate int num; 377c478bd9Sstevel@tonic-gate struct entry msg; 387c478bd9Sstevel@tonic-gate struct ch c; 397c478bd9Sstevel@tonic-gate } 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate %token <num> DOMAIN 427c478bd9Sstevel@tonic-gate %token <num> MSGID 437c478bd9Sstevel@tonic-gate %token <num> MSGID_PLURAL 447c478bd9Sstevel@tonic-gate %token <num> MSGSTR 457c478bd9Sstevel@tonic-gate %token <num> NUM 467c478bd9Sstevel@tonic-gate %token <str> STR 477c478bd9Sstevel@tonic-gate %token <str> COMMENT 487c478bd9Sstevel@tonic-gate %token <str> SYMBOL 497c478bd9Sstevel@tonic-gate %token <c> CHR 507c478bd9Sstevel@tonic-gate %type <msg> message_string plural_messages plural_message 517c478bd9Sstevel@tonic-gate %% 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate start : 547c478bd9Sstevel@tonic-gate | start po 557c478bd9Sstevel@tonic-gate ; 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate po : comment 587c478bd9Sstevel@tonic-gate | domain 597c478bd9Sstevel@tonic-gate | body 607c478bd9Sstevel@tonic-gate ; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate domain : DOMAIN STR 637c478bd9Sstevel@tonic-gate { 647c478bd9Sstevel@tonic-gate handle_domain($2); 657c478bd9Sstevel@tonic-gate } 667c478bd9Sstevel@tonic-gate ; 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate comment : COMMENT 697c478bd9Sstevel@tonic-gate { 707c478bd9Sstevel@tonic-gate handle_comment($1); 717c478bd9Sstevel@tonic-gate } 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate body : MSGID message_string MSGSTR message_string 747c478bd9Sstevel@tonic-gate { 757c478bd9Sstevel@tonic-gate struct entry och1, och2; 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate och1.no = 1; 787c478bd9Sstevel@tonic-gate och1.num = $1; 797c478bd9Sstevel@tonic-gate och1.str = $2.str; 807c478bd9Sstevel@tonic-gate och1.len = $2.len; 817c478bd9Sstevel@tonic-gate och1.pos = NULL; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate och2.no = 1; 847c478bd9Sstevel@tonic-gate och2.num = $3; 857c478bd9Sstevel@tonic-gate och2.str = $4.str; 867c478bd9Sstevel@tonic-gate och2.len = $4.len; 877c478bd9Sstevel@tonic-gate och2.pos = NULL; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate handle_message(&och1, &och2); 907c478bd9Sstevel@tonic-gate clear_state(); 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate | MSGID message_string MSGID_PLURAL 937c478bd9Sstevel@tonic-gate message_string {plural_index = 0;} plural_messages 947c478bd9Sstevel@tonic-gate { 957c478bd9Sstevel@tonic-gate size_t len; 967c478bd9Sstevel@tonic-gate struct entry och1, och2; 977c478bd9Sstevel@tonic-gate struct loc *pos1; 987c478bd9Sstevel@tonic-gate char *id_str; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate len = $2.len + $4.len; 1017c478bd9Sstevel@tonic-gate id_str = (char *)Xmalloc(len); 1027c478bd9Sstevel@tonic-gate (void) memcpy(id_str, $2.str, $2.len); 1037c478bd9Sstevel@tonic-gate (void) memcpy(id_str + $2.len, $4.str, $4.len); 1047c478bd9Sstevel@tonic-gate free($2.str); 1057c478bd9Sstevel@tonic-gate free($4.str); 106*2a8bcb4eSToomas Soome 1077c478bd9Sstevel@tonic-gate pos1 = (struct loc *)Xmalloc(2 * sizeof (struct loc)); 1087c478bd9Sstevel@tonic-gate pos1[0].off = 0; 1097c478bd9Sstevel@tonic-gate pos1[0].len = $2.len; 1107c478bd9Sstevel@tonic-gate pos1[0].num = $1; 1117c478bd9Sstevel@tonic-gate pos1[1].off = $2.len; 1127c478bd9Sstevel@tonic-gate pos1[1].len = $4.len; 1137c478bd9Sstevel@tonic-gate pos1[1].num = $3; 1147c478bd9Sstevel@tonic-gate och1.no = 2; 1157c478bd9Sstevel@tonic-gate och1.num = $1; 1167c478bd9Sstevel@tonic-gate och1.str = id_str; 1177c478bd9Sstevel@tonic-gate och1.len = len; 1187c478bd9Sstevel@tonic-gate och1.pos = pos1; 119*2a8bcb4eSToomas Soome 1207c478bd9Sstevel@tonic-gate och2 = $6; 1217c478bd9Sstevel@tonic-gate handle_message(&och1, &och2); 1227c478bd9Sstevel@tonic-gate clear_state(); 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate | MSGID message_string 1257c478bd9Sstevel@tonic-gate { 1267c478bd9Sstevel@tonic-gate error(gettext(ERR_NO_MSGSTR), $1, cur_po); 1277c478bd9Sstevel@tonic-gate /* NOTREACHED */ 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate | MSGID message_string MSGID_PLURAL message_string 1307c478bd9Sstevel@tonic-gate { 1317c478bd9Sstevel@tonic-gate error(gettext(ERR_NO_MSGSTRS), $1, cur_po); 1327c478bd9Sstevel@tonic-gate /* NOTRECHED */ 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate | MSGID message_string plural_messages 1357c478bd9Sstevel@tonic-gate { 1367c478bd9Sstevel@tonic-gate error(gettext(ERR_NO_MSGID_PLURAL), $1, cur_po); 1377c478bd9Sstevel@tonic-gate /* NOTREACHED */ 1387c478bd9Sstevel@tonic-gate } 1397c478bd9Sstevel@tonic-gate ; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate message_string : STR 1427c478bd9Sstevel@tonic-gate { 1437c478bd9Sstevel@tonic-gate $$.str = $1; 1447c478bd9Sstevel@tonic-gate $$.len = strlen($1) + 1; 1457c478bd9Sstevel@tonic-gate } 1467c478bd9Sstevel@tonic-gate | message_string STR 1477c478bd9Sstevel@tonic-gate { 1487c478bd9Sstevel@tonic-gate size_t len, len1, len2; 1497c478bd9Sstevel@tonic-gate char *str; 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* $1.len includes null-termination */ 1527c478bd9Sstevel@tonic-gate len1 = $1.len - 1; 1537c478bd9Sstevel@tonic-gate len2 = strlen($2); 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate /* len doesn't include null-termination */ 1567c478bd9Sstevel@tonic-gate len = len1 + len2; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate str = (char *)Xmalloc(len + 1); 1597c478bd9Sstevel@tonic-gate (void) memcpy(str, $1.str, len1); 1607c478bd9Sstevel@tonic-gate (void) memcpy(str + len1, $2, len2 + 1); 1617c478bd9Sstevel@tonic-gate free($1.str); 1627c478bd9Sstevel@tonic-gate free($2); 1637c478bd9Sstevel@tonic-gate $$.str = str; 1647c478bd9Sstevel@tonic-gate $$.len = len + 1; 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate ; 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate plural_messages : plural_message 1697c478bd9Sstevel@tonic-gate { 1707c478bd9Sstevel@tonic-gate $$ = $1; 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate | plural_messages plural_message 1737c478bd9Sstevel@tonic-gate { 1747c478bd9Sstevel@tonic-gate struct loc *tmp; 1757c478bd9Sstevel@tonic-gate size_t len; 1767c478bd9Sstevel@tonic-gate char *plural_str; 1777c478bd9Sstevel@tonic-gate int no; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate no = $1.no + 1; 1807c478bd9Sstevel@tonic-gate tmp = (struct loc *)Xrealloc($1.pos, 1817c478bd9Sstevel@tonic-gate no * sizeof (struct loc)); 1827c478bd9Sstevel@tonic-gate tmp[no - 1].off = $1.len; 1837c478bd9Sstevel@tonic-gate tmp[no - 1].len = $2.len; 1847c478bd9Sstevel@tonic-gate tmp[no - 1].num = $2.num; 1857c478bd9Sstevel@tonic-gate free($2.pos); 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate len = $1.len + $2.len; 1887c478bd9Sstevel@tonic-gate plural_str = (char *)Xmalloc(len); 1897c478bd9Sstevel@tonic-gate (void) memcpy(plural_str, $1.str, $1.len); 1907c478bd9Sstevel@tonic-gate (void) memcpy(plural_str + $1.len, $2.str, $2.len); 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate $$.no = no; 1937c478bd9Sstevel@tonic-gate $$.num = $1.num; 1947c478bd9Sstevel@tonic-gate $$.str = plural_str; 1957c478bd9Sstevel@tonic-gate $$.len = len; 1967c478bd9Sstevel@tonic-gate $$.pos = tmp; 1977c478bd9Sstevel@tonic-gate free($1.str); 1987c478bd9Sstevel@tonic-gate free($2.str); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate ; 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate plural_message : MSGSTR '[' NUM ']' message_string 2037c478bd9Sstevel@tonic-gate { 2047c478bd9Sstevel@tonic-gate struct loc *pos; 2057c478bd9Sstevel@tonic-gate if ($3 != plural_index) { 2067c478bd9Sstevel@tonic-gate error(gettext(ERR_INVALID_PLURALS), $1, cur_po); 2077c478bd9Sstevel@tonic-gate /* NOTREACHED */ 2087c478bd9Sstevel@tonic-gate } 2097c478bd9Sstevel@tonic-gate plural_index++; 2107c478bd9Sstevel@tonic-gate pos = (struct loc *)Xmalloc(sizeof (struct loc)); 2117c478bd9Sstevel@tonic-gate pos->off = 0; 2127c478bd9Sstevel@tonic-gate pos->len = $5.len; 2137c478bd9Sstevel@tonic-gate pos->num = $1; 2147c478bd9Sstevel@tonic-gate $$.no = 1; 2157c478bd9Sstevel@tonic-gate $$.num = $1; 2167c478bd9Sstevel@tonic-gate $$.str = $5.str; 2177c478bd9Sstevel@tonic-gate $$.len = $5.len; 2187c478bd9Sstevel@tonic-gate $$.pos = pos; 2197c478bd9Sstevel@tonic-gate } 2207c478bd9Sstevel@tonic-gate ; 2217c478bd9Sstevel@tonic-gate %% 2227c478bd9Sstevel@tonic-gate void 2237c478bd9Sstevel@tonic-gate yyerror(const char *err) 2247c478bd9Sstevel@tonic-gate { 2257c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2267c478bd9Sstevel@tonic-gate gettext(ERR_LOCATION), cur_line, cur_po); 2277c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s\n", err); 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate exit(1); 2307c478bd9Sstevel@tonic-gate } 231