1 //
2 // aegis - project change supervisor
3 // Copyright (C) 1999, 2002-2006, 2008, 2011, 2012 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at
8 // your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #include <common/ac/assert.h>
20 
21 #include <common/nstring/list.h>
22 #include <common/trace.h>
23 #include <libaegis/change/file.h>
24 #include <libaegis/os/isa/path_prefix.h>
25 #include <libaegis/project/file.h>
26 
27 
28 bool
file_directory_query(const nstring & file_name,nstring_list & result_in,nstring_list & result_out,view_path_ty as_view_path)29 project::file_directory_query(const nstring &file_name,
30     nstring_list &result_in, nstring_list &result_out,
31     view_path_ty as_view_path)
32 {
33     trace(("project::file_directory_query(file_name = %s)\n{\n",
34         file_name.quote_c().c_str()));
35     result_in.clear();
36     result_out.clear();
37     bool retval = false;
38     for (size_t j = 0;; ++j)
39     {
40         fstate_src_ty *src_data = file_nth(j, as_view_path);
41         if (!src_data)
42             break;
43         nstring filename(src_data->file_name);
44         switch (src_data->usage)
45         {
46         case file_usage_source:
47         case file_usage_config:
48         case file_usage_test:
49         case file_usage_manual_test:
50 #ifndef DEBUG
51         default:
52 #endif
53             if (os_isa_path_prefix(file_name, filename))
54             {
55                 retval = true;
56                 switch (src_data->action)
57                 {
58                 case file_action_remove:
59                     result_out.push_back(filename);
60                     break;
61 
62                 case file_action_create:
63                 case file_action_modify:
64                 case file_action_insulate:
65                 case file_action_transparent:
66 #ifndef DEBUG
67                 default:
68 #endif
69                     result_in.push_back(filename);
70                     break;
71                 }
72             }
73             break;
74 
75         case file_usage_build:
76             break;
77         }
78     }
79     trace(("}\n"));
80     return retval;
81 }
82 
83 
84 void
file_directory_query(string_ty * file_name,string_list_ty * result_in,string_list_ty * result_out,view_path_ty as_view_path)85 project::file_directory_query(string_ty *file_name,
86     string_list_ty *result_in, string_list_ty *result_out,
87     view_path_ty as_view_path)
88 {
89     trace(("project::file_directory_query(file_name = \"%s\")\n{\n",
90         file_name->str_text));
91     assert(result_in);
92     result_in->clear();
93     if (result_out)
94         result_out->clear();
95     for (size_t j = 0;; ++j)
96     {
97         fstate_src_ty *src_data = file_nth(j, as_view_path);
98         if (!src_data)
99             break;
100         switch (src_data->usage)
101         {
102         case file_usage_source:
103         case file_usage_config:
104         case file_usage_test:
105         case file_usage_manual_test:
106 #ifndef DEBUG
107         default:
108 #endif
109             if (os_isa_path_prefix(file_name, src_data->file_name))
110             {
111                 switch (src_data->action)
112                 {
113                 case file_action_remove:
114                     if (result_out)
115                         result_out->push_back(src_data->file_name);
116                     break;
117 
118                 case file_action_create:
119                 case file_action_modify:
120                 case file_action_insulate:
121                 case file_action_transparent:
122 #ifndef DEBUG
123                 default:
124 #endif
125                     result_in->push_back(src_data->file_name);
126                     break;
127                 }
128             }
129             break;
130 
131         case file_usage_build:
132             break;
133         }
134     }
135     trace(("}\n"));
136 }
137 
138 
139 // vim: set ts=8 sw=4 et :
140