sort.c File Reference

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <limits.h>

Include dependency graph for sort.c:

Go to the source code of this file.

Data Structures

struct  MERGE
struct  FIELD

Defines

#define OPEN_FILES   (OPEN_MAX-4)
#define MEMORY_SIZE   ((10 * sizeof(int)) * 1024)
#define LINE_SIZE   (1024 >> 1)
#define IO_SIZE   (2 * 1024)
#define STD_OUT   1
#define OK   0
#define ERROR   -1
#define NIL_PTR   ((char *) 0)
#define LOWER   -1
#define SAME   0
#define HIGHER   1
#define DICT   0x001
#define ASCII   0x002
#define BLANK   0x004
#define DIGIT   0x008
#define UPPER   0x010
#define FALSE   0
#define TRUE   1
#define NIL_MERGE   ((MERGE *) 0)
#define FIELDS_LIMIT   10
#define GLOBAL   0

Typedefs

typedef int BOOL

Functions

 _PROTOTYPE (int main,(int argc, char **argv))
 _PROTOTYPE (void get_opts,(char *ptr, FIELD *field))
 _PROTOTYPE (void new_field,(FIELD *field, int *offset, BOOL beg_fl))
 _PROTOTYPE (void adjust_options,(FIELD *field))
 _PROTOTYPE (void error,(BOOL quit, char *message, char *arg))
 _PROTOTYPE (void open_outfile,(void))
 _PROTOTYPE (void get_file,(int fd, off_t size))
 _PROTOTYPE (int last_line,(void))
 _PROTOTYPE (void print_table,(int fd))
 _PROTOTYPE (char *file_name,(int nr))
 _PROTOTYPE (void mread,(int fd, char *address, int bytes))
 _PROTOTYPE (void sort_table,(int nel))
 _PROTOTYPE (void incr,(int si, int ei))
 _PROTOTYPE (int cmp_fields,(char *el1, char *el2))
 _PROTOTYPE (void build_field,(char *dest, FIELD *field, char *src))
 _PROTOTYPE (char *skip_fields,(char *str, int nf))
 _PROTOTYPE (int cmp,(unsigned char *el1, unsigned char *el2, FIELD *field))
 _PROTOTYPE (int digits,(char *str1, char *str2, BOOL check_sign))
 _PROTOTYPE (void files_merge,(int file_cnt))
 _PROTOTYPE (void merge,(int start_file, int limit_file))
 _PROTOTYPE (void put_line,(char *line))
 _PROTOTYPE (MERGE *print,(MERGE *merg, int file_cnt))
 _PROTOTYPE (int read_line,(MERGE *merg))
 _PROTOTYPE (MERGE *skip_lines,(MERGE *smallest, int file_cnt))
 _PROTOTYPE (void uniq_lines,(MERGE *merg))
 _PROTOTYPE (void check_file,(int fd, char *file))
 _PROTOTYPE (int length,(char *line))
 _PROTOTYPE (void copy,(char *dest, char *src))
 _PROTOTYPE (char *msbrk,(int size))
 _PROTOTYPE (void mbrk,(char *address))
 _PROTOTYPE (void catch,(int dummy))
void get_opts (char *ptr, FIELD *field)
void new_field (FIELD *field, int *offset, BOOL beg_fl)
int main (int argc, argv)
void adjust_options (FIELD *field)
void error (BOOL quit, char *message, char *arg)
void open_outfile ()
void get_file (int fd, off_t size)
int last_line ()
void print_table (int fd)
char * file_name (int nr)
void mread (int fd, char *address, int bytes)
void mwrite (int fd, char *address, int bytes)
void sort ()
void sort_table (int nel)
void incr (int si, int ei)
int cmp_fields (char *el1, char *el2)
void build_field (char *dest, FIELD *field, char *src)
char * skip_fields (char *str, int nf)
int compare (char *el1, char *el2)
int cmp (unsigned char *el1, unsigned char *el2, FIELD *field)
int digits (char *str1, char *str2, BOOL check_sign)
void files_merge (int file_cnt)
void merge (int start_file, int limit_file)
void put_line (char *line)
MERGEprint (MERGE *merg, int file_cnt)
int read_line (MERGE *merg)
MERGEskip_lines (MERGE *smallest, int file_cnt)
void uniq_lines (MERGE *merg)
void check_file (int fd, char *file)
int length (char *line)
void copy (char *dest, char *src)
char * msbrk (int size)
void mbrk (char *address)
void catch (int dummy)

