/* >>>>>>>>>> EXA12_1 <<<<<<<<<< */ void exa12_1 (void) { int n = 50 ,i, j; static int ixp[4] = {200, 1999, 1999, 200}, iyp[4] = {2600, 2600, 801, 801}; double fpi = 3.1415927 / 180., step, x, y; step = 360. / (n - 1); for (i = 0; i < n; i++) { x = i * step; for (j = 0; j < n; j++) { y = j * step; zmat[i][j] = (float) (2 * sin (x * fpi) * sin (y * fpi)); } } setpag ("da4p"); disini (); pagera (); hwfont (); axspos (200, 2600); axslen (1800, 1800); name ("X-axis", "x"); name ("Y-axis", "y"); name ("Z-axis", "z"); titlin ("Surface Plot (SURMAT)", 2); titlin ("F(X,Y) = 2*SIN(X)*SIN(Y)", 4); graf3d (0.f, 360.f, 0.f, 90.f, 0.f, 360.f, 0.f, 90.f, -3.f, 3.f, -3.f, 1.f); height (50); title (); shlsur (); color ("green"); surmat ((float *) zmat, n, n, 1, 1); color ("fore"); grfini (-1.f, -1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, -1.f); nograf (); graf (0.f, 360.f, 0.f, 90.f, 0.f, 360.f, 0.f, 90.f); dashl (); grid (1,1); grffin (); grfini (-1.f, -1.f, -1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f); graf (0.f, 360.f, 0.f, 90.f, -3.f, 3.f, -3.f, 1.f); grid (1, 1); grffin (); grfini (-1.f, 1.f, -1.f, 1.f, 1.f, -1.f, 1.f, 1.f, 1.f); shdpat (7L); solid (); areaf (ixp, iyp, 4); grffin (); disfin (); }
static void a_showname(const menu_t * pm) { char buf[PATHLEN]; int len; int i; int sym; move(b_lines - 1, 0); snprintf(buf, sizeof(buf), "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); if (dashl(buf)) { prints("此 symbolic link 名稱為 %s\n", pm->header[pm->now - pm->page].filename); if ((len = readlink(buf, buf, PATHLEN - 1)) >= 0) { buf[len] = '\0'; for (i = 0; BBSHOME[i] && buf[i] == BBSHOME[i]; i++); if (!BBSHOME[i] && buf[i] == '/') { if (HasUserPerm(PERM_BBSADM)) sym = 1; else { sym = 0; for (i++; BBSHOME "/man"[i] && buf[i] == BBSHOME "/man"[i]; i++); if (!BBSHOME "/man"[i] && buf[i] == '/') sym = 1; } if (sym) { vmsgf("此 symbolic link 指向 %s", &buf[i + 1]); } } } } else if (dashf(buf)) prints("此文章名稱為 %s", pm->header[pm->now - pm->page].filename); else if (dashd(buf)) prints("此目錄名稱為 %s", pm->header[pm->now - pm->page].filename); else outs("此項目已損毀, 建議將其刪除!"); pressanykey(); }
// Delete and archive the physical (except header) of file // // if backup_direct is provided, backup according to that directory. // if backup_path points to buffer, return back the backuped file // Return -1 if cannot delete file, 0 for success, // 1 if delete success but backup failed. int delete_file_content2(const char *direct, const fileheader_t *fh, const char *backup_direct, char *backup_path, size_t sz_backup_path, const char *reason) { char fpath[PATHLEN]; fileheader_t backup = { {0} }; int backup_failed = DELETE_FILE_CONTENT_SUCCESS; if(!fh->filename[0] || !direct) return DELETE_FILE_CONTENT_FAILED; #ifdef FN_SAFEDEL if ( #ifdef FN_SAFEDEL_PREFIX_LEN strncmp(fh->filename, FN_SAFEDEL, FN_SAFEDEL_PREFIX_LEN) == 0 || #endif strcmp(fh->filename, FN_SAFEDEL) == 0 || #endif 0) return DELETE_FILE_CONTENT_SUCCESS; if (backup_path) { assert(backup_direct); assert(sz_backup_path > 0); *backup_path = 0; } // solve source file name setdirpath(fpath, direct, fh->filename); if (!dashf(fpath)) return DELETE_FILE_CONTENT_BACKUP_FAILED; // FIXME some announcements were made by sym-links, especial for those // in mail. we should ignore them. if (backup_direct && !dashl(fpath) && strncmp(fh->owner, RECYCLE_BIN_OWNER, strlen(RECYCLE_BIN_OWNER)) != 0) { // FIXME maybe for non-board files we should do this by simply touching // file instead of full log. if (reason && *reason) log_filef(fpath, LOG_CREAT, "\n※ 刪除原因: %s", reason); log_filef(fpath, LOG_CREAT, "\n※ Deleted by: %s (%s) %s\n", cuser.userid, fromhost, Cdatelite(&now)); // TODO or only memcpy(&backup, fh, sizeof(backup)); ? strlcpy(backup.owner, fh->owner, sizeof(backup.owner)); strlcpy(backup.date, fh->date, sizeof(backup.date)); strlcpy(backup.title, fh->title, sizeof(backup.title)); strlcpy(backup.filename, fh->filename, sizeof(backup.filename)); if (backup_direct != direct && strcmp(backup_direct, direct) != 0) { // need to create a new file entry. char *slash = NULL; char bakpath[PATHLEN]; strlcpy(bakpath, backup_direct, sizeof(bakpath)); slash = strrchr(bakpath, '/'); if (slash) *slash = 0; if (stampfile_u(bakpath, &backup) == 0 && Rename(fpath, bakpath) == 0) { strlcpy(fpath, bakpath, sizeof(fpath)); } else { backup_direct = NULL; backup_failed = 1; } } // now, always backup according to fpath if (backup_direct) { #ifdef USE_TIME_CAPSULE if (!timecapsule_archive_new_revision( fpath, &backup, sizeof(backup), backup_path, sz_backup_path)) backup_failed = DELETE_FILE_CONTENT_BACKUP_FAILED; #else // we can't backup to same folder. if (strcmp(direct, backup_direct) == 0) { backup_failed = DELETE_FILE_CONTENT_BACKUP_FAILED; } else { if (append_record(backup_direct, &backup, sizeof(backup)) < 0) backup_failed = DELETE_FILE_CONTENT_BACKUP_FAILED; if (backup_path) strlcpy(backup_path, fpath, sz_backup_path); } // the fpath is used as-is. *fpath = 0; #endif } } // the file should be already in time capsule if (*fpath && unlink(fpath) != 0) return DELETE_FILE_CONTENT_FAILED; return backup_failed; }
static void a_delete(menu_t * pm, const char *backup_dir) { char fpath[PATHLEN], buf[PATHLEN], cmd[PATHLEN]; char ans[4]; fileheader_t backup, *fhdr = &(pm->header[pm->now - pm->page]); const char *msg_errsync = "刪除檔案失敗,請退回上層目錄後再重試一次", *msg_errsync2 = "檔案可能已被它人刪除,請退回上層目錄再重進確認", *msg_errbackup = "檔案已刪除但無法備份。請至 " BN_BUGREPORT "報告您試圖刪除檔案的位置。"; snprintf(fpath, sizeof(fpath), "%s/%s", pm->path, fhdr->filename); setadir(buf, pm->path); if (fhdr->filename[0] == 'H' && fhdr->filename[1] == '.') { getdata(b_lines - 1, 1, "您確定要刪除此精華區連線嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); if (ans[0] != 'y') return; if (delete_fileheader(buf, fhdr, pm->now + 1) == -1) { vmsg(msg_errsync); return; } } else if (dashl(fpath)) { getdata(b_lines - 1, 1, "您確定要刪除此 symbolic link 嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); if (ans[0] != 'y') return; if (delete_fileheader(buf, fhdr, pm->now + 1) == -1) { vmsg(msg_errsync); return; } unlink(fpath); } else if (dashf(fpath)) { getdata(b_lines - 1, 1, "您確定要刪除此檔案嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); if (ans[0] != 'y') return; if (delete_fileheader(buf, fhdr, pm->now + 1) == -1) { vmsg(msg_errsync); return; } switch(delete_file_content(buf, fhdr, backup_dir, NULL, 0)) { case DELETE_FILE_CONTENT_BACKUP_FAILED: vmsg(msg_errbackup); break; case DELETE_FILE_CONTENT_FAILED: vmsg(msg_errsync2); break; default: #ifndef USE_TIME_CAPSULE // When not using time capsule, .DIR content may be changed in // board (BN_DELETE/BN_JUNK) and need to be changed. However // since that's going to be deprecated in future, let's have a // simple workaround here. if (backup_dir) { const char *bn = NULL; if (strstr(backup_dir, "/" BN_JUNK "/")) bn = BN_JUNK; else if (strstr(backup_dir, "/" BN_DELETED "/")) bn = BN_DELETED; if (bn) setbtotal(getbnum(bn)); } #endif break; } } else if (dashd(fpath)) { // TODO(hungte) We should create a top level folder and move everything // inside. // XXX we also check PERM_MAILLIMIT here because RMAIL // may be not trusted... const char *save_bn = ( HasUserPerm(PERM_MAILLIMIT) && (currstat & RMAIL) ) ? BN_JUNK : BN_DELETED; getdata(b_lines - 1, 1, "您確定要刪除整個目錄嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); if (ans[0] != 'y') return; if (delete_fileheader(buf, fhdr, pm->now + 1) == -1) { vmsg(msg_errsync); return; } setapath(buf, save_bn); // XXX because this directory will hold folders from entire site, // let's allow it to use a large set of file names. if (stampadir(buf, &backup, 1) != 0) { vmsg("抱歉,系統目前無法刪除資料,請通知站務人員"); return; } snprintf(cmd, sizeof(cmd), "rm -rf %s;/bin/mv -f %s %s", buf, fpath, buf); system(cmd); strlcpy(backup.owner, cuser.userid, sizeof(backup.owner)); strcpy(backup.title, "◆"); strlcpy(backup.title + 2, fhdr->title + 2, sizeof(backup.title) - 3); // restrict access if source is hidden if ((fhdr->filemode & FILE_BM) || (fhdr->filemode & FILE_HIDE)) backup.filemode |= FILE_BM; /* merge setapath(buf, save_bn); setadir(buf, buf); */ snprintf(buf, sizeof(buf), "man/boards/%c/%s/" FN_DIR, *save_bn, save_bn); append_record(buf, &backup, sizeof(backup)); } else { /* Ptt 損毀的項目 */ getdata(b_lines - 1, 1, "您確定要刪除此損毀的項目嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); if (ans[0] != 'y') return; if (delete_fileheader(buf, fhdr, pm->now + 1) == -1) return; } pm->num--; }