static afs_uint32 file_cb(afs_vnode * v, XFILE * X, void *refcon) { char *vnodepath, vnpx[30]; dt_uint64 where; XFILE OX; int r, use = 0; if (!dirs_done) { dirs_done = 1; if (verbose) printf("* Extracting files...\n"); } /* Should we even use this? */ if (!use_vnum) { if ((r = Path_Build(X, &phi, v->vnode, &vnodepath, !use_realpath))) return r; if (!(use = usevnode(X, v->vnode, vnodepath))) { free(vnodepath); return 0; } if (use == 2) { free(vnodepath); sprintf(vnpx, "#%d:%d", v->vnode, v->vuniq); vnodepath = vnpx; } } else { sprintf(vnpx, "#%d:%d", v->vnode, v->vuniq); vnodepath = vnpx; } /* Print it out */ if (verbose) { printf("-%s %3d %-11d %11d %s %s\n", modestr(v->mode), v->nlinks, v->owner, v->size, datestr(v->server_date), vnodepath); } else if (!quiet) { printf("%s\n", vnodepath); } if (!nomode) { if ((r = xftell(X, &where)) || (r = xfseek(X, &v->d_offset)) || (r = xfopen_path(&OX, O_RDWR | O_CREAT | O_TRUNC, vnodepath + 1, 0644))) { if (vnodepath != vnpx) free(vnodepath); return r; } r = copyfile(X, &OX, v->size); xfclose(&OX); xfseek(X, &where); } else r = 0; if (vnodepath != vnpx) free(vnodepath); return r; }
string logstream::date() { time_t rawtime; time ( &rawtime ); string datestr (ctime ( &rawtime )); return datestr.substr(0, datestr.size()-1); }
static afs_uint32 directory_cb(afs_vnode * v, XFILE * X, void *refcon) { char *vnodepath; int r, use = 0; /* Should we even use this? */ if (!use_vnum) { if ((r = Path_Build(X, &phi, v->vnode, &vnodepath, !use_realpath))) return r; if (!(use = usevnode(X, v->vnode, vnodepath))) { free(vnodepath); return 0; } } /* Print it out */ if (verbose) { if (use_vnum) printf("d%s %3d %-11d %11d %s #%d:%d\n", modestr(v->mode), v->nlinks, v->owner, v->size, datestr(v->server_date), v->vnode, v->vuniq); else printf("d%s %3d %-11d %11d %s %s\n", modestr(v->mode), v->nlinks, v->owner, v->size, datestr(v->server_date), vnodepath); } else if (!quiet && !use_vnum) printf("%s\n", vnodepath); /* Make the directory, if needed */ if (!nomode && !use_vnum && use != 2) { if (strcmp(vnodepath, "/") && (r = mkdirp(vnodepath + 1))) { free(vnodepath); return r; } if (do_acls) { /* XXX do ACL's later */ } } if (!use_vnum) free(vnodepath); return 0; }
int main(void){ char *date; int count; char buf[80]; while(1){ count = count_user(); date = datestr(); sprintf(buf, "%s %d\n", date, count); save2file(FILENAME3, buf); sleep(1); } }
/* Displays information about a file. */ long fileinfo( struct _find_t *pfind ) { char timebuf[10], datebuf[10], *pkind; datestr( pfind->wr_date, datebuf ); timestr( pfind->wr_time, timebuf ); if( pfind->attrib & _A_SUBDIR ) pkind = "Directory"; else if( pfind->attrib & _A_VOLID ) pkind = "Label"; else pkind = "File"; printf( "%-12s %8ld %8s %8s %-9s %c %c %c %c\n", pfind->name, pfind->size, timebuf, datebuf, pkind, (pfind->attrib & _A_RDONLY) ? 'Y' : 'N', (pfind->attrib & _A_HIDDEN) ? 'Y' : 'N', (pfind->attrib & _A_SYSTEM) ? 'Y' : 'N', (pfind->attrib & _A_ARCH) ? 'Y' : 'N' ); return pfind->size; }
int mbtransfer (char *ziel) //************************************************************************* // // TRANSFER-Prozedur // (wird fuer jedes transferierte File einzeln aufgerufen) // //************************************************************************* { char name[20]; strcpy(name, "mbtransfer"); lastfunc(name); char *line = b->line; int findex; FILE *oldf, *newf; char usermail = 0; int retwert = NO; int nocp; //no-copy flag char oldsubject[101]; unsigned long int oldfpos; char oldmsgty; char oldmailfname[10]; time_t oldmsgtime; char old_ziel[DIRLEN+1]; int old_usermail; char oldboardname[10]; char oldmailpath[FNAMELEN+1]; char zielcall[CALLEN+1]; char newcall[CALLEN+1]; int gleichesboard = NO; unsigned long nummer; #ifdef USERLT short int old_lt; #endif #ifdef DEBUG_FWD trace(report, "mbtransfer", "ziel: %s", ziel); #endif strupr(ziel); nexttoken(ziel, zielcall, CALLEN); strcpy(oldmailpath, b->mailpath); if (sema_test("sendlock") || m.disable) { putf(ms(m_sendnotpossible)); return NO; } if (mbcallok(zielcall)) { // Use newcall if (get_newcall(zielcall, newcall)) { strcpy(zielcall, newcall); putf(ms(m_usingnewcall), newcall); } } char *bbuf = (char *) t_malloc(sizeof(tvar_t) - sizeof(task_t), "tran"); char *oldfname; oldfname = (char *) t_malloc(sizeof(char) * (FNAMELEN+1), "tra2"); if (! bbuf || ! oldfname) return NO; memcpy(bbuf, (char *) b + sizeof(task_t), sizeof(tvar_t) - sizeof(task_t)); strlwr(b->mailpath); strcpy(oldfname, b->mailpath); strcpy(oldmailfname, b->mailfname); oldmsgtime = filename2time(b->mailfname); if ((oldf = s_fopen(oldfname, "srt")) != NULL) { fgets(b->line, BUFLEN - 1, oldf); // Befehlszeile einlesen mbsend_parse(line, 0); if (b->mailtype == 'A' || (b->mailtype == 'B' && b->eraseinfo == 'T')) { retwert = NIL; s_fclose(oldf); goto error_exit; } oldmsgty = b->conttype; // save mailflags ...(conttype) fgets(b->line, BUFLEN - 1, oldf); // Forwardzeile vernichten fgets(b->line, BUFLEN - 1, oldf); // Read-Zeile fgets(oldsubject, BETREFFLEN, oldf); // Betreff cut_blank(oldsubject); // Newline entfernen if (mbcallok(zielcall)) *b->at = 0; // Verteiler loeschen -> Neubestimmen strcpy(old_ziel, b->ziel); #ifdef USERLT old_lt = b->lifetime; b->lifetime = 0; #endif old_usermail = b->usermail; mbsend_parse(ziel, 2); if (! stricmp(b->ziel, b->mailpath+strlen(b->mailpath)-strlen(b->ziel)-8)) { retwert = NIL; s_fclose(oldf); goto error_exit; } b->conttype = oldmsgty; // set mailflags again.. (conttype) if (b->mailtype == 'B' && ! old_usermail) strcpy(b->ziel, old_ziel); weiterleiten(1, b->zielboard); waitfor(e_ticsfull); findex = finddir(b->zielboard, b->sysop); if (findex && !(strlen(b->zielboard)==1 && !b->sysop)) { if (xmkdir(b->boardpath)) { trace(serious, name, "mkdir %s error", b->boardpath); s_fclose(oldf); goto error_exit; } nocp = ! strcmp(b->herkunft, b->logincall) || b->sysop; //kein "CP " wenn Sysop! if (nocp || b->mailtype == 'B') strcpy(b->betreff, oldsubject); else sprintf(b->betreff, "CP %s: %.67s", b->logincall, oldsubject); //Bei Nicht-Bulletin BID neu generieren bzw. wenn BID fehlt if (b->mailtype != 'B'|| ! *b->bid) strcpy(b->bid, newbid()); make_mask(b->mailpath, b->boardfullname); strcpy(b->mask, b->mailpath); // Ursprungsboardnamen aus b->mailpath holen und mit ziel vergleichen strcpy(oldboardname, b->boardname); oldmailpath[strlen(oldmailpath)-8] = 0; if (finddir(oldmailpath,0) > 0) { if (! strcmp(ziel, b->boardname)) gleichesboard = YES; } else gleichesboard = NO; strcpy(b->boardname,oldboardname); // b->boardname wieder herstellen // bei Usermail oder gleichem Board zum Sortieren // Filezeit/-namen neu setzen if (mbcallok(zielcall) || gleichesboard) { strcpy(b->mailfname, time2filename(0)); } else strcpy(b->mailfname, oldmailfname); if (! strstr(b->mailpath, "*.*")) trace(fatal, name, "mask %s", b->mailpath); strcpy(strstr(b->mailpath, "*.*"), b->mailfname); strlwr(b->mailpath); if ((newf = s_fopen(b->mailpath, "sw+t")) != NULL) { s_fsetopt(newf, 1); #ifdef USERLT set_boardlife_max(old_lt); b->lifetime = old_lt; #endif writeheader(newf, 1); if (b->mailtype != 'B') { if (fgets(b->line, BUFLEN - 1, oldf)) { do { // fputs(line,f); skip old R-lines waitfor(e_ticsfull); fgets(b->line, BUFLEN - 1, oldf); } while (! feof(oldf) && *line == 'R' && line[1] == ':'); } fprintf(newf, "%s\n", makeheader(1)); fprintf(newf, "X-Transfer: %s by %s @ %s\n", datestr(ad_time(), 12), b->logincall, m.boxadress); fprintf(newf, "X-Original-Date: %s\n", datestr(oldmsgtime, 10)); do { if(( ! strncasecmp(line, "from", 4) || ! strncmp(line, "de: ", 4) || ! strncmp(line, "de ", 3) || ! strncmp(line, "fm ", 3)) && ! nocp) fprintf(newf, "X-Originally %s", line); else if (( ! strncasecmp(line, "to: ", 4) || ! strncasecmp(line, "to ", 3)) && ! nocp) fprintf(newf, "X-Originally %s", line); else if (! strncmp(line, "X-MID: ", 7)) fprintf(newf, "X-Old-MID: %s", line + 7); else if (! strncmp(line, "X-BID: ", 7)) fprintf(newf, "X-Old-BID: %s", line + 7); else fputs(line, newf); waitfor(e_ticsfull); fgets(b->line, BUFLEN - 1, oldf); } while (! feof(oldf) && *line != LF); fputc(LF, newf); } //Files binaer behandeln oldfpos = ftell(oldf); s_fclose(oldf); s_fclose(newf); writemailflags(); if ((oldf = s_fopen(oldfname, "srb")) != NULL) { if ((newf = s_fopen(b->mailpath, "sab")) != NULL) //append to file { fseek(oldf, oldfpos, SEEK_SET); do { //oe3dzw: Transferroutine transparent int len; len = fread(line, 1, 255, oldf); if (len) fwrite(line, 1, len, newf); waitfor(e_ticsfull); } while (! feof(oldf)); if (b->binstart) //bei binaeren Mails offset neu berechnen { b->binstart += ftell(newf) - ftell(oldf); if (b->binstart < 0) trace(serious, name, "offset %ld in %s", b->binstart, b->mailpath); } s_fclose(newf); if (b->binstart) writelines(); //Neuen Binstart speichern if (b->bytes) { if (old_usermail || gleichesboard) nummer = appenddirlist(1); else nummer = appenddirlist(0); //change old CHECKLINE if (b->usermail) { add_fwdfile("", get_fdelay(b->herkunft), 0); sprintf(b->line, "%s %lu", b->herkunft, nummer); mbtalk("\001", b->zielboard, b->line); trigger_ufwd(b->zielboard); } else { handle fh; char found; if (old_usermail) add_fwdfile("", get_fdelay(b->herkunft), 0); else add_fwdfile("", get_fdelay(b->herkunft), 1); if (findex > 0) tree[findex - 1].newestmail = oldmsgtime; if ((fh = s_open(CHECKNAME, "sr+b")) != EOF) { seek_fname(fh, b->mailfname, &found, 1); long pos = ltell(fh); if (found) { _read(fh, b->line, BLEN); sprintf(b->line + 15, "%-8s", b->boardname); b->line[23] = '~'; #ifdef USERLT char nlt[4]; sprintf(nlt, "%3.3d", b->boardlife_max); memcpy(b->line + 51, nlt, 3); #endif lseek(fh, -(LBLEN), SEEK_CUR); _write(fh, b->line, BLEN); } s_close(fh); if (found && (fh = s_open(CHECKNUMNAME, "sr+b")) != EOF) { lseek(fh, 2*(pos >> 6), SEEK_SET); //2* da 32bit! _write(fh, &nummer, 4); // 4Byte=32 bit s_close(fh); } } else trace(serious, name, "check"); } inc_mailgot(b->boardname); writemailflags(); retwert = OK;
static afs_uint32 symlink_cb(afs_vnode * v, XFILE * X, void *refcon) { char *vnodepath, *linktarget, vnpx[30]; dt_uint64 where; int r, use = 0; if (!dirs_done) { dirs_done = 1; if (verbose) printf("* Extracting files...\n"); } /* Should we even use this? */ if (!use_vnum) { if ((r = Path_Build(X, &phi, v->vnode, &vnodepath, !use_realpath))) return r; if (!(use = usevnode(X, v->vnode, vnodepath))) { free(vnodepath); return 0; } if (use == 2) { free(vnodepath); sprintf(vnpx, "#%d:%d", v->vnode, v->vuniq); vnodepath = vnpx; } } else { sprintf(vnpx, "#%d:%d", v->vnode, v->vuniq); vnodepath = vnpx; } if (!(linktarget = malloc(v->size + 1))) { if (vnodepath != vnpx) free(vnodepath); return DSERR_MEM; } if ((r = xftell(X, &where)) || (r = xfseek(X, &v->d_offset)) || (r = xfread(X, linktarget, v->size))) { if (vnodepath != vnpx) free(vnodepath); free(linktarget); return r; } xfseek(X, &where); linktarget[v->size] = 0; /* Print it out */ if (verbose) printf("l%s %3d %-11d %11d %s %s -> %s\n", modestr(v->mode), v->nlinks, v->owner, v->size, datestr(v->server_date), vnodepath, linktarget); else if (!quiet) printf("%s\n", vnodepath); r = 0; if (!nomode) { if (symlink(linktarget, vnodepath + 1)) r = errno; } free(linktarget); if (vnodepath != vnpx) free(vnodepath); return r; }
void wx::show_diags (int what, time_t t_n) //************************************************************************* // //************************************************************************* { //show diagram int i; wxdata_t wxt; char oneline[80]; double temp[48]; time_t next_t; for (i = 0; i < 48; i++) { next_t = t_n-DAY-400+1800*(i+1); if (! read_wx_data(oneline, next_t)) { putf("No data for %s available.\n", datestr(next_t, 12)); return; } //printf("oneline %s\n", oneline); if (orgdata(&wxt, oneline)) switch (what) { case 3: temp[i] = wxt.humidity; break; case 2: temp[i] = wxt.air_pres_qnh; break; case 1: temp[i] = wxt.windspeed; break; default: temp[i] = wxt.outdoort; break; } else { putf("Data invalid.\n"); return; } } switch (what) { case 1: diag_24h("Windstaerke der letzten 24h", "m/s", temp); break; case 2: diag_24h("Luftdruck QNH der letzten 24h", "hPa", temp); break; case 3: diag_24h("Luftfeuchtigkeit der letzten 24h", "%", temp); break; default: diag_24h("Temperatur der letzten 24h", "Grad C", temp); break; } }
void wx::show_wx (wxdata_t *wx, int detail) //************************************************************************* // Userinterface for wx-data // detail: 0..raw format (debugging-output) // 1..short format // 2..long (detailed) format // 3..dl3baa-format //************************************************************************* { static char *beaunam[] = { "Windstille", "leiser Zug", "leichte Briese", "maessige Briese", "frische Briese", "starker Wind", "steifer Wind", "stuermischer Wind", "Sturm", "schwerer Sturm", "orkanartiger Sturm", "Orkan"}; if (! wx->data_valid) { putf("Sorry, no data available.\n"); return; } putf("WX-Station %s\n", m.wxstnname); switch (detail) { case 1: //short format putf("Aussentemperatur.....%6.1f C\n", wx->outdoort); putf("Raumtemperatur.......%6.1f C\n", wx->indoort); putf("Luftdruck QNH........%6.1f hPa\n", wx->air_pres_qnh); putf("Rel.Luftfeuchte......%6.1f %%\n", wx->humidity); putf("Windgeschwindigkeit..%6.1f km/h\n", wx->windspeed*3.6); if (wx->windspeed > 0.1) // wind_direction only valid if there is wind putf("Windrichtung........%6s\n", wx->winddir_str); putf("Messzeit............%s\n", datestr(wx->t,12)); putf("\nMehr Infos sind mit WX INFO abrufbar!\n"); break; case 2: //detailed format putf("Aussentemperatur.......%6.1f C\n", wx->outdoort); putf("Windchill-Temp.........%6.1f C\n", wx->wind_chill); putf("Taupunkt...............%6.1f C\n", wx->dew_point); putf("Schneefallgrenze.......%6.0f m\n", wx->snowfall_limit); putf("Raumtemperatur.........%6.1f C\n", wx->indoort); putf("Luftdruck QNH..........%6.1f hPa\n", wx->air_pres_qnh); putf("Luftdruck lokal QFE....%6.1f hPa\n", wx->air_pres_qfe); putf("Saettigungsdampfdruck..%6.1f hPa\n", wx->sat_sp); putf("Dampfdruck.............%6.1f hPa\n", wx->steam_pressure); putf("Rel.Luftfeuchte........%6.1f %%\n", wx->humidity); if (wx->humidity < 100.0) //only defined when < 100% putf("Absolute Feuchte.......%6.1f g/m3\n", wx->abs_humidity); putf("Windgeschwindigkeit....%6.1f m/s = %4.1f km/h (%ld Bf %s)\n", wx->windspeed, wx->windspeed*3.6, wx->wind_beaufort, beaunam[wx->wind_beaufort]); if (wx->windspeed > 0.1) /*wind-direction only when there is wind*/ putf("Windrichtung...........%6.1f Grad (%s)\n", wx->wind_direction, wx->winddir_str); putf("Messzeit...............%s\n", datestr(wx->t, 12)); break; case 3: //special format /* Format compatible with DC4FS: ============================================================================ Temperatur : -9.0 C 15.8 F konstant Luftdruck QNH : 997 hPa 748 mmHg steigend relative Feuchte : 88 % konstant Sonnenscheindauer : 2.5 h Niederschlagsmenge : 0.0 mm 0.0 l/m2 Windgeschwindigkeit : 0.8 m/s 2.9 km/h konstant Windrichtung : 100 Grad O konstant ============================================================================ */ putf("Gekuerzte Ausgabe kompatibel zu DC4FS's WX-Software\n"); putf("Temperatur :%6.1f C\n", wx->outdoort); putf("Luftdruck QNH :%6.0f hPa\n", wx->air_pres_qnh); putf("relative Feuchte :%6.0f %%\n", wx->humidity); putf("Windgeschwindigkeit :%6.1f m/s\n", wx->windspeed); if (wx->windspeed > 0.1) // wind-direction only when there is wind... putf("Windrichtung :%6.0f Grad\n", wx->wind_direction); break; } }
int autohadr (char *call, int ausgabe) //************************************************************************* // // Search for address in HADR database // //************************************************************************* { lastfunc("autohadr"); int pos; int i; bitfeld options = b->optplus; int which = -1; hadr_t *ha = (hadr_t*) t_malloc(sizeof(hadr_t), "hadr"); if (m.hadrstore) { strupr(call); hadr_tryopen(); pos = loadhadr(call, ha, 0); uclose(); if (pos) { which = which_partner(call, ha); if (ausgabe && (options & o_a)) { time_t mindelay = ad_time(); time_t mtime = ad_time(); putf("Forward data from HADR-entry:\n"); putf("H-Addr : %s\n", ha->adr); putf("R-Header : %s\n", ha->lastheader); putf("Last BID : %s\n", ha->lastbid); putf("Last Board : %s\n", ha->lastboard); putf("Last User : %s\n", ha->lastuser); putf("Header Date: %s\n", datestr(ha->lasthtime, 12)); if (*ha->sysopcall) putf("Sysop: %s %s\n", ha->sysopcall, get_name(ha->sysopcall, 1)); if (*ha->protocol && *ha->hwaddress) putf("HW-Address: %s: %s\n", ha->protocol, ha->hwaddress); if (ha->bversion && *ha->bstatus && ha->lastwprcvd) putf("BVersion: %ld %s (%s)\n", ha->bversion, ha->bstatus, datestr(ha->lastwprcvd, 12)); putf("Bulletins : %ld\n", ha->bulletins); putf("Usermails : %ld\n", ha->usermails); putf("Neighbour Count Update +Delay Hops\n"); for (i = 0; i < ADJNUM; i++) { if (ha->adjacent[i][0]) { if (ha->delay[i] < mindelay) mindelay = ha->delay[i]; } } for (i = 0; i < ADJNUM; i++) { // Ausgabe HADR-Eintrag if (ha->adjacent[i][0]) { putf("%-9s%6d%7s%7s%5d", ha->adjacent[i], ha->rel_mails[i], zeitspanne(mtime - ha->lastupdate[i], zs_seconds), zeitspanne(ha->delay[i] - mindelay, zs_seconds), ha->hops[i]); if (i == which) putf(" <"); if (isforwardpartner(ha->adjacent[i]) == NOTFOUND) putf(" fwd terminated"); putv(LF); } } putv(LF); } } } if (which != NOTFOUND) strcpy(b->destboxlist, ha->adjacent[which]); t_free(ha); if (which == NOTFOUND) return unbekannt; return auto_bekannt; }
int bbsvote_act(char * info) { FILE *fp; struct votebal currvote, ent; char buf[STRLEN], buf1[512]; char buf2[1024]; struct ballot uservote; // struct votelog log; int aborted = NA, pos; int i, chkd; unsigned int j, multiroll = 0; char board[80]; char posturl[256]; char controlfile[STRLEN]; char *date, *tmp1, *tmp2; char flagname[STRLEN]; char logname[STRLEN]; int voted_flag; //用户是否投过该项票 int num_voted; //这个是有多少人投过票 int num_of_vote; //这个是开启的投票数 int votenum; //这个是用户选择进行第几个投票 int votevalue = 0; int procvote; time_t closedate; struct stat st; int now_t=time(0); if (!loginok) { strcpy(info, "匆匆过客不能投票。"); return -1; } strsncpy(board, getparm("B"), 32); if (!*board) { strsncpy(board, getparm("board"), 32); } votenum = atoi(getparm("votenum")); procvote = atoi(getparm("procvote")); modify_mode(u_info, VOTING); if(!has_post_perm(¤tuser, board) || !HAS_PERM(PERM_VOTE))//去死吧倒霉的全站投票 { strcpy(info, "您无权在本板内投票。"); return -1; } sprintf(controlfile, "vote/%s/%s", board, "control"); num_of_vote = (stat(controlfile, &st) == -1) ? 0 : st.st_size / sizeof (struct votebal); if (!num_of_vote) { strcpy(info, "抱歉, 目前并没有任何投票举行。"); return -2; } fp = fopen(controlfile, "r"); if (!fp)//大概不会发生 { strcpy(info, "系统错误。"); return -256; } //从if中提出来的 if (!votenum) //这是投票列表 { printf ("<card title=\"投票箱 -- %s\">", BBSNAME); printf ("<p><anchor><go href=\"bbsdoc.wml?board=%s\" />%s板</anchor>投票</p>", board, board); for (i = 1; i <= num_of_vote; i++) { fread(&ent, sizeof (struct votebal), 1, fp); sprintf(flagname, "vote/%s/flag.%d", board, (int) ent.opendate); num_voted = (stat(flagname, &st) == -1) ? 0 : st.st_size / sizeof (struct ballot); closedate = ent.opendate + ent.maxdays * 86400; //注意,这里的date成了结束时间 w_hsprintf(buf2, "%s", ent.title);//输出标题 printf("<p><anchor><go href=\"bbsvote.wml?board=%s&votenum=%d\" />#%d %s<br />", board, i, i, buf2); //发起投票者被华丽地无视了! datestr(buf2, closedate); //类别也被华丽地无视了! printf ("结束:%s 参与:%d</anchor></p>", buf2, num_voted); } fclose(fp); return 0; } else { if (votenum > num_of_vote) { strcpy(info, "参数错误。"); return -3; } fseek(fp, sizeof (struct votebal) * (votenum - 1), 0); fread(&currvote, sizeof (struct votebal), 1, fp); fclose(fp); sprintf(flagname, "vote/%s/flag.%d", board, (int) currvote.opendate); num_voted = (stat(flagname, &st) == -1) ? 0 : st.st_size / sizeof (struct ballot); pos = 0; fp = fopen(flagname, "r"); voted_flag = NA; if (fp) { for (i = 1; i <= num_voted; i++) { fread(&uservote, sizeof (struct ballot), 1, fp); if (!strcasecmp(uservote.uid, currentuser.userid)) { voted_flag = YEA; pos = i; break; } } fclose(fp); } if (!voted_flag) { memset(&uservote, 0, sizeof (uservote)); } if (procvote == 0) //-------投票权限判断 //没仔细看-_-b { if (currentuser.firstlogin > currvote.opendate) { strcpy(info, "对不起, 本投票在您帐号申请之前开启,您不能投票。"); return -3; } else if (!HAS_PERM(currvote.level & ~(LISTMASK | VOTEMASK))) { strcpy(info, "对不起,您目前尚无权在本票箱投票。"); return -4; } else if(currvote.level & LISTMASK ) { char listfilename[STRLEN]; setvfile(listfilename, board, "vote.list"); if(!dashf(listfilename)) { strcpy(info, "对不起,本票箱需要设定好投票名册方可进行投票。"); return -5; } else if(!seek_in_file(listfilename,currentuser.userid)) { strcpy(info, "对不起, 投票名册上找不到您的大名。"); return -6; } } else if(currvote.level & VOTEMASK ) { if(currentuser.numlogins < currvote.x_logins || currentuser.numposts < currvote.x_posts ||currentuser.stay < currvote.x_stay * 3600 || currentuser.firstlogin > currvote.opendate - currvote.x_live * 86400) { strcpy(info, "对不起,您目前尚不够资格在本票箱投票。"); return -7; } } closedate = currvote.opendate + currvote.maxdays * 86400; printf ("<card title=\"投票箱 -- %s\">", BBSNAME); w_hsprintf (buf2, "%s", currvote.title); printf("<p>投票主题: %s<br />", buf2); printf("投票类型: %s<br />", vote_type[currvote.type - 1]); printf("发起投票: <anchor><go href=\"bbsqry.wml?userid=%s\" />%s</anchor><br />", currvote.userid, currvote.userid); printf("所在板面: <anchor><go href=\"bbsdoc.wml?board=%s\" />%s</anchor><br />", board, board); datetime(buf2, closedate); printf("结束时间: %s<br />", buf2); if (currvote.type != VOTE_ASKING) { printf("最多投票: %d<br />", currvote.maxtkt); printf("投票说明:<br />"); sprintf(buf, "vote/%s/desc.%d", board, (int) currvote.opendate); fp = fopen(buf, "r"); if (fp) { while (1) { if (fgets(buf1, sizeof (buf1), fp) == 0) { break; } w_hprintf("%s", buf1); printf ("<br />"); } fclose(fp); } } printf ("</p>"); //multiroll这种东西没用啦 sprintf (posturl, "bbsvote.wml?board=%s&votenum=%d", board, votenum); switch (currvote.type) { case VOTE_SINGLE: //单选 j = uservote.voted + (uservote.voted << currvote.totalitems); chkd = 0; //这是当前选中的 printf ("<p>选项列表:<br />"); for (i = 0; i < currvote.totalitems; i++) { w_hprintf ("选项%d %s", i + 1, currvote.items[i]); printf ("<br />"); if (j & 1) { chkd = i + 1; } j >>= 1; } printf ("请选择:<select name=\"inp_vote\" value=\"%d\">", chkd); printf ("<option value=\"0\">未选择</option>"); for (i = 0; i < currvote.totalitems; i++) { printf ("<option value=\"%d\">%d</option>", i + 1, i + 1); } printf ("</select></p>"); votesug_inp(&uservote); printf ("<p><anchor><go href=\"%s\" method=\"post\"><postfield name=\"procvote\" value=\"2\" />", posturl); wmlPostfield("vote"); votesug_pst(); printf ("</go>投票</anchor></p>"); break; case VOTE_MULTI: //复选 j = uservote.voted + (uservote.voted << currvote.totalitems); printf ("<p>选项列表<em>(最多投%d票)</em>:<br />", currvote.maxtkt); for (i = 0; i < currvote.totalitems; i++) { printf ("<select name=\"inp_votemulti%d\" value=\"%d\"><option value=\"0\">不选择</option><option value=\"1\">已选择</option></select> ", i + 1, (j & 1)); w_hprintf ("%s", currvote.items[i]); printf ("<br />"); j >>= 1; } printf ("</p>"); votesug_inp(&uservote); printf ("<p><anchor><go href=\"%s\" method=\"post\"><postfield name=\"procvote\" value=\"3\" />", posturl); for (i = 0; i < currvote.totalitems; i++) { sprintf (buf2, "votemulti%d", i + 1); wmlPostfield(buf2); } votesug_pst(); printf ("</go>投票</anchor></p>"); break; case VOTE_YN: //是非 ... 不是跟单选一样的么? j = uservote.voted + (uservote.voted << currvote.totalitems); chkd = 0; //这是当前选中的 printf ("<p>选项列表:<br />"); for (i = 0; i < currvote.totalitems; i++) { if (j & 1) { chkd = i + 1; break; } j >>= 1; } printf ("请选择:<select name=\"inp_vote\" value=\"%d\">", chkd); printf ("<option value=\"0\">未选择</option>"); for (i = 0; i < currvote.totalitems; i++) { printf ("<option value=\"%d\">", i + 1); w_hprintf ("%s", currvote.items[i]); printf ("</option>"); } printf ("</select></p>"); votesug_inp(&uservote); printf ("<p><anchor><go href=\"%s\" method=\"post\"><postfield name=\"procvote\" value=\"1\" />", posturl); //这里不同,单选procvote=2 wmlPostfield("vote"); votesug_pst(); printf ("</go>投票</anchor></p>"); break; case VOTE_VALUE: //数值 printf ("<p>请输入一个值:"); printf ("<input name=\"inp_votevalue\" value=\"%d\" /></p>", uservote.voted); votesug_inp(&uservote); printf ("<p><anchor><go href=\"%s\" method=\"post\"><postfield name=\"procvote\" value=\"4\" />", posturl); wmlPostfield("votevalue"); votesug_pst(); printf ("</go>投票</anchor></p>"); break; case VOTE_ASKING: votesug_inp(&uservote); printf ("<p><anchor><go href=\"%s\" method=\"post\"><postfield name=\"procvote\" value=\"5\" />", posturl); votesug_pst(); printf ("</go>投票</anchor></p>"); break; default: printf ("<p>没有这种类型的投票啊。</p>"); return 0; //:( //<-switch } } else { if (procvote != currvote.type) { strcpy(info, "投票错误。"); return -1; } switch (procvote) { case 2: //VOTE_SINGLE votevalue = 1; votevalue <<= atoi(getparm("vote")) - 1; if (atoi(getparm("vote")) > currvote.totalitems + 1) { strcpy(info, "无效选项。"); return -1; } aborted = (votevalue == uservote.voted); break; case 3: //VOTE_MULTI votevalue = 0; j = 0; for (i = currvote.totalitems - 1; i >= 0; i--) { votevalue <<= 1; sprintf(buf, "votemulti%d", i + 1); votevalue |= !!atoi(getparm(buf)); j += !!atoi(getparm(buf)); } aborted = (votevalue == uservote.voted); if (j > currvote.maxtkt) { sprintf(info, "本投票最多只能选择%d个选项。", currvote.maxtkt); return -1; } break; case 1: //VOTE_YN votevalue = 1; j = atoi(getparm("vote")) - 1; if (j > currvote.totalitems || j < 0) { strcpy(info, "无效选项。"); return -1; } votevalue <<= j; aborted = (votevalue == uservote.voted); break; case 4: //VOTE_VALUE aborted = ((votevalue = atoi(getparm("votevalue"))) == uservote.voted); if (votevalue < 0 || votevalue > currvote.maxtkt) { sprintf(info, "应当介于0到%d之间(含)。", currvote.maxtkt); return -1; } break; case 5: //VOTE_ASKING aborted = NA; break; //<-switch } printf ("<card title=\"投票箱 -- %s\">", BBSNAME); if (aborted == YEA) { printf ("<p>未修改该投票的选项。</p>"); return 0; } else { fp = fopen(flagname, "r+"); if (fp == 0) { fp = fopen(flagname, "w+"); } if (fp) { flock(fileno(fp), LOCK_EX); if (pos > 0) { fseek(fp, (pos - 1) * sizeof (struct ballot), SEEK_SET); } else { fseek(fp, 0, SEEK_END); } strcpy(uservote.uid, currentuser.userid); uservote.voted = votevalue; for (i = 0; i < 3; i++) { sprintf (buf2, "sug%d", i); strncpy (uservote.msg[i], getparm(buf2), 78); removeInvisibleChars(uservote.msg[i], ' '); } fwrite(&uservote, sizeof (struct ballot), 1, fp); flock(fileno(fp), LOCK_UN); fclose(fp); printf("<p>已经帮您投入票箱中。</p>"); sprintf(buf, "%s %s %s", currentuser.userid, currentuser.lasthost, Ctime(now_t)); fs_append(BBSHOME"/vote.log", buf); } else { printf ("<p>系统发生了一点小小的问题-_-b</p>"); } } } }