diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/index.sh | 95 | ||||
-rwxr-xr-x | src/index_pages.sh | 42 | ||||
-rwxr-xr-x | src/index_terms.sh | 39 | ||||
-rw-r--r-- | src/lib/create_table | 7 | ||||
-rw-r--r-- | src/lib/get_type | 13 | ||||
-rw-r--r-- | src/lib/insert | 8 |
6 files changed, 109 insertions, 95 deletions
diff --git a/src/index.sh b/src/index.sh deleted file mode 100755 index a2a52d0..0000000 --- a/src/index.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env sh - -DB_PATH="$1" -shift - -get_title() { - FILE="$1" - - PATTERN="<[tT][iI][tT][lL][eE]>.*</[tT][iI][tT][lL][eE]>" - - #Find pattern in file - grep -Eo "$PATTERN" "$FILE" | - #Remove tag - sed 's/<[^>]*>//g' | \ - #Remove '(automake)' - sed 's/(Autoconf)//g' | \ - #Remove trailing space - sed 's/[ ]*$//g' | \ - #Remove trailing man categories - sed 's/ [0-9][mx]\?$//g' | \ - #Replace '&' with '&' - sed 's/&/&/g' | \ - # ReplACE '–' with '-' - sed 's/–/-/g' | \ - #Replace '<' with '<' - sed 's/</</g' -} - -get_type() { - FILE="$1" - CATEGORY="$(echo "$FILE" | grep -Eo "\.[0-9].?\.html$")" - - if [ -n "$CATEGORY" ]; then - case "$CATEGORY" in - .1*) echo "Command" ;; - .2*) echo "Service" ;; - .3*) echo "Function" ;; - *) echo "Object" ;; - esac - fi -} - -insert() { - NAME="$1" - TYPE="$2" - PAGE_PATH="$3" - - sqlite3 "$DB_PATH" "INSERT INTO searchIndex(name, type, path) VALUES (\"$NAME\",\"$TYPE\",\"$PAGE_PATH\");" -} - -skip_check() { - NAME="$1" - - case "$NAME" in - [A-Z]) return 1 ;; - "Source Browser") return 1 ;; - terminal_interface*) return 1 ;; - esac -} - -# Get title and insert into table for each html file -main() { - while [ -n "$1" ]; do - unset PAGE_NAME - unset PAGE_TYPE - - #echo "FILE: $1" - # Recurse into subdirectories - if [ -d "$1" ]; then - main "$1"/* - else - PAGE_NAME="$(get_title "$1")" - if skip_check "$PAGE_NAME"; then - if [ -n "$PAGE_NAME" ]; then - PAGE_TYPE="$(get_type "$1")" - #get_type "$1" - if [ -z "$PAGE_TYPE" ]; then - PAGE_TYPE="Guide" - fi - #echo "$PAGE_NAME" - #echo "$PAGE_TYPE" - insert "$PAGE_NAME" "$PAGE_TYPE" "$(echo "$1" | sed 's/^ncurses.docset\/Contents\/Resources\/Documents\///')" - fi - fi - fi - - shift - done -} - -# Create table -sqlite3 "$DB_PATH" "CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);" -sqlite3 "$DB_PATH" "CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);" - -main "$@" diff --git a/src/index_pages.sh b/src/index_pages.sh new file mode 100755 index 0000000..030bda5 --- /dev/null +++ b/src/index_pages.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env sh + +# shellcheck source=./lib/create_table +. "$(dirname "$0")"/lib/create_table +# shellcheck source=./lib/insert +. "$(dirname "$0")"/lib/insert +# shellcheck source=./lib/get_type +. "$(dirname "$0")"/lib/get_type + +DB_PATH="$1" +shift + +get_title() { + FILE="$1" + + pup -p -f "$FILE" 'title text{}' | \ + tr -d \\n | \ + #Remove trailing man categories + sed 's/ [0-9][mx]\?$//g' | \ + 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")" + if [ -n "$PAGE_NAME" ]; then + PAGE_TYPE="$(get_type "$1")" + if [ -z "$PAGE_TYPE" ]; then + PAGE_TYPE="Guide" + fi + insert "$DB_PATH" "$PAGE_NAME" "$PAGE_TYPE" "$(echo "$1" | sed 's/^ncurses.docset\/Contents\/Resources\/Documents\///')" + 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..a2b39fb --- /dev/null +++ b/src/index_terms.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env sh + +# shellcheck source=./lib/create_table +. "$(dirname "$0")"/lib/create_table +# shellcheck source=./lib/insert +. "$(dirname "$0")"/lib/insert +# shellcheck source=./lib/get_type +. "$(dirname "$0")"/lib/get_type + +DB_PATH="$1" +shift + +insert_index_terms() { + # Get each term from an index page and insert + while [ -n "$1" ]; do + grep -Eoi "^[a-zA-Z_ ]{45}<STRONG><A HREF=\"[^\"]*\">[^<]*</A></STRONG>" "$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)" + NAME="$(echo "$LINK" | cut -d ' ' -f 1)" + PAGE_PATH="$(echo "$LINK" | pup -p 'a attr{href}')" + + TYPE=$(get_type "$PAGE_PATH") + if [ -z "$TYPE" ]; then + TYPE="Guide" + fi + + insert "$DB_PATH" "$NAME" "$TYPE" "man/$PAGE_PATH" +} + +create_table "$DB_PATH" +insert_index_terms "$@" 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/get_type b/src/lib/get_type new file mode 100644 index 0000000..9f04b53 --- /dev/null +++ b/src/lib/get_type @@ -0,0 +1,13 @@ +get_type() { + FILE="$1" + CATEGORY="$(echo "$FILE" | grep -Eo "\.[0-9].?\.html$")" + + if [ -n "$CATEGORY" ]; then + case "$CATEGORY" in + .1*) echo "Command" ;; + .2*) echo "Service" ;; + .3*) echo "Function" ;; + *) echo "Object" ;; + esac + fi +} diff --git a/src/lib/insert b/src/lib/insert new file mode 100644 index 0000000..31c1b4c --- /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\",\"$PAGE_PATH\");" +} |