source: CMT/v1r18p20041201/source/cmt_sequence.cxx @ 1

Last change on this file since 1 was 1, checked in by arnault, 19 years ago

Import all tags

File size: 3.8 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// See the complete license in cmt_license.txt "http://www.cecill.info".
5//-----------------------------------------------------------
6
7#include "cmt_sequence.h"
8#include "cmt_system.h"
9
10SequenceRunner::SequenceRunner ()
11{
12}
13
14void SequenceRunner::begin ()
15{
16  started = false;
17  running = false;
18  if (style == CmtSystem::getenv ("CMTSTRUCTURINGSTYLE"))
19    {
20      vdir = CmtSystem::file_separator (); 
21      vdir += "v1"; 
22    } 
23  else
24    {
25      vdir = ""; 
26    }
27  package = "";
28  filename = "";
29  buffer = "";
30  pwd = "";
31}
32
33void SequenceRunner::filter (const cmt_string& line)
34{
35    //cout << "line=[" << line << "]" << endl;
36 
37  CmtSystem::cmt_string_vector words;
38 
39  CmtSystem::split (line, " \t", words);
40 
41  cmt_string verb;
42 
43  if (words.size () > 0) verb = words[0];
44 
45  if (verb.substr (0, 2) == "%%")
46    {
47      if (verb.substr (0, 3) == "%%%") return;
48     
49      if (running)
50        {
51          buffer.write (filename);
52          cout << "%%Writing file " << filename << endl;
53            //cout << buffer << endl;
54          buffer = "";
55         
56          running = false;
57        }
58    }
59 
60  if (verb == "%%package")
61    {
62      package = words[1];
63      version = words[2];
64     
65      if (version == "") version = "v1";
66     
67      cmt_string command = "cmt create ";
68      command += package;
69      command += " ";
70      command += version;
71     
72      CmtSystem::execute (command);
73      cout << "%% creating package " << package << " with command [" << command << "]" << endl;
74
75      if (style == CmtSystem::getenv ("CMTSTRUCTURINGSTYLE"))
76        {
77          vdir = CmtSystem::file_separator (); 
78          vdir += version; 
79        } 
80      else
81        {
82          vdir = ""; 
83        }
84     
85      filename = package;
86      filename += vdir;
87      filename += CmtSystem::file_separator ();
88      filename += "cmt";
89      filename += CmtSystem::file_separator ();
90      filename += "requirements";
91     
92      started = true;
93    }
94  else if (verb == "%%file") 
95    {
96      cmt_string file = words[1];
97     
98      cmt_string d = package;
99      d += vdir;
100      d += CmtSystem::file_separator ();
101      d += file;
102      CmtSystem::dirname (d, d);
103     
104      CmtSystem::mkdir (d);
105      cout << "%% creating directory " << d << endl;
106
107      buffer = "";
108     
109      filename = package;
110      filename += vdir;
111      filename += CmtSystem::file_separator ();
112      filename += file; 
113      started = true;
114    }
115  else if (verb == "%%cdpackage") 
116    {
117      package = words[1];
118     
119      pwd = package;
120      pwd += vdir;
121      pwd += CmtSystem::file_separator ();
122      pwd += "cmt";
123      cout << "%% moving to package " << package << endl;
124    }
125  else if (verb == "%%cmt") 
126    {
127      cmt_string command;
128     
129      if (pwd != "")
130        {
131          command = "cd ";
132          command += pwd;
133          command += " ";
134          command += CmtSystem::command_separator ();
135          command += " ";
136        }
137     
138      command += line;
139      command.replace ("%%", "");
140     
141      cout << "%% executing cmt command " << line << endl;
142
143      CmtSystem::execute (command);
144    }
145  else
146    {
147      buffer += line;
148      buffer += "\n";
149    }
150 
151  if (started)
152    {
153      started = false;
154      running = true;
155    }
156}
157
158void SequenceRunner::end ()
159{
160  if (running)
161    {
162      if (buffer != "")
163        {
164          buffer.write (filename);
165          cout << "%%Writing file " << filename << endl;
166            //cout << buffer << endl;
167          buffer = "";
168        }
169      running = false;
170    }
171}
172
173
Note: See TracBrowser for help on using the repository browser.