gereon
12 years ago
7 changed files with 220 additions and 273 deletions
-
123src/parser/readLabFile.cpp
-
19src/parser/readLabFile.h
-
107src/parser/readTraFile.cpp
-
19src/parser/readTraFile.h
-
181src/parser/read_lab_file.cpp
-
24src/parser/read_lab_file.h
-
20src/parser/read_tra_file.h
@ -0,0 +1,123 @@ |
|||||
|
/*
|
||||
|
* readLabFile.cpp |
||||
|
* |
||||
|
* Created on: 21.11.2012 |
||||
|
* Author: Gereon Kremer |
||||
|
*/ |
||||
|
|
||||
|
#include "parser.h"
|
||||
|
|
||||
|
#include "readLabFile.h"
|
||||
|
|
||||
|
#include "src/exceptions/wrong_file_format.h"
|
||||
|
#include "src/exceptions/file_IO_exception.h"
|
||||
|
|
||||
|
#include <cstdlib>
|
||||
|
#include <cstdio>
|
||||
|
#include <cstring>
|
||||
|
#include <clocale>
|
||||
|
#include <iostream>
|
||||
|
#include <errno.h>
|
||||
|
#include <time.h>
|
||||
|
#include <sys/stat.h>
|
||||
|
#include <sys/mman.h>
|
||||
|
#include <fcntl.h>
|
||||
|
#include <locale.h>
|
||||
|
|
||||
|
#include <pantheios/pantheios.hpp>
|
||||
|
#include <pantheios/inserters/integer.hpp>
|
||||
|
|
||||
|
namespace mrmc { |
||||
|
|
||||
|
namespace parser { |
||||
|
|
||||
|
|
||||
|
/*!
|
||||
|
* Reads a .lab file and puts the result in a labeling structure. |
||||
|
* |
||||
|
* Labelings created with this method have to be freed with the delete operator. |
||||
|
* @param node_count the number of states. |
||||
|
* @param filename input .lab file's name. |
||||
|
* @return The pointer to the created labeling object. |
||||
|
*/ |
||||
|
mrmc::models::AtomicPropositionsLabeling * readLabFile(int node_count, const char * filename) |
||||
|
{ |
||||
|
/*!
|
||||
|
* open file and map to memory |
||||
|
*/ |
||||
|
struct stat st; |
||||
|
int f = open(filename, O_RDONLY); |
||||
|
if ((f < 0) || (stat(filename, &st) != 0)) { |
||||
|
/*!
|
||||
|
* |
||||
|
*/ |
||||
|
pantheios::log_ERROR("File could not be opened."); |
||||
|
throw mrmc::exceptions::file_IO_exception(); |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
char* data = (char*) mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, f, 0); |
||||
|
if (data == (char*)-1) |
||||
|
{ |
||||
|
pantheios::log_ERROR("File could not be mapped. Something went wrong with mmap."); |
||||
|
close(f); |
||||
|
throw mrmc::exceptions::file_IO_exception(); |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
char* buf = data; |
||||
|
char sep[] = " \n\t"; |
||||
|
uint_fast32_t proposition_count = 0; |
||||
|
size_t cnt = 0; |
||||
|
|
||||
|
do { |
||||
|
buf += cnt; |
||||
|
cnt = strcspn(buf, sep); |
||||
|
if (cnt > 0) { |
||||
|
if (strncmp(buf, "#DECLARATION", cnt) == 0) continue; |
||||
|
if (strncmp(buf, "#END", cnt) == 0) break; |
||||
|
proposition_count++; |
||||
|
} |
||||
|
else cnt = 1; |
||||
|
} while (cnt > 0); |
||||
|
|
||||
|
mrmc::models::AtomicPropositionsLabeling* result = new mrmc::models::AtomicPropositionsLabeling(node_count, proposition_count); |
||||
|
char proposition[128]; |
||||
|
buf = data; |
||||
|
cnt = 0; |
||||
|
do { |
||||
|
buf += cnt; |
||||
|
cnt = strcspn(buf, sep); |
||||
|
if (cnt > 0) { |
||||
|
if (strncmp(buf, "#DECLARATION", cnt) == 0) continue; |
||||
|
if (strncmp(buf, "#END", cnt) == 0) break; |
||||
|
strncpy(proposition, buf, cnt); |
||||
|
proposition[cnt] = '\0'; |
||||
|
result->addAtomicProposition(proposition); |
||||
|
} |
||||
|
else cnt = 1; |
||||
|
} while (cnt > 0); |
||||
|
buf += 4; |
||||
|
|
||||
|
uint_fast32_t node; |
||||
|
while (1) { |
||||
|
node = strtol(buf, &buf, 10); |
||||
|
while (*buf != '\0') { |
||||
|
cnt = strcspn(buf, sep); |
||||
|
if (cnt == 0) buf++; |
||||
|
else break; |
||||
|
} |
||||
|
strncpy(proposition, buf, cnt); |
||||
|
proposition[cnt] = '\0'; |
||||
|
result->addAtomicPropositionToState(proposition, node); |
||||
|
buf += cnt; |
||||
|
} |
||||
|
|
||||
|
munmap(data, st.st_size); |
||||
|
close(f); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
} //namespace parser
|
||||
|
|
||||
|
} //namespace mrmc
|
@ -0,0 +1,19 @@ |
|||||
|
/* |
||||
|
* read_lab_file.h |
||||
|
* |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include "src/models/atomic_propositions_labeling.h" |
||||
|
|
||||
|
|
||||
|
namespace mrmc { |
||||
|
|
||||
|
namespace parser { |
||||
|
|
||||
|
mrmc::models::AtomicPropositionsLabeling * readLabFile(int node_count, const char * filename); |
||||
|
|
||||
|
} |
||||
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
Tree:
a2b31f7d6b
main
${ noResults }
GSW_AI_LAB/tempest-devel/resources/3rdparty/cudd-3.0.0/nanotrav/adj49.blif
286 lines
3.8 KiB
|