├── dumping.jpg ├── src ├── plugins │ ├── arduino │ │ ├── arduino.plugin │ │ ├── spi-dump.ino │ │ └── arduino.vala │ └── Makefile.am ├── progressbar │ ├── progressbar.vapi │ ├── progressbar.h │ └── progressbar.c ├── libplugin │ ├── Makefile.am │ └── libspi-dump-plugin.vala ├── Makefile.am ├── plugin-engine.vala ├── transfer.vala ├── spi-dump.bup.vala └── spi-dump.vala ├── Makefile.am ├── test ├── Makefile.am ├── tty.vala └── mock-arduino.vala ├── autogen.sh ├── configure.ac ├── README.md ├── git.mk └── LICENSE /dumping.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bob131/spi-dump/HEAD/dumping.jpg -------------------------------------------------------------------------------- /src/plugins/arduino/arduino.plugin: -------------------------------------------------------------------------------- 1 | [Plugin] 2 | Name=arduino 3 | Module=arduino 4 | Description=Simple serial protocol with Ardiuno sketch 5 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | AM_MAKEFLAGS = --no-print-directory 2 | 3 | SUBDIRS = src test 4 | 5 | MAINTAINERCLEANFILES = \ 6 | $(GITIGNORE_MAINTAINERCLEANFILES_TOPLEVEL) \ 7 | $(GITIGNORE_MAINTAINERCLEANFILES_MAKEFILE_IN) \ 8 | $(GITIGNORE_MAINTAINERCLEANFILES_M4_LIBTOOL) \ 9 | m4/pkg.m4 10 | 11 | EXTRA_DIST = autogen.sh 12 | 13 | GITIGNOREFILES = *.bin 14 | 15 | -include git.mk 16 | -------------------------------------------------------------------------------- /src/progressbar/progressbar.vapi: -------------------------------------------------------------------------------- 1 | [Compact] 2 | [CCode (cheader_filename = "progressbar/progressbar.h", cname = "progressbar", lower_case_cprefix = "progressbar_")] 3 | public class ProgressBar { 4 | public time_t start; 5 | public void update(ulong @value); 6 | public void update_label(string label); 7 | [DestroysInstance] 8 | public void finish(); 9 | public ProgressBar(string label, ulong max); 10 | } 11 | -------------------------------------------------------------------------------- /test/Makefile.am: -------------------------------------------------------------------------------- 1 | check_PROGRAMS = mock-arduino 2 | 3 | mock_arduino_SOURCES = \ 4 | tty.vala \ 5 | mock-arduino.vala 6 | 7 | mock_arduino_VALAFLAGS = \ 8 | --enable-experimental \ 9 | $(AM_VALAFLAGS) \ 10 | $(glib_U_VALAFLAGS) \ 11 | $(spi_dump_U_VALAFLAGS) 12 | 13 | mock_arduino_CFLAGS = \ 14 | $(AM_CFLAGS) \ 15 | $(glib_U_CFLAGS) \ 16 | $(spi_dump_U_CFLAGS) 17 | 18 | mock_arduino_LDADD = \ 19 | $(glib_U_LIBS) \ 20 | $(spi_dump_U_LIBS) 21 | 22 | -include $(top_srcdir)/git.mk 23 | -------------------------------------------------------------------------------- /src/libplugin/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libspi-dump-plugin.la 2 | 3 | BUILT_SOURCES = \ 4 | libspi-dump-plugin.h \ 5 | libspi-dump-plugin.vapi 6 | 7 | libspi_dump_plugin_la_SOURCES = libspi-dump-plugin.vala 8 | 9 | libspi_dump_plugin_la_VALAFLAGS = \ 10 | --library libspi-dump-plugin \ 11 | -H libspi-dump-plugin.h \ 12 | --vapi libspi-dump-plugin.vapi \ 13 | $(AM_VALAFLAGS) \ 14 | $(glib_U_VALAFLAGS) 15 | 16 | libspi_dump_plugin_la_CFLAGS = \ 17 | $(AM_CFLAGS) \ 18 | $(glib_U_CFLAGS) 19 | 20 | libspi_dump_plugin_la_LIBADD = $(glib_U_LIBS) 21 | 22 | -include $(top_srcdir)/git.mk 23 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = libplugin plugins 2 | 3 | bin_PROGRAMS = spi-dump 4 | 5 | spi_dump_SOURCES = \ 6 | libplugin/libspi-dump-plugin.vapi \ 7 | progressbar/progressbar.c \ 8 | progressbar/progressbar.vapi \ 9 | plugin-engine.vala \ 10 | transfer.vala \ 11 | spi-dump.vala 12 | 13 | spi_dump_VALAFLAGS = \ 14 | $(AM_VALAFLAGS) \ 15 | $(glib_U_VALAFLAGS) \ 16 | $(peas_U_VALAFLAGS) \ 17 | $(spi_dump_U_VALAFLAGS) 18 | 19 | spi_dump_CFLAGS = \ 20 | -Ilibplugin \ 21 | -DPLUGINDIR=\"$(plugindir)\" \ 22 | $(AM_CFLAGS) \ 23 | $(glib_U_CFLAGS) \ 24 | $(peas_U_CFLAGS) \ 25 | $(spi_dump_U_CFLAGS) 26 | 27 | spi_dump_LDADD = \ 28 | -lm \ 29 | libplugin/libspi-dump-plugin.la \ 30 | $(glib_U_LIBS) \ 31 | $(peas_U_LIBS) \ 32 | $(spi_dump_U_LIBS) 33 | 34 | -include $(top_srcdir)/git.mk 35 | -------------------------------------------------------------------------------- /src/plugins/Makefile.am: -------------------------------------------------------------------------------- 1 | base_sources = $(top_srcdir)/src/libplugin/libspi-dump-plugin.vapi 2 | base_valaflags = $(AM_VALAFLAGS) $(glib_U_VALAFLAGS) $(peas_U_VALAFLAGS) 3 | base_cflags = -I$(top_srcdir)/src/libplugin $(AM_CFLAGS) $(glib_U_CFLAGS) $(peas_U_CFLAGS) 4 | base_libs = $(top_srcdir)/src/libplugin/libspi-dump-plugin.la $(glib_U_LIBS) $(peas_U_LIBS) 5 | base_ldflags = -module -avoid-version -no-undefined 6 | 7 | plugin_LTLIBRARIES = arduino/libarduino.la 8 | 9 | arduino_libarduino_la_SOURCES = \ 10 | arduino/arduino.vala \ 11 | $(base_sources) 12 | 13 | arduino_libarduino_la_VALAFLAGS = \ 14 | --pkg posix \ 15 | $(base_valaflags) 16 | 17 | arduino_libarduino_la_CFLAGS = $(base_cflags) 18 | 19 | arduino_libarduino_la_LIBADD = $(base_libs) 20 | 21 | arduino_libarduino_la_LDFLAGS = $(base_ldflags) 22 | 23 | -include $(top_srcdir)/git.mk 24 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | _openbsd_acenv_set() { 6 | [ -z ${AUTOCONF_VERSION:-} ] || return 0 7 | export AUTOCONF_VERSION 8 | AUTOCONF_VERSION="$( ls -1 /usr/local/bin/autoreconf-* | sort | tail -n 1 )" 9 | AUTOCONF_VERSION="${AUTOCONF_VERSION##*-}" 10 | } 11 | 12 | _openbsd_amenv_set() { 13 | [ -z ${AUTOMAKE_VERSION:-} ] || return 0 14 | export AUTOMAKE_VERSION 15 | AUTOMAKE_VERSION="$( ls -1 /usr/local/bin/automake-* | sort | tail -n 1 )" 16 | AUTOMAKE_VERSION="${AUTOMAKE_VERSION##*-}" 17 | } 18 | 19 | _openbsd_env_set() { 20 | [ `uname` = OpenBSD ] || return 0 21 | _openbsd_acenv_set 22 | _openbsd_amenv_set 23 | } 24 | 25 | _openbsd_env_set 26 | 27 | set -e 28 | 29 | srcdir=`dirname $0` 30 | test -z "$srcdir" && srcdir=. 31 | 32 | aclocal -I m4 --install 33 | autoreconf --force --install 34 | 35 | if [ -z "$NOCONFIGURE" ]; then 36 | "$srcdir"/configure ${1+"$@"} 37 | fi 38 | 39 | -------------------------------------------------------------------------------- /src/plugins/arduino/spi-dump.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define CS_PIN 10 4 | 5 | #define CMD_PREFIX 0xff 6 | #define CS_PULL_LOW 0x1 7 | #define CS_PULL_HIGH 0x2 8 | 9 | void setup() { 10 | Serial.begin(57600); 11 | 12 | pinMode(CS_PIN, OUTPUT); 13 | digitalWrite(CS_PIN, HIGH); 14 | SPI.begin(); 15 | } 16 | 17 | void loop() { 18 | if (Serial.available()) { 19 | byte input = Serial.read(); 20 | if (input == CMD_PREFIX) { 21 | while (Serial.available() == 0) {} 22 | byte cmd = Serial.read(); 23 | switch (cmd) { 24 | case CS_PULL_LOW: 25 | digitalWrite(CS_PIN, LOW); 26 | break; 27 | case CS_PULL_HIGH: 28 | digitalWrite(CS_PIN, HIGH); 29 | break; 30 | } 31 | if (cmd != CMD_PREFIX) { 32 | Serial.write(cmd xor 0xff); 33 | return; 34 | } 35 | } 36 | Serial.write(SPI.transfer(input)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/tty.vala: -------------------------------------------------------------------------------- 1 | [PrintfFormat] 2 | IOError ioerror(string message, ...) { 3 | return new IOError.FAILED("%s: %s", message.vprintf(va_list()), 4 | strerror(errno)); 5 | } 6 | 7 | // just provides a convenience function 8 | class InputWrap : Object { 9 | public InputStream stream {construct; get;} 10 | 11 | public new async void read_all(uint8[] buffer) throws Error { 12 | size_t _; 13 | yield stream.read_all_async(buffer, Priority.DEFAULT, null, out _); 14 | } 15 | 16 | public async void skip(ssize_t length) throws IOError { 17 | yield stream.skip_async(length); 18 | } 19 | 20 | public InputWrap(InputStream stream) { 21 | Object(stream: stream); 22 | } 23 | } 24 | 25 | class TTY : Object { 26 | public InputWrap @in {construct; get;} 27 | public OutputStream @out {construct; get;} 28 | 29 | public TTY.from_fd(int tty_fd) throws IOError { 30 | Posix.termios termios; 31 | if (Posix.tcgetattr(tty_fd, out termios) == -1) 32 | throw ioerror("Failed getting TTY settings"); 33 | Posix.cfmakeraw(ref termios); 34 | if (Posix.cfsetspeed(ref termios, Posix.B57600) == -1) 35 | throw ioerror("Failed setting TTY baud rate"); 36 | if (Posix.tcsetattr(tty_fd, 0, termios) == -1) 37 | throw ioerror("Failed setting TTY settings"); 38 | 39 | Object(@in: new InputWrap(new UnixInputStream(tty_fd, false)), 40 | @out: new UnixOutputStream(tty_fd, false)); 41 | } 42 | 43 | public TTY(string tty_path) throws IOError { 44 | var tty_fd = Posix.open((!) tty_path, Posix.O_RDWR); 45 | if (tty_fd == -1) 46 | throw ioerror("Failed to open TTY '%s'", tty_path); 47 | if (!Posix.isatty(tty_fd)) 48 | throw new IOError.FAILED("File '%s' is not a TTY", tty_path); 49 | 50 | this.from_fd(tty_fd); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/mock-arduino.vala: -------------------------------------------------------------------------------- 1 | // ptsname is missing from posix.vapi 2 | [CCode (type = "char*")] 3 | extern unowned string ptsname (int file_descriptor); 4 | 5 | async void loop (TTY tty) { 6 | var buf = new uint8[1]; 7 | 8 | try { 9 | while (true) { 10 | yield tty.in.read_all (buf); 11 | 12 | switch (buf[0]) { 13 | case 0x03: 14 | yield tty.in.skip (3); 15 | for (var i = 0; i < 4; i++) 16 | yield tty.out.write_async ({0x00}); 17 | break; 18 | 19 | case 0x00: 20 | yield tty.out.write_async ({0x00}); 21 | break; 22 | 23 | case 0xFF: 24 | yield tty.in.read_all (buf); 25 | yield tty.out.write_async ({buf[0] ^ 0xFF}); 26 | break; 27 | 28 | default: 29 | assert_not_reached (); 30 | } 31 | } 32 | } catch (Error e) { 33 | stderr.printf ("Operation failed: %s\n", e.message); 34 | Posix.exit (Posix.EXIT_FAILURE); 35 | } 36 | } 37 | 38 | int main(string[] args) { 39 | var fd = Posix.posix_openpt (Posix.O_RDWR | Posix.O_NOCTTY); 40 | 41 | if (fd == -1) 42 | error ("Failed to create PTY: %s", strerror (errno)); 43 | 44 | if (Posix.grantpt (fd) == -1) 45 | error ("Failed to set PTY permissions: %s", strerror (errno)); 46 | 47 | if (Posix.unlockpt (fd) == -1) 48 | error ("Failed to unlock PTY: %s", strerror (errno)); 49 | 50 | message ("Successfully opened PTY %s", ptsname (fd)); 51 | 52 | var mainloop = new MainLoop (); 53 | 54 | TTY tty; 55 | try { 56 | tty = new TTY.from_fd (fd); 57 | } catch (IOError e) { 58 | error ("Failed to init TTY: %s", e.message); 59 | } 60 | 61 | loop.begin (tty); 62 | 63 | mainloop.run (); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([spi-dump], [0.3]) 2 | 3 | AC_CONFIG_AUX_DIR([build-aux]) 4 | AC_CONFIG_MACRO_DIR([m4]) 5 | 6 | AM_INIT_AUTOMAKE([foreign subdir-objects]) 7 | AM_SILENT_RULES([yes]) 8 | 9 | AM_PROG_VALAC([0.28]) 10 | AM_PROG_CC_C_O 11 | 12 | AC_PROG_LN_S 13 | 14 | LT_INIT([disable-static]) 15 | 16 | AC_SUBST([plugindir], ["\$(libdir)/spi-dump/plugins"]) 17 | 18 | AC_SUBST([AM_CFLAGS], ["\ 19 | -Wall -Wextra \ 20 | -Wno-unused-function \ 21 | -Wno-unused-parameter \ 22 | -Wno-unused-variable -Wno-unused-but-set-variable \ 23 | \$(NULL)"]) 24 | 25 | dnl ########################################################################### 26 | dnl Dependencies 27 | dnl ########################################################################### 28 | 29 | GLIB_REQUIRED=2.40.0 30 | 31 | PKG_CHECK_MODULES(glib_U, [ 32 | glib-2.0 >= $GLIB_REQUIRED 33 | gobject-2.0 >= $GLIB_REQUIRED 34 | gio-2.0 >= $GLIB_REQUIRED 35 | gio-unix-2.0 >= $GLIB_REQUIRED 36 | ]) 37 | 38 | PKG_CHECK_MODULES(peas_U, [libpeas-1.0]) 39 | 40 | PKG_CHECK_MODULES(spi_dump_U, [ 41 | zlib 42 | ncurses 43 | ]) 44 | 45 | AC_SUBST([AM_VALAFLAGS], ["\ 46 | --fatal-warnings \ 47 | --enable-checking \ 48 | --enable-experimental-non-null \ 49 | \$(NULL)"]) 50 | 51 | AC_SUBST([glib_U_VALAFLAGS], ["\ 52 | --pkg gio-2.0 \ 53 | --pkg gio-unix-2.0 \ 54 | --target-glib=$GLIB_REQUIRED \ 55 | \$(NULL)"]) 56 | 57 | AC_SUBST([peas_U_VALAFLAGS], ["--pkg libpeas-1.0"]) 58 | 59 | AC_SUBST([spi_dump_U_VALAFLAGS], ["\ 60 | --pkg posix \ 61 | --pkg zlib \ 62 | \$(NULL)"]) 63 | 64 | dnl ########################################################################### 65 | dnl Files to generate 66 | dnl ########################################################################### 67 | 68 | AC_CONFIG_FILES([ 69 | Makefile 70 | src/Makefile 71 | src/libplugin/Makefile 72 | src/plugins/Makefile 73 | test/Makefile 74 | ]) 75 | AC_OUTPUT 76 | -------------------------------------------------------------------------------- /src/plugins/arduino/arduino.vala: -------------------------------------------------------------------------------- 1 | [PrintfFormat] 2 | IOError ioerror (string message, ...) { 3 | return new IOError.FAILED ("%s: %s", message.vprintf (va_list ()), 4 | strerror (errno)); 5 | } 6 | 7 | class Arduino.TTY : SpiDump.DeviceIOStream { 8 | public override async void set_chip_select (SpiDump.PinState state) 9 | throws Error 10 | { 11 | uint8 command = state == SpiDump.PinState.LOW ? 0x1 : 0x2; 12 | 13 | this.@out.write_all.begin ({0xFF, command}); 14 | 15 | if ((yield this.@in.read_byte ()) != (command ^ 0xFF)) 16 | throw new IOError.FAILED ("Invalid response"); 17 | } 18 | 19 | public TTY.from_fd (int tty_fd) throws IOError { 20 | Posix.termios termios; 21 | 22 | if (Posix.tcgetattr (tty_fd, out termios) == -1) 23 | throw ioerror ("Failed getting TTY settings"); 24 | 25 | Posix.cfmakeraw (ref termios); 26 | if (Posix.cfsetspeed (ref termios, Posix.B57600) == -1) 27 | throw ioerror ("Failed setting TTY baud rate"); 28 | if (Posix.tcsetattr (tty_fd, 0, termios) == -1) 29 | throw ioerror ("Failed setting TTY settings"); 30 | 31 | Object ( 32 | @in: new SpiDump.SimpleDeviceInputStream ( 33 | new UnixInputStream (tty_fd, false) 34 | ), 35 | @out: new SpiDump.SimpleDeviceOutputStream ( 36 | new UnixOutputStream (tty_fd, false) 37 | ) 38 | ); 39 | } 40 | 41 | public TTY (string tty_path) throws IOError { 42 | var tty_fd = Posix.open ((!) tty_path, Posix.O_RDWR); 43 | 44 | if (tty_fd == -1) 45 | throw ioerror ("Failed to open TTY '%s'", tty_path); 46 | if (!Posix.isatty (tty_fd)) 47 | throw new IOError.FAILED ("File '%s' is not a TTY", tty_path); 48 | 49 | this.from_fd (tty_fd); 50 | } 51 | } 52 | 53 | class Arduino.Plugin : Object, SpiDump.HardwarePlugin { 54 | string tty_path; 55 | 56 | public OptionEntry[] get_options () { 57 | return { 58 | OptionEntry () { 59 | long_name = "tty", 60 | arg = OptionArg.FILENAME, 61 | arg_data = &tty_path, 62 | description = "Path to Arduino serial console", 63 | arg_description = "/dev/ttyUSB0" 64 | } 65 | }; 66 | } 67 | 68 | public SpiDump.DeviceIOStream open () throws Error { 69 | if ((void*) tty_path == null) 70 | throw new SpiDump.HardwarePluginError.INVALID_ARGS ( 71 | "TTY path not specified" 72 | ); 73 | 74 | return new TTY (tty_path); 75 | } 76 | } 77 | 78 | [ModuleInit] 79 | public void peas_register_types (TypeModule module) { 80 | ((Peas.ObjectModule) module).register_extension_type ( 81 | typeof (SpiDump.HardwarePlugin), 82 | typeof (Arduino.Plugin) 83 | ); 84 | } 85 | -------------------------------------------------------------------------------- /src/progressbar/progressbar.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \author Trevor Fountain 4 | * \author Johannes Buchner 5 | * \author Erik Garrison 6 | * \date 2010-2014 7 | * \copyright BSD 3-Clause 8 | * 9 | * progressbar -- a C class (by convention) for displaying progress 10 | * on the command line (to stderr). 11 | */ 12 | 13 | #ifndef PROGRESSBAR_H 14 | #define PROGRESSBAR_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /** 26 | * Progressbar data structure (do not modify or create directly) 27 | */ 28 | typedef struct _progressbar_t 29 | { 30 | /// maximum value 31 | unsigned long max; 32 | /// current value 33 | unsigned long value; 34 | 35 | /// time progressbar was started 36 | time_t start; 37 | 38 | /// label 39 | const char *label; 40 | 41 | /// characters for the beginning, filling and end of the 42 | /// progressbar. E.g. |### | has |#| 43 | struct { 44 | char begin; 45 | char fill; 46 | char end; 47 | } format; 48 | } progressbar; 49 | 50 | /// Create a new progressbar with the specified label and number of steps. 51 | /// 52 | /// @param label The label that will prefix the progressbar. 53 | /// @param max The number of times the progressbar must be incremented before it is considered complete, 54 | /// or, in other words, the number of tasks that this progressbar is tracking. 55 | /// 56 | /// @return A progressbar configured with the provided arguments. Note that the user is responsible for disposing 57 | /// of the progressbar via progressbar_finish when finished with the object. 58 | progressbar *progressbar_new(const char *label, unsigned long max); 59 | 60 | /// Create a new progressbar with the specified label, number of steps, and format string. 61 | /// 62 | /// @param label The label that will prefix the progressbar. 63 | /// @param max The number of times the progressbar must be incremented before it is considered complete, 64 | /// or, in other words, the number of tasks that this progressbar is tracking. 65 | /// @param format The format of the progressbar. The string provided must be three characters, and it will 66 | /// be interpretted with the first character as the left border of the bar, the second 67 | /// character of the bar and the third character as the right border of the bar. For example, 68 | /// "<->" would result in a bar formatted like "<------ >". 69 | /// 70 | /// @return A progressbar configured with the provided arguments. Note that the user is responsible for disposing 71 | /// of the progressbar via progressbar_finish when finished with the object. 72 | progressbar *progressbar_new_with_format(const char *label, unsigned long max, const char *format); 73 | 74 | /// Free an existing progress bar. Don't call this directly; call *progressbar_finish* instead. 75 | void progressbar_free(progressbar *bar); 76 | 77 | /// Increment the given progressbar. Don't increment past the initialized # of steps, though. 78 | void progressbar_inc(progressbar *bar); 79 | 80 | /// Set the current status on the given progressbar. 81 | void progressbar_update(progressbar *bar, unsigned long value); 82 | 83 | /// Set the label of the progressbar. Note that no rendering is done. The label is simply set so that the next 84 | /// rendering will use the new label. To immediately see the new label, call progressbar_draw. 85 | /// Does not update display or copy the label 86 | void progressbar_update_label(progressbar *bar, const char *label); 87 | 88 | /// Finalize (and free!) a progressbar. Call this when you're done, or if you break out 89 | /// partway through. 90 | void progressbar_finish(progressbar *bar); 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /src/plugin-engine.vala: -------------------------------------------------------------------------------- 1 | errordomain PluginError { 2 | UNKNOWN_PLUGIN, 3 | LOADING_FAILED 4 | } 5 | 6 | class PluginEngine : Object { 7 | [Compact] 8 | class Plugin { 9 | public unowned Peas.PluginInfo info; 10 | public List extensions; 11 | 12 | public Plugin (Peas.PluginInfo info) { 13 | this.info = info; 14 | } 15 | } 16 | 17 | class PluginTable { 18 | HashTable plugins; 19 | 20 | static string get_key (Peas.PluginInfo info) { 21 | return info.get_name (); 22 | } 23 | 24 | public bool has_name (string name) { 25 | return name in plugins; 26 | } 27 | 28 | public bool contains (Peas.PluginInfo info) { 29 | return has_name (get_key (info)); 30 | } 31 | 32 | public unowned Plugin get_for_name (string name) 33 | requires (has_name (name)) 34 | { 35 | return plugins[name]; 36 | } 37 | 38 | public unowned Plugin @get (Peas.PluginInfo info) 39 | requires (contains (info)) 40 | { 41 | return this.get_for_name (get_key (info)); 42 | } 43 | 44 | public void add (Peas.PluginInfo info) { 45 | if (info in this) { 46 | warn_if_fail (this[info].info == info); 47 | return; 48 | } 49 | 50 | plugins[get_key (info)] = new Plugin (info); 51 | } 52 | 53 | public void remove (Peas.PluginInfo info) 54 | requires (contains (info)) 55 | { 56 | warn_if_fail (this[info].extensions.length () == 0); 57 | plugins.remove (get_key (info)); 58 | } 59 | 60 | public PluginTable () { 61 | plugins = new HashTable (str_hash, str_equal); 62 | } 63 | } 64 | 65 | Peas.Engine engine; 66 | Peas.ExtensionSet extension_set; 67 | PluginTable plugins; 68 | 69 | public void add_search_path (string module_dir, string? data_dir = null) { 70 | engine.add_search_path (module_dir, data_dir); 71 | } 72 | 73 | public void prepend_search_path ( 74 | string module_dir, 75 | string? data_dir = null 76 | ) { 77 | engine.prepend_search_path (module_dir, data_dir); 78 | } 79 | 80 | public new unowned List @get (string plugin_name) throws PluginError { 81 | if (!plugins.has_name (plugin_name)) { 82 | unowned Peas.PluginInfo? info = 83 | engine.get_plugin_info (plugin_name); 84 | 85 | if (info == null) 86 | throw new PluginError.UNKNOWN_PLUGIN ( 87 | "Unknown plugin '%s'", plugin_name 88 | ); 89 | 90 | plugins.add ((!) info); 91 | } 92 | 93 | unowned Plugin plugin = plugins.get_for_name (plugin_name); 94 | 95 | if (!plugin.info.is_loaded () && !engine.try_load_plugin (plugin.info)) 96 | { 97 | try { 98 | plugin.info.is_available (); 99 | return_val_if_reached (null); // above should throw 100 | } catch (Error e) { 101 | if (e is Peas.PluginInfoError) 102 | throw new PluginError.LOADING_FAILED (e.message); 103 | return_val_if_reached (null); 104 | } 105 | } 106 | 107 | return plugin.extensions; 108 | } 109 | 110 | public unowned List get_all () { 111 | return engine.get_plugin_list (); 112 | } 113 | 114 | public PluginEngine () 115 | requires (typeof (T).is_a (typeof (Object))) 116 | requires (typeof (T).is_interface ()) 117 | { 118 | engine = new Peas.Engine.with_nonglobal_loaders (); 119 | extension_set = new Peas.ExtensionSet (engine, typeof (T)); 120 | plugins = new PluginTable (); 121 | 122 | extension_set.extension_added.connect ((info, extension) => { 123 | plugins.add (info); 124 | plugins[info].extensions.append (extension); 125 | }); 126 | 127 | extension_set.extension_removed.connect ((info, extension) => { 128 | if (!plugins.contains (info)) 129 | return; 130 | 131 | plugins[info].extensions.remove_all (extension); 132 | 133 | if (plugins[info].extensions.length () == 0) 134 | plugins.remove (info); 135 | }); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/transfer.vala: -------------------------------------------------------------------------------- 1 | enum TransferStatus { 2 | STOPPED, 3 | DOWNLOADING, 4 | VERIFYING, 5 | REDOWNLOADING; 6 | 7 | public string to_string () { 8 | switch (this) { 9 | case STOPPED: 10 | return "Stopped"; 11 | 12 | case DOWNLOADING: 13 | return "Downloading"; 14 | 15 | case VERIFYING: 16 | return "Verifying"; 17 | 18 | case REDOWNLOADING: 19 | return "Redownloading (CRC mismatch)"; 20 | 21 | default: 22 | assert_not_reached (); 23 | } 24 | } 25 | } 26 | 27 | class Transfer : Object { 28 | public SpiDump.DeviceIOStream device {construct; get;} 29 | public TransferStatus status {private set; get;} 30 | 31 | public uint32 bytes_read {private set; get;} 32 | public uint32 read_count {private set; get;} 33 | public uint32 checksum_fails {private set; get;} 34 | 35 | public async void write (OutputStream file, uint32 num_bytes) 36 | throws Error 37 | { 38 | try { 39 | var byte = new uint8[1]; 40 | 41 | while (bytes_read < num_bytes) { 42 | status = TransferStatus.DOWNLOADING; 43 | 44 | assert (bytes_read < MAX_SPI_READ); 45 | 46 | // 0x03: Read array opcode 47 | // address bytes are big-endian 48 | uint8[4] send_buffer = { 49 | 0x03, 50 | (uint8) (bytes_read >> 16 & 0xFF), 51 | (uint8) (bytes_read >> 8 & 0xFF), 52 | (uint8) (bytes_read & 0xFF) 53 | }; 54 | 55 | // we don't have to escape 0xFF in send_buffer since there 56 | // shouldn't ever be an 0xFF byte in the address 57 | 58 | var buffer = new uint8[ 59 | uint32.min(2048, num_bytes - bytes_read) 60 | ]; 61 | ulong checksum = 0; 62 | 63 | while (true) { 64 | yield device.set_chip_select (SpiDump.PinState.LOW); 65 | 66 | device.out.write_async.begin (send_buffer); 67 | yield device.in.skip (send_buffer.length); 68 | 69 | for (var i = 0; i < buffer.length; i++) { 70 | device.out.write_async.begin ({0x00}); 71 | yield device.in.read_all (byte); 72 | buffer[i] = byte[0]; 73 | } 74 | 75 | yield device.set_chip_select (SpiDump.PinState.HIGH); 76 | 77 | read_count++; 78 | 79 | var current_checksum = 80 | ZLib.Utility.crc32 (ZLib.Utility.crc32 (), buffer); 81 | 82 | if (checksum == 0) { 83 | checksum = current_checksum; 84 | status = TransferStatus.VERIFYING; 85 | 86 | } else if (current_checksum == checksum) { 87 | break; 88 | 89 | } else { 90 | checksum_fails++; 91 | checksum = 0; 92 | status = TransferStatus.REDOWNLOADING; 93 | } 94 | } 95 | 96 | bytes_read += buffer.length; 97 | file.write_bytes_async.begin (new Bytes.take (buffer)); 98 | } 99 | 100 | } catch (Error e) { 101 | throw e; 102 | } finally { 103 | // finally code in a different function so we don't overwrite this 104 | // function's GError 105 | yield transfer_cleanup (file); 106 | status = TransferStatus.STOPPED; 107 | } 108 | } 109 | 110 | async void transfer_cleanup (OutputStream stream) { 111 | try { 112 | yield device.set_chip_select (SpiDump.PinState.HIGH); 113 | } catch (Error e) { 114 | warning ("Failed toggling CS pin: %s", e.message); 115 | } 116 | 117 | while (stream.has_pending ()) { 118 | Idle.add (transfer_cleanup.callback); 119 | yield; 120 | } 121 | 122 | try { 123 | yield stream.flush_async (); 124 | } catch (Error e) { 125 | warning ("Failed to flush data to disk: %s", e.message); 126 | } 127 | } 128 | 129 | public Transfer (SpiDump.DeviceIOStream device) { 130 | Object (device: device); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/spi-dump.bup.vala: -------------------------------------------------------------------------------- 1 | [CCode (cname = "G_OPTION_REMAINING")] 2 | extern const string OPTION_REMAINING; 3 | 4 | extern const string PLUGINDIR; 5 | 6 | [NoReturn] 7 | [PrintfFormat] 8 | void error(string message, ...) { 9 | stderr.printf("** ERROR: %s\n", message.vprintf(va_list())); 10 | Posix.exit(Posix.EXIT_FAILURE); 11 | } 12 | 13 | class SpiDump : Application { 14 | int64 num_bytes = 128; 15 | string output_path = "eeprom.bin"; 16 | bool force = false; 17 | 18 | [CCode (array_null_terminated = true)] 19 | string[] tty_path = {}; 20 | 21 | internal override void activate() { 22 | // we use a 64 bit int to make dealing with GLib's command line 23 | // parser a little easier, since it only supports signed values 24 | if (num_bytes > 0xFFFFFF) 25 | error(@"Can't read more than $(0xFFFFFF) bytes over SPI"); 26 | else if (num_bytes < 1) 27 | error("-n must be greater than 0"); 28 | 29 | if (tty_path.length < 1) 30 | error("You must provide the TTY to open"); 31 | if (tty_path.length > 1) 32 | error("Please provide only one TTY path"); 33 | 34 | TTY tty; 35 | try { 36 | tty = new TTY(tty_path[0]); 37 | } catch (IOError e) { 38 | error(e.message); 39 | } 40 | 41 | var output_file = File.new_for_commandline_arg(output_path); 42 | 43 | bool can_overwrite; 44 | if (!(can_overwrite = force || !output_file.query_exists())) { 45 | FileInfo info; 46 | try { 47 | info = output_file.query_info(FileAttribute.STANDARD_SIZE, 0); 48 | } catch (Error e) { 49 | error("Cannot access '%s': %s", output_path, e.message); 50 | } 51 | if (info.get_size() == 0) 52 | can_overwrite = true; 53 | else 54 | can_overwrite = false; 55 | } 56 | if (!can_overwrite) 57 | error("File '%s' exists and is non-empty. Use --force to overwrite", 58 | output_path); 59 | 60 | OutputStream stream; 61 | try { 62 | stream = new BufferedOutputStream( 63 | output_file.replace(null, false, 0)); 64 | } catch (Error e) { 65 | error("Failed to create '%s': %s", output_path, e.message); 66 | } 67 | 68 | var num_bytes_truncated = (uint32) (num_bytes & 0xFFFFFFF); 69 | 70 | var transfer = new Transfer(tty); 71 | var progress = new ProgressBar("", num_bytes_truncated); 72 | 73 | transfer.notify["bytes-read"].connect( 74 | () => progress.update(transfer.bytes_read)); 75 | transfer.notify["status"].connect( 76 | () => progress.update_label(transfer.status.to_string())); 77 | 78 | this.hold(); 79 | transfer.do_transfer.begin(stream, num_bytes_truncated, (obj, res) => { 80 | try { 81 | transfer.do_transfer.end(res); 82 | 83 | var seconds = time_t() - progress.start; 84 | stderr.printf("\nDone! (%.0fm%02.0fs)\n", 85 | Math.floor(seconds / 60), seconds % 60); 86 | 87 | stderr.printf( 88 | "Read %u byte%s in %u read%s, including %u retr%s\n", 89 | transfer.bytes_read, transfer.bytes_read == 1 ? "" : "s", 90 | transfer.read_count, transfer.read_count == 1 ? "" : "s", 91 | transfer.checksum_fails, 92 | transfer.checksum_fails == 1 ? "y" : "ies"); 93 | } catch (Error e) { 94 | warning(e.message); 95 | } 96 | this.release(); 97 | }); 98 | } 99 | 100 | SpiDump() { 101 | Object(flags: ApplicationFlags.NON_UNIQUE); 102 | 103 | var opts = new OptionEntry[5]; 104 | // hard-code "128" since some sort of buffer overrun was happening 105 | opts[0] = {"num", 'n', 0, OptionArg.INT64, ref num_bytes, 106 | "Number of bytes to read from the tty", "128"}; 107 | opts[1] = {"output", 'o', 0, OptionArg.FILENAME, ref output_path, 108 | "Output file path", output_path}; 109 | opts[2] = {"force", 'f', 0, OptionArg.NONE, ref force, 110 | "Overwrite output file"}; 111 | opts[3] = {OPTION_REMAINING, 0, 0, OptionArg.FILENAME_ARRAY, 112 | ref tty_path, "", "TTY"}; 113 | opts[4] = {(string) null}; 114 | this.add_main_option_entries(opts); 115 | } 116 | 117 | public static int main(string[] args) { 118 | return new SpiDump().run(args); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/libplugin/libspi-dump-plugin.vala: -------------------------------------------------------------------------------- 1 | namespace SpiDump { 2 | public enum PinState { 3 | LOW, HIGH 4 | } 5 | 6 | public errordomain HardwarePluginError { 7 | INVALID_ARGS 8 | } 9 | 10 | public interface DeviceInputStream : InputStream { 11 | public new async void read_all (uint8[] buffer) throws Error { 12 | yield this.read_all_async (buffer, Priority.DEFAULT, null, null); 13 | } 14 | 15 | public async uint8 read_byte () throws Error { 16 | var ret = new uint8[1]; 17 | yield read_all (ret); 18 | return ret[0]; 19 | } 20 | 21 | public async void skip (ssize_t length) throws IOError { 22 | yield this.skip_async (length); 23 | } 24 | } 25 | 26 | public class SimpleDeviceInputStream : InputStream, DeviceInputStream { 27 | public InputStream inner {construct; get;} 28 | 29 | public override bool close (Cancellable? cancellable = null) 30 | throws IOError 31 | { 32 | return inner.close (cancellable); 33 | } 34 | 35 | public override async bool close_async ( 36 | int io_priority = Priority.DEFAULT, 37 | Cancellable? cancellable = null 38 | ) 39 | throws IOError 40 | { 41 | return yield inner.close_async (); 42 | } 43 | 44 | public override ssize_t skip ( 45 | size_t count, 46 | Cancellable? cancellable = null 47 | ) 48 | throws IOError 49 | { 50 | return inner.skip (count, cancellable); 51 | } 52 | 53 | public override async ssize_t skip_async ( 54 | size_t count, 55 | int io_priority = Priority.DEFAULT, 56 | Cancellable? cancellable = null 57 | ) 58 | throws IOError 59 | { 60 | return yield inner.skip_async (count, io_priority, cancellable); 61 | } 62 | 63 | public override ssize_t read ( 64 | uint8[] buffer, 65 | Cancellable? cancellable = null 66 | ) 67 | throws IOError 68 | { 69 | return inner.read (buffer, cancellable); 70 | } 71 | 72 | public override async ssize_t read_async ( 73 | uint8[]? buffer, 74 | int io_priority = Priority.DEFAULT, 75 | Cancellable? cancellable = null 76 | ) 77 | throws IOError 78 | { 79 | return yield inner.read_async (buffer, io_priority, cancellable); 80 | } 81 | 82 | public SimpleDeviceInputStream (InputStream inner) { 83 | Object (inner: inner); 84 | } 85 | } 86 | 87 | public interface DeviceOutputStream : OutputStream { 88 | public new async void write_all (uint8[] buffer) throws Error { 89 | yield this.write_all_async (buffer, Priority.DEFAULT, null, null); 90 | } 91 | } 92 | 93 | public class SimpleDeviceOutputStream : OutputStream, DeviceOutputStream { 94 | public OutputStream inner {construct; get;} 95 | 96 | public override bool close (Cancellable? cancellable = null) 97 | throws IOError 98 | { 99 | return inner.close (cancellable); 100 | } 101 | 102 | public override async bool close_async ( 103 | int io_priority = Priority.DEFAULT, 104 | Cancellable? cancellable = null 105 | ) 106 | throws IOError 107 | { 108 | return yield inner.close_async (); 109 | } 110 | 111 | public override bool flush (Cancellable? cancellable = null) 112 | throws Error 113 | { 114 | return inner.flush (cancellable); 115 | } 116 | 117 | public override async bool flush_async ( 118 | int io_priority = Priority.DEFAULT, 119 | Cancellable? cancellable = null 120 | ) 121 | throws Error 122 | { 123 | return yield inner.flush_async (io_priority, cancellable); 124 | } 125 | 126 | public override ssize_t write ( 127 | uint8[] buffer, 128 | Cancellable? cancellable = null 129 | ) 130 | throws IOError 131 | { 132 | return inner.write (buffer, cancellable); 133 | } 134 | 135 | public override async ssize_t write_async ( 136 | uint8[]? buffer, 137 | int io_priority = Priority.DEFAULT, 138 | Cancellable? cancellable = null 139 | ) 140 | throws IOError 141 | { 142 | return yield inner.write_async (buffer, io_priority, cancellable); 143 | } 144 | 145 | public SimpleDeviceOutputStream (OutputStream inner) { 146 | Object (inner: inner); 147 | } 148 | } 149 | 150 | public abstract class DeviceIOStream : Object { 151 | public DeviceInputStream @in {construct; get;} 152 | public DeviceOutputStream @out {construct; get;} 153 | 154 | public abstract async void set_chip_select (PinState state) 155 | throws Error; 156 | } 157 | 158 | public interface HardwarePlugin : Object { 159 | [CCode (array_length = false, array_null_terminated = true)] 160 | public abstract OptionEntry[] get_options (); 161 | public abstract DeviceIOStream open () throws Error; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | spi-dump 2 | ======== 3 | 4 | spi-dump is a commandline utility for dumping SPI EEPROMs, using an Arduino as a 5 | bridge between a console and SPI bus. 6 | 7 | ![](dumping.jpg) 8 | 9 | There are quite a few quick tutorials and code snippets floating around 10 | demonstrating how to use an Arduino to interface with SPI EEPROMs, but all that 11 | I've come across implement the majority of the logic on the Arduino side. I 12 | found this to be problematic for a couple of reasons: 13 | 14 | * **Arduinos are difficult to debug**: If your sketch crashes, it can be 15 | non-trivial to work out why. This can be particularly frustrating when 16 | implementing extra functionality. 17 | 18 | * **Many cheaper Arduinos have pretty extreme resource constraints**: When 19 | trying to extend several of the more popular code snippets, my off-brand 20 | board soft-locked regularly. The more host resources you can use, the better. 21 | 22 | With spi-dump, the Arduino serves only as a dumb bridge; the amount of code 23 | needed to drive it is minimal. This allows the added convenience of the host's 24 | friendlier development environment and vastly greater resources to be leveraged 25 | in the implementation of some handy features: 26 | 27 | ### Checksumming 28 | 29 | In-system programming often yields sub-optimal reads, making the creation of 30 | large EEPROM dumps next to impossible. This is the killer feature I really 31 | needed, and similarly the reason this program exists. 32 | 33 | The way this is implemented isn't exactly efficient, however: The redundancy 34 | comes from performing every array read twice. As such, checksumming cuts an 35 | already bitterly slow transfer speed in half. This seems to be a necessary cost, 36 | since any bit in the stream could potentially be flipped. There are a couple of 37 | ways this could be improved in the future though: 38 | 39 | * Currently, spi-dump uses opcode 0x03 to perform reads since it and its 40 | parameters seem to be reasonably universal. However, most EEPROMs define 41 | vendor-specific opcodes which allow reading data at a higher rate. Attempting 42 | to leverage this will be a challenge, but it should be possible. 43 | 44 | * A commandline switch to disable checksumming would probably be a good idea. 45 | 46 | ### Progress metering 47 | 48 | With the host computer in the driver's seat, keeping track of where in the 49 | transfer we're up to and working out roughly how long we have left is a little 50 | easier. As such, spi-dump provides a progress meter with the standard bells and 51 | whistles to tell you that, yes, that transfer really is going to take three 52 | hours. 53 | 54 | The progress meter is done using an in-tree copy of 55 | https://github.com/doches/progressbar 56 | 57 | ## "How do I use this?" 58 | 59 | 1. Flash `spi-dump.ino` to your Arduino and reset it 60 | 2. Install spi-dump: 61 | ``` 62 | sudo dnf install glib2-devel 63 | ./autogen.sh 64 | sudo make install 65 | ``` 66 | 3. You're ready to go! 67 | ``` 68 | spi-dump -o my_dump.bin -n 0xffff /dev/ttyUSB0 69 | ``` 70 | 71 | ### Testing 72 | 73 | If you want to mess with things without working on real hardware, there's a test 74 | application that mocks the Arduino: 75 | 76 | ``` 77 | make check 78 | test/mock-arduino 79 | ``` 80 | 81 | This will print out a PTY path that you can then use with spi-dump. 82 | 83 | ## "This is broken" 84 | 85 | Some stuff to be weary of: 86 | 87 | * Most EEPROM datasheets I've read outline opcodes whose purpose is to wipe the 88 | entire chip, and often they're only a bitflip away from more useful ones. 89 | Having had several stomach-sinking close calls in the development of this 90 | tool, I have some advice: read the datasheet carefully, quintuple check your 91 | wiring and be sure spi-dump isn't going to accidentally nuke your data. 92 | 93 | * Something that frustrated me for quite some time were issues of the host 94 | machine and the Arduino getting out of sync. If spi-dump appears to have hung 95 | and the transfer lights aren't flashing, this is probably your problem. It 96 | took me a while to work out that [DTR][dtr] will cause an Arduino reset and 97 | this problem along with it, but this [can be fixed][reset fix]. 98 | 99 | * I'm by no means an expert, so this program may or may not eat your babies. If 100 | your offspring are indeed offered as sacrifice to the Dark Lord, however, a 101 | bug report would be much appreciated. 102 | 103 | [dtr]: https://en.wikipedia.org/wiki/Data_Terminal_Ready 104 | [reset fix]: http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection 105 | 106 | ## "What's so special about `0xff`?" 107 | 108 | For the most part, SPI and RS-232 are pretty compatible. Data in, data out, 109 | that's no problem. But the extra pins, usually required to operate an EEPROM, 110 | don't map so conveniently. So spi-dump (and the Arduino sketch it comes with) 111 | implement a sort of mini-protocol. Basically, `0xff` serves like an escape 112 | opcode; the next byte the Arduino receives should be interpreted as a command 113 | for the Arduino itself, rather than being forwarded onto the SPI bus. For 114 | example, pulling the chip select pin low might go something like this: 115 | 116 | 1. spi-dump sends `0xff 0x01` (escape command, pull low command) 117 | 2. As an acknowledgement, the Arduino will reply with `0xfe` (`0x01` ⊕ 118 | `0xff`) 119 | 120 | That's all there is to it. 121 | 122 | I hate to be that guy, but if you want more detail then the source really is the 123 | best place to find it. 124 | 125 | ## "Goddamn, this README is _long_" 126 | 127 | Yes. Yes it is. 128 | -------------------------------------------------------------------------------- /src/progressbar/progressbar.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \author Trevor Fountain 4 | * \author Johannes Buchner 5 | * \author Erik Garrison 6 | * \date 2010-2014 7 | * \copyright BSD 3-Clause 8 | * 9 | * progressbar -- a C class (by convention) for displaying progress 10 | * on the command line (to stderr). 11 | */ 12 | 13 | #include /* tgetent, tgetnum */ 14 | #include 15 | #include 16 | #include "progressbar.h" 17 | 18 | /// How wide we assume the screen is if termcap fails. 19 | enum { DEFAULT_SCREEN_WIDTH = 80 }; 20 | /// The smallest that the bar can ever be (not including borders) 21 | enum { MINIMUM_BAR_WIDTH = 10 }; 22 | /// The format in which the estimated remaining time will be reported 23 | static const char *const ETA_FORMAT = "ETA:%2dh%02dm%02ds"; 24 | /// The maximum number of characters that the ETA_FORMAT can ever yield 25 | enum { ETA_FORMAT_LENGTH = 13 }; 26 | /// Amount of screen width taken up by whitespace (i.e. whitespace between label/bar/ETA components) 27 | enum { WHITESPACE_LENGTH = 2 }; 28 | /// The amount of width taken up by the border of the bar component. 29 | enum { BAR_BORDER_WIDTH = 2 }; 30 | 31 | /// Models a duration of time broken into hour/minute/second components. The number of seconds should be less than the 32 | /// number of seconds in one minute, and the number of minutes should be less than the number of minutes in one hour. 33 | typedef struct { 34 | int hours; 35 | int minutes; 36 | int seconds; 37 | } progressbar_time_components; 38 | 39 | static void progressbar_draw(const progressbar *bar); 40 | 41 | /** 42 | * Create a new progress bar with the specified label, max number of steps, and format string. 43 | * Note that `format` must be exactly three characters long, e.g. "<->" to render a progress 44 | * bar like "<---------->". Returns NULL if there isn't enough memory to allocate a progressbar 45 | */ 46 | progressbar *progressbar_new_with_format(const char *label, unsigned long max, const char *format) 47 | { 48 | progressbar *new = malloc(sizeof(progressbar)); 49 | if(new == NULL) { 50 | return NULL; 51 | } 52 | 53 | new->max = max; 54 | new->value = 0; 55 | new->start = time(NULL); 56 | assert(3 == strlen(format) && "format must be 3 characters in length"); 57 | new->format.begin = format[0]; 58 | new->format.fill = format[1]; 59 | new->format.end = format[2]; 60 | 61 | progressbar_update_label(new, label); 62 | progressbar_draw(new); 63 | 64 | return new; 65 | } 66 | 67 | /** 68 | * Create a new progress bar with the specified label and max number of steps. 69 | */ 70 | progressbar *progressbar_new(const char *label, unsigned long max) 71 | { 72 | return progressbar_new_with_format(label, max, "|=|"); 73 | } 74 | 75 | void progressbar_update_label(progressbar *bar, const char *label) 76 | { 77 | bar->label = label; 78 | progressbar_draw(bar); 79 | } 80 | 81 | /** 82 | * Delete an existing progress bar. 83 | */ 84 | void progressbar_free(progressbar *bar) 85 | { 86 | free(bar); 87 | } 88 | 89 | /** 90 | * Increment an existing progressbar by `value` steps. 91 | */ 92 | void progressbar_update(progressbar *bar, unsigned long value) 93 | { 94 | bar->value = value; 95 | progressbar_draw(bar); 96 | } 97 | 98 | /** 99 | * Increment an existing progressbar by a single step. 100 | */ 101 | void progressbar_inc(progressbar *bar) 102 | { 103 | progressbar_update(bar, bar->value+1); 104 | } 105 | 106 | static void progressbar_write_char(FILE *file, const int ch, const size_t times) { 107 | size_t i; 108 | for (i = 0; i < times; ++i) { 109 | fputc(ch, file); 110 | } 111 | } 112 | 113 | static int progressbar_max(int x, int y) { 114 | return x > y ? x : y; 115 | } 116 | 117 | static unsigned int get_screen_width(void) { 118 | char termbuf[2048]; 119 | if (tgetent(termbuf, getenv("TERM")) >= 0) { 120 | return tgetnum("co") /* -2 */; 121 | } else { 122 | return DEFAULT_SCREEN_WIDTH; 123 | } 124 | } 125 | 126 | static int progressbar_bar_width(int screen_width, int label_length) { 127 | return progressbar_max(MINIMUM_BAR_WIDTH, screen_width - label_length - ETA_FORMAT_LENGTH - WHITESPACE_LENGTH); 128 | } 129 | 130 | static int progressbar_label_width(int screen_width, int label_length, int bar_width) { 131 | int eta_width = ETA_FORMAT_LENGTH; 132 | 133 | // If the progressbar is too wide to fit on the screen, we must sacrifice the label. 134 | if (label_length + 1 + bar_width + 1 + ETA_FORMAT_LENGTH > screen_width) { 135 | return progressbar_max(0, screen_width - bar_width - eta_width - WHITESPACE_LENGTH); 136 | } else { 137 | return label_length; 138 | } 139 | } 140 | 141 | static int progressbar_remaining_seconds(const progressbar* bar) { 142 | double offset = difftime(time(NULL), bar->start); 143 | if (bar->value > 0 && offset > 0) { 144 | return (offset / (double) bar->value) * (bar->max - bar->value); 145 | } else { 146 | return 0; 147 | } 148 | } 149 | 150 | static progressbar_time_components progressbar_calc_time_components(int seconds) { 151 | int hours = seconds / 3600; 152 | seconds -= hours * 3600; 153 | int minutes = seconds / 60; 154 | seconds -= minutes * 60; 155 | 156 | progressbar_time_components components = {hours, minutes, seconds}; 157 | return components; 158 | } 159 | 160 | static void progressbar_draw(const progressbar *bar) 161 | { 162 | int screen_width = get_screen_width(); 163 | int label_length = strlen(bar->label); 164 | int bar_width = progressbar_bar_width(screen_width, label_length); 165 | int label_width = progressbar_label_width(screen_width, label_length, bar_width); 166 | 167 | int progressbar_completed = (bar->value >= bar->max); 168 | int bar_piece_count = bar_width - BAR_BORDER_WIDTH; 169 | int bar_piece_current = (progressbar_completed) 170 | ? bar_piece_count 171 | : bar_piece_count * ((double) bar->value / bar->max); 172 | 173 | progressbar_time_components eta = (progressbar_completed) 174 | ? progressbar_calc_time_components(difftime(time(NULL), bar->start)) 175 | : progressbar_calc_time_components(progressbar_remaining_seconds(bar)); 176 | 177 | if (label_width == 0) { 178 | // The label would usually have a trailing space, but in the case that we don't print 179 | // a label, the bar can use that space instead. 180 | bar_width += 1; 181 | } else { 182 | // Draw the label 183 | fwrite(bar->label, 1, label_width, stderr); 184 | fputc(' ', stderr); 185 | } 186 | 187 | // Draw the progressbar 188 | fputc(bar->format.begin, stderr); 189 | progressbar_write_char(stderr, bar->format.fill, bar_piece_current); 190 | progressbar_write_char(stderr, ' ', bar_piece_count - bar_piece_current); 191 | fputc(bar->format.end, stderr); 192 | 193 | // Draw the ETA 194 | fputc(' ', stderr); 195 | fprintf(stderr, ETA_FORMAT, eta.hours, eta.minutes, eta.seconds); 196 | fputc('\r', stderr); 197 | } 198 | 199 | /** 200 | * Finish a progressbar, indicating 100% completion, and free it. 201 | */ 202 | void progressbar_finish(progressbar *bar) 203 | { 204 | // Make sure we fill the progressbar so things look complete. 205 | progressbar_draw(bar); 206 | 207 | // Print a newline, so that future outputs to stderr look prettier 208 | fprintf(stderr, "\n"); 209 | 210 | // We've finished with this progressbar, so go ahead and free it. 211 | progressbar_free(bar); 212 | } 213 | -------------------------------------------------------------------------------- /src/spi-dump.vala: -------------------------------------------------------------------------------- 1 | [CCode (cname = "G_OPTION_REMAINING")] 2 | extern const string OPTION_REMAINING; 3 | 4 | extern const string PLUGINDIR; 5 | 6 | const string PLUGIN_PATH_ENV = "SPI_DUMP_PLUGIN_PATH"; 7 | const int64 MAX_SPI_READ = (1 << 24) - 1; 8 | 9 | [NoReturn] 10 | [PrintfFormat] 11 | void error (string message, ...) { 12 | stderr.printf ("** ERROR: %s\n", message.vprintf (va_list ())); 13 | Posix.exit (Posix.EXIT_FAILURE); 14 | } 15 | 16 | SpiDump.HardwarePlugin extension; 17 | [CCode (array_length = false, array_null_terminated = true)] 18 | string[] filenames; 19 | 20 | public int main (string[] args) { 21 | var args_copy = args; 22 | 23 | string? plugin_path = null; 24 | string cable = ""; 25 | int64 num_bytes = 128; 26 | bool force = false; 27 | 28 | var option_context = new OptionContext ("OUTPUT-FILE"); 29 | option_context.set_help_enabled (false); 30 | option_context.set_ignore_unknown_options (true); 31 | 32 | option_context.add_main_entries ({ 33 | OptionEntry () { 34 | long_name = "cable", 35 | short_name = 'c', 36 | arg = OptionArg.STRING, 37 | arg_data = &cable, 38 | description = "The cable type to use. " 39 | + "Specify '?' to list supported cables", 40 | arg_description = "CABLE" 41 | }, 42 | 43 | OptionEntry () { 44 | long_name = "plugin-path", 45 | arg = OptionArg.STRING, 46 | arg_data = &plugin_path, 47 | description = "Path to cable plugins", 48 | arg_description = "PATH" 49 | }, 50 | 51 | OptionEntry () { 52 | long_name = "num", 53 | short_name = 'n', 54 | arg = OptionArg.INT64, 55 | arg_data = &num_bytes, 56 | description = "Number of bytes to read from the device", 57 | arg_description = "128" 58 | }, 59 | 60 | OptionEntry () { 61 | long_name = "force", 62 | arg_data = &force, 63 | description = "Overwrite output file" 64 | } 65 | }, null); 66 | 67 | try { 68 | option_context.parse_strv (ref args_copy); 69 | } catch (OptionError e) { 70 | error (e.message); 71 | } 72 | 73 | var plugins = new PluginEngine (); 74 | plugins.add_search_path (PLUGINDIR); 75 | plugins.prepend_search_path ( 76 | Path.build_filename (Environment.get_home_dir (), ".local", "lib", 77 | "spi-dump", "plugins") 78 | ); 79 | 80 | if (plugin_path != null) 81 | plugins.prepend_search_path ( 82 | Path.build_filename (Environment.get_current_dir (), 83 | (!) plugin_path) 84 | ); 85 | 86 | if (Environment.get_variable (PLUGIN_PATH_ENV) != null) 87 | plugins.prepend_search_path ( 88 | (!) Environment.get_variable (PLUGIN_PATH_ENV) 89 | ); 90 | 91 | switch (cable) { 92 | case "?": 93 | stderr.printf ("Known cables:\n"); 94 | 95 | foreach (unowned Peas.PluginInfo plugin in plugins.get_all ()) 96 | stderr.printf (" %s\t%s\n", plugin.get_name (), 97 | plugin.get_description ()); 98 | 99 | return 0; 100 | 101 | case "": 102 | break; 103 | 104 | default: 105 | unowned List extensions; 106 | try { 107 | extensions = plugins[cable]; 108 | } catch (PluginError e) { 109 | error ("Failed to load cable plugin: %s", e.message); 110 | } 111 | 112 | assert (extensions.length () == 1); 113 | extension = extensions.nth_data (0); 114 | 115 | var cable_options = new OptionGroup ( 116 | cable, 117 | @"Options for cable '$cable':", 118 | "Show cable help options" 119 | ); 120 | cable_options.add_entries (extension.get_options ()); 121 | option_context.add_group ((owned) cable_options); 122 | 123 | break; 124 | } 125 | 126 | option_context.set_help_enabled (true); 127 | option_context.set_ignore_unknown_options (false); 128 | 129 | option_context.add_main_entries ({ 130 | OptionEntry () { 131 | long_name = OPTION_REMAINING, 132 | arg = OptionArg.FILENAME_ARRAY, 133 | arg_data = &filenames 134 | } 135 | }, null); 136 | 137 | try { 138 | option_context.parse_strv (ref args_copy); 139 | } catch (OptionError e) { 140 | error (e.message); 141 | } 142 | 143 | if (cable == "") 144 | error ("No cable specified!"); 145 | 146 | assert ((void*) extension != null); 147 | 148 | if (filenames.length == 0) 149 | error ("You must provide a file path to save"); 150 | else if (filenames.length > 1) 151 | error ("Unrecognized extra options"); 152 | 153 | var output_file = File.new_for_commandline_arg (filenames[0]); 154 | 155 | bool can_overwrite; 156 | 157 | if (!(can_overwrite = force || !output_file.query_exists ())) { 158 | FileInfo info; 159 | try { 160 | info = output_file.query_info ( 161 | string.joinv (",", new string?[] { 162 | FileAttribute.STANDARD_SIZE, 163 | FileAttribute.STANDARD_TYPE 164 | }), 165 | FileQueryInfoFlags.NONE 166 | ); 167 | } catch (Error e) { 168 | error ("Cannot access '%s': %s", filenames[0], e.message); 169 | } 170 | 171 | if (info.get_file_type () == FileType.DIRECTORY) 172 | error ("Cannot open file: is a directory"); 173 | 174 | if (info.get_size () == 0) 175 | can_overwrite = true; 176 | else 177 | can_overwrite = false; 178 | } 179 | 180 | if (!can_overwrite) 181 | error ( 182 | "File '%s' exists and is non-empty. Use --force to overwrite", 183 | filenames[0] 184 | ); 185 | 186 | // We use a 64 bit int to make dealing with GLib's command line 187 | // parser a little easier, since it only supports signed values. 188 | if (num_bytes > MAX_SPI_READ) 189 | error (@"Can't read more than %s bytes over SPI", 190 | MAX_SPI_READ.to_string ("0x%lX")); 191 | else if (num_bytes < 1) 192 | error ("-n must be greater than 0"); 193 | 194 | OutputStream file_stream; 195 | try { 196 | file_stream = new BufferedOutputStream ( 197 | output_file.replace (null, false, FileCreateFlags.NONE) 198 | ); 199 | } catch (Error e) { 200 | error ("Failed to create '%s': %s", filenames[0], e.message); 201 | } 202 | 203 | SpiDump.DeviceIOStream device_stream; 204 | try { 205 | device_stream = extension.open (); 206 | } catch (Error e) { 207 | if (e is SpiDump.HardwarePluginError) 208 | error (e.message); 209 | error ("Failed to open device: %s", e.message); 210 | } 211 | 212 | var num_bytes_truncated = (uint32) (num_bytes & MAX_SPI_READ); 213 | 214 | var transfer = new Transfer (device_stream); 215 | var progress = new ProgressBar ("", num_bytes_truncated); 216 | 217 | transfer.notify["bytes-read"].connect ( 218 | () => progress.update (transfer.bytes_read) 219 | ); 220 | 221 | transfer.notify["status"].connect ( 222 | () => progress.update_label (transfer.status.to_string ()) 223 | ); 224 | 225 | var main_loop = new MainLoop (); 226 | 227 | transfer.write.begin (file_stream, num_bytes_truncated, (obj, res) => { 228 | try { 229 | transfer.write.end (res); 230 | } catch (Error e) { 231 | warning (e.message); 232 | main_loop.quit (); 233 | return; 234 | } 235 | 236 | var seconds = time_t () - progress.start; 237 | stderr.printf ("\nDone! (%.0fm%02.0fs)\n", 238 | Math.floor (seconds / 60), seconds % 60); 239 | 240 | stderr.printf ("Read %u byte%s in %u read%s, including %u retr%s\n", 241 | transfer.bytes_read, transfer.bytes_read == 1 ? "" : "s", 242 | transfer.read_count, transfer.read_count == 1 ? "" : "s", 243 | transfer.checksum_fails, 244 | transfer.checksum_fails == 1 ? "y" : "ies"); 245 | 246 | main_loop.quit (); 247 | }); 248 | 249 | main_loop.run (); 250 | 251 | return 0; 252 | } 253 | -------------------------------------------------------------------------------- /git.mk: -------------------------------------------------------------------------------- 1 | # git.mk, a small Makefile to autogenerate .gitignore files 2 | # for autotools-based projects. 3 | # 4 | # Copyright 2009, Red Hat, Inc. 5 | # Copyright 2010,2011,2012,2013 Behdad Esfahbod 6 | # Written by Behdad Esfahbod 7 | # 8 | # Copying and distribution of this file, with or without modification, 9 | # is permitted in any medium without royalty provided the copyright 10 | # notice and this notice are preserved. 11 | # 12 | # The latest version of this file can be downloaded from: 13 | GIT_MK_URL = https://raw.githubusercontent.com/behdad/git.mk/master/git.mk 14 | # 15 | # Bugs, etc, should be reported upstream at: 16 | # https://github.com/behdad/git.mk 17 | # 18 | # To use in your project, import this file in your git repo's toplevel, 19 | # then do "make -f git.mk". This modifies all Makefile.am files in 20 | # your project to -include git.mk. Remember to add that line to new 21 | # Makefile.am files you create in your project, or just rerun the 22 | # "make -f git.mk". 23 | # 24 | # This enables automatic .gitignore generation. If you need to ignore 25 | # more files, add them to the GITIGNOREFILES variable in your Makefile.am. 26 | # But think twice before doing that. If a file has to be in .gitignore, 27 | # chances are very high that it's a generated file and should be in one 28 | # of MOSTLYCLEANFILES, CLEANFILES, DISTCLEANFILES, or MAINTAINERCLEANFILES. 29 | # 30 | # The only case that you need to manually add a file to GITIGNOREFILES is 31 | # when remove files in one of mostlyclean-local, clean-local, distclean-local, 32 | # or maintainer-clean-local make targets. 33 | # 34 | # Note that for files like editor backup, etc, there are better places to 35 | # ignore them. See "man gitignore". 36 | # 37 | # If "make maintainer-clean" removes the files but they are not recognized 38 | # by this script (that is, if "git status" shows untracked files still), send 39 | # me the output of "git status" as well as your Makefile.am and Makefile for 40 | # the directories involved and I'll diagnose. 41 | # 42 | # For a list of toplevel files that should be in MAINTAINERCLEANFILES, see 43 | # Makefile.am.sample in the git.mk git repo. 44 | # 45 | # Don't EXTRA_DIST this file. It is supposed to only live in git clones, 46 | # not tarballs. It serves no useful purpose in tarballs and clutters the 47 | # build dir. 48 | # 49 | # This file knows how to handle autoconf, automake, libtool, gtk-doc, 50 | # gnome-doc-utils, yelp.m4, mallard, intltool, gsettings, dejagnu, appdata, 51 | # appstream, hotdoc. 52 | # 53 | # This makefile provides the following targets: 54 | # 55 | # - all: "make all" will build all gitignore files. 56 | # - gitignore: makes all gitignore files in the current dir and subdirs. 57 | # - .gitignore: make gitignore file for the current dir. 58 | # - gitignore-recurse: makes all gitignore files in the subdirs. 59 | # 60 | # KNOWN ISSUES: 61 | # 62 | # - Recursive configure doesn't work as $(top_srcdir)/git.mk inside the 63 | # submodule doesn't find us. If you have configure.{in,ac} files in 64 | # subdirs, add a proxy git.mk file in those dirs that simply does: 65 | # "include $(top_srcdir)/../git.mk". Add more ..'s to your taste. 66 | # And add those files to git. See vte/gnome-pty-helper/git.mk for 67 | # example. 68 | # 69 | 70 | 71 | 72 | ############################################################################### 73 | # Variables user modules may want to add to toplevel MAINTAINERCLEANFILES: 74 | ############################################################################### 75 | 76 | # 77 | # Most autotools-using modules should be fine including this variable in their 78 | # toplevel MAINTAINERCLEANFILES: 79 | GITIGNORE_MAINTAINERCLEANFILES_TOPLEVEL = \ 80 | $(srcdir)/aclocal.m4 \ 81 | $(srcdir)/autoscan.log \ 82 | $(srcdir)/configure.scan \ 83 | `AUX_DIR=$(srcdir)/$$(cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_AUX_DIR:$$1' ./configure.ac); \ 84 | test "x$$AUX_DIR" = "x$(srcdir)/" && AUX_DIR=$(srcdir); \ 85 | for x in \ 86 | ar-lib \ 87 | compile \ 88 | config.guess \ 89 | config.rpath \ 90 | config.sub \ 91 | depcomp \ 92 | install-sh \ 93 | ltmain.sh \ 94 | missing \ 95 | mkinstalldirs \ 96 | test-driver \ 97 | ylwrap \ 98 | ; do echo "$$AUX_DIR/$$x"; done` \ 99 | `cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_HEADERS:$$1' ./configure.ac | \ 100 | head -n 1 | while read f; do echo "$(srcdir)/$$f.in"; done` 101 | # 102 | # All modules should also be fine including the following variable, which 103 | # removes automake-generated Makefile.in files: 104 | GITIGNORE_MAINTAINERCLEANFILES_MAKEFILE_IN = \ 105 | `cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_FILES:$$1' ./configure.ac | \ 106 | while read f; do \ 107 | case $$f in Makefile|*/Makefile) \ 108 | test -f "$(srcdir)/$$f.am" && echo "$(srcdir)/$$f.in";; esac; \ 109 | done` 110 | # 111 | # Modules that use libtool and use AC_CONFIG_MACRO_DIR() may also include this, 112 | # though it's harmless to include regardless. 113 | GITIGNORE_MAINTAINERCLEANFILES_M4_LIBTOOL = \ 114 | `MACRO_DIR=$(srcdir)/$$(cd $(top_srcdir); $(AUTOCONF) --trace 'AC_CONFIG_MACRO_DIR:$$1' ./configure.ac); \ 115 | if test "x$$MACRO_DIR" != "x$(srcdir)/"; then \ 116 | for x in \ 117 | libtool.m4 \ 118 | ltoptions.m4 \ 119 | ltsugar.m4 \ 120 | ltversion.m4 \ 121 | lt~obsolete.m4 \ 122 | ; do echo "$$MACRO_DIR/$$x"; done; \ 123 | fi` 124 | 125 | 126 | 127 | ############################################################################### 128 | # Default rule is to install ourselves in all Makefile.am files: 129 | ############################################################################### 130 | 131 | git-all: git-mk-install 132 | 133 | git-mk-install: 134 | @echo "Installing git makefile" 135 | @any_failed=; \ 136 | find "`test -z "$(top_srcdir)" && echo . || echo "$(top_srcdir)"`" -name Makefile.am | while read x; do \ 137 | if grep 'include .*/git.mk' $$x >/dev/null; then \ 138 | echo "$$x already includes git.mk"; \ 139 | else \ 140 | failed=; \ 141 | echo "Updating $$x"; \ 142 | { cat $$x; \ 143 | echo ''; \ 144 | echo '-include $$(top_srcdir)/git.mk'; \ 145 | } > $$x.tmp || failed=1; \ 146 | if test x$$failed = x; then \ 147 | mv $$x.tmp $$x || failed=1; \ 148 | fi; \ 149 | if test x$$failed = x; then : else \ 150 | echo "Failed updating $$x"; >&2 \ 151 | any_failed=1; \ 152 | fi; \ 153 | fi; done; test -z "$$any_failed" 154 | 155 | git-mk-update: 156 | wget $(GIT_MK_URL) -O $(top_srcdir)/git.mk 157 | 158 | .PHONY: git-all git-mk-install git-mk-update 159 | 160 | 161 | 162 | ############################################################################### 163 | # Actual .gitignore generation: 164 | ############################################################################### 165 | 166 | $(srcdir)/.gitignore: Makefile.am $(top_srcdir)/git.mk 167 | @echo "git.mk: Generating $@" 168 | @{ \ 169 | if test "x$(DOC_MODULE)" = x -o "x$(DOC_MAIN_SGML_FILE)" = x; then :; else \ 170 | for x in \ 171 | $(DOC_MODULE)-decl-list.txt \ 172 | $(DOC_MODULE)-decl.txt \ 173 | tmpl/$(DOC_MODULE)-unused.sgml \ 174 | "tmpl/*.bak" \ 175 | $(REPORT_FILES) \ 176 | $(DOC_MODULE).pdf \ 177 | xml html \ 178 | ; do echo "/$$x"; done; \ 179 | FLAVOR=$$(cd $(top_srcdir); $(AUTOCONF) --trace 'GTK_DOC_CHECK:$$2' ./configure.ac); \ 180 | case $$FLAVOR in *no-tmpl*) echo /tmpl;; esac; \ 181 | if echo "$(SCAN_OPTIONS)" | grep -q "\-\-rebuild-types"; then \ 182 | echo "/$(DOC_MODULE).types"; \ 183 | fi; \ 184 | if echo "$(SCAN_OPTIONS)" | grep -q "\-\-rebuild-sections"; then \ 185 | echo "/$(DOC_MODULE)-sections.txt"; \ 186 | fi; \ 187 | if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \ 188 | for x in \ 189 | $(SETUP_FILES) \ 190 | $(DOC_MODULE).types \ 191 | ; do echo "/$$x"; done; \ 192 | fi; \ 193 | fi; \ 194 | if test "x$(DOC_MODULE)$(DOC_ID)" = x -o "x$(DOC_LINGUAS)" = x; then :; else \ 195 | for lc in $(DOC_LINGUAS); do \ 196 | for x in \ 197 | $(if $(DOC_MODULE),$(DOC_MODULE).xml) \ 198 | $(DOC_PAGES) \ 199 | $(DOC_INCLUDES) \ 200 | ; do echo "/$$lc/$$x"; done; \ 201 | done; \ 202 | for x in \ 203 | $(_DOC_OMF_ALL) \ 204 | $(_DOC_DSK_ALL) \ 205 | $(_DOC_HTML_ALL) \ 206 | $(_DOC_MOFILES) \ 207 | $(DOC_H_FILE) \ 208 | "*/.xml2po.mo" \ 209 | "*/*.omf.out" \ 210 | ; do echo /$$x; done; \ 211 | fi; \ 212 | if test "x$(HOTDOC)" = x; then :; else \ 213 | $(foreach project, $(HOTDOC_PROJECTS),echo "/$(call HOTDOC_TARGET,$(project))"; \ 214 | echo "/$(shell $(call HOTDOC_PROJECT_COMMAND,$(project)) --get-conf-path output)" ; \ 215 | echo "/$(shell $(call HOTDOC_PROJECT_COMMAND,$(project)) --get-private-folder)" ; \ 216 | ) \ 217 | for x in \ 218 | .hotdoc.d \ 219 | ; do echo "/$$x"; done; \ 220 | fi; \ 221 | if test "x$(HELP_ID)" = x -o "x$(HELP_LINGUAS)" = x; then :; else \ 222 | for lc in $(HELP_LINGUAS); do \ 223 | for x in \ 224 | $(HELP_FILES) \ 225 | "$$lc.stamp" \ 226 | "$$lc.mo" \ 227 | ; do echo "/$$lc/$$x"; done; \ 228 | done; \ 229 | fi; \ 230 | if test "x$(gsettings_SCHEMAS)" = x; then :; else \ 231 | for x in \ 232 | $(gsettings_SCHEMAS:.xml=.valid) \ 233 | $(gsettings__enum_file) \ 234 | ; do echo "/$$x"; done; \ 235 | fi; \ 236 | if test "x$(appdata_XML)" = x; then :; else \ 237 | for x in \ 238 | $(appdata_XML:.xml=.valid) \ 239 | ; do echo "/$$x"; done; \ 240 | fi; \ 241 | if test "x$(appstream_XML)" = x; then :; else \ 242 | for x in \ 243 | $(appstream_XML:.xml=.valid) \ 244 | ; do echo "/$$x"; done; \ 245 | fi; \ 246 | if test -f $(srcdir)/po/Makefile.in.in; then \ 247 | for x in \ 248 | ABOUT-NLS \ 249 | po/Makefile.in.in \ 250 | po/Makefile.in.in~ \ 251 | po/Makefile.in \ 252 | po/Makefile \ 253 | po/Makevars.template \ 254 | po/POTFILES \ 255 | po/Rules-quot \ 256 | po/stamp-it \ 257 | po/stamp-po \ 258 | po/.intltool-merge-cache \ 259 | "po/*.gmo" \ 260 | "po/*.header" \ 261 | "po/*.mo" \ 262 | "po/*.sed" \ 263 | "po/*.sin" \ 264 | po/$(GETTEXT_PACKAGE).pot \ 265 | intltool-extract.in \ 266 | intltool-merge.in \ 267 | intltool-update.in \ 268 | ; do echo "/$$x"; done; \ 269 | fi; \ 270 | if test -f $(srcdir)/configure; then \ 271 | for x in \ 272 | autom4te.cache \ 273 | configure \ 274 | config.h \ 275 | stamp-h1 \ 276 | libtool \ 277 | config.lt \ 278 | ; do echo "/$$x"; done; \ 279 | fi; \ 280 | if test "x$(DEJATOOL)" = x; then :; else \ 281 | for x in \ 282 | $(DEJATOOL) \ 283 | ; do echo "/$$x.sum"; echo "/$$x.log"; done; \ 284 | echo /site.exp; \ 285 | fi; \ 286 | if test "x$(am__dirstamp)" = x; then :; else \ 287 | echo "$(am__dirstamp)"; \ 288 | fi; \ 289 | if test "x$(findstring libtool,$(LTCOMPILE))" = x -a "x$(findstring libtool,$(LTCXXCOMPILE))" = x -a "x$(GTKDOC_RUN)" = x; then :; else \ 290 | for x in \ 291 | "*.lo" \ 292 | ".libs" "_libs" \ 293 | ; do echo "$$x"; done; \ 294 | fi; \ 295 | for x in \ 296 | .gitignore \ 297 | $(GITIGNOREFILES) \ 298 | $(CLEANFILES) \ 299 | $(PROGRAMS) $(check_PROGRAMS) $(EXTRA_PROGRAMS) \ 300 | $(LIBRARIES) $(check_LIBRARIES) $(EXTRA_LIBRARIES) \ 301 | $(LTLIBRARIES) $(check_LTLIBRARIES) $(EXTRA_LTLIBRARIES) \ 302 | so_locations \ 303 | $(MOSTLYCLEANFILES) \ 304 | $(TEST_LOGS) \ 305 | $(TEST_LOGS:.log=.trs) \ 306 | $(TEST_SUITE_LOG) \ 307 | $(TESTS:=.test) \ 308 | "*.gcda" \ 309 | "*.gcno" \ 310 | $(DISTCLEANFILES) \ 311 | $(am__CONFIG_DISTCLEAN_FILES) \ 312 | $(CONFIG_CLEAN_FILES) \ 313 | TAGS ID GTAGS GRTAGS GSYMS GPATH tags \ 314 | "*.tab.c" \ 315 | $(MAINTAINERCLEANFILES) \ 316 | $(BUILT_SOURCES) \ 317 | $(patsubst %.vala,%.c,$(filter %.vala,$(SOURCES))) \ 318 | $(filter %_vala.stamp,$(DIST_COMMON)) \ 319 | $(filter %.vapi,$(DIST_COMMON)) \ 320 | $(filter $(addprefix %,$(notdir $(patsubst %.vapi,%.h,$(filter %.vapi,$(DIST_COMMON))))),$(DIST_COMMON)) \ 321 | Makefile \ 322 | Makefile.in \ 323 | "*.orig" \ 324 | "*.rej" \ 325 | "*.bak" \ 326 | "*~" \ 327 | ".*.sw[nop]" \ 328 | ".dirstamp" \ 329 | ; do echo "/$$x"; done; \ 330 | for x in \ 331 | "*.$(OBJEXT)" \ 332 | $(DEPDIR) \ 333 | ; do echo "$$x"; done; \ 334 | } | \ 335 | sed "s@^/`echo "$(srcdir)" | sed 's/\(.\)/[\1]/g'`/@/@" | \ 336 | sed 's@/[.]/@/@g' | \ 337 | LC_ALL=C sort | uniq > $@.tmp && \ 338 | mv $@.tmp $@; 339 | 340 | all: $(srcdir)/.gitignore gitignore-recurse-maybe 341 | gitignore: $(srcdir)/.gitignore gitignore-recurse 342 | 343 | gitignore-recurse-maybe: 344 | @for subdir in $(DIST_SUBDIRS); do \ 345 | case " $(SUBDIRS) " in \ 346 | *" $$subdir "*) :;; \ 347 | *) test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir");; \ 348 | esac; \ 349 | done 350 | gitignore-recurse: 351 | @for subdir in $(DIST_SUBDIRS); do \ 352 | test "$$subdir" = . -o -e "$$subdir/.git" || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) gitignore || echo "Skipping $$subdir"); \ 353 | done 354 | 355 | maintainer-clean: gitignore-clean 356 | gitignore-clean: 357 | -rm -f $(srcdir)/.gitignore 358 | 359 | .PHONY: gitignore-clean gitignore gitignore-recurse gitignore-recurse-maybe 360 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------