void Debug( char *fmt, ...) { va_list args; Va_start(args,fmt); if (debugLevel > 0) { if ( strlen(DisplayName) > 0 && DoName) fprintf(stdout, "(%s) ", DisplayName); vprintf (fmt, args); fflush (stdout); /* * don't prepend the display name next time if this debug message * does not contain a "new line" character... */ if ( strchr(fmt,'\n') == NULL ) DoName=False; else DoName=True; } va_end(args); }
void F90_FunctionBegin( int f, ... ) { Va_list args; int i; int v; int vars[20]; char * name; int narg; FILE *oldf; name = varTable[ f ]->name; narg = varTable[ f ]->maxi; Va_start( args, f ); for( i = 0; i < narg; i++ ) vars[ i ] = va_arg( args, int ); va_end( args ); CommentFncBegin( f, vars ); F90_FunctionStart( f, vars ); NewLines(1); /* bprintf(" USE %s_Precision\n", rootFileName ); bprintf(" USE %s_Parameters\n\n", rootFileName ); */ /* bprintf(" IMPLICIT NONE\n" ); */ FlushBuf(); for( i = 0; i < narg; i++ ) F90_Declare( vars[ i ] ); bprintf("\n"); FlushBuf(); MapFunctionComment( f, vars ); }
void MATLAB_FunctionBegin( int f, ... ) { Va_list args; int i; int v; int vars[20]; char * name; int narg; FILE *oldf; char buf[200], bufname[200]; time_t t; name = varTable[ f ]->name; narg = varTable[ f ]->maxi; /*Adi - each Matlab functin requires a separate file*/ sprintf( buf, "%s_%s.m", rootFileName, varTable[ f ]->name ); mex_funFile = fopen(buf, "w"); if( mex_funFile == 0 ) { FatalError(3,"%s: Can't create file", buf ); } UseFile( mex_funFile ); /*Adi*/ Va_start( args, f ); for( i = 0; i < narg; i++ ) vars[ i ] = va_arg( args, int ); va_end( args ); CommentFncBegin( f, vars ); WriteDelim(); WriteComment(""); WriteComment("Generated by KPP - symbolic chemistry Kinetics PreProcessor" ); WriteComment(" KPP is developed at CGRER labs University of Iowa by" ); WriteComment(" Valeriu Damian & Adrian Sandu" ); WriteComment(""); WriteComment("%-20s : %s", "File", buf ); strcpy( buf, (char*)ctime( &t ) ); buf[ (int)strlen(buf) - 1 ] = 0; WriteComment("%-20s : %s", "Time", buf ); WriteComment("%-20s : %s", "Working directory", getcwd(buf, 200) ); WriteComment("%-20s : %s", "Equation file", eqFileName ); WriteComment("%-20s : %s", "Output root filename", rootFileName ); WriteComment(""); WriteDelim(); NewLines(1); MATLAB_FunctionStart( f, vars ); NewLines(1); FlushBuf(); MapFunctionComment( f, vars ); }
void bprintf( char *fmt, ... ) { Va_list args; if ( !fmt ) return; Va_start( args, fmt ); vsprintf( outBuffer, fmt, args ); va_end( args ); outBuffer += strlen( outBuffer ); }
Widget XmVaCreateManagedCommand( Widget parent, char *name, ...) { Widget w = NULL; va_list var; int count; Va_start(var, name); count = XmeCountVaListSimple(var); va_end(var); Va_start(var, name); w = XmeVLCreateWidget(name, xmCommandWidgetClass, parent, True, var, count); va_end(var); return w; }
void MATLAB_Inline( char *fmt, ... ) { Va_list args; char buf[ 1000 ]; if( useLang != MATLAB_LANG ) return; Va_start( args, fmt ); vsprintf( buf, fmt, args ); va_end( args ); bprintf( "%s\n", buf ); FlushBuf(); }
Widget XmVaCreateCommand( Widget parent, char *name, ...) { register Widget w; va_list var; int count; Va_start(var,name); count = XmeCountVaListSimple(var); va_end(var); Va_start(var, name); w = XmeVLCreateWidget(name, xmCommandWidgetClass, parent, False, var, count); va_end(var); return w; }
/**************************************************************************** * * LogPanic * * Write a panic message to the log file. * ****************************************************************************/ void LogPanic( char *fmt, ...) { va_list args; Va_start(args,fmt); if ( SyncErrorFile(1) ) { fprintf (stderr, "panic (pid %ld): ", (long)getpid()); vfprintf (stderr, fmt, args); fflush (stderr); } va_end(args); }
void LogOutOfMem( unsigned char *fmt, ...) { va_list args; Va_start(args,fmt); if ( SyncErrorFile(1) ) { fprintf(stderr,(char *)ReadCatalog(MC_ERROR_SET,MC_NO_MEMORY,MC_DEF_NO_MEMORY)); vfprintf (stderr, (char *)fmt, args); fflush (stderr); } va_end(args); }
void LogError( unsigned char *fmt, ...) { va_list args; Va_start(args,fmt); if ( SyncErrorFile(1) ) { fprintf (stderr, "error (pid %ld): ", (long)getpid()); vfprintf (stderr, (char *)fmt, args); fflush (stderr); } va_end(args); }
NODE * Elm( int v, ... ) { Va_list args; NODE *n; ELEMENT *elm; VARIABLE *var; int i, j; float val; char *expr; var = varTable[ v ]; n = (NODE*) malloc( sizeof(NODE) ); elm = (ELEMENT*) malloc( sizeof(ELEMENT) ); n->left = 0; n->right = 0; n->sign = 1; n->type = var->type; n->elm = elm; elm->var = v; Va_start( args, v ); switch( var->type ) { case CONST: switch( var->baseType ) { case REAL: elm->val.cnst = (float)va_arg( args, double ); break; case INT: elm->val.cnst = (float)va_arg( args, int ); } if( elm->val.cnst < 0 ) { elm->val.cnst = -elm->val.cnst; n->sign = -1; } break; case ELM: break; case VELM: elm->val.idx.i = va_arg( args, int ); break; case MELM: elm->val.idx.i = va_arg( args, int ); elm->val.idx.j = va_arg( args, int ); break; case EELM: elm->val.expr = va_arg( args, char* ); break; } va_end( args ); return n; }
void F90_WriteComment( char *fmt, ... ) { Va_list args; int n; char buf[ MAX_LINE ]; Va_start( args, fmt ); vsprintf( buf, fmt, args ); va_end( args ); /* remove trailing spaces */ /* taken from http://www.cs.bath.ac.uk/~pjw/NOTES/ansi_c/ch10-idioms.pdf */ for (n= strlen(buf) - 1; n >= 0; n--) if (buf[n] != ' ') break; buf[n + 1]= '\0'; bprintf( "! %s\n", buf ); FlushBuf(); }
void CommentFunctionBegin( int f, ... ) { Va_list args; int i; int vars[20]; char * name; int narg; name = varTable[ f ]->name; narg = varTable[ f ]->maxi; Va_start( args, f ); for( i = 0; i < narg; i++ ) vars[i] = va_arg( args, int ); va_end( args ); CommentFncBegin( f, vars ); /* MapFunctionComment( f, vars ); */ }
void _DtSimpleErrnoError( char *progName, DtSeverity severity, char *help, char *format, ... ) { va_list args; char *message = (char*) malloc(MESSAGE_BUFFER); if (NULL == message) return; Va_start(args, format); #if defined(USE_SNPRINTF) (void) vsnprintf(message, MESSAGE_BUFFER, format, args); #else (void) vsprintf(message, format, args); #endif va_end(args); log_message(progName, help, message, severity, TRUE); if (message) free(message); }
void IncludeCode( char* fmt, ... ) { Va_list args; char buf[200]; char cmd[500]; static char tmpfile[] = "kppfile.tmp"; FILE * fp; Va_start( args, fmt ); vsprintf( buf, fmt, args ); va_end( args ); switch( useLang ) { case F77_LANG: sprintf( buf, "%s.f", buf ); break; case F90_LANG: sprintf( buf, "%s.f90", buf ); break; case C_LANG: sprintf( buf, "%s.c", buf ); break; case MATLAB_LANG: sprintf( buf, "%s.m", buf ); break; default: printf("\n Language '%d' not implemented!\n",useLang); exit(1); } fp = fopen( buf, "r" ); if ( fp == 0 ) FatalError(3,"%s: Can't read file", buf ); fclose(fp); strcpy( cmd, "sed " ); sprintf( cmd, "%s -e 's/KPP_ROOT/%s/g'", cmd, rootFileName ); sprintf( cmd, "%s -e 's/KPP_NVAR/%d/g'", cmd, VarNr ); sprintf( cmd, "%s -e 's/KPP_NFIX/%d/g'", cmd, FixNr ); sprintf( cmd, "%s -e 's/KPP_NSPEC/%d/g'", cmd,SpcNr ); sprintf( cmd, "%s -e 's/KPP_NREACT/%d/g'", cmd, EqnNr ); sprintf( cmd, "%s -e 's/KPP_NONZERO/%d/g'", cmd, Jac_NZ ); sprintf( cmd, "%s -e 's/KPP_LU_NONZERO/%d/g'", cmd, LU_Jac_NZ ); sprintf( cmd, "%s -e 's/KPP_NHESS/%d/g'", cmd, Hess_NZ ); switch( useLang ) { case F77_LANG: sprintf( cmd, "%s -e 's/KPP_REAL/%s/g'", cmd, F77_types[real] ); break; case F90_LANG: sprintf( cmd, "%s -e 's/KPP_REAL/%s/g'", cmd, F90_types[real] ); break; case C_LANG: sprintf( cmd, "%s -e 's/KPP_REAL/%s/g'", cmd, C_types[real] ); break; case MATLAB_LANG: break; default: printf("\n Language '%d' not implemented!\n",useLang); exit(1); } sprintf( cmd, "%s %s > %s", cmd, buf, tmpfile ); system( cmd ); IncludeFile( tmpfile ); sprintf( cmd, "rm %s", tmpfile ); system( cmd ); }