int main(string dir) { string path = resolve_path(this_player()->query_cwd(), dir); string *files; string *fulls; mixed *combined; if (!sizeof(stat(path))) { return error_out(sprintf("No such file or directory: %s", path)); } if (dirp(path) && path != "/") { path += "/"; } files = filter(get_dir(path), (: $1[0] != '.' :)); if (filep(path)) { fulls = ({ path }); } else {
vector<Poly> thick_line(const Vector2d &from, const Vector2d &to, double width) { vector<Poly> p; if (width < 0.001) return p; if (to.squared_distance(from) < 0.001) return p; Poly poly; Vector2d dir = (to-from); dir.normalize(); dir *= width/4.; Vector2d dirp(-dir.y(),dir.x()); poly.addVertex(from-dir-dirp); poly.addVertex(from-dir+dirp); poly.addVertex(to+dir+dirp); poly.addVertex(to+dir-dirp); p.push_back(poly); return Clipping::getOffset(poly, width/4, jmiter, 0); // slow: // poly.addVertex(from); // poly.addVertex(to); // return Clipping::getOffset(poly, distance/2, jround, distance/2.); }
static int lua_dir(lua_State *L) { int k = 0; const char *s = luaL_checkstring(L, 1); #ifdef _WIN32 SB sb; struct _finddata_t info; long hfind; /* special cases */ lua_createtable(L, 0, 0); if ((s[0]=='/' || s[0]=='\\') && (s[1]=='/' || s[1]=='\\') && !s[2]) { int drive; hfind = GetLogicalDrives(); for (drive='A'; drive<='Z'; drive++) if (hfind & (1<<(drive-'A'))) { lua_pushfstring(L, "%c:/", drive); lua_rawseti(L, -2, ++k); } } else if (dirp(L, 1)) { lua_pushliteral(L, ".."); lua_rawseti(L, -2, ++k); } else { lua_pushnil(L); return 1; } /* files */ sbinit(&sb); sbaddn(&sb, s, strlen(s)); if (sb.len>0 && sb.buffer[sb.len-1]!='/' && sb.buffer[sb.len-1]!='\\') sbadd1(&sb, '/'); sbaddn(&sb, "*.*", 3); sbadd1(&sb, 0); hfind = _findfirst(sb.buffer, &info); if (hfind != -1) { do { if (strcmp(".",info.name) && strcmp("..",info.name)) { lua_pushstring(L, info.name); lua_rawseti(L, -2, ++k); } } while ( _findnext(hfind, &info) != -1 ); _findclose(hfind); } sbfree(&sb); #else DIR *dirp; struct dirent *d; dirp = opendir(s); if (dirp) { lua_createtable(L, 0, 0); while ((d = readdir(dirp))) { int n = NAMLEN(d); lua_pushlstring(L, d->d_name, n); lua_rawseti(L, -2, ++k); } closedir(dirp); } else lua_pushnil(L); #endif return 1; }
static int lua_dirp(lua_State *L) { lua_pushboolean(L, dirp(L, 1)); return 1; }