diff options
Diffstat (limited to 'cmd/sgs/tools/common')
-rw-r--r-- | cmd/sgs/tools/common/sgsmsg.c | 57 | ||||
-rw-r--r-- | cmd/sgs/tools/common/string_table.c | 31 |
2 files changed, 57 insertions, 31 deletions
diff --git a/cmd/sgs/tools/common/sgsmsg.c b/cmd/sgs/tools/common/sgsmsg.c index 9b2e37b507d6..1cdd584c7427 100644 --- a/cmd/sgs/tools/common/sgsmsg.c +++ b/cmd/sgs/tools/common/sgsmsg.c @@ -19,8 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. * * sgsmsg generates several message files from an input template file. Messages * are constructed for use with gettext(3i) - the default - or catgets(3c). The @@ -66,7 +65,6 @@ * the data array being built in msg.c. The index into this array * becomes the `message' identifier created in the msg.h file. */ -#pragma ident "%Z%%M% %I% %E% SMI" #include <fcntl.h> #include <stdlib.h> @@ -393,15 +391,22 @@ init_defs(void) return (1); } + if (fprintf(fddefs, "#include <sgsmsg.h>\t/* Msg typedef */\n\n") < 0) { + (void) fprintf(stderr, Errmsg_wrte, fldefs, strerror(errno)); + return (1); + } + if (fprintf(fddefs, "#ifndef\t__lint\n\n") < 0) { (void) fprintf(stderr, Errmsg_wrte, fldefs, strerror(errno)); return (1); } /* - * add "typedef int Msg;" + * The MSG_SGS_ARRAY_NAME macro supplies a generic way to + * reference the string table regardless of its name. */ - if (fprintf(fddefs, "typedef int\tMsg;\n\n") < 0) { + if (fprintf(fddefs, "#define\tMSG_SGS_LOCAL_ARRAY\t__%s\n\n", + interface) < 0) { (void) fprintf(stderr, Errmsg_wrte, fldefs, strerror(errno)); return (1); } @@ -418,7 +423,13 @@ init_defs(void) return (1); } } - if (fprintf(fddefs, "#define\tMSG_ORIG(x)\t&__%s[x]\n\n", + if (fprintf(fddefs, + "#define\tMSG_ORIG_STRTAB(_x, _s)\t&_s[_x]\n\n") < 0) { + (void) fprintf(stderr, Errmsg_wrte, fldefs, strerror(errno)); + return (1); + } + if (fprintf(fddefs, + "#define\tMSG_ORIG(x)\tMSG_ORIG_STRTAB(x, __%s)\n\n", interface) < 0) { (void) fprintf(stderr, Errmsg_wrte, fldefs, strerror(errno)); return (1); @@ -453,17 +464,14 @@ fini_defs(void) return (1); } - /* - * When __lint is defined, Msg is a char *. This allows lint to - * check our format strings against it's arguments. - */ - if (fprintf(fddefs, "\ntypedef char *\tMsg;\n\n") < 0) { + if (fprintf(fddefs, "extern\tconst char *\t_%s(Msg);\n\n", + interface) < 0) { (void) fprintf(stderr, Errmsg_wrte, fldefs, strerror(errno)); return (1); } - if (fprintf(fddefs, "extern\tconst char *\t_%s(Msg);\n\n", - interface) < 0) { + if (fprintf(fddefs, "#ifndef MSG_SGS_LOCAL_ARRAY\n" + "#define\tMSG_SGS_LOCAL_ARRAY\t\"\"\n#endif\n\n") < 0) { (void) fprintf(stderr, Errmsg_wrte, fldefs, strerror(errno)); return (1); } @@ -478,12 +486,25 @@ fini_defs(void) } if (fprintf(fddefs, + "#define MSG_ORIG_STRTAB(_x, _s)\t_x\n" "#define MSG_ORIG(x)\tx\n#define MSG_INTL(x)\tx\n") < 0) { (void) fprintf(stderr, Errmsg_wrte, fldefs, strerror(errno)); return (1); } /* + * Provide a way to get the array and function declarations above + * without also getting the actual messages. This is useful in + * our lintsup.c files that include more than one message header. + * lintsup doesn't need the actual messages, and this prevents + * macro name collisions. + */ + if (fprintf(fddefs, "\n#ifndef LINTSUP_SUPPRESS_STRINGS\n") < 0) { + (void) fprintf(stderr, Errmsg_wrte, fldefs, strerror(errno)); + return (1); + } + + /* * Copy the temporary lint defs file into the new header. */ if (fdlint) { @@ -510,6 +531,11 @@ fini_defs(void) (void) free(buf); } + if (fprintf(fddefs, "\n#endif\t/* LINTSUP_SUPPRESS_STRINGS */\n") < 0) { + (void) fprintf(stderr, Errmsg_wrte, fldefs, strerror(errno)); + return (1); + } + if (fprintf(fddefs, "\n#endif\t/* __lint */\n") < 0) { (void) fprintf(stderr, Errmsg_wrte, fldefs, strerror(errno)); return (1); @@ -1102,8 +1128,9 @@ main(int argc, char ** argv) } } if (fddefs && fddata) { - (void) sprintf(fllint, "%s.%d", nmlint, (int)getpid()); - if ((fdlint = fopen(fllint, "w+")) == NULL) { + (void) sprintf(fllint, "%s.%d.XXXXXX", nmlint, (int)getpid()); + if ((mkstemp(fllint) == -1) || + ((fdlint = fopen(fllint, "w+")) == NULL)) { (void) fprintf(stderr, Errmsg_opne, fllint, strerror(errno)); return (1); diff --git a/cmd/sgs/tools/common/string_table.c b/cmd/sgs/tools/common/string_table.c index e174acaf0419..c15473150e4c 100644 --- a/cmd/sgs/tools/common/string_table.c +++ b/cmd/sgs/tools/common/string_table.c @@ -20,12 +20,10 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <_string_table.h> #include <strings.h> #include <sgs.h> @@ -160,7 +158,7 @@ st_new(uint_t flags) { Str_tbl *stp; - if ((stp = calloc(sizeof (Str_tbl), 1)) == NULL) + if ((stp = calloc(sizeof (*stp), 1)) == NULL) return (NULL); /* @@ -175,7 +173,7 @@ st_new(uint_t flags) if ((stp->st_flags & FLG_STTAB_COMPRESS) == 0) return (stp); - if ((stp->st_lentree = calloc(sizeof (avl_tree_t), 1)) == NULL) + if ((stp->st_lentree = calloc(sizeof (*stp->st_lentree), 1)) == NULL) return (NULL); avl_create(stp->st_lentree, &avl_len_compare, sizeof (LenNode), @@ -187,9 +185,9 @@ st_new(uint_t flags) /* * Insert a new string into the Str_tbl. There are two AVL trees used. * - * . The first LenNode AVL tree maintains a tree of nodes based on string + * - The first LenNode AVL tree maintains a tree of nodes based on string * sizes. - * . Each LenNode maintains a StrNode AVL tree for each string. Large + * - Each LenNode maintains a StrNode AVL tree for each string. Large * applications have been known to contribute thousands of strings of * the same size. Should strings need to be removed (-z ignore), then * the string AVL tree makes this removal efficient and scalable. @@ -227,12 +225,13 @@ st_insert(Str_tbl *stp, const char *str) */ ln.ln_strlen = len; if ((lnp = avl_find(stp->st_lentree, &ln, &where)) == NULL) { - if ((lnp = calloc(sizeof (LenNode), 1)) == NULL) + if ((lnp = calloc(sizeof (*lnp), 1)) == NULL) return (-1); lnp->ln_strlen = len; avl_insert(stp->st_lentree, lnp, where); - if ((lnp->ln_strtree = calloc(sizeof (avl_tree_t), 1)) == NULL) + if ((lnp->ln_strtree = calloc(sizeof (*lnp->ln_strtree), 1)) == + NULL) return (0); avl_create(lnp->ln_strtree, &avl_str_compare, sizeof (StrNode), @@ -246,7 +245,7 @@ st_insert(Str_tbl *stp, const char *str) */ sn.sn_str = str; if ((snp = avl_find(lnp->ln_strtree, &sn, &where)) == NULL) { - if ((snp = calloc(sizeof (StrNode), 1)) == NULL) + if ((snp = calloc(sizeof (*snp), 1)) == NULL) return (-1); snp->sn_str = str; avl_insert(lnp->ln_strtree, snp, where); @@ -513,7 +512,7 @@ st_hash_insert(Str_tbl *stp, const char *str, size_t len) /* * allocate a new master string */ - if ((mstr = calloc(sizeof (Str_hash), 1)) == 0) + if ((mstr = calloc(sizeof (*mstr), 1)) == 0) return (-1); mstr->sm_next = stp->st_mstrlist; stp->st_mstrlist = mstr; @@ -528,7 +527,7 @@ st_hash_insert(Str_tbl *stp, const char *str, size_t len) stp->st_strsize += len - mstr->sm_strlen; } - if ((sthash = calloc(sizeof (Str_hash), 1)) == 0) + if ((sthash = calloc(sizeof (*sthash), 1)) == 0) return (-1); mstr->sm_hashval = sthash->hi_hashval = hashval; @@ -569,8 +568,8 @@ st_getstrtab_sz(Str_tbl *stp) * strings input. */ stp->st_hbckcnt = findprime(stp->st_strcnt); - if ((stp->st_hashbcks = - calloc(sizeof (Str_hash), stp->st_hbckcnt)) == NULL) + if ((stp->st_hashbcks = calloc(sizeof (*stp->st_hashbcks), + stp->st_hbckcnt)) == NULL) return (0); /* @@ -673,8 +672,8 @@ st_setstrbuf(Str_tbl *stp, char *stbuf, size_t bufsize) #ifdef DEBUG /* * for debug builds - start with a stringtable filled in - * with '0xff'. This makes it very easy to find wholes - * which we failed to fill in - in the strtab. + * with '0xff'. This makes it very easy to spot unfilled + * holes in the strtab. */ memset(stbuf, 0xff, bufsize); stbuf[0] = '\0'; |