diff options
author | Bastian Wissler | 2008-04-15 16:17:12 +0200 |
---|---|---|
committer | Bastian Wissler | 2008-04-15 16:17:12 +0200 |
commit | 565f8f731eb8e4516aa56feb4e699a428a68f100 (patch) | |
tree | 2c976b3ff2ba72ae8d0e34884f359de5f89fe622 | |
parent | More complete version of vmchooser. (diff) | |
download | vmchooser-565f8f731eb8e4516aa56feb4e699a428a68f100.tar.gz vmchooser-565f8f731eb8e4516aa56feb4e699a428a68f100.tar.xz vmchooser-565f8f731eb8e4516aa56feb4e699a428a68f100.zip |
missing CXX-file
git-svn-id: http://svn.openslx.org/svn/openslx/openslx-src-tools/trunk/os-plugins/plugins/vmchooser@1743 95ad53e4-c205-0410-b2fa-d234c58c8868
-rw-r--r-- | vmchooser/readLinSess.cxx | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/vmchooser/readLinSess.cxx b/vmchooser/readLinSess.cxx new file mode 100644 index 0000000..8066441 --- /dev/null +++ b/vmchooser/readLinSess.cxx @@ -0,0 +1,114 @@ + +/** + * + * @author Bastian Wissler + * @description: Scan a given folder for XML-Files and get information + * about installed Images / SessionManagers + */ + +#include <stdio.h> +#include <glob.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include <fstream> +#include <iostream> + +#include "inc/DataEntry.h" +#include "inc/functions.h" + +static int errorfunc(const char* errpath, int errno) +{ + fprintf(stderr, "GLOB(): Fehler aufgetreten unter %s mit Fehlernummer %d \n",errpath, errno); + return 0; +} + + +static glob_t* globber(char* path, const char* filetype) +{ + glob_t* gResult = (glob_t*) malloc(sizeof(glob_t)); + char* temp = (char*) malloc(strlen(path)+strlen(filetype)-1); + strcpy(temp, path); + strcat(temp, filetype); + + if (glob(temp, GLOB_NOSORT, &errorfunc, gResult)) { + fprintf(stderr, "Fehler beim Öffnen des Ordners!\n"); + return NULL; + } + return gResult; + +} + +DataEntry** readLinSess(char* path) +{ + + int MAX_LENGTH = 200; + char line[MAX_LENGTH]; + char* found; + char* val; + + if ( path== NULL) { + return NULL; + } + glob_t *gResult = globber(path, "*.desktop"); + if ( gResult== NULL) { + return NULL; + } + if ( gResult->gl_pathc == 0 ) { + return NULL; + } + DataEntry** result = (DataEntry**) malloc(gResult->gl_pathc * sizeof(DataEntry*) +1); + + int c = 0; + + for (int i=0; gResult->gl_pathv[i] != NULL; i++) { + ifstream desk(gResult->gl_pathv[i]); + + DataEntry* de = new DataEntry(); + de->imgtype = LINUX; + while( desk.getline(line, MAX_LENGTH) ) { + found = strstr(line, "Name="); + if(found != NULL) { + val = strtok(found, "="); + val = strtok(NULL, "="); + de->short_description = string(val); + } + found = NULL; + + found = strstr(line, "Exec="); + if(found != NULL) { + val = strtok(found, "="); + val = strtok(NULL, "="); + de->command = string(val); + } + found = NULL; + + found = strstr(line, "Comment="); + if(found != NULL && de->description.empty()) { + val = strtok(found, "="); + val = strtok(NULL, "="); + de->description = string(val); + } + found = NULL; + + found = strstr(line, "Comment[de]="); + if(found != NULL) { + val = strtok(found, "="); + val = strtok(NULL, "="); + de->description = string(val); + } + found = NULL; + } + + if(! (de->short_description.empty() || de->command.empty()) ) { + result[c] = de; + c++; + } + else { + delete de; + } + } + result[c] = NULL; + + return result; +} |