I call it my ctaginator

The Linux Kernel source is too big to generate all tags for all files. I want only a subset of C files and the corresponding headers. Here is my first take at it. yes it is in python. The program is designed to be run from the root of the Linux Kernel tree.

#!/usr/bin/python3

import sys
from plumbum import local,  FG

print("Hello, Tristate Area.")

sources = []

for file in sys.argv[1:]:
    sources.append(file)
    print("file = " + file)
    with open(file) as cfile:
        for line in cfile.readlines():
            if line.startswith("#include"):
                for part in line.split():
                    if part.startswith("<"):
                        header = part.replace("<","").replace(">","")
                        header = "include/" + header
                        sources.append(header)
sources =sorted(set(sources))

ctags = local['ctags']
print(ctags.bound_command(sources).formulate())
ctags.bound_command(sources) & FG

A Typical run looks like this:

~/ctaginator drivers/mailbox/pcc.c  drivers/mailbox/mailbox.c drivers/net/mctp/mctp-pcc.c
Hello, Tristate Area.
file = drivers/mailbox/pcc.c
file = drivers/mailbox/mailbox.c
file = drivers/net/mctp/mctp-pcc.c
['/usr/bin/ctags', 'drivers/mailbox/mailbox.c', 'drivers/mailbox/pcc.c', 'drivers/net/mctp/mctp-pcc.c', 'include/acpi/acpi_bus.h', 'include/acpi/acpi_drivers.h', 'include/acpi/acrestyp.h', 'include/acpi/actbl.h', 'include/acpi/pcc.h', 'include/linux/acpi.h', 'include/linux/cleanup.h', 'include/linux/delay.h', 'include/linux/device.h', 'include/linux/err.h', 'include/linux/hrtimer.h', 'include/linux/if_arp.h', 'include/linux/init.h', 'include/linux/interrupt.h', 'include/linux/io-64-nonatomic-lo-hi.h', 'include/linux/io.h', 'include/linux/kernel.h', 'include/linux/list.h', 'include/linux/log2.h', 'include/linux/mailbox_client.h', 'include/linux/mailbox_controller.h', 'include/linux/module.h', 'include/linux/mutex.h', 'include/linux/netdevice.h', 'include/linux/of.h', 'include/linux/platform_device.h', 'include/linux/spinlock.h', 'include/linux/string.h', 'include/net/mctp.h', 'include/net/mctpdevice.h']

When I ran ctags from the command line by hand:

ctags drivers/net/mctp/mctp-pcc.c include/acpi/pcc.h drivers/mailbox/mailbox.c drivers/mailbox/mailbox.h drivers/mailbox/pcc.c include/linux/hrtimer.h kernel/time/hrtimer.c include/linux/platform_device.h include/linux/mailbox_controller.h include/linux/mailbox_client.h include/linux/device.h include/linux/skbuff.h

I get a file of size 155502. Running ctaginator I get a file of size 491157. Feels about right.

However, this does not include headers only included from other headers. To do that, we would need something recursive. That something would need cycle-breaking ability….

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.