Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / support / bboards / bbtar.c
1 /* bbtar.c - generate the names of archive files to be put to tape */
2 #ifndef lint
3 static char ident[] = "@(#)$Id: bbtar.c,v 1.6 1992/12/15 00:20:22 jromine Exp $";
4 #endif  /* lint */
5
6 /* Usage:
7
8         % cd ~bboards/archive           # followed by one of:
9
10         % tar cv `bbtar private`        # to save private BBoard archives
11         % tar cv `bbtar public`         # to save public BBoard archives
12         % tar cv `bbtar`                # to save all BBoard archives
13
14  */
15
16
17 #include <pwd.h>
18 #include <stdio.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include "../zotnet/bboards.h"
22
23
24 #define NOTOK   (-1)
25
26
27 static int  priv = 0;
28
29 static char archives[BUFSIZ];
30
31 static  process();
32
33 #ifndef __STDC__
34 #ifdef  SYS5
35 struct passwd  *getpwnam ();
36 #endif
37 #endif
38
39 /* \f */
40
41 /* ARGSUSED */
42
43 main (argc, argv)
44 int     argc;
45 char  **argv;
46 {
47     struct bboard  *bb;
48     struct passwd  *pw;
49
50     if ((pw = getpwnam (BBOARDS)) == NULL)
51         exit (1);
52     (void) sprintf (archives, "%s/archive/", pw -> pw_dir);
53
54     if (argc > 1)
55         priv = strcmp (argv[1], "private") == 0 ? 1
56             : strcmp (argv[1], "public") == 0 ? -1
57             : 0;
58
59     (void) setbbent (SB_STAY);
60     while (bb = getbbent ())
61         process (bb);
62     (void) endbbent ();
63
64     exit (0);
65 }
66
67 /* \f */
68
69 static  process (bb)
70 struct bboard  *bb;
71 {
72     struct stat st;
73
74     if (stat (bb -> bb_archive, &st) == NOTOK)
75         return;
76     if (strncmp (archives, bb -> bb_archive, strlen (archives)) == 0)
77         bb -> bb_archive += strlen (archives);
78
79     if (priv == 0)
80         printf ("%s\n", bb -> bb_archive);
81     else
82         if ((st.st_mode & 0444) != 0444 ? (priv > 0) : (priv < 0))
83             printf ("%s\n", bb -> bb_archive);
84 }