home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / XGRP_000.SZH / ASSHOLES.C next >
C/C++ Source or Header  |  1991-08-21  |  4KB  |  173 lines

  1. #include "xgroup.h"
  2.  
  3. /* external var references */
  4.  
  5. extern char     buffer[1024];
  6. extern GROUP    *group;
  7. extern CONTROLS control;
  8. extern ADDR     *myaddr;
  9. extern ECHOREC  *echos;
  10. extern ASSHOLE  *assholes;
  11. extern char     *groupin;
  12. extern char     *groupout;
  13. extern char     *grouphold;
  14. extern char     *msgdir;
  15. extern char     *outbound;
  16. extern char     *inbound;
  17. extern char     *archive;
  18. extern char     *unarchive;
  19. extern word     packsize;
  20. extern word     netarea;
  21.  
  22. /* local-only functions */
  23.  
  24. static void _fastcall turn_uls_to_spaces (char *s);
  25. static void _fastcall turn_spaces_to_uls (char *s);
  26.  
  27.  
  28.  
  29.  
  30.  
  31. /*  asshole manager module for XGroup.  an asshole is, in the context of
  32.     this code, someone whose messages you don't want to see. */
  33.  
  34.  
  35. void _fastcall free_assholes (void) {      /* free all area's assholes */
  36.  
  37.     ASSHOLE *anass,*nextass;
  38.  
  39.  
  40.     anass = assholes;
  41.     while(anass) {
  42.         my_free(anass->name);
  43.         nextass = anass->next;
  44.         my_free(anass);
  45.         anass = nextass;
  46.     }
  47.     assholes = NULL;
  48. }
  49.  
  50.  
  51. void _fastcall load_assholes (word areano) {   /* load area asshole file */
  52.  
  53.     ASSHOLE *anass,*lastass;
  54.     char    s[257],*p,*pp;
  55.     int     handle,rewrite = 0;
  56.     time_t  t1;
  57.  
  58.  
  59.     if(assholes) free_assholes();
  60.     sprintf(s,"%s/assholes.%03x",msgdir,areano);
  61.     handle = sopen(s,O_RDONLY | O_BINARY,SH_DENYNO);
  62.     if(handle == -1) return;
  63.     while(!eof(handle)) {
  64.         if(!fgetsx(s,132,handle)) break;
  65.         p = strchr(s,' ');
  66.         if(!p) continue;
  67.         *p = 0;
  68.         p++;
  69.         while(*p && *p == ' ') p++;
  70.         if(!*p || (!strchr(p,'F') && !strchr(p,'T'))) continue;
  71.         pp = strchr(p,' ');
  72.         if(pp) {
  73.             while(*pp && *pp == ' ') pp++;
  74.             if(*pp) {
  75.                 t1 = atol(pp);
  76.                 if(t1 != 0L) {
  77.                     if(t1 < time(NULL)) {   /* assholes expired */
  78.                         rewrite = 1;
  79.                         continue;
  80.                     }
  81.                 }
  82.             }
  83.             else t1 = 0L;
  84.         }
  85.         else t1 = 0L;
  86.         anass = (ASSHOLE *)malloc(sizeof(ASSHOLE));
  87.         if(!anass) {
  88.             close(handle);
  89.             return;
  90.         }
  91.         memset(anass,0,sizeof(ASSHOLE));
  92.         anass->name=strdup(s);
  93.         if(!anass->name) {
  94.             my_free(anass);
  95.             close(handle);
  96.             return;
  97.         }
  98.         turn_uls_to_spaces(anass->name);
  99.         if(strchr(p,'F')) anass->from = 1;
  100.         if(strchr(p,'T')) anass->to   = 1;
  101.         if(strchr(p,'K')) anass->del  = 1;
  102.         if(strchr(p,'N')) anass->noin = 1;
  103.         anass->expire = t1;
  104.         if(!assholes) {
  105.             assholes = anass;
  106.         }
  107.         else {
  108.             lastass->next = anass;
  109.         }
  110.         lastass = anass;
  111.         anass->next = NULL;
  112.     }
  113.     close(handle);
  114.     if(rewrite) rewrite_assholes(areano);
  115. }
  116.  
  117.  
  118.  
  119. void _fastcall rewrite_assholes (word areano) {    /* rewrite area asshole file */
  120.  
  121.     ASSHOLE *anass;
  122.     char s[257];
  123.     int handle;
  124.  
  125.  
  126.     sprintf(s,"%s/assholes.%03x",msgdir,areano);
  127.     unlink(s);
  128.     if(!assholes) {
  129.         return;
  130.     }
  131.     handle = sopen(s,O_RDWR | O_BINARY | O_CREAT,SH_DENYWR,S_IWRITE);
  132.     if(handle == -1) {
  133.         return;
  134.     }
  135.     anass = assholes;
  136.     while(anass && anass->name) {
  137.         turn_spaces_to_uls(anass->name);
  138.         ffprintf(handle,"%s ",anass->name);
  139.         turn_uls_to_spaces(anass->name);
  140.         if(anass->from) write(handle,"F",1);
  141.         if(anass->to) write(handle,"T",1);
  142.         if(anass->del) write(handle,"K",1);
  143.         if(anass->noin) write(handle,"N",1);
  144.         ffprintf(handle," %lu\r\n",anass->expire);
  145.         anass = anass->next;
  146.     }
  147.     if(tell(handle) == 0L) {
  148.         close(handle);
  149.         unlink(s);
  150.     }
  151.     else close(handle);
  152. }
  153.  
  154.  
  155.  
  156.  
  157. static void _fastcall turn_uls_to_spaces (char *s) {
  158.  
  159.     while(s && *s) {
  160.         if(*s == '_') *s = ' ';
  161.         s++;
  162.     }
  163. }
  164.  
  165.  
  166. static void _fastcall turn_spaces_to_uls (char *s) {
  167.  
  168.     while(s && *s) {
  169.         if(*s == ' ') *s = '_';
  170.         s++;
  171.     }
  172. }
  173.