home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
t
/
tags18.zip
/
SORT.DIF
< prev
next >
Wrap
Text File
|
1991-10-02
|
6KB
|
260 lines
*** tmp\sort.c Sun Aug 26 23:19:34 1990
--- sort.c Wed Oct 02 20:13:38 1991
***************
*** 30,39 ****
--- 30,44 ----
static char version[] = "GNU sort, version 0.3";
#include "std.h"
+
#ifndef MSDOS
#include "unix.h"
#endif /* not MSDOS */
+ #ifdef SORT_MODULE
+ #include "sort.h"
+ #endif
+
#include <errno.h>
#include <signal.h>
#include <stdio.h>
***************
*** 72,78 ****
--- 77,85 ----
static void usage (void);
static void badfieldspec (char *s);
static void inthandler (void);
+ #ifndef SORT_MODULE
int main (int argc, char **argv);
+ #endif
#endif /* MSDOS */
/* A few useful macros. */
***************
*** 187,192 ****
--- 194,202 ----
" the MS-DOS version. For files with short lines, use\n"
" the `-S <num>' option to reduce the buffer size.\n");
cleanup ();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
exit (-1);
}
}
***************
*** 239,244 ****
--- 249,258 ----
{
struct tempnode *node;
+ #ifdef MSDOS
+ fcloseall();
+ #endif
+
for (node = temphead.next; node; node = node->next)
remove(node->name);
}
***************
*** 255,260 ****
--- 269,277 ----
return r;
fprintf (stderr, "sort: memory exausted\n");
cleanup ();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
exit (-1);
}
***************
*** 267,272 ****
--- 284,292 ----
return r;
fprintf (stderr, "sort: memory exhausted\n");
cleanup ();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
exit (-1);
}
***************
*** 282,287 ****
--- 302,310 ----
return r;
fprintf(stderr, "sort: memory exausted\n");
cleanup();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
exit(-1);
}
***************
*** 296,301 ****
--- 319,327 ----
return r;
fprintf(stderr, "sort: memory exhausted\n");
cleanup();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
exit(-1);
}
***************
*** 312,317 ****
--- 338,346 ----
fprintf(stderr, "sort: cannot open %s (%s): %s\n", file, how,
strerror(errno));
cleanup();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
exit(-1);
}
***************
*** 325,330 ****
--- 354,362 ----
{
fprintf(stderr, "sort: error in fclose: %s\n", strerror(errno));
cleanup();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
exit(-1);
}
}
***************
*** 335,344 ****
--- 367,383 ----
int size, nelem;
FILE *fp;
{
+ #ifdef MSDOS
+ if (fwrite(buf, size, nelem, fp) < (unsigned) nelem)
+ #else /* not MSDOS */
if (fwrite(buf, size, nelem, fp) < 0)
+ #endif /* not MSDOS */
{
fprintf(stderr, "sort: error in fwrite: %s\n", strerror(errno));
cleanup();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
exit(-1);
}
}
***************
*** 354,360 ****
(struct tempnode *) xmalloc(sizeof (struct tempnode));
#ifdef MSDOS
! if (len && prefix[len - 1] != '/')
sprintf(name, "%s/sort%4.4x.%3.3x", prefix, getpid(), ++seq);
else
sprintf(name, "%ssort%4.4x.%3.3x", prefix, getpid(), ++seq);
--- 393,399 ----
(struct tempnode *) xmalloc(sizeof (struct tempnode));
#ifdef MSDOS
! if (len && prefix[len - 1] != '/' && prefix[len - 1] != '\\')
sprintf(name, "%s/sort%4.4x.%3.3x", prefix, getpid(), ++seq);
else
sprintf(name, "%ssort%4.4x.%3.3x", prefix, getpid(), ++seq);
***************
*** 448,453 ****
--- 487,495 ----
"sort: lines longer than 32k are not supported under\n"
" MS-DOS because of performance considerations.\n");
cleanup ();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
exit (-1);
}
#else /* not MSDOS */
***************
*** 458,463 ****
--- 500,508 ----
{
fprintf(stderr, "sort: read error (%s)\n", strerror(errno));
cleanup();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
exit(-1);
}
buf->used += cc;
***************
*** 473,478 ****
--- 518,526 ----
"sort: lines longer than 32k are not supported under\n"
" MS-DOS because of performance considerations.\n");
cleanup ();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
exit (-1);
}
#else /* not MSDOS */
***************
*** 1122,1127 ****
--- 1170,1177 ----
saved.length = lines[ord[0]].lines[cur[ord[0]]].length;
memcpy(saved.text, lines[ord[0]].lines[cur[ord[0]]].text,
saved.length + 1);
+ saved.keybeg = lines[ord[0]].lines[cur[ord[0]]].keybeg;
+ saved.keylim = lines[ord[0]].lines[cur[ord[0]]].keylim;
savedflag = 1;
}
else
***************
*** 1405,1410 ****
--- 1455,1463 ----
{
signal(SIGINT, SIG_DFL);
cleanup();
+ #ifdef SORT_MODULE
+ external_cleanup();
+ #endif
#ifdef MSDOS
abort ();
#else /* not MSDOS */
***************
*** 1423,1429 ****
--- 1476,1486 ----
#endif /* not MSDOS */
int
+ #ifdef SORT_MODULE
+ sort_main(argc, argv)
+ #else
main(argc, argv)
+ #endif
int argc;
char *argv[];
{
***************
*** 1753,1758 ****
--- 1810,1826 ----
merge(files, nfiles, ofp);
else
sort(files, nfiles, ofp);
+
+ /* close the file */
+ if (ofp != stdout)
+ fclose(ofp);
+
cleanup();
+
+ #ifdef SORT_MODULE
+ return(0);
+ #else /* not SORT_MODULE */
exit(0);
+ #endif /* not SORT_MODULE */
+
}