CppUmlClass 0.8.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ class IfdefProcess
4
+ attr_reader :define_list
5
+
6
+ def initialize()
7
+ @define_list = []
8
+ end
9
+
10
+ def remove_suffixes(text)
11
+ suffixes = %w[ULL LL UL D F U L]
12
+ suffix_pattern = suffixes.uniq.sort_by(&:length).reverse.join("|")
13
+ #puts suffix_pattern
14
+ regex = /(\d+\.?\d*)(?:#{suffix_pattern})\b/i
15
+ text.gsub(regex, '\1')
16
+ end
17
+
18
+ def check_ifdefined(cond_string, define_hash)
19
+ pattern = /(!)?defined\(([^)]*)\)/
20
+ define_hash_new = define_hash.dup
21
+ matches = cond_string.scan(pattern)
22
+
23
+ matches.each do |match|
24
+ # !definedでKeyが未登録の場合は登録
25
+ has_exclamation = !match[0].nil?
26
+ key = match[1]
27
+ if has_exclamation
28
+ unless define_hash.key? key
29
+ define_hash_new[key] = false
30
+ end
31
+ end
32
+ end
33
+
34
+ return define_hash_new
35
+ end
36
+
37
+ def condition_judge(cond_string, define_hash)
38
+ ret = false
39
+ #puts "cond_string=#{cond_string}"
40
+ cond_string = remove_suffixes(cond_string)
41
+ #puts "cond_string=#{cond_string}"
42
+ define_hash_new = check_ifdefined(cond_string, define_hash)
43
+ #pp define_hash_new
44
+ cond_string.gsub!(/defined/, "")
45
+ if cond_string.gsub(/ /, "").to_s == "0"
46
+ # not define
47
+ #puts "return ifdef_judge #{ret}"
48
+ return false
49
+ end
50
+ eval_buf = []
51
+ arg_hash = {}
52
+ eval_buf.push "def judge_ifdef"
53
+ cond_string.scan(/[_A-Za-z][_A-Za-z_0-9]+/) do |m|
54
+ #puts "scan word=#{m}"
55
+ @define_list.push m
56
+ next if m == "false" or m == "true"
57
+ if define_hash_new.key? m
58
+ arg_hash[m] = define_hash_new[m]
59
+ else
60
+ # not define
61
+ #puts "return ifdef_judge #{ret}"
62
+ return false
63
+ end
64
+ end
65
+ #puts "arg_hash=#{arg_hash}"
66
+ arg_hash.each do |key, val|
67
+ eval_buf.push " #{key.downcase} = #{val}"
68
+ end
69
+ eval_buf.push " if #{cond_string.downcase}"
70
+ eval_buf.push " return true"
71
+ eval_buf.push " else"
72
+ eval_buf.push " return false"
73
+ eval_buf.push " end"
74
+ eval_buf.push "end"
75
+ eval_buf.push "judge_ifdef()"
76
+ eval_string = eval_buf.join("\n")
77
+ #puts "eval_string=#{eval_string}"
78
+ ret = eval eval_string
79
+ #puts "return ifdef_judge #{ret}"
80
+ return ret
81
+ end
82
+
83
+ def process_ifdef(file_buf, define_hash)
84
+ out_buf = []
85
+ proc_list = [true]
86
+ line_count = 1
87
+ ifdef_flag = [false]
88
+ file_buf.each_line do |line|
89
+ line = line.strip
90
+ case line
91
+ when /^#ifdef\s+(.*)/
92
+ proc_list.push condition_judge($1, define_hash)
93
+ ifdef_flag.push proc_list[-1]
94
+ #puts "#ifdef #{ifdef_flag[-1]}:#{line_count}:line=[#{line}]:#{$1}"
95
+ when /^#ifndef\s+(.+)/
96
+ proc_list.push !(condition_judge($1, define_hash))
97
+ ifdef_flag.push proc_list[-1]
98
+ #puts "#ifndef #{ifdef_flag[-1]}:#{line_count}:line=[#{line}]:#{$1}"
99
+ when /^#if\s+(.+)/
100
+ proc_list.push condition_judge($1, define_hash)
101
+ ifdef_flag.push proc_list[-1]
102
+ #puts "#if #{ifdef_flag[-1]}:#{line_count}:line=[#{line}]:#{$1}"
103
+ when /^#elif\s+(.+)/
104
+ if !ifdef_flag[-1]
105
+ proc_list[-1] = condition_judge($1, define_hash)
106
+ ifdef_flag[-1] = proc_list[-1]
107
+ else
108
+ proc_list[-1] = false
109
+ ifdef_flag[-1] = true
110
+ end
111
+ #puts "#elif #{ifdef_flag[-1]}:#{line_count}:line=[#{line}]:#{$1}"
112
+ when /^#else/
113
+ if !ifdef_flag[-1]
114
+ proc_list[-1] = !proc_list[-1]
115
+ else
116
+ proc_list[-1] = false
117
+ ifdef_flag[-1] = true
118
+ end
119
+ #puts "#else #{ifdef_flag[-1]}:#{line_count}:line=[#{line}]"
120
+ when /^#endif/
121
+ proc_list.pop
122
+ ifdef_flag.pop
123
+ #puts "#endif #{ifdef_flag[-1]}:#{line_count}:line=[#{line}]"
124
+ else
125
+ #print "proc_list="
126
+ #pp proc_list
127
+ if 0 == proc_list.select { |p| p == false }.size
128
+ #puts "#{ifdef_flag[-1]}:#{line_count}: #{line}"
129
+ out_buf.push line
130
+ else
131
+ #puts "#{ifdef_flag[-1]}:#{line_count}: #{line}"
132
+ end
133
+ end
134
+ line_count += 1
135
+ end
136
+ @define_list.uniq!
137
+ return out_buf
138
+ end
139
+ end
140
+
141
+ if $0 == __FILE__
142
+ #file = "/home/kuwayama/tool/cpp_test/test1/test3.cpp"
143
+ file = ARGV[0]
144
+ buf = File.read(file)
145
+ # define_hash = {
146
+ # "TEST" => false,
147
+ # "TEST2" => false,
148
+ # "TEST3" => false,
149
+ # "DEBUG" => false,
150
+ # "AAA" => false,
151
+ # "BBB" => true,
152
+ # }
153
+ define_hash = {}
154
+ pifdef = IfdefProcess.new
155
+ out = pifdef.process_ifdef(buf, define_hash)
156
+ puts "-----------------------------------------------------------------------------------------"
157
+ puts out
158
+ puts "-----------------------------------------------------------------------------------------"
159
+ puts pifdef.define_list
160
+ end
data/lib/js/main.js CHANGED
@@ -81,9 +81,12 @@ function server_connect(url) {
81
81
  open_dialog("<font color='red'>エラーが発生しました</font>");
82
82
  }
