#!/bin/sh # man2ps, (c) 2004,2005 Toni Corvera, published under a BSD license # # Saves a man page as either a PostScript (PS) or as a PDF file. # # This file can be used directly as a script or as a function including it # from some file parsed on login, such as .bashrc # Current version VER=0.9.2 # Command name for information messages CMD=man2ps # --- Simple localization support --- # Language codes _EN=0 _ES=1 _CA=2 # Translated strings _STR_USAGE=( "Usage: ${CMD} [-p|--pdf] [-h|--help] command" "Uso: ${CMD} [-p|--pdf] [-h|--help] comando" "Ús: ${CMD} [-p|--pdf] [-h|--help] comanda" ) _STR_HELP=( "${CMD} v${VER}, (c) 2004,2005 Toni Corvera saves a man page as a PostScript or PDF file" "${CMD} v${VER}, (c) 2004,2005 Toni Corvera guarda una página de manual como archivo PostScript o PDF" "${CMD} v${VER}, (c) 2004,2005 Toni Corvera guarda una pŕgina de manual com un arxiu PostScript o PDF" ) _STR_NOPDF=( "ps2pdf wasn't found, can't export to PDF" "No se ha encontrado ps2pdf, no se puede exportar a PDF" "No s'ha trobat ps2pdf, no es pot exportar a PDF" ) _STR_PDFVER=( "Using ps2pdf version:" "Usando ps2pdf en su variante:" "Fent servir ps2pdf en sa versió:" ) # Language detection case "$LANG" in es*) _L=$_ES ;; ca*) _L=$_CA ;; *) _L=$_EN ;; esac # The function with the core of the functionality, will take # a command and two possible options: # -p / --pdf to export as PDF (by default will export as PS) # -h / --help to print a short help message man2ps() { PDF=0 # Rudimentary command line parsing while [ "$1" ]; do case "$1" in -h|--help) echo "${_STR_HELP[${_L}]}" echo "${_STR_USAGE[${_L}]}" return 0 ;; --pdf|-p) PDF=1 ;; *) break ;; esac shift done if [ -z "$1" ]; then echo "${_STR_USAGE[${_L}]}" >&2 return 1 fi if [ $PDF -eq 0 ]; then man -t "$1" > "${1}.ps" else for prog in ps2pdf14 ps2pdf13 ps2pdf12 ps2pdf do ps2pdf=`which $prog` && break done if [ -z "$ps2pdf" ]; then echo "${_STR_NOPDF[${_L}]}" >&2 return 2 fi echo "${_STR_PDFVER[${_L}]} `basename \"${ps2pdf}\"`" >&2 man -t "$1" | ${ps2pdf} - > "${1}.pdf" fi } # Alias function in cases where the file is sourced. When the file # is used as a script a symbolic link should be created to have the same # effect if [ "$PS1" ]; then man2pdf() { man2ps --pdf $* } else # If used as a script call the function if [ "`basename \"$0\"`" == "man2pdf" ]; then man2ps --pdf $* else man2ps $* fi fi