/* valacomment.vala
 *
 * Copyright (C) 2008-2009  Florian Brosch
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Florian Brosch <flo.brosch@gmail.com>
 */

using GLib;

/**
 * A documentation comment used by valadoc
 */
public class Vala.Comment {
	public Comment (string comment, SourceReference _source_reference) {
		source_reference = _source_reference;
		content = comment;
	}

	/**
	 * The text describing the referenced source code.
	 */
	public string content { set; get; }

	/**
	 * References the location in the source file where this code node has
	 * been written.
	 */
	public SourceReference source_reference { get; set; }
}

Allow overriding content property in Comment class

/* valacomment.vala
 *
 * Copyright (C) 2008-2009  Florian Brosch
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Florian Brosch <flo.brosch@gmail.com>
 */

using GLib;

/**
 * A documentation comment used by valadoc
 */
public class Vala.Comment {
	public Comment (string comment, SourceReference _source_reference) {
		source_reference = _source_reference;
		content = comment;
	}

	/**
	 * The text describing the referenced source code.
	 */
	public virtual string content { set; get; }

	/**
	 * References the location in the source file where this code node has
	 * been written.
	 */
	public SourceReference source_reference { get; set; }
}


[CCode (prefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
namespace Config
{
	public const string PKGDATADIR;
	public const string UIDIR;

	public const string VERSION;
	public const string PACKAGE;
	public const string GETTEXT_PACKAGE;
}

/*
 * TODO: Temporary hacks for interfacing with some very simple C code in
 * the current C code base. In general we want to port to vala instead of
 * listing stuff here. Otherwise things will get unmanageable.
 */
namespace Seahorse {

namespace Prefs {
	public void show(Gtk.Window window, string? tabid);
	public bool available();
}

namespace Application {
	public unowned Gtk.Application @get();
}

}

Include correct headers for vala calling C code

[CCode (prefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
namespace Config
{
	public const string PKGDATADIR;
	public const string UIDIR;

	public const string VERSION;
	public const string PACKAGE;
	public const string GETTEXT_PACKAGE;
}

/*
 * TODO: Temporary hacks for interfacing with some very simple C code in
 * the current C code base. In general we want to port to vala instead of
 * listing stuff here. Otherwise things will get unmanageable.
 */
namespace Seahorse {

[CCode (cheader_filename = "libseahorse/seahorse-prefs.h")]
namespace Prefs {
	public void show(Gtk.Window window, string? tabid);
	public bool available();
}

[CCode (cheader_filename = "libseahorse/seahorse-application.h")]
namespace Application {
	public unowned Gtk.Application @get();
}

}


public string generate_uuid() {
	char[] uuid = new char[16];
	var output = new StringBuilder();
	weak char[] hexstring = (char[]) "0123456789ABCDEF";
	char left;
	char right;
	uuid_generate(uuid);
	for (int i = 0;i <16; i++) {
		left = (uuid[i] >> 4) & 0x0f ;
		right = uuid[i] & 0x0f;
		output.append_c(hexstring[left]);
		output.append_c(hexstring[right]);
	}
	return output.str;
}

Make UUID generation an internal helper

internal string generate_uuid() {
	char[] uuid = new char[16];
	var output = new StringBuilder();
	weak char[] hexstring = (char[]) "0123456789ABCDEF";
	char left;
	char right;
	uuid_generate(uuid);
	for (int i = 0;i <16; i++) {
		left = (uuid[i] >> 4) & 0x0f ;
		right = uuid[i] & 0x0f;
		output.append_c(hexstring[left]);
		output.append_c(hexstring[right]);
	}
	return output.str;
}


namespace Ui {

    public class HeaderBar : Gtk.Box {

        private Gtk.Entry  entry;
        private Gtk.Button search_button;

        public signal void docker_daemon_lookup_request(string docker_path);

        public HeaderBar(string docker_host) {
            Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 0);

            this.entry = new Gtk.Entry();
            this.entry.text = docker_host;
            this.entry.width_chars = 30;

            this.search_button = new Gtk.Button.from_icon_name("edit-find-symbolic", Gtk.IconSize.BUTTON);
            this.search_button.expand = false;

            this.pack_start(entry, false, true, 3);
            this.pack_start(search_button, false, true, 0);

            this.search_button.clicked.connect(() => {
                this.docker_daemon_lookup_request(entry.text);
            });
        }
    }
}

Enhance Docker unix socket entry

namespace Ui {

    public class HeaderBar : Gtk.Box {

        private Gtk.Label  entry_label;
        private Gtk.Entry  entry;

        public signal void docker_daemon_lookup_request(string docker_path);

        public HeaderBar(string docker_host) {
            Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 0);

            this.entry_label = new Gtk.Label("Docker unix socket");

            this.entry = new Gtk.Entry();
            this.entry.text = docker_host;
            this.entry.width_chars = 30;
            this.entry.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, "edit-find-symbolic");

            this.pack_start(entry_label, false, true, 3);
            this.pack_start(entry, false, true, 3);

            entry.icon_press.connect ((pos, event) => {
                if (pos == Gtk.EntryIconPosition.SECONDARY) {
                    this.docker_daemon_lookup_request(entry.text);
                }
            });

            entry.activate.connect (() => {
                this.docker_daemon_lookup_request(entry.text);
            });
        }
    }
}


/* Copyright 2011-2012 Yorba Foundation
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

public class Geary.Imap.ResponseCode : Geary.Imap.ListParameter {
    public ResponseCode(ListParameter parent, Parameter? initial = null) {
        base (parent, initial);
    }

    public ResponseCodeType get_code_type() throws ImapError {
        return ResponseCodeType.from_parameter(get_as_string(0));
    }

    public override string to_string() {
        return "[%s]".printf(stringize_list());
    }

    public override async void serialize(Serializer ser) throws Error {
        ser.push_ascii('[');
        serialize_list(ser);
        ser.push_ascii(']');
    }
}

Fix async call in Imap.ResponseCode.serialize

/* Copyright 2011-2012 Yorba Foundation
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

public class Geary.Imap.ResponseCode : Geary.Imap.ListParameter {
    public ResponseCode(ListParameter parent, Parameter? initial = null) {
        base (parent, initial);
    }

    public ResponseCodeType get_code_type() throws ImapError {
        return ResponseCodeType.from_parameter(get_as_string(0));
    }

    public override string to_string() {
        return "[%s]".printf(stringize_list());
    }

    public override async void serialize(Serializer ser) throws Error {
        ser.push_ascii('[');
        yield serialize_list(ser);
        ser.push_ascii(']');
    }
}


[Import ()]
[CCode (cprefix = "Totem", lower_case_cprefix = "totem_")]

namespace Totem {
	[CCode (cheader_filename = "totem.h")]
	public class Object {
		[NoArrayLength]
		[CCode (cname = "totem_object_get_type")]
		public static GLib.Type get_type ();
	}

	[CCode (cheader_filename = "totem-plugin.h")]
	public abstract class Plugin :GLib.Object {
		[NoArrayLength]
		[CCode (cname = "totem_plugin_get_type")]
		public static GLib.Type get_type ();

		[NoArrayLength]
		[CCode (cname = "totem_plugin_activate")]
		public abstract bool activate (Totem.Object totem) throws GLib.Error;
		[NoArrayLength]
		[CCode (cname = "totem_plugin_deactivate")]
		public abstract void deactivate (Totem.Object totem);

		[NoArrayLength]
		[CCode (cname = "totem_plugin_is_configurable")]
		public virtual bool is_configurable ();
		[NoArrayLength]
		[CCode (cname = "totem_plugin_create_configure_dialog")]
		public virtual Gtk.Widget create_configure_dialog ();

		[NoArrayLength]
		[CCode (cname = "totem_plugin_find_file")]
		public virtual weak string find_file (string file);
	}

}

Improve Vala bindings to avoid warning

[Import ()]
[CCode (cprefix = "Totem", lower_case_cprefix = "totem_")]

namespace Totem {
	[CCode (cheader_filename = "totem.h")]
	public class Object {
		[NoArrayLength]
		[CCode (cname = "totem_object_get_type")]
		public static GLib.Type get_type ();
	}

	[CCode (cheader_filename = "totem-plugin.h")]
	public abstract class Plugin :GLib.Object {
		[CCode (has_construct_function = false)]
		protected Plugin ();

		[NoArrayLength]
		[CCode (cname = "totem_plugin_get_type")]
		public static GLib.Type get_type ();

		[NoArrayLength]
		[CCode (cname = "totem_plugin_activate")]
		public abstract bool activate (Totem.Object totem) throws GLib.Error;
		[NoArrayLength]
		[CCode (cname = "totem_plugin_deactivate")]
		public abstract void deactivate (Totem.Object totem);

		[NoArrayLength]
		[CCode (cname = "totem_plugin_is_configurable")]
		public virtual bool is_configurable ();
		[NoArrayLength]
		[CCode (cname = "totem_plugin_create_configure_dialog")]
		public virtual Gtk.Widget create_configure_dialog ();

		[NoArrayLength]
		[CCode (cname = "totem_plugin_find_file")]
		public virtual weak string find_file (string file);
	}

}


/*
 * Copyright (C) 2011 Collabora Ltd.
 *
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *       Marco Barisione <marco.barisione@collabora.co.uk>
 */

using GLib;
using Gee;

/**
 * Interface for classes that have email addresses, such as {@link Persona}
 * and {@link Individual}.
 *
 * @since 0.3.5
 */
public interface Folks.EmailDetails : Object
{
  /**
   * The email addresses of the contact.
   *
   * @since 0.5.1
   */
  public abstract Set<FieldDetails> email_addresses { get; set; }
}

Expand the documentation of EmailDetails.email_addresses

/*
 * Copyright (C) 2011 Collabora Ltd.
 *
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *       Marco Barisione <marco.barisione@collabora.co.uk>
 */

using GLib;
using Gee;

/**
 * Interface for classes that have email addresses, such as {@link Persona}
 * and {@link Individual}.
 *
 * @since 0.3.5
 */
public interface Folks.EmailDetails : Object
{
  /**
   * The email addresses of the contact.
   *
   * Each of the {@link FieldDetails.value}s in this property contains just an
   * e-mail address (e.g. “foo@bar.com”), rather than any other way of
   * formatting an e-mail address (such as “John Smith <foo@bar.com>”).
   *
   * @since 0.5.1
   */
  public abstract Set<FieldDetails> email_addresses { get; set; }
}


[Compact]
class Foo {
	public int i = 42;
	public int j = 23;

	public Foo () {
		assert (i == 42);
		j = 23;
	}

	public Foo.bar () {
		this ();
		assert (i == 42);
		assert (j == 23);
	}
}

void main () {
	{
		var foo = new Foo ();
		assert (foo.i == 42);
		assert (foo.j == 23);
	}
	{
		var foo = new Foo.bar ();
		assert (foo.i == 42);
		assert (foo.j == 23);
	}
}

Extend "this chainup in compact class" test

[Compact]
class Foo {
	public string s = "foo";
	public int i = 42;
	public int j;

	public Foo () {
		assert (s == "foo");
		assert (i == 42);
		j = 23;
	}

	public Foo.bar () {
		this ();
		assert (s == "foo");
		assert (i == 42);
		assert (j == 23);
	}
}

void main () {
	{
		var foo = new Foo ();
		assert (foo.s == "foo");
		assert (foo.i == 42);
		assert (foo.j == 23);
	}
	{
		var foo = new Foo.bar ();
		assert (foo.s == "foo");
		assert (foo.i == 42);
		assert (foo.j == 23);
	}
}


void do_foo (out int i) {
	i = 0;
	try {
		return;
	} finally {
		i = 42;
	}
}

void main () {
	int i;
	do_foo (out i);
	assert (i == 42);
}

Extend "finally block execution" test to increase coverage

errordomain FooError {
	FAIL
}

void do_foo (out int i) {
	i = 0;
	try {
		return;
	} finally {
		i = 42;
	}

	assert_not_reached ();
}

string do_bar (out int i) {
	string s = "bar";
	try {
		if (s == "bar") {
			return s;
		}
	} finally {
		i = 23;
	}

	assert_not_reached ();
}

string do_manam (out int i) {
	string s = "manam";
	try {
		throw new FooError.FAIL ("manam");
	} catch {
		if (s == "manam") {
			return s;
		}
	} finally {
		i = 4711;
	}

	assert_not_reached ();
}

void main () {
	{
		int i;
		do_foo (out i);
		assert (i == 42);
	}
	{
		int i;
		string s = do_bar (out i);
		assert (i == 23);
		assert (s == "bar");
	}
	{
		int i;
		string s = do_manam (out i);
		assert (i == 4711);
		assert (s == "manam");
	}
}


using GLib;
using Wiz;
using Graph;

public void test_commit() {
	var s = new CommitStore("data/foo");

	var c1 = new RarCommit();
	c1.blob = "rararar";
	s.store_commit(c1);

	var c2 = new RarCommit();
	c2.blob = "rararararar";
	c2.parents.append(c1.uuid);
	s.store_commit(c2);

	var tips = s.get_tips("sdsdsd");
	stdout.printf("%u", tips.length());
}

public static void main (string[] args) {
	if (!FileUtils.test("data", FileTest.IS_DIR)) {
		DirUtils.create_with_parents("data", 0755);
		/* Should write some data to the file data/blob-data */
	}
	Test.init (ref args);
	Test.add_func("/wizbit/commit_store/1", test_commit);
	Test.run();
}

Make sure finds right number of tips

using GLib;
using Wiz;
using Graph;

public void test_commit() {
	var s = new CommitStore("data/foo");

	var c1 = new RarCommit();
	c1.blob = "rararar";
	s.store_commit(c1);

	var c2 = new RarCommit();
	c2.blob = "rararararar";
	c2.parents.append(c1.uuid);
	s.store_commit(c2);

	var tips = s.get_tips("sdsdsd");
	assert(tips.length() == 1);
}

public static void main (string[] args) {
	if (!FileUtils.test("data", FileTest.IS_DIR)) {
		DirUtils.create_with_parents("data", 0755);
		/* Should write some data to the file data/blob-data */
	}
	Test.init (ref args);
	Test.add_func("/wizbit/commit_store/1", test_commit);
	Test.run();
}


/*
 * Copyright (C) 2012 Openismus GmbH.
 *
 * Author: Jens Georg <jensg@openismus.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

using Rygel;

public void module_init (PluginLoader loader) {
    if (loader.plugin_disabled (Playbin.Plugin.NAME)) {
        message ("Plugin '%s' disabled by user, ignoring..",
                 Playbin.Plugin.NAME);

        return;
    }

    var plugin = new Playbin.Plugin ();

    loader.add_plugin (plugin);
}

Make plugin usable with simple engine

/*
 * Copyright (C) 2012 Openismus GmbH.
 *
 * Author: Jens Georg <jensg@openismus.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

using Rygel;
using Gst;

public void module_init (PluginLoader loader) {
    if (loader.plugin_disabled (Playbin.Plugin.NAME)) {
        message ("Plugin '%s' disabled by user, ignoring..",
                 Playbin.Plugin.NAME);

        return;
    }

    unowned string[] args = null;

    Gst.init (ref args);

    var plugin = new Playbin.Plugin ();

    loader.add_plugin (plugin);
}


using GLib;

enum Maman.Foo {
	VAL2 = 2,
	VAL3,
	VAL5 = 5
}

class Maman.Bar : Object {
	public void run () {
		stdout.printf (" %d", Foo.VAL2);

		stdout.printf (" %d", Foo.VAL3);

		stdout.printf (" 4");

		stdout.printf (" %d", Foo.VAL5);
	}

	static void test_enums_0_conversion () {
		Foo foo = 0;
	}

	public static int main () {
		stdout.printf ("Enum Test: 1");

		var bar = new Bar ();
		bar.run ();

		stdout.printf (" 6\n");

		test_enums_0_conversion ();

		return 0;
	}
}

void main () {
	Maman.Bar.main ();
}

Add a test for enum methods and constants

using GLib;

enum Maman.Foo {
	VAL2 = 2,
	VAL3,
	VAL5 = 5
}

enum Maman.Fooish {
	VAL1,
	VAL2;

	public int something () {
		return (int) this;
	}

	public const int FOO = 2;
}

class Maman.Bar : Object {
	public void run () {
		stdout.printf (" %d", Foo.VAL2);

		stdout.printf (" %d", Foo.VAL3);

		stdout.printf (" 4");

		stdout.printf (" %d", Foo.VAL5);
	}

	static void test_enums_0_conversion () {
		Foo foo = 0;
	}

	static void test_enum_methods_constants () {
		Fooish x = Fooish.VAL1;
		stdout.printf ("%d", x.something ());
		stdout.printf ("%d", Fooish.FOO);
	}

	public static int main () {
		stdout.printf ("Enum Test: 1");

		var bar = new Bar ();
		bar.run ();

		stdout.printf (" 6\n");

		test_enums_0_conversion ();
		test_enum_methods_constants ();

		return 0;
	}
}

void main () {
	Maman.Bar.main ();
}


[Compact]
public class BaseTestSuite {
	void setup(void *fixture) {}
	void teardown(void *fixture) {}

	void assert_true(bool condition) {
		assert(condition);
	}
}

public class TestSuiteWithTempDir : BaseTestSuite {

	private string olddir;
	protected string directory;

	public void setup(void *fixture) {
		this.olddir = Environment.get_current_dir();
		this.directory = DirUtils.mkdtemp(Path.build_filename(Environment.get_tmp_dir(), "XXXXXX"));
		Environment.set_current_dir(this.directory);
	}

	public void teardown(void *fixture) {
		Environment.set_current_dir(this.olddir);
		DirUtils.remove(this.directory);
	}
}

Clean up test base code

[Compact]
public class BaseTestSuite {
	public void setup(void *fixture) {}
	public void teardown(void *fixture) {}
}

public class TestSuiteWithTempDir : BaseTestSuite {

	private string olddir;
	protected string directory;

	public void setup(void *fixture) {
		this.olddir = Environment.get_current_dir();
		this.directory = DirUtils.mkdtemp(Path.build_filename(Environment.get_tmp_dir(), "XXXXXX"));
		Environment.set_current_dir(this.directory);
	}

	public void teardown(void *fixture) {
		Environment.set_current_dir(this.olddir);
		DirUtils.remove(this.directory);
	}
}


bool foo (out string? s) {
	s = "foo";
	return true;
}

int bar () {
	return 42;
}

void main () {
	{
		string? s;
		if (!foo (out s) || s == null) {
			assert_not_reached ();
		}
	}
	{
		int i;
		if ((i = bar ()) > 42 || i < 23) {
			assert_not_reached ();
		}
	}
}

Extend "assigned local variable" control flow tests

bool foo (out string? s) {
	s = "foo";
	return true;
}

int bar () {
	return 42;
}

void main () {
	{
		string? s;
		if (!foo (out s) || s == null) {
			assert_not_reached ();
		}
	}
	{
		int i;
		if ((i = bar ()) > 42 || i < 23) {
			assert_not_reached ();
		}
	}

	{
		string? s;
		while (!foo (out s) || s == null) {
			assert_not_reached ();
		}
	}
	{
		int i;
		while ((i = bar ()) > 42 || i < 23) {
			assert_not_reached ();
		}
	}

	{
		string? s;
		assert (!foo (out s) || s == null ? false : true);
	}
	{
		int i;
		assert ((i = bar ()) > 42 || i < 23 ? false : true);
	}
}


namespace yrcd {
  class yrcd_constants : Object {
    public const string version = "0.1";
    public const string software = "yrcd";
    public const string motd = "Welcome!";
    public const string[] listen_ips = {"127.0.0.1"};
    public const uint16[] listen_ports = {6667, 6668};
    public const string sname = "test.net.local";
  }
}

Add cmode and umodes arrays, even though they aren't used yet

namespace yrcd {
  class yrcd_constants : Object {
    public const string version = "0.1";
    public const string software = "yrcd";
    public const string motd = "Welcome!";
    public const string[] listen_ips = {"127.0.0.1"};
    public const uint16[] listen_ports = {6667, 6668};
    public const string sname = "test.net.local";
    public const string[] cmodes = {};
    public const string[] umodes = {};
  }
}


/*
 * Copyright (C) 2008 Zeeshan Ali <zeenix@gmail.com>.
 *
 * Author: Zeeshan Ali <zeenix@gmail.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

using Gee;
using Tracker;

public class Rygel.Tracker.Plugin : Rygel.MediaServerPlugin {
    public const string NAME = "Tracker3";

    private static RootContainer root;

    public Plugin () {
        if (root == null) {
            // translators: @REALNAME@ is substituted for user's real name and it doesn't need translation.
            root = new RootContainer (_("@REALNAME@’s media"));
        }

        base (root, Plugin.NAME, null, PluginCapabilities.UPLOAD);
    }
}

Disable upload capability for now

/*
 * Copyright (C) 2008 Zeeshan Ali <zeenix@gmail.com>.
 *
 * Author: Zeeshan Ali <zeenix@gmail.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

using Gee;
using Tracker;

public class Rygel.Tracker.Plugin : Rygel.MediaServerPlugin {
    public const string NAME = "Tracker3";

    private static RootContainer root;

    public Plugin () {
        if (root == null) {
            // translators: @REALNAME@ is substituted for user's real name and it doesn't need translation.
            root = new RootContainer (_("@REALNAME@’s media"));
        }

        base (root, Plugin.NAME, null, PluginCapabilities.NONE);
    }
}


namespace View.Docker {

    using global::Sdk.Docker.Model;

    public class Terminal : Vte.Terminal {

        protected string[] command;

        public Terminal(string[] command) {
            this.command = command;
        }

        public Terminal.from_bash_in_container(Container container) {
            command = {"/usr/bin/docker", "exec", "-ti", container.id, "bash"};

            this.child_exited.connect((term) => {
                Gtk.Container c;
                if (null != parent_container_widget) {
                    c = parent_container_widget;
                } else {
                    c = this.get_parent();
                }
                c.destroy();
                this.destroy();
            });
        }

        public void start() {

            Pid pid;
            fork_command_full(
                Vte.PtyFlags.DEFAULT,
                Environment.get_variable("HOME"),
                command,
                new string[]{Environment.get_variable("HOME"), Environment.get_variable("PATH")},
                SpawnFlags.LEAVE_DESCRIPTORS_OPEN ,
                null,
                out pid
            );
        }

        public Gtk.Container? parent_container_widget {
            get; set; default = null;
        }
    }
}

Add cast in Terminal widget for older valac version

namespace View.Docker {

    using global::Sdk.Docker.Model;

    public class Terminal : Vte.Terminal {

        protected string[] command;

        public Terminal(string[] command) {
            this.command = command;
        }

        public Terminal.from_bash_in_container(Container container) {
            command = {"/usr/bin/docker", "exec", "-ti", container.id, "bash"};

            this.child_exited.connect((term) => {
                Gtk.Container c;
                if (null != parent_container_widget) {
                    c = parent_container_widget;
                } else {
                    c = (Gtk.Container) this.get_parent();
                }
                c.destroy();
                this.destroy();
            });
        }

        public void start() {

            Pid pid;
            fork_command_full(
                Vte.PtyFlags.DEFAULT,
                Environment.get_variable("HOME"),
                command,
                new string[]{Environment.get_variable("HOME"), Environment.get_variable("PATH")},
                SpawnFlags.LEAVE_DESCRIPTORS_OPEN ,
                null,
                out pid
            );
        }

        public Gtk.Container? parent_container_widget {
            get; set; default = null;
        }
    }
}


/*
 * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

public abstract class Tracker.Sparql.Cursor : Object {
	public Connection connection { get; set; }
	public abstract int n_columns { get; }
	public abstract unowned string get_string (int column, out int length = null);

	public abstract bool next (Cancellable? cancellable = null) throws GLib.Error;
	public async abstract bool next_async (Cancellable? cancellable = null) throws GLib.Error;
	public abstract void rewind ();
}

Allow Cursor.get_string to return null

/*
 * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

public abstract class Tracker.Sparql.Cursor : Object {
	public Connection connection { get; set; }
	public abstract int n_columns { get; }
	public abstract unowned string? get_string (int column, out long length = null);

	public abstract bool next (Cancellable? cancellable = null) throws GLib.Error;
	public async abstract bool next_async (Cancellable? cancellable = null) throws GLib.Error;
	public abstract void rewind ();
}


/*
 * Copyright (C) 2013 Intel Corporation.
 *
 * Author: Jussi Kukkonen <jussi.kukkonen@intel.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

using Rygel;

public class Rygel.LMS.Plugin : Rygel.MediaServerPlugin {
    public const string NAME = "LMS";

    private static RootContainer root;

    public Plugin() {
        if (root == null)
            root = new RootContainer();
        base(root, Plugin.NAME, null, 0);
    }
}

Set TRACK_CHANGES capability for plugin

/*
 * Copyright (C) 2013 Intel Corporation.
 *
 * Author: Jussi Kukkonen <jussi.kukkonen@intel.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

using Rygel;

public class Rygel.LMS.Plugin : Rygel.MediaServerPlugin {
    public const string NAME = "LMS";

    private static RootContainer root;

    public Plugin() {
        if (root == null)
            root = new RootContainer();
        base(root, Plugin.NAME, null, PluginCapabilities.TRACK_CHANGES);
    }
}


namespace Fenice {

public interface TranscriptEntry : Object {

    public abstract path_t path { get; protected set; }

    public abstract ChangeType change_type { get; set; }

    public abstract bool equal(TranscriptEntry other);

    public abstract TranscriptEntryType entry_type();

    public bool recurse() {
        return false;
    }

    public bool has_changed() {
        return change_type != ChangeType.UNCHANGED;
    }

    public bool was_removed() {
        return change_type == ChangeType.REMOVED;
    }

    protected bool object_equal(TranscriptEntry other) {
        return get_class() == other.get_class() && path.equal(other.path);
    }
}

}

Allow overriding recurse in entry implementation classes

namespace Fenice {

public interface TranscriptEntry : Object {

    public abstract path_t path { get; protected set; }

    public abstract ChangeType change_type { get; set; }

    public abstract bool equal(TranscriptEntry other);

    public abstract TranscriptEntryType entry_type();

    public virtual bool recurse() {
        return false;
    }

    public bool has_changed() {
        return change_type != ChangeType.UNCHANGED;
    }

    public bool was_removed() {
        return change_type == ChangeType.REMOVED;
    }

    protected bool object_equal(TranscriptEntry other) {
        return get_class() == other.get_class() && path.equal(other.path);
    }
}

}


/*
 * Copyright (C) 2013 Intel Corporation.
 *
 * Author: Jussi Kukkonen <jussi.kukkonen@intel.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

using Rygel;

public class Rygel.LMS.Plugin : Rygel.MediaServerPlugin {
    public const string NAME = "LMS";

    private static RootContainer root;

    public Plugin() {
        if (root == null)
            root = new RootContainer();
        base(root, Plugin.NAME, null, 0);
    }
}

Set TRACK_CHANGES capability for LMS plugin


/*
 * Copyright (C) 2008 Zeeshan Ali <zeenix@gmail.com>.
 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
 *
 * Author: Zeeshan Ali <zeenix@gmail.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

using GUPnP;

/**
 * Represents MediaExport item.
 */
public class Rygel.MediaExportItem : MediaItem {
    public MediaExportItem (MediaContainer parent,
                            File           file,
                            FileInfo       info) {
        string content_type = info.get_content_type ();
        string item_class = null;
        string id = Checksum.compute_for_string (ChecksumType.MD5,
                                                 info.get_name ());

        // use heuristics based on content type; will use MediaHarvester
        // when it's ready

        if (content_type.has_prefix ("video/")) {
            item_class = MediaItem.VIDEO_CLASS;
        } else if (content_type.has_prefix ("audio/")) {
            item_class = MediaItem.AUDIO_CLASS;
        } else if (content_type.has_prefix ("image/")) {
            item_class = MediaItem.IMAGE_CLASS;
        }

        if (item_class == null) {
            item_class = MediaItem.AUDIO_CLASS;
            warning ("Failed to detect UPnP class for '%s', assuming it's '%s'",
                     file.get_uri (), item_class);
        }

        base (id, parent, info.get_name (), item_class);

        this.mime_type = content_type;
        this.uris.add (file.get_uri ());
    }
}


using IBus;

class TestEngine : Engine {
    public override bool process_key_event (uint keyval, uint keycode, uint state) {
        stdout.printf("process_key_event(%u, %u, 0x%x)\n", keyval, keycode, state);
        return true;
    }
}

void main (string []argv) {
    var bus = new Bus();
    var factory = new Factory(bus.get_connection());
    factory.add_engine("vala-debug", typeof(TestEngine));
    var component = new Component (
                            "org.freedesktop.IBus.Vala",
                            "ValaTest", "0.0.1", "GPL",
                            "Peng Huang <shawn.p.huang@gmail.com>",
                            "http://code.google.com/p/ibus/",
                            "",
                            "ibus-vala");
    var engine = new EngineDesc ("vala-debug",
                                 "Vala (debug)",
                                 "Vala demo input method",
                                 "zh_CN",
                                 "GPL",
                                 "Peng Huang <shawn.p.huang@gmail.com>",
                                 "",
                                 "us");
    component.add_engine (engine);
    bus.register_component (component);
    IBus.main ();
}


/*
 * This file is Public Domain and provided only for documentation purposes.
 *
 * Note this is buttugly, please don't actually use this as a UI template.
 *
 * Compile: valac list.vala --pkg gtk+-3.0 --pkg ldm-0.1
 * Run    : ./list
 */
public class MyLister : Gtk.Window
{
    Ldm.Manager manager;
    Gtk.ListBox listing;

    public MyLister()
    {
        // Construct a new manager without hotplug capabilites
        manager = new Ldm.Manager(Ldm.ManagerFlags.NO_MONITOR);

        // Set up main window attributes
        var header = new Gtk.HeaderBar();
        header.set_show_close_button(true);
        set_titlebar(header);
        set_title("List devices");
        set_size_request(550, 400);
        get_settings().gtk_application_prefer_dark_theme =  true;

        // Init UI area
        listing = new Gtk.ListBox();
        var scroll = new Gtk.ScrolledWindow(null, null);
        add(scroll);
        scroll.add(listing);

        // Whack all devices in as simple labels (ugly)
        foreach (var device in manager.get_devices()) {
            var label = new Gtk.Label(@"$(device.vendor) - $(device.name)");
            listing.add(label);
            label.margin = 10;
            label.halign = Gtk.Align.START;

            if (device.has_type(Ldm.DeviceType.GPU)) {
                message("Found a GPU: %s", device.name);
            }
        }

        destroy.connect(Gtk.main_quit);
        show_all();
    }
}

int main(string[] args)
{
    Gtk.init(ref args);
    var lister = new MyLister();
    Gtk.main();
    return 0;
}


[CCode (cprefix="", lower_case_prefix="", cheader_filename="config.h")]
namespace Config {
	[CCode (cname = "VERSION")]
	public const string VERSION;

	[CCode (cname = "GETTEXT_PACKAGE")]
	public const string GETTEXT_PACKAGE;

	[CCode (cname = "SEAHORSE_GLADEDIR")]
	public const string SEAHORSE_GLADEDIR;
}


using GLib;
using Json;

public class Sample : GLib.Object {
        public bool toggle { get; set; }
        public string name { get; set; }

        public Sample () {
                name = "Hello, world!";
                toggle = true;
        }

        public string to_json () {
                var obj = new Json.Object ();

                var node = new Json.Node (Json.NodeType.VALUE);
                node.set_string (name);
                obj.add_member ("name", node.copy ());

                node = new Json.Node (Json.NodeType.VALUE);
                node.set_boolean (toggle);
                obj.add_member ("toggle", node.copy ());

                var root = new Json.Node (Json.NodeType.OBJECT);
                root.set_object (obj);

                var generator = new Json.Generator ();
                generator.set_root (root);

                return generator.to_data ();
        }

        static int main (string[] args) {
                var sample = new Sample ();

                stdout.printf ("var sample = %s;\n", sample.to_json ());

                return 0;
        }
}


/*
 * Copyright (C) 2009,2010 Nokia Corporation.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *                               <zeeshan.ali@nokia.com>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

/**
 * Container listing music genres as containers.
 */
public class Rygel.Tracker.Genre : MetadataValues {
    public Genre (Music parent) {
        var key_chain = new string[] { "nfo:genre", null };

        base (parent.id + "Genre",
              parent,
              _("Genre"),
              parent.item_factory,
              key_chain,
              MediaContainer.MUSIC_GENRE);
    }
}


#!/usr/bin/awk -f
BEGIN {
	# Determines whether to print 'Unreleased' banner at top
	UNRELEASED_COMMITS = 1
	# Prefixes that determine whether a commit will be printed
	CHANGELOG_REGEX = "^(changelog|fix|docs|chore|feat): "
	FS="|"
	while ("git log --pretty='%D|%s|%H'" | getline) {
		IS_GIT_TAG = length($1) && match($1, /tag:/)
		if (IS_GIT_TAG) {
			UNRELEASED_COMMITS = 0
			# Cut out text up to tag
			sub(/.*tag: /, "", $1)
			# Cut out text after tag
			sub(/,.*/, "", $1)
			print $1
		} else {
			if ( UNRELEASED_COMMITS ) {
				print "Unreleased"
				UNRELEASED_COMMITS = 0
			}
			if ( match($2, CHANGELOG_REGEX) ) {
				sub(CHANGELOG_REGEX, "", $2)
				printf("\t- %s\n", $2)
			}
		}

	}
}

Add new prefixes: feature, refactor and update

#!/usr/bin/awk -f
BEGIN {
	# Determines whether to print 'Unreleased' banner at top
	UNRELEASED_COMMITS = 1
	# Prefixes that determine whether a commit will be printed
	CHANGELOG_REGEX = "^(changelog|fix|docs|chore|feat|feature|refactor|update): "
	FS="|"
	while ("git log --pretty='%D|%s|%H'" | getline) {
		IS_GIT_TAG = length($1) && match($1, /tag:/)
		if (IS_GIT_TAG) {
			UNRELEASED_COMMITS = 0
			# Cut out text up to tag
			sub(/.*tag: /, "", $1)
			# Cut out text after tag
			sub(/,.*/, "", $1)
			print $1
		} else {
			if ( UNRELEASED_COMMITS ) {
				print "Unreleased"
				UNRELEASED_COMMITS = 0
			}
			if ( match($2, CHANGELOG_REGEX) ) {
				sub(CHANGELOG_REGEX, "", $2)
				printf("\t- %s\n", $2)
			}
		}

	}
}


# awk script to convert symbol export table formats

# converts an msvc .def file to an darwin ld export-symbols-list file
# we only support the most basic module definition syntax

# skip comments
/^\w*#.*/ {next}
/^\w*;.*/ {next}

# remember and propagate the library name
/LIBRARY/ {name = $2; print "\# export list for", name; next}

# skip various other lines
/^\w*NAME/ ||
/^\w*VERSION/ ||
/^\w*EXPORTS/ ||
/^\w*HEAPSIZE/ ||
/^\w*STACKSIZE/ ||
/^\w*STUB/ {next}

# todo: handle SECTIONS

# for symbols, strip the semicolon and mangle the name
/[a-zA-Z]+/ {sub(/\;/, ""); print "_" $1}

# todo: warn if we see publicname=privatename mappings
#       which other linkers don't support

Remove a redundant escape character.

# awk script to convert symbol export table formats

# converts an msvc .def file to an darwin ld export-symbols-list file
# we only support the most basic module definition syntax

# skip comments
/^\w*#.*/ {next}
/^\w*;.*/ {next}

# remember and propagate the library name
/LIBRARY/ {name = $2; print "# export list for", name; next}

# skip various other lines
/^\w*NAME/ ||
/^\w*VERSION/ ||
/^\w*EXPORTS/ ||
/^\w*HEAPSIZE/ ||
/^\w*STACKSIZE/ ||
/^\w*STUB/ {next}

# todo: handle SECTIONS

# for symbols, strip the semicolon and mangle the name
/[a-zA-Z]+/ {sub(/\;/, ""); print "_" $1}

# todo: warn if we see publicname=privatename mappings
#       which other linkers don't support


# Print lines from a WebScraper csv file after joining extra newlines

# INVOCATION:
#   awk -f fixExtraLinesFrom-webscraper.awk BritBoxPrograms.csv

{
    if (/^"/)
        printf ("\n" $0)
    else
        printf
}

Make sure newline at end of file

# Print lines from a WebScraper csv file after joining extra newlines

# INVOCATION:
#   awk -f fixExtraLinesFrom-webscraper.awk BritBoxPrograms.csv

{
    if (/^"/)
        printf ("\n" $0)
    else
        printf
}

END {
    printf ("\n")
}


{
    if (1==NR)
    {
        startTimestamp = substr($1, 2, length($1) - 2)
        printf(";$FILEVERSION=1.3\n")
        printf(";$STARTTIME=%u.%u\n", mktime(strftime("%Y %m %d 0 0 0", startTimestamp)) / 86400 + 25569, \
                10000000000 / 86400 * (mktime(strftime("%Y %m %d %H %M %S", startTimestamp)) - mktime(strftime("%Y %m %d 0 0 0", startTimestamp))))
        currentTimeOffset = 0.0
    }
    else
    {
        previousTimeOffset = currentTimeOffset
        currentTimestamp = substr($1, 2, length($1) - 2)
        currentTimeOffset = currentTimestamp - startTimestamp
        if (currentTimeOffset < 0)
        {
            startTimestamp = currentTimestamp + currentTimeOffset
            currentTimeOffset = previousTimeOffset
        }
    }
    printf("%u) %.3f 1 Rx %s - %s", NR, currentTimeOffset * 1000, $3, substr($4, 2, length($4) - 2))
    if (5<=NF)
    {
        for(i=5;i<=NF;i++)
        {
            printf " "$i
        }
    }
    printf "\n"
}

Use float for calculating fractional part of STARTTIME to support busybox awk. Also print used start time is various representations.

{
    if (1==NR)
    {
        startTimestamp = substr($1, 2, length($1) - 2)
        printf(";$FILEVERSION=1.3\n")
        printf(";$STARTTIME=%u.%.0f\n", mktime(strftime("%Y %m %d 0 0 0", startTimestamp)) / 86400 + 25569, \
                10000000000.0 / 86400.0 * (mktime(strftime("%Y %m %d %H %M %S", startTimestamp)) - mktime(strftime("%Y %m %d 0 0 0", startTimestamp))))
        printf(";\n; Start time: %s\n", startTimestamp)
        printf(";             %u\n", mktime(strftime("%Y %m %d %H %M %S", startTimestamp)))
        printf(";             %s\n;\n", strftime("%Y-%m-%dT%H:%M:%S%z (%Z)", startTimestamp))
        currentTimeOffset = 0.0
    }
    else
    {
        previousTimeOffset = currentTimeOffset
        currentTimestamp = substr($1, 2, length($1) - 2)
        currentTimeOffset = currentTimestamp - startTimestamp
        if (currentTimeOffset < 0)
        {
            startTimestamp = currentTimestamp + currentTimeOffset
            currentTimeOffset = previousTimeOffset
        }
    }
    printf("%u) %.3f 1 Rx %s - %s", NR, currentTimeOffset * 1000, $3, substr($4, 2, length($4) - 2))
    if (5<=NF)
    {
        for(i=5;i<=NF;i++)
        {
            printf " "$i
        }
    }
    printf "\n"
}


#!/usr/bin/awk -f
BEGIN {
	# Determines whether to print 'Unreleased' banner at top
	UNRELEASED_COMMITS = 1
	# Prefixes that determine whether a commit will be printed
	CHANGELOG_REGEX = "^(changelog|fix|docs|chore|feat|feature|refactor|update): "
	FS="|"
	while ("git log --pretty='%D|%s|%H'" | getline) {
		IS_GIT_TAG = length($1) && match($1, /tag:/)
		if (IS_GIT_TAG) {
			UNRELEASED_COMMITS = 0
			# Cut out text up to tag
			sub(/.*tag: /, "", $1)
			# Cut out text after tag
			sub(/,.*/, "", $1)
			print $1
		} else {
			if ( UNRELEASED_COMMITS ) {
				print "Unreleased"
				UNRELEASED_COMMITS = 0
			}
			if ( match($2, CHANGELOG_REGEX) ) {
				sub(CHANGELOG_REGEX, "", $2)
				printf("\t- %s\n", $2)
			}
		}

	}
}

Update to output in markdown format

#!/usr/bin/awk -f
BEGIN {
	REPO_URL = getRepoURL()
	# Prefixes that determine whether a commit will be printed
	CHANGELOG_REGEX = "^(changelog|fix|docs|chore|feat|feature|refactor|update): "
	FS="|"
	# %D: tags
	# %s: commit message
	# %H: long hash
	# %h: short hash
	while ("git log --pretty='%D|%s|%H|%h'" | getline) {
		IS_GIT_TAG = length($1) && match($1, /tag:/)
		if (IS_GIT_TAG) {
			printTag($1)
		} else {
			printCommit($2, $3, $4)
		}

	}
}
function printTag(input) {
	# Cut out text up to tag
	sub(/.*tag: /, "", input)
	# Cut out text after tag
	sub(/,.*/, "", input)
	printf("## %s\n", input)
}
function printCommit(input, longHash, shortHash) {
	if ( match(input, CHANGELOG_REGEX) ) {
		sub(CHANGELOG_REGEX, "", input)
		printf("- %s (%s)\n", input, makeCommitLink(REPO_URL, shortHash, longHash) )
	}
}
function makeCommitLink(repoUrl, shortHash, longHash) {
	return ("[" shortHash "](" repoUrl "/commit/" longHash ")")
}
# Get Git repo URL
function getRepoURL() {
	"git config --get remote.upstream.url || git config --get remote.origin.url || git config --get remote.dev.url" | getline REPO_URL
	sub(/:/, "/", REPO_URL)
	sub(/git@/, "https://", REPO_URL)
	sub(/\.git/, "", REPO_URL)
	return REPO_URL
}


#!/usr/bin/env awk -f
#
# Computes the median.
#
# Usage: median
#
# Input:
#   - a column of numbers
#
# Output:
#   - median value

BEGIN {
	i = 0
}
{
	a[i++] = $1
}
END {
	j = i/2
	if ( i%2 == 1 ) {
		median = a[int(j)]
	} else {
		median = (a[j] + a[j-1])/2
	}
	print median
}

Clarify that input must be sorted

#!/usr/bin/env awk -f
#
# Computes the median.
#
# Usage: median
#
# Input:
#   - a sorted column of numbers
#
# Output:
#   - median value

BEGIN {
	i = 0
}
{
	a[i++] = $1
}
END {
	j = i/2
	if ( i%2 == 1 ) {
		median = a[int(j)]
	} else {
		median = (a[j] + a[j-1])/2
	}
	print median
}


BEGIN {
    FS = "\n";
}

/Targets:/ {
    while (getline && $0 != "") {
        if ($0 ~ /Tests/) continue;

        sub(/^ +/, "");
        print;
    }
}

Exclude any target with "Test" in the name

BEGIN {
    FS = "\n";
}

/Targets:/ {
    while (getline && $0 != "") {
        if ($0 ~ /Test/) continue;

        sub(/^ +/, "");
        print;
    }
}


#!/usr/bin/awk
#
# Patch the generated wrapper Swift code to handle special cases
#
BEGIN { depr_init = 0 }
/open .* ColorSelection/ { depr_init = 1 }
/public .* ColorSelection/ { depr_init = 1 }
/public .* HSV/ { depr_init = 1 }
/open .* HSV/ { depr_init = 1 }
/ init.. {/ {
	if (depr_init) {
		printf("@available(*, deprecated) ")
		depr_init = 0
	}
}
/ init. title:/ {
	if (depr_init) {
		printf("@available(*, deprecated) ")
		depr_init = 0
	}
}
// { print }

Make this link against gtk+-3.24.4

#!/usr/bin/awk
#
# Patch the generated wrapper Swift code to handle special cases
#
BEGIN { depr_init = 0 ; comment = 0 }
/open .* ColorSelection/ { depr_init = 1 }
/public .* ColorSelection/ { depr_init = 1 }
/public .* HSV/ { depr_init = 1 }
/open .* HSV/ { depr_init = 1 }
/open .* HSV/ { depr_init = 1 }
/func getColumnHeaderCells/ { comment = 1 }
/func getRowHeaderCells/ { comment = 1 }
/ init.. {/ {
	if (depr_init) {
		printf("@available(*, deprecated) ")
		depr_init = 0
	}
}
/ init. title:/ {
	if (depr_init) {
		printf("@available(*, deprecated) ")
		depr_init = 0
	}
}
// {
	if (comment) {
		printf("// ")
	}
	print
}
/^    }$/ { comment = 0 }


BEGIN {
	print "V1.0 {";
	print "    global:";
}
{
	# Remove the CR character in case the sources are mapped from
	# a Windows share and contain CRLF line endings
	gsub(/\r/,"", $0);

	# Skip empty lines and comment lines starting with semicolon
	if (NF && !match($0, /^[[:space:]]*;/))
	{
		print "        "  $0 ";";
	}
}
END {
	print "    local: *;"
	print "};";
}

Revert "Fix bracket expression matches a character at gawk"

BEGIN {
	print "V1.0 {";
	print "    global:";
}
{
	# Remove the CR character in case the sources are mapped from
	# a Windows share and contain CRLF line endings
	gsub(/\r/,"", $0);

	# Skip empty lines and comment lines starting with semicolon
	if (NF && !match($0, /^[:space:]*;/))
	{
		print "        "  $0 ";";
	}
}
END {
	print "    local: *;"
	print "};";
}


#!/bin/awk
#
# $Id$

{
	if (NR == 1) {
		print
	}
	else {
		for (i = 1; i <= NF; i++) {
			if ($i ~ /^include\// ||
				$i ~ /^src\// ||
				$i ~ /^obj\// ||
				$i == "\\")
			printf " " $i
		}
		print ""
	}
}

Include header files whose path begins with ../ .


BEGIN{
        now = systime()
        format = "%Y/%m/%d %H:%M:%S"

}
{
        split($1, DATE, "/")
        split($2, TIME, ":")
        $1 = ""
        $2 = ""
        t = mktime(DATE[1] " " DATE[2] " " DATE[3] " " TIME[1] " " TIME[2] " " TIME[3])
        if (delta == "") {
                delta = now - t
        }
        print strftime(format, t + delta) $0
}

Fix an output formatting bug in the rewriter script.

BEGIN{
        now = systime()
        format = "%Y/%m/%d %H:%M:%S"

}
{
        split($1, DATE, "/")
        split($2, TIME, ":")
        t = mktime(DATE[1] " " DATE[2] " " DATE[3] " " TIME[1] " " TIME[2] " " TIME[3])
        if (delta == "") {
                delta = now - t
        }
        out = strftime(format, t + delta)
        for (i = 3; i <= NF; i++) {
                out = out OFS $i
        }
        print out
}


BEGIN{doit = 0}
 { if (doit) print $0 }
 $0 == "%%EndSetup" { doit = 1 }

Fix awk script to work with cairo generated postscript

BEGIN{doit = 0}
 { if (doit) print $0 }
 $0 = /%%End.*Setup/ { doit = 1 }


#!/usr/bin/awk -f

BEGIN { FS = "," }

$1 == "pld" { p += $2 }
$1 == "val" { v += $2 }
{ "date -d "$3" +%B" | getline month
  monthly[month][$1] += $2
  categorically[$1][$4] += $2 }

END { print "Val spent "v"€"
      print "PLD spent "p"€"
      if ( p < v )
        print "PLD owe "v - p"€ to val."
      else if ( p > v )
        print "Val owe "p - v"€ to PLD."
      else
        print "Accounts are balanced."

      print ""

      if ( verbose == 1 ) {
        print "Here's the detail:"

        print "  Spendings per month:"
        for ( month in monthly ) {
          print "    In "month":"
          for ( who in monthly[month] ) {
            print "      "who" spent "monthly[month][who]"€."
          }
        }

        print "  Spendings by category:"
        for ( who in categorically ) {
          print "    By "who":"
          for ( category in categorically[who] ) {
            print "      "categorically[who][category]"€ in "category"."
          }
        }
      }
    }

Add year differentation into monthly report

#!/usr/bin/awk -f

BEGIN { FS = "," }

$1 == "pld" { p += $2 }
$1 == "val" { v += $2 }
{ "date -d "$3" '+%B %Y'" | getline month_and_year
  monthly[month_and_year][$1] += $2
  categorically[$1][$4] += $2 }

END { print "Val spent "v"€"
      print "PLD spent "p"€"
      if ( p < v )
        print "PLD owe "v - p"€ to val."
      else if ( p > v )
        print "Val owe "p - v"€ to PLD."
      else
        print "Accounts are balanced."

      print ""

      if ( verbose == 1 ) {
        print "Here's the detail:"

        print "  Spendings per month:"
        for ( month_and_year in monthly ) {
          print "    In "month_and_year":"
          total_for_month = 0
          for ( who in monthly[month_and_year] ) {
            spent = monthly[month_and_year][who]
            print "      "who" spent "spent"€."
            total_for_month += spent
          }
          print "      Total: "total_for_month"€."
        }

        print "  Spendings by category:"
        for ( who in categorically ) {
          print "    By "who":"
          for ( category in categorically[who] ) {
            print "      "categorically[who][category]"€ in "category"."
          }
        }
      }
    }


#
# Parsing output of:
#
# hdfs dfs -du -s '/user/*'
#

function dbstr(s) {
	if (s) { return "'" s "'" }
	else { return "NULL" }
}

function dbi(i) {
	if (i >= 0) { return i }
	else { return "NULL" }
}

BEGIN {
	FS="[ \t/]+"
	print "INSERT INTO measure (name) VALUES ('quota');";
}

{
	used=$1
	user=$4
	print "INSERT INTO quota (id_measure, user, used) VALUES (last_insert_id(), " dbstr(user) ", " dbi(used) ");"
}

Support also different version of Hadoop (=Fedora).

#
# Parsing output of:
#
# hdfs dfs -du -s '/user/*'
#

function dbstr(s) {
	if (s) { return "'" s "'" }
	else { return "NULL" }
}

function dbi(i) {
	if (i >= 0) { return i }
	else { return "NULL" }
}

BEGIN {
	FS="[ \t/]+"
	print "INSERT INTO measure (name) VALUES ('quota');";
}

/^[0-9]+[ 	]+[0-9]+[ 	]+\/.*/ {
	used=$1
	user=$4
	print "INSERT INTO quota (id_measure, user, used) VALUES (last_insert_id(), " dbstr(user) ", " dbi(used) ");"
}
/^[0-9]+[ 	]+\/.*/ {
	used=$1
	user=$3
	print "INSERT INTO quota (id_measure, user, used) VALUES (last_insert_id(), " dbstr(user) ", " dbi(used) ");"
}


{
    title = $0
    if (match (title, /, The"$/)) {
        sub (/^"/,"\"The ", title)
        sub (/, The"$/,"\"", title)
    }
    printf ("echo ==\\> %3d: %s\n",NR,title) >> TITLES_SCRIPT
    printf ("./getIMDbInfoFrom-titles.py %s\n",title) >> TITLES_SCRIPT
    printf ("echo \n\n") >> TITLES_SCRIPT

    printf ("echo ==\\> %3d: %s\n",NR,title) >> ID_SCRIPT
    printf ("./getIMDb_IDsFrom-titles.py %s | head -7\n",title) >> ID_SCRIPT
    printf ("echo \n\n") >> ID_SCRIPT
}

Add identifier KEY so we can see where we are in -v script

{
    title = $0
    if (match (title, /, The"$/)) {
        sub (/^"/,"\"The ", title)
        sub (/, The"$/,"\"", title)
    }

    if (FILENAME ~ /Acorn/)
        KEY = "A"
    if (FILENAME ~ /BBox/)
        KEY = "B"
    if (FILENAME ~ /MHz/)
        KEY = "M"
    if (FILENAME ~ /Watched/)
        KEY = "W"

    printf ("echo ==\\> %sT %3d: %s\n", KEY, NR, title) >> TITLES_SCRIPT
    printf ("./getIMDbInfoFrom-titles.py %s\n",title) >> TITLES_SCRIPT
    printf ("echo \n\n") >> TITLES_SCRIPT

    printf ("echo ==\\> %sI %3d: %s\n", KEY, NR, title) >> ID_SCRIPT
    printf ("./getIMDb_IDsFrom-titles.py %s | head -7\n",title) >> ID_SCRIPT
    printf ("echo \n\n") >> ID_SCRIPT
}


BEGIN {
  session_count = 0;
  FS="|"
  OFS="|"
}

{
  if ($3 ~ "[0-9]+") {
    # See if the current line is already in the table
    frame_file = destDir "/frames/Frame"$3".html"
    session_line = ""
    "grep -i \"" session_token "\" " frame_file | getline session_line

    if (session_line == "" ) {
      $6 = "{0}"
      print $0

    } else {
      found = 0;
      split(session_line, array, " ")
      session = array[2]
      for (i=0; i < session_count; i++) {
        if (sessions[i] == session) {
          found = 1
          $6 = "{" i+1 "}"
          print $0
          break
        }
      }

      if (found == 0) {
        $6 = "{" session_count+1 "}"
        sessions[session_count++] = session
        print $0
        s = sprintf("echo '%2d: new session in frame %4s: %s' >&2", session_count, $3, session)
        system(s)
      }
    }

  } else {
    # Comment line, line starting with "#".
    # Requires no processing, just print it
    print $0
  }
}

Add a close command to avoid too many files opened problems (encountered with large libpcap file)

BEGIN {
  session_count = 0;
  FS="|"
  OFS="|"
}

{
  if ($3 ~ "[0-9]+") {
    # See if the current line is already in the table
    frame_file = destDir "/frames/Frame"$3".html"
    session_line = ""
    "grep -i \"" session_token "\" " frame_file | getline session_line
    close(grep)

    if (session_line == "" ) {
      $6 = "{0}"
      print $0

    } else {
      found = 0;
      split(session_line, array, " ")
      session = array[2]
      for (i=0; i < session_count; i++) {
        if (sessions[i] == session) {
          found = 1
          $6 = "{" i+1 "}"
          print $0
          break
        }
      }

      if (found == 0) {
        $6 = "{" session_count+1 "}"
        sessions[session_count++] = session
        print $0
        s = sprintf("echo '%2d: new session in frame %4s: %s' >&2", session_count, $3, session)
        system(s)
      }
    }

  } else {
    # Comment line, line starting with "#".
    # Requires no processing, just print it
    print $0
  }
}


###############################################################################
# BRLTTY - A background process providing access to the console screen (when in
#          text mode) for a blind person using a refreshable braille display.
#
# Copyright (C) 1995-2006 by The BRLTTY Developers.
#
# BRLTTY comes with ABSOLUTELY NO WARRANTY.
#
# This is free software, placed under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation.  Please see the file COPYING for details.
#
# Web Page: http://mielke.cc/brltty/
#
# This software is maintained by Dave Mielke <dave@mielke.cc>.
###############################################################################

/#define[ \t]*BRLAPI_KEY_[A-Z_]+_MASK/ {
  apiMask(substr($2, 12), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_[A-Z_]+_SHIFT/ {
  apiShift(substr($2, 12), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_TYPE_/ {
  apiType(substr($2, 17), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_SYM_/ {
  apiKey(substr($2, 16), $2, getDefineValue(), "")
  next
}

Define KEY_MAX for Python. (dm)

###############################################################################
# BRLTTY - A background process providing access to the console screen (when in
#          text mode) for a blind person using a refreshable braille display.
#
# Copyright (C) 1995-2006 by The BRLTTY Developers.
#
# BRLTTY comes with ABSOLUTELY NO WARRANTY.
#
# This is free software, placed under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation.  Please see the file COPYING for details.
#
# Web Page: http://mielke.cc/brltty/
#
# This software is maintained by Dave Mielke <dave@mielke.cc>.
###############################################################################

/#define[ \t]*BRLAPI_KEY_MAX/ {
  apiMask(substr($2, 12), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_[A-Z_]+_MASK/ {
  apiMask(substr($2, 12), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_[A-Z_]+_SHIFT/ {
  apiShift(substr($2, 12), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_TYPE_/ {
  apiType(substr($2, 17), $2, getDefineValue(), "")
  next
}

/#define[ \t]*BRLAPI_KEY_SYM_/ {
  apiKey(substr($2, 16), $2, getDefineValue(), "")
  next
}


#!/usr/bin/awk -f
#
# Adds github compatible labels to level 1 and 2 markdown headings
# in underline style.
#

#
# Substitute github references with doxygen references.
#
/\(#[_a-z0-9-]*\)/ {
	gsub(/\(#[_a-z0-9-]*\)/, "<__REF__&__REF__>")
	gsub(/<__REF__\(#/, "(@ref ")
	gsub(/\)__REF__>/, ")")
}

#
# If this line is underlining a heading, add a label to the previous
# line.
#
line && (/^===*$/ || /^---*$/) {
	id = tolower(line)
	gsub(/[^_a-z0-9]+/, "-", id)
	line = line " {#" id "}"
}

#
# Print the previous line, after a label might have been added.
#
{print line}

#
# Remember this line when scanning the next one for underlining.
#
{line = $0}

#
# Print the last line.
#
END { print }

Use a file name prefix for generated labels

#!/usr/bin/awk -f
#
# Adds github compatible labels to level 1 and 2 markdown headings
# in underline style.
#

#
# Get file name prefix for references.
#
filename != FILENAME {
	filename = FILENAME
	# strip path
	"pwd" | getline path
	path = path "/"
	prefix = substr(filename, 1, length(path)) == path \
	         ? substr(filename, length(path) + 1) \
	         : filename
	sub(/\.[^.]*$/, "", prefix)
	gsub(/[^_a-z0-9]+/, "-", prefix)
	prefix = "md_" prefix "_"
}

#
# Substitute github references with doxygen references.
#
/\(#[_a-z0-9-]*\)/ {
	gsub(/\(#[_a-z0-9-]*\)/, "<__REF__&__REF__>")
	gsub(/<__REF__\(#/, "(@ref " prefix)
	gsub(/\)__REF__>/, ")")
}

#
# If this line is underlining a heading, add a label to the previous
# line.
#
line && (/^===*$/ || /^---*$/) {
	id = tolower(line)
	gsub(/[^_a-z0-9]+/, "-", id)
	line = line " {#" prefix id "}"
}

#
# Print the previous line, after a label might have been added.
#
{print line}

#
# Remember this line when scanning the next one for underlining.
#
{line = $0}

#
# Print the last line.
#
END { print }


BEGIN {
}

function extension(str){
  n = split(str, parts, ".")
  if (n == 1){
    return "<NO EXTENSION>"
  } else {
    return parts[n]
  }
}

$2 != "total" {
  by_type[extension($2)] += $1
}

$2 ~ "CMakeLists.txt" {
  #cmake should not count as text
  by_type["txt"] -= $1
  by_type["cmake"] += $1
}

$2 ~ "test" {
  by_type[extension($2)] -= $1
  by_type["TEST"] += $1
}

END {

  # join up cpp types
  by_type["cpp"] += by_type["hpp"]
  delete by_type["hpp"]

  #get rid of some filetypes I dont care about
  delete by_type["gitignore"]
  delete by_type["jpg"]
  delete by_type["png"]
  delete by_type["ttf"]
  delete by_type["pdf"]

  #print each extension, collect the total
  total=0
  for (x in by_type) {
    if (by_type[x] > 0) {
      total += by_type[x]
      print (x, by_type[x])
    }
  }

  print("Total:", total)
}

Fix an awk script that doesn't seem to be very portable

BEGIN {
}

function getExtension(str){
  n = split(str, parts, ".")
  if (n == 1){
    return "<NO EXTENSION>"
  } else {
    return parts[n]
  }
}

$2 != "total" {
  by_type[getExtension($2)] += $1
}

$2 ~ "CMakeLists.txt" {
  #cmake should not count as text
  by_type["txt"] -= $1
  by_type["cmake"] += $1
}

$2 ~ "test" {
  by_type[getExtension($2)] -= $1
  by_type["TEST"] += $1
}

END {

  # join up cpp types
  by_type["cpp"] += by_type["hpp"]
  delete by_type["hpp"]

  #get rid of some filetypes I dont care about
  delete by_type["gitignore"]
  delete by_type["jpg"]
  delete by_type["png"]
  delete by_type["ttf"]
  delete by_type["pdf"]

  #print each getExtension, collect the total
  total=0
  for (x in by_type) {
    if (by_type[x] > 0) {
      total += by_type[x]
      print (x, by_type[x])
    }
  }

  print("Total:", total)
}


{ content = $1 ~ /^(content|skin|locale)$/ }
content && $NF ~ /^[a-z]/ { $NF = "/" name "/" $NF }
content {
    sub(/^\.\./, "", $NF);
    $NF = "jar:chrome/" name ".jar!" $NF
}
{
    sub("^\\.\\./liberator/", "", $NF)
    print
}

Fix the modules path in the xpi chrome.manifests

{ content = $1 ~ /^(content|skin|locale)$/ }
content && $NF ~ /^[a-z]/ { $NF = "/" name "/" $NF }
content {
    sub(/^\.\./, "", $NF);
    $NF = "jar:chrome/" name ".jar!" $NF
}
{
    sub("^\\.\\./common/", "", $NF)
    print
}


# Generate MHz_TV_Shows_minutes.csv by processing  SHORT_SPREADSHEET to figure
# average episode length
#

BEGIN {
    FS = "\t"
}

/^Title/ {
    printf ("%s\t%s\t%s\t%s\tAvg Len\t%s\t%s\t%s\t%s\t%s\n",
            $1,$2,$3,$4,$5,$6,$7,$8,$9)
}

/=HYPERLINK/ {
    dur=$4
    sub (/h/,"",dur)
    sub (/m/,"",dur)
    split (dur,fld," ")
    eplen = (fld[1]*60+fld[2])/$3
    printf ("%s\t%s\t%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\n",
            $1,$2,$3,$4,eplen,$5,$6,$7,$8,$9)
}

Print last two lines in Avg

# Generate MHz_TV_Shows_minutes.csv by processing  SHORT_SPREADSHEET to figure
# average episode length
#

BEGIN {
    FS = "\t"
}

/^Title/ {
    printf ("%s\t%s\t%s\t%s\tAvg Len\t%s\t%s\t%s\t%s\t%s\n",
            $1,$2,$3,$4,$5,$6,$7,$8,$9)
}

/=HYPERLINK/ {
    dur=$4
    sub (/h/,"",dur)
    sub (/m/,"",dur)
    split (dur,fld," ")
    eplen = (fld[1]*60+fld[2])/$3
    printf ("%s\t%s\t%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\n",
            $1,$2,$3,$4,eplen,$5,$6,$7,$8,$9)
}

/^Non-blank values/ || /^Total seasons & episodes/ { print }


BEGIN {
	print "V1.0 {";
	print "    global:";
}
{
	# Remove the CR character in case the sources are mapped from
	# a Windows share and contain CRLF line endings
	gsub(/\r/,"", $0);

	# Skip empty lines and comment lines starting with semicolon
	if (NF && !match($0, /^[:space:]*;/))
	{
		print "        "  $0 ";";
	}
}
END {
	print "    local: *;"
	print "};";
}

Handle mscorwks_unixexports.src with better regexp operator for compatibility

BEGIN {
	print "V1.0 {";
	print "    global:";
}
{
	# Remove the CR character in case the sources are mapped from
	# a Windows share and contain CRLF line endings
	gsub(/\r/,"", $0);

	# Skip empty lines and comment lines starting with semicolon
	if (NF && !match($0, /^[ \t]*;/))
	{
		print "        "  $0 ";";
	}
}
END {
	print "    local: *;"
	print "};";
}


#
# Converts the output of 'nm' into a C source containing an array of symbols
# that correspond to functions (t and T in terms of 'nm').
#
# Usage:
#   nm -n image | awk -f nm2c.awk
#
#   Date: Aug 28, 2012
# Author: Eldar Abusalimov
#

BEGIN {
	print "/* Auto-generated file. Do not edit. */";
	print "";
	print "#include <debug/symbol.h>";
	print "#include <stddef.h>";
	print "";
	print "const struct symbol __symbol_table[] = {";
}

/^[0-9a-fA-F]* [tT]/ {
	printf "\t{ (void *) 0x%s, \"%s\" },\n", $1, $3;
}

END {
	print "};";
	print "const size_t __symbol_table_size =";
	print "\tsizeof(__symbol_table) / sizeof(__symbol_table[0]);";
	print "";
}

Fix for symbol table demangled names with spaces

#
# Converts the output of 'nm' into a C source containing an array of symbols
# that correspond to functions (t and T in terms of 'nm').
#
# Usage:
#   nm -n image | awk -f nm2c.awk
#
#   Date: Aug 28, 2012
# Author: Eldar Abusalimov
#

BEGIN {
	print "/* Auto-generated file. Do not edit. */";
	print "";
	print "#include <debug/symbol.h>";
	print "#include <stddef.h>";
	print "";
	print "const struct symbol __symbol_table[] = {";
}

/^[0-9a-fA-F]* [tT]/ {
	split($0,a," [tT] ");
	printf "\t{ (void *) 0x%s, \"%s\" },\n", $1, a[2];
}

END {
	print "};";
	print "const size_t __symbol_table_size =";
	print "\tsizeof(__symbol_table) / sizeof(__symbol_table[0]);";
	print "";
}


BEGIN {
    FS="\n"
    OFS=""
    ORS="\n"
    print "#!/bin/sh"
    print " "
}
# blank lines
/^$/ { next }
# record header
$1 ~ /^\*\*\*\*/ {
    next
}
# summary field
$1 ~ /^[ ]*summary\:/ {
    gsub(/\r/,"");
    idx = match($1, /summary\:(.*)/)
    print "SUMMARY=\"" substr($1, idx + 9) "\""
    next
}
# startdate field
$1 ~ /^[ ]*startdate\: / {
    match($1, /startdate\: /)
    print "STARTDATE=\"`date -d '" substr($1, RSTART + RLENGTH) "-000' '+%a %e %b %R'`\""
    next
}
# vcalendar start tag
$1 ~ /^[ ]*calendardata\: / {
    gsub(/\r/,"");
    match($1, /calendardata\: /)
    print "echo \"" substr($1, RSTART + RLENGTH) "\" >event.ics"
    next
}
# vcalendar end tag
$1 ~ /^END\:VCALENDAR/ {
    gsub(/\r/,"");
    print "echo \"" $1 "\" >>event.ics"
    print "mpack -s \"$SUMMARY - $STARTDATE\" event.ics $1"
    print ""
    next
}
# vcalendar body
{
    gsub(/\r/,"");
    print "echo \"" $0 "\" >> event.ics"
}

Improve shell script (thx 'Barmic')

BEGIN {
    FS="\n";
    OFS="";
    ORS="\n";
    print "#!/bin/sh";
    print "#";
}
# blank lines
/^$/ {
    next;
}
# record header
$1 ~ /^\*\*\*\*/ {
    next;
}
# summary field
$1 ~ /^[ ]*summary\:/ {
    gsub(/\r/,"");
    idx = match($1, /summary\:(.*)/);
    print "SUMMARY=\"" substr($1, idx + 9) "\"";
    next;
}
# startdate field
$1 ~ /^[ ]*startdate\: / {
    match($1, /startdate\: /);
    print "STARTDATE=\"`date -d '" substr($1, RSTART + RLENGTH) "-000' '+%a %e %b %R'`\"";
    next;
}
# vcalendar start tag
$1 ~ /^[ ]*calendardata\: / {
    gsub(/\r/,"");
    match($1, /calendardata\: /);
    print "ICS=$(mktemp --suffix=.ics)";
    print "cat > \"${ICS}\" <<EOF";
    print substr($1, RSTART + RLENGTH);
    next;
}
# vcalendar end tag
$1 ~ /^END\:VCALENDAR/ {
    gsub(/\r/,"");
    print $1;
    print "EOF";
    print "mpack -s \"$SUMMARY - $STARTDATE\" \"${ICS}\" $1";
    print "#";
    next;
}
# vcalendar body
{
    gsub(/\r/,"");
    print $0;
}


#!/usr/bin/awk -f
BEGIN {
    FS = OFS = "\t";
}
{
    len = split($3, words, ", ");

    if (length(N) > 0 && len >= N) next;

    for (i = 1; i <= len - 1; i++) {
        for (j = i + 1; j <= len; j++) {
            print words[i], words[j], ORS, words[j], words[i] | "sort --parallel=$(nproc) -us";
        }
    }
}

Fix the pair generation and also speed up the sorting

#!/usr/bin/awk -f
BEGIN {
    FS  = "\t";
    OFS = "";
}
{
    len = split($3, words, ", ");

    if (length(N) > 0 && len >= N) next;

    for (i = 1; i <= len - 1; i++) {
        for (j = i + 1; j <= len; j++) {
            print words[i], FS, words[j], ORS, words[j], FS, words[i] | "sort --parallel=$(nproc) -S1G -us";
        }
    }
}


{
    if (1==NR)
    {
        startTimestamp = substr($1, 2, length($1) - 2)
        printf(";$FILEVERSION=1.3\n")
        printf(";$STARTTIME=%u.%u\n", mktime(strftime("%Y %m %d 0 0 0", startTimestamp)) / 86400 + 25569, \
                10000000000 / 86400 * (mktime(strftime("%Y %m %d %H %M %S", startTimestamp)) - mktime(strftime("%Y %m %d 0 0 0", startTimestamp))))
    }
    printf("%u) %.3f 1 Rx %s - %s", NR, (substr($1, 2, length($1) - 2) - startTimestamp) * 1000, $3, substr($4, 2, length($4) - 2))
    if (5<=NF)
    {
        for(i=5;i<=NF;i++)
        {
            printf " "$i
        }
    }
    printf "\n"
}

Handle cases where system time is adjusted backwards (e.g. by NTP).

{
    if (1==NR)
    {
        startTimestamp = substr($1, 2, length($1) - 2)
        printf(";$FILEVERSION=1.3\n")
        printf(";$STARTTIME=%u.%u\n", mktime(strftime("%Y %m %d 0 0 0", startTimestamp)) / 86400 + 25569, \
                10000000000 / 86400 * (mktime(strftime("%Y %m %d %H %M %S", startTimestamp)) - mktime(strftime("%Y %m %d 0 0 0", startTimestamp))))
        currentTimeOffset = 0.0
    }
    else
    {
        previousTimeOffset = currentTimeOffset
        currentTimestamp = substr($1, 2, length($1) - 2)
        currentTimeOffset = currentTimestamp - startTimestamp
        if (currentTimeOffset < 0)
        {
            startTimestamp = currentTimestamp + currentTimeOffset
            currentTimeOffset = previousTimeOffset
        }
    }
    printf("%u) %.3f 1 Rx %s - %s", NR, currentTimeOffset * 1000, $3, substr($4, 2, length($4) - 2))
    if (5<=NF)
    {
        for(i=5;i<=NF;i++)
        {
            printf " "$i
        }
    }
    printf "\n"
}


#!/usr/bin/awk
#
# Patch the generated wrapper Swift code to handle special cases
#
BEGIN { etpInit = 0 }
/public convenience init.T: ErrorTypeProtocol./ {
	etpInit = 1
	print "    /// Convenience copy constructor, creating a unique copy"
	print "    /// of the passed in Error.  Needs to be freed using free()"
	print "    /// (automatically done in deinit if you use ErrorType)."
}
/self.init.other.ptr./ {
	if (etpInit) {
		print "	self.init(g_error_copy(other.ptr))"
		etpInit = 0
		next
	}
}
/no reference counting for GError, cannot ref/ { next }
/no reference counting for GError, cannot unref/ {
	print "	    g_error_free(error_ptr)"
	next
}
/ -> GIConv {/, /^}/ {
	sub(/GIConv {/,"GIConv? {")
	sub(/return rv/,"return rv == unsafeBitCast(-1, to: GIConv.self) ? nil : rv")
}
// { print }

Mark CVaListPointer array generators as unavailable on Linux

#!/usr/bin/awk
#
# Patch the generated wrapper Swift code to handle special cases
#
BEGIN { etpInit = 0 ; vaptrptr = 0 }
/public convenience init.T: ErrorTypeProtocol./ {
	etpInit = 1
	print "    /// Convenience copy constructor, creating a unique copy"
	print "    /// of the passed in Error.  Needs to be freed using free()"
	print "    /// (automatically done in deinit if you use ErrorType)."
}
/self.init.other.ptr./ {
	if (etpInit) {
		print "	self.init(g_error_copy(other.ptr))"
		etpInit = 0
		next
	}
}
/no reference counting for GError, cannot ref/ { next }
/no reference counting for GError, cannot unref/ {
	print "	    g_error_free(error_ptr)"
	next
}
/ -> GIConv {/, /^}/ {
	sub(/GIConv {/,"GIConv? {")
	sub(/return rv/,"return rv == unsafeBitCast(-1, to: GIConv.self) ? nil : rv")
}
/UnsafeMutablePointer.CVaListPointer/ {
	vaptrptr = 1
	print "#if !os(Linux)"
}
/^$/ {
	if (vaptrptr) {
		print "#endif"
		vaptrptr = 0
	}
}
/\/\/\// {
	if (vaptrptr) {
		print "#endif"
		vaptrptr = 0
	}
}
// { print }


# $Id: ndcedit.awk,v 1.4 1997/02/22 16:08:19 peter Exp $
NR == 3 {
	print "#"
	print "# This file is generated automatically, do not edit it here!"
	print "# Please change src/usr.sbin/ndc/ndcedit.awk instead"
	print "#"
	print ""

	print "# If there is a global system configuration file, suck it in."
	print "if [ -f /etc/rc.conf ]; then"
	print "\t. /etc/rc.conf"
	print "fi\n"
}
{
	if ($1 == "named") {
		printf "\t\t# $namedflags is imported from /etc/rc.conf\n"
		printf "\t\tif [ \"X${named_flags}\" != X\"NO\" ]; then\n"
		printf "\t\t\tnamed ${named_flags} && {\n"
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		printf "\t\tfi\n"
	} else {
	        if (/PATH=/) {
			gsub(":/usr/ucb:", ":", $0);
		      	if (!/export/) {
				$0=$0"\nexport PATH";
			}
		}
		print;
	}
}

Check named_enable rather than just named_flags. PR: 3893 (sort of)

# $Id: ndcedit.awk,v 1.5 1997/05/27 07:19:57 jkh Exp $
NR == 3 {
	print "#"
	print "# This file is generated automatically, do not edit it here!"
	print "# Please change src/usr.sbin/ndc/ndcedit.awk instead"
	print "#"
	print ""

	print "# If there is a global system configuration file, suck it in."
	print "if [ -f /etc/rc.conf ]; then"
	print "\t. /etc/rc.conf"
	print "fi\n"
}
{
	if ($1 == "named") {
		printf "\t\t# $named_flags is imported from /etc/rc.conf\n"
		printf "\t\tif [ \"X${named_enable}\" = X\"YES\" ]; then\n"
		printf "\t\t\tnamed ${named_flags} && {\n"
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		getline
		printf "\t%s\n", $0
		printf "\t\tfi\n"
	} else {
	        if (/PATH=/) {
			gsub(":/usr/ucb:", ":", $0);
		      	if (!/export/) {
				$0=$0"\nexport PATH";
			}
		}
		print;
	}
}


BEGIN {
    FS = "\""
}

/\/us\/movie\// {
    numMovies += 1
    shortURL = $6
    printf ("%s    \"https://www.britbox.com%s\"", trailingComma, shortURL) >> EPISODES_JSON_FILE
    trailingComma = ",\n"
}

/\/us\/show\// {
    numShows += 1
    shortURL = $6
    printf ("%s    \"https://www.britbox.com%s\"", trailingComma, shortURL) >> EPISODES_JSON_FILE
    printf ("%s    \"https://www.britbox.com%s\"", trailingComma, shortURL) >> SEASONS_JSON_FILE
    trailingComma = ",\n"
}

END {
    print "" >> EPISODES_JSON_FILE
    print "" >> SEASONS_JSON_FILE
    print "==> Found " numMovies " movies"
    print "==> Found " numShows " shows"
}

Fix extra comma in json file

BEGIN {
    FS = "\""
}

/\/us\/movie\// {
    numMovies += 1
    shortURL = $6
    printf ("%s    \"https://www.britbox.com%s\"", trailingEpisodesComma, shortURL) \
        >> EPISODES_JSON_FILE
    trailingEpisodesComma = ",\n"
}

/\/us\/show\// {
    numShows += 1
    shortURL = $6
    printf ("%s    \"https://www.britbox.com%s\"", trailingEpisodesComma, shortURL) \
        >> EPISODES_JSON_FILE
    trailingEpisodesComma = ",\n"
    printf ("%s    \"https://www.britbox.com%s\"", trailingSeasonsComma, shortURL) \
        >> SEASONS_JSON_FILE
    trailingSeasonsComma = ",\n"
}

END {
    print "" >> EPISODES_JSON_FILE
    print "" >> SEASONS_JSON_FILE
    print "==> Found " numMovies " movies"
    print "==> Found " numShows " shows"
}


Add script for generating vendor header include lines

# Usage: awk -f <this_script> vendor/MKxxxx.h vendor/MKxxyy.h vendor/MKzzz.h ...
/Processor[s]?:/ {
    i=0;
    if (FNR == NR) {
        printf "#if";
    } else {
        printf "#elif";
    }
    while(match($0, /MK.*/)) {
        if (i>0) {
            printf " || \\\n   ";
        }
        printf " defined(CPU_MODEL_%s)", substr($0, RSTART, RLENGTH);
        getline;
        i++;
    }
    printf("\n#include \"%s\"\n", FILENAME);
    nextfile;
}
END {
  print "#endif"
}


#!/usr/bin/awk -f
# cat *.tdb | tdbout -t publisher,plugin,publisher:info[tester],status

BEGIN {
  FS="\t"
  pn = 0
}

{
    nn = split($2,na,/\./)
    lp2 = na[nn]
    if (!(($1,lp2) in b)) {
      p[pn] = $1
      n[pn] = lp2
  #    n[pn] = $2
      r[pn] = $3
      pn++
    }
    b[$1,lp2]++
    c[$1,lp2,$4]++
    x[$4]++
    tt++
}

END {
  s[0] = "expected"
  s[1] = "exists"
  s[2] = "manifest"
  s[3] = "wanted"
  s[4] = "crawling"
  s[5] = "testing"
  s[6] = "notReady"
  s[7] = "released"
  s[8] = "down"
  s[9] = "superseded"
  s[10] = "zapped"
  sn = 11

  sc[0] = "expe"
  sc[1] = "exis"
  sc[2] = "mani"
  sc[3] = "want"
  sc[4] = "craw"
  sc[5] = "test"
  sc[6] = "notR"
  sc[7] = "rele"
  sc[8] = "down"
  sc[9] = "supe"
  sc[10] = "zapp"
  scn = 11

  #print out header
  printf "Publisher\tPlugin\tT\tTotal"
  for (j = 0 ; j < scn ; j++) {
    if (x[s[j]] > 0) {
    printf "\t%s", sc[j]
    }
  }
  printf "\n"

  #print out publisher, plugin, tester, total aus
  for (i = 0 ; i < pn ; i++) {
    printf "%s\t%s\t%s\t%d", p[i], n[i], r[i], b[p[i],n[i]]
    for (j = 0 ; j < sn ; j++) {
      if (x[s[j]] > 0){
      if (c[p[i],n[i],s[j]] == 0) {
      printf "\t.."
    } else {
        printf "\t%d", c[p[i],n[i],s[j]]
      }
    }
    }
    printf "\n"
  }
    #print out bottom line sums
    printf "Publisher\tPlugin\tT\t%d", tt
    for (j = 0 ; j < sn ; j++) {
      if (x[s[j]] > 0) {
        printf "\t%d", x[s[j]]
      }
    }

  printf "\n"
}


Add AWK script to generate a frequency table from a column of numbers

#!/usr/bin/env awk -f
#
# Generates a frequency table.
#
# Usage: frequency_table
#
# Input:
#   - a column of numbers
#
# Output:
#   - frequency table

{
	total += 1
	table[$1] += 1
}
END {
	for (v in table) {
		count = table[v]
		print v OFS count OFS count/total
	}
}


Add Tobias Waldekranz's awesome little AWK script


Add an awk script used in one-vs-the-rest classification example.

BEGIN{ FS="\t"; OFS="\t"; }
{
 	possible_labels=$1;
 	rowid=$2;
    label=$3;
    features=$4;

 	label_count = split(possible_labels, label_array, ",");

	for(i = 1; i <= label_count; i++) {
    	if (label_array[i] == label)
      		print rowid, label, 1, features;
      	else
      		print rowid, label_array[i], -1, features;
	}
}
END{}


Add script to convert old submission format to new format.

#!/usr/bin/env awk -f

{
    for (i = 1; i <= NF; i++) {
        if (i == 3) printf "-1 ";
        printf $i" "
    }
    printf "\n"
}


# WebScraper has problems getting incomplete data.
#
# Crosscheck the info in EPISODES with the info in SEASONS. Count up episodes
# and compare with the number of episodes listed in the seasons file.

# For now these seem more likely a problem in scraping SEASONS than EPISODES
# so it could be these are false positives in generating spreadsheets.
# Problems listed in BBox_anomalies files are more likely to be real.

# INVOCATION
#    awk -f verifyBBoxInfoFrom-webscraper.awk BBox_episodeInfo-180421.123042.txt

/ movie / {
    title = $3
    numEpisodes = $5
    if (numEpisodes == 0)
        print
}

/ show / {
    numShows += 1
    showTitle[numShows] = $3
    shouldHave[numShows] = $5
    doesHave[numShows] = 0
    if (numEpisodes == 0)
        print
}

/^         / {
    epis  = NF-1
    if ($epis !~ /^[[:digit:]]*$/)
        print "==> Bad input line " NR "\n" $0
    else
        doesHave[numShows] += $epis
}

END {
    print ""
    for ( i = 1; i <= numShows; i++ ) {
        if (shouldHave[i] != doesHave[i]) {
            print "==> show  "showTitle[i] " has " doesHave[i] " instead of " \
                shouldHave[i] " episodes."
        }
    }
}


#!/usr/bin/awk -f

{
    protein = ""
    flag = 0    # Get rid of line with label
    while (("curl -Ls http://www.uniprot.org/uniprot/"$1".fasta" | getline prot_line) > 0) {
        if (flag)
            # Append line to protein
            protein = protein prot_line
        else
            # We're on the first line - ignore label and set flag
            flag = 1
    }

    first = 1    # Print label only once
    startidx = 1
    do {
        where = match(substr(protein, startidx), /N[^P][ST][^P]/)
        if (where != 0) {
            if (first) {
                # Print label, start location string
                print $0
                loc_string = where + startidx - 1
                # Reset flag
                first = 0
            }
            else {
                # Append to location string
                loc_string = loc_string " " where + startidx - 1
            }
            # Update offset: start one after start of last match
            startidx += where
        }
    } while (where != 0)

    # Did we find something?
    if (loc_string)
        print loc_string
}


Add a crosscheck for the SEASONS_SORTED_FILE

# Crosscheck the number of episodes of each show found by counting them (grep -c)
# in EPISODES_SORTED_FILE versus the number added up from SEASONS_SORTED_FILE
# Both numbers are found by processing a checkEpisodeInfo file
#
# For now these seem more likely a problem in scraping SEASONS_SORTED_FILE than EPISODES_SORTED_FILE
# so it could be these are false positives in generating spreadsheets. The case is stronger for
# problems listed in checkBBox_anomalies files.

# INVOCATION:
#    awk -f crosscheckInfo.awk checkEpisodeInfo-180415.185805.txt

/ movie / {
    title = $3
    numEpisodes = $5
    if (numEpisodes == 0)
        print
}

/ show / {
    numShows += 1
    showTitle[numShows] = $3
    shouldHave[numShows] = $5
    doesHave[numShows] = 0
    if (numEpisodes == 0)
        print
}

/^         / {
    epis  = NF-1
    if ($epis !~ /^[[:digit:]]*$/)
        print "==> Bad input line " NR "\n" $0
    else
        doesHave[numShows] += $epis
}

END {
    for ( i = 1; i <= numShows; i++ ) {
        if (shouldHave[i] != doesHave[i]) {
            print "==> show  "showTitle[i] " has " doesHave[i] " instead of " \
                shouldHave[i] " episodes."
        }
    }
}


Add AWK script to merge comma-terminated lines

#!/usr/bin/awk -f
#
# AWK script to join multiple lines if the preceeding line ends with a comma (,).
#
# For example:
#
#   1,
#   2,
#   3
#
# Turns into:
#
#   1, 2, 3
#

/,$/ {
    ORS=""
    print $0
    do {
        getline
        print $0
    } while ($0 ~ /,$/)
    ORS="\n"
    print ""
}


# Helper for converting Netflix "viewing activity" into hyperlinks
#

# Death in Paradise: Season 6: "Man Overboard, Part 2"
# Ugly Delicious: Season 1: "Pizza"
# Hinterland: Season 3: "Episode 2"

# INVOCATION:
#    Browse to https://www.netflix.com/viewingactivity
#    Save as 'Page Source'
#    awk -f generateLinksFrom-NetflixActivityPage.awk ~/Downloads/Netflix.html

BEGIN {
    RS="\<"
    # print 10 records unless overridden with "-v maxRecordsToPrint=<n>"
    if (maxRecordsToPrint == "") maxRecordsToPrint = 10
}

/div class="col date nowrap"/ {
    split ($0,fld,">")
    date = fld[2]
}

/a href="\/title\// {
    split ($0,fld,">")
    title = fld[2]
    split ($0,fld,"\"")
    URL = fld[2]
    gsub (/"/,"",title)
    printf ("=HYPERLINK(\"https://www.netflix.com/%s\";\"%s\")\t%s\tNetflix Streaming\n",\
        URL,title,date)
    recordsPrinted += 1
    if (recordsPrinted >= maxRecordsToPrint)
        exit
}


Add AWK script to compute the corrected sample standard deviation

#!/usr/bin/env awk -f
#
# Computes the corrected sample standard deviation.
#
# Usage: stdev
#
# Input:
#   - a column of numbers
#
# Output:
#   - corrected sample standard deviation
#
# Notes:
#   - Uses [Welford's method][1].
#
# [1]: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm

BEGIN {
	delta = 0
	mean = 0
	M2 = 0
	N = 0
}
{
	N += 1
	delta = $1 - mean
	mean += delta / N
	M2 += delta * ($1 - mu)
}
END {
	if (N < 2) {
		print 0
	} else {
		print sqrt(M2 / (N-1))
	}
}


Make script to process top level BritBox shows

BEGIN {
    FS="\t"
    print "Sortkey\tTitle\tSeasons\tDuration\tYear\tRating\tDescription"
}

# if needed for debugging record placment, replace "/nosuchrecord/" below
/nosuchrecord/ {
    print ""
    print NR " - " $0
    for ( i = 1; i <= NF; i++ ) {
        print "field " i " = " $i
    }
}

{
    for ( i = 1; i <= NF; i++ ) {
        if ($i == "null")
            $i = ""
    }
}

/\/us\/movie\/|\/us\/show\//{
    URL = $3
    showTitle = $4
    Year = $5
    NumSeasons = $6
    Duration = $7
    Rating = $8
    Description = $9

    sub (/ Season[s]/,"",NumSeasons)
    sub( / min/,"",Duration)

    # Convert duration from minutes to HMS
    secs = 0
    mins = Duration % 60
    hrs = int(Duration / 60)
    HMS = sprintf ("%02d:%02d:%02d", hrs, mins, secs)

    # Titles starting with "The" should not sort based on "The"
    if (match (showTitle, /^The /)) {
        showTitle = substr(showTitle, 5) ", The"
    }
}

/\/us\/movie\// {
    # Extract movie sortkey from URL
    nflds = split (URL,fld,"_")
    if (URL ~ /_[[:digit:]]*$/) {
        sortkey = sprintf ("M%05d", fld[nflds])
        printf \
            ("%s %s - mv\t=HYPERLINK(\"https://www.britbox.com%s\";\"%s, %s, %s\"\)\t\t%s\t%s\t%s\t%s\n", \
             showTitle, sortkey, URL, showTitle, sortkey, \
             Title, HMS, Year, Rating, Description)
    }
    next
}

/\/us\/show\// {
    # Extract show sortkey from URL
    nflds = split (URL,fld,"_")
    if (URL ~ /_[[:digit:]]*$/) {
        sortkey = sprintf ("S%05d", fld[nflds])
        printf \
            ("%s %s - sh\t=HYPERLINK(\"https://www.britbox.com%s\";\"%s, %s, %s\"\)\t\t%s\t%s\t%s\t%s\n", \
             showTitle, sortkey, URL, showTitle, sortkey, \
             Title, HMS, Year, Rating, Description)
    }
    next
}


# Helper for converting Netflix "viewing activity" into hyperlinks
#
# Since there is no way to paste an embedded hyperlink into a text filei,
# paste the link and the title on two consecutive lines, e.g.
#
# https://www.netflix.com/title/80174814
# Borderliner: Season 1: "Milla’s Future"
# https://www.netflix.com/title/80203122
# Luxury Travel Show: Season 1: "Chiang Mai & Eze"
# https://www.netflix.com/title/80217826
# Kavin Jay: Everybody Calm Down!

/^https:/ {
    link = $0
    if ((getline title) > 0) {
        gsub (/"/,"\"\"",title)
        printf ("=HYPERLINK(\"%s\";\"%s\")\n",link,title)
    }
}


Add debugging tool which prints WebScraper field names

# Print field numbers and field names from a WebScraper csv file saved in tsv format

# INVOCATION:
#   awk -f printFieldNamesFrom-webscraper.awk -v maxRecordsToPrint=5 BritBoxSeasons-test-tabs.csv

BEGIN {
    FS="\t"
    # print 3 records unless overridden with "-v maxRecordsToPrint=<n>"
    if (maxRecordsToPrint == "") maxRecordsToPrint = 3
}

NR <= maxRecordsToPrint {
    print "Record " NR
    for ( i = 1; i <= NF; i++ ) {
        print i " - " $i
    }
    print ""
}


#!/usr/bin/awk -f
BEGIN{
    FS = OFS = "\t";
}
{
    split($3, words, ", ");
    for (i = 1; i <= length(words) - 1; i++) {
        for (j = i + 1; j <= length(words); j++) {
            print words[i], words[j];
            print words[j], words[i];
        }
    }
}


Add only unique reads for paired end filter

BEGIN {
  OFS="\t";
  lastid="";
  id_counts=0;
}
{
  if ( $1 ~ /^@/ )
  {
    # headers go straight through
    print $0;
    next;
  }
  if (lastid == "") {
    lastid=$1;
    r1["read"] = $0;
    r1["chr"] = $3;
    r1["tags"] = "";
    for(i=12;i<NF;i++) { r1["tags"]=r1["tags"] $i " ";}
    r1["tags"]=r1["tags"] $i;
    next;
  }

  if ( lastid == $1 ) {
    id_counts++;
    if ( id_counts == 2 ) {
      r2["read"] = $0;
      r2["chr"] = $3;
      r2["tags"] = "";
      for(i=12;i<NF;i++) { r2["tags"]=r2["tags"] $i " ";}
      r2["tags"]=r2["tags"] $i;
    }
  } else if ( lastid != $1 ) {
    if ( 2 == id_counts ) {
      # two matching ends of a pair, should we include them?
      if ( (r1["chr"] ~ /chr([[:digit:]]+|[XY]|MT)/) && (r2["chr"] ~ /chr([[:digit:]]+|[XY]|MT)/) &&
           (r1["tags"] ~ /XT:A:U/) && (r2["tags"] ~ /XT:A:U/) ) {
             print r1["read"];
             print r2["read"];
      }
    }
    id_counts=1;
    lastid=$1;
    r1["read"] = $0;
    r1["chr"] = $3;
    r1["tags"]="";
    for(i=12;i<NF;i++) { r1["tags"]=r1["tags"] $i " ";}
    r1["tags"]=r1["tags"] $i;
  }

}
END {
  if ( 2 == id_counts ) {
    # two matching ends of a pair, should we include them?
    if ( (r1["chr"] ~ /chr([[:digit:]]+|[XY]|MT)/) && (r2["chr"] ~ /chr([[:digit:]]+|[XY]|MT)/) &&
         (r1["tags"] ~ /XT:A:U/) && (r2["tags"] ~ /XT:A:U/) ) {
           print r1["read"];
           print r2["read"];
    }
  }
}


Add awk script to deobfuscate wasm stack traces.

# Usage:
# awk -f deobfuscate_wasm_log.awk <wat_file> <log_file>

# Process the log file which is the 2nd argument.
FILENAME == ARGV[2] {
  match($0, /<anonymous>:wasm-function\[([0-9]+)\]/, groups)
  print $0, functions[groups[1]]
}

# Collects function declarations
/^\(func/ {
  functions[last_function++] =  $2
}


#!/usr/bin/env awk -f
#
# Computes the mid-range.
#
# Usage: mid-range
#
# Input:
#   - a column of numbers
#
# Output:
#   - mid-range

!i++ {
	# Only for the first record:
	max = $1
	min = $1
}
{
	if ($1 > max) {
		max = $1
	} else if ($1 < min) {
		min = $1
	}
}
END {
	print (max + min) / 2
}


Add a short program that rewrites the testdata/rsyncd.log timestamps to nowish.

BEGIN{
        now = systime()
        format = "%Y/%m/%d %H:%M:%S"

}
{
        split($1, DATE, "/")
        split($2, TIME, ":")
        $1 = ""
        $2 = ""
        t = mktime(DATE[1] " " DATE[2] " " DATE[3] " " TIME[1] " " TIME[2] " " TIME[3])
        if (delta == "") {
                delta = now - t
        }
        print strftime(format, t + delta) $0
}


Add an awk script for reading CVC's output.

#!/usr/bin/awk -f

BEGIN{
	outarr[0] = "";
	outarr[1] = "";
	outarr[2] = "";
	outarr[3] = "";
	idx = 0;
}

/.*sparticus.*/{
	sub(/bv/, "", $12);
	outarr[idx] = $12;
	idx++;
	if (idx == 4) {
		print outarr[0] "|" outarr[1] "|" outarr[2] "|" outarr[3]
		idx = 0;
	}
}


# Invoke as awk addloadexample.awk

BEGIN {
  lms = 0;
}

tolower($0) ~ /^[# \t]*loadmodule[ \t]/ {
  if ( $2 == MODULE "_module" ) {
    print "LoadModule " MODULE "_module " LIBPATH "/mod_" MODULE DSO;
    lms = 2;
    next;
  }
  # test $3 since # LoadModule is split into two tokens
  else if ( $3 == MODULE "_module" ) {
    print $1 "LoadModule " MODULE "_module " LIBPATH "/mod_" MODULE DSO;
    lms = 2;
    next;
  }
  else if ( ! lms ) lms = 1;
}

$0 ~ /^[ \t]*$/ && lms == 1 {
  print "LoadModule " MODULE "_module " LIBPATH "/mod_" MODULE DSO;
  lms = 2;
}

tolower($0) ~ /^[# \t]*include[ \t]/ && $NF == EXAMPLECONF {
  lms = 3;
}

{ print }

END {
  if ( lms < 3 ) {
    if ( ! /^[ \t]*$/ ) print "";
    if ( lms < 2 ) {
      print "LoadModule " MODULE "_module " LIBPATH "/mod_" MODULE DSO;
      print "";
    }
    if ( length(EXAMPLECONF) ) {
      print "# Example mod_" MODULE " configuration";
      print "#Include " EXAMPLECONF "\n";
    }
  }
}


Array<Cell<Key->Item>?> makeCellEntryArray<Key,Item>(Integer size)
    given Key satisfies Object
    given Item satisfies Object {

    return makeArray<Cell<Key->Item>?>(size, (Integer index) null);
}
Array<Cell<Element>?> makeCellElementArray<Element>(Integer size) {
    return makeArray<Cell<Element>?>(size, (Integer index) null);
}

Change makeArray -> arrayOfSize to fix compilation error

Array<Cell<Key->Item>?> makeCellEntryArray<Key,Item>(Integer size)
    given Key satisfies Object
    given Item satisfies Object {

    return arrayOfSize<Cell<Key->Item>?>(size, null);
}
Array<Cell<Element>?> makeCellElementArray<Element>(Integer size) {
    return arrayOfSize<Cell<Element>?>(size, null);
}