1 /* |
1 /* |
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
1107 e.printStackTrace(); |
1107 e.printStackTrace(); |
1108 } |
1108 } |
1109 } |
1109 } |
1110 |
1110 |
1111 public void writeJavaWrapperClass(String outputDir) { |
1111 public void writeJavaWrapperClass(String outputDir) { |
1112 // (new File(outputDir, package_path)).mkdirs(); |
|
1113 try { |
1112 try { |
1114 for (Enumeration e = symbolTable.elements() ; e.hasMoreElements() ;) { |
1113 for (Enumeration e = symbolTable.elements() ; e.hasMoreElements() ;) { |
1115 BaseType tp = (BaseType) e.nextElement(); |
1114 BaseType tp = (BaseType) e.nextElement(); |
1116 if (tp instanceof StructType) { |
1115 if (tp instanceof StructType) { |
1117 StructType st = (StructType) tp; |
1116 StructType st = (StructType) tp; |
1156 pw.println(" unsigned long decorations;\n"); |
1153 pw.println(" unsigned long decorations;\n"); |
1157 pw.println(" long inputMode;\n"); |
1154 pw.println(" long inputMode;\n"); |
1158 pw.println(" unsigned long status;\n"); |
1155 pw.println(" unsigned long status;\n"); |
1159 pw.println("} PropMwmHints;\n"); |
1156 pw.println("} PropMwmHints;\n"); |
1160 |
1157 |
1161 |
|
1162 pw.println("\n\nint main(){"); |
1158 pw.println("\n\nint main(){"); |
1163 j=0; |
1159 j=0; |
1164 for ( eo = symbolTable.elements() ; eo.hasMoreElements() ;) { |
1160 for ( eo = symbolTable.elements() ; eo.hasMoreElements() ;) { |
1165 tp = (BaseType) eo.nextElement(); |
1161 tp = (BaseType) eo.nextElement(); |
1166 if (tp instanceof StructType) |
1162 if (tp instanceof StructType) |
1179 pw.println("printf(\"short\t%d\\n\",(int)sizeof(short));"); |
1175 pw.println("printf(\"short\t%d\\n\",(int)sizeof(short));"); |
1180 pw.println("printf(\"ptr\t%d\\n\",(int)sizeof(void *));"); |
1176 pw.println("printf(\"ptr\t%d\\n\",(int)sizeof(void *));"); |
1181 pw.println("printf(\"Bool\t%d\\n\",(int)sizeof(Bool));"); |
1177 pw.println("printf(\"Bool\t%d\\n\",(int)sizeof(Bool));"); |
1182 pw.println("printf(\"Atom\t%d\\n\",(int)sizeof(Atom));"); |
1178 pw.println("printf(\"Atom\t%d\\n\",(int)sizeof(Atom));"); |
1183 pw.println("printf(\"Window\t%d\\n\",(int)sizeof(Window));"); |
1179 pw.println("printf(\"Window\t%d\\n\",(int)sizeof(Window));"); |
1184 |
|
1185 |
1180 |
1186 for (eo = symbolTable.elements() ; eo.hasMoreElements() ;) { |
1181 for (eo = symbolTable.elements() ; eo.hasMoreElements() ;) { |
1187 |
1182 |
1188 |
1183 |
1189 tp = (BaseType) eo.nextElement(); |
1184 tp = (BaseType) eo.nextElement(); |
1232 symbolTable.put("pointer", new AtomicType(AtomicType.TYPE_PTR, "", "pointer")); |
1227 symbolTable.put("pointer", new AtomicType(AtomicType.TYPE_PTR, "", "pointer")); |
1233 symbolTable.put("longlong", new AtomicType(AtomicType.TYPE_LONG_LONG, "", "longlong")); |
1228 symbolTable.put("longlong", new AtomicType(AtomicType.TYPE_LONG_LONG, "", "longlong")); |
1234 symbolTable.put("Atom", new AtomicType(AtomicType.TYPE_ATOM, "", "Atom")); |
1229 symbolTable.put("Atom", new AtomicType(AtomicType.TYPE_ATOM, "", "Atom")); |
1235 symbolTable.put("ulong", new AtomicType(AtomicType.TYPE_ULONG, "", "ulong")); |
1230 symbolTable.put("ulong", new AtomicType(AtomicType.TYPE_ULONG, "", "ulong")); |
1236 } |
1231 } |
1237 public WrapperGenerator(String outputDir, String xlibFilename) { |
1232 |
|
1233 public WrapperGenerator(String xlibFilename) { |
1238 initTypes(); |
1234 initTypes(); |
1239 try { |
1235 try { |
1240 BufferedReader in = new BufferedReader(new FileReader(xlibFilename)); |
1236 BufferedReader in = new BufferedReader(new FileReader(xlibFilename)); |
1241 String line; |
1237 String line; |
1242 String splits[]; |
1238 String splits[]; |
1301 in.close(); |
1297 in.close(); |
1302 } |
1298 } |
1303 catch (Exception e) { |
1299 catch (Exception e) { |
1304 e.printStackTrace(); |
1300 e.printStackTrace(); |
1305 } |
1301 } |
1306 |
1302 } |
1307 } |
1303 |
1308 private void makeSizer(String outputDir) { |
1304 private void makeSizer(String sizerFileName) { |
1309 if (wide) { |
1305 File fp = new File(sizerFileName); |
1310 sizerFileName = "sizer.64.c"; |
|
1311 } else { |
|
1312 sizerFileName = "sizer.32.c"; |
|
1313 } |
|
1314 File fp = new File(outputDir, sizerFileName); |
|
1315 writeNativeSizer(fp.getAbsolutePath()); |
1306 writeNativeSizer(fp.getAbsolutePath()); |
1316 } |
1307 } |
1317 private boolean readSizeInfo(String sizeInfo) { |
1308 |
|
1309 private boolean readSizeInfo(String file32, String file64) { |
1318 try { |
1310 try { |
1319 File f = new File(sizeInfo+".32"); |
|
1320 boolean res = true; |
1311 boolean res = true; |
1321 FileInputStream fis = null; |
1312 if (!file32.equals("IGNORE")) { |
1322 if (f.exists()) { |
1313 FileInputStream fis = new FileInputStream(file32); |
1323 fis = new FileInputStream(f); |
|
1324 res = readSizeInfo(fis, false); |
1314 res = readSizeInfo(fis, false); |
1325 fis.close(); |
1315 fis.close(); |
1326 } |
1316 } |
1327 f = new File(sizeInfo+".64"); |
1317 if (!file64.equals("IGNORE")) { |
1328 if (f.exists()) { |
1318 FileInputStream fis = new FileInputStream(file64); |
1329 fis = new FileInputStream(f); |
|
1330 res &= readSizeInfo(fis, true); |
1319 res &= readSizeInfo(fis, true); |
1331 fis.close(); |
1320 fis.close(); |
1332 } |
1321 } |
1333 return res; |
1322 return res; |
1334 } catch (Exception e) { |
1323 } catch (Exception e) { |
1335 e.printStackTrace(); |
1324 e.printStackTrace(); |
1336 return false; |
1325 return false; |
1337 } |
1326 } |
1338 } |
1327 } |
1339 |
1328 |
1340 private void startGeneration(String outputDir, String sizeInfo) { |
1329 private void startGeneration(String outputDir, String file32, String file64) { |
1341 if (readSizeInfo(sizeInfo)) |
1330 if (readSizeInfo(file32, file64)) |
1342 { |
1331 { |
1343 writeJavaWrapperClass(outputDir); |
1332 writeJavaWrapperClass(outputDir); |
1344 } |
1333 } |
1345 else { |
1334 else { |
1346 System.out.println("Error calculating offsets"); |
1335 System.out.println("Error calculating offsets"); |
1348 } |
1337 } |
1349 |
1338 |
1350 public static void main(String[] args) { |
1339 public static void main(String[] args) { |
1351 |
1340 |
1352 if (args.length < 4) { |
1341 if (args.length < 4) { |
1353 System.out.println("Usage:\nWrapperGenerator <output_dir> <xlibtypes.txt> <action> [<platform> | <sizes info file>]"); |
1342 System.out.println("Usage:\nWrapperGenerator gen_java <output_dir> <xlibtypes.txt> <sizes-32.txt|IGNORE> <sizes-64.txt|IGNORE>"); |
1354 System.out.println("Where <action>: gen, sizer"); |
1343 System.out.println(" or"); |
1355 System.out.println(" <platform>: 32, 64"); |
1344 System.out.println("WrapperGenerator gen_c_source <output_file> <xlibtypes.txt> <platform>"); |
|
1345 System.out.println("Where <platform>: 32, 64"); |
|
1346 |
1356 System.exit(1); |
1347 System.exit(1); |
1357 } |
1348 } |
1358 |
1349 |
1359 WrapperGenerator xparser = new WrapperGenerator(args[0], args[1]); |
1350 WrapperGenerator xparser = new WrapperGenerator(args[2]); |
1360 if (args[2].equals("sizer")) { |
1351 if (args[0].equals("gen_c_source")) { |
1361 xparser.wide = args[3].equals("64"); |
1352 xparser.wide = args[3].equals("64"); |
1362 xparser.makeSizer(args[0]); |
1353 xparser.makeSizer(args[1]); |
1363 } else if (args[2].equals("gen")) { |
1354 } else if (args[0].equals("gen_java")) { |
1364 xparser.startGeneration(args[0], args[3]); |
1355 xparser.startGeneration(args[1], args[3], args[4]); |
1365 } |
1356 } |
1366 } |
1357 } |
1367 |
|
1368 } |
1358 } |