[Assorted-commits] SF.net SVN: assorted: [815] configs/trunk/src/topcoder
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-05-14 22:55:37
|
Revision: 815 http://assorted.svn.sourceforge.net/assorted/?rev=815&view=rev Author: yangzhang Date: 2008-05-14 15:55:40 -0700 (Wed, 14 May 2008) Log Message: ----------- added proper properties-file manipulation; allowed me to separate out the language template files Modified Paths: -------------- configs/trunk/src/topcoder/contestapplet.conf.template configs/trunk/src/topcoder/setup.py Added Paths: ----------- configs/trunk/src/topcoder/setup.scala configs/trunk/src/topcoder/template.cpp configs/trunk/src/topcoder/template.cs configs/trunk/src/topcoder/template.java Modified: configs/trunk/src/topcoder/contestapplet.conf.template =================================================================== --- configs/trunk/src/topcoder/contestapplet.conf.template 2008-05-14 18:00:58 UTC (rev 814) +++ configs/trunk/src/topcoder/contestapplet.conf.template 2008-05-14 22:55:40 UTC (rev 815) @@ -2,7 +2,7 @@ #Thu Sep 13 01:33:13 EDT 2007 com.topcoder.client.contestApplet.common.LocalPreferences.menufont=Arial com.topcoder.client.contestApplet.common.LocalPreferences.menufontsize=10 -com.topcoder.client.contestApplet.common.LocalPreferences.commonclasspath=`CLASSPATH` +com.topcoder.client.contestApplet.common.LocalPreferences.commonclasspath= com.topcoder.client.contestApplet.common.LocalPreferences.chatpanelback=-16777216 com.topcoder.client.contestApplet.common.LocalPreferences.chatfindhighlight=-8355712 com.topcoder.client.contestApplet.common.LocalPreferences.chatfindback=-16776961 @@ -139,8 +139,8 @@ com.topcoder.client.contestApplet.common.LocalPreferences.edstdsyntaxliteralsstyle=0 com.topcoder.client.contestApplet.common.LocalPreferences.edstdsyntaxkeywordsstyle=0 com.topcoder.client.contestApplet.common.LocalPreferences.edstdsyntaxdefaultstyle=0 +com.topcoder.client.contestApplet.common.LocalPreferences.chalsrcsyntaxhighlight=true com.topcoder.client.contestApplet.common.LocalPlight=true -com.topcoder.client.contestApplet.common.LocalPreferences.chalsrcsyntaxhighlight=true com.topcoder.client.contestApplet.LocalPreferences.connectionType=DIRECT com.topcoder.client.contestApplet.panels.ChatPanel.generalback=-16777216 com.topcoder.client.contestApplet.panels.ChatPanel.whispertoback=-65536 @@ -165,11 +165,11 @@ com.topcoder.jmaContestApplet.frames.codingframe.size=1024\:746 com.topcoder.jmaContestApplet.frames.codingframe.dividerloc=319 com.topcoder.jmaContesntApplet.ContestApplet.enableTimestamps=true -fileeditor.config.dirName=`USERDIR` +fileeditor.config.dirName= fileeditor.config.fileName=Program -fileeditor.config.beginCut=// BEGIN CUT HERE -fileeditor.config.endCut=// END CUT HERE -fileeditor.config.probdescfileextnsion=txignaturefilename= +fileeditor.config.beginCut=//\ BEGIN\ CUT\ HERE +fileeditor.config.endCut=//\ END\ CUT\ HERE +fileeditor.config.probdescfileextnsion=txignaturefilename\= fileeditor.config.lineComments=true fileeditor.config.overrideFileName=true fileeditor.config.provideBreaks=false @@ -177,9 +177,9 @@ fileeditor.config.breakAt=60 fileeditor.config.htmldesc=false fileeditor.config.backup=true -fileeditor.config.javatemplate=$BEGINCUT$\n$PROBLEMDESC$\n$ENDCUT$\nimport java.util.*;\npublic class $CLASSNAME$ {\n\tpublic $RC$ $METHODNAME$($METHODPARMS$) {\n\t\t\n\t}\n\tpublic static void main(String[] args) {\n\t\t$CLASSNAME$ temp \= new $CLASSNAME$();\n\t\tSystem.out.println(temp.$METHODNAME$($METHODPARMS$));\n\t}\n} -fileeditor.config.cpptemplate=// vim\:et\:sw\=2\:ts\=2\n\n$BEGINCUT$\n\#if 0\n$PROBLEMDESC$\n\#endif\n$ENDCUT$\n\n\n\n\n\n\n\n//\#line $NEXTLINENUMBER$ "$FILENAME$"\n\#include <algorithm>\n\#include <cassert>\n\#include <cctype>\n\#include <cmath>\n\#include <cstdio>\n\#include <cstdlib>\n\#include <deque>\n\#include <iostream>\n\#include <map>\n\#include <queue>\n\#include <set>\n\#include <sstream>\n\#include <stack>\n\#include <string>\n\#include <vector>\nusing namespace std;\n\n\#define ARRSIZE(x) (sizeof(x)/sizeof(x[0]))\n\n\n\n\n\n\n\n$BEGINCUT$\ntemplate<typename T> void print( T a ) {\n\tcerr << a;\n}\nstatic void print( long long a ) {\n\tcerr << a << "L";\n}\nstatic void print( string a ) {\n\tcerr << '"' << a << '"';\n}\ntemplate<typename T> void print( vector<T> a ) {\n\tcerr << "{";\n\tfor ( int i \= 0 ; i \!\= a.size() ; i++ ) {\n\t\tif ( i \!\= 0 ) cerr << ", ";\n\t\tprint( a[i] );\n\t}\n\tcerr << "}" << endl;\n}\ntemplate<typename T> void eq( int n, T have, T need ) {\n\tif ( have \=\= need ) {\n\t\tcerr << "Case " << n << " passed." << endl;\n\t} else {\n\t\tcerr << "Case " << n << " failed\: expected ";\n\t\tprint( need );\n\t\tcerr << " received ";\n\t\tprint( have );\n\t\tcerr << "." << endl;\n\t}\n}\ntemplate<typename T> void eq( int n, vector<T> have, vector<T> need ) {\n\tif( have.size() \!\= need.size() ) {\n\t\tcerr << "Case " << n << " failed\: returned " << have.size() << " elements; expected " << need.size() << " elements." << endl;\n\t\tcerr << " have\: "; print( have );\n\t\tcerr << " need\: "; print( need );\n\t\treturn;\n\t}\n\tfor( size_t i\= 0; i < have.size(); i++ ) {\n\t\tif( have[i] \!\= need[i] ) {\n\t\t\tcerr << "Case " << n << " failed. Expected and returned array differ in position " << i << "." << endl;\n\t\t\tcerr << " have\: "; print( have );\n\t\t\tcerr << " need\: "; print( need );\n\t\t\treturn;\n\t\t}\n\t}\n\tcerr << "Case " << n << " passed." << endl;\n}\nstatic void eq( int n, string have, string need ) {\n\tif ( have \=\= need ) {\n\t\tcerr << "Case " << n << " passed." << endl;\n\t} else {\n\t\tcerr << "Case " << n << " failed\: expected ";\n\t\tprint( need );\n\t\tcerr << " received ";\n\t\tprint( have );\n\t\tcerr << "." << endl;\n\t}\n}\n$ENDCUT$\n\n\n\n\n\n\n\n$BEGINCUT$\n\#if 0\ntemplate<typename T> void pp(const T & xs) {\n\tfor (typename T\:\:const_iterator it \= xs.begin();\n\t\tit \!\= xs.end();\n\t\tit++)\n\t\tcout << *it << " ";\n\tcout << endl;\n}\n\nvector<string> split( const string& s, const string& delim \=" " ) {\n\tvector<string> res;\n\tstring t;\n\tfor ( int i \= 0 ; i \!\= s.size() ; i++ ) {\n\t\tif ( delim.find( s[i] ) \!\= string\:\:npos ) {\n\t\t\tif ( \!t.empty() ) {\n\t\t\t\tres.push_back( t );\n\t\t\t\tt \= "";\n\t\t\t}\n\t\t} else {\n\t\t\tt +\= s[i];\n\t\t}\n\t}\n\tif ( \!t.empty() ) {\n\t\tres.push_back(t);\n\t}\n\treturn res;\n}\n\nvector<int> splitInt( const string& s, const string& delim \=" " ) {\n\tvector<string> tok \= split( s, delim );\n\tvector<int> res;\n\tfor ( int i \= 0 ; i \!\= tok.size(); i++ )\n\t\tres.push_back( atoi( tok[i].c_str() ) );\n\treturn res;\n}\n\#endif\n$ENDCUT$\n\n\n\n\n\n\n\nclass $CLASSNAME$ {\n\tpublic\:\n\t$RC$ $METHODNAME$($METHODPARMS$) {\n\t\t$RC$ res;\n\t\treturn res;\n\t}\n};\n\n\n\n\n\n\n\n$BEGINCUT$\nint main() {\n$MAINBODY$\n\tcin.get();\n\treturn 0;\n}\n$ENDCUT$\n -fileeditor.config.csharptemplate=using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Text.RegularExpressions;\n\npublic class $CLASSNAME$ {\n\tpublic $RC$ $METHODNAME$($METHODPARMS$) {\n\t}\n\n\n\n\n\n\n\tpublic void pp<T>(T x) { Console.WriteLine(x); }\n\n\n\n\n\n\n\n\n\t$BEGINCUT$\n\tpublic static void Main(string[] args) {\n\t\t$MAINBODY$\n\t\tConsole.WriteLine("done\!");\n\t\tConsole.Read();\n\t}\n private static void eq( int n, object have, object need) {\n if( eq( have, need ) ) {\n Console.WriteLine( "Case "+n+" passed." );\n } else {\n Console.Write( "Case "+n+" failed\: expected " );\n print( need );\n Console.Write( ", received " );\n print( have );\n Console.WriteLine();\n }\n }\n private static void eq( int n, Array have, Array need) {\n if( have \=\= null || have.Length \!\= need.Length ) {\n Console.WriteLine("Case "+n+" failed\: returned "+have.Length+" elements; expected "+need.Length+" elements.");\n print( have );\n print( need );\n return;\n }\n for( int i\= 0; i < have.Length; i++ ) {\n if( \! eq( have.GetValue(i), need.GetValue(i) ) ) {\n Console.WriteLine( "Case "+n+" failed. Expected and returned array differ in position "+i );\n print( have );\n print( need );\n return;\n }\n }\n Console.WriteLine("Case "+n+" passed.");\n }\n private static bool eq( object a, object b ) {\n if ( a is double && b is double ) {\n return Math.Abs((double)a-(double)b) < 1E-9;\n } else {\n return a\!\=null && b\!\=null && a.Equals(b);\n }\n }\n private static void print( object a ) {\n if ( a is string ) {\n Console.Write("\\"{0}\\"", a);\n } else if ( a is long ) {\n Console.Write("{0}L", a);\n } else {\n Console.Write(a);\n }\n }\n private static void print( Array a ) {\n if ( a \=\= null) {\n Console.WriteLine("<NULL>");\n;\n for ( int i\= 0; i < a.Length; i++ ) {\n print( a.GetValue(i) );\n if( i \!\= a.Length-1 ) {\n Console.Write(", ");\n }\n }\n Console.WriteLine( '}' );\n }\n\t$ENDCUT$\n}\n +fileeditor.config.javatemplate= +fileeditor.config.cpptemplate= +fileeditor.config.csharptemplate= fileeditor.config.javaextension=java fileeditor.config.cppextension=cpp fileeditor.config.csharpextension=cs @@ -194,4 +194,6 @@ editor.2.classpath= editor.2.eager=1 codeprocessor.config.pluginentrypoint=fileedit.EntryPoint -codeprocessor.config.codeprocessor=tc_plugin.ExampleBuilder +codeprocessor.ExampleBuildercodeprocessor.config.pluginentrypoint=fileedit.EntryPoint +codeprocessor.ExampleBuildercodeprocessor.config.codeprocessor#0=tc_plugin.ExampleBuilder +codeprocessor.ExampleBuildercodeprocessor.config.numofcodeprocessors=1 Modified: configs/trunk/src/topcoder/setup.py =================================================================== --- configs/trunk/src/topcoder/setup.py 2008-05-14 18:00:58 UTC (rev 814) +++ configs/trunk/src/topcoder/setup.py 2008-05-14 22:55:40 UTC (rev 815) @@ -11,12 +11,12 @@ """ from __future__ import with_statement -from contextlib import * -from os import * -from os.path import * -from re import * -from sys import * -from urllib import * +from os import environ, makedirs +from os.path import basename, exists, pathsep, sep +from re import sub +from subprocess import call +from sys import argv, platform +from urllib import urlretrieve # Utilities. def esc( s ): return sub( r'([\\:])', r'\\\1', s ) @@ -53,9 +53,11 @@ urlretrieve(url, path) # Generate the final configuration file from the template. -with file( 'contestapplet.conf.template' ) as template: - contents = template.read() -contents = sub( '`CLASSPATH`', esc( pathsep.join( paths ) ), contents ) -contents = sub( '`USERDIR`', esc( userdir ), contents ) -with file( homedir + 'contestapplet.conf', 'w' ) as output: - output.write( contents ) +call( [ 'scala', '-classpath', 'bin', 'TopCoderSetup', 'load', + pathsep.join(paths), userdir ] ) +#with file( 'contestapplet.conf.template' ) as template: +# contents = template.read() +#contents = sub( '`CLASSPATH`', esc( pathsep.join( paths ) ), contents ) +#contents = sub( '`USERDIR`', esc( userdir ), contents ) +#with file( homedir + 'contestapplet.conf', 'w' ) as output: +# output.write( contents ) Added: configs/trunk/src/topcoder/setup.scala =================================================================== --- configs/trunk/src/topcoder/setup.scala (rev 0) +++ configs/trunk/src/topcoder/setup.scala 2008-05-14 22:55:40 UTC (rev 815) @@ -0,0 +1,46 @@ +import java.util.Properties +import java.io.{FileInputStream, FileOutputStream} +import commons.Control._ +import commons.Io._ +import commons.Path._ + +object TopCoderSetup { + def main(args: Array[String]) { + val cmd = args(0) + val homedir = System getenv "HOME" + val srcconf = "contestapplet.conf.template" + val dstconf = homedir / "contestapplet.conf" + // List of language names (identifying the properties) and their source + // file extensions. + val langs = List(("cpp", "cpp"), ("java", "java"), ("csharp", "cs")) + + val ps = new Properties + val fis = new FileInputStream(srcconf) + try { ps.load(fis) } + finally { fis.close } + + cmd match { + case "dump" => { + for ((lang, ext) <- langs) { + val src = ps.getProperty("fileeditor.config." + lang + "template") + using (TextWriter("template." + ext)) (_ write src) + } + } + case "load" => { + for ((lang, ext) <- langs) { + val src = using (TextReader("template." + ext)) (_ read) + ps.setProperty("fileeditor.config." + lang + "template", src) + } + + val (classpath, userdir) = (args(1), args(2)) + ps.setProperty("com.topcoder.client.contestApplet.common.LocalPreferences.commonclasspath", + classpath) + ps.setProperty("fileeditor.config.dirName", userdir) + + val fos = new FileOutputStream(dstconf) + try { ps.store(fos, "TopCoder ContestApplet Preferences File") } + finally { fos.close } + } + } + } +} Added: configs/trunk/src/topcoder/template.cpp =================================================================== --- configs/trunk/src/topcoder/template.cpp (rev 0) +++ configs/trunk/src/topcoder/template.cpp 2008-05-14 22:55:40 UTC (rev 815) @@ -0,0 +1,171 @@ +// vim:et:sw=2:ts=2 + +$BEGINCUT$ +#if 0 +$PROBLEMDESC$ +#endif +$ENDCUT$ + + + + + + + +//#line $NEXTLINENUMBER$ "$FILENAME$" +#include <algorithm> +#include <cassert> +#include <cctype> +#include <cmath> +#include <cstdio> +#include <cstdlib> +#include <deque> +#include <iostream> +#include <map> +#include <queue> +#include <set> +#include <sstream> +#include <stack> +#include <string> +#include <vector> +using namespace std; + +#define ARRSIZE(x) (sizeof(x)/sizeof(x[0])) + + + + + + + +$BEGINCUT$ +template<typename T> void print( T a ) { + cerr << a; +} +static void print( long long a ) { + cerr << a << "L"; +} +static void print( string a ) { + cerr << '"' << a << '"'; +} +template<typename T> void print( vector<T> a ) { + cerr << "{"; + for ( int i = 0 ; i != a.size() ; i++ ) { + if ( i != 0 ) cerr << ", "; + print( a[i] ); + } + cerr << "}" << endl; +} +template<typename T> void eq( int n, T have, T need ) { + if ( have == need ) { + cerr << "Case " << n << " passed." << endl; + } else { + cerr << "Case " << n << " failed: expected "; + print( need ); + cerr << " received "; + print( have ); + cerr << "." << endl; + } +} +template<typename T> void eq( int n, vector<T> have, vector<T> need ) { + if( have.size() != need.size() ) { + cerr << "Case " << n << " failed: returned " << have.size() << " elements; expected " << need.size() << " elements." << endl; + cerr << " have: "; print( have ); + cerr << " need: "; print( need ); + return; + } + for( size_t i= 0; i < have.size(); i++ ) { + if( have[i] != need[i] ) { + cerr << "Case " << n << " failed. Expected and returned array differ in position " << i << "." << endl; + cerr << " have: "; print( have ); + cerr << " need: "; print( need ); + return; + } + } + cerr << "Case " << n << " passed." << endl; +} +static void eq( int n, string have, string need ) { + if ( have == need ) { + cerr << "Case " << n << " passed." << endl; + } else { + cerr << "Case " << n << " failed: expected "; + print( need ); + cerr << " received "; + print( have ); + cerr << "." << endl; + } +} +$ENDCUT$ + + + + + + + +$BEGINCUT$ +#if 0 +template<typename T> void pp(const T & xs) { + for (typename T::const_iterator it = xs.begin(); + it != xs.end(); + it++) + cout << *it << " "; + cout << endl; +} + +vector<string> split( const string& s, const string& delim =" " ) { + vector<string> res; + string t; + for ( int i = 0 ; i != s.size() ; i++ ) { + if ( delim.find( s[i] ) != string::npos ) { + if ( !t.empty() ) { + res.push_back( t ); + t = ""; + } + } else { + t += s[i]; + } + } + if ( !t.empty() ) { + res.push_back(t); + } + return res; +} + +vector<int> splitInt( const string& s, const string& delim =" " ) { + vector<string> tok = split( s, delim ); + vector<int> res; + for ( int i = 0 ; i != tok.size(); i++ ) + res.push_back( atoi( tok[i].c_str() ) ); + return res; +} +#endif +$ENDCUT$ + + + + + + + +class $CLASSNAME$ { + public: + $RC$ $METHODNAME$($METHODPARMS$) { + $RC$ res; + return res; + } +}; + + + + + + + +$BEGINCUT$ +int main() { + $MAINBODY$ + cin.get(); + return 0; +} +$ENDCUT$ Added: configs/trunk/src/topcoder/template.cs =================================================================== --- configs/trunk/src/topcoder/template.cs (rev 0) +++ configs/trunk/src/topcoder/template.cs 2008-05-14 22:55:40 UTC (rev 815) @@ -0,0 +1,89 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; + +public class $CLASSNAME$ { + public $RC$ $METHODNAME$($METHODPARMS$) { + // asdf + } + + + + + + + public void pp<T>(T x) { Console.WriteLine(x); } + + + + + + + + + $BEGINCUT$ + public static void Main(string[] args) { + $MAINBODY$ + Console.WriteLine("done!"); + Console.Read(); + } + private static void eq( int n, object have, object need) { + if( eq( have, need ) ) { + Console.WriteLine( "Case "+n+" passed." ); + } else { + Console.Write( "Case "+n+" failed: expected " ); + print( need ); + Console.Write( ", received " ); + print( have ); + Console.WriteLine(); + } + } + private static void eq( int n, Array have, Array need) { + if( have == null || have.Length != need.Length ) { + Console.WriteLine("Case "+n+" failed: returned "+have.Length+" elements; expected "+need.Length+" elements."); + print( have ); + print( need ); + return; + } + for( int i= 0; i < have.Length; i++ ) { + if( ! eq( have.GetValue(i), need.GetValue(i) ) ) { + Console.WriteLine( "Case "+n+" failed. Expected and returned array differ in position "+i ); + print( have ); + print( need ); + return; + } + } + Console.WriteLine("Case "+n+" passed."); + } + private static bool eq( object a, object b ) { + if ( a is double && b is double ) { + return Math.Abs((double)a-(double)b) < 1E-9; + } else { + return a!=null && b!=null && a.Equals(b); + } + } + private static void print( object a ) { + if ( a is string ) { + Console.Write("\"{0}\"", a); + } else if ( a is long ) { + Console.Write("{0}L", a); + } else { + Console.Write(a); + } + } + private static void print( Array a ) { + if ( a == null) { + Console.WriteLine("<NULL>"); + for ( int i= 0; i < a.Length; i++ ) { + print( a.GetValue(i) ); + if( i != a.Length-1 ) { + Console.Write(", "); + } + } + Console.WriteLine( '}' ); + } + $ENDCUT$ + } +} Added: configs/trunk/src/topcoder/template.java =================================================================== --- configs/trunk/src/topcoder/template.java (rev 0) +++ configs/trunk/src/topcoder/template.java 2008-05-14 22:55:40 UTC (rev 815) @@ -0,0 +1,15 @@ +$BEGINCUT$ +$PROBLEMDESC$ +$ENDCUT$ +import java.util.*; +public class $CLASSNAME$ { + public $RC$ $METHODNAME$($METHODPARMS$) { + // asdf + } + public static void main(String[] args) { + $CLASSNAME$ temp = new $CLASSNAME$(); + System.out.println(temp.$METHODNAME$($METHODPARMS$)); + } +} + +// vim:et:sw=2:ts=2 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |