Re: API - message callback
Date | 2007-07-31 22:22 |
From | Victor Lazzarini |
Subject | Re: API - message callback |
I'm just eliminating the '\n' characters, because PD's post() adds them and I don't want two newlines after every msg string. It's just a formatting issue, you don't need to do it if you are just using printf() or fprintf() etc. > > i understand using that using vsnprintf would allow me to > get it to work .. few questions though: > > > if i == 0 and csmess[i] == '\0' > wouldn't x->csmess[i - 1] = ' ' be illegal? > > > I haven't analyzed the stream .. but is it just that 0's > are being written into it and this just replaces the > character before it with a space? Why are some strings > formatted correctly in the first place? Why is any of > this buffer manipulation necessary in the first place? > > greg > > > On Jul 31, 2007, at 2:48 PM, Victor Lazzarini wrote: > > > Use vsnprintf(...). > > > > This is an example callback from csoundapi_tilde.c: > > > > static void message_callback(CSOUND *csound, > > int attr, const char *format,va_list > > valist){ int i; > > t_csoundapi *x = (t_csoundapi *) > > csoundGetHostData(csound); > > > > if(x->csmess != NULL) > > vsnprintf(x->csmess, MAXMESSTRING, format, valist); > > for(i=0;i |
Date | 2007-08-01 13:41 |
From | Greg Thompson |
Subject | Re: API - message callback |
Well - I should have known. I found the culprit. Its calling the callback for every character .. only doing this for syntax errors though - so special code must be written to handle this case .. of course the message handler doesn't know what it is going to receive so .. special code must always be used. It seems to me this synterr function should construct a string and then call the message handler once. void synterr(CSOUND *csound, const char *s, ...) { va_list args; char *cp; int c; csound->MessageS(csound, CSOUNDMSG_ERROR, Str("error: ")); va_start(args, s); csound->MessageV(csound, CSOUNDMSG_ERROR, s, args); va_end(args); /* FIXME - Removed temporarily for debugging * This function may not be necessary at all in the end if some of this is * done in the parser */ if (ST(linadr) != NULL && (cp = ST(linadr)[ST(curline)]) != NULL #if defined(ENABLE_NEW_PARSER) && !csound->oparms->newParser #endif ) { csound->MessageS(csound, CSOUNDMSG_ERROR, Str(", line %d:\n"), ST(curline)); do { csound->MessageS(csound, CSOUNDMSG_ERROR, "%c", (c = *cp++)); } while (c != '\n'); } else { csound->MessageS(csound, CSOUNDMSG_ERROR, "\n"); } csound->synterrcnt++; } greg On Jul 31, 2007, at 5:22 PM, Victor Lazzarini wrote:
|