Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
cifmsg.c
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2.1 of the GNU Lesser General Public License 
00007   as published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU Lesser General Public 
00021   License along with this program; if not, write the Free Software 
00022   Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 
00023   USA.
00024 
00025   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00026   Mountain View, CA 94043, or:
00027 
00028   http://www.sgi.com
00029 
00030   For further information regarding this notice, see:
00031 
00032   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00033 
00034 */
00035 
00036 
00037 static char USMID[] = "@(#) libcif/cifmsg.c     30.3    07/26/96 07:19:13";
00038 
00039 
00040 /*
00041  * Cif_Msginsert accepts a cif message structure and message text string.  It
00042  * returns a new text string with the message arguments inserted in place of
00043  * "%" printf fields in the old string.
00044  */
00045 
00046 #define CIF_VERSION 3
00047 
00048 #ifdef _ABSOFT
00049 #include "cif.h"
00050 #else
00051 #include <cif.h>
00052 #endif
00053 
00054 #include <stdio.h>
00055 #include <string.h>
00056 
00057 #include "cif_int.h"
00058 
00059 int Cif_Msginsert
00060 #ifdef __STDC__
00061 (char *msgtext, struct Cif_generic *cr, char *newtext, int ntlen)
00062 #else
00063 (msgtext, cr, newtext, ntlen)
00064 char *msgtext;                                                  /* pointer to original message text */  
00065 struct Cif_generic *cr;                         /* pointer to cif message structure */
00066 char *newtext;                                                  /* pointer to new message text buffer*/
00067 int ntlen;                                                              /* length of 'newtext' */
00068 #endif
00069 {
00070         int i, ocptr, argno, nargs;
00071         char ichr, **args;
00072         char *fchars = "dgiopuxXfeEgGcsn";
00073 
00074         for (ocptr = 0; ocptr < ntlen; ocptr++) newtext[ocptr] = '\0';
00075         if (cr->rectype == CIF_MESSAGE) {
00076                 if (_cif_version <= 2) { /* must use v1,2 cif records */
00077                         nargs = CIFMSG1(cr)->nargs;
00078                         args = CIFMSG1(cr)->args;
00079                 }
00080                 else {
00081                         nargs = CIFMSG(cr)->nargs;
00082                         args = CIFMSG(cr)->args;
00083                 }
00084         }
00085         else if (cr->rectype == CIF_ND_MSG) {
00086                 nargs = CIFNMSG(cr)->nargs;
00087                 args = CIFNMSG(cr)->args;
00088         }
00089         else if (cr->rectype == CIF_C_MESSAGE) {
00090                 if (_cif_version == 1) { /* must use v1 cif records */
00091 
00092                         nargs = CIFCMSG1(cr)->nargs;
00093                         args = CIFCMSG1(cr)->args;
00094 
00095                 }
00096                 else { /* version 2 cif */
00097 
00098                         nargs = CIFCMSG(cr)->nargs;
00099                         args = CIFCMSG(cr)->args;
00100 
00101                 }
00102         }
00103         else
00104                 return (CIF_BADREQ);
00105         
00106         argno = ocptr = 0;
00107         while (ichr = *msgtext++) {
00108                 if (ichr != '%') {
00109                         if (ocptr < ntlen-1) newtext[ocptr++] = ichr;
00110                 }
00111                 else {
00112                         ichr = *msgtext++;
00113                         if (ichr == '%') {
00114                                 if (ocptr < ntlen-1) newtext[ocptr++] = ichr;
00115                         }
00116                         else {
00117                                 while (strchr (fchars, ichr) == NULL)
00118                                         ichr = *msgtext++;
00119                                 if (argno >= nargs) {
00120                                   /* something has gone wrong, but do the best we
00121                                      can, so that the user gets some message */
00122                                   (void) strncpy (&newtext[ocptr],"?",1);
00123                                   ocptr += 1;
00124                                   continue;
00125                                   /* return (CIF_BADREQ); gave in previously */
00126                                 }
00127                                 i = strlen (args[argno]);
00128                                 if (ntlen-ocptr-1 < i) i = ntlen-ocptr-1;
00129                                 (void) strncpy (&newtext[ocptr], args[argno++], i);
00130                                 ocptr += i;
00131                         }
00132                 }
00133         }
00134         return (0);
00135 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines