IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 19, 2005, 2:31:22 PM (21 years ago)
Author:
drobbin
Message:

Inserted Gene's code for psTrace in and fixed psTraceV to use va_arg

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psTrace.c

    r4972 r5071  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-09-08 00:27:50 $
     11 *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-09-20 00:31:22 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5454
    5555static p_psComponent* cRoot = NULL; // The root of the trace component
    56 static FILE *traceFP = NULL;        // File destination for messages.
     56// static FILE *traceFP = NULL;        // File destination for messages.
    5757static psBool traceTime = false;     // Flag to include time info
    5858static psBool traceHost = false;     // Flag to include host info
     
    6060static psBool traceName = false;     // Flag to include name info
    6161static psBool traceMsg = true;      // Flag to include message info
    62 //static int traceFD = 0;
     62static int traceFD = STDOUT_FILENO; // default value
    6363
    6464static void componentFree(p_psComponent* comp);
     
    259259    if (cRoot == NULL) {
    260260        initTrace();
    261     }
    262 
    263     if (traceFP == NULL) {
    264         traceFP = stdout;
    265261    }
    266262
     
    436432                               psS32 defLevel)
    437433{
     434    char line[1024];
    438435    psS32 i = 0;
    439436
    440     if (traceFP == NULL) {
    441         traceFP = stdout;
    442     }
     437    // XXX EAM : probably should just return if traceFD < 1
     438    if (traceFD < 1)
     439        return;
    443440
    444441    if (comp->name[0] == '\0') {
     
    446443    } else {
    447444        if (comp->level == PS_DEFAULT_TRACE_LEVEL) {
    448             fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel);
     445            // fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel);
     446            sprintf(line,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel);
     447            write (traceFD, line, strlen(line));
    449448        } else {
    450             fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
     449            // fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
     450            sprintf(line, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
     451            write (traceFD, line, strlen(line));
    451452        }
    452453    }
     
    486487              va_list ap)
    487488{
    488     char *fmt = NULL;
     489    // char *fmt = NULL;
    489490    //    va_list ap;
    490491    static psS32 first = 1;       // Flag for calling gethostname()
     
    498499    struct tm *utc = gmtime(&clock);    // The current gm time.
    499500
    500     if (traceFP == NULL) {
    501         traceFP = stdout;
    502     }
     501    // XXX EAM : fd < 1 does not print messages
     502    if (traceFD < 1)
     503        return;
    503504
    504505    if (NULL == comp) {
     
    590591
    591592
    592 
    593         fputs(head, traceFP);
     593        // fputs(head, traceFP);
     594        write (traceFD, head, strlen(head));
     595
    594596        if (traceMsg) {
     597            char line[1024];
     598
    595599            // The following functions get the variable list of parameters with
    596600            // which this function was called, and print them to the standard
    597601            // output.
    598             fmt = va_arg(ap, char *);
     602            // fmt = va_arg(ap, char *);
    599603
    600604            // We indent each message one space for each level of the message.
    601605            for (i = 0; i < level; i++) {
    602606                //            fprintf(traceFP, " ");
    603                 fprintf(traceFP, "%s", format);
     607                // fprintf(traceFP, "%s", format);
     608                // sprintf(line, "%s", format);
     609                write (traceFD, " ", 1);
    604610            }
    605             vfprintf(traceFP, fmt, ap);
     611            // vfprintf(traceFP, fmt, ap);
     612            vsprintf(line, format, ap);
     613            write (traceFD, line, strlen(line));
     614
    606615            //        vfprintf(traceFP, format, ap);
    607616            //        va_end(ap);
     
    609618                        char* msgPtr;
    610619                        vsnprintf(msg,1024, format, ap);  // create message
    611              
     620
    612621                        // detect multiple lines in message and indent each line by 4 spaces.
    613622                        char* line = strtok_r(msg,"\n",&msgPtr);
     
    618627            */
    619628        } else {
    620             fputc('\n', traceFP);
     629            // fputc('\n', traceFP);
     630            write(traceFD, "\n", 1);
    621631        }
    622632
     
    647657    va_list ap;
    648658    va_start(ap, format);
     659    format = va_arg(ap, char *);
    649660    psTraceV(comp, level, format, ap);
    650661    va_end(ap);
    651     fflush(traceFP);
     662    // fflush(traceFP);
     663    // XXX EAM : what is fd-appropriate equivalent?
    652664}
    653665
     
    676688        traceFP = fp;
    677689    */
    678     if (fd == -1) {
     690    if (fd < 1) {
     691        traceFD = 0;
    679692        return;
    680693    }
    681694    if (fd == 1) {
    682         traceFP = stdout;
     695        traceFD = STDOUT_FILENO;
    683696    } else if (fd == 2) {
    684         traceFP = stderr;
    685     } else if (fd == 0) {
    686         traceFP = stdin;
     697        traceFD = STDERR_FILENO;
    687698    } else if (fd > 2) {
    688         traceFP = fdopen(fd, "w");
     699        close (traceFD);
     700        traceFD = fd;
    689701    }
    690702}
     
    692704int psTraceGetDestination()
    693705{
    694     int fd;
    695     fd = fileno(traceFP);
    696     return fd;
     706    return traceFD;
    697707}
    698708
Note: See TracChangeset for help on using the changeset viewer.