summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2019-01-28 11:43:57 +0100
committerDirk Engling <erdgeist@erdgeist.org>2019-01-28 11:43:57 +0100
commit28d6e80db08f44a0a0c822a30d4b83e6312e5b85 (patch)
treed153847dfb23ebe8a929e6d96d9ceb8591d82fc6
parent05ed6c06edfd2f3214cb2dcb1933bf067648823d (diff)
Try to make accessing filenames with spaces more robust
-rwxr-xr-xmakecolumns.sh28
1 files changed, 14 insertions, 14 deletions
diff --git a/makecolumns.sh b/makecolumns.sh
index c38a791..4920550 100755
--- a/makecolumns.sh
+++ b/makecolumns.sh
@@ -77,12 +77,12 @@ do_processfile_version_3() {
77} 77}
78 78
79size() { 79size() {
80 stat -f %z `printf %0${filename_len}d $1` 80 stat -f %z `printf %0${filename_len}d "$1"`
81} 81}
82 82
83get_dword() { 83get_dword() {
84 # $1 file 84 # $1 file
85 hexdump -n 4 -v -e '" " 1/4 "%u"' `printf %0${filename_len}d ${1}` 85 hexdump -n 4 -v -e '" " 1/4 "%u"' `printf %0${filename_len}d "${1}"`
86} 86}
87 87
88handle_format_version_1() { 88handle_format_version_1() {
@@ -165,7 +165,7 @@ handle_format_version_2() {
165handle_format_version_3() { 165handle_format_version_3() {
166 echo "Working on $1. Detected pre-2004 Telefonbuch version." 166 echo "Working on $1. Detected pre-2004 Telefonbuch version."
167 # Extract teiln.dat 167 # Extract teiln.dat
168 do_decompress_version_3 $1/[Dd][Aa][Tt]/[Tt][Ee][Ii][Ll][Nn].[Dd][Aa][Tt] "teiln.dat" 168 do_decompress_version_3 "$1/[Dd][Aa][Tt]/[Tt][Ee][Ii][Ll][Nn].[Dd][Aa][Tt]" "teiln.dat"
169 169
170 # See how long each filename is 170 # See how long each filename is
171 export filename_len=$(( `ls | head -n 1 | wc -c` - 1 )) 171 export filename_len=$(( `ls | head -n 1 | wc -c` - 1 ))
@@ -251,7 +251,7 @@ handle_format_version_3() {
251 251
252 # If street names come in an extra file, extract 252 # If street names come in an extra file, extract
253 # street names first 253 # street names first
254 streets=$1/[Dd][Aa][Tt]/[Ss][Tt][Rr][Aa][Ss][Ss][Ee][Nn].[Dd][Aa][Tt] 254 streets="$1/[Dd][Aa][Tt]/[Ss][Tt][Rr][Aa][Ss][Ss][Ee][Nn].[Dd][Aa][Tt]"
255 [ -f ${streets} ] && do_processfile_version_3 ${streets} "street name" 99_Strassenname convert_zeros 255 [ -f ${streets} ] && do_processfile_version_3 ${streets} "street name" 99_Strassenname convert_zeros
256 256
257 # extract street names if 07_unknown contains street indexes 257 # extract street names if 07_unknown contains street indexes
@@ -272,7 +272,7 @@ handle_format_version_3() {
272 tidy_streetnames 07_Strasse 272 tidy_streetnames 07_Strasse
273 fi 273 fi
274 274
275 karto=$1/[Dd][Aa][Tt]/[Kk][Aa][Rr][Tt][Oo].[Dd][Aa][Tt] 275 karto="$1/[Dd][Aa][Tt]/[Kk][Aa][Rr][Tt][Oo].[Dd][Aa][Tt]"
276 if [ -f ${karto} ]; then 276 if [ -f ${karto} ]; then
277 do_processfile_version_3 ${karto} "geo coordinates" 90_Geokoordinaten_hnr_raw 277 do_processfile_version_3 ${karto} "geo coordinates" 90_Geokoordinaten_hnr_raw
278 278
@@ -285,7 +285,7 @@ handle_format_version_3() {
285} 285}
286 286
287handle_format_version_4() { 287handle_format_version_4() {
288 if [ -f $1/branchcodes.tl ]; then 288 if [ -f "$1/branchcodes.tl" ]; then
289 is_yp=true 289 is_yp=true
290 echo "Working on $1. Detected post-2003 Yellow Pages version." 290 echo "Working on $1. Detected post-2003 Yellow Pages version."
291 else 291 else
@@ -294,14 +294,14 @@ handle_format_version_4() {
294 fi 294 fi
295 295
296 printf "Extracting street names ... " 296 printf "Extracting street names ... "
297 extract_version_4 $1/streets.tl 297 extract_version_4 "$1/streets.tl"
298 298
299 cat file_* | tr '\n\0' '\t\n' > 99_Strassenname 299 cat file_* | tr '\n\0' '\t\n' > 99_Strassenname
300 rm file_* 300 rm file_*
301 printf "done.\n" 301 printf "done.\n"
302 302
303 printf "Extracting phonebook.db ... " 303 printf "Extracting phonebook.db ... "
304 extract_version_4 $1/phonebook.db 304 extract_version_4 "$1/phonebook.db"
305 305
306 rows=`find . -name file_\* | wc -l` 306 rows=`find . -name file_\* | wc -l`
307 printf "done.\n" 307 printf "done.\n"
@@ -353,17 +353,17 @@ handle_format_version_4() {
353 tr '\t' ' ' < 04_05_Namenszusatz_Addresszusatz | sed -E s/' +'/' '/g > 04_Zusaetze 353 tr '\t' ' ' < 04_05_Namenszusatz_Addresszusatz | sed -E s/' +'/' '/g > 04_Zusaetze
354 printf "done.\n" 354 printf "done.\n"
355 355
356 if [ -f $1/zip-streets-hn-geo.tl ]; then 356 if [ -f "$1/zip-streets-hn-geo.tl" ]; then
357 printf "Extracting geo coordinates (precision: house number) ... " 357 printf "Extracting geo coordinates (precision: house number) ... "
358 extract_version_4 $1/zip-streets-hn-geo.tl 358 extract_version_4 "$1/zip-streets-hn-geo.tl"
359 cat file_* > 90_Geokoordinaten_hnr 359 cat file_* > 90_Geokoordinaten_hnr
360 printf "done.\n" 360 printf "done.\n"
361 printf "Looking up geo coordinates for each phonebook entry ... " 361 printf "Looking up geo coordinates for each phonebook entry ... "
362 paste 10_Postleitzahl 07_Strasse 08_Hausnummer | map_coords 90_Geokoordinaten_hnr | convert_coords > 16_Koordinaten 362 paste 10_Postleitzahl 07_Strasse 08_Hausnummer | map_coords 90_Geokoordinaten_hnr | convert_coords > 16_Koordinaten
363 printf "done.\n" 363 printf "done.\n"
364 elif [ -f $1/zip-streets-geo.tl ]; then 364 elif [ -f "$1/zip-streets-geo.tl" ]; then
365 printf "Extracting geo coordinates (precision: street) ... " 365 printf "Extracting geo coordinates (precision: street) ... "
366 extract_version_4 $1/zip-streets-geo.tl 366 extract_version_4 "$1/zip-streets-geo.tl"
367 cat file_* > 91_Geokoordinaten_str 367 cat file_* > 91_Geokoordinaten_str
368 printf "done.\n" 368 printf "done.\n"
369 printf "Looking up geo coordinates for each phonebook entry ... " 369 printf "Looking up geo coordinates for each phonebook entry ... "
@@ -374,7 +374,7 @@ handle_format_version_4() {
374 374
375 if [ "${is_yp}" ]; then 375 if [ "${is_yp}" ]; then
376 printf "Extracting branch names ... " 376 printf "Extracting branch names ... "
377 extract_version_4 $1/branchcodes.tl 377 extract_version_4 "$1/branchcodes.tl"
378 cat file_* | tr '\n\0' '\t\n' > 97_Branchenname 378 cat file_* | tr '\n\0' '\t\n' > 97_Branchenname
379 rm file_* 379 rm file_*
380 printf "done.\n" 380 printf "done.\n"
@@ -394,7 +394,7 @@ handle_format_version_4() {
394} 394}
395 395
396tidy_streetnames () { 396tidy_streetnames () {
397 streets=$1 397 streets="$1"
398 398
399 # Replace any dots at end of line by a single one 399 # Replace any dots at end of line by a single one
400 # finish any str abbreviation without a period with a period 400 # finish any str abbreviation without a period with a period