Variables

MERGE merge_f [OPEN_FILES]
int buf_size
FIELD fields [FIELDS_LIMIT]
int field_cnt
BOOL check = FALSE
BOOL only_merge = FALSE
BOOL uniq = FALSE
char * mem_top
char * cur_pos
char ** line_table
BOOL in_core = TRUE
char temp_files [] = "/tmp/sort.XXXXX.XX"
char * output_file
int out_fd
char out_buffer [IO_SIZE]
char ** argptr
int args_offset
int args_limit
char separator
int nr_of_files = 0
int disabled
char USAGE [] = "Usage: sort [-funbirdcmt'x'] [+beg_pos [-end_pos]] [-o outfile] [file] .."
char table [256]


Define Documentation

#define ASCII   0x002
 

Definition at line 67 of file sort.c.

Referenced by complement().

#define BLANK   0x004
 

Definition at line 68 of file sort.c.

#define DICT   0x001
 

Definition at line 66 of file sort.c.

Referenced by inflateSetDictionary().

#define DIGIT   0x008
 

Definition at line 69 of file sort.c.

#define ERROR   -1
 

Definition at line 57 of file sort.c.

#define FALSE   0
 

Definition at line 74 of file sort.c.

#define FIELDS_LIMIT   10
 

Definition at line 89 of file sort.c.

Referenced by main().

#define GLOBAL   0
 

Definition at line 90 of file sort.c.

Referenced by adjust_options(), compare(), and main().

#define HIGHER   1
 

Definition at line 63 of file sort.c.

#define IO_SIZE   (2 * 1024)
 

Definition at line 52 of file sort.c.

#define LINE_SIZE   (1024 >> 1)
 

Definition at line 51 of file sort.c.

Referenced by check_file(), cmp_fields(), merge(), read_line(), and uniq_lines().

#define LOWER   -1
 

Definition at line 61 of file sort.c.

Referenced by digits(), and dos_name().

#define MEMORY_SIZE   ((10 * sizeof(int)) * 1024)
 

Definition at line 48 of file sort.c.

#define NIL_MERGE   ((MERGE *) 0)
 

Definition at line 85 of file sort.c.

#define NIL_PTR   ((char *) 0)
 

Definition at line 58 of file sort.c.

#define OK   0
 

Definition at line 56 of file sort.c.

#define OPEN_FILES   (OPEN_MAX-4)
 

Definition at line 44 of file sort.c.

Referenced by files_merge().

#define SAME   0
 

Definition at line 62 of file sort.c.

#define STD_OUT   1
 

Definition at line 53 of file sort.c.

#define TRUE   1
 

Definition at line 75 of file sort.c.

#define UPPER   0x010
 

Definition at line 70 of file sort.c.


Typedef Documentation

typedef int BOOL
 

Definition at line 72 of file sort.c.


Function Documentation

_PROTOTYPE void  catch,
(int dummy) 
 

_PROTOTYPE void  mbrk,
(char *address) 
 

_PROTOTYPE char *  msbrk,
(int size) 
 

_PROTOTYPE void  copy,
(char *dest, char *src) 
 

