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,263 @@
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 : p4clientapi.h
30
+ *
31
+ * Author : Tony Smith <tony@perforce.com> or <tony@smee.org>
32
+ *
33
+ * Description : Ruby bindings for the Perforce API. Definitions of our
34
+ * main interface to Perforce
35
+ *
36
+ ******************************************************************************/
37
+
38
+
39
+ /*******************************************************************************
40
+ * P4ClientApi class - where we register our Ruby classes and plumb together
41
+ * the components
42
+ ******************************************************************************/
43
+
44
+ class Enviro;
45
+ class P4ClientApi
46
+ {
47
+ public:
48
+ P4ClientApi();
49
+ ~P4ClientApi();
50
+
51
+ // Tagged mode - can be enabled/disabled on a per-command basis
52
+ void Tagged( int enable );
53
+ int IsTagged() { return IsTag(); }
54
+
55
+ // Set track mode - track usage of this command on the server
56
+ int SetTrack( int enable );
57
+ int GetTrack() { return IsTrackMode() != 0; }
58
+
59
+ // Set streams mode
60
+ void SetStreams( int enable );
61
+ int IsStreams() { return IsStreamsMode() != 0; };
62
+
63
+ // Set graph mode
64
+ void SetGraph( int enable );
65
+ int IsGraph() { return IsGraphMode() != 0; };
66
+
67
+ // Returns bool, but may raise exception
68
+ int SetCharset( const char *c );
69
+
70
+ // Set API level for backwards compatibility
71
+ void SetApiLevel( int level );
72
+
73
+ void SetClient( const char *c ) { client.SetClient( c ); }
74
+ void SetCwd( const char *c );
75
+ void SetEnviroFile( const char *c );
76
+ void SetEVar( const char *var, const char *val );
77
+ void SetHost( const char *h ) { client.SetHost( h ); }
78
+ void SetIgnoreFile( const char *f ) { client.SetIgnoreFile( f ); }
79
+ void SetMaxResults( int v ) { maxResults = v; }
80
+ void SetMaxScanRows( int v ) { maxScanRows = v; }
81
+ void SetMaxLockTime( int v ) { maxLockTime = v; }
82
+ VALUE SetEnv( const char *var, const char *val );
83
+ void SetLanguage( const char *l ) { client.SetLanguage( l ); }
84
+ void SetPassword( const char *p ) { client.SetPassword( p ); }
85
+ void SetPort( const char *p ) { client.SetPort( p ); }
86
+ void SetProg( const char *p ) { prog = p; }
87
+ void SetProtocol( const char *var, const char *val );
88
+ void SetTicketFile( const char *p );
89
+ void SetTrustFile( const char *p );
90
+ void SetUser( const char *u ) { client.SetUser( u ); }
91
+ void SetVersion( const char *v ) { version = v; }
92
+ void SetArrayConversion ( int i );
93
+
94
+ int GetApiLevel() { return apiLevel; }
95
+ const StrPtr &GetCharset() { return client.GetCharset(); }
96
+ const StrPtr &GetClient() { return client.GetClient(); }
97
+ const StrPtr &GetConfig() { return client.GetConfig(); }
98
+ const StrPtr &GetCwd() { return client.GetCwd(); }
99
+ const char * GetEnv( const char *v);
100
+ const StrPtr *GetEnviroFile();
101
+ const StrPtr *GetEVar(const char *v);
102
+ const StrPtr &GetHost() { return client.GetHost(); }
103
+ const StrPtr &GetIgnoreFile() { return client.GetIgnoreFile();}
104
+ const StrPtr &GetLanguage() { return client.GetLanguage(); }
105
+ const StrPtr &GetPassword() { return client.GetPassword(); }
106
+ const StrPtr &GetPort() { return client.GetPort(); }
107
+ const StrPtr &GetProg() { return prog; }
108
+ const StrPtr &GetTicketFile() { return ticketFile; }
109
+ const StrPtr &GetTrustFile() { return trustFile; }
110
+ const StrPtr &GetUser() { return client.GetUser(); }
111
+ const StrPtr &GetVersion() { return version; }
112
+
113
+ int IsIgnored( const char *path );
114
+
115
+ int GetMaxResults() { return maxResults; }
116
+ int GetMaxScanRows() { return maxScanRows; }
117
+ int GetMaxLockTime() { return maxLockTime; }
118
+ int GetServerLevel();
119
+ int ServerCaseSensitive();
120
+ int ServerUnicode();
121
+
122
+
123
+ // Session management
124
+ VALUE Connect(); // P4Exception on error
125
+ VALUE Connected(); // Return true if connected and not dropped.
126
+ VALUE Disconnect();
127
+
128
+ // Executing commands.
129
+ VALUE Run( const char *cmd, int argc, char * const *argv );
130
+ VALUE SetInput( VALUE input );
131
+
132
+ // Result handling
133
+ VALUE GetErrors() { return ui.GetResults().GetErrors();}
134
+ VALUE GetWarnings() { return ui.GetResults().GetWarnings();}
135
+ VALUE GetMessages() { return ui.GetResults().GetMessages();}
136
+ VALUE GetTrackOutput() { return ui.GetResults().GetTrack();}
137
+
138
+ // Spec parsing
139
+ VALUE ParseSpec( const char * type, const char *form );
140
+ VALUE FormatSpec( const char *type, VALUE hash );
141
+ VALUE SpecFields( const char * type );
142
+
143
+ // Exception levels:
144
+ //
145
+ // 0 - No exceptions raised
146
+ // 1 - Exceptions raised for errors
147
+ // 2 - Exceptions raised for errors and warnings
148
+ //
149
+ void ExceptionLevel( int i ) { exceptionLevel = i; }
150
+ int ExceptionLevel() { return exceptionLevel; }
151
+
152
+ void Except( const char *func, Error *e );
153
+ void Except( const char *func, const char *msg );
154
+ void Except( const char *func, const char *msg, const char *cmd );
155
+
156
+ //
157
+ // Debugging support. Debug levels are:
158
+ //
159
+ // 1: Debugs commands being executed
160
+ // 2: Debug UI method calls
161
+ // 3: Show garbage collection
162
+ //
163
+ int GetDebug() { return debug; }
164
+ void SetDebug( int d );
165
+
166
+ // Handler support
167
+
168
+ VALUE SetHandler( VALUE handler );
169
+ VALUE GetHandler() { return ui.GetHandler(); }
170
+
171
+ // Progress API support
172
+ VALUE SetProgress( VALUE progress );
173
+ VALUE GetProgress() { return ui.GetProgress(); }
174
+
175
+ // SSO handler
176
+ VALUE SetEnableSSO( VALUE e );
177
+ VALUE GetEnableSSO();
178
+ VALUE GetSSOVars();
179
+ VALUE SetSSOPassResult( VALUE r );
180
+ VALUE GetSSOPassResult();
181
+ VALUE SetSSOFailResult( VALUE r );
182
+ VALUE GetSSOFailResult();
183
+ VALUE SetSSOHandler( VALUE handler );
184
+ VALUE GetSSOHandler() { return ui.GetRubySSOHandler(); }
185
+
186
+ // Ruby garbage collection
187
+ void GCMark();
188
+
189
+
190
+ private:
191
+
192
+ void RunCmd(const char *cmd, ClientUser *ui, int argc, char * const *argv);
193
+
194
+ VALUE ConnectOrReconnect(); // internal connect method
195
+
196
+ enum {
197
+ S_TAGGED = 0x0001,
198
+ S_CONNECTED = 0x0002,
199
+ S_CMDRUN = 0x0004,
200
+ S_UNICODE = 0x0008,
201
+ S_CASEFOLDING = 0x0010,
202
+ S_TRACK = 0x0020,
203
+ S_STREAMS = 0x0040,
204
+ S_GRAPH = 0x0080,
205
+
206
+ S_INITIAL_STATE = 0x00C1, // Streams, Graph, and Tagged enabled by default
207
+ S_RESET_MASK = 0x001E,
208
+ };
209
+
210
+ void InitFlags() { flags = S_INITIAL_STATE; }
211
+ void ResetFlags() { flags &= ~S_RESET_MASK; }
212
+
213
+ void SetTag() { flags |= S_TAGGED; }
214
+ void ClearTag() { flags &= ~S_TAGGED; }
215
+ int IsTag() { return flags & S_TAGGED; }
216
+
217
+ void SetConnected() { flags |= S_CONNECTED; }
218
+ void ClearConnected() { flags &= ~S_CONNECTED; }
219
+ int IsConnected() { return flags & S_CONNECTED; }
220
+
221
+ void SetCmdRun() { flags |= S_CMDRUN; }
222
+ void ClearCmdRun() { flags &= ~S_CMDRUN; }
223
+ int IsCmdRun() { return flags & S_CMDRUN; }
224
+
225
+ void SetUnicode() { flags |= S_UNICODE; }
226
+ void ClearUnicode() { flags &= ~S_UNICODE; }
227
+ int IsUnicode() { return flags & S_UNICODE; }
228
+
229
+ void SetCaseFold() { flags |= S_CASEFOLDING; }
230
+ void ClearCaseFold() { flags &= ~S_CASEFOLDING; }
231
+ int IsCaseFold() { return flags & S_CASEFOLDING; }
232
+
233
+ void SetTrackMode() { flags |= S_TRACK; }
234
+ void ClearTrackMode() { flags &= ~S_TRACK; }
235
+ int IsTrackMode() { return flags & S_TRACK; }
236
+
237
+ void SetStreamsMode() { flags |= S_STREAMS; }
238
+ void ClearStreamsMode() { flags &= ~S_STREAMS; }
239
+ int IsStreamsMode() { return flags & S_STREAMS; }
240
+
241
+ void SetGraphMode() { flags |= S_GRAPH; }
242
+ void ClearGraphMode() { flags &= ~S_GRAPH; }
243
+ int IsGraphMode() { return flags & S_GRAPH; }
244
+
245
+ private:
246
+ ClientApi client;
247
+ ClientUserRuby ui;
248
+ Enviro * enviro;
249
+ SpecMgr specMgr;
250
+ StrBuf prog;
251
+ StrBuf version;
252
+ StrBuf ticketFile;
253
+ StrBuf trustFile;
254
+ int depth;
255
+ int debug;
256
+ int exceptionLevel;
257
+ int apiLevel;
258
+ int server2;
259
+ int flags;
260
+ int maxResults;
261
+ int maxScanRows;
262
+ int maxLockTime;
263
+ };
@@ -0,0 +1,137 @@
1
+ /*******************************************************************************
2
+
3
+ Copyright (c) 2010, 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 : p4error.cc
30
+ *
31
+ * Author : Tony Smith <tony@perforce.com> or <tony@smee.org>
32
+ *
33
+ * Description : Class for bridging Perforce's Error class to Ruby
34
+ *
35
+ ******************************************************************************/
36
+ #include <ruby.h>
37
+ #include "undefdups.h"
38
+ #include <p4/clientapi.h>
39
+ #include "p4rubydebug.h"
40
+ #include "p4utils.h"
41
+ #include "p4error.h"
42
+
43
+
44
+ static void error_free( P4Error *e )
45
+ {
46
+ delete e;
47
+ }
48
+
49
+ static void error_mark( P4Error *e )
50
+ {
51
+ e->GCMark();
52
+ }
53
+
54
+
55
+ P4Error::P4Error( const Error &other )
56
+ {
57
+ this->debug = 0;
58
+
59
+ error = other;
60
+ }
61
+
62
+ VALUE
63
+ P4Error::GetId()
64
+ {
65
+ ErrorId *id = error.GetId( 0 );
66
+ if( !id )
67
+ return INT2NUM( 0 );
68
+ return INT2NUM( id->UniqueCode() );
69
+ }
70
+
71
+ VALUE
72
+ P4Error::GetGeneric()
73
+ {
74
+ return INT2NUM( error.GetGeneric() );
75
+ }
76
+
77
+ VALUE
78
+ P4Error::GetSeverity()
79
+ {
80
+ return INT2NUM( error.GetSeverity() );
81
+ }
82
+
83
+ VALUE
84
+ P4Error::GetText()
85
+ {
86
+ StrBuf t;
87
+ error.Fmt( t, EF_PLAIN );
88
+ return P4Utils::ruby_string( t.Text(), t.Length() );
89
+ }
90
+
91
+ VALUE
92
+ P4Error::GetDict()
93
+ {
94
+ VALUE dictHash = rb_hash_new();
95
+ StrDict* pDict = error.GetDict();
96
+ StrRef key, val;
97
+ // suppress -Wpointer-arith
98
+ for (int i=0;pDict->GetVar(i,key,val) != 0;i++) {
99
+ rb_hash_aset( dictHash,
100
+ P4Utils::ruby_string(key.Text(), key.Length()),
101
+ P4Utils::ruby_string(val.Text(), val.Length()));
102
+ }
103
+ return dictHash;
104
+ }
105
+
106
+ VALUE
107
+ P4Error::Inspect()
108
+ {
109
+ StrBuf a;
110
+ StrBuf b;
111
+
112
+ error.Fmt( a, EF_PLAIN );
113
+ b << "[";
114
+ b << "Gen:" << error.GetGeneric();
115
+ b << "/Sev:" << error.GetSeverity();
116
+ b << "]: ";
117
+ b << a;
118
+ return P4Utils::ruby_string( b.Text(), b.Length() );
119
+ }
120
+
121
+ VALUE
122
+ P4Error::Wrap( VALUE pClass )
123
+ {
124
+ VALUE e;
125
+ VALUE argv[ 1 ];
126
+
127
+ e = Data_Wrap_Struct( pClass, error_mark, error_free, this );
128
+ rb_obj_call_init( e, 0, argv );
129
+ return e;
130
+ }
131
+
132
+ void
133
+ P4Error::GCMark()
134
+ {
135
+ // We don't hold Ruby objects
136
+ }
137
+
data/ext/P4/p4error.h ADDED
@@ -0,0 +1,62 @@
1
+ /*******************************************************************************
2
+
3
+ Copyright (c) 2010, 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 : p4error.h
30
+ *
31
+ * Author : Tony Smith <tony@perforce.com> or <tony@smee.org>
32
+ *
33
+ * Description : Class for bridging Perforce's Error class to Ruby
34
+ *
35
+ ******************************************************************************/
36
+
37
+ class P4Error
38
+ {
39
+ public:
40
+ // Construct by copying another error object
41
+ P4Error( const Error &other );
42
+
43
+ void SetDebug( int d ) { debug = d; }
44
+
45
+ VALUE GetId();
46
+ VALUE GetGeneric();
47
+ VALUE GetSeverity();
48
+ VALUE GetText();
49
+ VALUE GetDict();
50
+ VALUE Inspect();
51
+
52
+ // Wrap as Ruby object of class pClass
53
+ VALUE Wrap( VALUE pClass );
54
+
55
+ // Ruby garbage collection
56
+ void GCMark();
57
+
58
+ private:
59
+ Error error;
60
+ int debug;
61
+ };
62
+