File: cccc_ext.cc

package info (click to toggle)
cccc 3.pre81-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,820 kB
  • ctags: 4,972
  • sloc: ansic: 33,244; cpp: 10,691; java: 618; makefile: 165; sh: 11
file content (156 lines) | stat: -rw-r--r-- 2,961 bytes parent folder | download | duplicates (2)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * cccc_ext.cc
 */

#include "cccc_itm.h"
#include "cccc_ext.h"
#include "cccc_db.h"
#include "cccc_utl.h"

unsigned int CCCC_Extent::nextkey=0;

CCCC_Extent::CCCC_Extent()
{
  v=vINVALID;
  ut=utINVALID;
  extkey=++nextkey;
}

CCCC_Extent::CCCC_Extent(CCCC_Item& is) 
{
  char v_as_char='!', ut_as_char='!';
 
  if(
     is.Extract(filename) &&
     is.Extract(linenumber) &&
     is.Extract(description) &&
     is.Extract(flags) &&
     is.Extract(count_buffer) &&
     is.Extract(v_as_char) &&
     is.Extract(ut_as_char)
     ) 
    {
      v=(Visibility) v_as_char;
      ut=(UseType) ut_as_char;
    }
  else
    {
      // we can trust the string constructor to give us empty strings,
      // but we need to initialise these
      v=vDONTKNOW;
      ut=utDONTKNOW;
    }
  extkey=++nextkey;
}

int CCCC_Extent::AddToItem(CCCC_Item& item)
{
  int retval=FALSE;
  
  if(
     item.Insert(filename) &&
     item.Insert(linenumber) &&
     item.Insert(description) &&
     item.Insert(flags) &&
     item.Insert(count_buffer) &&
     item.Insert((char) v) &&
     item.Insert((char) ut)
     )
    {
      retval=TRUE;
    }

  return retval;
}

int CCCC_Extent::GetFromItem(CCCC_Item &item)
{
  int retval=FALSE;
  char v_as_char, ut_as_char;
  if(
     item.Extract(filename) &&
     item.Extract(linenumber) &&
     item.Extract(description) &&
     item.Extract(flags) &&
     item.Extract(count_buffer) &&
     item.Extract(v_as_char) &&
     item.Extract(ut_as_char)
     )
    {
      v = (Visibility) v_as_char;
      ut = (UseType) ut_as_char;
      retval=TRUE;
    }

  return retval;
}


string CCCC_Extent::name(int level) const
{
  string rtnbuf;

  rtnbuf="";

  switch(level)
    {
    case nlFILENAME:
      rtnbuf=filename;
      break;
    case nlLINENUMBER:
      rtnbuf=linenumber;
      break;
    case nlDESCRIPTION:
      rtnbuf=description;
      break;
    case nlSEARCH:
    case nlRANK:
      // Extents have no meaningful internal primary key.
      // We never want two extents to have the same
      // key, so we use the running number extkey
      // which is initialized in both constructors.
      // This should cause extents to sort in order of
      // their creation, which is fine.
      char buf[16];
      sprintf(buf,"%015d",extkey);
      rtnbuf=buf;
      break;

    default:
      rtnbuf+=filename;
      rtnbuf+=":";
      rtnbuf+=linenumber;
    }
  return rtnbuf.c_str();
}

string CCCC_Extent::key() const { return name(nlRANK); }

int CCCC_Extent::get_count(const char* count_tag) {
  int retval=0;
  char local_count_buffer[100], *count_tag_ptr, *count_value_ptr;
  strcpy(local_count_buffer,count_buffer.c_str());
  count_tag_ptr=strtok(local_count_buffer,":");
  while(count_tag_ptr!=NULL)
    {
      count_value_ptr=strtok(NULL," ");
      if(strcmp(count_tag_ptr, count_tag) ==0)
	{
	  retval+=atoi(count_value_ptr);
	}
      count_tag_ptr=strtok(NULL,":");
    }
  return retval;
}