home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / HSRC_117.ZIP / MODERATE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-24  |  14.0 KB  |  490 lines

  1. #include "msgg.h"
  2. #include "twindow.h"
  3. #include "keys.h"
  4. #include "headedit.h"
  5.  
  6.     struct tracker {
  7.         char *str;
  8.         word x;
  9.         struct tracker *next;
  10.     };
  11.  
  12. extern WINDOW *ewnd;
  13.  
  14. extern char pascal ask_question(char *);
  15. struct tracker * pascal sort_tracker (struct tracker *);
  16. void pascal free_trackers(struct tracker *);
  17.  
  18.  
  19.  
  20. void pascal do_breakdown (void) {
  21.  
  22.     WINDOW *wnd;
  23.     char *hold,*tempo,*p;
  24.     char appendto=0;
  25.     struct ffblk f;
  26.     char fname[81];
  27.     char m[81];
  28.     word from,to,tempmessno,percent;
  29.     struct tracker *froms,*tos,*subjs,*origins,*tf,*tt,*ts,*too,*ttt;
  30.     int prnthandle=0;
  31.     long total,counter,scanned;
  32.  
  33.     froms=tos=subjs=origins=tf=tt=ts=too=NULL;
  34.     sprintf(m,"%01u",messno);
  35.     from=(word)atol(get_string(" Start at which #:",5,m,'N'));
  36.     if(from<1 || from>nomess) return;
  37.     sprintf(m,"%01u",nomess);
  38.     to=(word)atol(get_string(" End at which #:",5,m,'N'));
  39.     if(to<from) to=nomess;
  40.     sprintf(m,"ECHOBDN.%03x",currarea->number);
  41.     strcpy(fname,get_string(" Export filename: ",78,m,'A'));
  42.     if(!findfirst(fname,&f,0)) {
  43.         sprintf(m," %1.55s exists...overwrite? (Y/n)",fname);
  44.         tempmessno=ask_question(m);
  45.         if(tempmessno=='N' || tempmessno==ESC) appendto=1;
  46.         set_help("",0,0);
  47.     }
  48.     tempmessno=messno;
  49.  
  50.     _anymsg(" Working... ","                    ");
  51.     scanned=0L;
  52.     for(messno=from;messno<(to+1);messno++) {
  53.         wcursor(ewnd,0,0);
  54.         wprintf(ewnd," %01u  %01lu",messno,farcoreleft());
  55.         get_mess(0);
  56.         if(msg.m_attr & MSGDELETED) continue;
  57.         scanned++;
  58.         if((currarea->attr & ECHO) || (currarea->attr & ALTECHO)) {
  59.           hold=get_text();
  60.           if(hold) {
  61.             tempo=strstr(hold,"\r * Origin: ");
  62.             if(!tempo)tempo=strstr(hold,"\n * Origin: ");
  63.             if(tempo) {
  64.                 tempo+=12;
  65.                 p=strchr(tempo,'\r');
  66.                 if(p) *p=0;
  67.                 tempo=strrchr(tempo,'(');
  68.                 if(!tempo) goto SkipOrigins;
  69.                 tempo++;
  70.                 p=strchr(tempo,')');
  71.                 if(p)*p=0;
  72.                 rstrip(tempo);
  73.                 p=lstrip(tempo);
  74.                 while(*p!=' ' && *p)p++;
  75.                 if(*p==' ') {
  76.                     while(*p==' ')p++;
  77.                     tempo=p;
  78.                 }
  79.                 if(!tempo || !*tempo) goto SkipOrigins;
  80.                 if(origins) {
  81.                     ttt=origins;
  82.                     while(ttt) {
  83.                         if(!stricmp(ttt->str,tempo)) {
  84.                             ttt->x++;
  85.                             goto SkipOrigins;
  86.                         }
  87.                         ttt=ttt->next;
  88.                     }
  89.                 }
  90.                 ttt=(struct tracker *)malloc(sizeof(struct tracker));
  91.                 if(!ttt) {
  92.  
  93.                 }
  94.                 else {
  95.                     ttt->str=strdup(tempo);
  96.                     ttt->x=1;
  97.                     ttt->next=NULL;
  98.                     if(!origins) {
  99.                         origins=ttt;
  100.                         too=origins;
  101.                     }
  102.                     else {
  103.                         too->next=ttt;
  104.                         too=ttt;
  105.                     }
  106.                 }
  107.             }
  108. SkipOrigins:
  109.             if(hold)farfree(hold);
  110.           }
  111.         }
  112.         if(froms) {
  113.             ttt=froms;
  114.             while(ttt) {
  115.                 if(!stricmp(ttt->str,msg.from)) {
  116.                     ttt->x++;
  117.                     goto SkipFroms;
  118.                 }
  119.                 ttt=ttt->next;
  120.             }
  121.         }
  122.         ttt=(struct tracker *)malloc(sizeof(struct tracker));
  123.         if(!ttt) {
  124.  
  125.         }
  126.         else {
  127.             ttt->str=strdup(lstrip(rstrip(msg.from)));
  128.             ttt->x=1;
  129.             ttt->next=NULL;
  130.             if(!froms) {
  131.                 froms=ttt;
  132.                 tf=froms;
  133.             }
  134.             else {
  135.                 tf->next=ttt;
  136.                 tf=ttt;
  137.             }
  138.         }
  139. SkipFroms:
  140.         if(tos) {
  141.             ttt=tos;
  142.             while(ttt) {
  143.                 if(!stricmp(ttt->str,msg.to)) {
  144.                     ttt->x++;
  145.                     goto SkipTos;
  146.                 }
  147.                 ttt=ttt->next;
  148.             }
  149.         }
  150.         ttt=(struct tracker *)malloc(sizeof(struct tracker));
  151.         if(!ttt) {
  152.  
  153.         }
  154.         else {
  155.             ttt->str=strdup(lstrip(rstrip(msg.to)));
  156.             ttt->x=1;
  157.             ttt->next=NULL;
  158.             if(!tos) {
  159.                 tos=ttt;
  160.                 tt=tos;
  161.             }
  162.             else {
  163.                 tt->next=ttt;
  164.                 tt=ttt;
  165.             }
  166.         }
  167. SkipTos:
  168.         if(subjs) {
  169.             ttt=subjs;
  170.             while(ttt) {
  171.                 p=msg.subj;
  172.                 while(*p==' ')p++;
  173.                 if(!strnicmp(p,"RE:",3)) {
  174.                     p+=3;
  175.                     while(*p==' ')p++;
  176.                 }
  177.                 if(!stricmp(ttt->str,p)) {
  178.                     ttt->x++;
  179.                     goto SkipSubjs;
  180.                 }
  181.                 ttt=ttt->next;
  182.             }
  183.         }
  184.         ttt=(struct tracker *)malloc(sizeof(struct tracker));
  185.         if(!ttt) {
  186.  
  187.         }
  188.         else {
  189.             p=msg.subj;
  190.             while(*p==' ')p++;
  191.             if(!strnicmp(p,"RE:",3)) {
  192.                 p+=3;
  193.                 while(*p==' ')p++;
  194.             }
  195.             ttt->str=strdup(lstrip(rstrip(p)));
  196.             ttt->x=1;
  197.             ttt->next=NULL;
  198.             if(!subjs) {
  199.                 subjs=ttt;
  200.                 ts=subjs;
  201.             }
  202.             else {
  203.                 ts->next=ttt;
  204.                 ts=ttt;
  205.             }
  206.         }
  207. SkipSubjs:
  208. ;
  209.     }
  210.  
  211.     wprintf(ewnd,"\n Sorting ");
  212.     if(froms) froms=sort_tracker(froms);
  213.     if(tos) tos=sort_tracker(tos);
  214.     if(subjs) subjs=sort_tracker(subjs);
  215.     if(origins) origins=sort_tracker(origins);
  216.  
  217.     clear_message();
  218.     wnd=establish_window(7,5,maxy-5,80);
  219.     set_title(wnd," Msg area breakdown ");
  220.     set_colors(wnd,ALL,BLACK,WHITE,BRIGHT);
  221.     set_colors(wnd,ACCENT,WHITE,BLACK,BRIGHT);
  222.     set_colors(wnd,BORDER,BLACK,AQUA,DIM);
  223.     set_colors(wnd,TITLE,BLACK,AQUA,BRIGHT);
  224.     display_window(wnd);
  225.     wcursor(wnd,0,0);
  226.  
  227.     if(!stricmp(fname,"PRN")) {
  228.         _AH=2;
  229.         _DX=0;
  230.         geninterrupt(0x17);
  231.         if (_AH!=144) {
  232.             error_message(" Printer not ready ");
  233.             pause();
  234.             _AH=2;
  235.             _DX=0;
  236.             geninterrupt(0x17);
  237.             if(_AH!=144) prnthandle = -1;
  238.         }
  239.     }
  240.     if(!prnthandle && *fname) {
  241.         if(!appendto)unlink(fname);
  242.         prnthandle=_open(fname,O_WRONLY | O_BINARY | O_DENYWRITE);
  243.         if(prnthandle== -1) prnthandle=creat(fname,S_IWRITE);
  244.     }
  245.  
  246.     if(prnthandle!= -1) {
  247.         if(stricmp(fname,"PRN") && appendto) lseek(prnthandle,0L,SEEK_END);
  248.         ffprintf(prnthandle,"\r\n\r\n Date:  %s\r\n",fidodate());
  249.         ffprintf(prnthandle,"\r\n Summary of echo area #%u  \"%s\":\r\n Scanned %lu msgs\r\n\r\n",currarea->number,currarea->name,scanned);
  250.     }
  251.     else prnthandle= -1;
  252.     wprintf(wnd,"Summary of echo area #%u  \"%s\":\nScanned %lu msgs\n\n",currarea->number,currarea->name,scanned);
  253.  
  254.     if(froms) {
  255.         counter=total=0L;
  256.         if(prnthandle!= -1) {
  257.             ffprintf(prnthandle,"Author                                 #posts\r\n");
  258.             ffprintf(prnthandle,"=============================================\r\n");
  259.         }
  260.         wprintf(wnd,"Author                                 #posts\n");
  261.         wprintf(wnd,"=============================================\n");
  262.         tt=froms;
  263.         while(tt) {
  264.           if(tt->str) {
  265.             if(prnthandle!= -1) {
  266.                 ffprintf(prnthandle,"%-40.40s%5u",tt->str,tt->x);
  267.             }
  268.             wprintf(wnd,"%-40.40s%5u",tt->str,tt->x);
  269.             percent=(word)(((long)tt->x * 100L) / scanned);
  270.             if(percent) {
  271.                 if(prnthandle!= -1) {
  272.                     ffprintf(prnthandle,"  (%u%%)",percent);
  273.                 }
  274.                 wprintf(wnd,"  (%u%%)",percent);
  275.             }
  276.             if(prnthandle != -1) {
  277.                 ffprintf(prnthandle,"\r\n");
  278.             }
  279.             wprintf(wnd,"\n");
  280.             total+=(long)tt->x;
  281.             counter++;
  282.           }
  283.           tt=tt->next;
  284.         }
  285.         if(prnthandle!= -1) {
  286.             ffprintf(prnthandle,"=============================================\r\n");
  287.             ffprintf(prnthandle,"Totals:  %5lu                          %5lu\r\n\r\n",counter,total);
  288.         }
  289.         wprintf(wnd,"=============================================\n");
  290.         wprintf(wnd,"Totals:  %5lu                          %5lu\n\n",counter,total);
  291.     }
  292.     if(tos) {
  293.         counter=total=0L;
  294.         if(prnthandle!= -1) {
  295.             ffprintf(prnthandle,"Recipient                               #msgs\r\n");
  296.             ffprintf(prnthandle,"=============================================\r\n");
  297.         }
  298.         wprintf(wnd,"Recipient                               #msgs\n");
  299.         wprintf(wnd,"=============================================\n");
  300.         tt=tos;
  301.         while(tt) {
  302.           if(tt->str) {
  303.             if(prnthandle!= -1) {
  304.                 ffprintf(prnthandle,"%-40.40s%5u",tt->str,tt->x);
  305.             }
  306.             wprintf(wnd,"%-40.40s%5u",tt->str,tt->x);
  307.             percent=(word)(((long)tt->x * 100L) / scanned);
  308.             if(percent) {
  309.                 if(prnthandle!= -1) {
  310.                     ffprintf(prnthandle,"  (%u%%)",percent);
  311.                 }
  312.                 wprintf(wnd,"  (%u%%)",percent);
  313.             }
  314.             if(prnthandle != -1) {
  315.                 ffprintf(prnthandle,"\r\n");
  316.             }
  317.             wprintf(wnd,"\n");
  318.             total+=(long)tt->x;
  319.             counter++;
  320.           }
  321.           tt=tt->next;
  322.         }
  323.         if(prnthandle!= -1) {
  324.             ffprintf(prnthandle,"=============================================\r\n");
  325.             ffprintf(prnthandle,"Totals:  %5lu                          %5lu\r\n\r\n",counter,total);
  326.         }
  327.         wprintf(wnd,"=============================================\n");
  328.         wprintf(wnd,"Totals:  %5lu                          %5lu\n\n",counter,total);
  329.     }
  330.     if(subjs) {
  331.         counter=total=0L;
  332.         if(prnthandle!= -1) {
  333.             ffprintf(prnthandle,"Subject                                                    #times\r\n");
  334.             ffprintf(prnthandle,"=================================================================\r\n");
  335.         }
  336.         wprintf(wnd,"Subject                                                    #times\n");
  337.         wprintf(wnd,"=================================================================\n");
  338.         tt=subjs;
  339.         while(tt) {
  340.           if(tt->str) {
  341.             if(prnthandle!= -1) {
  342.                 ffprintf(prnthandle,"%-60.60s%5u",tt->str,tt->x);
  343.             }
  344.             wprintf(wnd,"%-60.60s%5u",tt->str,tt->x);
  345.             percent=(word)(((long)tt->x * 100L) / scanned);
  346.             if(percent) {
  347.                 if(prnthandle!= -1) {
  348.                     ffprintf(prnthandle,"  (%u%%)",percent);
  349.                 }
  350.                 wprintf(wnd,"  (%u%%)",percent);
  351.             }
  352.             if(prnthandle != -1) {
  353.                 ffprintf(prnthandle,"\r\n");
  354.             }
  355.             wprintf(wnd,"\n");
  356.             total+=(long)tt->x;
  357.             counter++;
  358.           }
  359.           tt=tt->next;
  360.         }
  361.         if(prnthandle!= -1) {
  362.             ffprintf(prnthandle,"=================================================================\r\n");
  363.             ffprintf(prnthandle,"Totals:  %5lu                                              %5lu\r\n\r\n",counter,total);
  364.         }
  365.         wprintf(wnd,"=================================================================\n");
  366.         wprintf(wnd,"Totals:  %5lu                                              %5lu\n\n",counter,total);
  367.     }
  368.     if(origins) {
  369.         counter=total=0L;
  370.         if(prnthandle!= -1) {
  371.             ffprintf(prnthandle,"Origin                       #posts\r\n");
  372.             ffprintf(prnthandle,"===================================\r\n");
  373.         }
  374.         wprintf(wnd,"Origin                       #posts\n");
  375.         wprintf(wnd,"===================================\n");
  376.         tt=origins;
  377.         while(tt) {
  378.           if(tt->str) {
  379.             if(prnthandle!= -1) {
  380.                 ffprintf(prnthandle,"%-30.30s%5u",tt->str,tt->x);
  381.             }
  382.             wprintf(wnd,"%-30.30s%5u",tt->str,tt->x);
  383.             percent=(word)(((long)tt->x * 100L) / scanned);
  384.             if(percent) {
  385.                 if(prnthandle!= -1) {
  386.                     ffprintf(prnthandle,"  (%u%%)",percent);
  387.                 }
  388.                 wprintf(wnd,"  (%u%%)",percent);
  389.             }
  390.             if(prnthandle != -1) {
  391.                 ffprintf(prnthandle,"\r\n");
  392.             }
  393.             wprintf(wnd,"\n");
  394.             total+=(long)tt->x;
  395.             counter++;
  396.           }
  397.           tt=tt->next;
  398.         }
  399.         wprintf(wnd,"===================================\n");
  400.         wprintf(wnd,"Totals:  %5lu                %5lu",counter,total);
  401.         if(prnthandle!= -1) {
  402.             ffprintf(prnthandle,"===================================\r\n");
  403.             ffprintf(prnthandle,"Totals:  %5lu                %5lu\r\n\r\n",counter,total);
  404.         }
  405.     }
  406.     if(prnthandle && prnthandle!= -1)_close(prnthandle);
  407.     if(froms) free_trackers(froms);
  408.     if(tos) free_trackers(tos);
  409.     if(subjs)free_trackers(subjs);
  410.     if(origins)free_trackers(origins);
  411.  
  412.     _anymsg(" Complete "," Any key ");
  413.     pause();
  414.     delete_window(wnd);
  415.     messno=tempmessno;
  416.     get_mess(0);
  417. }
  418.  
  419.  
  420.  
  421. void pascal free_trackers (struct tracker *t) {
  422.  
  423.     struct tracker *tt,*ttt;
  424.  
  425.     if(t) {
  426.         tt=t;
  427.         while(tt) {
  428.             if(tt->str)free(tt->str);
  429.             ttt=tt->next;
  430.             free(tt);
  431.             tt=ttt;
  432.         }
  433.     }
  434. }
  435.  
  436.  
  437.  
  438. struct tracker * pascal sort_tracker (struct tracker *t) {
  439.  
  440.     struct tracker *tempt,*tempt2,*last;
  441.     char swapped;
  442.  
  443.     do {        /* Sort by ascending string */
  444.         tempt=t;
  445.         last=NULL;
  446.         swapped=0;
  447.         while(tempt) {
  448.             if(tempt->next) {
  449.                 if(stricmp(tempt->str,tempt->next->str)>0) {
  450.                     if(tempt==t) {
  451.                         t=tempt->next;
  452.                     }
  453.                     tempt2=tempt->next;
  454.                     tempt->next=tempt->next->next;
  455.                     tempt2->next=tempt;
  456.                     if(last)last->next=tempt2;
  457.                     swapped=1;
  458.                 }
  459.             }
  460.             last=tempt;
  461.             tempt=tempt->next;
  462.         }
  463.     } while (swapped);
  464.  
  465.     do {            /* Then sort by descending quantity */
  466.         tempt=t;
  467.         last=NULL;
  468.         swapped=0;
  469.         while(tempt) {
  470.             if(tempt->next) {
  471.                 if(tempt->x < tempt->next->x) {
  472.                     if(tempt==t) {
  473.                         t=tempt->next;
  474.                     }
  475.                     tempt2=tempt->next;
  476.                     tempt->next=tempt->next->next;
  477.                     tempt2->next=tempt;
  478.                     if(last)last->next=tempt2;
  479.                     swapped=1;
  480.                 }
  481.             }
  482.             last=tempt;
  483.             tempt=tempt->next;
  484.         }
  485.     } while (swapped);
  486.  
  487.     return t;
  488. }
  489.  
  490.