IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 6, 2005, 2:15:51 PM (21 years ago)
Author:
drobbin
Message:

Updated/changed psTrace & psLog fxns to use fd (were FILE*) as described in SDRS

File:
1 edited

Legend:

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

    r4540 r4951  
    1212 *  @author GLG, MHPCC
    1313 *
    14  *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-07-12 19:12:01 $
     14 *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-09-07 00:15:48 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3737#include <time.h>
    3838#include <unistd.h>
     39#include <fcntl.h>
    3940
    4041#include "psLogMsg.h"
     
    8788 An psBool: TRUE if successful.
    8889 *****************************************************************************/
    89 bool psLogSetDestination(const char *dest)
     90bool psLogSetDestination(int fd)
    9091{
    91     char protocol[5];
    92     char location[257];
    93 
     92    //    char protocol[5];
     93    //    char location[257];
     94    //    char dest[257];
     95    FILE *fp;
    9496    // if logDest has not been initialized, do so before using it
    9597    if (logDest == (FILE *) 1) {
     
    9799    }
    98100
    99     if (dest == NULL || strcmp(dest, "none") == 0) {
     101    if ( fd == 1 ) {
     102        //        fp = stdout;
    100103        if (logDest != NULL && logDest != stderr && logDest != stdout) {
    101104            fclose(logDest);
    102105        }
     106        logDest = stdout;
     107    } else if (fd == 2) {
     108        //        fp = stderr;
     109        if (logDest != NULL && logDest != stderr && logDest != stdout) {
     110            fclose(logDest);
     111        }
     112        logDest = stderr;
     113    } else if (fd == 0) {
     114        //        fp = NULL;
     115        if (logDest != NULL && logDest != stderr && logDest != stdout) {
     116            fclose(logDest);
     117        }
    103118        logDest = NULL;
    104119        return true;
    105     }
    106 
    107     if (sscanf(dest, "%4s:%256s", protocol, location) < 2) {
    108         psError(PS_ERR_LOCATION_INVALID, true,
    109                 PS_ERRORTEXT_psLogMsg_DESTINATION_MALFORMED,
    110                 dest);
    111         return false;
    112     }
    113 
    114     if (strcmp(protocol, "dest") == 0) {
    115         if (strcmp(location, "stderr") == 0) {
     120    } else if (fd > 2) {
     121        if (logDest != NULL && logDest != stderr && logDest != stdout) {
     122            fclose(logDest);
     123        }
     124        fp = fdopen(fd, "w");
     125        logDest = fp;
     126        //        fclose(fp);
     127        return true;
     128    }
     129
     130    /*
     131        if (dest == NULL || strcmp(dest, "none") == 0) {
    116132            if (logDest != NULL && logDest != stderr && logDest != stdout) {
    117133                fclose(logDest);
    118134            }
    119             logDest = stderr;
     135            logDest = NULL;
    120136            return true;
    121137        }
    122         if (strcmp(location, "stdout") == 0) {
     138        if (sscanf(dest, "%4s:%256s", protocol, location) < 2) {
     139            psError(PS_ERR_LOCATION_INVALID, true,
     140                    PS_ERRORTEXT_psLogMsg_DESTINATION_MALFORMED,
     141                    dest);
     142            return false;
     143        }
     144    */
     145    /*
     146     
     147        if (strcmp(protocol, "dest") == 0) {
     148            if (strcmp(location, "stderr") == 0) {
     149                if (logDest != NULL && logDest != stderr && logDest != stdout) {
     150                    fclose(logDest);
     151                }
     152                logDest = stderr;
     153                return true;
     154            }
     155            if (strcmp(location, "stdout") == 0) {
     156                if (logDest != NULL && logDest != stderr && logDest != stdout) {
     157                    fclose(logDest);
     158                }
     159                logDest = stdout;
     160                return true;
     161            }
     162            psError(PS_ERR_LOCATION_INVALID, true, PS_ERRORTEXT_psLogMsg_DEST_LOCATION_INVALID,
     163                    location);
     164            return 1;
     165        } else if (strcmp(protocol, "file") == 0) {
     166            FILE *file = fopen(location, "w");
     167     
     168            if (file == NULL) {
     169                psError(PS_ERR_IO, true, PS_ERRORTEXT_psLogMsg_OPEN_FILE_FAILED,
     170                        location);
     171                return false;
     172            }
    123173            if (logDest != NULL && logDest != stderr && logDest != stdout) {
    124174                fclose(logDest);
    125175            }
    126             logDest = stdout;
     176            logDest = file;
    127177            return true;
    128178        }
    129         psError(PS_ERR_LOCATION_INVALID, true, PS_ERRORTEXT_psLogMsg_DEST_LOCATION_INVALID,
    130                 location);
    131         return 1;
    132     } else if (strcmp(protocol, "file") == 0) {
    133         FILE *file = fopen(location, "w");
    134 
    135         if (file == NULL) {
    136             psError(PS_ERR_IO, true, PS_ERRORTEXT_psLogMsg_OPEN_FILE_FAILED,
    137                     location);
    138             return false;
    139         }
    140         if (logDest != NULL && logDest != stderr && logDest != stdout) {
    141             fclose(logDest);
    142         }
    143         logDest = file;
    144         return true;
    145     }
    146 
    147     psError(PS_ERR_LOCATION_INVALID, true, PS_ERRORTEXT_psLogMsg_UNSUPPORTED_PROTOCOL,
    148             protocol);
    149     return false;
     179    */
     180    return true;
     181
    150182}
    151183
Note: See TracChangeset for help on using the changeset viewer.