_PROTOTYPE int  length,
(char *line
 

_PROTOTYPE void  check_file,
(int fd, char *file
 

_PROTOTYPE void  uniq_lines,
(MERGE *merg) 
 

_PROTOTYPE MERGE skip_lines,
(MERGE *smallest, int file_cnt) 
 

_PROTOTYPE int  read_line,
(MERGE *merg) 
 

_PROTOTYPE MERGE print,
(MERGE *merg, int file_cnt) 
 

_PROTOTYPE void  put_line,
(char *line
 

_PROTOTYPE void  merge,
(int start_file, int limit_file) 
 

_PROTOTYPE void  files_merge,
(int file_cnt) 
 

_PROTOTYPE int  digits,
(char *str1, char *str2, BOOL check_sign) 
 

_PROTOTYPE int  cmp,
(unsigned char *el1, unsigned char *el2, FIELD *field
 

_PROTOTYPE char *  skip_fields,
(char *str, int nf) 
 

_PROTOTYPE void  build_field,
(char *dest, FIELD *field, char *src) 
 

_PROTOTYPE int  cmp_fields,
(char *el1, char *el2) 
 

_PROTOTYPE void  incr,
(int si, int ei) 
 

_PROTOTYPE void  sort_table,
(int nel) 
 

_PROTOTYPE void  mread,
(int fd, char *address, int bytes
 

_PROTOTYPE char *  file_name,
(int nr) 
 

_PROTOTYPE void  print_table,
(int fd
 

_PROTOTYPE int  last_line,
(void) 
 

_PROTOTYPE void  get_file,
(int fd, off_t size) 
 

_PROTOTYPE void  open_outfile,
(void) 
 

_PROTOTYPE void  error,
(BOOL quit, char *message, char *arg
 

_PROTOTYPE void  adjust_options,
(FIELD *field
 

_PROTOTYPE void  new_field,
(FIELD *field, int *offset, BOOL beg_fl) 
 

_PROTOTYPE void  get_opts,
(char *ptr, FIELD *field
 

_PROTOTYPE int  main,
(int argc, char **argv) 
 

void adjust_options FIELD field  ) 
 

Definition at line 420 of file sort.c.

References FIELD::ascii, FIELD::blanks, FIELD::dictionary, fields, FIELD::fold_case, GLOBAL, FIELD::numeric, FIELD::reverse, and TRUE.

Referenced by main().

void build_field char *  dest,
FIELD field,
char *  src
 

Definition at line 692 of file sort.c.

References begin, copy, ERROR, i, and skip_fields().

Referenced by cmp_fields().

void catch int  dummy  ) 
 

Definition at line 1184 of file sort.c.

References exit(), FALSE, file_name, i, only_merge, SIG_IGN, SIGINT, signal(), and unlink.

void check_file int  fd,
char *  file
 

Definition at line 1110 of file sort.c.

References buf_size, MERGE::buffer, MERGE::cnt, compare, copy, ERROR, FALSE, MERGE::fd, lastline, MERGE::line, LINE_SIZE, mem_top, MEMORY_SIZE, msbrk(), MERGE::read_chars, read_line(), and write.

int cmp unsigned char *  el1,
unsigned char *  el2,
FIELD field
 

Definition at line 754 of file sort.c.

References BLANK, digits(), field, SAME, and TRUE.

int cmp_fields char *  el1,
char *  el2
 

Definition at line 668 of file sort.c.

References build_field(), cmp, field_cnt, fields, i, line1, line2, LINE_SIZE, and SAME.

Referenced by compare().

int compare char *  el1,
char *  el2
 

Definition at line 740 of file sort.c.

References cmp, cmp_fields(), field_cnt, fields, and GLOBAL.

void copy char *  dest,
char *  src
 

Definition at line 1160 of file sort.c.

int digits char *  str1,
char *  str2,
BOOL  check_sign
 

Definition at line 820 of file sort.c.

References BOOL, diff(), DIGIT, FALSE, LOWER, pow(), SAME, and TRUE.

Referenced by cmp(), cvtnum(), out_long(), out_num(), push_constant(), and zputhex().

void error BOOL  quit,
char *  message,
char *  arg
 

Definition at line 434 of file sort.c.

References exit(), NIL_PTR, perror(), strlen(), and write.

char* file_name int  nr  ) 
 

Definition at line 559 of file sort.c.

References argptr, args_limit, args_offset, only_merge, and temp_files.

void files_merge int  file_cnt  ) 
 

Definition at line 886 of file sort.c.

References i, OPEN_FILES, and open_outfile().

Referenced by main().

void get_file int  fd,
off_t  size
 

Definition at line 458 of file sort.c.

References cur_pos, FALSE, get_file(), i, in_core, last_line(), lseek, mem_top, MEMORY_SIZE, mread(), read, SEEK_CUR, and sort().

void get_opts char *  ptr,
FIELD field
 

Definition at line 234 of file sort.c.

References error, NIL_PTR, TRUE, and USAGE.

Referenced by main(), and new_field().

void incr int  si,
int  ei
 

Definition at line 647 of file sort.c.

References compare, line_table, and tmp.

Referenced by inflate_table(), inflate_table9(), main(), sort_table(), and tgoto().

int last_line  ) 
 

Definition at line 514 of file sort.c.

References i, mem_top, and MEMORY_SIZE.

Referenced by get_file(), overlay(), and overwrite().

int length char *  line  ) 
 

Definition at line 1150 of file sort.c.

References i.

int main int  argc,
argv 
 

Definition at line 311 of file sort.c.

References adjust_options(), arg_count, argptr, args_limit, args_offset, check, check_file(), cur_pos, error, exit(), FALSE, field_cnt, fields, FIELDS_LIMIT, files_merge(), get_file(), get_opts(), getpid, GLOBAL, mem_top, MEMORY_SIZE, msbrk(), new_field(), NIL_PTR, nr_of_files, O_RDONLY, only_merge, open, output_file, pid, pow(), ptr, separator, SIGINT, signal(), sort(), st, stat::st_size, stat, strcmp, temp_files, TRUE, and uniq.

void mbrk char *  address  ) 
 

Definition at line 1178 of file sort.c.

References brk, error, NIL_PTR, and TRUE.

Referenced by merge(), and sort().

void merge int  start_file,
int  limit_file
 

Definition at line 914 of file sort.c.

References buf_size, disabled, ERROR, FALSE, MERGE::fd, file_name, i, if(), LINE_SIZE, mbrk(), mem_top, MEMORY_SIZE, merge_f, O_RDONLY, open, and strcmp.

Referenced by _dis(), and free_mem().

void mread int  fd,
char *  address,
int  bytes
 

Definition at line 572 of file sort.c.

References error, NIL_PTR, read, and TRUE.

Referenced by add_file(), get_file(), and get_header().

char* msbrk int  size  ) 
 

Definition at line 1167 of file sort.c.

References address(), error, NIL_PTR, sbrk, and TRUE.

Referenced by check_file(), main(), and sort().

void mwrite int  fd,
char *  address,
int  bytes
 

Definition at line 582 of file sort.c.

References error, NIL_PTR, TRUE, and write.

void new_field FIELD field,
int *  offset,
BOOL  beg_fl
 

Definition at line 268 of file sort.c.

References argptr, atoi, DIGIT, ERROR, error, FALSE, get_opts(), NIL_PTR, ptr, and TRUE.

Referenced by main().

void open_outfile  ) 
 

