Class: IarProject

Inherits:
Object
  • Object
show all
Defined in:
lib/warlock/iar_project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath: '') ⇒ IarProject

Returns a new instance of IarProject.



10
11
12
13
14
15
16
17
# File 'lib/warlock/iar_project.rb', line 10

def initialize(filepath: '')
    @filepath = filepath
    @projectdirectory = File.dirname(filepath)
    @srcfiles = Array.new()
    @headerfiles = Array.new()
    @asmfiles = Array.new()
    read_data_from_file()
end

Instance Attribute Details

#asmfilesObject

Returns the value of attribute asmfiles.



8
9
10
# File 'lib/warlock/iar_project.rb', line 8

def asmfiles
  @asmfiles
end

#filepathObject

Returns the value of attribute filepath.



4
5
6
# File 'lib/warlock/iar_project.rb', line 4

def filepath
  @filepath
end

#headerfilesObject

Returns the value of attribute headerfiles.



7
8
9
# File 'lib/warlock/iar_project.rb', line 7

def headerfiles
  @headerfiles
end

#projectdirectoryObject

Returns the value of attribute projectdirectory.



5
6
7
# File 'lib/warlock/iar_project.rb', line 5

def projectdirectory
  @projectdirectory
end

#srcfilesObject

Returns the value of attribute srcfiles.



6
7
8
# File 'lib/warlock/iar_project.rb', line 6

def srcfiles
  @srcfiles
end

Instance Method Details

#add_source_file(referencefile: '', expectedclosenesslevel: 1) ⇒ Object



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
# File 'lib/warlock/iar_project.rb', line 19

def add_source_file(referencefile: '', expectedclosenesslevel: 1)
  normalizedReferencePath = Pathname.new(referencefile).cleanpath
  referenceFileParts = normalizedReferencePath.to_s.downcase.split( '/' )
  toAddArraySize = referenceFileParts.length()
  result = 0
  referenceLine = ''

  srcfiles.each do |l|
    line = l.downcase
    path = line.match(/[$]proj_dir[$](.*)/)[1]
    path = projectdirectory + '/' + path
    normalizedPath = Pathname.new(path).cleanpath
    srcProjectFileParts = normalizedPath.to_s.downcase.split('/');
  
    existingAraySize = srcProjectFileParts.length()
        
    size = [].push(existingAraySize).push(toAddArraySize).max()

    i = 0;
    for i in 1..size
        if srcProjectFileParts[i] != referenceFileParts[i]
            break
        end
    end
    if i != 0
        i = i -1
    end

    if i >= expectedclosenesslevel
      # first match of file with requried closeness level
      referenceLine = l
      srcfileLine = build_src_file_line_by_template(srcfile: referencefile, templatefile: referenceLine)
      insert_src_file_line_above_reference(srcfileLine: srcfileLine, referenceLine: referenceLine)
      break
    end
  end
end

#calculate_closeness_level(referencefile: '') ⇒ Object



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
# File 'lib/warlock/iar_project.rb', line 57

def calculate_closeness_level(referencefile: '') 
    normalizedReferencePath = Pathname.new(referencefile).cleanpath
    referenceFileParts = normalizedReferencePath.to_s.downcase.split( '/' )
    toAddArraySize = referenceFileParts.length()
    result = 0
    srcfiles.each do |l|
      line = l.downcase
      path = line.match(/[$]proj_dir[$](.*)/)[1]
      path = projectdirectory + '/' + path
      normalizedPath = Pathname.new(path).cleanpath
      srcProjectFileParts = normalizedPath.to_s.downcase.split('/');
    
      existingAraySize = srcProjectFileParts.length()
          
      size = [].push(existingAraySize).push(toAddArraySize).max()

      i = 0;
      for i in 1..size
          if srcProjectFileParts[i] != referenceFileParts[i]
              break
          end
      end
      if i != 0
          i = i -1
      end

      if i>result
        result = i
      end

    end

    return result
   
end