#! /bin/csh -f
#
# format_line - Format input strings with specified string formats.
#
# Version 1.3
#
# Pre:
#    $1,$2 - string1,format1
#    $3,$4 - string2,format2
#    ...
# Post:
#    stdout - a single output line containing the formatted strings
#
#    Each string except the last must be followed by a string format
#    (e.g., '-10.5' places the first 5 characters left-justified in
#     a 10-character field).
#    The default string format (%s) is used for the last string if the
#    format is not specified. It is also used if the format is empty.
#
# Copyright (c) 1995 by
#
#    Confluent, Inc.
#    400 Spear St., Suite 207
#    San Francisco, CA 94105
#
# Voice: 415-764-1000
# Fax: 415-764-1008
# Internet: info@confluent.com
#
# Created: 950116 - jag
# Modified: 950121 - jag : Speed up by only invoking awk once

# Create an empty awk command.
set fl_q = '"'
set fl_awk = ""

# Get the number of arguments.
@ fl_n = $#argv

# Go through the string/format pairs.
@ fl_i = 0
while ($fl_i < $fl_n)

  # Get the string and increment the argument index by 2.
  @ fl_i ++
  set fl_str = "$argv[$fl_i]"
  @ fl_i ++

  # If there is an argument for the format, use it.
  # Otherwise, use the default string format.
  if ($fl_i <= $fl_n) then
    set fl_fmt = "%$argv[$fl_i]s"
  else
    set fl_fmt = "%s"
  endif

  # Add output of the string using the format to the awk command.
  set fl_awk = "$fl_awk{printf $fl_q$fl_fmt$fl_q,$fl_q$fl_str$fl_q};"

end

# Add output of a newline to the awk command.
set fl_awk = "$fl_awk{printf $fl_q\n$fl_q}"

# Execute awk with the command.
echo "" | awk "$fl_awk"
