Bug 496271, automation config for Tb2.0.0.22 build1, p=joduinn, r=me
[mozilla-1.9.git] / extensions / java / xpcom / interfaces / gen-nsError.pl
blob2a98955c481309ed2264e4eaf5b8494237b4c00f
1 #! /usr/bin/env perl
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
15 # The Original Code is Java XPCOM Bindings.
17 # The Initial Developer of the Original Code is
18 # Michal Ceresna.
19 # Portions created by the Initial Developer are Copyright (C) 2005
20 # the Initial Developer. All Rights Reserved.
22 # Contributor(s):
23 # Michal Ceresna (ceresna@dbai.tuwien.ac.at)
24 # Javier Pedemonte (jhpedemonte@gmail.com)
26 # Alternatively, the contents of this file may be used under the terms of
27 # either the GNU General Public License Version 2 or later (the "GPL"), or
28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 # in which case the provisions of the GPL or the LGPL are applicable instead
30 # of those above. If you wish to allow use of your version of this file only
31 # under the terms of either the GPL or the LGPL, and not to allow others to
32 # use your version of this file under the terms of the MPL, indicate your
33 # decision by deleting the provisions above and replace them with the notice
34 # and other provisions required by the GPL or the LGPL. If you do not delete
35 # the provisions above, a recipient may use your version of this file under
36 # the terms of any one of the MPL, the GPL or the LGPL.
38 # ***** END LICENSE BLOCK *****
40 # Generates IXPCOMError.java from xpcom/base/nsError.h
42 # usage: perl gen-nsErrors.pl < <topsrcdir>/xpcom/base/nsError.h > IXPCOMError.java
45 print "/* ***** BEGIN LICENSE BLOCK *****\n";
46 print " * Version: MPL 1.1/GPL 2.0/LGPL 2.1\n";
47 print " *\n";
48 print " * The contents of this file are subject to the Mozilla Public License Version\n";
49 print " * 1.1 (the \"License\"); you may not use this file except in compliance with\n";
50 print " * the License. You may obtain a copy of the License at\n";
51 print " * http://www.mozilla.org/MPL/\n";
52 print " *\n";
53 print " * Software distributed under the License is distributed on an \"AS IS\" basis,\n";
54 print " * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\n";
55 print " * for the specific language governing rights and limitations under the\n";
56 print " * License.\n";
57 print " *\n";
58 print " * The Original Code is mozilla.org code.\n";
59 print " *\n";
60 print " * The Initial Developer of the Original Code is\n";
61 print " * Netscape Communications Corporation.\n";
62 print " * Portions created by the Initial Developer are Copyright (C) 1998\n";
63 print " * the Initial Developer. All Rights Reserved.\n";
64 print " *\n";
65 print " * Contributor(s):\n";
66 print " *\n";
67 print " * Alternatively, the contents of this file may be used under the terms of\n";
68 print " * either of the GNU General Public License Version 2 or later (the \"GPL\"),\n";
69 print " * or the GNU Lesser General Public License Version 2.1 or later (the \"LGPL\"),\n";
70 print " * in which case the provisions of the GPL or the LGPL are applicable instead\n";
71 print " * of those above. If you wish to allow use of your version of this file only\n";
72 print " * under the terms of either the GPL or the LGPL, and not to allow others to\n";
73 print " * use your version of this file under the terms of the MPL, indicate your\n";
74 print " * decision by deleting the provisions above and replace them with the notice\n";
75 print " * and other provisions required by the GPL or the LGPL. If you do not delete\n";
76 print " * the provisions above, a recipient may use your version of this file under\n";
77 print " * the terms of any one of the MPL, the GPL or the LGPL.\n";
78 print " *\n";
79 print " * ***** END LICENSE BLOCK ***** */\n";
81 print "\n";
82 print "package org.mozilla.xpcom;\n";
83 print "\n\n";
85 print "/**\n";
86 print " * Mozilla XPCOM error codes.\n";
87 print " * <p>\n";
88 print " * THIS FILE GENERATED FROM mozilla/xpcom/base/nsError.h.\n";
89 print " * PLEASE SEE THAT FILE FOR FULL DOCUMENTATION.\n";
90 print " */\n";
91 print "public interface IXPCOMError {\n";
93 while (<STDIN>) {
94 $line = $_;
96 if ($prevline) {
97 $_ = $prevline.$_;
99 if (/(.*)\\$/) {
100 #splitted line
101 $prevline = $1;
102 next;
104 $prevline = "";
106 if (/^\s*#define\s+(NS_[A-Z_]+)\s+(0x)?([0-9a-fA-F]+)\s*$/) {
107 #define NS_ERROR_MODULE_XPCOM 1
108 #define NS_ERROR_MODULE_BASE_OFFSET 0x45
109 print " long $1 = $2$3L;\n";
111 elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+\((NS_[A-Z_]+)\s+\+\s+(0x)?([0-9a-fA-F]+)\s*\)\s*/) {
112 #define NS_ERROR_NOT_INITIALIZED (NS_ERROR_BASE + 1)
113 #define NS_ERROR_FACTORY_EXISTS (NS_ERROR_BASE + 0x100)
114 print " long $1 = $2 + $3$4L;\n";
116 elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+(NS_[A-Z_]+)\s\s*/) {
117 #define NS_ERROR_NO_INTERFACE NS_NOINTERFACE
118 print " long $1 = $2;\n";
120 elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+\(\(nsresult\)\s*(0x)?([0-9a-fA-F]+)L?\)\s*$/) {
121 #define NS_ERROR_BASE ((nsresult) 0xC1F30000)
122 #define NS_ERROR_ABORT ((nsresult) 0x80004004L)
123 print " long $1 = $2$3L;\n";
125 elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+NS_ERROR_GENERATE_FAILURE\s*\(\s*(NS_[A-Z_]+)\s*,\s*([0-9]+)\s*\)\s*$/) {
126 #define NS_BASE_STREAM_CLOSED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_BASE, 2)
127 $module = $2;
128 $code = $3;
129 print " long $1 = ((NS_ERROR_SEVERITY_ERROR<<31) |\n";
130 print " (($module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | $code);\n";
132 elsif (/^\s*#define\s+(NS_[A-Z_]+)\s+NS_ERROR_GENERATE_SUCCESS\s*\(\s*(NS_[A-Z_]+)\s*,\s*([0-9]+)\s*\)\s*$/) {
133 #define NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_XPCOM, 1)
134 $module = $2;
135 $code = $3;
136 print " long $1 = ((NS_ERROR_SEVERITY_SUCCESS<<31) |\n";
137 print " (($module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | $code);\n";
139 elsif (/^\s*\/\*(.*)\*\/\s*$/ && !/^\s*\/\*@[\{\}]\*\/\s*$/ &&
140 !/^\s*\/\*\ -\*- Mode:/) {
141 #single line comment, but not
142 #/*@{*/, /*@}*/,
143 #/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
144 print " /*$1*/\n";
146 elsif (/^\s*$/) {
147 #empty line, but write only the first
148 #line from a sequence of empty lines
149 if (!$wasEmpty) {
150 print "\n";
152 $wasEmpty = 1;
153 next;
155 else {
156 next;
159 $wasEmpty = 0;
162 print "}\n";