2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: shipop.c /main/4 1996/10/04 15:58:45 drk $ */
24 /***************************************************************
26 * AT&T - PROPRIETARY *
28 * THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
31 * Copyright (c) 1995 AT&T Corp. *
32 * All Rights Reserved *
34 * This software is licensed by AT&T Corp. *
35 * under the terms and conditions of the license in *
36 * http://www.research.att.com/orgs/ssr/book/reuse *
38 * This software was created by the *
39 * Software Engineering Research Department *
40 * AT&T Bell Laboratories *
42 * For further information contact *
43 * gsf@research.att.com *
45 ***************************************************************/
47 /* : : generated by proto : : */
49 #if !defined(__PROTO__)
50 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
51 #if defined(__cplusplus)
52 #define __MANGLE__ "C"
57 #define __PROTO__(x) x
59 #define __PARAM__(n,o) n
60 #if !defined(__STDC__) && !defined(__cplusplus)
61 #if !defined(c_plusplus)
72 #define __PROTO__(x) ()
73 #define __OTORP__(x) x
74 #define __PARAM__(n,o) o
82 #if defined(__cplusplus) || defined(c_plusplus)
83 #define __VARARG__ ...
87 #if defined(__STDARG__)
88 #define __VA_START__(p,a) va_start(p,a)
90 #define __VA_START__(p,a) va_start(p)
93 static const char id[] = "\n@(#)shipop (AT&T Bell Laboratories) 06/11/92\0\n";
96 #include <sys/types.h>
99 #define elementsof(x) (sizeof(x)/sizeof(x[0]))
101 static char* cmd = "shipop";
106 extern __MANGLE__ int close __PROTO__((int));
107 extern __MANGLE__ void exit __PROTO__((int));
108 extern __MANGLE__ int open __PROTO__((const char*, int, ...));
109 extern __MANGLE__ int read __PROTO__((int, char*, int));
110 extern __MANGLE__ int strcmp __PROTO__((const char*, const char*));
111 extern __MANGLE__ time_t time __PROTO__((time_t*));
114 error __PARAM__((int level, const char* file, const char* msg), (level, file, msg)) __OTORP__(int level; const char* file; const char* msg;){
115 fprintf(stderr, "%s: %s", cmd, op);
116 if (level == 1) fprintf(stderr, ": warning");
117 if (file) fprintf(stderr, ": %s", file);
118 if (msg) fprintf(stderr, ": %s", msg);
119 fprintf(stderr, "\n");
122 if (level > 2) exit(level - 2);
128 * shipop newer [ reference [ file ... ] ]
132 shipnewer __PARAM__((register char** argv), (argv)) __OTORP__(register char** argv;){
136 if (!*argv || stat(*argv, &st)) return(1);
137 ref = (unsigned long)st.st_mtime;
139 if (stat(*argv, &st) || ref < (unsigned long)st.st_mtime) return(1);
143 #define HASHPART(h,c) (h = (h) * 987654321L + 123456879L + (c))
145 static char buf[4096];
148 sealfile __PARAM__((char* file, int fd, unsigned long s), (file, fd, s)) __OTORP__(char* file; int fd; unsigned long s;){
149 register unsigned char* b;
150 register unsigned char* e;
154 while ((n = read(fd, buf, sizeof(buf))) > 0)
156 b = (unsigned char*)buf;
158 while (b < e) HASHPART(s, *b++);
160 if (n < 0) error(2, file, "read error");
165 * shipop seal [ file ... ]
169 shipseal __PARAM__((register char** argv), (argv)) __OTORP__(register char** argv;){
175 if (!*argv) s = sealfile("/dev/stdin", 0, s);
176 else while (f = *argv++)
178 if (*f == '-' && !*(f + 1)) s = sealfile("/dev/stdin", 0, s);
179 else if ((fd = open(f, 0)) < 0) error(2, f, "cannot read");
182 s = sealfile(f, fd, s);
186 printf("%08lx\n", s);
191 * shipop state reference [ file ... | <file-list ]
195 shipstate __PARAM__((register char** argv), (argv)) __OTORP__(register char** argv;){
201 if (!(s = *argv++) || stat(s, &st)) error(3, (char*)0, "reference file omitted");
202 ref = (long)st.st_mtime;
206 printf("%s %ld\n", s, (long)st.st_mtime - ref);
207 } while (s = *argv++);
211 while ((c = getchar()) != EOF && c != ' ' && c != '\n')
212 if (s < buf + sizeof(buf) - 1) *s++ = c;
217 printf("%s %ld\n", buf, (long)st.st_mtime - ref);
224 * shipop time [ file ]
228 shiptime __PARAM__((register char** argv), (argv)) __OTORP__(register char** argv;){
232 if (*argv && !stat(*argv, &st)) date = st.st_mtime;
234 printf("%08lx\n", (long)date);
239 * shipop xap [ file ... ]
243 shipxap __PARAM__((char** argv), (argv)) __OTORP__(char** argv;){
244 error(2, "xap not implemented yet", (char*)0);
251 int (*func) __PROTO__((char**));
254 static struct optab ops[] =
264 main __PARAM__((int argc, char** argv), (argc, argv)) __OTORP__(int argc; char** argv;){
270 for (i = 0; i < elementsof(ops); i++)
271 if (!strcmp(s, ops[i].name))
274 exit((*ops[i].func)(argv + 1));
276 fprintf(stderr, "Usage: %s %s", cmd, ops[0].name);
277 for (i = 1; i < elementsof(ops); i++)
278 fprintf(stderr, " | %s", ops[i].name);
279 fprintf(stderr, " [ file ... ]\n");