00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 static char USMID[] = "@(#) libcif/cifmsg.c 30.3 07/26/96 07:19:13";
00038
00039
00040
00041
00042
00043
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;
00065 struct Cif_generic *cr;
00066 char *newtext;
00067 int ntlen;
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) {
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) {
00091
00092 nargs = CIFCMSG1(cr)->nargs;
00093 args = CIFCMSG1(cr)->args;
00094
00095 }
00096 else {
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
00121
00122 (void) strncpy (&newtext[ocptr],"?",1);
00123 ocptr += 1;
00124 continue;
00125
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 }