!636 !629 // standard functions main { psvm { String src = takeInput(args, null); List<String> cnc = parseCNC(src); for (int i = 1; i+2 < cnc.size(); i += 2) { if (cnc.get(i).equals("class") && cnc.get(i+2).equals("main")) { int j = i; while (j < cnc.size() && !cnc.get(j).equals("{")) j += 2; int k = findEndOfBlock(cnc, j); printExcerpt(cnc, i, k); break; } } } static int findEndOfBlock(List<String> cnc, int i) { int j = i+2, level = 1; while (j < cnc.size()) { if (cnc.get(j).equals("{")) ++level; else if (cnc.get(j).equals("}")) --level; if (level == 0) return j+1; } return cnc.size(); } static void printExcerpt(List<String> cnc, int i, int j) { StringBuilder out = new StringBuilder(); for (; i < j; i++) out.append(cnc.get(i)); System.out.println(out.toString()); } static String takeInput(String[] args, String def) tex { return args.length != 0 ? loadSnippet(args[0]) : loadTextFile("input/input.txt", def); } static List<String> parseCNC(String src) { List<String> list = new ArrayList<String>(); for (String s : toLines(src)) list.add(unquote(s)); return list; } }
Snippet is not live.
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, qbtsjoyahagl, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #2000396 |
Snippet name: | Find main class (developing) |
Eternal ID of this version: | #2000396/1 |
Text MD5: | 1727b670fd86e594345a288c07241eb2 |
Author: | stefan |
Category: | javax |
Type: | New Tinybrain snippet |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-06-27 20:33:18 |
Source code size: | 1328 bytes / 49 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 616 / 144 |
Referenced in: | [show references] |