indexgph2db.sh - gopher-lawn - The gopher lawn gopher directory project.
 (HTM) git clone git://bitreich.org/gopher-lawn/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/gopher-lawn/
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
       ---
       indexgph2db.sh (2011B)
       ---
            1 #!/bin/sh
            2 
            3 set -x
            4 
            5 if [ $# -gt 0 ];
            6 then
            7         inputfile="$1"
            8 else
            9         inputfile="/dev/stdin"
           10 fi
           11 
           12 printdbtmpl() {
           13         linetype="$1"
           14         linktext="$2"
           15         selector="$3"
           16         host="$4"
           17         port="$5"
           18         description="$6"
           19 
           20         case "${linetype}" in
           21         0|H)
           22                 linetypetext="text"
           23                 ;;
           24         1|h|w)
           25                 linetypetext="link"
           26                 ;;
           27         2)
           28                 linetypetext="cso"
           29                 ;;
           30         3|+|i)
           31                 linetypetext="error"
           32                 ;;
           33         6)
           34                 linetypetext="uuencoded"
           35                 ;;
           36         7)
           37                 linetypetext="search"
           38                 ;;
           39         8|T)
           40                 linetypetext="telnet"
           41                 ;;
           42         *)
           43                 linetypetext="binary"
           44                 ;;
           45         esac
           46 
           47         tmplfile="$host-$(printf "%s\n" "${selector}" \
           48                 | tr '/' '_').${linetypetext}"
           49 
           50         printf "Type: %s\n" "${linetypetext}" > "${tmplfile}"
           51         printf "Selector: %s\n" "${selector}" >> "${tmplfile}"
           52         printf "Host: %s\n" "${host}" >> "${tmplfile}"
           53         printf "Port: %s\n" "${port}" >> "${tmplfile}"
           54         printf "LinkName: %s\n" "${linktext}" >> "${tmplfile}"
           55         printf "Description: %s\n" "${description}" >> "${tmplfile}"
           56         printf "Category: \n" >> "${tmplfile}"
           57         printf "Keywords: \n" >> "${tmplfile}"
           58 }
           59 
           60 gphline=""
           61 cat "${inputfile}" \
           62 | while read -r line;
           63 do
           64         if [ -z "${line}" ];
           65         then
           66                 if [ -n "${gphline}" ];
           67                 then
           68                         case "${gphline}" in
           69                         '[1|<< back'*)
           70                                 ;;
           71                         *)
           72                                 linetype="$(printf "%s\n" "${gphline}" \
           73                                         | cut -d '[' -f 2 | cut -d '|' -f 1)";
           74                                 linktext="$(printf "%s\n" "${gphline}" \
           75                                         | cut -d '|' -f 2)";
           76                                 selector="$(printf "%s\n" "${gphline}" \
           77                                         | cut -d '|' -f 3)";
           78                                 host="$(printf "%s\n" "${gphline}" \
           79                                         | cut -d '|' -f 4)";
           80                                 port="$(printf "%s\n" "${gphline}" \
           81                                         | cut -d '|' -f 5 | cut -d ']' -f 1)";
           82 
           83                                 printdbtmpl "${linetype}" "${linktext}" \
           84                                         "${selector}" "${host}" "${port}" \
           85                                         "${description}"
           86                         ;;
           87                         esac
           88                 fi
           89 
           90                 gphline=""
           91                 description=""
           92                 continue;
           93         fi
           94 
           95         case "${line}" in
           96         \[*)
           97                 if [ -z "${gphline}" ];
           98                 then
           99                         gphline="${line}"
          100                         continue;
          101                 fi
          102                 ;;
          103         *) 
          104                 if [ -n "${gphline}" ];
          105                 then
          106                         if [ -z "${description}" ];
          107                         then
          108                                 description="${line}"
          109                         else
          110                                 description="${description} ${line}"
          111                         fi
          112                 fi
          113                 continue;
          114                 ;;
          115         esac
          116 done
          117