# Copyright 1989, 1990 Michael DeCorte


${awk} '
BEGIN {
# the defaults
        limit='${maxsum}';
        size=100000;
        len=130;
        pack="NONE";
        archiver="SIMPLE"
        encoder="UUENCODE"
        language="ENG"
}
/^SEARCH/ {
  if (!index($2, ".."))
  {
    if (NF == 3)
    {
        printf("SEARCH %s %s\n", $2, $3);
    }
    for (x=4; x <= NF; x++)
    {
      if (!index($x, ".."))
      {
          printf("SEARCH %s %s/%s\n", $2, $3, $x);
      }
    }
  }
}
/^LIMIT/ {
  if ((NF == 2) && !match($2, "[^0-9]"))
    limit = $2;
  if ((limit + 0) < 0)
    limit = 0;
}
/^FIND/ {
        print $0;
}
/^SEND/ {
  if (!index($2, ".."))
  {
    if (NF == 2)
    {
        printf("SEND %s\n", $2);
    }
    for (x=3; x <= NF; x++)
    {
      if (!index($x, ".."))
      {
          printf("SEND %s/%s\n", $2, $x);
      }
    }
  }
}
# send archive files...
/^ENCODEDSEND/ {
  if (!index($2, ".."))
  {
    if (NF == 2)
    {
      printf("ENCODEDSEND %s\n", $2);
    }
    for (x=3; x <= NF; x++)
    {
      if (!index($x, ".."))
      {
          printf("ENCODEDSEND %s/%s\n", $2, $x);
      }
    }
  }
}
# path your-favorite-path
/^PATH/ {
  if ((NF == 2) && !path)
  {
    $1 = "TO:";
    print $0;
    path = 1;
  }
}
/^LANGUAGE/ {
  if (NF == 2)
  {
    language = $2 "";
  }
}
/^INDEX/ {
  if (NF == 1)
  {
    printf("SEND Index\n");
  }
  else
    for (x=2; x<= NF; x++)
    {
      printf("SEND %s/Index\n", $x);
    }
}
/^HELP/ {
  if (!help)
  {
    printf("HELP\n");
    help = 1;
  }
}
/^PACK/ {
  if ((NF == 2) && !index($2, "/"))
  {
    pack = $2 "";
  }
}
/^ARCHIVER/ {
  if ((NF == 2) && !index($2, "/"))
  {
    archiver = $2 "";
  }
}
/^ENCODER/ {
  if ((NF == 2) && !index($2, "/"))
  {
    encoder = $2 "";
  }
}
/^SIZE/ {
  if ((NF == 2) && !match($2, "[^0-9]") && ($2 > 0))
  {
    size = $2 + 0;
  }
}
/^LENGTH/ {
  if ((NF == 2) && !match($2, "[^0-9]") && ($2 > 0))
  {
    len = $2 + 0;
  }
}
END {
  printf("LIMIT %d\n", limit);
  printf("SIZE %d\n", size);
  printf("LENGTH %d\n", len);
  printf("PACK %s\n", pack);
  printf("ARCHIVER %s\n", archiver);
  printf("ENCODER %s\n", encoder);
  printf("LANGUAGE %s\n", language);
}'
