@@ -343,6 +343,15 @@ public function put($message/* $args */)
343
343
}
344
344
class Fashion
345
345
{
346
+ protected $ name ;
347
+ protected $ flag ;
348
+
349
+ public function __construct ($ name , $ flag = false )
350
+ {
351
+ $ this ->name = basename ($ name , ".h " );
352
+ $ this ->flag = $ flag ;
353
+ }
354
+
346
355
public function shouldResource (Arg $ arg )
347
356
{
348
357
static $ types ;
@@ -396,6 +405,7 @@ public function shouldResource(Arg $arg)
396
405
"git_packbuilder " ,
397
406
"git_submodule " ,
398
407
"git_push " ,
408
+ "git_refspec " ,
399
409
);
400
410
}
401
411
@@ -1058,12 +1068,22 @@ public function generateStrarrayConversion(Printer $printer, Func $f)
1058
1068
}
1059
1069
}
1060
1070
1071
+ public function generateIncludes (Printer $ printer , Func $ f )
1072
+ {
1073
+ if ($ this ->flag ) {
1074
+ $ printer ->put ("#include \"php_git2.h \"\n" );
1075
+ $ printer ->put ("#include \"php_git2_priv.h \"\n" );
1076
+ $ printer ->put ("#include \"`name`.h \"\n" , "name " , $ this ->name );
1077
+ }
1078
+ }
1079
+
1061
1080
public function out (Func $ f )
1062
1081
{
1063
1082
$ stream = new StringStream ();
1064
1083
$ out = new ZeroCopyOutputStream ($ stream );
1065
1084
$ printer = new Printer ($ out , "` " );
1066
1085
1086
+ $ this ->generateIncludes ($ printer , $ f );
1067
1087
$ this ->generateProto ($ printer , $ f );
1068
1088
$ printer ->put ("PHP_FUNCTION(`function`) \n" ,
1069
1089
"function " , $ f ->getName ());
@@ -1089,6 +1109,108 @@ public function out(Func $f)
1089
1109
}
1090
1110
}
1091
1111
1112
+ class Header extends Fashion
1113
+ {
1114
+ public function generateLicense (Printer $ printer , Func $ f )
1115
+ {
1116
+ if (!$ this ->flag ) {
1117
+ return ;
1118
+ }
1119
+ $ printer ->put ("/* \n" );
1120
+ $ printer ->put (" * PHP Libgit2 Extension \n" );
1121
+ $ printer ->put (" * \n" );
1122
+ $ printer ->put (" * https://github.com/libgit2/php-git \n" );
1123
+ $ printer ->put (" * \n" );
1124
+ $ printer ->put (" * Copyright 2014 Shuhei Tanuma. All rights reserved. \n" );
1125
+ $ printer ->put (" * \n" );
1126
+ $ printer ->put (" * Permission is hereby granted, free of charge, to any person obtaining a copy \n" );
1127
+ $ printer ->put (" * of this software and associated documentation files (the \"Software \"), to deal \n" );
1128
+ $ printer ->put (" * in the Software without restriction, including without limitation the rights \n" );
1129
+ $ printer ->put (" * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell \n" );
1130
+ $ printer ->put (" * copies of the Software, and to permit persons to whom the Software is \n" );
1131
+ $ printer ->put (" * furnished to do so, subject to the following conditions: \n" );
1132
+ $ printer ->put (" * \n" );
1133
+ $ printer ->put (" * The above copyright notice and this permission notice shall be included in \n" );
1134
+ $ printer ->put (" * all copies or substantial portions of the Software. \n" );
1135
+ $ printer ->put (" * \n" );
1136
+ $ printer ->put (" * THE SOFTWARE IS PROVIDED \"AS IS \", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR \n" );
1137
+ $ printer ->put (" * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, \n" );
1138
+ $ printer ->put (" * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE \n" );
1139
+ $ printer ->put (" * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER \n" );
1140
+ $ printer ->put (" * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, \n" );
1141
+ $ printer ->put (" * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN \n" );
1142
+ $ printer ->put (" * THE SOFTWARE. \n" );
1143
+ $ printer ->put (" */ \n" );
1144
+ $ printer ->put ("#ifndef PHP_GIT2_`file`_H \n" , "file " , strtoupper ($ this ->name ));
1145
+ $ printer ->put ("#define PHP_GIT2_`file`_H \n" , "file " , strtoupper ($ this ->name ));
1146
+ $ printer ->put ("\n" );
1147
+ }
1148
+
1149
+ public function generateArgInfo (Printer $ printer , Func $ f )
1150
+ {
1151
+ $ printer ->put ("ZEND_BEGIN_ARG_INFO_EX(arginfo_`name`, `a`, `b`, `c`) \n" ,
1152
+ "name " , $ f ->getName (),
1153
+ "a " , 0 ,
1154
+ "b " , 0 ,
1155
+ "c " , count ($ f ->getArguments ())
1156
+ );
1157
+ foreach ($ f ->getArguments () as $ arg ) {
1158
+ /** @var Arg $arg */
1159
+ $ printer ->put ("\tZEND_ARG_INFO(`is_ref`, `name`) \n" ,
1160
+ "is_ref " , 0 ,
1161
+ "name " , $ arg ->getName ());
1162
+ }
1163
+ $ printer ->put ("ZEND_END_ARG_INFO() \n" );
1164
+ $ printer ->put ("\n" );
1165
+ }
1166
+
1167
+ public function out (Func $ f )
1168
+ {
1169
+ $ stream = new StringStream ();
1170
+ $ out = new ZeroCopyOutputStream ($ stream );
1171
+ $ printer = new Printer ($ out , "` " );
1172
+
1173
+ $ this ->generateLicense ($ printer , $ f );
1174
+ $ this ->generateArgInfo ($ printer , $ f );
1175
+
1176
+ return $ stream ->__toString ();
1177
+ }
1178
+ }
1179
+
1180
+ class Header2 extends Header
1181
+ {
1182
+ public function generateArgInfo (Printer $ printer , Func $ f )
1183
+ {
1184
+ $ printer ->put ("ZEND_BEGIN_ARG_INFO_EX(arginfo_`name`, `a`, `b`, `c`) \n" ,
1185
+ "name " , $ f ->getName (),
1186
+ "a " , 0 ,
1187
+ "b " , 0 ,
1188
+ "c " , count ($ f ->getArguments ())
1189
+ );
1190
+ foreach ($ f ->getArguments () as $ arg ) {
1191
+ /** @var Arg $arg */
1192
+ $ printer ->put ("\tZEND_ARG_INFO(`is_ref`, `name`) \n" ,
1193
+ "is_ref " , 0 ,
1194
+ "name " , $ arg ->getName ());
1195
+ }
1196
+ $ printer ->put ("ZEND_END_ARG_INFO() \n" );
1197
+ $ printer ->put ("\n" );
1198
+ }
1199
+
1200
+ public function out (Func $ f )
1201
+ {
1202
+ $ stream = new StringStream ();
1203
+ $ out = new ZeroCopyOutputStream ($ stream );
1204
+ $ printer = new Printer ($ out , "` " );
1205
+
1206
+ $ this ->generateProto ($ printer , $ f );
1207
+ $ printer ->put ("PHP_FUNCTION(`func`); \n" , "func " , $ f ->getName ());
1208
+ $ printer ->put ("\n" );
1209
+
1210
+ return $ stream ->__toString ();
1211
+ }
1212
+ }
1213
+
1092
1214
$ data = file_get_contents ($ _SERVER ['argv ' ][1 ]);
1093
1215
$ table = array ();
1094
1216
if (preg_match_all ("/GIT_EXTERN\((.+?)\)\s*([a-zA-Z0-9_-]+)\((.+?)\);/s " , $ data , $ match )) {
@@ -1108,14 +1230,30 @@ public function out(Func $f)
1108
1230
$ table [$ func ->getName ()] = $ func ;
1109
1231
}
1110
1232
}
1233
+ if (getenv ("PRINT_HEADER " )) {
1234
+ $ flag = true ;
1235
+ foreach ($ table as $ name => $ func ) {
1236
+ $ printer = new Header ($ _SERVER ['argv ' ][1 ], $ flag );
1237
+ echo $ printer ->out ($ func );
1238
+ $ flag = false ;
1239
+ }
1111
1240
1112
- if (isset ($ _SERVER ['argv ' ][2 ])) {
1113
- $ printer = new Fashion ();
1114
- echo $ printer ->out ($ table [$ _SERVER ['argv ' ][2 ]]);
1115
- } else {
1116
1241
foreach ($ table as $ name => $ func ) {
1117
- $ printer = new Fashion ( );
1242
+ $ printer = new Header2 ( $ _SERVER [ ' argv ' ][ 1 ], $ flag );
1118
1243
echo $ printer ->out ($ func );
1119
1244
}
1245
+ echo "#endif \n" ;
1246
+ } else {
1247
+ if (isset ($ _SERVER ['argv ' ][2 ])) {
1248
+ $ printer = new Fashion ($ _SERVER ['argv ' ][1 ]);
1249
+ echo $ printer ->out ($ table [$ _SERVER ['argv ' ][2 ]]);
1250
+ } else {
1251
+ $ flag = true ;
1252
+ foreach ($ table as $ name => $ func ) {
1253
+ $ printer = new Fashion ($ _SERVER ['argv ' ][1 ], $ flag );
1254
+ echo $ printer ->out ($ func );
1255
+ $ flag = false ;
1256
+ }
1257
+ }
1120
1258
}
1121
1259
0 commit comments