File: filespec.c

package info (click to toggle)
ytree 1.94-1.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 836 kB
  • ctags: 1,510
  • sloc: ansic: 15,271; makefile: 208
file content (108 lines) | stat: -rw-r--r-- 2,263 bytes parent folder | download | duplicates (6)
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
99
100
101
102
103
104
105
106
107
108
/***************************************************************************
 *
 * $Header: /usr/local/cvsroot/utils/ytree/filespec.c,v 1.13 2005/01/22 16:32:29 werner Exp $
 *
 * Setzt neue Datei-Spezifikation
 *
 ***************************************************************************/


#include "ytree.h"




int SetFileSpec(char *file_spec)
{
  if( SetMatchSpec( file_spec ) )
  {
    return( 1 );
  }

  statistic.disk_matching_files = 0L;
  statistic.disk_matching_bytes = 0L;

  SetMatchingParam( statistic.tree );

  return( 0 );
}




void SetMatchingParam(DirEntry *dir_entry)
{
  DirEntry  *de_ptr;
  FileEntry *fe_ptr;
  unsigned long  matching_files;
  LONGLONG matching_bytes;

  for( de_ptr = dir_entry; de_ptr; de_ptr = de_ptr->next )
  {
    matching_files = 0L;
    matching_bytes = 0L;

    for( fe_ptr = de_ptr->file; fe_ptr; fe_ptr = fe_ptr->next )
    {
      if( Match( fe_ptr->name ) )
      {
	matching_files++;
	matching_bytes += fe_ptr->stat_struct.st_size;
	fe_ptr->matching = TRUE;
      }
      else
      {
	fe_ptr->matching = FALSE;
      }
    }
   
    de_ptr->matching_files = matching_files;
    de_ptr->matching_bytes = matching_bytes;

    statistic.disk_matching_files += matching_files;
    statistic.disk_matching_bytes += matching_bytes;
    
    if( de_ptr->sub_tree ) 
    {
      SetMatchingParam( de_ptr->sub_tree );
    }
  }
}



/***************************************************************>>
ReadFileSpec.
Take in the user-specified new filespec.
As modified, it defaults to '*'; the original version offered the
current value as default, but that's just an up-arrow away.
Returns 0 on success, -1 on failure (empty string).
<<***************************************************************/            

int ReadFileSpec(void)
{
  int result = -1;

  char buffer[FILE_SPEC_LENGTH * 2 + 1];

  ClearHelp();

  (void) strcpy( buffer, "*" );
  MvAddStr( LINES - 2, 1, "New filespec:" );
  if( InputString( buffer, LINES - 2, 15, 0, FILE_SPEC_LENGTH, "\r\033" ) == CR )
  {
    if( SetFileSpec( buffer ) )
    {
      MESSAGE( "Invalid Filespec" );
    }
    else
    {
      (void) strcpy( statistic.file_spec, buffer );
      result = 0;
    }
  }
  move( LINES - 2, 1 ); clrtoeol();
  return(result);
}