83
83
  else if (evt.data.match(/^popup:/)) {
84
- open_dialog(evt.data.replace(/^popup:/, ""), 3000);
84
+ console.log("str=" + evt.data);
85
+ const timeout_str = evt.data.match(/:(\d+):/);
86
+ console.log("timeout_str=" + timeout_str[1]);
87
+ open_dialog(evt.data.replace(/^popup:(\d+):/, ""), Number(timeout_str[1]));
85
88
  } else {
86
- var log = "<li>" + evt.data + "</li>";
89
+ var log = evt.data;
87
90
  $('#log').append(log);
88
91
  if ($auto_scroll) {
89
92
  $('.outarea').scrollTop($('.outarea').get(0).scrollHeight);
@@ -184,7 +187,7 @@ function select_file_dialog(search_id, file_kind, dialog_id, select_file, file_n
184
187
  , hide: "explode" //閉じた時のアニメーション
185
188
  , title: "Select File" //ダイアログのタイトル
186
189
  , width: 580 //ダイアログの横幅
187
- , height: 400 //ダイアログの高さ
190
+ , height: 120 //ダイアログの高さ
188
191
  , resizable: true //リサイズ可
189
192
  , closeOnEscape: false //[ESC]キーで閉じられなくする
190
193
  , draggable: true //ダイアログの移動を可に
@@ -205,6 +208,8 @@ function select_file_dialog(search_id, file_kind, dialog_id, select_file, file_n
205
208
 
206
209
  function setting_dialog(open_id, dialog_id, json_file) {
207
210
  var version;
211
+ var is_error = false;
212
+
208
213
  $("#" + open_id).click(function () {
209
214
  $("#" + dialog_id).val = $(function () {
210
215
  $("dl#wrap").empty();
@@ -217,6 +222,14 @@ function setting_dialog(open_id, dialog_id, json_file) {
217
222
  + "<td><input class='setting_value' type='text' " + "id=" + s["setting_list"][i].name + "_value " + "value=" + "'" + s["setting_list"][i].value + "'" + ">"
218
223
  + "</td></tr></table>"
219
224
  $("dl#wrap").append(h);
225
+ } else if (s["setting_list"][i].type == "textarea") {
226
+ var h = "<table><tr>"
227
+ + "<td class='setting_name'>" + s["setting_list"][i].description + "</td>"
228
+ + "<td><textarea class='setting_value' rows='5' " + "id=" + s["setting_list"][i].name + "_value " + "value=" + ">"
229
+ + "" + JSON.stringify(s["setting_list"][i].value, null, 2)
230
+ + "</textarea>"
231
+ + "</td></tr></table>"
232
+ $("dl#wrap").append(h);
220
233
  } else if (s["setting_list"][i].type == "checkbox") {
221
234
  var h = "<table><tr>";
222
235
  h += "<td class='setting_name'>" + s["setting_list"][i].description + "</td>";
@@ -253,7 +266,7 @@ function setting_dialog(open_id, dialog_id, json_file) {
253
266
  , hide: "explode" //閉じた時のアニメーション
254
267
  , title: "Setting" //ダイアログのタイトル
255
268
  , width: 650 //ダイアログの横幅
256
- , height: 500 //ダイアログの高さ
269
+ , height: 600 //ダイアログの高さ
257
270
  , resizable: true //リサイズ可
258
271
  , closeOnEscape: false //[ESC]キーで閉じられなくする
259
272
  , draggable: true //ダイアログの移動を可に
@@ -261,6 +274,7 @@ function setting_dialog(open_id, dialog_id, json_file) {
261
274
  "OK": function () { //OKボタン
262
275
  var json_obj = {};
263
276
  var json_data = [];
277
+ is_error = false;
264
278
  $.getJSON(json_file, function (s) {
265
279
  json_obj["version"] = s["version"];
266
280
  for (var i in s["setting_list"]) {
@@ -274,6 +288,20 @@ function setting_dialog(open_id, dialog_id, json_file) {
274
288
  data["description"] = s["setting_list"][i].description;
275
289
  json_data.push(data);
276
290
  }
291
+ else if (s["setting_list"][i].type == "textarea") {
292
+ var data = {};
293
+ data["name"] = s["setting_list"][i].name;
294
+ try {
295
+ data["value"] = JSON.parse($("#" + s["setting_list"][i].name + "_value").val());
296
+ } catch (e) {
297
+ is_error = true;
298
+ alert("JavaScript error:" + e.message + "\n" + $("#" + s["setting_list"][i].name + "_value").val());
299
+ }
300
+ data["type"] = s["setting_list"][i].type;
301
+ data["select"] = s["setting_list"][i].select;
302
+ data["description"] = s["setting_list"][i].description;
303
+ json_data.push(data);
304
+ }
277
305
  else if (s["setting_list"][i].type == "checkbox") {
278
306
  var data = {};
279
307
  data["name"] = s["setting_list"][i].name;
@@ -298,13 +326,23 @@ function setting_dialog(open_id, dialog_id, json_file) {
298
326
  //console.log("type=" + s["setting_list"][i].type);
299
327
  }
300
328
  }
329
+ console.log("OK Button " + is_error);
301
330
  // Jsonデータをサーバに送信
302
- json_obj["setting_list"] = json_data;
303
- $ws.send("setting:" + JSON.stringify(json_obj));
304
- });
305
- $(this).dialog("close");
331
+ if (is_error == false) {
332
+ json_obj["setting_list"] = json_data;
333
+ var json_string = JSON.stringify(json_obj);
334
+ console.log("json_string:" + json_string);
335
+ $ws.send("setting:" + json_string);
336
+ }
337
+ })
338
+ .done(function () {
339
+ if (is_error == false) {
340
+ $("#" + dialog_id).dialog("close");
341
+ }
342
+ });
306
343
  },
307
344
  "Cancel": function () { //Cancelボタン
345
+ console.log("Cancel Button");
308
346
  $(this).dialog("close");
309
347
  }
310
348
  }
@@ -384,10 +422,10 @@ function openFile(file) {
384
422
  $(document).ready(function () {
385
423
 
386
424
  // サーバに接続
387
- server_connect("ws://localhost:34731/wsserver")
425
+ server_connect("ws://localhost:38899/wsserver")
388
426
  window.onload = function (e) {
389
427
  // サーバに接続
390
- //server_connect("ws://localhost:34731/wsserver")
428
+ //server_connect("ws://localhost:38899/wsserver")
391
429
  }
392
430
 
393
431
  // menu
@@ -408,14 +446,15 @@ $(document).ready(function () {
408
446
  var width = 800;
409
447
  var height = 600;
410
448
  $(window).resize(function () {
411
- $(".outarea").height($(window).height() - 180);
449
+ //$(".outarea").height($(window).height() - 170);
450
+
412
451
  });
413
452
  // ウインドウの位置
414
453
  $(function () {
415
454
  //window.resizeTo(width, height);
416
455
  //window.moveTo((window.screen.width / 2) - (width / 2), (screen.height / 2) - (height / 2));
417
456
  //window.moveTo(0,0);
418
- $(".outarea").height($(window).height() - 180);
457
+ //$(".outarea").height($(window).height() - 170);
419
458
  });
420
459
 
421
460
  $('.outarea').scroll(function () {
data/lib/wsserver.rb CHANGED
@@ -62,7 +62,7 @@ class WsServer < Sinatra::Base
62
62
  $app.start(argv.split(",")) do |out|
63
63
  ws_send(out)
64
64
  end
65
- ws_send("app_end:normal")
65
+ #ws_send("app_end:normal")
66
66
  rescue
67
67
  puts $!
68
68
  puts $@
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CppUmlClass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masataka Kuwayama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-23 00:00:00.000000000 Z
11
+ date: 2025-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: browser_app_base
@@ -65,6 +65,7 @@ files:
65
65
  - lib/css/index.css
66
66
  - lib/html/index.html
67
67
  - lib/html/test.html
68
+ - lib/ifdef_process.rb
68
69
  - lib/js/main.js
69
70
  - lib/my_app_sample.rb
70
71
  - lib/server.rb