/* $Id: qdsort.cc 6789 2018-02-19 20:10:22Z flaterco $

qdsort -- Quick and dirty replacement for sort.

The purpose of this filter is to provide semi-intelligent sorting of
text files using the Latin-1 character set.  None of the switches of
the Unix sort program are supported.

Requires libdstr, available from https://flaterco.com/util/index.html.

g++ -Wall -Wextra -pedantic -O2 -s -o qdsort qdsort.cc -ldstr

Usage:  qdsort < input.txt > output.txt

Obsoletes qdsort.c 2005-05-06

*/


#include <stdlib.h>
#include <assert.h>
#include <Dstr>
#include <vector>
#include <algorithm>


int main (int argc, char **argv __attribute__ ((unused))) {
  std::vector<Dstr> buf;
  Dstr lineBuf;

  if (argc > 1) {
    fprintf (stderr, "Usage:  qdsort < input.txt > output.txt\n");
    exit (-1);
  }

  while (!lineBuf.getline(stdin).isNull())
    buf.push_back (lineBuf);

  std::sort (buf.begin(), buf.end(), InsensitiveOrdering);
  for (std::vector<Dstr>::iterator it (buf.begin());
       it != buf.end();
       ++it)
    printf ("%s\n", it->aschar());

  return 0;
}
