curtis
16小時前 713024ccb5056e76bcfc9389664981da68a5139f
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
const fs = require('fs');
const path = require('path');
 
const JSON_FILES = [
  'doc/curtis/prompt/scanimpl_analysis/scanimpl_annalysis.BusinessLogic.json',
  'doc/curtis/prompt/scanimpl_analysis/scanimpl_annalysis.ImageProcessor.json',
  'doc/curtis/prompt/scanimpl_analysis/scanimpl_annalysis.ScannerController.json',
  'doc/curtis/prompt/scanimpl_analysis/scanimpl_annalysis.TransportManager.json',
  'doc/curtis/prompt/scanimpl_analysis/scanimpl_annalysis.UIView.json'
];
 
const TAGS_TO_FILE = {
  // ScannerController
  'ScannerController.acquisitionHandler': 'CB_IMGPSScanImp.scan.ac.pas',
  'ScannerController.twainWrapper': 'CB_IMGPSScanImp.scan.twain.pas',
 
  // TransportManager
  'TransportManager.apiClient': 'CB_IMGPSScanImp.apiClient.pas',
  'TransportManager.fileTransfer': 'CB_IMGPSScanImp.fileClient.pas',
  'TransportManager.certificateManager': 'CB_IMGPSScanImp.cert.pas',
  'TransportManager.payloadArchiver': 'CB_IMGPSScanImp.archiver.pas',
 
  // ImageProcessor
  'ImageProcessor.transformer': 'CB_IMGPSScanImp.img.trans.pas',
  'ImageProcessor.converter': 'CB_IMGPSScanImp.img.cnv.pas',
  'ImageProcessor.anchorAnalyzer': 'CB_IMGPSScanImp.img.anchor.pas',
  'ImageProcessor.payloadArchiver': 'CB_IMGPSScanImp.archiver.pas',
 
  // BusinessLogic
  'BusinessLogic.systemInternal': 'CB_IMGPSScanImp.bloc.sys.pas',
  'BusinessLogic.configRepository': 'CB_IMGPSScanImp.bloc.cfg.pas',
  'BusinessLogic.ruleEngine': 'CB_IMGPSScanImp.bloc.rule.pas',
  'BusinessLogic.entityMapping': 'CB_IMGPSScanImp.bloc.map.pas',
  'BusinessLogic.fileManager': 'CB_IMGPSScanImp.bloc.file.pas',
  'BusinessLogic.caseManager': 'CB_IMGPSScanImp.bloc.case.pas',
  'BusinessLogic.entityModel': 'CB_IMGPSScanImp.bloc.model.pas',
  'BusinessLogic.activeXWrapper': 'CB_IMGPSScanImp.bloc.ocx.pas',
 
  // UIView
  '初始化與生命週期': 'CB_IMGPSScanImp.view.lfcycle.pas',
  'UIView.events': 'CB_IMGPSScanImp.view.evt.pas',
  'UIView.inputHandler': 'CB_IMGPSScanImp.view.evt.pas',
  'UIView.configRepository': 'CB_IMGPSScanImp.view.cfg.pas',
  'UIView.ruleEngine': 'CB_IMGPSScanImp.view.rule.pas',
  'UIView.entityMapping': 'CB_IMGPSScanImp.view.map.pas',
  'UIView.fileManager': 'CB_IMGPSScanImp.view.file.pas',
  'UIView.caseManager': 'CB_IMGPSScanImp.view.case.pas',
  'UIView.entityModel': 'CB_IMGPSScanImp.view.model.pas',
  'UIView.activeXWrapper': 'CB_IMGPSScanImp.view.ocx.pas',
  'UIView.treeView': 'CB_IMGPSScanImp.view.tree.pas',
  'UIView.toolBar': 'CB_IMGPSScanImp.view.toolbar.pas',
  'UIView.imageScrollBox': 'CB_IMGPSScanImp.view.isb.pas',
  'UIView.popupMenu': 'CB_IMGPSScanImp.view.menu.pas',
  'UIView.listView': 'CB_IMGPSScanImp.view.list.pas',
};
 
const SRC_FILE = 'CB_IMGPSScanImp.pas.bk';
 
function main() {
  const originalContent = fs.readFileSync(SRC_FILE, 'utf8');
  const lines = originalContent.split(/\r?\n/);
 
  let successCount = 0;
  let failCount = 0;
 
  JSON_FILES.forEach(jsonFile => {
    console.log(`Checking ${jsonFile}...`);
    const data = JSON.parse(fs.readFileSync(jsonFile, 'utf8'));
    data.forEach(m => {
      const lIndex = parseInt(m.lIndex);
      const rIndex = parseInt(m.rIndex);
      if (lIndex <= 0 || rIndex <= 0) return;
 
      // Find the target file
      let targetFile = null;
      for (const tag of m.tags) {
        if (TAGS_TO_FILE[tag]) {
          targetFile = TAGS_TO_FILE[tag];
          break; 
        }
      }
 
      if (targetFile) {
        if (!fs.existsSync(targetFile)) {
          console.error(`Error: Target file ${targetFile} does not exist.`);
          failCount++;
          return;
        }
 
        const subFileContent = fs.readFileSync(targetFile, 'utf8');
        const expectedCodeLines = lines.slice(lIndex - 1, rIndex);
        const expectedCode = expectedCodeLines.join('\n');
 
        // Check if expectedCode exists in subFileContent
        // Note: the subFileContent has an extra \n between methods
        if (subFileContent.includes(expectedCode)) {
          successCount++;
        } else {
          console.error(`Error: Code for ${m.matcher} (line ${lIndex}-${rIndex}) not found in ${targetFile}`);
          failCount++;
        }
      }
    });
  });
 
  console.log(`\nVerification Results:`);
  console.log(`  Success: ${successCount}`);
  console.log(`  Fail: ${failCount}`);
 
  if (failCount > 0) {
    process.exit(1);
  }
}
 
main();