p4ruby 2022.1.2359956-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
data/ext/P4/p4.cpp ADDED
@@ -0,0 +1,1509 @@
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 : p4.cc
30
+ *
31
+ * Author : Tony Smith <tony@perforce.com> or <tony@smee.org>
32
+ *
33
+ * Description : Ruby bindings for the Perforce API.
34
+ *
35
+ * vim:ts=8:sw=4
36
+ ******************************************************************************/
37
+ #include <ruby.h>
38
+ #include "undefdups.h"
39
+ #include <p4/clientapi.h>
40
+ #include <p4/strtable.h>
41
+ #include <p4/spec.h>
42
+ #include <p4/ident.h>
43
+ #include "p4result.h"
44
+ #include "specmgr.h"
45
+ #include "clientuserruby.h"
46
+ #include "p4rubyconf.h"
47
+ #include "p4clientapi.h"
48
+ #include "p4mergedata.h"
49
+ #include "p4mapmaker.h"
50
+ #include "p4error.h"
51
+ #include "p4utils.h"
52
+ #include "extconf.h"
53
+
54
+
55
+ // Our Ident mechanism doesn't really translate to a semantic versioning scheme,
56
+ // So it's been simply replaced by the current version string. We'll see if that
57
+ // needs to change, since a lot of the information this displayed is available
58
+ // via RbConfig locally.
59
+ //static Ident ident = {
60
+ // IdentMagic "P4RUBY " P4RUBY_VERSION
61
+ //};
62
+
63
+
64
+ /*******************************************************************************
65
+ * Our Ruby classes.
66
+ ******************************************************************************/
67
+ VALUE cP4; // Base P4 Class
68
+ VALUE eP4; // Exception class
69
+ VALUE cP4MD; // P4::MergeData class
70
+ VALUE cP4Map; // P4::Map class
71
+ VALUE cP4Msg; // P4::Message class
72
+ VALUE cP4Prog; // P4::Progress class
73
+
74
+
75
+ extern "C"
76
+ {
77
+
78
+ //
79
+ // Construction/destruction
80
+ //
81
+
82
+ static void p4_free( P4ClientApi *p4 )
83
+ {
84
+ delete p4;
85
+ }
86
+
87
+ static void p4_mark( P4ClientApi *p4 )
88
+ {
89
+ p4->GCMark();
90
+ }
91
+
92
+ static VALUE p4_new( VALUE pClass )
93
+ {
94
+ VALUE argv[ 1 ];
95
+ P4ClientApi *p4 = new P4ClientApi();
96
+ VALUE self;
97
+
98
+ self = Data_Wrap_Struct( pClass, p4_mark, p4_free, p4 );
99
+ rb_obj_call_init( self, 0, argv );
100
+ return self;
101
+ }
102
+
103
+
104
+ //
105
+ // Session connect/disconnect
106
+ //
107
+ static VALUE p4_connect( VALUE self )
108
+ {
109
+ P4ClientApi *p4;
110
+ Data_Get_Struct( self, P4ClientApi, p4 );
111
+ return p4->Connect();
112
+ }
113
+
114
+ static VALUE p4_disconnect( VALUE self )
115
+ {
116
+ P4ClientApi *p4;
117
+ Data_Get_Struct( self, P4ClientApi, p4 );
118
+ return p4->Disconnect();
119
+ }
120
+
121
+ static VALUE p4_connected( VALUE self )
122
+ {
123
+ P4ClientApi *p4;
124
+ Data_Get_Struct( self, P4ClientApi, p4 );
125
+ return p4->Connected();
126
+ }
127
+
128
+ static VALUE p4_server_case_sensitive( VALUE self )
129
+ {
130
+ P4ClientApi *p4;
131
+ Data_Get_Struct( self, P4ClientApi, p4 );
132
+ if( p4->ServerCaseSensitive() )
133
+ return Qtrue;
134
+ return Qfalse;
135
+ }
136
+
137
+ static VALUE p4_server_unicode( VALUE self )
138
+ {
139
+ P4ClientApi *p4;
140
+ Data_Get_Struct( self, P4ClientApi, p4 );
141
+ if( p4->ServerUnicode() )
142
+ return Qtrue;
143
+ return Qfalse;
144
+ }
145
+
146
+ static VALUE p4_run_tagged( VALUE self, VALUE tagged )
147
+ {
148
+ P4ClientApi *p4;
149
+ Data_Get_Struct( self, P4ClientApi, p4 );
150
+
151
+ if( ! rb_block_given_p() )
152
+ rb_raise( rb_eArgError, "P4#run_tagged requires a block" );
153
+
154
+ // The user might have passed an integer, or it might be a boolean,
155
+ // we convert to int for consistency.
156
+ int flag = 0;
157
+ if( tagged == Qtrue )
158
+ flag = 1;
159
+ else if( tagged == Qfalse )
160
+ flag = 0;
161
+ else
162
+ flag = NUM2INT( tagged ) ? 1 : 0;
163
+
164
+ int old_value = p4->IsTagged();
165
+ p4->Tagged( flag );
166
+
167
+ VALUE ret_val;
168
+
169
+ //
170
+ // XXX: This should perhaps be protected with rb_ensure()...
171
+ //
172
+ ret_val = rb_yield( self );
173
+
174
+ p4->Tagged( old_value );
175
+ return ret_val;
176
+ }
177
+
178
+ static VALUE p4_get_tagged( VALUE self )
179
+ {
180
+ P4ClientApi *p4;
181
+ Data_Get_Struct( self, P4ClientApi, p4 );
182
+ return p4->IsTagged() ? Qtrue : Qfalse;
183
+ }
184
+
185
+ static VALUE p4_set_tagged( VALUE self, VALUE toggle )
186
+ {
187
+ P4ClientApi *p4;
188
+ Data_Get_Struct( self, P4ClientApi, p4 );
189
+
190
+ // The user might have passed an integer, or it might be a boolean,
191
+ // we convert to int for consistency.
192
+ int flag = 0;
193
+ if( toggle == Qtrue )
194
+ flag = 1;
195
+ else if( toggle == Qfalse )
196
+ flag = 0;
197
+ else
198
+ flag = NUM2INT( toggle ) ? 1 : 0;
199
+
200
+ p4->Tagged( flag );
201
+ return flag ? Qtrue : Qfalse; // Seems to be ignored...
202
+ }
203
+
204
+ static VALUE p4_get_api_level( VALUE self )
205
+ {
206
+ P4ClientApi *p4;
207
+ Data_Get_Struct( self, P4ClientApi, p4 );
208
+ return INT2NUM( p4->GetApiLevel() );
209
+ }
210
+
211
+ static VALUE p4_set_api_level( VALUE self, VALUE level )
212
+ {
213
+ P4ClientApi *p4;
214
+ Data_Get_Struct( self, P4ClientApi, p4 );
215
+ p4->SetApiLevel( NUM2INT( level ) );
216
+ return self;
217
+ }
218
+
219
+ //
220
+ // Getting/Setting Perforce environment
221
+ //
222
+ static VALUE p4_get_charset( VALUE self )
223
+ {
224
+ P4ClientApi *p4;
225
+ Data_Get_Struct( self, P4ClientApi, p4 );
226
+ StrPtr c = p4->GetCharset();
227
+ return P4Utils::ruby_string( c.Text() );
228
+ }
229
+
230
+ static VALUE p4_set_charset( VALUE self, VALUE c )
231
+ {
232
+ P4ClientApi *p4;
233
+ Data_Get_Struct( self, P4ClientApi, p4 );
234
+
235
+ // p4.charset = nil prior to connect can be used to
236
+ // disable automatic charset detection
237
+ if( c == Qnil )
238
+ return p4->SetCharset( 0 );
239
+
240
+ return p4->SetCharset( StringValuePtr( c ) );
241
+ }
242
+
243
+ static VALUE p4_get_p4config( VALUE self )
244
+ {
245
+ P4ClientApi *p4;
246
+ Data_Get_Struct( self, P4ClientApi, p4 );
247
+ StrPtr c = p4->GetConfig();
248
+ return P4Utils::ruby_string( c.Text() );
249
+ }
250
+
251
+ static VALUE p4_get_cwd( VALUE self )
252
+ {
253
+ P4ClientApi *p4;
254
+ Data_Get_Struct( self, P4ClientApi, p4 );
255
+ StrPtr cwd = p4->GetCwd();
256
+ return P4Utils::ruby_string( cwd.Text() );
257
+ }
258
+
259
+ static VALUE p4_set_cwd( VALUE self, VALUE cwd )
260
+ {
261
+ P4ClientApi *p4;
262
+ Data_Get_Struct( self, P4ClientApi, p4 );
263
+ p4->SetCwd( StringValuePtr( cwd ) );
264
+ return Qtrue;
265
+ }
266
+
267
+ static VALUE p4_get_client( VALUE self )
268
+ {
269
+ P4ClientApi *p4;
270
+ Data_Get_Struct( self, P4ClientApi, p4 );
271
+ StrPtr client = p4->GetClient();
272
+ return P4Utils::ruby_string( client.Text() );
273
+ }
274
+
275
+ static VALUE p4_set_client( VALUE self, VALUE client )
276
+ {
277
+ P4ClientApi *p4;
278
+ Data_Get_Struct( self, P4ClientApi, p4 );
279
+ p4->SetClient( StringValuePtr( client ) );
280
+ return Qtrue;
281
+ }
282
+
283
+ static VALUE p4_get_env( VALUE self, VALUE var )
284
+ {
285
+ P4ClientApi *p4;
286
+ const char *val;
287
+ Data_Get_Struct( self, P4ClientApi, p4 );
288
+ val = p4->GetEnv( StringValuePtr( var ) );
289
+ if( !val ) return Qnil;
290
+
291
+ return P4Utils::ruby_string( val );
292
+ }
293
+
294
+ static VALUE p4_set_env( VALUE self, VALUE var, VALUE val )
295
+ {
296
+ P4ClientApi *p4;
297
+ Data_Get_Struct( self, P4ClientApi, p4 );
298
+ return p4->SetEnv( StringValuePtr( var ), StringValuePtr( val ) );
299
+ }
300
+
301
+ static VALUE p4_get_enviro_file( VALUE self )
302
+ {
303
+ P4ClientApi *p4;
304
+ Data_Get_Struct( self, P4ClientApi, p4 );
305
+ const StrPtr *enviro_file = p4->GetEnviroFile();
306
+ return P4Utils::ruby_string( enviro_file->Text() );
307
+ }
308
+
309
+ static VALUE p4_set_enviro_file( VALUE self, VALUE rbstr )
310
+ {
311
+ P4ClientApi *p4;
312
+ Data_Get_Struct( self, P4ClientApi, p4 );
313
+ p4->SetEnviroFile( StringValuePtr(rbstr) );
314
+ return Qtrue;
315
+ }
316
+
317
+ static VALUE p4_get_evar( VALUE self, VALUE var )
318
+ {
319
+ P4ClientApi *p4;
320
+ const StrPtr *val;
321
+ Data_Get_Struct( self, P4ClientApi, p4 );
322
+ val = p4->GetEVar( StringValuePtr( var ) );
323
+ if( !val ) return Qnil;
324
+
325
+ return P4Utils::ruby_string( val->Text() );
326
+ }
327
+
328
+ static VALUE p4_set_evar( VALUE self, VALUE var, VALUE val )
329
+ {
330
+ P4ClientApi *p4;
331
+ Data_Get_Struct( self, P4ClientApi, p4 );
332
+ p4->SetEVar( StringValuePtr( var ), StringValuePtr( val ) );
333
+ return Qtrue;
334
+ }
335
+
336
+ static VALUE p4_get_host( VALUE self )
337
+ {
338
+ P4ClientApi *p4;
339
+ Data_Get_Struct( self, P4ClientApi, p4 );
340
+ StrPtr host = p4->GetHost();
341
+ return P4Utils::ruby_string( host.Text() );
342
+ }
343
+
344
+ static VALUE p4_set_host( VALUE self, VALUE host )
345
+ {
346
+ P4ClientApi *p4;
347
+ Data_Get_Struct( self, P4ClientApi, p4 );
348
+ p4->SetHost( StringValuePtr( host ) );
349
+ return Qtrue;
350
+ }
351
+
352
+ static VALUE p4_get_ignore( VALUE self )
353
+ {
354
+ P4ClientApi *p4;
355
+ Data_Get_Struct( self, P4ClientApi, p4 );
356
+ StrPtr ignore = p4->GetIgnoreFile();
357
+ return P4Utils::ruby_string( ignore.Text() );
358
+ }
359
+
360
+ static VALUE p4_set_ignore( VALUE self, VALUE file )
361
+ {
362
+ P4ClientApi *p4;
363
+ Data_Get_Struct( self, P4ClientApi, p4 );
364
+ p4->SetIgnoreFile( StringValuePtr( file ) );
365
+ return Qtrue;
366
+ }
367
+
368
+ static VALUE p4_is_ignored( VALUE self, VALUE path )
369
+ {
370
+ P4ClientApi *p4;
371
+ Data_Get_Struct( self, P4ClientApi, p4 );
372
+ if( p4->IsIgnored( StringValuePtr( path ) ) )
373
+ return Qtrue;
374
+ return Qfalse;
375
+ }
376
+
377
+ static VALUE p4_get_language( VALUE self )
378
+ {
379
+ P4ClientApi *p4;
380
+ Data_Get_Struct( self, P4ClientApi, p4 );
381
+ StrPtr lang = p4->GetLanguage();
382
+ return P4Utils::ruby_string( lang.Text() );
383
+ }
384
+
385
+ static VALUE p4_set_language( VALUE self, VALUE lang )
386
+ {
387
+ P4ClientApi *p4;
388
+ Data_Get_Struct( self, P4ClientApi, p4 );
389
+ p4->SetLanguage( StringValuePtr( lang ) );
390
+ return Qtrue;
391
+ }
392
+
393
+ static VALUE p4_get_maxresults( VALUE self )
394
+ {
395
+ P4ClientApi *p4;
396
+ Data_Get_Struct( self, P4ClientApi, p4 );
397
+ return INT2NUM( p4->GetMaxResults() );
398
+ }
399
+
400
+ static VALUE p4_set_maxresults( VALUE self, VALUE val )
401
+ {
402
+ P4ClientApi *p4;
403
+ Data_Get_Struct( self, P4ClientApi, p4 );
404
+ p4->SetMaxResults( NUM2INT( val ) );
405
+ return Qtrue;
406
+ }
407
+
408
+ static VALUE p4_get_maxscanrows( VALUE self )
409
+ {
410
+ P4ClientApi *p4;
411
+ Data_Get_Struct( self, P4ClientApi, p4 );
412
+ return INT2NUM( p4->GetMaxScanRows() );
413
+ }
414
+
415
+ static VALUE p4_set_maxscanrows( VALUE self, VALUE val )
416
+ {
417
+ P4ClientApi *p4;
418
+ Data_Get_Struct( self, P4ClientApi, p4 );
419
+ p4->SetMaxScanRows( NUM2INT( val ) );
420
+ return Qtrue;
421
+ }
422
+
423
+ static VALUE p4_get_maxlocktime( VALUE self )
424
+ {
425
+ P4ClientApi *p4;
426
+ Data_Get_Struct( self, P4ClientApi, p4 );
427
+ return INT2NUM( p4->GetMaxLockTime() );
428
+ }
429
+
430
+ static VALUE p4_set_maxlocktime( VALUE self, VALUE val )
431
+ {
432
+ P4ClientApi *p4;
433
+ Data_Get_Struct( self, P4ClientApi, p4 );
434
+ p4->SetMaxLockTime( NUM2INT( val ) );
435
+ return Qtrue;
436
+ }
437
+
438
+ static VALUE p4_get_password( VALUE self )
439
+ {
440
+ P4ClientApi *p4;
441
+ Data_Get_Struct( self, P4ClientApi, p4 );
442
+ StrPtr passwd = p4->GetPassword();
443
+ return P4Utils::ruby_string( passwd.Text() );
444
+ }
445
+
446
+ static VALUE p4_set_password( VALUE self, VALUE passwd )
447
+ {
448
+ P4ClientApi *p4;
449
+ Data_Get_Struct( self, P4ClientApi, p4 );
450
+ p4->SetPassword( StringValuePtr( passwd ) );
451
+ return Qtrue;
452
+ }
453
+
454
+ static VALUE p4_get_port( VALUE self )
455
+ {
456
+ P4ClientApi *p4;
457
+ Data_Get_Struct( self, P4ClientApi, p4 );
458
+ StrPtr port = p4->GetPort();
459
+ return P4Utils::ruby_string( port.Text() );
460
+ }
461
+
462
+ static VALUE p4_set_port( VALUE self, VALUE port )
463
+ {
464
+ P4ClientApi *p4;
465
+ Data_Get_Struct( self, P4ClientApi, p4 );
466
+ if( p4->Connected() )
467
+ rb_raise( eP4, "Can't change port once you've connected." );
468
+
469
+ p4->SetPort( StringValuePtr( port ) );
470
+ return Qtrue;
471
+ }
472
+
473
+ static VALUE p4_get_prog( VALUE self )
474
+ {
475
+ P4ClientApi *p4;
476
+ Data_Get_Struct( self, P4ClientApi, p4 );
477
+ return P4Utils::ruby_string( p4->GetProg().Text() );
478
+ }
479
+
480
+ static VALUE p4_set_prog( VALUE self, VALUE prog )
481
+ {
482
+ P4ClientApi *p4;
483
+ Data_Get_Struct( self, P4ClientApi, p4 );
484
+ p4->SetProg( StringValuePtr( prog ) );
485
+ return Qtrue;
486
+ }
487
+
488
+ static VALUE p4_set_protocol( VALUE self, VALUE var, VALUE val )
489
+ {
490
+ P4ClientApi *p4;
491
+ Data_Get_Struct( self, P4ClientApi, p4 );
492
+ p4->SetProtocol( StringValuePtr( var ), StringValuePtr( val ) );
493
+ return Qtrue;
494
+ }
495
+
496
+ static VALUE p4_get_ticket_file( VALUE self )
497
+ {
498
+ P4ClientApi *p4;
499
+ Data_Get_Struct( self, P4ClientApi, p4 );
500
+ return P4Utils::ruby_string( p4->GetTicketFile().Text() );
501
+ }
502
+
503
+ static VALUE p4_set_ticket_file( VALUE self, VALUE path )
504
+ {
505
+ P4ClientApi *p4;
506
+ Data_Get_Struct( self, P4ClientApi, p4 );
507
+ p4->SetTicketFile( StringValuePtr( path ) );
508
+ return Qtrue;
509
+ }
510
+
511
+ static VALUE p4_get_trust_file( VALUE self )
512
+ {
513
+ P4ClientApi *p4;
514
+ Data_Get_Struct( self, P4ClientApi, p4 );
515
+ return P4Utils::ruby_string( p4->GetTrustFile().Text() );
516
+ }
517
+
518
+ static VALUE p4_set_trust_file( VALUE self, VALUE path )
519
+ {
520
+ P4ClientApi *p4;
521
+ Data_Get_Struct( self, P4ClientApi, p4 );
522
+ p4->SetTrustFile( StringValuePtr( path ) );
523
+ return Qtrue;
524
+ }
525
+
526
+ static VALUE p4_get_user( VALUE self )
527
+ {
528
+ P4ClientApi *p4;
529
+ Data_Get_Struct( self, P4ClientApi, p4 );
530
+ StrPtr user = p4->GetUser();
531
+ return P4Utils::ruby_string( user.Text() );
532
+ }
533
+
534
+ static VALUE p4_set_user( VALUE self, VALUE user )
535
+ {
536
+ P4ClientApi *p4;
537
+ Data_Get_Struct( self, P4ClientApi, p4 );
538
+ p4->SetUser( StringValuePtr( user ) );
539
+ return Qtrue;
540
+ }
541
+
542
+ static VALUE p4_get_version( VALUE self )
543
+ {
544
+ P4ClientApi *p4;
545
+ Data_Get_Struct( self, P4ClientApi, p4 );
546
+ return P4Utils::ruby_string( p4->GetVersion().Text() );
547
+ }
548
+
549
+ static VALUE p4_set_version( VALUE self, VALUE version )
550
+ {
551
+ P4ClientApi *p4;
552
+ Data_Get_Struct( self, P4ClientApi, p4 );
553
+ p4->SetVersion( StringValuePtr( version ) );
554
+ return Qtrue;
555
+ }
556
+
557
+ static VALUE p4_get_track( VALUE self )
558
+ {
559
+ P4ClientApi *p4;
560
+ Data_Get_Struct( self, P4ClientApi, p4 );
561
+ return p4->GetTrack() ? Qtrue : Qfalse;
562
+ }
563
+
564
+ static VALUE p4_set_track( VALUE self, VALUE toggle )
565
+ {
566
+ P4ClientApi *p4;
567
+ Data_Get_Struct( self, P4ClientApi, p4 );
568
+
569
+ // The user might have passed an integer, or it might be a boolean,
570
+ // we convert to int for consistency.
571
+ int flag = 0;
572
+ if( toggle == Qtrue )
573
+ flag = 1;
574
+ else if( toggle == Qfalse )
575
+ flag = 0;
576
+ else
577
+ flag = NUM2INT( toggle ) ? 1 : 0;
578
+
579
+ p4->SetTrack( flag );
580
+ return flag ? Qtrue : Qfalse; // Seems to be ignored...
581
+ }
582
+
583
+ static VALUE p4_get_streams( VALUE self )
584
+ {
585
+ P4ClientApi *p4;
586
+ Data_Get_Struct( self, P4ClientApi, p4 );
587
+ return p4->IsStreams() ? Qtrue : Qfalse;
588
+ }
589
+
590
+ static VALUE p4_set_streams( VALUE self, VALUE toggle )
591
+ {
592
+ P4ClientApi *p4;
593
+ Data_Get_Struct( self, P4ClientApi, p4 );
594
+
595
+ // The user might have passed an integer, or it might be a boolean,
596
+ // we convert to int for consistency.
597
+ int flag = 0;
598
+ if( toggle == Qtrue )
599
+ flag = 1;
600
+ else if( toggle == Qfalse )
601
+ flag = 0;
602
+ else
603
+ flag = NUM2INT( toggle ) ? 1 : 0;
604
+
605
+ p4->SetStreams( flag );
606
+ return flag ? Qtrue : Qfalse; // Seems to be ignored...
607
+ }
608
+
609
+ static VALUE p4_get_graph( VALUE self )
610
+ {
611
+ P4ClientApi *p4;
612
+ Data_Get_Struct( self, P4ClientApi, p4 );
613
+ return p4->IsGraph() ? Qtrue : Qfalse;
614
+ }
615
+
616
+ static VALUE p4_set_graph( VALUE self, VALUE toggle )
617
+ {
618
+ P4ClientApi *p4;
619
+ Data_Get_Struct( self, P4ClientApi, p4 );
620
+
621
+ // The user might have passed an integer, or it might be a boolean,
622
+ // we convert to int for consistency.
623
+ int flag = 0;
624
+ if( toggle == Qtrue )
625
+ flag = 1;
626
+ else if( toggle == Qfalse )
627
+ flag = 0;
628
+ else
629
+ flag = NUM2INT( toggle ) ? 1 : 0;
630
+
631
+ p4->SetGraph( flag );
632
+ return flag ? Qtrue : Qfalse; // Seems to be ignored...
633
+ }
634
+
635
+ static VALUE p4_set_array_conversion( VALUE self, VALUE toggle )
636
+ {
637
+ P4ClientApi *p4;
638
+ Data_Get_Struct( self, P4ClientApi, p4 );
639
+ int flag = 1;
640
+
641
+ if( toggle == Qtrue )
642
+ flag = 1;
643
+ else if( toggle == Qfalse )
644
+ flag = 0;
645
+ else
646
+ flag = NUM2INT( toggle ) ? 1 : 0;
647
+
648
+ p4->SetArrayConversion( flag );
649
+ return flag ? Qtrue : Qfalse;
650
+ }
651
+
652
+ /*******************************************************************************
653
+ * Running commands. General purpose Run method and method for supplying
654
+ * input to "p4 xxx -i" commands
655
+ ******************************************************************************/
656
+
657
+ static VALUE p4_run( VALUE self, VALUE args )
658
+ {
659
+ int i;
660
+ int argc = 0;
661
+ ID idFlatten = rb_intern( "flatten" );
662
+ ID idLength = rb_intern( "length" );
663
+ ID idTo_S = rb_intern( "to_s" );
664
+
665
+ P4ClientApi *p4;
666
+ Data_Get_Struct( self, P4ClientApi, p4 );
667
+
668
+ // Flatten the args array, and extract the Perforce command leaving
669
+ // the remaining args in the array.
670
+ VALUE flatArgs = rb_funcall( args, idFlatten, 0 );
671
+
672
+ if ( ! NUM2INT( rb_funcall( flatArgs, idLength, 0 ) ) )
673
+ rb_raise( eP4, "P4#run requires an argument" );
674
+
675
+ VALUE v = rb_funcall( flatArgs, rb_intern( "shift" ), 0 );
676
+ char *cmd = StringValuePtr( v );
677
+ argc = NUM2INT( rb_funcall( flatArgs, idLength, 0 ) );
678
+
679
+ // Allocate storage on the stack so it's automatically reclaimed
680
+ // when we exit.
681
+ char **p4args = RB_ALLOC_N( char *, argc + 1 );
682
+
683
+ // Copy the args across
684
+ for ( i = 0; i < argc; i++ )
685
+ {
686
+ VALUE entry = rb_ary_entry( flatArgs, i );
687
+ VALUE v = rb_funcall( entry, idTo_S, 0 );
688
+ p4args[ i ] = StringValuePtr( v );
689
+ }
690
+ p4args[ i ] = 0;
691
+
692
+ // Run the command
693
+ VALUE res = p4->Run( cmd, argc, p4args );
694
+ return res;
695
+ }
696
+
697
+ static VALUE p4_set_input( VALUE self, VALUE input )
698
+ {
699
+ P4ClientApi *p4;
700
+ Data_Get_Struct( self, P4ClientApi, p4 );
701
+ return p4->SetInput( input );
702
+ }
703
+
704
+ static VALUE p4_get_errors( VALUE self )
705
+ {
706
+ P4ClientApi *p4;
707
+ Data_Get_Struct( self, P4ClientApi, p4 );
708
+ return p4->GetErrors();
709
+ }
710
+
711
+ static VALUE p4_get_messages( VALUE self )
712
+ {
713
+ P4ClientApi *p4;
714
+ Data_Get_Struct( self, P4ClientApi, p4 );
715
+ return p4->GetMessages();
716
+ }
717
+
718
+ static VALUE p4_get_warnings( VALUE self )
719
+ {
720
+ P4ClientApi *p4;
721
+ Data_Get_Struct( self, P4ClientApi, p4 );
722
+ return p4->GetWarnings();
723
+ }
724
+
725
+ static VALUE p4_set_except_level( VALUE self, VALUE level )
726
+ {
727
+ P4ClientApi *p4;
728
+ Data_Get_Struct( self, P4ClientApi, p4 );
729
+ p4->ExceptionLevel( NUM2INT(level) );
730
+ return level;
731
+ }
732
+
733
+ static VALUE p4_get_except_level( VALUE self )
734
+ {
735
+ P4ClientApi *p4;
736
+ Data_Get_Struct( self, P4ClientApi, p4 );
737
+ return INT2NUM( p4->ExceptionLevel() );
738
+ }
739
+
740
+ static VALUE p4_get_server_level( VALUE self )
741
+ {
742
+ P4ClientApi *p4;
743
+ Data_Get_Struct( self, P4ClientApi, p4 );
744
+ int level = p4->GetServerLevel();
745
+ return INT2NUM( level );
746
+ }
747
+
748
+ static VALUE p4_parse_spec( VALUE self, VALUE type, VALUE form )
749
+ {
750
+ P4ClientApi *p4;
751
+
752
+ Check_Type( form, T_STRING );
753
+ Check_Type( type, T_STRING );
754
+
755
+ Data_Get_Struct( self, P4ClientApi, p4 );
756
+ return p4->ParseSpec( StringValuePtr(type), StringValuePtr(form) );
757
+ }
758
+
759
+ static VALUE p4_format_spec( VALUE self, VALUE type, VALUE hash )
760
+ {
761
+ P4ClientApi *p4;
762
+
763
+ Check_Type( type, T_STRING );
764
+ Check_Type( hash, T_HASH );
765
+
766
+ Data_Get_Struct( self, P4ClientApi, p4 );
767
+ return p4->FormatSpec( StringValuePtr(type), hash );
768
+ }
769
+
770
+ static VALUE p4_track_output( VALUE self )
771
+ {
772
+ P4ClientApi *p4;
773
+ Data_Get_Struct( self, P4ClientApi, p4 );
774
+ return p4->GetTrackOutput();
775
+ }
776
+
777
+ /*******************************************************************************
778
+ * Self identification
779
+ ******************************************************************************/
780
+ static VALUE p4_identify( VALUE self )
781
+ {
782
+ StrBuf s;
783
+ s.Append("P4RUBY ");
784
+ s.Append(P4RUBY_VERSION);
785
+ s.Append(" P4API ");
786
+ s.Append(P4APIVER_STRING);
787
+ s.Append(" PATCHLEVEL ");
788
+ s.Append(P4API_PATCHLEVEL_STRING);
789
+ s.Append(" WITH_LIBS ");
790
+ s.Append(WITH_LIBS);
791
+ return P4Utils::ruby_string( s.Text() );
792
+ }
793
+
794
+ /*******************************************************************************
795
+ * Debugging support
796
+ ******************************************************************************/
797
+ static VALUE p4_get_debug( VALUE self)
798
+ {
799
+ P4ClientApi *p4;
800
+ Data_Get_Struct( self, P4ClientApi, p4);
801
+ return INT2NUM( p4->GetDebug() );
802
+ }
803
+
804
+ static VALUE p4_set_debug( VALUE self, VALUE debug )
805
+ {
806
+ P4ClientApi *p4;
807
+ Data_Get_Struct( self, P4ClientApi, p4 );
808
+ p4->SetDebug( NUM2INT(debug) );
809
+ return Qtrue;
810
+ }
811
+
812
+ /*******************************************************************************
813
+ * Handler support
814
+ ******************************************************************************/
815
+ static VALUE p4_get_handler( VALUE self )
816
+ {
817
+ P4ClientApi *p4;
818
+ Data_Get_Struct( self, P4ClientApi, p4 );
819
+ return p4->GetHandler();
820
+ }
821
+
822
+ static VALUE p4_set_handler( VALUE self, VALUE handler )
823
+ {
824
+ P4ClientApi *p4;
825
+ Data_Get_Struct( self, P4ClientApi, p4 );
826
+ p4->SetHandler( handler );
827
+ return Qtrue;
828
+ }
829
+
830
+ /*******************************************************************************
831
+ * Progress support
832
+ ******************************************************************************/
833
+ static VALUE p4_get_progress( VALUE self )
834
+ {
835
+ P4ClientApi *p4;
836
+ Data_Get_Struct( self, P4ClientApi, p4 );
837
+ return p4->GetProgress();
838
+ }
839
+
840
+ static VALUE p4_set_progress( VALUE self, VALUE progress )
841
+ {
842
+ P4ClientApi *p4;
843
+ Data_Get_Struct( self, P4ClientApi, p4 );
844
+ return p4->SetProgress( progress );
845
+ }
846
+
847
+ /*******************************************************************************
848
+ * SSO handler support
849
+ ******************************************************************************/
850
+ static VALUE p4_get_enabled_sso( VALUE self )
851
+ {
852
+ P4ClientApi *p4;
853
+ Data_Get_Struct( self, P4ClientApi, p4 );
854
+ return p4->GetEnableSSO();
855
+ }
856
+
857
+ static VALUE p4_set_enable_sso( VALUE self, VALUE enable )
858
+ {
859
+ P4ClientApi *p4;
860
+ Data_Get_Struct( self, P4ClientApi, p4 );
861
+ return p4->SetEnableSSO( enable );
862
+ }
863
+
864
+ static VALUE p4_get_sso_vars( VALUE self )
865
+ {
866
+ P4ClientApi *p4;
867
+ Data_Get_Struct( self, P4ClientApi, p4 );
868
+ return p4->GetSSOVars();
869
+ }
870
+
871
+ static VALUE p4_get_sso_passresult( VALUE self )
872
+ {
873
+ P4ClientApi *p4;
874
+ Data_Get_Struct( self, P4ClientApi, p4 );
875
+ return p4->GetSSOPassResult();
876
+ }
877
+
878
+ static VALUE p4_set_sso_passresult( VALUE self, VALUE result )
879
+ {
880
+ P4ClientApi *p4;
881
+ Data_Get_Struct( self, P4ClientApi, p4 );
882
+ return p4->SetSSOPassResult( result );
883
+ }
884
+
885
+ static VALUE p4_get_sso_failresult( VALUE self )
886
+ {
887
+ P4ClientApi *p4;
888
+ Data_Get_Struct( self, P4ClientApi, p4 );
889
+ return p4->GetSSOFailResult();
890
+ }
891
+
892
+ static VALUE p4_set_sso_failresult( VALUE self, VALUE result )
893
+ {
894
+ P4ClientApi *p4;
895
+ Data_Get_Struct( self, P4ClientApi, p4 );
896
+ return p4->SetSSOFailResult( result );
897
+ }
898
+ static VALUE p4_get_ssohandler( VALUE self )
899
+ {
900
+ P4ClientApi *p4;
901
+ Data_Get_Struct( self, P4ClientApi, p4 );
902
+ return p4->GetSSOHandler();
903
+ }
904
+
905
+ static VALUE p4_set_ssohandler( VALUE self, VALUE handler )
906
+ {
907
+ P4ClientApi *p4;
908
+ Data_Get_Struct( self, P4ClientApi, p4 );
909
+ p4->SetSSOHandler( handler );
910
+ return Qtrue;
911
+ }
912
+
913
+ /*******************************************************************************
914
+ * P4::MergeData methods. Construction/destruction defined elsewhere
915
+ ******************************************************************************/
916
+
917
+ static VALUE p4md_getyourname( VALUE self )
918
+ {
919
+ P4MergeData *md = 0;
920
+ Data_Get_Struct( self, P4MergeData, md );
921
+ return md->GetYourName();
922
+ }
923
+
924
+ static VALUE p4md_gettheirname( VALUE self )
925
+ {
926
+ P4MergeData *md = 0;
927
+ Data_Get_Struct( self, P4MergeData, md );
928
+ return md->GetTheirName();
929
+ }
930
+
931
+ static VALUE p4md_getbasename( VALUE self )
932
+ {
933
+ P4MergeData *md = 0;
934
+ Data_Get_Struct( self, P4MergeData, md );
935
+ return md->GetBaseName();
936
+ }
937
+
938
+ static VALUE p4md_getyourpath( VALUE self )
939
+ {
940
+ P4MergeData *md = 0;
941
+ Data_Get_Struct( self, P4MergeData, md );
942
+ return md->GetYourPath();
943
+ }
944
+
945
+ static VALUE p4md_gettheirpath( VALUE self )
946
+ {
947
+ P4MergeData *md = 0;
948
+ Data_Get_Struct( self, P4MergeData, md );
949
+ return md->GetTheirPath();
950
+ }
951
+
952
+ static VALUE p4md_getbasepath( VALUE self )
953
+ {
954
+ P4MergeData *md = 0;
955
+ Data_Get_Struct( self, P4MergeData, md );
956
+ return md->GetBasePath();
957
+ }
958
+
959
+ static VALUE p4md_getresultpath( VALUE self )
960
+ {
961
+ P4MergeData *md = 0;
962
+ Data_Get_Struct( self, P4MergeData, md );
963
+ return md->GetResultPath();
964
+ }
965
+
966
+ static VALUE p4md_getmergehint( VALUE self )
967
+ {
968
+ P4MergeData *md = 0;
969
+ Data_Get_Struct( self, P4MergeData, md );
970
+ return md->GetMergeHint();
971
+ }
972
+
973
+ static VALUE p4md_runmerge( VALUE self )
974
+ {
975
+ P4MergeData *md = 0;
976
+ Data_Get_Struct( self, P4MergeData, md );
977
+ return md->RunMergeTool();
978
+ }
979
+
980
+ static VALUE p4md_getcontentresolve( VALUE self )
981
+ {
982
+ P4MergeData *md = 0;
983
+ Data_Get_Struct( self, P4MergeData, md );
984
+ return md->GetContentResolveStatus();
985
+ }
986
+
987
+ //
988
+ // Additional methods added for action resolve
989
+ //
990
+ static VALUE p4md_getactionresolve( VALUE self )
991
+ {
992
+ P4MergeData *md = 0;
993
+ Data_Get_Struct( self, P4MergeData, md );
994
+ return md->GetActionResolveStatus();
995
+ }
996
+
997
+ static VALUE p4md_getyoursaction( VALUE self )
998
+ {
999
+ P4MergeData *md = 0;
1000
+ Data_Get_Struct( self, P4MergeData, md );
1001
+ return md->GetYoursAction();
1002
+ }
1003
+
1004
+ static VALUE p4md_gettheiraction( VALUE self )
1005
+ {
1006
+ P4MergeData *md = 0;
1007
+ Data_Get_Struct( self, P4MergeData, md );
1008
+ return md->GetTheirAction();
1009
+ }
1010
+
1011
+ static VALUE p4md_getmergeaction( VALUE self )
1012
+ {
1013
+ P4MergeData *md = 0;
1014
+ Data_Get_Struct( self, P4MergeData, md );
1015
+ return md->GetMergeAction();
1016
+ }
1017
+
1018
+ static VALUE p4md_getactiontype( VALUE self )
1019
+ {
1020
+ P4MergeData *md = 0;
1021
+ Data_Get_Struct( self, P4MergeData, md );
1022
+ return md->GetType();
1023
+ }
1024
+
1025
+ static VALUE p4md_getinfo( VALUE self )
1026
+ {
1027
+ P4MergeData *md = 0;
1028
+ Data_Get_Struct( self, P4MergeData, md );
1029
+ return md->GetMergeInfo();
1030
+ }
1031
+
1032
+ static VALUE p4md_invalidate( VALUE self )
1033
+ {
1034
+ P4MergeData *md = 0;
1035
+ Data_Get_Struct( self, P4MergeData, md );
1036
+ md->Invalidate();
1037
+ return self;
1038
+ }
1039
+
1040
+ static VALUE p4md_tos( VALUE self )
1041
+ {
1042
+ P4MergeData *md = 0;
1043
+ Data_Get_Struct( self, P4MergeData, md );
1044
+ return md->GetString();
1045
+ }
1046
+ /******************************************************************************
1047
+ * P4::Map class
1048
+ ******************************************************************************/
1049
+ static void p4map_free( P4MapMaker *m )
1050
+ {
1051
+ delete m;
1052
+ }
1053
+
1054
+ static VALUE p4map_new( int argc, VALUE *argv, VALUE pClass )
1055
+ {
1056
+ //VALUE pClass;
1057
+ VALUE array;
1058
+ VALUE self;
1059
+ P4MapMaker *m = new P4MapMaker;
1060
+
1061
+ // First arg is the class
1062
+ // pClass = argv[ 0 ];
1063
+
1064
+ // Now instantiate the new object.
1065
+ self = Data_Wrap_Struct( pClass, 0, p4map_free, m );
1066
+ rb_obj_call_init( self, 0, argv );
1067
+
1068
+ if( argc )
1069
+ {
1070
+ array = argv[ 0 ];
1071
+ if( !rb_obj_is_kind_of( array, rb_cArray ) )
1072
+ rb_raise( rb_eRuntimeError, "Not an array" );
1073
+
1074
+ StrBuf t;
1075
+ ID idLen = rb_intern( "length" );
1076
+ int len;
1077
+ VALUE entry;
1078
+
1079
+ // Now iterate over the array, inserting the mappings
1080
+ len = NUM2INT( rb_funcall( array, idLen, 0 ) );
1081
+ for( int i = 0; i < len; i++ )
1082
+ {
1083
+ entry = rb_ary_entry( array, i );
1084
+ m->Insert( entry );
1085
+ }
1086
+ }
1087
+ return self;
1088
+ }
1089
+
1090
+ //
1091
+ // Joins the RHS of the first mapping with the LHS of the second, and
1092
+ // returns a new P4::Map object made up of the LHS of the first and the
1093
+ // RHS of the second where the joins match up.
1094
+ //
1095
+ static VALUE p4map_join( VALUE pClass, VALUE left, VALUE right )
1096
+ {
1097
+ P4MapMaker * l = 0;
1098
+ P4MapMaker * r = 0;
1099
+ P4MapMaker * j = 0;
1100
+ VALUE m;
1101
+ VALUE argv[ 1 ];
1102
+
1103
+ Data_Get_Struct( left, P4MapMaker, l );
1104
+ Data_Get_Struct( right, P4MapMaker, r );
1105
+
1106
+ j = P4MapMaker::Join( l, r );
1107
+ if( !j ) return Qnil;
1108
+
1109
+ m = Data_Wrap_Struct( pClass, 0, p4map_free, j );
1110
+ rb_obj_call_init( m, 0, argv );
1111
+ return m;
1112
+ }
1113
+
1114
+ //
1115
+ // Debugging support
1116
+ //
1117
+ static VALUE p4map_inspect( VALUE self )
1118
+ {
1119
+ P4MapMaker * m = 0;
1120
+ StrBuf b;
1121
+ StrBuf tb;
1122
+
1123
+ tb.Alloc( 32 );
1124
+ sprintf( tb.Text(), "%p", (void*) self );
1125
+ tb.SetLength();
1126
+
1127
+ Data_Get_Struct( self, P4MapMaker, m );
1128
+
1129
+ b << "#<P4::Map:" << tb << "> ";
1130
+
1131
+ m->Inspect( b );
1132
+ return P4Utils::ruby_string( b.Text(), b.Length() );
1133
+ }
1134
+
1135
+ //
1136
+ // Insert a mapping into a P4::Map object. Can be called with either
1137
+ // one, or two arguments. If one, it's assumed to be a string containing
1138
+ // either a half-map, or both halves of the mapping.
1139
+ //
1140
+ static VALUE p4map_insert( int argc, VALUE *argv, VALUE self )
1141
+ {
1142
+ P4MapMaker * m = 0;
1143
+ StrBuf t;
1144
+
1145
+ Data_Get_Struct( self, P4MapMaker, m );
1146
+
1147
+ if( argc < 1 || argc > 2 )
1148
+ rb_raise( rb_eArgError, "P4::Map#insert takes 1, or 2 arguments" );
1149
+
1150
+
1151
+ if( argc == 1 )
1152
+ {
1153
+ // A mapping with only a left hand side.
1154
+ m->Insert( *argv );
1155
+ return self;
1156
+ }
1157
+
1158
+ if( argc == 2 )
1159
+ {
1160
+ // Separate left- and right-hand strings.
1161
+ VALUE left;
1162
+ VALUE right;
1163
+
1164
+ left = *argv++;
1165
+ right = *argv;
1166
+
1167
+ m->Insert( left, right );
1168
+ }
1169
+ return self;
1170
+ }
1171
+ static VALUE p4map_clear( VALUE self )
1172
+ {
1173
+ P4MapMaker * m = 0;
1174
+
1175
+ Data_Get_Struct( self, P4MapMaker, m );
1176
+ m->Clear();
1177
+ return Qtrue;
1178
+ }
1179
+
1180
+ static VALUE p4map_count( VALUE self )
1181
+ {
1182
+ P4MapMaker * m = 0;
1183
+
1184
+ Data_Get_Struct( self, P4MapMaker, m );
1185
+ return INT2NUM( m->Count() );
1186
+ }
1187
+
1188
+ static VALUE p4map_empty( VALUE self )
1189
+ {
1190
+ P4MapMaker * m = 0;
1191
+
1192
+ Data_Get_Struct( self, P4MapMaker, m );
1193
+ return m->Count() ? Qfalse : Qtrue;
1194
+ }
1195
+
1196
+ static VALUE p4map_reverse( VALUE self )
1197
+ {
1198
+ P4MapMaker * m = 0;
1199
+ P4MapMaker * m2 = 0;
1200
+ VALUE rval;
1201
+ VALUE argv[ 1 ];
1202
+
1203
+ Data_Get_Struct( self, P4MapMaker, m );
1204
+ m2 = new P4MapMaker( *m );
1205
+ m2->Reverse();
1206
+
1207
+ rval = Data_Wrap_Struct( cP4Map, 0, p4map_free, m2 );
1208
+ rb_obj_call_init( rval, 0, argv );
1209
+ return rval;
1210
+ }
1211
+
1212
+ //
1213
+ // P4::Map#translate( string, fwd=true )
1214
+ //
1215
+ static VALUE p4map_trans( int argc, VALUE *argv, VALUE self )
1216
+ {
1217
+ P4MapMaker * m = 0;
1218
+ int fwd = 1;
1219
+ VALUE string;
1220
+
1221
+ if( argc < 1 || argc > 2 )
1222
+ rb_raise( rb_eArgError,
1223
+ "Invalid arguments to P4::Map#translate. "
1224
+ "Pass the string you wish to translate, and an optional "
1225
+ "boolean to indicate whether translation should be in "
1226
+ "the forward direction." );
1227
+
1228
+ argc--;
1229
+ string = *argv++;
1230
+
1231
+ if( argc && *argv == Qfalse )
1232
+ fwd = 0;
1233
+
1234
+ Data_Get_Struct( self, P4MapMaker, m );
1235
+ return m->Translate( string, fwd );
1236
+ }
1237
+
1238
+ static VALUE p4map_includes( VALUE self, VALUE string )
1239
+ {
1240
+ P4MapMaker * m = 0;
1241
+
1242
+ Data_Get_Struct( self, P4MapMaker, m );
1243
+ if( m->Translate( string, 1 ) != Qnil )
1244
+ return Qtrue;
1245
+ if( m->Translate( string, 0 ) != Qnil )
1246
+ return Qtrue;
1247
+ return Qfalse;
1248
+ }
1249
+
1250
+ static VALUE p4map_lhs( VALUE self )
1251
+ {
1252
+ P4MapMaker * m = 0;
1253
+
1254
+ Data_Get_Struct( self, P4MapMaker, m );
1255
+ return m->Lhs();
1256
+ }
1257
+
1258
+ static VALUE p4map_rhs( VALUE self )
1259
+ {
1260
+ P4MapMaker * m = 0;
1261
+
1262
+ Data_Get_Struct( self, P4MapMaker, m );
1263
+ return m->Rhs();
1264
+ }
1265
+
1266
+ static VALUE p4map_to_a( VALUE self )
1267
+ {
1268
+ P4MapMaker * m = 0;
1269
+
1270
+ Data_Get_Struct( self, P4MapMaker, m );
1271
+ return m->ToA();
1272
+ }
1273
+
1274
+ /*******************************************************************************
1275
+ * P4::Message methods. Construction/destruction defined elsewhere
1276
+ ******************************************************************************/
1277
+ static VALUE p4msg_get_severity( VALUE self )
1278
+ {
1279
+ P4Error * e = 0;
1280
+
1281
+ Data_Get_Struct( self, P4Error, e );
1282
+ return e->GetSeverity();
1283
+ }
1284
+
1285
+ static VALUE p4msg_get_generic( VALUE self )
1286
+ {
1287
+ P4Error * e = 0;
1288
+
1289
+ Data_Get_Struct( self, P4Error, e );
1290
+ return e->GetGeneric();
1291
+ }
1292
+
1293
+ static VALUE p4msg_get_text( VALUE self )
1294
+ {
1295
+ P4Error * e = 0;
1296
+
1297
+ Data_Get_Struct( self, P4Error, e );
1298
+ return e->GetText();
1299
+ }
1300
+
1301
+ static VALUE p4msg_get_dict( VALUE self )
1302
+ {
1303
+ P4Error * e = 0;
1304
+
1305
+ Data_Get_Struct( self, P4Error, e );
1306
+ return e->GetDict();
1307
+ }
1308
+
1309
+ static VALUE p4msg_get_id( VALUE self )
1310
+ {
1311
+ P4Error * e = 0;
1312
+
1313
+ Data_Get_Struct( self, P4Error, e );
1314
+ return e->GetId();
1315
+ }
1316
+ static VALUE p4msg_inspect( VALUE self )
1317
+ {
1318
+ P4Error * e = 0;
1319
+
1320
+ Data_Get_Struct( self, P4Error, e );
1321
+ return e->Inspect();
1322
+ }
1323
+
1324
+
1325
+ /******************************************************************************
1326
+ * Extension initialisation
1327
+ ******************************************************************************/
1328
+
1329
+ void Init_P4()
1330
+ {
1331
+ // Ruby instantiation
1332
+ eP4 = rb_define_class( "P4Exception", rb_eRuntimeError );
1333
+
1334
+ // We ensure this class already exists by loading the version file in P4.rb.
1335
+ // If we don't do this, calling things via rake might change the load order
1336
+ // in "interesting" ways.
1337
+ cP4 = rb_path2class("P4");
1338
+
1339
+ rb_define_singleton_method( cP4, "new", RUBY_METHOD_FUNC(p4_new), 0 );
1340
+
1341
+ // Protocol options
1342
+ rb_define_method( cP4, "api_level", RUBY_METHOD_FUNC(p4_get_api_level), 0);
1343
+ rb_define_method( cP4, "api_level=", RUBY_METHOD_FUNC(p4_set_api_level), 1);
1344
+ rb_define_method( cP4, "streams?", RUBY_METHOD_FUNC(p4_get_streams) , 0 );
1345
+ rb_define_method( cP4, "streams=", RUBY_METHOD_FUNC(p4_set_streams) , 1 );
1346
+ rb_define_method( cP4, "tagged", RUBY_METHOD_FUNC(p4_run_tagged), 1 );
1347
+ rb_define_method( cP4, "tagged?", RUBY_METHOD_FUNC(p4_get_tagged), 0 );
1348
+ rb_define_method( cP4, "tagged=", RUBY_METHOD_FUNC(p4_set_tagged), 1 );
1349
+ rb_define_method( cP4, "track?", RUBY_METHOD_FUNC(p4_get_track) , 0 );
1350
+ rb_define_method( cP4, "track=", RUBY_METHOD_FUNC(p4_set_track) , 1 );
1351
+ rb_define_method( cP4, "graph?", RUBY_METHOD_FUNC(p4_get_graph) , 0 );
1352
+ rb_define_method( cP4, "graph=", RUBY_METHOD_FUNC(p4_set_graph) , 1 );
1353
+
1354
+
1355
+ // Perforce client settings.
1356
+ //
1357
+ rb_define_method( cP4, "charset", RUBY_METHOD_FUNC(p4_get_charset) , 0 );
1358
+ rb_define_method( cP4, "charset=", RUBY_METHOD_FUNC(p4_set_charset) , 1 );
1359
+ rb_define_method( cP4, "cwd", RUBY_METHOD_FUNC(p4_get_cwd) , 0 );
1360
+ rb_define_method( cP4, "cwd=", RUBY_METHOD_FUNC(p4_set_cwd) , 1 );
1361
+ rb_define_method( cP4, "client", RUBY_METHOD_FUNC(p4_get_client) , 0 );
1362
+ rb_define_method( cP4, "client=", RUBY_METHOD_FUNC(p4_set_client) , 1 );
1363
+ rb_define_method( cP4, "env", RUBY_METHOD_FUNC(p4_get_env) , 1 );
1364
+ rb_define_method( cP4, "set_env", RUBY_METHOD_FUNC(p4_set_env) , 2 );
1365
+ rb_define_method( cP4, "enviro_file", RUBY_METHOD_FUNC(p4_get_enviro_file), 0);
1366
+ rb_define_method( cP4, "enviro_file=", RUBY_METHOD_FUNC(p4_set_enviro_file), 1);
1367
+ rb_define_method( cP4, "evar", RUBY_METHOD_FUNC(p4_get_evar) , 1 );
1368
+ rb_define_method( cP4, "set_evar", RUBY_METHOD_FUNC(p4_set_evar) , 2 );
1369
+ rb_define_method( cP4, "host", RUBY_METHOD_FUNC(p4_get_host) , 0 );
1370
+ rb_define_method( cP4, "host=", RUBY_METHOD_FUNC(p4_set_host) , 1 );
1371
+ rb_define_method( cP4, "ignore_file",RUBY_METHOD_FUNC(p4_get_ignore) , 0 );
1372
+ rb_define_method( cP4, "ignore_file=",RUBY_METHOD_FUNC(p4_set_ignore), 1 );
1373
+ rb_define_method( cP4, "ignored?", RUBY_METHOD_FUNC(p4_is_ignored) , 1 );
1374
+ rb_define_method( cP4, "language", RUBY_METHOD_FUNC(p4_get_language), 0 );
1375
+ rb_define_method( cP4, "language=", RUBY_METHOD_FUNC(p4_set_language), 1 );
1376
+ rb_define_method( cP4, "p4config_file",RUBY_METHOD_FUNC(p4_get_p4config),0);
1377
+ rb_define_method( cP4, "password", RUBY_METHOD_FUNC(p4_get_password), 0 );
1378
+ rb_define_method( cP4, "password=", RUBY_METHOD_FUNC(p4_set_password), 1 );
1379
+ rb_define_method( cP4, "port", RUBY_METHOD_FUNC(p4_get_port) , 0 );
1380
+ rb_define_method( cP4, "port=", RUBY_METHOD_FUNC(p4_set_port) , 1 );
1381
+ rb_define_method( cP4, "prog", RUBY_METHOD_FUNC(p4_get_prog) , 0 );
1382
+ rb_define_method( cP4, "prog=", RUBY_METHOD_FUNC(p4_set_prog) , 1 );
1383
+ rb_define_method( cP4, "protocol", RUBY_METHOD_FUNC(p4_set_protocol), 2 );
1384
+ rb_define_method( cP4, "ticket_file", RUBY_METHOD_FUNC(p4_get_ticket_file), 0 );
1385
+ rb_define_method( cP4, "ticket_file=", RUBY_METHOD_FUNC(p4_set_ticket_file), 1 );
1386
+ rb_define_method( cP4, "trust_file", RUBY_METHOD_FUNC(p4_get_trust_file), 0 );
1387
+ rb_define_method( cP4, "trust_file=", RUBY_METHOD_FUNC(p4_set_trust_file), 1 );
1388
+ rb_define_method( cP4, "user", RUBY_METHOD_FUNC(p4_get_user) , 0 );
1389
+ rb_define_method( cP4, "user=", RUBY_METHOD_FUNC(p4_set_user) , 1 );
1390
+ rb_define_method( cP4, "version", RUBY_METHOD_FUNC(p4_get_version) , 0 );
1391
+ rb_define_method( cP4, "version=", RUBY_METHOD_FUNC(p4_set_version) , 1 );
1392
+
1393
+
1394
+ rb_define_method( cP4, "maxresults", RUBY_METHOD_FUNC(p4_get_maxresults),0);
1395
+ rb_define_method( cP4, "maxresults=",RUBY_METHOD_FUNC(p4_set_maxresults),1);
1396
+ rb_define_method( cP4, "maxscanrows", RUBY_METHOD_FUNC(p4_get_maxscanrows),0);
1397
+ rb_define_method( cP4, "maxscanrows=",RUBY_METHOD_FUNC(p4_set_maxscanrows), 1 );
1398
+ rb_define_method( cP4, "maxlocktime", RUBY_METHOD_FUNC(p4_get_maxlocktime), 0 );
1399
+ rb_define_method( cP4, "maxlocktime=", RUBY_METHOD_FUNC(p4_set_maxlocktime), 1 );
1400
+
1401
+ // Session Connect/Disconnect
1402
+ rb_define_method( cP4, "connect", RUBY_METHOD_FUNC(p4_connect) , 0 );
1403
+ rb_define_method( cP4, "connected?",RUBY_METHOD_FUNC(p4_connected) , 0 );
1404
+ rb_define_method( cP4, "disconnect", RUBY_METHOD_FUNC(p4_disconnect) , 0 );
1405
+
1406
+ // Running commands - general purpose commands
1407
+ rb_define_method( cP4, "run", RUBY_METHOD_FUNC(p4_run) ,-2 );
1408
+ rb_define_method( cP4, "input=", RUBY_METHOD_FUNC(p4_set_input) , 1 );
1409
+ rb_define_method( cP4, "errors", RUBY_METHOD_FUNC(p4_get_errors) , 0 );
1410
+ rb_define_method( cP4, "messages", RUBY_METHOD_FUNC(p4_get_messages), 0 );
1411
+ rb_define_method( cP4, "warnings", RUBY_METHOD_FUNC(p4_get_warnings), 0 );
1412
+ rb_define_method( cP4, "exception_level", RUBY_METHOD_FUNC(p4_get_except_level), 0 );
1413
+ rb_define_method( cP4, "exception_level=", RUBY_METHOD_FUNC(p4_set_except_level), 1 );
1414
+ rb_define_method( cP4, "server_level", RUBY_METHOD_FUNC(p4_get_server_level), 0 );
1415
+ rb_define_method( cP4, "server_case_sensitive?", RUBY_METHOD_FUNC(p4_server_case_sensitive), 0 );
1416
+ rb_define_method( cP4, "track_output", RUBY_METHOD_FUNC(p4_track_output), 0 );
1417
+
1418
+ rb_define_method( cP4, "server_unicode?", RUBY_METHOD_FUNC(p4_server_unicode), 0 );
1419
+
1420
+ // Spec parsing
1421
+ rb_define_method( cP4, "parse_spec", RUBY_METHOD_FUNC(p4_parse_spec), 2 );
1422
+ rb_define_method( cP4, "format_spec", RUBY_METHOD_FUNC(p4_format_spec), 2 );
1423
+ rb_define_method( cP4, "set_array_conversion=", RUBY_METHOD_FUNC(p4_set_array_conversion), 1 );
1424
+
1425
+ // Identification
1426
+ rb_define_const( cP4, "P4API_VERSION", P4Utils::ruby_string(P4APIVER_STRING));
1427
+ rb_define_const( cP4, "P4API_PATCHLEVEL", INT2NUM(P4API_PATCHLEVEL));
1428
+ rb_define_const( cP4, "P4RUBY_VERSION", P4Utils::ruby_string(P4RUBY_VERSION) );
1429
+ rb_define_singleton_method( cP4, "identify", RUBY_METHOD_FUNC(p4_identify), 0 );
1430
+
1431
+ // Debugging support
1432
+ rb_define_method( cP4, "debug", RUBY_METHOD_FUNC(p4_get_debug), 0);
1433
+ rb_define_method( cP4, "debug=", RUBY_METHOD_FUNC(p4_set_debug), 1 );
1434
+
1435
+ // Support for OutputHandler
1436
+ rb_define_method( cP4, "handler", RUBY_METHOD_FUNC(p4_get_handler), 0);
1437
+ rb_define_method( cP4, "handler=", RUBY_METHOD_FUNC(p4_set_handler), 1);
1438
+
1439
+ // Support for Progress API
1440
+ rb_define_method( cP4, "progress", RUBY_METHOD_FUNC(p4_get_progress), 0);
1441
+ rb_define_method( cP4, "progress=", RUBY_METHOD_FUNC(p4_set_progress), 1);
1442
+
1443
+ // SSO handling
1444
+ rb_define_method( cP4, "loginsso", RUBY_METHOD_FUNC(p4_get_enabled_sso), 0);
1445
+ rb_define_method( cP4, "loginsso=", RUBY_METHOD_FUNC(p4_set_enable_sso), 1);
1446
+ rb_define_method( cP4, "ssovars", RUBY_METHOD_FUNC(p4_get_sso_vars), 0);
1447
+ rb_define_method( cP4, "ssopassresult", RUBY_METHOD_FUNC(p4_get_sso_passresult), 0);
1448
+ rb_define_method( cP4, "ssopassresult=", RUBY_METHOD_FUNC(p4_set_sso_passresult), 1);
1449
+ rb_define_method( cP4, "ssofailresult", RUBY_METHOD_FUNC(p4_get_sso_failresult), 0);
1450
+ rb_define_method( cP4, "ssofailresult=", RUBY_METHOD_FUNC(p4_set_sso_failresult), 1);
1451
+ rb_define_method( cP4, "ssohandler", RUBY_METHOD_FUNC(p4_get_ssohandler), 0);
1452
+ rb_define_method( cP4, "ssohandler=", RUBY_METHOD_FUNC(p4_set_ssohandler), 1);
1453
+
1454
+
1455
+ // P4::MergeData class
1456
+ cP4MD = rb_define_class_under( cP4, "MergeData", rb_cObject );
1457
+
1458
+ rb_define_method( cP4MD, "your_name", RUBY_METHOD_FUNC(p4md_getyourname),0);
1459
+ rb_define_method( cP4MD, "their_name", RUBY_METHOD_FUNC(p4md_gettheirname),0);
1460
+ rb_define_method( cP4MD, "base_name", RUBY_METHOD_FUNC(p4md_getbasename),0);
1461
+ rb_define_method( cP4MD, "your_path", RUBY_METHOD_FUNC(p4md_getyourpath),0);
1462
+ rb_define_method( cP4MD, "their_path", RUBY_METHOD_FUNC(p4md_gettheirpath),0);
1463
+ rb_define_method( cP4MD, "base_path", RUBY_METHOD_FUNC(p4md_getbasepath),0);
1464
+ rb_define_method( cP4MD, "result_path", RUBY_METHOD_FUNC(p4md_getresultpath),0);
1465
+ rb_define_method( cP4MD, "merge_hint", RUBY_METHOD_FUNC(p4md_getmergehint),0);
1466
+ rb_define_method( cP4MD, "run_merge", RUBY_METHOD_FUNC(p4md_runmerge),0);
1467
+
1468
+ rb_define_method(cP4MD, "action_resolve?", RUBY_METHOD_FUNC(p4md_getactionresolve), 0);
1469
+ rb_define_method(cP4MD, "action_type", RUBY_METHOD_FUNC(p4md_getactiontype), 0);
1470
+ rb_define_method(cP4MD, "content_resolve?", RUBY_METHOD_FUNC(p4md_getcontentresolve), 0);
1471
+ rb_define_method(cP4MD, "info", RUBY_METHOD_FUNC(p4md_getinfo), 0);
1472
+ rb_define_method(cP4MD, "invalidate", RUBY_METHOD_FUNC(p4md_invalidate), 0);
1473
+ rb_define_method(cP4MD, "merge_action", RUBY_METHOD_FUNC(p4md_getmergeaction), 0);
1474
+ rb_define_method(cP4MD, "their_action", RUBY_METHOD_FUNC(p4md_gettheiraction), 0);
1475
+ rb_define_method(cP4MD, "to_s", RUBY_METHOD_FUNC(p4md_tos), 0);
1476
+ rb_define_method(cP4MD, "yours_action", RUBY_METHOD_FUNC(p4md_getyoursaction), 0);
1477
+
1478
+ // P4::Map class
1479
+ cP4Map = rb_define_class_under( cP4, "Map", rb_cObject );
1480
+ rb_define_singleton_method( cP4Map, "new", RUBY_METHOD_FUNC(p4map_new), -1);
1481
+ rb_define_singleton_method( cP4Map, "join", RUBY_METHOD_FUNC(p4map_join), 2 );
1482
+ rb_define_method( cP4Map, "insert", RUBY_METHOD_FUNC(p4map_insert),-1);
1483
+ rb_define_method( cP4Map, "inspect", RUBY_METHOD_FUNC(p4map_inspect),0);
1484
+ rb_define_method( cP4Map, "clear", RUBY_METHOD_FUNC(p4map_clear),0);
1485
+ rb_define_method( cP4Map, "count", RUBY_METHOD_FUNC(p4map_count),0);
1486
+ rb_define_method( cP4Map, "empty?", RUBY_METHOD_FUNC(p4map_empty),0);
1487
+ rb_define_method( cP4Map, "translate", RUBY_METHOD_FUNC(p4map_trans),-1);
1488
+ rb_define_method( cP4Map, "reverse", RUBY_METHOD_FUNC(p4map_reverse),0);
1489
+ rb_define_method( cP4Map, "includes?", RUBY_METHOD_FUNC(p4map_includes),1);
1490
+ rb_define_method( cP4Map, "lhs", RUBY_METHOD_FUNC(p4map_lhs),0);
1491
+ rb_define_method( cP4Map, "rhs", RUBY_METHOD_FUNC(p4map_rhs),0);
1492
+ rb_define_method( cP4Map, "to_a", RUBY_METHOD_FUNC(p4map_to_a),0);
1493
+
1494
+ // P4::Message class.
1495
+ cP4Msg = rb_define_class_under( cP4, "Message", rb_cObject );
1496
+ rb_define_method( cP4Msg, "inspect", RUBY_METHOD_FUNC(p4msg_inspect),0);
1497
+ rb_define_method( cP4Msg, "msgid", RUBY_METHOD_FUNC(p4msg_get_id), 0);
1498
+ rb_define_method( cP4Msg, "severity", RUBY_METHOD_FUNC(p4msg_get_severity), 0);
1499
+ rb_define_method( cP4Msg, "generic", RUBY_METHOD_FUNC(p4msg_get_generic), 0);
1500
+ rb_define_method( cP4Msg, "dictionary", RUBY_METHOD_FUNC(p4msg_get_dict), 0);
1501
+ rb_define_method( cP4Msg, "to_s", RUBY_METHOD_FUNC(p4msg_get_text), 0);
1502
+
1503
+ // P4::Progress class.
1504
+ cP4Prog = rb_define_class_under( cP4, "Progress", rb_cObject );
1505
+
1506
+ };
1507
+
1508
+
1509
+ } // Extern C