Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:normalize and improve usage of quotes, printf vs echo and subshells
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ee4fbdb256dc67bcdd4833d314851e5fe129342b
User & Date: brandon 2016-04-06 20:30:08
Context
2016-04-06
20:30
fix bug in logging read papers check-in: dc57cc0020 user: brandon tags: trunk
20:30
normalize and improve usage of quotes, printf vs echo and subshells check-in: ee4fbdb256 user: brandon tags: trunk
20:02
clean up indentation check-in: 844f122db4 user: brandon tags: trunk
Changes

Changes to paperq.in.

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229
...
253
254
255
256
257
258
259

260

261
262
263
264
265
266
267
...
286
287
288
289
290
291
292
293
294
295
296
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
EOF
    exit 0
}

add_doc () {
    grep -q "$1" ${QFILE} || echo $1 >>${QFILE}
    echo "`date '+[%Y-%m-%d %H:%M]'` ADDED   $1" >>${LOGFILE}
}

get_doc () {
    check_pos
    sed -n "${pos}p" ${QFILE}
}

rem_doc () {
    check_pos

    echo "`date '+[%Y-%m-%d %H:%M]'` REMOVED `sed -n "${pos}p" ${QFILE}`" >>${LOGFILE}
    sed -i "${pos}d" ${QFILE}
}

open_doc () {
    check_pos
    $(printf "$OPENCMD" `get_doc $pos`)
    echo "`date '+[%Y-%m-%d %H:%M]'` READ    `sed -n "$1p" ${QFILE}`" >>${LOGFILE}

    rem_doc
}

print_bib () {
    if ! grep -q $1 $2; then
        return
    fi
    if [ -f ${BIBCACHE} ]; then
        wrapped_bib="`echo $1 | zdbf ${BIBCACHE} 2>/dev/null`"
    fi
    if [[ "x$wrapped_bib" == "x" ]]; then
        wrapped_bib="`paperbib -a${MAXAUTHORS} -w${WRAP} -i'	' $1 <$2 2>/dev/null`"
    fi
    printf "%s:${wrapped_bib}\n\n" $pos
}

