2020-09-06 05:43:07 -07:00

32 lines
867 B
C

/* /secure/ambassador/_head.c
* from Dead Souls 3.3
* gives the first 22 lines of a file
* created by Descartes of Borg 940928
*/
#include <lib.h>
inherit LIB_DAEMON;
int cmd(string str) {
string *lines;
string file;
int x;
if(!str) return notify_fail("Syntax: head <file>\n");
file = absolute_path(this_player()->query_cwd(),str);
if(!file_exists(file)) return notify_fail("No such file: "+file+"\n");
else if(!(str = read_file(file)))
return notify_fail("Empty file: "+file+"\n");
if((x = sizeof(lines = explode(str, "\n"))) > 22) x = 23;
str = implode(lines[0..x-1], "\n");
message("system", str, this_player());
return 1;
}
string GetHelp() {
return ("Syntax: head <file>\n\n"
"Gives you the first lines in the file specified.\n"
"See also: cat, more, tail");
}