/* /cmd * from Foundation II * a faster, newer ls command * created by Descartes of Borg 940724 */ #include inherit LIB_DAEMON; static private mapping file_mapping(string *files); static private string display_ls(mixed targ, int aflag, int lflag, int tflag, int nflag, int bflag, int sflag); static private string long_list(string dir, mixed *files); static private string short_list(string dir, mixed *files, int n, int s); int cmd(string str) { string *args, *paths, *options, *files, *tmp, *dirs; string show; int moref, brief, size; int all_files, long_details, time_sort, no_load_info, i, x, maxi; if(str == "" || !str) str = previous_object()->query_cwd(); if(!str) return notify_fail("No current working directory.\n"); i = sizeof(args = explode(str, " ")); if(args[0][0] == '-') { if((x = strlen(args[0])) > 1) options = explode(args[0][1..x-1], ""); else options = ({}); if(i == 1) paths = ({ previous_object()->query_cwd() }); else paths = args[1..i-1]; } else { options = ({}); paths = args; } i = sizeof(options); while(i--) { switch(options[i]) { case "a": all_files = 1; break; case "l": long_details = 1; break; case "t": time_sort = 1; break; case "m": moref = 1; break; case "n": no_load_info = 1; break; case "b": brief = 1; break; case "s": size = 1; break; } } for(i=0, maxi = sizeof(paths), files = ({}); imore(explode(show, "\n"), "system"); else message("system", show, previous_object()); return 1; } for(i=0; ieventPrint(show); else print_long_string(this_player(),show); return 1; } static int is_dir(string str) { return (file_size(str) == -2); } static private mapping file_mapping(string *files) { mapping borg; string *tmp; string dir; int i, maxi, x; for(i=0, maxi = sizeof(files), borg = ([]); i beta[2]) return -1; else return 0; } static private string long_list(string dir, mixed *files) { string ret, acc, loaded; int i, maxi; if(!(maxi = sizeof(files))) return ""; else ret = ""; if(master()->valid_read(dir, previous_object())) acc = "r"; else acc = "-"; if(master()->valid_write(dir, previous_object())) acc += "w"; else acc += "-"; if(member_array(dir[0..strlen(dir)-2], previous_object()->GetSearchPath()) != -1) acc += "x"; else acc += "-"; for(i=0, maxi=sizeof(files); i long) long = x; tmp = previous_object()->GetEnvVar("SCREEN"); if(!tmp || !sscanf(tmp, "%d", x) || !x) x = 80; x = x-2; if(long > x/3-3) long = x/3-3; cols = x/(long+3); rows = (max = sizeof(newfiles))/cols; if(max % cols) rows++; ret = ""; for(i=0; i\n\n" "If you pass a single directory as an argument, it will list all " "files and directories in that directory. If you list a single " "file, then information about that file will be displayed. If you " "use special characters like wild cards, then relevant information " "regarding those files and/or directories will be displayed. The " "options have the following meanings:\n" " -a List all files, including files beginning with a '.'\n" " -b Brief listing, leaving out the directory name\n" " -l Long listing of all details about a file\n" " -m Page the output through more\n" " -n No display of loaded object information\n" " -s No display of size information\n" " -t Sort directory listings by time last modified\n\n" "The -l option overrides the -n and -s options. The columns " "in the -l listing break down in the following manner:\n" " * if loaded, blank space if not loaded\n" " Access permissions, in the form of rwx\n" " Time last modified\n" " Size of the file\n" " File name\n\nSee also: cd, mkdir, mv, pwd, rm, rmdir"); }