doc_info () {
    # Print information on the document: bibliographic data unless the -f
    # option was used.
    local doc=`get_doc`
    local key=`basename ${doc} .pdf`
    if $files; then
        printf "`get_doc`\n"
    elif [[ "x$BIBTEXDIR" != "x" ]]; then
        for bibfile in "${BIBTEXDIR}"/*.bib; do
            print_bib "${key}" "${bibfile}"
        done
    elif [[ "x$BIBTEXFILE" != "x" ]]; then
        print_bib "${key}" "${BIBTEXFILE}"
    else
        printf "No bibtex file specified.  Set either 'bibtex-file FILE' or \
'bibtex-dir DIR' in ${CONFFILE}\n"
    fi
}

list_docs () {
    # List all of the documents in the queue
    local numdocs
    if $files || [[ "x$BIBTEXFILE" == "x" && "x$BIBTEXDIR" == "x" ]]; then
        awk '{print FNR": \t" $1}' ${QFILE}
    else
        numdocs=`sed '/^ *$/d' ${QFILE} | wc -l | cut -f1 -d' '`
        if [[ "$numdocs" == "0" ]]; then
            return
        fi
        for pos in `seq 1 $numdocs`; do
            doc_info false
        done
    fi
}

archive_queue () {
    # Make a tarball of all the papers in the queue
    mkdir /tmp/paperq-papers
    local -i n=1
    while read line; do
        paper_file=`basename $line`
        if (( n < 10 )); then
            cp $line /tmp/paperq-papers/0${n}_$paper_file
        else
            cp $line /tmp/paperq-papers/${n}_$paper_file
        fi
        n=$(( n+1 ))
    done <${QFILE}
    dir=`pwd`
    cd /tmp && tar -czf $dir/paperq-papers.tar.gz paperq-papers
    rm -rf /tmp/paperq-papers
}

check_pos () {
    if [ ! -e ${QFILE} ]; then
        printf "The queue has not yet been created.  Add some documents to it first.\n"

        exit 1
    fi
    len=`sed '/^ *$/d' ${QFILE} | wc -l | cut -f1 -d' '`
    if (( len == 0 )); then
        printf "The queue is empty.\n"
        exit 1
    elif [ $pos -gt $len ]; then
        printf "The specified position is larger than the queue length.\n"
        exit 1
    fi
................................................................................
[ -f ${QFILE} ] || touch ${QFILE}
[ -f ${LOGFILE} ] || touch ${LOGFILE}
if [ -f ${CONFFILE} ]; then
    parse_conf
else
    touch ${CONFFILE}
fi

[ -f ${BIBCACHE} ] || (command -v zdbc >/dev/null && zdbc --num-buckets=${BIBCACHE_SIZE} ${BIBCACHE})



files=false
pos=1
mode=open_doc
while getopts "oalirpfhvtzn:" opt; do
    case $opt in
................................................................................
             for doc in "$@"; do \
                 add_doc "`realpath "$doc"`"; \
             done;;
    list_docs) list_docs ;;
    doc_info) doc_info ;;
    rem_doc) rem_doc ;;
    open_doc) open_doc ;;
    peek_doc) $(printf "$OPENCMD" `get_doc $pos`) ;;
    print_doc) $(printf "$PRINTCMD" `get_doc $pos`) ;;
    archive_queue) archive_queue ;;
esac







|
|









>
|





|
|
>








|


|

|





|
|

|

|
|


|

|
|









|



|










|







|






|
>


|







 







>
|
>







 







|
|


122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
...
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
291
292
293
294
295
296
297
298
299
300
301
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
EOF
    exit 0
}

add_doc () {
    grep -q "$1" ${QFILE} || printf "%s\n" "$1" >>${QFILE}
    printf "%s ADDED %s\n" "$(date '+[%Y-%m-%d %H:%M]')" "$1" >>${LOGFILE}
}

get_doc () {
    check_pos
    sed -n "${pos}p" ${QFILE}
}

rem_doc () {
    check_pos
    printf "%s REMOVED %s\n" "$(date '+[%Y-%m-%d %H:%M]')" \
           "$(sed -n "${pos}p" ${QFILE})" >>${LOGFILE}
    sed -i "${pos}d" ${QFILE}
}

open_doc () {
    check_pos
    $(printf "$OPENCMD" "$(get_doc $pos)")
    printf "%s READ %s\n" "$(date '+[%Y-%m-%d %H:%M]')" \
           "$(sed -n "$1p" ${QFILE})" >>${LOGFILE}
    rem_doc
}

print_bib () {
    if ! grep -q $1 $2; then
        return
    fi
    if [ -f ${BIBCACHE} ]; then
        wrapped_bib="$(echo "$1" | zdbf ${BIBCACHE} 2>/dev/null)"
    fi
    if [[ "x$wrapped_bib" == "x" ]]; then
        wrapped_bib="$(paperbib -a${MAXAUTHORS} -w${WRAP} -i'	' $1 <$2 2>/dev/null)"
    fi
    printf "%s:%s\n\n" "$pos" "$wrapped_bib"
}

doc_info () {
    # Print information on the document: bibliographic data unless the -f
    # option was used.
    local doc=$(get_doc)
    local key=$(basename ${doc} .pdf)
    if $files; then
        printf "%s\n" "$(get_doc)"
    elif [[ "x$BIBTEXDIR" != "x" ]]; then
        for bibfile in "$BIBTEXDIR"/*.bib; do
            print_bib "$key" "$bibfile"
        done
    elif [[ "x$BIBTEXFILE" != "x" ]]; then
        print_bib "$key" "$BIBTEXFILE"
    else
        printf "No bibtex file specified.  Set either 'bibtex-file FILE' or "
        printf "'bibtex-dir DIR' in ${CONFFILE}\n"
    fi
}

list_docs () {
    # List all of the documents in the queue
    local numdocs
    if $files || [[ "x$BIBTEXFILE" == "x" && "x$BIBTEXDIR" == "x" ]]; then
        awk '{print FNR": \t" $1}' ${QFILE}
    else
        numdocs=$(sed '/^ *$/d' ${QFILE} | wc -l | cut -f1 -d' ')
        if [[ "$numdocs" == "0" ]]; then
            return
        fi
        for pos in $(seq 1 $numdocs); do
            doc_info false
        done
    fi
}

archive_queue () {
    # Make a tarball of all the papers in the queue
    mkdir /tmp/paperq-papers
    local -i n=1
    while read line; do
        paper_file=$(basename $line)
        if (( n < 10 )); then
            cp $line /tmp/paperq-papers/0${n}_$paper_file
        else
            cp $line /tmp/paperq-papers/${n}_$paper_file
        fi
        n=$(( n+1 ))
    done <${QFILE}
    dir=$(pwd)
    cd /tmp && tar -czf $dir/paperq-papers.tar.gz paperq-papers
    rm -rf /tmp/paperq-papers
}

check_pos () {
    if [ ! -e ${QFILE} ]; then
        printf "The queue has not yet been created.  Add some documents to it "
        printf "first.\n"
        exit 1
    fi
    len=$(sed '/^ *$/d' ${QFILE} | wc -l | cut -f1 -d' ')
    if (( len == 0 )); then
        printf "The queue is empty.\n"
        exit 1
    elif [ $pos -gt $len ]; then
        printf "The specified position is larger than the queue length.\n"
        exit 1
    fi
................................................................................
[ -f ${QFILE} ] || touch ${QFILE}
[ -f ${LOGFILE} ] || touch ${LOGFILE}
if [ -f ${CONFFILE} ]; then
    parse_conf
else
    touch ${CONFFILE}
fi
if [ -f ${BIBCACHE} ] && command -v zdbc >/dev/null; then
    zdbc --num-buckets=${BIBCACHE_SIZE} ${BIBCACHE}
fi


files=false
pos=1
mode=open_doc
while getopts "oalirpfhvtzn:" opt; do
    case $opt in
................................................................................
             for doc in "$@"; do \
                 add_doc "`realpath "$doc"`"; \
             done;;
    list_docs) list_docs ;;
    doc_info) doc_info ;;
    rem_doc) rem_doc ;;
    open_doc) open_doc ;;
    peek_doc) $(printf "$OPENCMD" $(get_doc $pos)) ;;
    print_doc) $(printf "$PRINTCMD" $(get_doc $pos)) ;;
    archive_queue) archive_queue ;;
esac