Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DICT server dictionary lookup [script attached] #30

Closed
Boruch-Baum opened this issue Oct 28, 2016 · 1 comment
Closed

DICT server dictionary lookup [script attached] #30

Boruch-Baum opened this issue Oct 28, 2016 · 1 comment

Comments

@Boruch-Baum
Copy link

Boruch-Baum commented Oct 28, 2016

Hello Tats,

I noticed that this package included a cgi-bin script for querying 'dictionary.goo.ne.jp', so I thought I'd offer a second script that queries any DICT server and can prioritize any DICT database.

#!/bin/sh
# w3mdict.cgi - A dictd dictionary query cgi for w3m
#
# REQUIREMENTS:
# + dict client software
# + an address of a dict server, for variable ${DICT_SERVER}
# + a name of a favorite database on that server, for variable
#   ${FAVORITE_DATABASE}
# OPTIONALLY:
# + locally install a dict server (eg. dictd) and a collection
#   of dict databases (eg. wordnet, aka "wn")
# INSTALLATION:
#1] Copy this file to your ~/.w3m/cgi-bin folder
#2] Mark it executable (ie chmod +x ~/.w3m/cgi-bin/w3mdict.cgi)
#3] From inside w3m, type 'O' for the options page, and for the
#   setting "URL of dictionary lookup command",
#   enter "file:/cgi-bin/w3mdict.cgi"
DICT_SERVER="localhost"
FAVORITE_DATABASE="wn"
RETURN_MESSAGE="\n\nPress 'B' to return to the previous page."
printf "Content-type: text/plain\n"
type dict \
|| {
  # Originally, we inconsiderately failed silently ...
  #     printf "W3m-control: BACK\n\n"
  printf "\n\nERROR: dict client software not found${RETURN_MESSAGE}"
  exit
  }
# First, we check only our best and favorite database. This is most
# likely to give us a best defintion, and avoids displaying a long and
# cluttered page with entries from many databases.
dict --host "${DICT_SERVER}" \
     --database "${FAVORITE_DATABASE}" \
     "${QUERY_STRING}" 2>&1 \
&& {
  printf "${RETURN_MESSAGE}"
  } \
|| {
  # The initial attempt failed, so let's search ALL databases
  # available on the server.
  dict --host "${DICT_SERVER}" \
       "${QUERY_STRING}" 2>&1 \
  && {
    printf "${RETURN_MESSAGE}"
    } \
  || {
    # No defintions were found in any of the server's databases, so
    # let's return to the favorite database in order to retrieve its
    # guess of what we meant to type. Originally, for this case, we
    # pushed the user's default action to be entering another word for
    # a dict defintion, so the print command was:
    #     printf "W3m-control: DICT_WORD\n\n"
    # Now, we need only print a blank line to separate the cgi header
    # from the page content.
    printf "\n"
    dict --host "${DICT_SERVER}" \
         --database "${FAVORITE_DATABASE}" \
         "${QUERY_STRING}" 2>&1
    printf "${RETURN_MESSAGE}"
    }
  }
tats pushed a commit that referenced this issue Oct 30, 2016
@tats
Copy link
Owner

tats commented Oct 30, 2016

Merged. Thank you for your contribution.

@tats tats closed this as completed Oct 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants