home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: DFÜ und Kommunikation / SOS-DFUE.ISO / programm / dos / utility / pccp076 / messin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-12  |  3.5 KB  |  184 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  *    MicroSoft QuickC
  3.  */
  4.  
  5. #include<stdio.h>
  6. #include<bios.h>
  7. #include<dos.h>
  8. #include<fcntl.h>
  9. #include<sys\types.h>
  10. #include<sys\stat.h>
  11. #include<signal.h>
  12. #include<process.h>
  13. #include<time.h>
  14. #include"port.h"
  15.  
  16. sendchar(c)
  17.     unsigned char c;
  18.     {
  19.     while(!((inp(basereg+STATREG)&TXMTMASK)&&(inp(basereg+MSTATREG)&CTSMASK)))
  20.         if(kbhit())
  21.             getch();
  22.     outp(basereg, c);
  23.     }
  24.  
  25. int follow;
  26.  
  27. quit()
  28.     {
  29.     cleanup(0);
  30.     exit(99);
  31.     }
  32.  
  33. sendstr(str)
  34.     char *str;
  35.     {
  36.     int i;
  37.     for(i=0;str[i]!='\0';++i)
  38.         if(str[i]=='\n')
  39.             {
  40.             sendchar('\r');
  41.             sendchar('\n');
  42.             }
  43.         else
  44.             sendchar(str[i]);
  45.     }
  46.  
  47. portgets(str)
  48.     char *str;
  49.     {
  50.     int i;
  51.     i=0;
  52.     while(i<255)
  53.         {
  54.         while(follow==index)
  55.             {
  56.             if(!(inp(basereg+MSTATREG)&DCDMASK))
  57.                 return(-1);
  58.             if(kbhit())
  59.                 getch();
  60.             }
  61.         str[i]=buf[follow++];
  62.         if(follow>=TBUFSIZ)
  63.             follow=0;
  64.         if(str[i]=='\b')
  65.             if(i>0)
  66.                 {
  67.                 i-=2;
  68.                 sendchar('\b');
  69.                 sendchar(' ');
  70.                 sendchar('\b');
  71.                 }
  72.             else
  73.                 {
  74.                 i--;
  75.                 sendchar(0x07);
  76.                 }
  77.         else
  78.             sendchar(str[i]);
  79.         if((str[i]=='\r')||(str[i]=='\n'))
  80.             {
  81.             sendchar('\r');
  82.             sendchar('\n');
  83.             str[i]='\0';
  84.             break;
  85.             }
  86.         i++;
  87.         }
  88.     str[255]='\0';
  89.     return(0);
  90.     }
  91.         
  92. main(argc, argv)
  93.     int argc;
  94.     char **argv;
  95.     {
  96.     FILE *fd;
  97.     long timestamp;
  98.     struct tm *tstructptr;
  99.     int i, j, outfd, ok, c, run, result, maxlines;
  100.     char str[256];
  101.     index=follow=0;
  102.     printf("Copyright (C) 1992 Peter Edward Cann, all rights reserved.\n");
  103.     if(!strcmp(getenv("REMOTE"), "YES"))
  104.         {
  105.         printf("You appear to be already logged in remotely, judging by the environment\n");
  106.         printf("variable REMOTE, so this is probably a very bad idea.\n");
  107.         printf("Are you sure you want to run MESSIN? (y or n) --> ");
  108.         if(getchar()!='y') /* Note getchar() and not getch()! */
  109.             {
  110.             printf("I didn't think so!\n");
  111.             exit(99);
  112.             }
  113.         else
  114.             printf("OK, you're the boss!");
  115.         }
  116.     printf("Control-C to Exit.\n");
  117.     if(argc!=6)
  118.         {
  119.         printf("USAGE: messin <comnum> <bps> <file> <max file bytes> <max message lines>\n");
  120.         exit(10);
  121.         }
  122.     comnum=atoi(argv[1])-1;
  123.     speed=atoi(argv[2]);
  124.     databits='8';
  125.     parity='n';
  126.     stopbits='1';
  127.     setport();
  128.     readset();
  129.     setup();
  130.     signal(SIGINT, quit);
  131.     if((fd=fopen(argv[3], "a"))==NULL)
  132.         {
  133.         sprintf(str, "Sorry, can't open the file.\n");
  134.         sendstr(str);
  135.         printf("Error opening MESSIN file.\n");
  136.         exit(11);
  137.         }
  138.     if(filelength(fd)>atol(argv[4]))
  139.         {
  140.         sprintf(str, "Sorry, the file has reached its limit.\n");
  141.         sendstr(str);
  142.         exit(12);
  143.         }
  144.     maxlines=atoi(argv[5]);
  145.     sprintf(str, "\nEnter your name: --> ");
  146.     sendstr(str);
  147.     timestamp=time(NULL);
  148.     tstructptr=localtime(×tamp);
  149.     if(portgets(str)==-1)
  150.         {
  151.         printf("Lost carrier detect.\n");
  152.         exit(13);
  153.         }
  154.     fprintf(fd, "\nFROM: %s\nDATE: %02d.%02d.%02d/%02d:%02d\n", str,
  155.         tstructptr->tm_year,
  156.         (tstructptr->tm_mon)+1,
  157.         tstructptr->tm_mday,
  158.         tstructptr->tm_hour,
  159.         tstructptr->tm_min);
  160.     printf("Message comming in from %s:\n", str);
  161.     sprintf(str, "End message with a line containing only period (.).\n\n");
  162.     sendstr(str);
  163.     i=0;
  164.     while(portgets(str)!=-1)
  165.         {
  166.         if((strlen(str)==1)&&(str[0]=='.'))
  167.             exit(0);
  168.         printf("%s\n", str);
  169.         fprintf(fd, "%s\n", str);
  170.         if(i==(maxlines-5))
  171.             {
  172.             sprintf(str, "*** %d LINES REMAIN BEFORE LIMIT IS REACHED ***\n", maxlines-i);
  173.             sendstr(str);
  174.             }
  175.         if(i>=maxlines)
  176.             {
  177.             sprintf(str, "*** LENGTH LIMIT REACHED ***\n");
  178.             sendstr(str);
  179.             exit(14);
  180.             }
  181.         }
  182.     exit(0);
  183.     }
  184.