• R/O
  • SSH
  • HTTPS

cadencii: コミット


コミットメタ情報

リビジョン1762 (tree)
日時2011-11-09 21:35:42
作者kbinani

ログメッセージ

[luavsq] クラス毎のファイルを、リリース用にまとめるツールを追加

変更サマリ

差分

--- luavsq/trunk/tool/files.lua (revision 1761)
+++ luavsq/trunk/tool/files.lua (nonexistent)
@@ -1,16 +0,0 @@
1-dofile( "../Util.lua" );
2-
3-dofile( "../ArticulationType.lua" );
4-dofile( "../Handle.lua" );
5-dofile( "../HandleType.lua" );
6-dofile( "../IconDynamicsHandle.lua" );
7-dofile( "../IconHandle.lua" );
8-dofile( "../IconParameter.lua" );
9-dofile( "../Lyric.lua" );
10-dofile( "../LyricHandle.lua" );
11-dofile( "../NoteHeadHandle.lua" );
12-dofile( "../PhoneticSymbol.lua" );
13-dofile( "../TextStream.lua" );
14-dofile( "../VibratoBPList.lua" );
15-dofile( "../VibratoBPPair.lua" );
16-dofile( "../VibratoHandle.lua" );
--- luavsq/trunk/tool/SourceFilePacker.java (nonexistent)
+++ luavsq/trunk/tool/SourceFilePacker.java (revision 1762)
@@ -0,0 +1,148 @@
1+import java.io.*;
2+import java.util.*;
3+import java.util.regex.*;
4+
5+class SourceFilePacker
6+{
7+ public static void main( String[] args )
8+ {
9+ File directory = new File( "../" );
10+ BufferedWriter writer = null;
11+ try{
12+ writer = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( "luavsq.lua" ), "UTF-8" ) );
13+ int startYear = 2011;
14+ int currentYear = Calendar.getInstance().get( Calendar.YEAR );
15+ String year = "" + startYear;
16+ if( startYear != currentYear ){
17+ year = Math.min( startYear, currentYear ) + "-" + Math.max( startYear, currentYear );
18+ }
19+ String[] license = new String[]{
20+ "--[[",
21+ " luavsq.lua",
22+ " Copyright © " + year + " kbinani, All Rights Reserved.",
23+ "",
24+ " This file is part of luavsq.",
25+ "",
26+ " luavsq is free software; you can redistribute it and/or",
27+ " modify it under the terms of the BSD License.",
28+ "",
29+ " luavsq is distributed in the hope that it will be useful,",
30+ " but WITHOUT ANY WARRANTY; without even the implied warranty of",
31+ " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.",
32+ "]]",
33+ "",
34+ "-- This file is automatically generated by SourceFilePacker.",
35+ "-- To generate this file, just execute the command below:",
36+ "-- $cd tool && make",
37+ "-- See tool/makefile and tool/SourceFilePacker.java.",
38+ "",
39+ "if( nil == luavsq )then",
40+ " luavsq = {};",
41+ "end"
42+ };
43+ for( String line : license ){
44+ writer.write( line );
45+ writer.newLine();
46+ }
47+ for( File file : directory.listFiles() ){
48+ if( false == file.getAbsolutePath().endsWith( ".lua" ) ){
49+ continue;
50+ }
51+ concatFile( file.getAbsolutePath(), writer );
52+ }
53+ }catch( Exception e ){
54+ e.printStackTrace();
55+ }finally{
56+ if( writer != null ){
57+ try{
58+ writer.close();
59+ }catch( Exception e ){}
60+ }
61+ }
62+ }
63+
64+ private static void concatFile( String path, BufferedWriter writer )
65+ {
66+ BufferedReader reader = null;
67+ StringBuilder builder = new StringBuilder();
68+ try{
69+ reader = new BufferedReader( new InputStreamReader( new FileInputStream( path ), "UTF-8" ) );
70+ boolean first = true;
71+ while( reader.ready() ){
72+ if( !first ){
73+ builder.append( "\n" );
74+ }else{
75+ first = false;
76+ }
77+ builder.append( reader.readLine() );
78+ }
79+ String source = builder.toString();
80+ source = extract( source, new File( path ).getName().replace( ".lua", "" ) );
81+ source = packAll( source );
82+ writer.write( source );
83+ }catch( Exception e ){
84+ e.printStackTrace();
85+ }finally{
86+ if( reader != null ){
87+ try{
88+ reader.close();
89+ }catch( Exception e ){}
90+ }
91+ }
92+ }
93+
94+ private static String packAll( String source )
95+ {
96+ Pattern pattern = null;
97+ Matcher matcher = null;
98+
99+ // 長いコメントを削除
100+ pattern = Pattern.compile( "--\\[\\[.*?\\]\\]", Pattern.DOTALL );
101+ matcher = pattern.matcher( source );
102+ if( matcher.find() ){
103+ source = matcher.replaceAll( "" );
104+ }
105+
106+ // 行コメントを削除
107+ pattern = Pattern.compile( "--.*?\n" );
108+ matcher = pattern.matcher( source );
109+ if( matcher.find() ){
110+ source = matcher.replaceAll( "\n" );
111+ }
112+
113+ // 空白のみの行を削除
114+ pattern = Pattern.compile( "^[ ]*$", Pattern.MULTILINE );
115+ matcher = pattern.matcher( source );
116+ if( matcher.find() ){
117+ source = matcher.replaceAll( "" );
118+ }
119+
120+ // 連続した改行を削除
121+ pattern = Pattern.compile( "\n\n", Pattern.MULTILINE );
122+ while( true ){
123+ matcher = pattern.matcher( source );
124+ if( false == matcher.find() ){
125+ break;
126+ }
127+ source = matcher.replaceAll( "\n" );
128+ }
129+
130+ return source;
131+ }
132+
133+ private static String extract( String source, String className )
134+ {
135+ String patternString = "if\\( nil == luavsq\\." + className + " \\)then\n(.*)end";
136+ Pattern pattern = Pattern.compile( patternString, Pattern.DOTALL );
137+ Matcher matcher = pattern.matcher( source );
138+ if( matcher.find() ){
139+ source = matcher.group( 1 );
140+
141+ // インデントを1つ解除
142+ pattern = Pattern.compile( "^[ ]{4}", Pattern.MULTILINE );
143+ matcher = pattern.matcher( source );
144+ source = matcher.replaceAll( "" );
145+ }
146+ return source;
147+ }
148+}
旧リポジトリブラウザで表示