Definition at line 447 of file sort.c.

References creat, error, NIL_PTR, out_fd, output_file, STD_OUT, and TRUE.

MERGE* print MERGE merg,
int  file_cnt
 

Definition at line 1008 of file sort.c.

References ERROR, i, merge_f, put_line(), and read_line().

void print_table int  fd  ) 
 

Definition at line 526 of file sort.c.

References compare, creat, error, ERROR, file_name, index(), line_table, NIL_PTR, nr_of_files, ptr, SAME, TRUE, and uniq.

void put_line char *  line  ) 
 

Definition at line 983 of file sort.c.

References close, index(), IO_SIZE, mwrite(), NIL_PTR, out_buffer, and out_fd.

int read_line MERGE merg  ) 
 

Definition at line 1034 of file sort.c.

References buf_size, close, disabled, ERROR, LINE_SIZE, OK, ptr, and read.

char* skip_fields char *  str,
int  nf
 

Definition at line 720 of file sort.c.

References BLANK, and separator.

Referenced by build_field().

MERGE* skip_lines MERGE smallest,
int  file_cnt
 

Definition at line 1065 of file sort.c.

References compare, disabled, ERROR, i, if(), MERGE::line, merge_f, and read_line().

void sort void   ) 
 

Definition at line 592 of file sort.c.

