summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles3/shader_compiler_gles3.cpp22
-rw-r--r--drivers/unix/SCsub2
-rw-r--r--drivers/unix/dir_access_unix.cpp93
3 files changed, 104 insertions, 13 deletions
diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp
index 419decce29..5401c8266a 100644
--- a/drivers/gles3/shader_compiler_gles3.cpp
+++ b/drivers/gles3/shader_compiler_gles3.cpp
@@ -441,12 +441,12 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
if (!bnode->single_statement) {
code += _mktab(p_level - 1) + "{\n";
}
-
+
for (int i = 0; i < bnode->statements.size(); i++) {
String scode = _dump_node_code(bnode->statements[i], p_level, r_gen_code, p_actions, p_default_actions);
- if (bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW || bnode->single_statement ) {
+ if (bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW || bnode->single_statement) {
code += scode; //use directly
} else {
code += _mktab(p_level) + scode + ";\n";
@@ -461,20 +461,20 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
SL::VariableDeclarationNode *vdnode = (SL::VariableDeclarationNode *)p_node;
String declaration = _prestr(vdnode->precision) + _typestr(vdnode->datatype);
- for(int i=0;i<vdnode->declarations.size();i++) {
- if (i>0) {
- declaration+=",";
+ for (int i = 0; i < vdnode->declarations.size(); i++) {
+ if (i > 0) {
+ declaration += ",";
} else {
- declaration+=" ";
+ declaration += " ";
}
- declaration += _mkid(vdnode->declarations[i].name);
+ declaration += _mkid(vdnode->declarations[i].name);
if (vdnode->declarations[i].initializer) {
- declaration+="=";
- declaration+=_dump_node_code(vdnode->declarations[i].initializer, p_level, r_gen_code, p_actions, p_default_actions);
+ declaration += "=";
+ declaration += _dump_node_code(vdnode->declarations[i].initializer, p_level, r_gen_code, p_actions, p_default_actions);
}
}
- code+=declaration;
+ code += declaration;
} break;
case SL::Node::TYPE_VARIABLE: {
SL::VariableNode *vnode = (SL::VariableNode *)p_node;
@@ -623,7 +623,7 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener
String left = _dump_node_code(cfnode->blocks[0], p_level, r_gen_code, p_actions, p_default_actions);
String middle = _dump_node_code(cfnode->expressions[0], p_level, r_gen_code, p_actions, p_default_actions);
String right = _dump_node_code(cfnode->expressions[1], p_level, r_gen_code, p_actions, p_default_actions);
- code += _mktab(p_level) + "for (" +left+";"+middle+";"+right+")\n";
+ code += _mktab(p_level) + "for (" + left + ";" + middle + ";" + right + ")\n";
code += _dump_node_code(cfnode->blocks[1], p_level + 1, r_gen_code, p_actions, p_default_actions);
} else if (cfnode->flow_op == SL::FLOW_OP_RETURN) {
diff --git a/drivers/unix/SCsub b/drivers/unix/SCsub
index 5ced44dfda..c560e1289f 100644
--- a/drivers/unix/SCsub
+++ b/drivers/unix/SCsub
@@ -14,4 +14,6 @@ f.close()
env.add_source_files(env.drivers_sources, "*.cpp")
+env["check_c_headers"] = [ [ "mntent.h", "HAVE_MNTENT" ] ]
+
Export('env')
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index 6b8038c3ef..45ea654bad 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -35,10 +35,17 @@
#include <sys/statvfs.h>
#endif
+#include "core/list.h"
#include "os/memory.h"
#include "print_string.h"
#include <errno.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef HAVE_MNTENT
+#include <mntent.h>
+#endif
DirAccess *DirAccessUnix::create_fs() {
@@ -176,13 +183,95 @@ void DirAccessUnix::list_dir_end() {
_cisdir = false;
}
+#ifdef HAVE_MNTENT
+static bool _filter_drive(struct mntent *mnt) {
+ // Ignore devices that don't point to /dev
+ if (strncmp(mnt->mnt_fsname, "/dev", 4) != 0) {
+ return false;
+ }
+
+ // Accept devices mounted at /media, /mnt or /home
+ if (strncmp(mnt->mnt_dir, "/media", 6) == 0 ||
+ strncmp(mnt->mnt_dir, "/mnt", 4) == 0 ||
+ strncmp(mnt->mnt_dir, "/home", 5) == 0) {
+ return true;
+ }
+
+ // Ignore everything else
+ return false;
+}
+#endif
+
+static void _get_drives(List<String> *list) {
+
+#ifdef HAVE_MNTENT
+ // Check /etc/mtab for the list of mounted partitions
+ FILE *mtab = setmntent("/etc/mtab", "r");
+ if (mtab) {
+ struct mntent mnt;
+ char strings[4096];
+
+ while (getmntent_r(mtab, &mnt, strings, sizeof(strings))) {
+ if (mnt.mnt_dir != NULL && _filter_drive(&mnt)) {
+ // Avoid duplicates
+ if (!list->find(mnt.mnt_dir)) {
+ list->push_back(mnt.mnt_dir);
+ }
+ }
+ }
+
+ endmntent(mtab);
+ }
+#endif
+
+ // Add $HOME
+ const char *home = getenv("HOME");
+ if (home) {
+ // Only add if it's not a duplicate
+ if (!list->find(home)) {
+ list->push_back(home);
+ }
+
+ // Check $HOME/.config/gtk-3.0/bookmarks
+ char path[1024];
+ snprintf(path, 1024, "%s/.config/gtk-3.0/bookmarks", home);
+ FILE *fd = fopen(path, "r");
+ if (fd) {
+ char string[1024];
+ while (fgets(string, 1024, fd)) {
+ // Parse only file:// links
+ if (strncmp(string, "file://", 7) == 0) {
+ // Strip any unwanted edges on the strings and push_back if it's not a duplicate
+ String fpath = String(string + 7).strip_edges();
+ if (!list->find(fpath)) {
+ list->push_back(fpath);
+ }
+ }
+ }
+
+ fclose(fd);
+ }
+ }
+
+ list->sort();
+}
+
int DirAccessUnix::get_drive_count() {
- return 0;
+ List<String> list;
+ _get_drives(&list);
+
+ return list.size();
}
+
String DirAccessUnix::get_drive(int p_drive) {
- return "";
+ List<String> list;
+ _get_drives(&list);
+
+ ERR_FAIL_INDEX_V(p_drive, list.size(), "");
+
+ return list[p_drive];
}
Error DirAccessUnix::make_dir(String p_dir) {