home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / index-db / part01 / samples / pphone.fmt < prev    next >
Encoding:
Text File  |  1989-10-23  |  1.4 KB  |  86 lines

  1. #!/bin/sh
  2. #
  3. # pphone.fmt - format the pphone database into a nice troff-able
  4. #           phone list of the format
  5. #
  6. #    Name in bold face
  7. #       Home Address        Work Address
  8. #       Home Phone        Work Phone
  9. #                Electronic Mail Address
  10. #
  11.  
  12. #
  13. # Put out troff header (set point size, etc.)
  14. #
  15. cat << EOF
  16. .\"
  17. .\" Run me off with "troff -ms"
  18. .\"
  19. .nr LL 6.5i
  20. .nr PO 1i
  21. .nr PS 12
  22. .nr VS 14
  23. .ll 6.5i
  24. .po 1i
  25. .ps 12
  26. .vs 14
  27. .nf
  28. EOF
  29.  
  30. #
  31. # Let awk handle reformatting.  Basically, we want to print out, for
  32. # each entry:
  33. #
  34. #    .ne 6v        <-- makes sure whole entry fits on page
  35. #    .B "Name"
  36. #    .mk
  37. #    .in .5i
  38. #    Home Address
  39. #    Home Phone
  40. #    .rt
  41. #    .in 3i
  42. #    Work Address
  43. #    Work Phone
  44. #    Electronic Address
  45. #    .sp
  46. #
  47. # We have special stuff to handle blank lines in the home and/or work
  48. # address, and then at the end we have to put in some blank lines to
  49. # make sure the work address is at least as long as the home address,
  50. # since we're using marks/returns.
  51. #
  52. awk    'BEGIN    { FS = "\t" }
  53.         { if (NR > 1) {
  54.             home = ""
  55.             homen = 0
  56.             for (i=2; i <= 4; i++) {
  57.                 if (length($i) > 0) {
  58.                     home = home $i "\n"
  59.                     homen++
  60.                 }
  61.             }
  62.  
  63.             work = ""
  64.             workn = 0
  65.             for (i=5; i <= 9; i++) {
  66.                 if (length($i) > 0) {
  67.                     work = work $i "\n"
  68.                     workn++
  69.                 }
  70.             }
  71.  
  72.             printf ".ne 6v\n.B \"%s\"\n", $1
  73.             printf ".in .5i\n.mk\n"
  74.             printf "%s", home
  75.             printf ".rt\n.in 3i\n"
  76.             printf "%s", work
  77.  
  78.             while (homen > workn) {
  79.                 printf "\n"
  80.                 homen--
  81.             }
  82.  
  83.             printf ".sp\n.in 0\n"
  84.           }
  85.         }'
  86.