download b_logs.cpp
Language: C++
Copyright: Copyright 1987-96, Bit Bucket Software Co.
LOC: 171
Project Info
BinkleyTerm XE(btxe)
Server: SourceForge
Type: cvs
...e\b\btxe\btxe\btnt\sources\
   Addr.cpp
   Addr.h
   aglcrc.cpp
   aglcrc.h
   asyn_lnx.cpp
   asyn_os2.cpp
   asyn_w32.cpp
   async.h
   asyos2v1.h
   b_banner.cpp
   b_bbs.cpp
   b_faxrcv.cpp
   b_flofil.cpp
   b_frproc.cpp
   b_help.cpp
   b_initva.cpp
   b_logs.cpp
   b_passwo.cpp
   b_proto.cpp
   b_rspfil.cpp
   b_sbinit.cpp
   b_script.cpp
   b_search.cpp
   b_sessio.cpp
   b_spawn.cpp
   b_term.cpp
   b_termov.cpp
   b_today.cpp
   b_wazoo.cpp
   b_whack.cpp
   b_wzsend.cpp
   banner.cpp
   banner.h
   BasicString.h
   bbs_ctra.cpp
   bbs_data.cpp
   bbs_incl.h
   bbs_io.cpp
   bink.h
   bink_asm.cpp
   binkdlg.cpp
   binkpipe.h
   box.h
   brec.cpp
   bsend.cpp
   bt.cpp
   btconfig.cpp
   btutil.cpp
   buffer.h
   cache.cpp
   cache.h
   callback.cpp
   callerid.cpp
   callwin.cpp
   callwin.h
   capi.cpp
   cfosline.cpp
   chat.cpp
   com.h
   com_dos.h
   com_lnx.h
   com_os2.h
   com_w32.h
   common.cpp
   cpuload.cpp
   css.cpp
   css.h
   data.cpp
   debug.cpp
   debug.h
   defines.h
   dosfuncs.cpp
   emsi.cpp
   emxmxcom.cpp
   evtparse.cpp
   evtsetup.cpp
   exceptio.cpp
   exceptio.h
   Exceptions.cpp
   Exceptions.h
   externs.h
   faxproto.h
   fcfgread.cpp
   fidomail.h
   file_all.cpp
   file_dos.cpp
   file_io.h
   file_lnx.cpp
   file_os2.cpp
   file_w32.cpp
   foffsets.h
   fossil.cpp
   freepoll.cpp
   ftsc.cpp
   gethcomm.h
   heap.cpp
   history.cpp
   history.h
   hydra.cpp
   hydra.h
   includes.cpp
   includes.h
   janus.cpp
   janus.h
   keybd.h
   keyfncs.h
   keymap.cpp
   langload.cpp
   language.h
   lngmagic.h
   m7rec.cpp
   m7send.cpp
   mailer.cpp
   mailovly.cpp
   mailroot.cpp
   maxcomm.h
   maxmcp.cpp
   maxmcp.h
   maxprm.cpp
   mdm_proc.cpp
   misc.cpp
   msgs.h
   Node.cpp
   Node.h
   NodeList.cpp
   NodeList.h
   nodeproc.cpp
   os2_pm.cpp
   outbound.cpp
   pipe.cpp
   pktmsgs.cpp
   pktmsgs.h
   protcomm.cpp
   prototyp.h
   recvbark.cpp
   recvsync.cpp
   sbuf.cpp
   sbuf.h
   sched.cpp
   sched.h
   script2.cpp
   SelfTest.cpp
   SelfTest.h
   sendbark.cpp
   sendsync.cpp
   squish.cpp
   squish.h
   srif.cpp
   statetbl.cpp
   stats.cpp
   stdafx.cpp
   stdafx.h
   timer.cpp
   timer.h
   times.cpp
   types.h
   v7debug.cpp
   version.cpp
   version7.cpp
   version7.h
   vfos_dos.cpp
   vfos_lnx.cpp
   vfos_os2.cpp
   vfos_qnx.cpp
   vfos_w32.cpp
   vfossil.h
   video.h
   vt100.cpp
   vt100.h
   xfer.h
   xmrec.cpp
   xmsend.cpp
   xstring.h
   yoohoo.cpp
   zmodem.cpp
   zmodem.h

/*---------------------------------------------------------------------------*
 *
 *                               BinkleyTerm
 *
 *              (C) Copyright 1987-96, Bit Bucket Software Co.
 *     For license and contact information see /doc/orig_260/license.260.
 *
 *           This version was modified by the BinkleyTerm XE Team.
 *        For contact information see /doc/team.lst and /doc/join.us.
 *  For a complete list of changes see /doc/xe_user.doc and /doc/xe_hist.doc.
 *
 * Filename    : $Source: /cvsroot/btxe/btnt/sources/b_logs.cpp,v $
 * Revision    : $Revision: 1.1 $
 * Tagname     : $Name:  $
 * Last updated: $Date: 2005/01/01 15:18:11 $
 * State       : $State: Exp $
 *
 * Description : log handling
 *
 *---------------------------------------------------------------------------*/

#include "includes.h"

static char *LOCALFUNC status_log_path (void);
static char *LOCALFUNC cost_log_path (void);

static char temp[PATHLEN];      /* MMP 960419 - Ugly, i know :-( */

static char *LOCALFUNC
status_log_path (void)
{
    if (locallogs || log_name == NULL)
        sprintf (temp, "%s%s.l%02x", task_dir, PRDCT_PRFXlower, TaskNumber);
    else
        strntcpy (temp, log_name, PATHLEN);
    return (temp);
}

