home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d832 / term.lha / Term / term-3.1-Source.lha / termCall.c < prev    next >
C/C++ Source or Header  |  1993-02-12  |  3KB  |  172 lines

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