home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / bos2_xr5.zip / developr / gethist / ra / getra.c
C/C++ Source or Header  |  1997-06-09  |  3KB  |  113 lines

  1. /* This small program imports RemoteAccess' (and others) LASTCALL.BBS
  2.    into BT-XE's history file */
  3. /* by C.F.S., 2:341/70 */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <time.h>
  9.  
  10. typedef unsigned short word;
  11. typedef unsigned char byte;
  12.  
  13. typedef struct _ADDRESS
  14. {
  15.     word Zone;
  16.     word Net;
  17.     word Node;
  18.     word Point;
  19.     char *Domain;
  20. } ADDR, *ADDRP;
  21.  
  22. #include "..\..\include\history.h"
  23.  
  24. struct /* Lastcall */
  25. {
  26.     byte line;
  27.     char pasname[36];
  28.     char pashandle[36];
  29.     char pascity[26];
  30.     word baud;
  31.     long times;
  32.     char paslogon[6];
  33.     char paslogoff[6];
  34.     byte attribute;
  35. } lastcall;
  36.  
  37. char *pas2c (char *s)
  38. {
  39.     char c;
  40.     c=s[0];
  41.     memmove (s,s+1,c);
  42.     s[c]=0;
  43.     return s;
  44. }
  45.  
  46. char *pack (char *s)
  47. {
  48.     printf ("In: %s\n",s);
  49.     while (*s==' ' || *s=='\n' || *s=='\r')
  50.         strcpy (s,s+1);
  51.     while (s[strlen (s)-1]==' ' || s[strlen (s)-1]=='\n' || s[strlen (s)-1]=='\r')
  52.         s[strlen (s)-1]=0;
  53.     return s;
  54. }
  55.  
  56. int main (int argc,char **argv)
  57. {
  58.     CALLHIST rec;
  59.     FILE *in, *out;
  60.     char *x1,*x2,l1[7],l2[7];
  61.     time_t curtime;
  62.     long calc,len;
  63.     unsigned task;
  64.     char line[160];
  65.     time (&curtime);
  66.     printf ("RemoteAccess to BT-XE, 0.1b, by C.F.S., 2:341/70 - Part of the BT-XE package\n");
  67.     printf ("----------------------------------------------------------------------------\n");
  68.     if (argc!=4)
  69.     {
  70.         printf ("Usage: GETRA task_number bgfax_log_file btxe_history_file\n");
  71.         printf ("Example: GETRA 2 P:\\RA\\LASTCALL.BBS P:\\BTXE\\TASK\\CALLHIST.ALL\n\n");
  72.         exit (1);
  73.     }
  74.     task=atoi (argv[1]);
  75.     in=fopen (argv[2],"rb");
  76.     if (in==NULL)
  77.     {
  78.         printf ("Failed to open input file %s\n",argv[1]);
  79.         exit (2);
  80.     }
  81.     fseek (in,-sizeof (lastcall),SEEK_END);
  82.     fread (&lastcall,1,sizeof (lastcall),in);
  83.     fclose (in);
  84.     pas2c (lastcall.pasname);
  85.     pas2c (lastcall.pashandle);
  86.     pas2c (lastcall.pascity);
  87.     pas2c (lastcall.paslogon);
  88.     pas2c (lastcall.paslogoff);
  89.     rec.task=task;
  90.     rec.outgoing=0;
  91.     rec.calltype=CT_BBS;
  92.     rec.subclass=SC_LASTCALL;
  93.     strcpy (l1,lastcall.paslogon);
  94.     strcpy (l2,lastcall.paslogoff);
  95.     *(x1=strchr (l1,':'))=0;
  96.     *(x2=strchr (l2,':'))=0;
  97.     calc=atoi (l2)*3600+atoi (x2+1)*60;
  98.     calc-=atoi (l1)*3600+atoi (x1+1)*60;
  99.     rec.length=calc;
  100.     rec.starttime=curtime-rec.length;
  101.     memcpy (&rec.h.b1,&lastcall,sizeof (lastcall));
  102.     out=fopen (argv[3],"a+b");
  103.     if (out==NULL)
  104.     {
  105.         printf ("Unable to open output file %s\n",argv[3]);
  106.         exit (3);
  107.     }
  108.     fwrite (&rec,1,sizeof (CALLHIST),out);
  109.     fclose (out);
  110.     printf ("Done.\n");
  111.     return 0;
  112. }
  113.