summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2023-05-05 19:16:11 -0700
committerLouie S <louie@example.com>2023-05-05 19:18:23 -0700
commitd7ce7c21ad5fe18b7d0a4e6a496cce2783a50d1e (patch)
tree68a182570c4dd7bf1edb5ed6f4c438900326038f
parenta26adab1566f7ad0574c93b841f640363a799092 (diff)
First commit for glibc docset
-rw-r--r--.gitignore2
-rw-r--r--Makefile17
-rw-r--r--README17
-rw-r--r--README.md33
-rw-r--r--README.template16
-rw-r--r--src/Info.plist8
-rw-r--r--src/icon.pngbin0 -> 1617 bytes
-rwxr-xr-xsrc/index-page.sh35
-rwxr-xr-xsrc/index-terms.sh33
-rwxr-xr-xsrc/index.sh43
-rw-r--r--src/lib/create_table7
-rw-r--r--src/lib/insert8
12 files changed, 118 insertions, 101 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c1b7024
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+tmp
+glibc.docset
diff --git a/Makefile b/Makefile
index 9339745..32b8aaa 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-#DOCSET_NAME = ...
+DOCSET_NAME = glibc
DOCSET_DIR = $(DOCSET_NAME).docset
CONTENTS_DIR = $(DOCSET_DIR)/Contents
@@ -10,10 +10,10 @@ INDEX_FILE = $(RESOURCES_DIR)/docSet.dsidx
ICON_FILE = $(DOCSET_DIR)/icon.png
ARCHIVE_FILE = $(DOCSET_NAME).tgz
-#SRC_ICON = src/icon.png
+SRC_ICON = src/icon.png
-#MANUAL_URL = ...
-#MANUAL_FILE = tmp/...
+MANUAL_URL = https://www.gnu.org/software/libc/manual/html_node/libc-html_node.tar.gz
+MANUAL_FILE = tmp/libc-html_node.tar.gz
ERROR_DOCSET_NAME = $(error DOCSET_NAME is unset)
WARNING_MANUAL_URL = $(warning MANUAL_URL is unset)
@@ -71,9 +71,14 @@ $(DOCUMENTS_DIR): $(RESOURCES_DIR) $(MANUAL_FILE)
$(INFO_PLIST_FILE): src/Info.plist $(CONTENTS_DIR)
cp src/Info.plist $@
-$(INDEX_FILE): src/index.sh $(DOCUMENTS_DIR)
+$(INDEX_FILE): src/index-page.sh src/index-terms.sh $(DOCUMENTS_DIR)
rm -f $@
- src/index.sh $@ $(DOCUMENTS_DIR)/*.html
+ src/index-page.sh $@ $(DOCUMENTS_DIR)/libc/*.html
+ src/index-terms.sh "Entry" $@ $(DOCUMENTS_DIR)/libc/Concept-Index.html
+ src/index-terms.sh "Type" $@ $(DOCUMENTS_DIR)/libc/Type-Index.html
+ src/index-terms.sh "Function" $@ $(DOCUMENTS_DIR)/libc/Function-Index.html
+ src/index-terms.sh "Variable" $@ $(DOCUMENTS_DIR)/libc/Variable-Index.html
+ src/index-terms.sh "File" $@ $(DOCUMENTS_DIR)/libc/File-Index.html
$(ICON_FILE): src/icon.png $(DOCSET_DIR)
cp $(SRC_ICON) $@
diff --git a/README b/README
new file mode 100644
index 0000000..08484e4
--- /dev/null
+++ b/README
@@ -0,0 +1,17 @@
+Here is a script and a Makefile for generating a GNU C Library (or "glibc") docset for Dash. The script is loosely based on benzado's script for GNU Make https://github.com/benzado/gnu-make-dash-docset.
+
+- GNU C Library: https://www.gnu.org/software/libc/libc.html
+- Dash: https://kapeli.com/dash
+- dash-docset-generation-template: https://github.com/lshprung/dash-docset-generation-template
+
+To generate a docset from the latest edition of the GNU C Library Manual, simply
+execute `make` from the same directory as this README file. The latest edition
+will be downloaded from https://www.gnu.org/software/libc/manual/html_node/libc-html_node.tar.gz and packaged appropriately.
+
+Requirements:
+
+- any POSIX-compliant shell
+- curl
+- make
+- pup
+- sqlite3
diff --git a/README.md b/README.md
deleted file mode 100644
index 7fb5e46..0000000
--- a/README.md
+++ /dev/null
@@ -1,33 +0,0 @@
-# Dash Docset Template
-
-This is a repository providing a template to package a Dash docset from HTML source documentation. Files that need to be manually configured are listed below. Additional fine tuning is also recommended, depending on the quirks of the documentation being packaged. An example docset packaging script for GNU Make using this template can be seen [here](https://github.com/lshprung/gnu-make-dash-docset)
-
-### `README.template`
-
-This file will provide a README for the packaging script. Replace `<NAME>`, `<UPSTREAM LINK>`, and `<UPSTREAM HOST>` with appropriate values.
-
-### `Makefile`
-
-This file will build the docset.
-
-- `DOCSET_NAME` must be set
-- `MANUAL_FILE` must be set
- - If the script should download documentation from the internet, `MANUAL_URL` must also be set. If not, ensure a `.tgz` archive of the HTML documentation exists at `tmp/MANUAL.tgz` (where MANUAL is the name of the archive)
-
-### `src/icon.png`
-
-If you want to associate an icon with the docset, it should be saved to `src/icon.png`.
-
-### `src/index.sh`
-
-This is the main script that builds the docset index. This script does not require any manual modifications, but you will probably want to make additions/changes to improve the quality of your docset and accomodate any quirks.
-
-### `src/Info.plist`
-
-This file contains metadata for the docset. Replace `<!-- VALUE -->` with appropriate values. It may be useful to refer to the `Info.plist` file of an existing docset for reference.
-
----
-
-### Credits
-
-Created by [lshprung](https://github.com/lshprung), and originally based on [benzado](https://github.com/benzado)'s [gnu-make-dash-docset](https://github.com/benzado/gnu-make-dash-docset).
diff --git a/README.template b/README.template
deleted file mode 100644
index 8c254e4..0000000
--- a/README.template
+++ /dev/null
@@ -1,16 +0,0 @@
-Here is a script and a Makefile for generating a <NAME> docset for Dash. The script is loosely based on benzado's script for GNU Make https://github.com/benzado/gnu-make-dash-docset.
-
-- <NAME>: <UPSTREAM LINK>
-- Dash: https://kapeli.com/dash
-
-To generate a docset from the latest edition of the <NAME> Manual, simply
-execute `make` from the same directory as this README file. The latest edition
-will be downloaded from <UPSTREAM HOST> and packaged appropriately.
-
-Requirements:
-
-- any POSIX-compliant shell
-- curl
-- make
-- pup
-- sqlite3
diff --git a/src/Info.plist b/src/Info.plist
index 111baae..d306013 100644
--- a/src/Info.plist
+++ b/src/Info.plist
@@ -3,12 +3,14 @@
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
- <string><!-- VALUE --></string>
+ <string>glibc</string>
<key>CFBundleName</key>
- <string><!-- VALUE --></string>
+ <string>GNU C Library</string>
<key>DocSetPlatformFamily</key>
- <string><!-- VALUE --></string>
+ <string>glibc</string>
<key>isDashDocset</key>
<true/>
+ <key>dashIndexFilePath</key>
+ <string>libc/index.html</string>
</dict>
</plist>
diff --git a/src/icon.png b/src/icon.png
new file mode 100644
index 0000000..9b18522
--- /dev/null
+++ b/src/icon.png
Binary files differ
diff --git a/src/index-page.sh b/src/index-page.sh
new file mode 100755
index 0000000..a57fd07
--- /dev/null
+++ b/src/index-page.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env sh
+
+# shellcheck source=./lib/create_table
+. "$(dirname "$0")"/lib/create_table
+# shellcheck source=./lib/insert
+. "$(dirname "$0")"/lib/insert
+
+DB_PATH="$1"
+shift
+
+get_title() {
+ FILE="$1"
+
+ pup -p -f "$FILE" 'title text{}' | \
+ sed 's/ (The GNU C Library)//g' | \
+ tr -d \\n | \
+ sed 's/\"/\"\"/g'
+}
+
+insert_pages() {
+ # Get title and insert into table for each html file
+ while [ -n "$1" ]; do
+ unset PAGE_NAME
+ unset PAGE_TYPE
+ PAGE_NAME="$(get_title "$1")"
+ PAGE_TYPE="Guide"
+ if [ -n "$PAGE_NAME" ]; then
+ insert "$DB_PATH" "$PAGE_NAME" "$PAGE_TYPE" "$(basename "$1")"
+ fi
+ shift
+ done
+}
+
+create_table "$DB_PATH"
+insert_pages "$@"
diff --git a/src/index-terms.sh b/src/index-terms.sh
new file mode 100755
index 0000000..f74af03
--- /dev/null
+++ b/src/index-terms.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env sh
+
+# shellcheck source=./lib/create_table
+. "$(dirname "$0")"/lib/create_table
+# shellcheck source=./lib/insert
+. "$(dirname "$0")"/lib/insert
+
+TYPE="$1"
+shift
+DB_PATH="$1"
+shift
+
+insert_index_terms() {
+ # Get each term from an index page and insert
+ while [ -n "$1" ]; do
+ grep -Eo "<a href.*</a>:" "$1" | while read -r line; do
+ insert_term "$line"
+ done
+
+ shift
+ done
+}
+
+insert_term() {
+ LINK="$1"
+ NAME="$(echo "$LINK" | pup -p 'a text{}' | sed 's/\"\"//g' | tr -d \\n)"
+ PAGE_PATH="$(echo "$LINK" | pup -p 'a attr{href}')"
+
+ insert "$DB_PATH" "$NAME" "$TYPE" "$PAGE_PATH"
+}
+
+create_table "$DB_PATH"
+insert_index_terms "$@"
diff --git a/src/index.sh b/src/index.sh
deleted file mode 100755
index 35ed08c..0000000
--- a/src/index.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/env sh
-
-DB_PATH="$1"
-shift
-
-create_table() {
- sqlite3 "$DB_PATH" "CREATE TABLE IF NOT EXISTS searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);"
- sqlite3 "$DB_PATH" "CREATE UNIQUE INDEX IF NOT EXISTS anchor ON searchIndex (name, type, path);"
-}
-
-
-get_title() {
- FILE="$1"
-
- pup -p -f "$FILE" 'title text{}' | \
- tr -d \\n | \
- sed 's/\"/\"\"/g'
-}
-
-insert() {
- NAME="$1"
- TYPE="$2"
- PAGE_PATH="$3"
-
- sqlite3 "$DB_PATH" "INSERT INTO searchIndex(name, type, path) VALUES (\"$NAME\",\"$TYPE\",\"$PAGE_PATH\");"
-}
-
-insert_pages() {
- # Get title and insert into table for each html file
- while [ -n "$1" ]; do
- unset PAGE_NAME
- unset PAGE_TYPE
- PAGE_NAME="$(get_title "$1")"
- PAGE_TYPE="Guide"
- if [ -n "$PAGE_NAME" ]; then
- insert "$PAGE_NAME" "$PAGE_TYPE" "$(basename "$1")"
- fi
- shift
- done
-}
-
-create_table
-insert_pages "$@"
diff --git a/src/lib/create_table b/src/lib/create_table
new file mode 100644
index 0000000..a783c50
--- /dev/null
+++ b/src/lib/create_table
@@ -0,0 +1,7 @@
+create_table() {
+ DB_PATH="$1"
+
+ sqlite3 "$DB_PATH" "CREATE TABLE IF NOT EXISTS searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);"
+ sqlite3 "$DB_PATH" "CREATE UNIQUE INDEX IF NOT EXISTS anchor ON searchIndex (name, type, path);"
+}
+
diff --git a/src/lib/insert b/src/lib/insert
new file mode 100644
index 0000000..baa13bd
--- /dev/null
+++ b/src/lib/insert
@@ -0,0 +1,8 @@
+insert() {
+ DB_PATH="$1"
+ NAME="$2"
+ TYPE="$3"
+ PAGE_PATH="$4"
+
+ sqlite3 "$DB_PATH" "INSERT INTO searchIndex(name, type, path) VALUES (\"$NAME\",\"$TYPE\",\"libc/$PAGE_PATH\");"
+}