References count, ERROR, in_core, line_table, mbrk(), mem_top, msbrk(), NIL_PTR, open_outfile(), out_fd, print_table(), ptr, and sort_table().

void sort_table int  nel  ) 
 

Definition at line 628 of file sort.c.

References i, incr(), line_table, and tmp.

Referenced by sort().

void uniq_lines MERGE merg  ) 
 

Definition at line 1088 of file sort.c.

References compare, ERROR, if(), lastline, LINE_SIZE, put_line(), read_line(), and SAME.


Variable Documentation

char** argptr
 

Definition at line 123 of file sort.c.

int args_limit
 

Definition at line 125 of file sort.c.

Referenced by file_name(), and main().

int args_offset
 

Definition at line 124 of file sort.c.

Referenced by file_name(), and main().

int buf_size
 

Definition at line 87 of file sort.c.

BOOL check = FALSE
 

Definition at line 108 of file sort.c.

char* cur_pos
 

Definition at line 113 of file sort.c.

Referenced by get_file(), get_line(), and main().

int disabled
 

Definition at line 129 of file sort.c.

Referenced by merge(), read_line(), and skip_lines().

int field_cnt
 

Definition at line 105 of file sort.c.

Referenced by cmp_fields(), compare(), and main().

FIELD fields[FIELDS_LIMIT]
 

Definition at line 104 of file sort.c.

BOOL in_core = TRUE
 

Definition at line 115 of file sort.c.

Referenced by get_file(), and sort().

char** line_table
 

Definition at line 114 of file sort.c.

Referenced by incr(), print_table(), sort(), and sort_table().

char* mem_top
 

Definition at line 112 of file sort.c.

Referenced by check_file(), get_file(), last_line(), main(), merge(), and sort().

MERGE merge_f[OPEN_FILES]
 

Definition at line 86 of file sort.c.

Referenced by merge(), print(), and skip_lines().

int nr_of_files = 0
 

Definition at line 128 of file sort.c.

Referenced by main(), and print_table().

BOOL only_merge = FALSE
 

Definition at line 109 of file sort.c.

Referenced by catch(), file_name(), and main().

char out_buffer[IO_SIZE]
 

Definition at line 121 of file sort.c.

Referenced by put_line().

int out_fd
 

Definition at line 120 of file sort.c.

Referenced by open_outfile(), put_line(), and sort().

char* output_file
 

Definition at line 119 of file sort.c.

Referenced by copy_ident(), goto_actions(), main(), open_files(), open_outfile(), output_base(), output_check(), output_debug(), output_rule_data(), output_table(), and output_yydefred().

char separator
 

Definition at line 127 of file sort.c.

Referenced by main(), and skip_fields().

char table[256]
 

Definition at line 170 of file sort.c.

char temp_files[] = "/tmp/sort.XXXXX.XX"
 

Definition at line 118 of file sort.c.

Referenced by file_name(), and main().

BOOL uniq = FALSE
 

Definition at line 110 of file sort.c.

Referenced by main(), print_table(), and uniqname().

char USAGE[] = "Usage: sort [-funbirdcmt'x'] [+beg_pos [-end_pos]] [-o outfile] [file] .."
 

Definition at line 131 of file sort.c.


Generated on Fri Apr 14 23:07:27 2006 for minix by  doxygen 1.4.6