summaryrefslogtreecommitdiffstats
path: root/private/sdktools/head
diff options
context:
space:
mode:
Diffstat (limited to 'private/sdktools/head')
-rw-r--r--private/sdktools/head/head.c110
-rw-r--r--private/sdktools/head/head.rc11
-rw-r--r--private/sdktools/head/makefile6
-rw-r--r--private/sdktools/head/sources37
4 files changed, 164 insertions, 0 deletions
diff --git a/private/sdktools/head/head.c b/private/sdktools/head/head.c
new file mode 100644
index 000000000..cf96becee
--- /dev/null
+++ b/private/sdktools/head/head.c
@@ -0,0 +1,110 @@
+/* head - first n lines to STDOUT
+ *
+ * 20-Jul-1991 ianja Wrote it.
+ * 21-Jul-1991 ianja Close stdin (for piped input)
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+
+int Head(char *pszFile, int nLines, BOOL fBanner);
+char *Version = "HEAD v1.1 1991-06-20:";
+
+#define BUFSZ 256
+
+void
+_CRTAPI1 main (argc, argv)
+int argc;
+char *argv[];
+{
+ int nArg;
+ int cLines = 10; // default
+ int nFiles = 0;
+ int nErr = 0;
+
+ if ((argc > 1) && ((*argv[1] == '-') || (*argv[1] == '/'))) {
+ if (argv[1][1] == '?') {
+ printf("%s\n", Version);
+ printf("usage: HEAD [switches] [filename]*\n");
+ printf(" switches: [-?] display this message\n");
+ printf(" [-n] display top n lines of each file (default 10)\n");
+ exit(0);
+ }
+
+ cLines = atoi(argv[1]+1);
+ nArg = 2;
+ } else {
+ nArg = 1;
+ }
+
+ nFiles = argc - nArg;
+
+ if (nFiles < 1) {
+ nErr += Head(NULL, cLines, FALSE);
+ } else while (nArg < argc) {
+ nErr += Head(argv[nArg], cLines, (nFiles > 1));
+ nArg++;
+ }
+
+ if (nErr) {
+ exit(2);
+ } else {
+ exit(0);
+ }
+}
+
+int Head(char *pszFile, int nLines, BOOL fBanner)
+{
+ FILE *fp;
+ int nErr = 0;
+ char buff[BUFSZ];
+
+ /*
+ * Open file for reading
+ */
+ if (pszFile) {
+ if ((fp = fopen(pszFile, "r")) == NULL) {
+ fprintf(stderr, "HEAD: can't open %s\n", pszFile);
+ return 1;
+ }
+ } else {
+ fp = stdin;
+ }
+
+ /*
+ * Banner printed if there is more than one input file
+ */
+ if (fBanner) {
+ fprintf(stdout, "==> %s <==\n", pszFile);
+ }
+
+ /*
+ * Print cLines, or up to end of file, whichever comes first
+ */
+ while (nLines-- > 0) {
+ if (fgets(buff, BUFSZ-1, fp) == NULL) {
+ if (!feof(fp)) {
+ fprintf(stderr, "HEAD: can't read %s\n", pszFile);
+ nErr++;
+ goto CloseOut;
+ }
+ break;
+ }
+ if (fputs(buff, stdout) == EOF) {
+ fprintf(stderr, "can't write output\n");
+ nErr++;
+ goto CloseOut;
+ }
+ }
+
+ if (fBanner) {
+ fprintf(stdout, "\n");
+ }
+
+CloseOut:
+ fclose(fp);
+ return nErr;
+}
+
diff --git a/private/sdktools/head/head.rc b/private/sdktools/head/head.rc
new file mode 100644
index 000000000..917be3822
--- /dev/null
+++ b/private/sdktools/head/head.rc
@@ -0,0 +1,11 @@
+#include <windows.h>
+#include <ntverp.h>
+
+#define VER_FILETYPE VFT_APP
+#define VER_FILESUBTYPE VFT2_UNKNOWN
+#define VER_FILEDESCRIPTION_STR "Microsoft\256 Head Utility"
+
+#define VER_INTERNALNAME_STR "head.exe"
+#define VER_ORIGINALFILENAME_STR "head.exe"
+
+#include <common.ver>
diff --git a/private/sdktools/head/makefile b/private/sdktools/head/makefile
new file mode 100644
index 000000000..6ee4f43fa
--- /dev/null
+++ b/private/sdktools/head/makefile
@@ -0,0 +1,6 @@
+#
+# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
+# file to this component. This file merely indirects to the real make file
+# that is shared by all the components of NT OS/2
+#
+!INCLUDE $(NTMAKEENV)\makefile.def
diff --git a/private/sdktools/head/sources b/private/sdktools/head/sources
new file mode 100644
index 000000000..31b32d969
--- /dev/null
+++ b/private/sdktools/head/sources
@@ -0,0 +1,37 @@
+!IF 0
+
+Copyright (c) 1989 Microsoft Corporation
+
+Module Name:
+
+ sources.
+
+Abstract:
+
+ This file specifies the target component being built and the list of
+ sources files needed to build that component. Also specifies optional
+ compiler switches and libraries that are unique for the component being
+ built.
+
+
+Author:
+
+ Steve Wood (stevewo) 12-Apr-1990
+
+NOTE: Commented description of this file is in \nt\bak\bin\sources.tpl
+
+!ENDIF
+
+MAJORCOMP=sdktools
+MINORCOMP=head
+GPSIZE=32
+
+TARGETNAME=head
+TARGETPATH=obj
+TARGETTYPE=PROGRAM
+
+SOURCES=head.c head.rc
+
+C_DEFINES=-D_OS2_20_=0 -Dnear= -Dfar= -Dpascal=
+
+UMTYPE=console