Last active
November 8, 2016 05:35
-
-
Save ayumi/f14be6cf39f855a82ffd9ddc8839f08b to your computer and use it in GitHub Desktop.
chromium net_error_list.h -> js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
/* This Source Code Form is subject to the terms of the Mozilla Public | |
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | |
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
# net_error_list.h | |
# https://cs.chromium.org/chromium/src/net/base/net_error_list.h?sq=package:chromium | |
path = ARGV[0] or (puts "Usage: Pass path to net_error_list.h."; exit) | |
path_out = "./net_error_list_#{Time.now.to_i}.js" | |
File.exists?(path_out) and raise "Output file exists: #{path_out}" | |
regex = /^NET_ERROR\(([\w]+),\s+?(\-?\d+?)\)$/ | |
begin | |
file_out = File.open(path_out, "w:UTF-8") | |
file_out.puts("const requestErrorList = {") | |
write_buffer = nil | |
File.readlines(path).each do |line| | |
next if !line.start_with?("NET_ERROR") | |
match_result = regex.match(line) or next | |
error_name, error_code = match_result[1], match_result[2] | |
file_out.puts("#{write_buffer},") if write_buffer | |
write_buffer = " #{error_name}: #{error_code}" | |
end | |
file_out.puts(write_buffer) if write_buffer | |
file_out.puts("}\n\nmodule.exports = requestErrorList") | |
ensure | |
file_out.close | |
end | |
puts "Wrote #{path_out}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment