home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / dos / sbbs_src.exe / SBBS / SMM / MAKEMSG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-26  |  1.6 KB  |  71 lines

  1. /* MAKEMSG.C */
  2.  
  3. /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
  4.  
  5. #include <dos.h>
  6. #include <stdio.h>
  7. #include <time.h>
  8. #include "gen_defs.h"
  9.  
  10. /****************************************************************************/
  11. /* Converts a date string in format MM/DD/YY into unix time format            */
  12. /****************************************************************************/
  13. time_t dstrtounix(char *str)
  14. {
  15.     struct date date;
  16.     struct time curtime;
  17.  
  18. if(!strcmp(str,"00/00/00") || !str[0])
  19.     return(NULL);
  20. curtime.ti_hour=curtime.ti_min=curtime.ti_sec=0;
  21. if(str[6]<'7')
  22.     date.da_year=2000+((str[6]&0xf)*10)+(str[7]&0xf);
  23. else
  24.     date.da_year=1900+((str[6]&0xf)*10)+(str[7]&0xf);
  25. date.da_mon=((str[0]&0xf)*10)+(str[1]&0xf);
  26. date.da_day=((str[3]&0xf)*10)+(str[4]&0xf);
  27. return(dostounix(&date,&curtime));
  28. }
  29.  
  30. uchar cryptchar(uchar ch, ulong seed)
  31. {
  32. if(ch==1)
  33.     return(0xfe);
  34. if(ch<0x20 || ch&0x80)    /* Ctrl chars and ex-ASCII are not xlated */
  35.     return(ch);
  36. return(ch^(seed&0x1f));
  37. }
  38.  
  39. int main(int argc, char **argv)
  40. {
  41.     char str[256];
  42.     FILE *in,*out;
  43.     int i,j;
  44.     long l;
  45.  
  46. if(argc<4) {
  47.     printf("usage: makemsg infile outfile mm/dd/yy\n");
  48.     exit(1); }
  49.  
  50. if((in=fopen(argv[1],"rb"))==NULL) {
  51.     printf("error opening %s\n",argv[1]);
  52.     exit(1); }
  53.  
  54. if((out=fopen(argv[2],"wb"))==NULL) {
  55.     printf("error opening %s\n",argv[2]);
  56.     exit(1); }
  57.  
  58. l=dstrtounix(argv[3]);
  59. if(!l) {
  60.     printf("Invalid date %s\n",argv[3]);
  61.     exit(1); }
  62. fprintf(out,"%lx\r\n",l^0x305F6C81UL);
  63. i=ftell(out);
  64. while(!feof(in)) {
  65.     if(!fgets(str,128,in))
  66.         break;
  67.     for(j=0;str[j];j++,i++)
  68.         fputc(cryptchar(str[j],l^(i&7)),out); }
  69. return(0);
  70. }
  71.