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

  1. /* GENETEXT.C */
  2.  
  3. /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
  4.  
  5. /* Creates the file ETEXT.C which has the encrypted text strings for use in */
  6. /* Synchronet */
  7.  
  8. #include <stdio.h>
  9.  
  10. void cvtusc(char *str)
  11. {
  12.     int i;
  13.  
  14. for(i=0;str[i];i++)
  15.     if(str[i]=='_')
  16.         str[i]=' ';
  17. }
  18.  
  19. void main()
  20. {
  21.     unsigned char str[129],bits,len;
  22.     unsigned int i,j;
  23.     unsigned long l,m;
  24.     FILE *in,*cout,*hout;
  25.  
  26. if((in=fopen("ETEXT.DAT","rb"))==NULL) {
  27.     printf("can't open ETEXT.DAT\n");
  28.     return; }
  29.  
  30. if((cout=fopen("ETEXT.C","wb"))==NULL) {
  31.     printf("can't create ETEXT.C\n");
  32.     return; }
  33.  
  34. if((hout=fopen("ETEXT.H","wb"))==NULL) {
  35.     printf("can't create ETEXT.H\n");
  36.     return; }
  37.  
  38. fprintf(cout,"/* ETEXT.C */\r\n\r\n#include \"etext.h\"\r\n\r\n");
  39. fprintf(hout,"/* ETEXT.H */\r\n\r\n");
  40. while(!feof(in)) {
  41.     if(!fgets(str,127,in))
  42.         break;
  43.     str[strlen(str)-3]=0;    /* chop off :crlf */
  44.     if(!str[0])
  45.         break;
  46.     fprintf(hout,"extern unsigned long %s[];\r\n",str);
  47.     fprintf(cout,"unsigned long %s[]={ ",str);
  48.     if(!fgets(str,127,in))
  49.         break;
  50.     str[strlen(str)-2]=0;    /* chop off crlf */
  51.     if(!str[0])
  52.         break;
  53.     cvtusc(str);
  54.     len=strlen(str);
  55.     l=len^0x49;
  56.     bits=7;
  57.     for(i=0,j=1;i<len;i++) {
  58.         m=(unsigned long)(str[i]^(i^0x2c));
  59.         l|=(m<<bits);
  60.         bits+=7;
  61.         if(bits>=32) {
  62.             fprintf(cout,"%luUL,",l);
  63.             j++;
  64.             l=0UL;
  65.             bits-=32;
  66.             if(bits)
  67.                 l=(unsigned long)(str[i]^(i^0x2c))>>(7-bits); } }
  68.     fprintf(cout,"%luUL };\r\n",l); }
  69. }
  70.