home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / comm / term23_2.lha / Source_Code / termSource / termCall.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  3KB  |  170 lines

  1. /*
  2. **    $Id: termCall.c,v 1.3 92/08/15 20:13:42 olsen Sta Locker: olsen $
  3. **    $Revision: 1.3 $
  4. **    $Date: 92/08/15 20:13:42 $
  5. **
  6. **    NComm-compatible log file maintenance routines
  7. **
  8. **    Copyright © 1990-1992 by Olaf `Olsen' Barthel & MXM
  9. **        All Rights Reserved
  10. */
  11.  
  12. #include "termGlobal.h"
  13.  
  14.     /* Some local variables. */
  15.  
  16. STATIC BPTR        CallFile;
  17. STATIC struct timeval    CallTime;
  18.  
  19.     /* CallDate():
  20.      *
  21.      *    Add the current date and time to the logfile.
  22.      */
  23.  
  24. STATIC VOID
  25. CallDate()
  26. {
  27.         /* Days of the week. */
  28.  
  29.     STATIC STRPTR CallDays[7] =
  30.     {
  31.         "Sun","Mon","Tue","Wed","Thu","Fri","Sat"
  32.     };
  33.  
  34.         /* Months of the year. */
  35.  
  36.     STATIC STRPTR CallMonths[12] =
  37.     {
  38.         "Jan","Feb","Mar","Apr","Mai","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
  39.     };
  40.  
  41.     struct DateStamp __aligned    Date;
  42.     struct ClockData        ClockData;
  43.  
  44.         /* Obtain current date. */
  45.  
  46.     DateStamp(&Date);
  47.  
  48.         /* Convert time and date. */
  49.  
  50.     Amiga2Date((Date . ds_Days * 86400) + (Date . ds_Minute * 60) + (Date . ds_Tick / TICKS_PER_SECOND),&ClockData);
  51.  
  52.         /* Add the date line. */
  53.  
  54.     FPrintf(CallFile,"%s %s %2ld %02ld:%02ld:%02ld %ld\n",CallDays[ClockData . wday - 1],CallMonths[ClockData . month - 1],ClockData . mday,ClockData . hour,ClockData . min,ClockData . sec,ClockData . year);
  55. }
  56.  
  57.     /* MakeCall(struct PhoneEntry *Entry):
  58.      *
  59.      *    Register a new phone call.
  60.      */
  61.  
  62. VOID
  63. MakeCall(STRPTR Name,STRPTR Number)
  64. {
  65.         /* End previous entry. */
  66.  
  67.     if(CallFile)
  68.         StopCall(FALSE);
  69.  
  70.     if(Config . NCommLog)
  71.     {
  72.         STRPTR File;
  73.  
  74.         strcpy(SharedBuffer,Config . LogFile);
  75.  
  76.         if(File = PathPart(SharedBuffer))
  77.             *File = 0;
  78.  
  79.         if(AddPart(SharedBuffer,"term-call.log",256))
  80.         {
  81.                 /* Open logfile for writing. */
  82.  
  83.             if(CallFile = Open(SharedBuffer,MODE_READWRITE))
  84.             {
  85.                     /* Seek to the end of it (append). */
  86.  
  87.                 if(Seek(CallFile,0,OFFSET_END) != -1)
  88.                 {
  89.                         /* Get current system time. */
  90.  
  91.                     TimeRequest -> tr_node . io_Command = TR_GETSYSTIME;
  92.  
  93.                     DoIO(TimeRequest);
  94.  
  95.                         /* Remember the starting time, we will need
  96.                          * it later.
  97.                          */
  98.  
  99.                     CallTime = TimeRequest -> tr_time;
  100.  
  101.                         /* Add the title line. */
  102.  
  103.                     FPrintf(CallFile,"%s (%s)\n--------------------------------\nLogin:  ",Name,Number);
  104.  
  105.                         /* Make the line complete. */
  106.  
  107.                     CallDate();
  108.                 }
  109.                 else
  110.                 {
  111.                     Close(CallFile);
  112.  
  113.                     CallFile = NULL;
  114.                 }
  115.             }
  116.         }
  117.     }
  118. }
  119.  
  120.     /* StopCall(BYTE Finish):
  121.      *
  122.      *    End the current phone call.
  123.      */
  124.  
  125. VOID
  126. StopCall(BYTE Finish)
  127. {
  128.         /* Is a call currently being made? */
  129.  
  130.     if(CallFile)
  131.     {
  132.         struct timeval StopTime;
  133.  
  134.             /* Get current system time. */
  135.  
  136.         TimeRequest -> tr_node . io_Command = TR_GETSYSTIME;
  137.  
  138.         DoIO(TimeRequest);
  139.  
  140.             /* Remember it. */
  141.  
  142.         StopTime = TimeRequest -> tr_time;
  143.  
  144.             /* Subtract the starting time from it. */
  145.  
  146.         SubTime(&StopTime,&CallTime);
  147.  
  148.             /* Add the info line. */
  149.  
  150.         if(Finish)
  151.             FPrintf(CallFile,"*** term exited before logout: ");
  152.         else
  153.             FPrintf(CallFile,"Logout: ");
  154.  
  155.             /* Make the line complete. */
  156.  
  157.         CallDate();
  158.  
  159.             /* Add the online time. */
  160.  
  161.         FPrintf(CallFile,"Time online: %02ld:%02ld:%02ld\n\n",(StopTime . tv_secs % 86400) / 3600,(StopTime . tv_secs % 3600) / 60,StopTime . tv_secs % 60);
  162.  
  163.             /* Finis... */
  164.  
  165.         Close(CallFile);
  166.  
  167.         CallFile = NULL;
  168.     }
  169. }
  170.