1 | #ifdef VHDL |
---|
2 | |
---|
3 | /* |
---|
4 | * $Id: Vhdl_get_header.cpp 113 2009-04-14 18:39:12Z rosiere $ |
---|
5 | * |
---|
6 | * [ Description ] |
---|
7 | * |
---|
8 | */ |
---|
9 | |
---|
10 | #include "Behavioural/include/Vhdl.h" |
---|
11 | #include "Behavioural/include/Version.h" |
---|
12 | #include <time.h> |
---|
13 | #include <sstream> |
---|
14 | #include <fstream> |
---|
15 | |
---|
16 | namespace morpheo { |
---|
17 | namespace behavioural { |
---|
18 | |
---|
19 | #undef FUNCTION |
---|
20 | #define FUNCTION "Vhdl::get_header" |
---|
21 | std::string Vhdl::get_header(uint32_t depth, |
---|
22 | std::string filename) |
---|
23 | { |
---|
24 | log_begin(Behavioural,FUNCTION); |
---|
25 | |
---|
26 | std::string text; |
---|
27 | |
---|
28 | time_t current_time; |
---|
29 | time (¤t_time); |
---|
30 | |
---|
31 | text += "-------------------------------------------------------------------------------\n"; |
---|
32 | text += "-- "+toString(_("File : ")) + filename +"\n"; |
---|
33 | text += "-- "+toString(_("Date : ")) + ctime (¤t_time ); |
---|
34 | text += "-- "+toString(_("Version : ")) + MORPHEO_HEADER +"\n"; |
---|
35 | text += "-- "+toString(_("Id : ")) + _id +" \n"; |
---|
36 | text += "-- "+toString(_("Comment : ")) + _("it's a autogenerated file, don't modify") +"\n"; |
---|
37 | text += "-------------------------------------------------------------------------------\n"; |
---|
38 | |
---|
39 | log_end(Behavioural,FUNCTION); |
---|
40 | |
---|
41 | return text; |
---|
42 | }; |
---|
43 | |
---|
44 | #undef FUNCTION |
---|
45 | #define FUNCTION "vhdl_get_id" |
---|
46 | std::string vhdl_get_id(std::string model_name) |
---|
47 | { |
---|
48 | log_begin(Behavioural,FUNCTION); |
---|
49 | |
---|
50 | std::string id=""; |
---|
51 | |
---|
52 | directory(); |
---|
53 | |
---|
54 | std::string filename = MORPHEO_VHDL + "/" + model_name + VHDL_EXTENSION; |
---|
55 | std::ifstream file; |
---|
56 | |
---|
57 | file.open(filename.c_str(),std::ios::in); |
---|
58 | |
---|
59 | // open file |
---|
60 | if (!file) |
---|
61 | { |
---|
62 | log_printf(INFO,Behavioural,FUNCTION,_("Can't open file : \"%s\""),filename.c_str()); |
---|
63 | } |
---|
64 | else |
---|
65 | { |
---|
66 | // get line with Id |
---|
67 | do |
---|
68 | { |
---|
69 | std::getline(file,id,'\n'); // comment |
---|
70 | } while ((id.find("Id :") == std::string::npos) and |
---|
71 | (not file.eof())); |
---|
72 | |
---|
73 | if (file.eof()) |
---|
74 | log_printf(INFO,Behavioural,FUNCTION,_("\"Id\" not find in file : \"%s\""),filename.c_str()); |
---|
75 | else |
---|
76 | { |
---|
77 | // get id |
---|
78 | id = id.substr(id.find_first_of(':',0)+1,std::string::npos); |
---|
79 | |
---|
80 | // Erase all ' ' |
---|
81 | size_t i=id.find_first_of(' ',0); |
---|
82 | while (i!=std::string::npos) |
---|
83 | { |
---|
84 | id.erase(i,i+1); |
---|
85 | i=id.find_first_of(' ',i); |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | log_end(Behavioural,FUNCTION); |
---|
91 | |
---|
92 | return id; |
---|
93 | }; |
---|
94 | |
---|
95 | }; // end namespace behavioural |
---|
96 | }; // end namespace morpheo |
---|
97 | |
---|
98 | #endif |
---|