File: __packpats.c

package info (click to toggle)
afbackup 3.3.8.1beta2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,128 kB
  • ctags: 3,370
  • sloc: ansic: 46,932; sh: 4,654; tcl: 4,199; makefile: 536; csh: 416; perl: 133; sed: 93
file content (98 lines) | stat: -rw-r--r-- 2,025 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/****************** Start of $RCSfile: __packpats.c,v $  ****************
*
* $Source: /home/alb/afbackup/afbackup-3.3.8beta7/RCS/__packpats.c,v $
* $Id: __packpats.c,v 1.3 2004/07/08 20:34:42 alb Exp alb $
* $Date: 2004/07/08 20:34:42 $
* $Author: alb $
*
*
******* description ***********************************************
*
*
*
*******************************************************************/

#include <conf.h>
#include <version.h>

  static char * fileversion = "$RCSfile: __packpats.c,v $ $Source: /home/alb/afbackup/afbackup-3.3.8beta7/RCS/__packpats.c,v $ $Id: __packpats.c,v 1.3 2004/07/08 20:34:42 alb Exp alb $ " PACKAGE " " VERSION_STRING;

#include <stdio.h>
#include <unistd.h>
#include <x_types.h>
#include <genutils.h>
#include <fileutil.h>
#include <packer.h>
#include <backup.h>

#define	EM__(arg)	nomemmsgexit((arg), stderr)

void
usage(UChar * prognam)
{
  fprintf(stderr, "Usage: %s <path>\n", FN_BASENAME(prognam));

  exit(2);
}

main(int argc, char ** argv)
{
  UChar		*line = NULL, *oldline, *c2, *c3, *pat;
  Int32		len, clen, llen, nall = 0, oldall;

  if(argc > 2)
    usage(argv[0]);

  pat = argc > 1 ? argv[1] : "";
  if(pat[0] && strcmp(pat, "/"))
    EM__(pat = strapp(pat, "/"));

  len = strlen(pat);

  clen = strlen(CMDINOUTPREFIX);

  EM__(oldline = NEWP(UChar, oldall = 1024));
  strcpy(oldline, "");

  while(!feof(stdin)){
    if(fget_realloc_str(stdin, &line, &nall))
	continue;
    chop(line);

    if(!strncmp(line, CMDINOUTPREFIX, clen)){
	fprintf(stdout, "%s\n", line);
	fflush(stdout);
	continue;
    }

    if(!strncmp(pat, line, len)){
	c2 = line + len;
#if 0
	if(*c2 != FN_DIRSEPCHR)
	  continue;
#endif

	c3 = strchr(c2 + 1, FN_DIRSEPCHR);
	if(c3){
	  c2 = c3;
	  c3 = strchr(c2 + 1, FN_DIRSEPCHR);
	  if(c3)
	    *c3 = '\0';
	}

	if(!strcmp(line, oldline))
	  continue;

	fprintf(stdout, "%s\n", line);
	fflush(stdout);

	llen = strlen(line) + 1;
	if(llen > oldall)
	  oldline = RENEWP(oldline, UChar, oldall = llen);

	strcpy(oldline, line);
    }
  }

  exit(0);
}