home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / bbs / termv4.6 / extras / source / term-source.lha / Call.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  3.0 KB  |  163 lines

  1. /*
  2. **    Call.c
  3. **
  4. **    CallInfo-compatible log file maintenance routines
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #ifndef _GLOBAL_H
  11. #include "Global.h"
  12. #endif
  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(VOID)
  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","May","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 %02ld %02ld:%02ld:%02ld %ld\n",CallDays[ClockData . wday],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.         /* Get current system time. */
  71.  
  72.     GetSysTime(&CallTime);
  73.  
  74.         /* Call logging enabled? */
  75.  
  76.     if(Config -> CaptureConfig -> LogCall && Config -> CaptureConfig -> CallLogFileName[0])
  77.     {
  78.             /* Open logfile for writing. */
  79.  
  80.         if(CallFile = Open(Config -> CaptureConfig -> CallLogFileName,MODE_READWRITE))
  81.         {
  82.                 /* Seek to the end of it (append). */
  83.  
  84.             if(Seek(CallFile,0,OFFSET_END) != -1)
  85.             {
  86.                     /* Add the title line. */
  87.  
  88.                 FPrintf(CallFile,"%s (%s)\n--------------------------------\nLogin:  ",Name,Number);
  89.  
  90.                     /* Make the line complete. */
  91.  
  92.                 CallDate();
  93.             }
  94.             else
  95.             {
  96.                 Close(CallFile);
  97.  
  98.                 CallFile = NULL;
  99.             }
  100.         }
  101.     }
  102. }
  103.  
  104.     /* StopCall(BOOLEAN Finish):
  105.      *
  106.      *    End the current phone call.
  107.      */
  108.  
  109. VOID
  110. StopCall(BOOL Finish)
  111. {
  112.         /* Is a call currently being made? */
  113.  
  114.     if(CallFile)
  115.     {
  116.         struct timeval    StopTime;
  117.         BOOL        GotName;
  118.  
  119.             /* Get current system time. */
  120.  
  121.         GetSysTime(&StopTime);
  122.  
  123.             /* Subtract the starting time from it. */
  124.  
  125.         SubTime(&StopTime,&CallTime);
  126.  
  127.             /* Add the info line. */
  128.  
  129.         if(Finish)
  130.             FPrintf(CallFile,"*** term exited before logout: ");
  131.         else
  132.             FPrintf(CallFile,"Logout: ");
  133.  
  134.             /* Make the line complete. */
  135.  
  136.         CallDate();
  137.  
  138.             /* Get the file name. */
  139.  
  140.         GotName = NameFromFH(CallFile,SharedBuffer,MAX_FILENAME_LENGTH);
  141.  
  142.             /* Add the online time. */
  143.  
  144.         FPrintf(CallFile,"Time online: %02ld:%02ld:%02ld\n\n",(StopTime . tv_secs % 86400) / 3600,(StopTime . tv_secs % 3600) / 60,StopTime . tv_secs % 60);
  145.  
  146.             /* Finis... */
  147.  
  148.         Close(CallFile);
  149.  
  150.         CallFile = NULL;
  151.  
  152.             /* Clear the `executable' bit. */
  153.  
  154.         if(GotName)
  155.         {
  156.             AddProtection(SharedBuffer,FIBF_EXECUTE);
  157.  
  158.             if(Config -> MiscConfig -> CreateIcons)
  159.                 AddIcon(SharedBuffer,FILETYPE_TEXT,TRUE);
  160.         }
  161.     }
  162. }
  163.