p4ruby 2022.1.2359956-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,272 @@
1
+ /*******************************************************************************
2
+
3
+ Copyright (c) 2001-2008, Perforce Software, Inc. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+
26
+ *******************************************************************************/
27
+
28
+ /*******************************************************************************
29
+ * Name : p4mergedata.cc
30
+ *
31
+ * Author : Tony Smith <tony@perforce.com> or <tony@smee.org>
32
+ *
33
+ * Description : Class for holding merge data
34
+ *
35
+ ******************************************************************************/
36
+ #include <ruby.h>
37
+ #include "undefdups.h"
38
+ #include <p4/clientapi.h>
39
+ #include <p4/i18napi.h>
40
+ #include <p4/strtable.h>
41
+ #include <p4/spec.h>
42
+ #include "p4result.h"
43
+ #include "p4rubydebug.h"
44
+ #include "clientuserruby.h"
45
+ #include "p4utils.h"
46
+ #include "p4mergedata.h"
47
+
48
+ static void mergedata_free(P4MergeData *md) {
49
+ delete md;
50
+ }
51
+
52
+ static void mergedata_mark(P4MergeData *md) {
53
+ md->GCMark();
54
+ }
55
+
56
+ P4MergeData::P4MergeData(ClientUser *ui, ClientMerge *m, StrPtr &hint,
57
+ VALUE info) {
58
+ this->debug = 0;
59
+ this->actionmerger = 0;
60
+ this->ui = ui;
61
+ this->merger = m;
62
+ this->hint = hint;
63
+ this->info = info;
64
+
65
+ // Extract (forcibly) the paths from the RPC buffer.
66
+ StrPtr *t;
67
+ if ((t = ui->varList->GetVar("baseName"))) base = t->Text();
68
+ if ((t = ui->varList->GetVar("yourName"))) yours = t->Text();
69
+ if ((t = ui->varList->GetVar("theirName"))) theirs = t->Text();
70
+
71
+ }
72
+
73
+ P4MergeData::P4MergeData(ClientUser *ui, ClientResolveA *m, StrPtr &hint,
74
+ VALUE info) {
75
+ this->debug = 0;
76
+ this->merger = 0;
77
+ this->ui = ui;
78
+ this->hint = hint;
79
+ this->actionmerger = m;
80
+ this->info = info;
81
+
82
+ }
83
+
84
+ VALUE P4MergeData::GetYourName() {
85
+ if (merger && yours.Length())
86
+ return P4Utils::ruby_string(yours.Text());
87
+ else
88
+ return Qnil;
89
+ }
90
+
91
+ VALUE P4MergeData::GetTheirName() {
92
+ if (merger && theirs.Length())
93
+ return P4Utils::ruby_string(theirs.Text());
94
+ else
95
+ return Qnil;
96
+ }
97
+
98
+ VALUE P4MergeData::GetBaseName() {
99
+ if (merger && base.Length())
100
+ return P4Utils::ruby_string(base.Text());
101
+ else
102
+ return Qnil;
103
+ }
104
+
105
+ VALUE P4MergeData::GetYourPath() {
106
+ if (merger && merger->GetYourFile())
107
+ return P4Utils::ruby_string(merger->GetYourFile()->Name());
108
+ else
109
+ return Qnil;
110
+ }
111
+
112
+ VALUE P4MergeData::GetTheirPath() {
113
+ if (merger && merger->GetTheirFile())
114
+ return P4Utils::ruby_string(merger->GetTheirFile()->Name());
115
+ else
116
+ return Qnil;
117
+ }
118
+
119
+ VALUE P4MergeData::GetBasePath() {
120
+ if (merger && merger->GetBaseFile())
121
+ return P4Utils::ruby_string(merger->GetBaseFile()->Name());
122
+ else
123
+ return Qnil;
124
+ }
125
+
126
+ VALUE P4MergeData::GetResultPath() {
127
+ if (merger && merger->GetResultFile())
128
+ return P4Utils::ruby_string(merger->GetResultFile()->Name());
129
+ else
130
+ return Qnil;
131
+ }
132
+
133
+ VALUE P4MergeData::GetMergeHint() {
134
+ if (hint.Length())
135
+ return P4Utils::ruby_string(hint.Text());
136
+ else
137
+ return Qnil;
138
+ }
139
+
140
+ VALUE P4MergeData::RunMergeTool() {
141
+ Error e;
142
+ if (merger) {
143
+ ui->Merge(merger->GetBaseFile(), merger->GetTheirFile(),
144
+ merger->GetYourFile(), merger->GetResultFile(), &e);
145
+
146
+ if (e.Test()) return Qfalse;
147
+ return Qtrue;
148
+ }
149
+ return Qfalse;
150
+ }
151
+
152
+ VALUE P4MergeData::GetActionResolveStatus() {
153
+ return actionmerger ? Qtrue : Qfalse;
154
+ }
155
+
156
+ VALUE P4MergeData::GetContentResolveStatus() {
157
+ return merger ? Qtrue : Qfalse;
158
+ }
159
+
160
+ VALUE P4MergeData::GetMergeInfo() {
161
+ return this->info;
162
+ }
163
+
164
+ VALUE P4MergeData::GetMergeAction() {
165
+ // If we don't have an actionMerger then return nil
166
+ if (actionmerger) {
167
+ StrBuf buf;
168
+ actionmerger->GetMergeAction().Fmt(&buf, EF_PLAIN);
169
+ if (buf.Length())
170
+ return P4Utils::ruby_string(buf.Text());
171
+ else
172
+ return Qnil;
173
+ }
174
+ return Qnil;
175
+ }
176
+
177
+ VALUE P4MergeData::GetYoursAction() {
178
+ if (actionmerger) {
179
+ StrBuf buf;
180
+ actionmerger->GetYoursAction().Fmt(&buf, EF_PLAIN);
181
+ if (buf.Length())
182
+ return P4Utils::ruby_string(buf.Text());
183
+ else
184
+ return Qnil;
185
+ }
186
+ return Qnil;
187
+ }
188
+
189
+ VALUE P4MergeData::GetTheirAction() {
190
+ if (actionmerger) {
191
+ StrBuf buf;
192
+ actionmerger->GetTheirAction().Fmt(&buf, EF_PLAIN);
193
+ if (buf.Length())
194
+ return P4Utils::ruby_string(buf.Text());
195
+ else
196
+ return Qnil;
197
+ }
198
+ return Qnil;
199
+ }
200
+
201
+ VALUE P4MergeData::GetType() {
202
+ if (actionmerger) {
203
+ StrBuf buf;
204
+ actionmerger->GetType().Fmt(&buf, EF_PLAIN);
205
+ if (buf.Length())
206
+ return P4Utils::ruby_string(buf.Text());
207
+ else
208
+ return Qnil;
209
+ }
210
+ return Qnil;
211
+ }
212
+
213
+ void P4MergeData::Invalidate() {
214
+ actionmerger = NULL;
215
+ merger = NULL;
216
+ }
217
+
218
+ VALUE P4MergeData::GetString() {
219
+ StrBuf result;
220
+ StrBuf buffer;
221
+
222
+ if (actionmerger) {
223
+ result << "P4MergeData - Action\n";
224
+ actionmerger->GetMergeAction().Fmt(&buffer, EF_INDENT);
225
+ result << "\tmergeAction: " << buffer << "\n";
226
+ buffer.Clear();
227
+
228
+ actionmerger->GetTheirAction().Fmt(&buffer, EF_INDENT);
229
+ result << "\ttheirAction: " << buffer << "\n";
230
+ buffer.Clear();
231
+
232
+ actionmerger->GetYoursAction().Fmt(&buffer, EF_INDENT);
233
+ result << "\tyoursAction: " << buffer << "\n";
234
+ buffer.Clear();
235
+
236
+ actionmerger->GetType().Fmt(&buffer, EF_INDENT);
237
+ result << "\ttype: " << buffer << "\n";
238
+ buffer.Clear();
239
+
240
+ result << "\thint: " << hint << "\n";
241
+ return P4Utils::ruby_string(result.Text());
242
+ } else {
243
+ result << "P4MergeData - Content\n";
244
+ if (yours.Length()) result << "yourName: " << yours << "\n";
245
+ if (theirs.Length()) result << "thierName: " << theirs << "\n";
246
+ if (base.Length()) result << "baseName: " << base << "\n";
247
+
248
+ if ( merger && merger->GetYourFile())
249
+ result << "\tyourFile: " << merger->GetYourFile()->Name() << "\n";
250
+ if ( merger && merger->GetTheirFile())
251
+ result << "\ttheirFile: " << merger->GetTheirFile()->Name() << "\n";
252
+ if ( merger && merger->GetBaseFile())
253
+ result << "\tbaseFile: " << merger->GetBaseFile()->Name() << "\n";
254
+
255
+ return P4Utils::ruby_string(result.Text());
256
+ }
257
+ return Qnil;
258
+ }
259
+
260
+ VALUE P4MergeData::Wrap(VALUE pClass) {
261
+ VALUE md;
262
+ VALUE argv[1];
263
+
264
+ md = Data_Wrap_Struct(pClass, mergedata_mark, mergedata_free, this);
265
+ rb_obj_call_init(md, 0, argv);
266
+ return md;
267
+ }
268
+
269
+ void P4MergeData::GCMark() {
270
+ // We don't hold Ruby objects
271
+ }
272
+
@@ -0,0 +1,97 @@
1
+ /*******************************************************************************
2
+
3
+ Copyright (c) 2001-2008, Perforce Software, Inc. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+
26
+ *******************************************************************************/
27
+
28
+ /*******************************************************************************
29
+ * Name : p4mergedata.h
30
+ *
31
+ * Author : Tony Smith <tony@perforce.com> or <tony@smee.org>
32
+ *
33
+ * Description : Class for holding merge data
34
+ *
35
+ ******************************************************************************/
36
+
37
+ class P4MergeData
38
+ {
39
+ public:
40
+ P4MergeData( ClientUser *ui, ClientMerge *m, StrPtr &hint, VALUE info );
41
+ P4MergeData( ClientUser *ui, ClientResolveA *m, StrPtr &hint, VALUE info );
42
+
43
+ void SetDebug( int d ) { debug = d; }
44
+
45
+ // Content resolve
46
+ VALUE GetYourName();
47
+ VALUE GetTheirName();
48
+ VALUE GetBaseName();
49
+
50
+ VALUE GetYourPath();
51
+ VALUE GetTheirPath();
52
+ VALUE GetBasePath();
53
+ VALUE GetResultPath();
54
+
55
+ VALUE RunMergeTool();
56
+
57
+ // What type of resolve is it?
58
+ VALUE GetActionResolveStatus();
59
+ VALUE GetContentResolveStatus();
60
+
61
+ // Action Resolve
62
+ VALUE GetMergeInfo();
63
+
64
+ VALUE GetMergeAction();
65
+ VALUE GetYoursAction();
66
+ VALUE GetTheirAction();
67
+ VALUE GetType();
68
+
69
+
70
+ VALUE GetString();
71
+ VALUE GetMergeHint();
72
+
73
+ // Wrap as Ruby object of class pClass
74
+ VALUE Wrap( VALUE pClass );
75
+
76
+ // Invalidate our merger and actionMerger objects as they do not survive
77
+ // beyond the life of a resolve while this object itself might well do so,
78
+ // particularly in the case of an exception raised from within the block.
79
+ void Invalidate();
80
+
81
+ // Ruby garbage collection
82
+ void GCMark();
83
+
84
+ private:
85
+ int debug;
86
+ ClientUser * ui;
87
+ StrBuf hint;
88
+ ClientMerge * merger;
89
+ ClientResolveA* actionmerger;
90
+ StrBuf yours;
91
+ StrBuf theirs;
92
+ StrBuf base;
93
+
94
+ VALUE info;
95
+
96
+ };
97
+
@@ -0,0 +1,260 @@
1
+ /*******************************************************************************
2
+
3
+ Copyright (c) 2001-2008, Perforce Software, Inc. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+
26
+ *******************************************************************************/
27
+
28
+
29
+ /*******************************************************************************
30
+ * Name : p4result.cc
31
+ *
32
+ * Author : Tony Smith <tony@perforce.com> or <tony@smee.org>
33
+ *
34
+ * Description : Ruby class for holding results of Perforce commands
35
+ *
36
+ ******************************************************************************/
37
+
38
+ #include <ruby.h>
39
+ #include "undefdups.h"
40
+ #include <p4/clientapi.h>
41
+ #include "gc_hack.h"
42
+ #include "p4error.h"
43
+ #include "p4utils.h"
44
+ #include "p4result.h"
45
+
46
+ P4Result::P4Result()
47
+ {
48
+ output = rb_ary_new();
49
+ warnings = rb_ary_new();
50
+ errors = rb_ary_new();
51
+ messages = rb_ary_new();
52
+ track = rb_ary_new();
53
+ apiLevel = atoi( P4Tag::l_client );
54
+ ID idP4 = rb_intern( "P4" );
55
+ ID idP4Msg = rb_intern( "Message" );
56
+
57
+ VALUE cP4 = rb_const_get_at( rb_cObject, idP4 );
58
+ cP4Msg = rb_const_get_at( cP4, idP4Msg );
59
+
60
+ Reset();
61
+ }
62
+
63
+
64
+ void
65
+ P4Result::Reset()
66
+ {
67
+ output = rb_ary_new();
68
+ warnings = rb_ary_new();
69
+ errors = rb_ary_new();
70
+ messages = rb_ary_new();
71
+ track = rb_ary_new();
72
+ }
73
+
74
+ //
75
+ // Direct output - not via a message of any kind. For example,
76
+ // binary output.
77
+ //
78
+ void
79
+ P4Result::AddOutput( VALUE v )
80
+ {
81
+ rb_ary_push( output, v );
82
+
83
+ //
84
+ // Call the ruby thread scheduler to allow another thread to run
85
+ // now. We should perhaps only call this every 'n' times, but I've
86
+ // no idea what a good value for n might be; so for now at least, n=1
87
+ //
88
+ rb_thread_schedule();
89
+ }
90
+
91
+ /*
92
+ * Main distribution of output to the user. This method sorts the
93
+ * output into groups: output, warnings, errors, and sends all output
94
+ * (regardless of severity) to the messages array.
95
+ */
96
+ void
97
+ P4Result::AddMessage( Error *e )
98
+ {
99
+
100
+ int s;
101
+ s = e->GetSeverity();
102
+
103
+ //
104
+ // Empty and informational messages are pushed out as output as nothing
105
+ // worthy of error handling has occurred. Warnings go into the warnings
106
+ // list and the rest are lumped together as errors.
107
+ //
108
+
109
+ if ( s == E_EMPTY || s == E_INFO )
110
+ rb_ary_push( output, FmtMessage( e ) );
111
+ else if ( s == E_WARN )
112
+ rb_ary_push( warnings, FmtMessage( e ) );
113
+ else
114
+ rb_ary_push( errors, FmtMessage( e ) );
115
+
116
+ //
117
+ // Whatever severity, format the message into the messages array, wrapped
118
+ // up in a P4::Message object.
119
+ //
120
+ rb_ary_push( messages, WrapMessage( e ) );
121
+
122
+ //
123
+ // Call the ruby thread scheduler to allow another thread to run
124
+ // now. We should perhaps only call this every 'n' times, but I've
125
+ // no idea what a good value for n might be; so for now at least, n=1
126
+ //
127
+ rb_thread_schedule();
128
+ }
129
+
130
+ void
131
+ P4Result::AddTrack( const char *msg )
132
+ {
133
+ rb_ary_push( track, P4Utils::ruby_string( msg ) );
134
+
135
+ //
136
+ // Call the ruby thread scheduler to allow another thread to run
137
+ // now. We should perhaps only call this every 'n' times, but I've
138
+ // no idea what a good value for n might be; so for now at least, n=1
139
+ //
140
+ rb_thread_schedule();
141
+ }
142
+
143
+ void
144
+ P4Result::DeleteTrack()
145
+ {
146
+ rb_ary_clear( track );
147
+
148
+ //
149
+ // Call the ruby thread scheduler to allow another thread to run
150
+ // now. We should perhaps only call this every 'n' times, but I've
151
+ // no idea what a good value for n might be; so for now at least, n=1
152
+ //
153
+ rb_thread_schedule();
154
+ }
155
+
156
+ void
157
+ P4Result::AddTrack( VALUE t )
158
+ {
159
+ rb_ary_push( track, t );
160
+
161
+ //
162
+ // Call the ruby thread scheduler to allow another thread to run
163
+ // now. We should perhaps only call this every 'n' times, but I've
164
+ // no idea what a good value for n might be; so for now at least, n=1
165
+ //
166
+ rb_thread_schedule();
167
+ }
168
+
169
+ int
170
+ P4Result::ErrorCount()
171
+ {
172
+ return Length( errors );
173
+ }
174
+
175
+ int
176
+ P4Result::WarningCount()
177
+ {
178
+ return Length( warnings );
179
+ }
180
+
181
+ void
182
+ P4Result::FmtErrors( StrBuf &buf )
183
+ {
184
+ Fmt( "[Error]: ", errors, buf );
185
+ }
186
+
187
+ void
188
+ P4Result::FmtWarnings( StrBuf &buf )
189
+ {
190
+ Fmt( "[Warning]: ", warnings, buf );
191
+ }
192
+
193
+
194
+ int
195
+ P4Result::Length( VALUE ary )
196
+ {
197
+ ID iLength;
198
+ VALUE len;
199
+
200
+ iLength = rb_intern( "length" );
201
+
202
+ len = rb_funcall( ary, iLength, 0 );
203
+ return NUM2INT( len );
204
+ }
205
+
206
+ void
207
+ P4Result::GCMark()
208
+ {
209
+ rb_gc_mark( output );
210
+ rb_gc_mark( errors );
211
+ rb_gc_mark( warnings );
212
+ rb_gc_mark( messages );
213
+ rb_gc_mark( track );
214
+ }
215
+
216
+
217
+ void
218
+ P4Result::Fmt( const char *label, VALUE ary, StrBuf &buf )
219
+ {
220
+ ID idJoin;
221
+ VALUE s1;
222
+ StrBuf csep;
223
+ VALUE rsep;
224
+
225
+ buf.Clear();
226
+ // If the array is empty, then we just return
227
+ if( ! Length( ary ) ) return;
228
+
229
+ // Not empty, so we'll format it.
230
+ idJoin = rb_intern( "join" );
231
+
232
+ // This is the string we'll use to prefix each entry in the array
233
+ csep << "\n\t" << label;
234
+ rsep = P4Utils::ruby_string( csep.Text() );
235
+
236
+ // Since Array#join() won't prefix the first element with the separator
237
+ // we'll have to do it manually.
238
+ buf << csep;
239
+
240
+ // Join the array elements together, and append the result to the buffer
241
+ s1 = rb_funcall( ary, idJoin, 1, rsep );
242
+ buf << StringValuePtr( s1 );
243
+
244
+ return;
245
+ }
246
+
247
+ VALUE
248
+ P4Result::FmtMessage( Error *e )
249
+ {
250
+ StrBuf t;
251
+ e->Fmt( t, EF_PLAIN );
252
+ return P4Utils::ruby_string( t.Text(), t.Length() );
253
+ }
254
+
255
+ VALUE
256
+ P4Result::WrapMessage( Error *e )
257
+ {
258
+ P4Error *pe = new P4Error( *e );
259
+ return pe->Wrap( cP4Msg );
260
+ }
data/ext/P4/p4result.h ADDED
@@ -0,0 +1,86 @@
1
+ /*******************************************************************************
2
+
3
+ Copyright (c) 2001-2008, Perforce Software, Inc. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+
26
+ *******************************************************************************/
27
+
28
+ /*******************************************************************************
29
+ * Name : p4result.h
30
+ *
31
+ * Author : Tony Smith <tony@perforce.com> or <tony@smee.org>
32
+ *
33
+ * Description : C++ class for holding results of Perforce commands
34
+ *
35
+ ******************************************************************************/
36
+
37
+ class P4Result
38
+ {
39
+ public:
40
+
41
+ P4Result();
42
+
43
+ // Setting
44
+ void AddOutput( VALUE v );
45
+ void AddMessage( Error *e );
46
+ void AddTrack( const char *msg );
47
+ void AddTrack( VALUE t );
48
+ void DeleteTrack();
49
+
50
+ // Getting
51
+ VALUE GetOutput() { return output; }
52
+ VALUE GetErrors() { return errors; }
53
+ VALUE GetWarnings() { return warnings; }
54
+ VALUE GetMessages() { return messages; }
55
+ VALUE GetTrack() { return track; }
56
+
57
+ // Get errors/warnings as a formatted string
58
+ void FmtErrors( StrBuf &buf );
59
+ void FmtWarnings( StrBuf &buf );
60
+
61
+ // Set API level for backwards compatibility
62
+ void SetApiLevel( int l ) { apiLevel = l; }
63
+ // Testing
64
+ int ErrorCount();
65
+ int WarningCount();
66
+
67
+ // Clear previous results
68
+ void Reset();
69
+
70
+ // Ruby garbage collection
71
+ void GCMark();
72
+
73
+ private:
74
+ int Length( VALUE ary );
75
+ void Fmt( const char *label, VALUE ary, StrBuf &buf );
76
+ VALUE FmtMessage( Error *e );
77
+ VALUE WrapMessage( Error *e );
78
+
79
+ VALUE cP4Msg;
80
+ VALUE output;
81
+ VALUE warnings;
82
+ VALUE errors;
83
+ VALUE messages;
84
+ VALUE track;
85
+ int apiLevel;
86
+ };