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

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1991 by Wayne Bell
  5.  
  6. *****************************************************************************/
  7. #include "vars.h"
  8. #pragma hdrstop
  9.  
  10. void print_quests(int f)
  11. {
  12.   char s[100];
  13.   int i,abort;
  14.   votingrec v;
  15.  
  16.   abort=0;
  17.   for (i=1; (i<=20) && (abort==0); i++) {
  18.     lseek(f,((long) (i-1)) * sizeof(votingrec), SEEK_SET);
  19.     read(f,(void *)&v,sizeof(votingrec));
  20.     sprintf(s,"%2d: %s",i,
  21.       v.numanswers?v.question:">>> NO QUESTION <<<");
  22.     pla(s,&abort);
  23.   }
  24.   nl();
  25.   if (abort)
  26.     nl();
  27. }
  28.  
  29. void set_question(int f, int ii)
  30. {
  31.   votingrec v,v1;
  32.   int i,i1,i2;
  33.   char s[81];
  34.   userrec u;
  35.   voting_response vr;
  36.   pl("Enter new question, <C/R> for none.");
  37.   outstr(": ");
  38.   inputl(s,75);
  39.   strcpy(v.question,s);
  40.   v.numanswers=0;
  41.   vr.numresponses=0;
  42.   vr.response[0]='X';
  43.   vr.response[1]=0;
  44.   for (i=0; i<20; i++)
  45.     v.responses[i]=vr;
  46.   while ((v.numanswers<19) && (s[0])) {
  47.     npr("%d: ",v.numanswers+1);
  48.     inputl(s,63);
  49.     strcpy(vr.response,s);
  50.     vr.numresponses=0;
  51.     v.responses[v.numanswers]=vr;
  52.     if (s[0])
  53.       ++v.numanswers;
  54.   }
  55.   lseek(f,((long) (ii)) * sizeof(votingrec), SEEK_SET);
  56.   write(f,(void *)(&v),sizeof(votingrec));
  57.   lseek(f,((long) (ii)) * sizeof(votingrec), SEEK_SET);
  58.   read(f,(void *)(&v1),sizeof(votingrec));
  59.   close(f);
  60.   if (v.numanswers)
  61.     questused[ii]=1;
  62.   else
  63.     questused[ii]=0;
  64.   read_user(1,&u);
  65.   i1=number_userrecs();
  66.   for (i=1; i<=i1; i++) {
  67.     read_user(i,&u);
  68.     u.votes[ii]=0;
  69.     write_user(i,&u);
  70.   }
  71.   close_user();
  72. }
  73.  
  74. void ivotes()
  75. {
  76.   int i,f,abort,n,done;
  77.   char s[81];
  78.   votingrec v;
  79.  
  80.   close_user();
  81.   sprintf(s,"%sVOTING.DAT",syscfg.datadir);
  82.   f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  83.   n=(int) (filelength(f) / sizeof(votingrec)) -1;
  84.   if (n<20) {
  85.     v.question[0]=0;
  86.     v.numanswers=0;
  87.     for (i=n; i<20; i++)
  88.       write(f,(void *)&v,sizeof(votingrec));
  89.   }
  90.   done=0;
  91.   do {
  92.     print_quests(f);
  93.     nl();
  94.     prt(2,"Which (Q=Quit) ? ");
  95.     input(s,2);
  96.     if (strcmp(s,"Q")==0)
  97.       done=1;
  98.     i=atoi(s);
  99.     if ((i>0) && (i<21)) {
  100.       set_question(f,i-1);
  101.       sprintf(s,"%sVOTING.DAT",syscfg.datadir);
  102.       f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  103.     }
  104.   } while ((!done) && (!hangup));
  105.   close(f);
  106. }
  107.  
  108. void voteprint()
  109. {
  110.   int f,f1,i,i1,i2,i3,nu;
  111.   char s[81],s1[81],s2[81];
  112.   votingrec v;
  113.   char *x;
  114.   userrec u;
  115.  
  116.   read_user(1,&u);
  117.   nu=number_userrecs();
  118.   if ((x=malloca(20*(2+nu)))==NULL)
  119.     return;
  120.   for (i=0; i<nu; i++) {
  121.     read_user(i,&u);
  122.     for (i1=0; i1<20; i1++)
  123.       x[i1+i*20]=u.votes[i1];
  124.   }
  125.   close_user();
  126.   sprintf(s,"%sVOTING.TXT",syscfg.gfilesdir);
  127.   f=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  128.   sprintf(s,"%sVOTING.DAT",syscfg.datadir);
  129.   f1=open(s,O_RDWR | O_BINARY);
  130.   sprintf(s,"Voting results as of %s\r\n\r\n",date());
  131.   write(f,(void *)s,strlen(s));
  132.   for (i=0; i<20; i++) {
  133.     lseek(f1,((long)i)*sizeof(votingrec),SEEK_SET);
  134.     read(f1,(void *)&v,sizeof(votingrec));
  135.     if (v.numanswers) {
  136.       pl(v.question);
  137.       sprintf(s,"\r\n%s\r\n",v.question);
  138.       write(f,s,strlen(s));
  139.       for (i1=0; i1<v.numanswers; i1++) {
  140.     sprintf(s,"     %s\r\n",v.responses[i1].response);
  141.     write(f,s,strlen(s));
  142.     for (i2=0; i2<status.users; i2++)
  143.           if (x[i+20*smallist[i2].number]==i1+1) {
  144.         sprintf(s,"          %s #%d\r\n",smallist[i2].name,smallist[i2].number);
  145.         write(f,s,strlen(s));
  146.       }
  147.       }
  148.     }
  149.   }
  150.   close(f1);
  151.   close(f);
  152.   farfree(x);
  153. }
  154.