/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2011-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
static const char sort_usage[] =
"[+PLUGIN?\findex\f]"
"[+DESCRIPTION?The sort query writes the sorted input records to the"
" standard output. The unsorted record stream is passed to the"
" next query, if any. The sort keys are the \afield\a operands,"
" or the raw record data if there are no operands.]"
"[c:count?Prepend an integer count field of the number of records that "
"compare equal. Records with count less that \athreshhold\a are "
"omitted.]#?[threshold:=1]"
"[r:reverse|invert?Reverse the sense of comparisons.]"
"[u:unique?Keep only the first of multiple records that compare equal on "
"all keys.]"
"\n"
"\n[ field ... ]\n"
"\n"
"[+CAVEATS?Currently all data is sorted in memory -- spillover to "
"temporary files not implemented yet.]"
;
#include <dsslib.h>
#include <recsort.h>
#include <stk.h>
struct State_s
{
char* sortbase;
char* uniqbase;
void* data;
};
extern Dsslib_t dss_lib_sort;
static ssize_t
key(Rs_t* rs, unsigned char* data, size_t datasize, unsigned char* key, size_t keysize, Rsdisc_t* disc)
{
Cxoperand_t r;
unsigned char* k;
unsigned char* e;
k = key;
e = k + keysize;
{
if (cxcast(state->cx, &r, (Cxvariable_t*)field->user, state->cx->state->type_string, state->data, NiL))
return -1;
k += field->coder(state->sortkey, field, (unsigned char*)r.value.string.data, r.value.string.size, k, e);
}
return k - key;
}
static ssize_t
rev(Rs_t* rs, unsigned char* data, size_t datasize, unsigned char* key, size_t keysize, Rsdisc_t* disc)
{
return state->sortkey->head->coder(state->sortkey, state->sortkey->head, data, datasize, key, key + keysize);
}
static int
{
Rsobj_t* r;
Rsobj_t* q;
char* s;
ssize_t n;
switch (op)
{
case RS_POP:
break;
case RS_WRITE:
n = 1;
n++;
{
{
return -1;
}
}
return RS_DELETE;
default:
return -1;
}
return 0;
}
static int
{
int n;
int uniq;
char* s;
char* t;
char* num;
{
if (vm)
return -1;
}
goto bad;
goto bad;
goto bad;
goto bad;
goto bad;
uniq = 0;
for (;;)
{
{
case 0:
break;
case 'c':
continue;
case 'u':
uniq = 1;
continue;
case '?':
{
}
else
goto bad;
continue;
case ':':
else
goto bad;
continue;
default:
opt[1] = 0;
goto bad;
continue;
}
break;
}
goto bad;
n = 0;
while (s = *argv++)
{
if (t = strchr(s, '-'))
{
t++;
}
else
t = 0;
goto bad;
goto bad;
n = 1;
}
if (uniq)
{
}
{
goto bad;
goto bad;
goto bad;
goto bad;
{
goto bad;
}
if (rsinit(state->uniq, state->uniqkey->meth, state->uniqkey->procsize, state->uniqkey->type, state->uniqkey))
{
goto bad;
}
}
{
goto bad;
}
if (n)
{
}
{
}
if (rsinit(state->sort, state->sortkey->meth, state->sortkey->procsize, state->sortkey->type, state->sortkey))
{
goto bad;
}
return 0;
bad:
return -1;
}
static int
{
char* s;
ssize_t n;
return -1;
{
return -1;
}
return 0;
}
static int
{
int r;
r = 0;
{
r = -1;
}
{
r = -1;
}
{
r = -1;
}
{
{
r = -1;
}
{
r = -1;
}
{
r = -1;
}
}
return r;
}
{
{
"sort",
"sort records to the standard output",
CXH,
0,
},
{0}
};
{
"sort",
"sort query"
"[-1lms5P?\n@(#)$Id: dss sort query (AT&T Research) 2011-10-18 $\n]"
CXH,
0,
0,
0,
0,
0,
0,
&queries[0]
};