+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "fs.h"
+#include "icon.h"
+#include "gmath/gmath.h"
+#include "opengl.h"
+#include "app.h"
+
+static IconRenderer *iconrend;
+
+bool init_fs()
+{
+ iconrend = new ShapesIcons;
+ if(!iconrend->init()) {
+ return false;
+ }
+
+ return true;
+}
+
+void cleanup_fs()
+{
+ delete iconrend;
+}
+
+void draw_fs()
+{
+ FSNode test;
+ test.type = FSNODE_DIR;
+
+ Mat4 xform;
+ xform.rotate(time_sec, 0, 0);
+ xform.rotate(0, 0, time_sec * 0.5);
+ xform.translate(0, 2, -5);
+
+ glPushMatrix();
+ glMultMatrixf(xform[0]);
+
+ glUseProgram(0);
+ glDisable(GL_TEXTURE_2D);
+ iconrend->draw(&test);
+
+ glPopMatrix();
+}
+
+// ---- FSNode implementation ----
+FSNode::FSNode()
+{
+ type = FSNODE_UNKNOWN;
+ abs_path = name = suffix = 0;
+}
+
+FSNode::~FSNode()
+{
+ if(abs_path) {
+ delete [] abs_path;
+ }
+}
+
+void FSNode::set_path(const char *s)
+{
+ int len = strlen(s);
+ if(!len) return;
+
+ delete [] abs_path;
+
+ const char *slash = s + len - 1;
+ while(slash > s && *slash != '/') {
+ --slash;
+ }
+ if(name == s) { // no slashes found
+ char buf[1024];
+ if(!getcwd(buf, sizeof buf)) {
+ abort();
+ }
+
+ int dirlen = strlen(buf);
+ abs_path = new char[len + dirlen + 2];
+ sprintf(abs_path, "%s/%s", buf, s);
+
+ name = abs_path + dirlen + 1;
+ suffix = abs_path + len + dirlen - 1;
+ } else {
+ abs_path = new char[len + 1];
+ memcpy(abs_path, s, len + 1);
+
+ name = abs_path + (slash - s);
+ suffix = abs_path + len - 1;
+ }
+
+ while(suffix > name && *suffix != '.') {
+ --suffix;
+ }
+ if(suffix == name) {
+ suffix = 0;
+ }
+}