1 //
2 // aegis - project change supervisor
3 // Copyright (C) 2007 Walter Franzini
4 // Copyright (C) 2008 Peter Miller
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or (at
9 // your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this program. If not, see <http://www.gnu.org/licenses/>.
18 //
19 
20 #include <common/error.h>
21 #include <common/nstring.h>
22 #include <common/nstring/list.h>
23 
24 #include <libaegis/arglex2.h>
25 #include <libaegis/change/functor.h>
26 #include <libaegis/help.h>
27 #include <libaegis/os.h>
28 #include <libaegis/project/identifi_sub/plain.h>
29 #include <libaegis/project/invento_walk.h>
30 
31 #include <aedist/archive.h>
32 #include <aedist/arglex3.h>
33 #include <aedist/change/functor/archive.h>
34 #include <aedist/usage.h>
35 
36 
37 void
archive_main()38 archive_main()
39 {
40     nstring dest_dir;
41     nstring_list include_change;
42     nstring_list exclude_change;
43     project_identifier_subset_plain project;
44 
45     arglex();
46     while (arglex_token != arglex_token_eoln)
47     {
48     	switch (arglex_token)
49 	{
50         default:
51             generic_argument(usage);
52             break;
53 
54         case arglex_token_exclude_version:
55             switch (arglex())
56             {
57             default:
58                 option_needs_string(arglex_token_exclude_version, usage);
59                 // NOTREACHED
60 
61             case arglex_token_string:
62                 exclude_change.push_back(arglex_value.alv_string);
63                 break;
64             }
65             break;
66 
67         case arglex_token_exclude_version_not:
68             switch (arglex())
69             {
70             default:
71                 option_needs_string(arglex_token_exclude_version_not, usage);
72                 // NOTREACHED
73 
74             case arglex_token_string:
75                 include_change.push_back(arglex_value.alv_string);
76                 break;
77             }
78             break;
79 
80         case arglex_token_project:
81             project.command_line_parse(usage);
82             continue;
83 
84         case arglex_token_change_directory:
85             if (!dest_dir.empty())
86                 duplicate_option(usage);
87             switch (arglex())
88             {
89             default:
90                 option_needs_string(arglex_token_change_directory, usage);
91                 // NOTREACHED
92 
93             case arglex_token_string:
94                 dest_dir = nstring(arglex_value.alv_string);
95                 break;
96             }
97             break;
98         }
99         arglex();
100     }
101 
102     os_chdir(dest_dir);
103 
104     change_functor_archive
105 	arc
106 	(
107 	    false,
108 	    project.get_pp(),
109 	    ARCHIVE_SUFFIX,
110 	    FINGERPRINT_SUFFIX,
111             include_change,
112             exclude_change
113 	);
114     project_inventory_walk(project.get_pp(), arc);
115 }
116