/* ************************************************************************** * cat - display the contents of a file */ int cat_file(string path) { CHECK_SO_WIZ; if (!path) { notify_fail("What file do you want to cat?\n"); return 0; } path = FTPATH((string)this_interactive()->query_path(), path); if (!stringp(path)) { notify_fail("Bad file name format.\n"); return 0; } if (!(SECURITY->valid_read(path, geteuid(), "cat"))) { notify_fail("You have no read access to: " + path + "\n"); return 0; } if (file_size(path) <= 0) { notify_fail("No such file: " + path + "\n"); return 0; } cat(path); write("EOF\n"); return 1; }
/* ************************************************************************** * cd - change current directory */ int cd(string str) { string old_path; string new_path; string *parts; object ob; int auto; auto = this_player()->query_option(OPT_AUTO_PWD); CHECK_SO_WIZ; old_path = this_interactive()->query_path(); if (!stringp(str)) { new_path = SECURITY->query_wiz_path(this_player()->query_real_name()); } else switch(str) { case ".": new_path = old_path; if (auto) write("CWD: " + new_path + "\n"); else write("Ok.\n"); return 1; case "-": if (!(new_path = this_player()->query_prop(WIZARD_S_LAST_DIR))) { new_path = SECURITY->query_wiz_path( this_player()->query_real_name()); } break; default: new_path = FTPATH(old_path, str); break; }
/* * Function name: export_mail * Description : With this function the mail-folder of a player can be * exported to a file. * Arguments : string name - the lower case name of the player whose * mailbox is to be exported. * string path - the name of the output file. * Returns : int 1/0 - success/failure. */ static int export_mail(string name, string path) { mapping mail; mixed messages; int index; int size; string text; /* Get the output path and test its valitity by writing the header. */ path = FTPATH(this_player()->query_path(), path); if (file_size(path) != -1) { notify_fail("File " + path + " already exists.\n"); return 0; } /* This may fail if there is no such directory, for instance. */ if (!write_file(path, "Mailbox of: " + capitalize(name) + "\nPrinted at: " + ctime(time()) + "\n\n")) { notify_fail("Failed to write header of " + path + "\n"); return 0; } /* Read the mail file. */ mail = restore_mail(name); if (!mappingp(mail)) { notify_fail("No correct mail folder for player " + name + ".\n"); return 0; } /* Loop over all messages. */ messages = mail[MAIL_MAIL]; index = -1; size = sizeof(messages); while(++index < size) { mail = restore_message(messages[index][MAIL_DATE]); text = "Message: " + (index + 1) + "\nFrom : " + messages[index][MAIL_FROM] + "\n" + (messages[index][MAIL_REPLY] ? "Reply : " : "Subject: ") + messages[index][MAIL_SUBJ] + "\n"; if (mail[MSG_TO] != capitalize(name)) { text += HANGING_INDENT("To : " + COMPOSITE_WORDS(explode(mail[MSG_TO], ",")), 9, 1); } if (mail[MSG_CC] != "") { text += HANGING_INDENT("CC : " + COMPOSITE_WORDS(explode(mail["cc"], ",")), 9, 1); } /* Write the message to file and print a sequence number to the * wizard. Notice that the index of the loop is also increased in * this write-statement. */ write_file(path, text + "Date : " + MAKE_DATE(messages[index][MAIL_DATE]) + " " + DATE_YEAR(messages[index][MAIL_DATE]) + "\n\n" + wrap_text(mail[MSG_BODY]) + "\n\n"); } write("Mail folder written for " + capitalize(name) + ".\nFilename: " + path + "\n"); return 1; }