updated version of yc/struct-to-dot
tubo
posted @ 2014年9月03日 00:08
in 未分类
, 720 阅读
NOTE: Refer to https://github.com/yangyingchao/tubo-env/blob/master/.emacs.d/rc/01-rc-functions.el for newer version.
� ;; Function used to add fields of struct into a dot file (for Graphviz). ;;;;; Dot templates (defconst yc/dot-head "subgraph cluster_%s { node [shape=record fontsize=12 fontname=Courier style=filled]; color = lightgray; style=filled; label = \"%s %s\"; edge[color=\"brown\"];" "Header part of dot file.") (defconst yc/dot-tail " }" "Tail part of dot") (defconst yc/dot-node-head "node_%s[shape=record label=\"{<f0>*** %s %s ***|\\" "Format of node.") (defconst yc/dot-node-tail " }\"];" "Format of node.") (defconst attr_str " <f%d>+%s : %s\\l|\\" "nil") (defconst attr_func " -%s() : %s\\l\\" "nil") ;;;;; Regular expressions to match a field of a struct.
(defconst r_attr_str
(rx bow (group (+ (or alnum "_" blank "*"))) (one-or-more blank)
(group (+ alnum) (+? ascii)) ";")
"Regular expression for matching struct fields.")
(defconst r_name (rx (zero-or-one "typedef") (zero-or-more blank) (group (or "class" "struct")) (zero-or-more blank) (zero-or-one (group (+? (or alnum "_" )))) (zero-or-more blank) (zero-or-one ":" (+? (or alnum "_" blank))) (zero-or-more "
") (zero-or-more blank) "{"
(1+ anything) "}" (zero-or-more blank) (zero-or-one (group (zero-or-more not-newline)) ";") ) "Regular expression for mating struct name") (defconst r_func_l "\(.*" "Regular expression to match a function") (defconst r_func_r ".*\)" "Regular expression to match a function") (defconst r_comments (rx line-start (zero-or-more blank) (or "//" "/*") (zero-or-more anything) line-end) "Regular expression to match a commentted field.") (defconst r_struct_func "^[ \t]*\\(.+?\\)[ \t]*\(\\*\\(.*?\\)\)[ \t]*(\\(?:.\\|\\)*?);" "Regular expression to match a function decleration in a struct.") (defconst r_match_semicol (rx (+? anything) ";")) (defconst r_match_attr (rx (+? (not (any "(" ")" "{" "}"))) ";")) (defconst r_match_func (rx (zero-or-more blank) (zero-or-one (group (+? (or alnum "_" blank)))) (one-or-more blank) (group (+? (or alnum "_"))) (zero-or-more blank) "(" (*? anything) ");")) (defconst r_match_tag (rx (zero-or-more blank) (zero-or-one "typedef" (one-or-more blank)) (or "struct" "class") (zero-or-more (or alnum "_" ":" blank)) (zero-or-one " ") (zero-or-more blank) "{" )) (defconst r_c_comment (rx "/*" (*? anything) "*/") "Regular expression to match comment of C style.") (defconst r_cpp_comment (rx "//" (*? not-newline) line-end) "Regular expression to match comment of C style.") (defun clean_c_comment (a) "Function to remove all comments, both C style and C++ style." (let ((all-clean nil) (result nil) (tmp 0)) (while (not all-clean) (setq result (if (string-match r_c_comment a) (progn (cons (match-beginning 0) (match-end 0))) nil)) (if result (progn (setq tmp (car result)) (while (< tmp (cdr result)) (aset a tmp ? ) (setq tmp (1+ tmp)))) (setq all-clean t))) (setq all-clean nil) (setq result nil) (while (not all-clean) (setq result (if (string-match r_cpp_comment a) (progn (cons (match-beginning 0) (match-end 0))) nil)) (if result (progn (princ result) (setq tmp (car result)) (while (< tmp (cdr result)) (aset a tmp ? ) (setq tmp (1+ tmp)))) (setq all-clean t) ))) (replace-regexp-in-string " +" " " a)) (defun get_struct_tag (decleration) "Abstract decleration from a string" (message decleration) (if (string-match r_name decleration 0) (progn (cons (match-string 1 decleration) (if (and (match-string 3 decleration) (> (length (match-string 3 decleration)) 0)) (match-string 3 decleration) (if (match-string 2 decleration) (match-string 2 decleration) "nil")))) '("struct" . "nil"))) (defun skip(msg x) (if x (message (format "Skip invalid syntax for function: %s." msg)) (message (format "Skip invalid syntax for struct field: %s." msg)) ) ) (defun yc/struct-to-dot (start end) "generate c++ function definition and insert it into `buffer'" (interactive "rp") (let* ( (var-name "") (var-type "") (counter 0) (pos-end 0) (var-defination (buffer-substring-no-properties start end)) (item_str "") (tmp-item nil) (attr-list '()) (func-list '()) (tag-info nil) (item-iter 0) ) (defun iter (pos) (if (string-match r_match_tag var-defination pos) ;; Declerad a struct (progn (setq pos-end (match-end 0)) (setq tag-info (get_struct_tag var-defination)) (princ tag-info) (iter (1+ pos-end))) (progn (if (string-match r_match_semicol var-defination pos) (progn (setq pos-end (match-end 0)) (setq item_str (substring var-defination pos pos-end)) (if (string-match r_match_func item_str 0) ;; Function (progn (setq var-type (if (match-string 1 item_str) (match-string 1 item_str) " ")) (setq var-name (match-string 2 item_str)) (add-to-list 'func-list (cons var-type var-name))) (progn (if (equal (string-match r_match_attr item_str 0) 0) (progn (if (string-match r_attr_str item_str 0) (progn (setq var-type (match-string 1 item_str)) (setq var-name (match-string 2 item_str)) (add-to-list 'attr-list (cons var-type var-name))) (skip item_str nil))) (skip item_str nil)))) (iter pos-end)))))) (save-excursion (setq var-defination (clean_c_comment var-defination)) (iter 0) (set-buffer (get-buffer-create "tmp.dot")) (graphviz-dot-mode) (erase-buffer) (goto-char (point-max)) (insert (format yc/dot-node-head (cdr tag-info) (car tag-info) (cdr tag-info))) (setq item-iter (1- (length attr-list))) (while (>= item-iter 0) (setq counter (+ counter 1)) (setq tmp-item (nth item-iter attr-list)) (insert (format attr_str counter (cdr tmp-item) (car tmp-item))) (setq item-iter (1- item-iter))) (if func-list (progn (setq item-iter (1- (length func-list))) (while (>= item-iter 0) (setq counter (+ counter 1)) (setq tmp-item (nth item-iter func-list)) (insert (format attr_func (cdr tmp-item) (car tmp-item))) (setq item-iter (1- item-iter))) (insert " |\\")) ) (goto-char (point-max)) (delete-char -1) (insert "<f999>\\" yc/dot-node-tail)) (if (one-window-p) (split-window-vertically)) (switch-to-buffer-other-window "tmp.dot") (kill-ring-save (point-min) (point-max)) (goto-char (point-min)) ) (message "Finished, node copied to killing-ring."))
2023年1月24日 01:06
This updated version of yc/struct-to-dot provides a user-friendly function to generate a dot file from a struct. Through the use of regular expressions and dot templates, this function seo packages india allows users to add fields of a struct into a dot file. This helps them create diagrams in Graphviz that represent the structure of the struct. Additionally, users can customize the dot templates to create dot files that are well-suited to their needs. This makes it easy to generate visual representations of their structs and better understand their data.
2024年8月07日 04:44
I like this web site because so much utile stuff on here . Yep Media Group
2024年8月09日 00:40
I enjoy this website, will certainly arrive back. Make sure you carry on writing high quality posts. Seymour TN Remodeling
===============
Wonderful post, very informative. I wonder why the other experts of this sector do not notice this. You must continue your writing. I’m sure, you’ve a great readers’ base already! Gatlinburg historic church
===============
I’m curious to find out what blog platform you have been utilizing? I’m experiencing some minor security issues with my latest site and I’d like to find something more secure. Do you have any recommendations? web design sevierville
===============
I love meeting utile info, this post has got me even more info! . black soap
===============
Inspiring insights you are sharing. I love the way you are sharing it. Is there any way I could get updated for more? Horseback riding Gatlinburg
2024年8月11日 02:22
Wow i like yur site. It really helped me with the information i wus looking for. Appcriciate it, will bookmark. Advantages of Venturi Scrubber System manufacturing for Air Pollution Control
2024年8月13日 05:20
It’s perfect time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I desire to suggest you few interesting things or suggestions. Perhaps you could write next articles referring to this article. I wish to read even more things about it! Benefits and Regulatory Frameworks for ZLD Systems in Industrial Sector
2024年8月13日 05:21
I discovered your website site online and check many of your early posts. Keep on the top notch operate. I just now additional your Feed to my MSN News Reader. Looking for forward to reading much more from you finding out later on!… latex catsuit
2024年8月14日 06:25
fantastic points altogether, you simply gained a new reader. What would you recommend in regards to your post that you made some days ago? Any positive? 海外FX
=======================
I dont think Ive read anything like this before. So good to find somebody with some original thoughts on this subject. nice one for starting this up. This site is something that is needed on the web, someone with a little originality. Good job for bringing something new to the internet! Eufy S220 SoloCam
2024年8月19日 01:50
Hello! Do you know if they make any plugins to safeguard against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any suggestions? graphic design jobs
=======================
I am not rattling good with English but I get hold this very easygoing to read . アメリカ・ロサンゼルス州で飲食店開業・経営するまでの流れ
2024年8月21日 20:46
Very good suggestions, I just added this to my RSS feed. What would you suggest in regards to your post that you made a few days ago? artificial hanging plants for outdoors
======================
Cheap Handbags Wholesale Are you ok merely repost this in my site? I’ve to grant credit where it really is due. Have a very great day! 神社のクチコミ・レビュー
2024年8月27日 01:09
With havin so much content and articles do you ever run into any problems of plagorism or copyright infringement? My site has a lot of exclusive content I’ve either authored myself or outsourced but it seems a lot of it is popping it up all over the web without my authorization. Do you know any ways to help protect against content from being stolen? I’d certainly appreciate it. エロマンガ
2024年8月27日 01:12
You should take part in a contest for probably the greatest blogs on the web. I’ll recommend this web site! ゼロ塾ガイド|中学生の高校受験を応援
=========================
Someone necessarily assist to make seriously posts I might state. That is the very first time I frequented your website page and so far? I amazed with the analysis you made to create this particular publish extraordinary. Excellent process! 建設業許可
2024年9月02日 04:28
Great write-up, I am normal visitor of one?s blog, maintain up the excellent operate, and It is going to be a regular visitor for a long time. halloween zentai suit
2024年9月03日 07:52
Oh my goodness! an amazing post dude. Thanks a lot Even so We are experiencing problem with ur rss . Do not know why Can not sign up for it. Could there be anyone finding identical rss issue? Anybody who knows kindly respond. Thnkx masaje erotico mallorca
=======================
You got a very wonderful website, Gladiola I noticed it through yahoo. venta de flejes en mexico
2024年9月08日 04:01
Yours is a prime example of informative writing. I think my students could learn a lot from your writing style and your content. I may share this article with them. SOFT DRINK MANUFACTIRNG PLANT
2024年9月08日 04:49
I want to start a blog but would like to own the domain. Any ideas how to go about this?. catering services in London Caterers in London
2024年9月11日 07:19
It seems you are getting quite a lof of unwanted comments. Maybe you should look into a solution for that. … electric screwdriver cordless
2024年9月11日 07:19
The next time I read a weblog, I hope that it doesnt disappoint me as much as this one. I imply, I know it was my option to read, however I actually thought youd have one thing interesting to say. All I hear is a bunch of whining about something that you could possibly fix in the event you werent too busy searching for attention. mug warmer
2024年9月11日 07:20
I am continually looking online for articles that can facilitate me. Thank you! bed risers
2024年9月12日 03:38
I’m not sure why but this web site is loading incredibly slow for me. Is anyone else having this issue or is it a problem on my end? I’ll check back later and see if the problem still exists. Halloween Pumpkin Night Light
2024年9月13日 05:05
Whats tough now is how the systematic appearance to life is not changed. Do you know what I’m saying? It’s nearly as if we run through the life experience with our eyes closed on, not understanding the true meaning of our own destiny. MINERAL WATER BOTTLING PLANT MANUFACTURER
2024年9月16日 20:40
Someone necessarily assist to make seriously posts I might state. That is the very first time I frequented your website page and so far? I amazed with the analysis you made to create this particular publish extraordinary. Excellent process! Roofing Delmar
2024年9月16日 20:41
You should take part in a contest for probably the greatest blogs on the web. I’ll recommend this web site! Corporate Headshot photographers Miami, FL
=======================
Hello there! This is my first comment here so I just wanted to give a quick shout out and say I really enjoy reading through your blog posts. Can you recommend any other blogs/websites/forums that cover the same subjects? Thank you! Kitchen Remodel Contractors Lakeway TX
2024年9月18日 01:04
Good – I should certainly pronounce, impressed with your web site. I had no trouble navigating through all the tabs as well as related info ended up being truly simple to do to access. I recently found what I hoped for before you know it at all. Reasonably unusual. Is likely to appreciate it for those who add forums or anything, website theme . a tones way for your client to communicate. Nice task. 千葉県 塗装業者
2024年10月04日 09:09
I see that you are using WordPress on your blog, wordpress is the best.~’-~* Flexible
2024年10月09日 00:47
You made some decent points there. I looked on the net for the issue and discovered most people may go as well as with your internet site. Plumber Durham
2024年10月13日 04:08
Great post, thanks for the awesome blog post. I’m having troubles subscribing to your blogs feed. Thought I’d let you know logo design
2024年10月22日 08:28
An impressive share, I merely given this onto a colleague who was doing a little analysis for this. Anf the husband in truth bought me breakfast simply because I found it for him.. smile. So i want to reword that: Thnx for your treat! But yeah Thnkx for spending plenty of time to talk about this, I feel strongly regarding this and really like reading regarding this topic. If it is possible, as you grow expertise, can you mind updating your blog site with a lot more details? It’s highly useful for me. Huge thumb up with this writing! Taznakhte carpets
2024年10月31日 03:33
Performing arts is my thing, i am very much interested to learn more on this art“ Big Blue Restoration
2024年11月03日 21:07
i prefer wall clocks with hanging pendulums because they look nice at home., Ironbound Containers
2024年11月08日 20:29
An impressive share, I just with all this onto a colleague who has been doing little analysis on this. And the man in reality bought me breakfast since I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending enough time to debate this, I feel strongly regarding it and really like reading on this topic. If you can, as you become expertise, could you mind updating your blog post with more details? It is highly ideal for me. Huge thumb up in this article! FintechZoom
2024年11月10日 20:35
You created some decent points there. I looked on the internet for any issue and found most people should go as well as with the internet site. generator covers while running
2024年11月15日 03:13
excellent submit, I love it. I also buy ambien a good deal. You must buy ambien also. I will travel to the whole USA and buy ambien there and in other locations to. i will be downtown, you know for what ? just to buy ambien. I will rest a great deal soon after buy ambien and that it always make me feel so great. I will be buy ambien in a pharmacy or a different destinations, no matter what the daily life get me . rebirthro client
2024年11月21日 03:35
I have been exploring for a little bit for any high-quality articles or weblog posts on this kind of house . Exploring in Yahoo I finally stumbled upon this web site. Reading this info So i’m satisfied to express that I’ve an incredibly good uncanny feeling I came upon just what I needed. Abandoned Cart Email
2024年12月09日 03:09
A really interesting examine, I may not concur totally, but you do make some extremely valid points. Schilder Echt-Susteren
2024年12月10日 01:42
Im impressed. I dont think Ive met anyone who knows as much about this subject as you do. Youre truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog youve got here. IFA Guildford
2024年12月10日 01:42
I am often to blogging and i genuinely appreciate your articles. The article has truly peaks my interest. My goal is to bookmark your site and maintain checking choosing details. أدوات اللياقة المنزلية
2025年1月06日 02:57
Wow! Thank you! I always wanted to write on my site something like that. Can I include a portion of your post to my website? https://gidonlinekz.pro/movies/novogodnie-filmy