utils; Add banner, cmp and mkfifo
authorAlan Cox <alan@linux.intel.com>
Mon, 29 Dec 2014 22:10:47 +0000 (22:10 +0000)
committerAlan Cox <alan@linux.intel.com>
Mon, 29 Dec 2014 22:10:47 +0000 (22:10 +0000)
Applications/util/Makefile
Applications/util/banner.c [new file with mode: 0644]
Applications/util/cmp.c [new file with mode: 0644]
Applications/util/mkfifo.c [new file with mode: 0644]

index 7872325..ab7f494 100644 (file)
@@ -15,13 +15,15 @@ BINMAN = ../../Library/tools/binman
 .SUFFIXES: .c .rel
 
 
-SRCS  = basename.c \
+SRCS  = banner.c \
+       basename.c \
        bd.c \
        cal.c \
        cat.c \
        chgrp.c \
        chmod.c \
        chown.c \
+       cmp.c \
        cp.c \
        cut.c \
        date.c \
@@ -43,6 +45,7 @@ SRCS  = basename.c \
        ls.c \
        mkdir.c \
        mkfs.c \
+       mkfifo.c \
        mknod.c \
        more.c \
        mount.c \
diff --git a/Applications/util/banner.c b/Applications/util/banner.c
new file mode 100644 (file)
index 0000000..1061692
--- /dev/null
@@ -0,0 +1,149 @@
+/* banner - print a banner             Author: Brian Wallis */
+
+/*****************************************************************
+ *
+ * SYSVbanner.c
+ *
+ * This is a PD version of the SYS V banner program (at least I think
+ * it is compatible to SYS V) which I wrote to use with the clock
+ * program written by:
+ **     DCF, Inc.
+ **     14623 North 49th Place
+ **     Scottsdale, AZ 85254
+ * and published in the net comp.sources.misc newsgroup in early July
+ * since the BSD banner program works quite differently.
+ *
+ * There is no copyright or responsibility accepted for the use
+ * of this software.
+ *
+ * Brian Wallis, brw@jim.odr.oz, 4 July 1988
+ *
+ *****************************************************************/
+
+#include <string.h>
+#include <stdio.h>
+
+const char *glyphs[] = {
+         "         @@@  @@   @@  @ @   @@@@@          @@     @@@  ",
+         "         @@@  @@   @@  @ @  @  @  @@@   @  @  @    @@@  ",
+         "         @@@   @   @ @@@@@@@@  @   @@  @    @@      @   ",
+         "          @            @ @   @@@@@    @    @@@     @    ",
+         "                     @@@@@@@   @  @  @    @   @ @       ",
+         "         @@@           @ @  @  @  @ @  @@ @    @        ",
+         "         @@@           @ @   @@@@@ @   @@  @@@@ @       ",
+
+         "   @@    @@                                            @",
+         "  @        @   @   @    @                             @ ",
+         " @          @   @ @     @                            @  ",
+         " @          @ @@@@@@@ @@@@@   @@@   @@@@@           @   ",
+         " @          @   @ @     @     @@@                  @    ",
+         "  @        @   @   @    @      @            @@@   @     ",
+         "   @@    @@                   @             @@@  @      ",
+
+         "  @@@     @    @@@@@  @@@@@ @      @@@@@@@ @@@@@ @@@@@@@",
+         " @   @   @@   @     @@     @@    @ @      @     @@    @ ",
+         "@   @ @ @ @         @      @@    @ @      @          @  ",
+         "@  @  @   @    @@@@@  @@@@@ @@@@@@@ @@@@@ @@@@@@    @   ",
+         "@ @   @   @   @            @     @       @@     @  @    ",
+         " @   @    @   @      @     @     @ @     @@     @  @    ",
+         "  @@@   @@@@@ @@@@@@@ @@@@@      @  @@@@@  @@@@@   @    ",
+
+         " @@@@@  @@@@@          @@@      @           @     @@@@@ ",
+         "@     @@     @  @@@    @@@     @             @   @     @",
+         "@     @@     @  @@@           @     @@@@@     @        @",
+         " @@@@@  @@@@@@         @@@   @                 @     @@ ",
+         "@     @      @         @@@    @     @@@@@     @     @   ",
+         "@     @@     @  @@@     @      @             @          ",
+         " @@@@@  @@@@@   @@@    @        @           @       @   ",
+
+         " @@@@@    @   @@@@@@  @@@@@ @@@@@@ @@@@@@@@@@@@@@ @@@@@ ",
+         "@     @  @ @  @     @@     @@     @@      @      @     @",
+         "@ @@@ @ @   @ @     @@      @     @@      @      @      ",
+         "@ @ @ @@     @@@@@@@ @      @     @@@@@@  @@@@@  @  @@@@",
+         "@ @@@@ @@@@@@@@     @@      @     @@      @      @     @",
+         "@     @@     @@     @@     @@     @@      @      @     @",
+         " @@@@@ @     @@@@@@@  @@@@@ @@@@@@ @@@@@@@@       @@@@@ ",
+
+         "@     @  @*@        @@    @ @      @     @@     @@@@@@@@",
+         "@     @   @         @@   @  @      @@   @@@@    @@     @",
+         "@     @   @         @@  @   @      @ @ @ @@ @   @@     @",
+         "@@@@@@@   @         @@@@    @      @  @  @@  @  @@     @",
+         "@     @   @   @     @@  @   @      @     @@   @ @@     @",
+         "@     @   @   @     @@   @  @      @     @@    @@@     @",
+         "@     @  @@@   @@@@@ @    @ @@@@@@@@     @@     @@@@@@@@",
+
+         "@@@@@@  @@@@@ @@@@@@  @@@@@ @@@@@@@@     @@     @@     @",
+         "@     @@     @@     @@     @   @   @     @@     @@  @  @",
+         "@     @@     @@     @@         @   @     @@     @@  @  @",
+         "@@@@@@ @     @@@@@@@  @@@@@    @   @     @@     @@  @  @",
+         "@      @   @ @@   @        @   @   @     @ @   @ @  @  @",
+         "@      @    @ @    @ @     @   @   @     @  @ @  @  @  @",
+         "@       @@@@ @@     @ @@@@@    @    @@@@@    @    @@ @@ ",
+
+         "@     @@     @@@@@@@@ @@@@@ @       @@@@@    @          ",
+         " @   @  @   @      @  @      @          @   @ @         ",
+         "  @ @    @ @      @   @       @         @  @   @        ",
+         "   @      @      @    @        @        @               ",
+         "  @ @     @     @     @         @       @               ",
+         " @   @    @    @      @          @      @               ",
+         "@     @   @   @@@@@@@ @@@@@       @ @@@@@        @@@@@@@",
+
+         "  @@@                                                   ",
+         "  @@@     @@   @@@@@   @@@@  @@@@@  @@@@@@ @@@@@@  @@@@ ",
+         "   @     @  @  @    @ @    @ @    @ @      @      @    @",
+         "    @   @    @ @@@@@  @      @    @ @@@@@  @@@@@  @     ",
+         "        @@@@@@ @    @ @      @    @ @      @      @  @@@",
+         "        @    @ @    @ @    @ @    @ @      @      @    @",
+         "        @    @ @@@@@   @@@@  @@@@@  @@@@@@ @       @@@@ ",
+
+         "                                                        ",
+         " @    @    @        @ @    @ @      @    @ @    @  @@@@ ",
+         " @    @    @        @ @   @  @      @@  @@ @@   @ @    @",
+         " @@@@@@    @        @ @@@@   @      @ @@ @ @ @  @ @    @",
+         " @    @    @        @ @  @   @      @    @ @  @ @ @    @",
+         " @    @    @   @    @ @   @  @      @    @ @   @@ @    @",
+         " @    @    @    @@@@  @    @ @@@@@@ @    @ @    @  @@@@ ",
+
+         "                                                        ",
+         " @@@@@   @@@@  @@@@@   @@@@   @@@@@ @    @ @    @ @    @",
+         " @    @ @    @ @    @ @         @   @    @ @    @ @    @",
+         " @    @ @    @ @    @  @@@@     @   @    @ @    @ @    @",
+         " @@@@@  @  @ @ @@@@@       @    @   @    @ @    @ @ @@ @",
+         " @      @   @  @   @  @    @    @   @    @  @  @  @@  @@",
+         " @       @@@ @ @    @  @@@@     @    @@@@    @@   @    @",
+
+         "                       @@@     @     @@@   @@    @ @ @ @",
+         " @    @  @   @ @@@@@@ @        @        @ @  @  @ @ @ @ ",
+         "  @  @    @ @      @  @        @        @     @@ @ @ @ @",
+         "   @@      @      @  @@                 @@        @ @ @ ",
+         "   @@      @     @    @        @        @        @ @ @ @",
+         "  @  @     @    @     @        @        @         @ @ @ ",
+         " @    @    @   @@@@@@  @@@     @     @@@         @ @ @ @"
+};
+
+int main(int argc, char *argv[])
+{
+  int a, b, c, len, ind;
+  char line[80];
+
+  for (argv++; --argc; argv++) {
+       len = strlen(*argv);
+       if (len > 10) len = 10;
+       for (a = 0; a < 7; a++) {
+               for (b = 0; b < len; b++) {
+                       if ((ind = (*argv)[b] - ' ') < 0) ind = 0;
+                       for (c = 0; c < 7; c++) {
+                               line[b * 8 + c] = glyphs[(ind / 8 * 7) + a][(ind % 8 * 7) + c] == '@' ? ind + ' ' : ' ';
+                       }
+                       line[b * 8 + 7] = ' ';
+               }
+               for (b = len * 8 - 1; b >= 0; b--) {
+                       if (line[b] != ' ') break;
+                       line[b] = '\0';
+               }
+               printf("%s\n", line);
+       }
+       printf("\n");
+  }
+  return(0);
+}
diff --git a/Applications/util/cmp.c b/Applications/util/cmp.c
new file mode 100644 (file)
index 0000000..57057f5
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 1993 by David I. Bell
+ * Permission is granted to use, distribute, or modify this source,
+ * provided that this copyright notice remains intact.
+ *
+ * Most simple built-in commands are here.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#define putstr(x)      write(1, x, strlen(x))
+#define eputstr(x)     write(2, x, strlen(x))
+
+void main(int argc, char *argv[])
+{
+       int             fd1;
+       int             fd2;
+       int             cc1;
+       int             cc2;
+       long            pos;
+       char            *bp1;
+       char            *bp2;
+       char            buf1[512];
+       char            buf2[512];
+       struct  stat    statbuf1;
+       struct  stat    statbuf2;
+
+       if (argc < 3) {
+               eputstr(argv[0]);
+               eputstr(": file1 file2.\n");
+               exit(2);
+       }
+       if (stat(argv[1], &statbuf1) < 0) {
+               perror(argv[1]);
+               exit(2);
+       }
+
+       if (stat(argv[2], &statbuf2) < 0) {
+               perror(argv[2]);
+               exit(2);
+       }
+
+       if ((statbuf1.st_dev == statbuf2.st_dev) &&
+               (statbuf1.st_ino == statbuf2.st_ino))
+       {
+               putstr("Files are links to each other\n");
+               exit(0);
+       }
+
+       if (statbuf1.st_size != statbuf2.st_size) {
+               putstr("Files are different sizes\n");
+               exit(1);
+       }
+
+       fd1 = open(argv[1], 0);
+       if (fd1 < 0) {
+               perror(argv[1]);
+               exit(2);
+       }
+
+       fd2 = open(argv[2], 0);
+       if (fd2 < 0) {
+               perror(argv[2]);
+               close(fd1);
+               exit(2);
+       }
+
+       pos = 0;
+       while (1) {
+               cc1 = read(fd1, buf1, sizeof(buf1));
+               if (cc1 < 0) {
+                       perror(argv[1]);
+                       exit(2);
+               }
+
+               cc2 = read(fd2, buf2, sizeof(buf2));
+               if (cc2 < 0) {
+                       perror(argv[2]);
+                       goto differ;
+               }
+
+               if ((cc1 == 0) && (cc2 == 0)) {
+                       putstr("Files are identical\n");
+                       goto same;
+               }
+
+               if (cc1 < cc2) {
+                       putstr("First file is shorter than second\n");
+                       goto differ;
+               }
+
+               if (cc1 > cc2) {
+                       putstr("Second file is shorter than first\n");
+                       goto differ;
+               }
+
+               if (memcmp(buf1, buf2, cc1) == 0) {
+                       pos += cc1;
+                       continue;
+               }
+
+               bp1 = buf1;
+               bp2 = buf2;
+               while (*bp1++ == *bp2++)
+                       pos++;
+
+               putstr("Files differ at byte position ");
+               bp1 = ultostr(pos, buf1, 10);
+               putstr(bp1);
+               putstr("\n");
+               goto differ;
+       }
+same:
+       exit(0);
+differ:
+       exit(1);
+}
diff --git a/Applications/util/mkfifo.c b/Applications/util/mkfifo.c
new file mode 100644 (file)
index 0000000..bf13a22
--- /dev/null
@@ -0,0 +1,21 @@
+#include <unistd.h>
+#include <sys/stat.h>
+#include <string.h>
+
+int main (int argc, char *argv[])
+{
+       unsigned short newmode;
+       int i,er=0;
+       
+       newmode = 0666 & ~umask(0);
+       for(i=1;i<argc;i++)
+       {
+               if (mkfifo (argv[i],newmode)) {
+                       write(STDERR_FILENO,"mkfifo: cannot make fifo ",25);
+                       write(STDERR_FILENO,argv[i],strlen(argv[i]));
+                       write(STDERR_FILENO,"\n",1);
+                       er&=1;
+               }
+       }
+       return er;
+}