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

  1. /* This small program imports BGFAX's log file into BT-XE's history file */
  2. /* by C.F.S., 2:341/70 */
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <time.h>
  8.  
  9. typedef unsigned short word;
  10. typedef unsigned char byte;
  11.  
  12. typedef struct _ADDRESS
  13. {
  14.     word Zone;
  15.     word Net;
  16.     word Node;
  17.     word Point;
  18.     char *Domain;
  19. } ADDR, *ADDRP;
  20.  
  21. #include "..\..\include\history.h"
  22.  
  23. /*        1         2         3         4         5         6         7
  24. 01234567890123456789012345678901234567890123456789012345678901234567890123456789
  25. 04-04 13:56 00:48   42351  9600 FAX0101.FAX  5938404                1  Finished
  26. */
  27.  
  28. char length[30],bytes[30],speed[30],filename[30],remoteid[60],pages[20],status[30];
  29.  
  30. char *pack (char *s)
  31. {
  32.     printf ("In: %s\n",s);
  33.     while (*s==' ' || *s=='\n' || *s=='\r')
  34.         strcpy (s,s+1);
  35.     while (s[strlen (s)-1]==' ' || s[strlen (s)-1]=='\n' || s[strlen (s)-1]=='\r')
  36.         s[strlen (s)-1]=0;
  37.     return s;
  38. }
  39.  
  40. int main (int argc,char **argv)
  41. {
  42.     CALLHIST rec;
  43.     FILE *in, *out;
  44.     char *x;
  45.     time_t curtime;
  46.     unsigned task;
  47.     char line[160];
  48.     time (&curtime);
  49.     printf ("BGFAX to BT-XE, 0.0beta, by C.F.S., 2:341/70 - Part of the BT-XE package\n");
  50.     printf ("------------------------------------------------------------------------\n");
  51.     if (argc!=4)
  52.     {
  53.         printf ("Usage: GETBGFAX task_number bgfax_log_file btxe_history_file\n");
  54.         printf ("Example: GETBGFAX 2 P:\\BGFAX\\FAXES\\FAXIN.LOG P:\\BTXE\\TASK\\CALLHIST.ALL\n\n");
  55.         printf ("Make sure you do NOT run this program after every BGFAX run, but only after\n");
  56.         printf ("successfully receiving a fax, otherwise you will get duplicate entries in\n");
  57.         printf ("BT-XE's history. BGFAX exits with errorlevel 4 if a fax has been received.\n");
  58.         printf ("The task number is used for displaying purpuses only - but of course it should\n");
  59.         printf ("be the number of the mailer that has received the fax.\n");
  60.         exit (1);
  61.     }
  62.     task=atoi (argv[1]);
  63.     in=fopen (argv[2],"rb");
  64.     if (in==NULL)
  65.     {
  66.         printf ("Failed to open input file %s\n",argv[1]);
  67.         exit (2);
  68.     }
  69.     fseek (in,-120,SEEK_END);
  70.     line [fread (line,1,120,in)]=0;
  71.     fclose (in);
  72.     if (strchr (line,'\n'))
  73.         strcpy (line,strchr (line,'\n')+1);
  74.     printf ("Read: \n%s\n",line);
  75.     line[5]=line[11]=line[17]=line[25]=line[31]=line[43]=line[65]=
  76.     line[69]=0;
  77.     strcpy (length,line+12);
  78.     strcpy (bytes,line+18);
  79.     strcpy (speed,line+26);
  80.     strcpy (filename,line+32);
  81.     strcpy (remoteid,line+45);
  82.     strcpy (pages,line+66);
  83.     strcpy (status,line+71);
  84.     pack (length);
  85.     pack (bytes);
  86.     pack (speed);
  87.     pack (filename);
  88.     pack (remoteid);
  89.     pack (pages);
  90.     pack (status);
  91.     printf ("Length: %s\n",length);
  92.     printf ("Bytes: %s\n",bytes);
  93.     printf ("Speed: %s\n",speed);
  94.     printf ("Filename: %s\n",filename);
  95.     printf ("Remote ID: %s\n",remoteid);
  96.     printf ("Pages: %s\n",pages);
  97.     printf ("Status: %s\n",status);
  98.     rec.task=task;
  99.     rec.outgoing=0;
  100.     rec.calltype=CT_FAX;
  101.     rec.subclass=0; /* Subclass is currently unused in fax calls */
  102.     *(x=strchr (length,':'))=0;
  103.     rec.length=atoi (length)*60+atoi (x+1);
  104.     rec.starttime=curtime-rec.length;
  105.     strcpy (rec.h.f.remoteid,remoteid);
  106.     rec.h.f.pages=atoi (pages);
  107.     rec.h.f.bytes=atoi (bytes);
  108.     rec.h.f.speed=atoi (speed);
  109.     strcpy (rec.h.f.filename,filename);
  110.     strcpy (rec.h.f.status,status);
  111.     out=fopen (argv[3],"a+b");
  112.     if (out==NULL)
  113.     {
  114.         printf ("Unable to open output file %s\n",argv[3]);
  115.         exit (3);
  116.     }
  117.     fwrite (&rec,1,sizeof (CALLHIST),out);
  118.     fclose (out);
  119.     printf ("Done.\n");
  120.     return 0;
  121. }
  122.