home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / MYWIVE.ZIP / VOTEEDIT.C < prev    next >
C/C++ Source or Header  |  1993-05-06  |  3KB  |  148 lines

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