1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include "sun_msgfmt.h" 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate static const char *mandatory_fields[] = { 32*7c478bd9Sstevel@tonic-gate "Project-Id-Version", 33*7c478bd9Sstevel@tonic-gate "PO-Revision-Date", 34*7c478bd9Sstevel@tonic-gate "Last-Translator", 35*7c478bd9Sstevel@tonic-gate "Language-Team", 36*7c478bd9Sstevel@tonic-gate "Content-Type", 37*7c478bd9Sstevel@tonic-gate "Content-Transfer-Encoding", 38*7c478bd9Sstevel@tonic-gate NULL 39*7c478bd9Sstevel@tonic-gate }; 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate static const char *mandatory_fields_new[] = { 42*7c478bd9Sstevel@tonic-gate "POT-Creation-Date", 43*7c478bd9Sstevel@tonic-gate "Plural-Forms", 44*7c478bd9Sstevel@tonic-gate NULL 45*7c478bd9Sstevel@tonic-gate }; 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate extern int verbose; 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate extern void invoke_gnu_msgfmt(void); 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate static size_t 52*7c478bd9Sstevel@tonic-gate get_one_line(char **bufhead, char **mbuf, size_t *fsize) 53*7c478bd9Sstevel@tonic-gate { 54*7c478bd9Sstevel@tonic-gate size_t len; 55*7c478bd9Sstevel@tonic-gate char *p = *mbuf; 56*7c478bd9Sstevel@tonic-gate char *q, *tmp; 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate if (*bufhead) { 59*7c478bd9Sstevel@tonic-gate free(*bufhead); 60*7c478bd9Sstevel@tonic-gate *bufhead = NULL; 61*7c478bd9Sstevel@tonic-gate } 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate if (*fsize == 0) { 64*7c478bd9Sstevel@tonic-gate /* eof */ 65*7c478bd9Sstevel@tonic-gate return (0); 66*7c478bd9Sstevel@tonic-gate } 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate q = p; 69*7c478bd9Sstevel@tonic-gate while (((*fsize) != 0) && (*p++ != '\n')) { 70*7c478bd9Sstevel@tonic-gate (*fsize)--; 71*7c478bd9Sstevel@tonic-gate } 72*7c478bd9Sstevel@tonic-gate len = p - q; 73*7c478bd9Sstevel@tonic-gate if (len == 0) { 74*7c478bd9Sstevel@tonic-gate return (0); 75*7c478bd9Sstevel@tonic-gate } 76*7c478bd9Sstevel@tonic-gate tmp = (char *)Xmalloc(len + 1); 77*7c478bd9Sstevel@tonic-gate (void) memcpy(tmp, q, len); 78*7c478bd9Sstevel@tonic-gate tmp[len] = '\0'; 79*7c478bd9Sstevel@tonic-gate *bufhead = tmp; 80*7c478bd9Sstevel@tonic-gate *mbuf = p; 81*7c478bd9Sstevel@tonic-gate return (len); 82*7c478bd9Sstevel@tonic-gate } 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate void 85*7c478bd9Sstevel@tonic-gate check_gnu(char *addr, size_t fsize) 86*7c478bd9Sstevel@tonic-gate { 87*7c478bd9Sstevel@tonic-gate int i; 88*7c478bd9Sstevel@tonic-gate char c, mc; 89*7c478bd9Sstevel@tonic-gate char *linebuf; 90*7c478bd9Sstevel@tonic-gate char *mbuf, *p, *buf; 91*7c478bd9Sstevel@tonic-gate unsigned int n; 92*7c478bd9Sstevel@tonic-gate size_t ln_size; 93*7c478bd9Sstevel@tonic-gate size_t bufsize, index; 94*7c478bd9Sstevel@tonic-gate size_t size = fsize; 95*7c478bd9Sstevel@tonic-gate int quotefound = 0; 96*7c478bd9Sstevel@tonic-gate const char *field; 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate buf = NULL; 99*7c478bd9Sstevel@tonic-gate linebuf = NULL; 100*7c478bd9Sstevel@tonic-gate mbuf = addr; 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate loop: 103*7c478bd9Sstevel@tonic-gate ln_size = get_one_line(&linebuf, &mbuf, &size); 104*7c478bd9Sstevel@tonic-gate if ((ln_size == (size_t)-1) || 105*7c478bd9Sstevel@tonic-gate (ln_size == 0)) { 106*7c478bd9Sstevel@tonic-gate goto no_gnu; 107*7c478bd9Sstevel@tonic-gate } 108*7c478bd9Sstevel@tonic-gate p = linebuf; 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate while ((*p == '#') || (*p == '\n')) { 111*7c478bd9Sstevel@tonic-gate ln_size = get_one_line(&linebuf, &mbuf, &size); 112*7c478bd9Sstevel@tonic-gate if ((ln_size == (size_t)-1) || 113*7c478bd9Sstevel@tonic-gate (ln_size == 0)) { 114*7c478bd9Sstevel@tonic-gate goto no_gnu; 115*7c478bd9Sstevel@tonic-gate } 116*7c478bd9Sstevel@tonic-gate p = linebuf; 117*7c478bd9Sstevel@tonic-gate } 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate if (strncmp(p, "domain", 6) == 0) 120*7c478bd9Sstevel@tonic-gate goto loop; 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate if (strncmp(p, "msgid", 5) != 0) { 123*7c478bd9Sstevel@tonic-gate /* error */ 124*7c478bd9Sstevel@tonic-gate goto no_gnu; 125*7c478bd9Sstevel@tonic-gate } 126*7c478bd9Sstevel@tonic-gate 127*7c478bd9Sstevel@tonic-gate p += 5; 128*7c478bd9Sstevel@tonic-gate if ((*p != ' ') && (*p != '\t') && 129*7c478bd9Sstevel@tonic-gate (*p != '\n') && (*p != '\0')) { 130*7c478bd9Sstevel@tonic-gate /* no space after msgid */ 131*7c478bd9Sstevel@tonic-gate goto no_gnu; 132*7c478bd9Sstevel@tonic-gate } 133*7c478bd9Sstevel@tonic-gate /* skip spaces */ 134*7c478bd9Sstevel@tonic-gate while ((*p == ' ') || (*p == '\t')) 135*7c478bd9Sstevel@tonic-gate p++; 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate /* check if this entry is an empty string */ 138*7c478bd9Sstevel@tonic-gate if ((*p != '\"') || (*(p + 1) != '\"')) { 139*7c478bd9Sstevel@tonic-gate /* this is not an empty string */ 140*7c478bd9Sstevel@tonic-gate goto no_gnu; 141*7c478bd9Sstevel@tonic-gate } 142*7c478bd9Sstevel@tonic-gate p += 2; 143*7c478bd9Sstevel@tonic-gate while (*p && ((*p == ' ') || (*p == '\t'))) { 144*7c478bd9Sstevel@tonic-gate p++; 145*7c478bd9Sstevel@tonic-gate } 146*7c478bd9Sstevel@tonic-gate if ((*p != '\n') && (*p != '\0')) { 147*7c478bd9Sstevel@tonic-gate /* other characters than '\n' and '\0' found */ 148*7c478bd9Sstevel@tonic-gate goto no_gnu; 149*7c478bd9Sstevel@tonic-gate } 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate for (; ; ) { 152*7c478bd9Sstevel@tonic-gate ln_size = get_one_line(&linebuf, &mbuf, &size); 153*7c478bd9Sstevel@tonic-gate if ((ln_size == (size_t)-1) || 154*7c478bd9Sstevel@tonic-gate (ln_size == 0)) { 155*7c478bd9Sstevel@tonic-gate goto no_gnu; 156*7c478bd9Sstevel@tonic-gate } 157*7c478bd9Sstevel@tonic-gate p = linebuf; 158*7c478bd9Sstevel@tonic-gate /* skip leading spaces */ 159*7c478bd9Sstevel@tonic-gate while ((*p == ' ') || (*p == '\t')) 160*7c478bd9Sstevel@tonic-gate p++; 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate if (*p != '\"') { 163*7c478bd9Sstevel@tonic-gate if (strncmp(p, "msgstr", 6) == 0) { 164*7c478bd9Sstevel@tonic-gate break; 165*7c478bd9Sstevel@tonic-gate } 166*7c478bd9Sstevel@tonic-gate /* not a valid entry */ 167*7c478bd9Sstevel@tonic-gate goto no_gnu; 168*7c478bd9Sstevel@tonic-gate } 169*7c478bd9Sstevel@tonic-gate if (*(p + 1) != '\"') { 170*7c478bd9Sstevel@tonic-gate /* not an empty string */ 171*7c478bd9Sstevel@tonic-gate goto no_gnu; 172*7c478bd9Sstevel@tonic-gate } 173*7c478bd9Sstevel@tonic-gate p += 2; 174*7c478bd9Sstevel@tonic-gate while ((*p == ' ') || (*p == '\t')) 175*7c478bd9Sstevel@tonic-gate p++; 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate if ((*p != '\n') && (*p != '\0')) { 178*7c478bd9Sstevel@tonic-gate /* other characters than '\n' and '\0' found */ 179*7c478bd9Sstevel@tonic-gate goto no_gnu; 180*7c478bd9Sstevel@tonic-gate } 181*7c478bd9Sstevel@tonic-gate } 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate /* 184*7c478bd9Sstevel@tonic-gate * msgid for the header entry found 185*7c478bd9Sstevel@tonic-gate * Now p points to "msgstr" 186*7c478bd9Sstevel@tonic-gate */ 187*7c478bd9Sstevel@tonic-gate p += 6; 188*7c478bd9Sstevel@tonic-gate if ((*p != ' ') && (*p != '\t') && 189*7c478bd9Sstevel@tonic-gate (*p != '\n') && (*p != '\0')) { 190*7c478bd9Sstevel@tonic-gate /* no space after msgid */ 191*7c478bd9Sstevel@tonic-gate goto no_gnu; 192*7c478bd9Sstevel@tonic-gate } 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate /* skip spaces */ 195*7c478bd9Sstevel@tonic-gate while ((*p == ' ') || (*p == '\t')) 196*7c478bd9Sstevel@tonic-gate p++; 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate if (*p != '\"') { 199*7c478bd9Sstevel@tonic-gate /* no quote */ 200*7c478bd9Sstevel@tonic-gate goto no_gnu; 201*7c478bd9Sstevel@tonic-gate } 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate bufsize = ln_size + 1; 204*7c478bd9Sstevel@tonic-gate index = 0; 205*7c478bd9Sstevel@tonic-gate buf = (char *)Xmalloc(bufsize); 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate for (; ; ) { 208*7c478bd9Sstevel@tonic-gate if (*p != '\"') { 209*7c478bd9Sstevel@tonic-gate /* msgstr entry ends */ 210*7c478bd9Sstevel@tonic-gate buf[index] = '\0'; 211*7c478bd9Sstevel@tonic-gate break; 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate if (*p++ != '\"') { 215*7c478bd9Sstevel@tonic-gate /* no beginning quote */ 216*7c478bd9Sstevel@tonic-gate goto no_gnu; 217*7c478bd9Sstevel@tonic-gate } 218*7c478bd9Sstevel@tonic-gate while (*p) { 219*7c478bd9Sstevel@tonic-gate switch (mc = *p++) { 220*7c478bd9Sstevel@tonic-gate case '\n': 221*7c478bd9Sstevel@tonic-gate if (!quotefound) { 222*7c478bd9Sstevel@tonic-gate /* error */ 223*7c478bd9Sstevel@tonic-gate goto no_gnu; 224*7c478bd9Sstevel@tonic-gate } 225*7c478bd9Sstevel@tonic-gate break; 226*7c478bd9Sstevel@tonic-gate case '\"': 227*7c478bd9Sstevel@tonic-gate quotefound = 1; 228*7c478bd9Sstevel@tonic-gate break; 229*7c478bd9Sstevel@tonic-gate case '\\': 230*7c478bd9Sstevel@tonic-gate if (!*p) 231*7c478bd9Sstevel@tonic-gate break; 232*7c478bd9Sstevel@tonic-gate switch (c = *p++) { 233*7c478bd9Sstevel@tonic-gate case 'b': 234*7c478bd9Sstevel@tonic-gate buf[index++] = '\b'; 235*7c478bd9Sstevel@tonic-gate break; 236*7c478bd9Sstevel@tonic-gate case 'f': 237*7c478bd9Sstevel@tonic-gate buf[index++] = '\f'; 238*7c478bd9Sstevel@tonic-gate break; 239*7c478bd9Sstevel@tonic-gate case 'n': 240*7c478bd9Sstevel@tonic-gate buf[index++] = '\n'; 241*7c478bd9Sstevel@tonic-gate break; 242*7c478bd9Sstevel@tonic-gate case 'r': 243*7c478bd9Sstevel@tonic-gate buf[index++] = '\r'; 244*7c478bd9Sstevel@tonic-gate break; 245*7c478bd9Sstevel@tonic-gate case 't': 246*7c478bd9Sstevel@tonic-gate buf[index++] = '\t'; 247*7c478bd9Sstevel@tonic-gate break; 248*7c478bd9Sstevel@tonic-gate case 'v': 249*7c478bd9Sstevel@tonic-gate buf[index++] = '\v'; 250*7c478bd9Sstevel@tonic-gate break; 251*7c478bd9Sstevel@tonic-gate case 'a': 252*7c478bd9Sstevel@tonic-gate buf[index++] = '\a'; 253*7c478bd9Sstevel@tonic-gate break; 254*7c478bd9Sstevel@tonic-gate case '\"': 255*7c478bd9Sstevel@tonic-gate case '\\': 256*7c478bd9Sstevel@tonic-gate case '\'': 257*7c478bd9Sstevel@tonic-gate case '?': 258*7c478bd9Sstevel@tonic-gate buf[index++] = c; 259*7c478bd9Sstevel@tonic-gate break; 260*7c478bd9Sstevel@tonic-gate default: 261*7c478bd9Sstevel@tonic-gate if (isdigit((unsigned char)c)) { 262*7c478bd9Sstevel@tonic-gate unsigned int x; 263*7c478bd9Sstevel@tonic-gate unsigned char *up = 264*7c478bd9Sstevel@tonic-gate (unsigned char *)p; 265*7c478bd9Sstevel@tonic-gate n = c - '0'; 266*7c478bd9Sstevel@tonic-gate if (isdigit(*up)) { 267*7c478bd9Sstevel@tonic-gate x = *up++ - '0'; 268*7c478bd9Sstevel@tonic-gate n = 8 * n + x; 269*7c478bd9Sstevel@tonic-gate if (isdigit(*up)) { 270*7c478bd9Sstevel@tonic-gate x = *up++ - '0'; 271*7c478bd9Sstevel@tonic-gate n = 8 * n + x; 272*7c478bd9Sstevel@tonic-gate } 273*7c478bd9Sstevel@tonic-gate } 274*7c478bd9Sstevel@tonic-gate p = (char *)up; 275*7c478bd9Sstevel@tonic-gate buf[index++] = n; 276*7c478bd9Sstevel@tonic-gate } 277*7c478bd9Sstevel@tonic-gate break; 278*7c478bd9Sstevel@tonic-gate } 279*7c478bd9Sstevel@tonic-gate break; 280*7c478bd9Sstevel@tonic-gate default: 281*7c478bd9Sstevel@tonic-gate buf[index++] = mc; 282*7c478bd9Sstevel@tonic-gate break; 283*7c478bd9Sstevel@tonic-gate } 284*7c478bd9Sstevel@tonic-gate if (quotefound) { 285*7c478bd9Sstevel@tonic-gate while (*p && ((*p == ' ') || (*p == '\t'))) { 286*7c478bd9Sstevel@tonic-gate p++; 287*7c478bd9Sstevel@tonic-gate } 288*7c478bd9Sstevel@tonic-gate if ((*p != '\n') && (*p != '\0')) { 289*7c478bd9Sstevel@tonic-gate goto no_gnu; 290*7c478bd9Sstevel@tonic-gate } 291*7c478bd9Sstevel@tonic-gate quotefound = 0; 292*7c478bd9Sstevel@tonic-gate break; 293*7c478bd9Sstevel@tonic-gate } 294*7c478bd9Sstevel@tonic-gate } 295*7c478bd9Sstevel@tonic-gate ln_size = get_one_line(&linebuf, &mbuf, &size); 296*7c478bd9Sstevel@tonic-gate if ((ln_size == (size_t)-1) || 297*7c478bd9Sstevel@tonic-gate (ln_size == 0)) { 298*7c478bd9Sstevel@tonic-gate goto no_gnu; 299*7c478bd9Sstevel@tonic-gate } 300*7c478bd9Sstevel@tonic-gate p = linebuf; 301*7c478bd9Sstevel@tonic-gate /* skip spaces */ 302*7c478bd9Sstevel@tonic-gate while ((*p == ' ') || (*p == '\t')) 303*7c478bd9Sstevel@tonic-gate p++; 304*7c478bd9Sstevel@tonic-gate bufsize += ln_size; 305*7c478bd9Sstevel@tonic-gate buf = (char *)Xrealloc(buf, bufsize); 306*7c478bd9Sstevel@tonic-gate } 307*7c478bd9Sstevel@tonic-gate 308*7c478bd9Sstevel@tonic-gate for (i = 0; (field = mandatory_fields[i]) != NULL; i++) { 309*7c478bd9Sstevel@tonic-gate if (strstr(buf, field) == NULL) 310*7c478bd9Sstevel@tonic-gate continue; 311*7c478bd9Sstevel@tonic-gate /* one of mandatory fields found */ 312*7c478bd9Sstevel@tonic-gate free(linebuf); 313*7c478bd9Sstevel@tonic-gate free(buf); 314*7c478bd9Sstevel@tonic-gate (void) munmap(addr, fsize); 315*7c478bd9Sstevel@tonic-gate if (verbose) 316*7c478bd9Sstevel@tonic-gate diag(gettext(DIAG_GNU_FOUND)); 317*7c478bd9Sstevel@tonic-gate invoke_gnu_msgfmt(); 318*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 319*7c478bd9Sstevel@tonic-gate } 320*7c478bd9Sstevel@tonic-gate for (i = 0; (field = mandatory_fields_new[i]) != NULL; i++) { 321*7c478bd9Sstevel@tonic-gate if (strstr(buf, field) == NULL) 322*7c478bd9Sstevel@tonic-gate continue; 323*7c478bd9Sstevel@tonic-gate /* one of mandatory fields found */ 324*7c478bd9Sstevel@tonic-gate free(linebuf); 325*7c478bd9Sstevel@tonic-gate free(buf); 326*7c478bd9Sstevel@tonic-gate (void) munmap(addr, fsize); 327*7c478bd9Sstevel@tonic-gate if (verbose) 328*7c478bd9Sstevel@tonic-gate diag(gettext(DIAG_GNU_FOUND)); 329*7c478bd9Sstevel@tonic-gate invoke_gnu_msgfmt(); 330*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 331*7c478bd9Sstevel@tonic-gate } 332*7c478bd9Sstevel@tonic-gate 333*7c478bd9Sstevel@tonic-gate no_gnu: 334*7c478bd9Sstevel@tonic-gate free(linebuf); 335*7c478bd9Sstevel@tonic-gate if (buf) 336*7c478bd9Sstevel@tonic-gate free(buf); 337*7c478bd9Sstevel@tonic-gate } 338