Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 7c8c5e3
  • /
  • arch
  • /
  • metag
  • /
  • tbx
  • /
  • tbistring.c
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:f90cd082206587d9c87f1bdd1c8d7aac19ea9af5
directory badge Iframe embedding
swh:1:dir:32dfc6ba6b1c1865ff63980d6c9f3b1f1aee6138
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
tbistring.c
/*
 * tbistring.c
 *
 * Copyright (C) 2001, 2002, 2003, 2005, 2007, 2012 Imagination Technologies.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the
 * Free Software Foundation.
 *
 * String table functions provided as part of the thread binary interface for
 * Meta processors
 */

#include <linux/export.h>
#include <linux/string.h>
#include <asm/tbx.h>

/*
 * There are not any functions to modify the string table currently, if these
 * are required at some later point I suggest having a seperate module and
 * ensuring that creating new entries does not interfere with reading old
 * entries in any way.
 */

const TBISTR *__TBIFindStr(const TBISTR *start,
			   const char *str, int match_len)
{
	const TBISTR *search = start;
	bool exact = true;
	const TBISEG *seg;

	if (match_len < 0) {
		/* Make match_len always positive for the inner loop */
		match_len = -match_len;
		exact = false;
	} else {
		/*
		 * Also support historic behaviour, which expected match_len to
		 * include null terminator
		 */
		if (match_len && str[match_len-1] == '\0')
			match_len--;
	}

	if (!search) {
		/* Find global string table segment */
		seg = __TBIFindSeg(NULL, TBID_SEG(TBID_THREAD_GLOBAL,
						  TBID_SEGSCOPE_GLOBAL,
						  TBID_SEGTYPE_STRING));

		if (!seg || seg->Bytes < sizeof(TBISTR))
			/* No string table! */
			return NULL;

		/* Start of string table */
		search = seg->pGAddr;
	}

	for (;;) {
		while (!search->Tag)
			/* Allow simple gaps which are just zero initialised */
			search = (const TBISTR *)((const char *)search + 8);

		if (search->Tag == METAG_TBI_STRE) {
			/* Reached the end of the table */
			search = NULL;
			break;
		}

		if ((search->Len >= match_len) &&
		    (!exact || (search->Len == match_len + 1)) &&
		    (search->Tag != METAG_TBI_STRG)) {
			/* Worth searching */
			if (!strncmp(str, (const char *)search->String,
				     match_len))
				break;
		}

		/* Next entry */
		search = (const TBISTR *)((const char *)search + search->Bytes);
	}

	return search;
}

const void *__TBITransStr(const char *str, int len)
{
	const TBISTR *search = NULL;
	const void *res = NULL;

	for (;;) {
		/* Search onwards */
		search = __TBIFindStr(search, str, len);

		/* No translation returns NULL */
		if (!search)
			break;

		/* Skip matching entries with no translation data */
		if (search->TransLen != METAG_TBI_STRX) {
			/* Calculate base of translation string */
			res = (const char *)search->String +
				((search->Len + 7) & ~7);
			break;
		}

		/* Next entry */
		search = (const TBISTR *)((const char *)search + search->Bytes);
	}

	/* Return base address of translation data or NULL */
	return res;
}
EXPORT_SYMBOL(__TBITransStr);

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API