|
Modules
ADT Database GTK2 GUI IP PiJAX Public Sql Stdio Subversion System Tools Xosd lua v4l2 wx
Recent Changes
Public.USB 1.0
Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Popular Downloads
Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48
|
Module Information
Public.USB
Viewing contents of Public_USB-1.0/update_usb_ids.pike
#!/usr/bin/env pike
/*
* Download the latest usb.ids file from the USB ID Repository
*
* Usage: pike update_usb_ids.pike
*/
int main() {
string url = "http://www.linux-usb.org/usb.ids";
string output_file = "usb.ids";
write("Downloading USB ID database from %s...\n", url);
Protocols.HTTP.Query query = Protocols.HTTP.get_url(url);
if (!query || query->status != 200) {
werror("Failed to download usb.ids: HTTP %d\n", query ? query->status : 0);
return 1;
}
string data = query->data();
if (!data || sizeof(data) < 1000) {
werror("Downloaded file seems too small or empty\n");
return 1;
}
// Write to file
Stdio.write_file(output_file, data);
// Parse to verify format
int vendor_count = 0;
foreach(data / "\n", string line) {
if (sizeof(line) > 0 && line[0] != '#' && line[0] != '\t' && line[0] != ' ') {
vendor_count++;
}
}
write("â Downloaded successfully!\n");
write(" File size: %d bytes\n", sizeof(data));
write(" Vendors: ~%d\n", vendor_count);
write(" Saved to: %s\n", output_file);
return 0;
}
|
|
|