home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / WWIVSOR.ZIP / VOTEEDIT.C < prev    next >
C/C++ Source or Header  |  1995-04-25  |  4KB  |  178 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1995 by Wayne Bell
  5.  
  6. Distribution of the source code for WWIV, in any form, modified or unmodified,
  7. without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
  8. Distribution of compiled versions of WWIV is limited to copies compiled BY
  9. THE AUTHOR.  Distribution of any copies of WWIV not compiled by the author
  10. is expressly prohibited.
  11.  
  12.  
  13. *****************************************************************************/
  14.  
  15.  
  16.  
  17. #include "vars.h"
  18.  
  19. #pragma hdrstop
  20.  
  21.  
  22.  
  23. void print_quests(void)
  24. {
  25.   char s[100];
  26.   int i,abort,f;
  27.   votingrec v;
  28.  
  29.   sprintf(s,"%sVOTING.DAT",syscfg.datadir);
  30.   f=sh_open1(s,O_RDONLY | O_BINARY);
  31.   abort=0;
  32.   for (i=1; (i<=20) && (abort==0); i++) {
  33.     sh_lseek(f,((long) (i-1)) * sizeof(votingrec), SEEK_SET);
  34.     sh_read(f,(void *)&v,sizeof(votingrec));
  35.     sprintf(s,"%2d: %s",i,
  36.       v.numanswers?v.question:get_string(99));
  37.     pla(s,&abort);
  38.   }
  39.   f=sh_close(f);
  40.   nl();
  41.   if (abort)
  42.     nl();
  43. }
  44.  
  45.  
  46. void set_question(int ii)
  47. {
  48.   votingrec v;
  49.   int i,i1,f;
  50.   char s[81];
  51.   userrec u;
  52.   voting_response vr;
  53.  
  54.   pl(get_string(100));
  55.   outstr(": ");
  56.   inputl(s,75);
  57.   strcpy(v.question,s);
  58.   v.numanswers=0;
  59.   vr.numresponses=0;
  60.   vr.response[0]='X';
  61.   vr.response[1]=0;
  62.   for (i=0; i<20; i++)
  63.     v.responses[i]=vr;
  64.   while ((v.numanswers<19) && (s[0])) {
  65.     npr("%d: ",v.numanswers+1);
  66.     inputl(s,63);
  67.     strcpy(vr.response,s);
  68.     vr.numresponses=0;
  69.     v.responses[v.numanswers]=vr;
  70.     if (s[0])
  71.       ++v.numanswers;
  72.   }
  73.  
  74.   sprintf(s,"%sVOTING.DAT",syscfg.datadir);
  75.   f=sh_open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  76.  
  77.   sh_lseek(f,((long) (ii)) * sizeof(votingrec), SEEK_SET);
  78.   sh_write(f,(void *)(&v),sizeof(votingrec));
  79.   f=sh_close(f);
  80.  
  81.   if (v.numanswers)
  82.     questused[ii]=1;
  83.   else
  84.     questused[ii]=0;
  85.  
  86.   read_user(1,&u);
  87.   i1=number_userrecs();
  88.   for (i=1; i<=i1; i++) {
  89.     read_user(i,&u);
  90.     u.votes[ii]=0;
  91.     write_user(i,&u);
  92.   }
  93. }
  94.  
  95.  
  96. void ivotes(void)
  97. {
  98.   int i,f,n,done;
  99.   char s[81];
  100.   votingrec v;
  101.  
  102.   sprintf(s,"%sVOTING.DAT",syscfg.datadir);
  103.   f=sh_open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  104.   n=(int) (filelength(f) / sizeof(votingrec)) -1;
  105.   if (n<20) {
  106.     v.question[0]=0;
  107.     v.numanswers=0;
  108.     for (i=n; i<20; i++)
  109.       sh_write(f,(void *)&v,sizeof(votingrec));
  110.   }
  111.   f=sh_close(f);
  112.   done=0;
  113.   do {
  114.     print_quests();
  115.     nl();
  116.     prt(2,get_string(101));
  117.     input(s,2);
  118.     if (strcmp(s,"Q")==0)
  119.       done=1;
  120.     i=atoi(s);
  121.     if ((i>0) && (i<21)) {
  122.       set_question(i-1);
  123.     }
  124.   } while ((!done) && (!hangup));
  125. }
  126.  
  127.  
  128. void voteprint(void)
  129. {
  130.   int f,f1,i,i1,i2,nu;
  131.   char s[81], fn[81];
  132.   votingrec v;
  133.   char *x;
  134.   userrec u;
  135.  
  136.   nu=number_userrecs();
  137.   if ((x=malloca(20*(2+nu)))==NULL)
  138.     return;
  139.   for (i=0; i<=nu; i++) {
  140.     read_user(i,&u);
  141.     for (i1=0; i1<20; i1++)
  142.       x[i1+i*20]=u.votes[i1];
  143.   }
  144.   sprintf(s,"%sVOTING.TXT",syscfg.gfilesdir);
  145.   f=sh_open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  146.   sprintf(s,get_stringx(1,16),date());
  147.   sh_write(f,(void *)s,strlen(s));
  148.  
  149.   sprintf(fn,"%sVOTING.DAT",syscfg.datadir);
  150.  
  151.   read_status();
  152.  
  153.   for (i=0; i<20; i++) {
  154.     f1=sh_open1(fn,O_RDONLY | O_BINARY);
  155.     sh_lseek(f1,((long)i)*sizeof(votingrec),SEEK_SET);
  156.     sh_read(f1,(void *)&v,sizeof(votingrec));
  157.     f1=sh_close(f1);
  158.     if (v.numanswers) {
  159.       pl(v.question);
  160.       sprintf(s,"\r\n%s\r\n",v.question);
  161.       sh_write(f,s,strlen(s));
  162.       for (i1=0; i1<v.numanswers; i1++) {
  163.         sprintf(s,"     %s\r\n",v.responses[i1].response);
  164.         sh_write(f,s,strlen(s));
  165.         for (i2=0; i2<status.users; i2++)
  166.           if (x[i+20*smallist[i2].number]==i1+1) {
  167.             sprintf(s,"          %s #%d\r\n",smallist[i2].name,smallist[i2].number);
  168.             sh_write(f,s,strlen(s));
  169.           }
  170.       }
  171.     }
  172.   }
  173.   sh_close(f);
  174.   bbsfree(x);
  175. }
  176.  
  177.  
  178.