1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Copyright (c) 2003, 2004, 2005, 2006, Michael Brasher
5 **
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and associated documentation files (the "Software"),
8 ** to deal in the Software without restriction, including without limitation
9 ** the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 ** and/or sell copies of the Software, and to permit persons to whom the
11 ** Software is furnished to do so, subject to the following conditions:
12 **
13 ** The above copyright notice and this permission notice shall be included in
14 ** all copies or substantial portions of the Software.
15 **
16 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 mike 1.1 ** SOFTWARE.
23 **
24 **==============================================================================
25 */
26
27 #include <string>
28 #include <vector>
29 #include <cstdio>
30 #include <cstdlib>
31
32 using namespace std;
33
34 int main(int argc, char** argv)
35 {
36 // Usage:
37
38 if (argc != 2)
39 {
40 fprintf(stderr, "Usage: %s bug-number\n", argv[0]);
41 exit(1);
42 }
43 mike 1.1
44 // Check bug-number:
45
46 size_t bug_number = atoi(argv[1]);
47
48 if (bug_number == 0)
49 {
50 fprintf(stderr, "%s: invalid bug-number argument\n", argv[0]);
51 exit(1);
52 }
53
54 // Run CVS log and save results.
55
56 FILE* is = popen("cvs log", "r");
57
58 if (!is)
59 {
60 fprintf(stderr, "%s: failed to exec cvs\n", argv[0]);
61 exit(1);
62 }
63
64 mike 1.1 char buffer[1024];
65 vector<string> lines;
66
67 while (fgets(buffer, sizeof(buffer), is) != 0)
68 {
69 // Remove trailing '\n' and '\r' characters.
70
71 char* p = buffer + strlen(buffer);
72
73 while (p != buffer && p[-1] == '\n' || p[-1] == '\r')
74 *--p = '\0';
75
76 // Save working file, bug number, and revision lines only.
77
78 lines.push_back(buffer);
79 }
80
81 fclose(is);
82
83 // Build file-revision pairs:
84
85 mike 1.1 string file;
86 bool found_bug = true;
87
88 for (size_t i = 0; i < lines.size(); i++)
89 {
90 string line = lines[i];
91
92 if (line.substr(0, 14) == "Working file: ")
93 {
94 file = line.substr(14);
95 found_bug = false;
96 continue;
97 }
98
99 if (line.substr(0, 6) == "BUG#: " && line.substr(6) == argv[1])
100 {
101 found_bug = true;
102 continue;
103 }
104
105 if (found_bug && line.substr(0, 9) == "revision ")
106 mike 1.1 {
107 string rev = line.substr(9).c_str();
108
109 char cmd[1024];
110 sprintf(cmd, "cvs update -r %s %s", rev.c_str(), file.c_str());
111 printf("%s\n", cmd);
112 system(cmd);
113 found_bug = false;
114 }
115 }
116
117 return 0;
118 }
|