static char *LOCALFUNC
cost_log_path (void)
{
    if (locallogs || cost_log_name == NULL)
        sprintf (temp, "%s%s.c%02x", task_dir, PRDCT_PRFXlower, TaskNumber);
    else
        strntcpy (temp, cost_log_name, PATHLEN);
    return (temp);
}

static FILE *
movelog (FILE * in, char *localpath, char *globalpath)
{
    FILE *out;
    char *mode;
    int ch;
    int ok = 0;

    if (in == NULL)
        return (NULL);

    fclose (in);

    if ((in = share_fopen (localpath, read_binary, DENY_WRITE)) != NULL)
    {
        if ((out = share_fopen (globalpath, append_binary, DENY_WRITE)) != NULL)
        {
            while ((ch = fgetc (in)) != EOF)
                fputc (ch, out);
            ok = 1;
            if (ferror (in) || ferror (out))
                ok = 0;
            if (fclose (out))
                ok = 0;
        }
        if (fclose (in))
            ok = 0;
    }

    mode = ok ? write_ascii_plus : append_ascii;
    return (share_fopen (localpath, mode, DENY_WRITE));
}


void
openlogs (int newlineflag)
{
    if (log_name && status_log == NULL)
    {
        status_log = share_fopen (status_log_path (), append_ascii, DENY_WRITE);
        if (status_log == NULL)
        {
            printf ("\n%s\n", MSG_TXT (M_NO_LOGFILE));
            free (log_name);
            log_name = NULL;
        }
        else if (newlineflag)
        {                           /* TJW 960527 */
            fprintf (status_log, "\n");
            fflush (status_log);
            real_flush (fileno (status_log));
        }
    }
    if (cost_log_name && cost_log == NULL)
    {
        cost_log = share_fopen (cost_log_path (), append_ascii, DENY_WRITE);
        if (cost_log == NULL)
        {
            printf ("\n%s\n", MSG_TXT (M_NO_COSTFILE));
            free (cost_log_name);
            cost_log_name = NULL;
        }
    }
}

void
read_in_log (void)
{
    char in_line[256], *p, *sp;
    char logchar, logdate[20], logtime[20], logproduct[10], logtext[256];
    int hr, mi, sc, hs, count;
    char logline[256];
    char hundredths[10];
    FILE *fp;

    if (!readlog_name)
        return;

    if ((fp = share_fopen (readlog_name, read_ascii, DENY_WRITE)) != NULL)
    {
        while (!feof (fp))
        {
            if (fgets (in_line, sizeof (in_line), fp) && strlen (in_line) > 1)
            {

                p = in_line;
                p[strlen (p) - 1] = '\0';  /* kill \n at end */

                logchar = *p++;

                sp = p = skip_blanks (p);  /* skip to day start */
                p = skip_to_word (p);   /* skip to month start */
                p = skip_to_blank (p);  /* skip to blank after month */
                *p++ = '\0';            /* terminate here */
                strntcpy (logdate, sp, 20);  /* copy this to logdate */

                sp = p = skip_blanks (p);  /* skip to time start */
                p = skip_to_blank (p);  /* skip to blank after time */
                *p++ = '\0';            /* terminate here */
                hr = mi = sc = -1;
                hs = 0;
                count = sscanf (sp, "%d:%d:%d.%d", &hr, &mi, &sc, &hs);
                if (count < 3
                        || hr < 0 || hr > 24
                        || mi < 0 || mi > 60
                        || sc < 0 || sc > 60
                        || hs < 0 || hs > 100)
                    continue;             /* parsing time failed - continue */

                sp = p = skip_blanks (p);  /* skip to product */
                p = skip_to_blank (p);  /* skip to blank after product */
                *p++ = '\0';            /* terminate here */
                strntcpy (logproduct, sp, 10);  /* copy this to product */

                sp = p = skip_blanks (p);  /* skip to text */
                strntcpy (logtext, sp, 256);  /* copy this to text */

                if (status_log)
                {
                    if (!nologhundredths)
                        sprintf (hundredths, ".%02d", hs);
                    else
                        hundredths[0] = '\0';
                    sprintf (logtime, "%02d:%02d:%02d%s", hr, mi, sc, hundredths);
                    sprintf (logline, "%c %s %s %-4s %s\n",
                             logchar, logdate, logtime, logproduct, logtext);
                    fputs (logline, status_log);
                }

                sprintf (logtime, "%02d:%02d:%02d", hr, mi, sc);
                sprintf (logline, "%c%s", logchar, logtext);
                log_screen (logtime, logline);
            }
        }

        fclose (fp);
        unlink (readlog_name);
    }
}

void
closelogs (void)                /* TJW 960527 */
{
    movelogs ();                  /* MR 970503 */

    if (status_log != NULL)
    {
        fflush (status_log);
        real_flush (fileno (status_log));
        fclose (status_log);        /*mtt 96-05-17 */
        status_log = NULL;
    }

    if (cost_log != NULL)
    {
        fflush (cost_log);
        real_flush (fileno (cost_log));
        fclose (cost_log);          /*mtt 96-05-17 */
        cost_log = NULL;
    }
}

void
movelogs (void)
{
    if (locallogs)
    {
        status_log = movelog (status_log, status_log_path (), log_name);
        cost_log = movelog (cost_log, cost_log_path (), cost_log_name);
    }
}

/* $Id: b_logs.cpp,v 1.1 2005/01/01 15:18:11 vildanov Exp $ */

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us