自动生成流程图 flow.pl

软件和网站开发以及相关技术探讨
shirazbj
帖子: 333
注册时间: 2010-01-30 18:38

Re: 自动生成流程图 flow.pl

#31

帖子 shirazbj » 2012-06-04 14:41

my test code, i use !!! for fortran. still an un_wanted line between check2 & rerurn. this is the best result i can get now.

it's so fun. like to learn a new language.

代码: 全选

subroutine test02 !!!test02>
!
!***********************************************************************
!
!! TEST02 tests CMCIRC.
!
  implicit none
!
  integer cmcirc
  integer in
  double precision, parameter :: x0 = 3.0D+00
  double precision, parameter :: y0 =  3.0D+00
  double precision, parameter :: x1 =  5.0D+00
  double precision, parameter :: y1 =  0.0D+00
  double precision, parameter :: x2 =  0.0D+00
  double precision, parameter :: y2 =  5.0D+00
  double precision, parameter :: x3 = -5.0D+00
  double precision, parameter :: y3 =  0.0D+00
!
  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) 'TEST02'
  write ( *, '(a)' ) '  CMCIRC determines if a point lies in, on'
  write ( *, '(a)' ) '  or outside a circle given by 3 points.'
  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) '  The points defining the circle:'
  write ( *, '(a)' ) ' '
  write ( *, '(a,2g14.6)' ) '    X1,Y1 = ', x1, y1
  write ( *, '(a,2g14.6)' ) '    X2,Y2 = ', x2, y2
  write ( *, '(a,2g14.6)' ) '    X3,Y3 = ', x3, y3
  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) '  The point to be tested:'
  write ( *, '(a)' ) ' '
  write ( *, '(a,2g14.6)' ) '    X0,Y0 = ', x0, y0

  in = cmcirc ( x0, y0, x1, y1, x2, y2, x3, y3 )  !!!cmcirc

  write ( *, '(a)' ) ' '
  write ( *, '(a)' ) '  Test results:'

  if ( in == 2 ) then  !!!check2?>collinear:check1
    write ( *, '(a)' ) '    The three points are collinear.'   !!!>collinear!!!>
  else if ( in == 1 ) then  !!!check1?>inside:check0
    write ( *, '(a)' ) '    The point is inside the circle.'  !!!>inside!!!>
  else if ( in == 0 ) then  !!!check0?>on:check_1
    write ( *, '(a)' ) '    The point is on the circle.'  !!!>on!!!>
  else if ( in == -1 ) then !!!check_1?outside:return
    write ( *, '(a)' ) '    The point is outside the circle.'  !!!>outside!!!>
  end if !!!check_1!!!check0!!!check1!!!check2
  return  !!!return
end   !!!>test02
免费NanoCAD=免费DraftSight+可API编程(用.net或者vbs和java脚本)=白白 AutoCAD
http://nanocad.com/
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 自动生成流程图 flow.pl

#32

帖子 eexpress » 2012-06-04 14:49

#----------define here-----------
$ext="svg"; $sep='!!!'; $font='Vera Sans YuanTi';

你修改这句。

你的代码,我测试没问题。剩下的,只是你的写法问题了。因为你好多地方是多个>xxx>的。而>是当成入口或者出口的标志的。
附件
tmp.png
● 鸣学
头像
ttand
帖子: 1745
注册时间: 2005-08-22 14:05
来自: 离开北京

Re: 自动生成流程图 flow.pl

#33

帖子 ttand » 2012-06-04 14:49

大神。。支持
#define 那些没
支持 ?运算符那写比较冷的语法没??
错过好多好贴,没占到广告位后悔啊
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 自动生成流程图 flow.pl

#34

帖子 eexpress » 2012-06-04 14:54

KISS的原则。。没任何源语法分析。只分析///后面的注释嘛。

代码: 全选

$sep='///'
● 鸣学
shirazbj
帖子: 333
注册时间: 2010-01-30 18:38

Re: 自动生成流程图 flow.pl

#35

帖子 shirazbj » 2012-06-04 15:13

我也是这个结果。为什么outside是方框,而不是椭圆框。

那几个椭圆圈要能指到return就好了。

语言太灵活了。不容易掌握。dot倒是不辞辛劳。什么都画,呵呵。
免费NanoCAD=免费DraftSight+可API编程(用.net或者vbs和java脚本)=白白 AutoCAD
http://nanocad.com/
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 自动生成流程图 flow.pl

#36

帖子 eexpress » 2012-06-04 15:23

!!!check_1?>outside:>return
这样就是椭圆的,返回了。

!!!>xxx!!!> 这种写法,你改改。这不规范的。
● 鸣学
shirazbj
帖子: 333
注册时间: 2010-01-30 18:38

Re: 自动生成流程图 flow.pl

#37

帖子 shirazbj » 2012-06-04 19:28

要是能支持多分支就好了,不是只是y和n.

这个if...else if ...真麻烦。
免费NanoCAD=免费DraftSight+可API编程(用.net或者vbs和java脚本)=白白 AutoCAD
http://nanocad.com/
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 自动生成流程图 flow.pl

#38

帖子 eexpress » 2012-06-04 19:39

if ... else if .... else

也只要写一部分。缺省向下的,都可以省略啊。

if xxxx ///如果是xxx?:下一个判断
....
else if yyyy ///如果是yyy?:再下一个
....
else

标准的流程图,就只有y/n的分支。没多分支的嘛。如果一定要多分支,这dot要写出html格式的才行。那就复杂了。
● 鸣学
shirazbj
帖子: 333
注册时间: 2010-01-30 18:38

Re: 自动生成流程图 flow.pl

#39

帖子 shirazbj » 2012-06-06 12:52

省略了,不好看。另外自动出来的椭圆圈Yes, 语法太难掌握了。
免费NanoCAD=免费DraftSight+可API编程(用.net或者vbs和java脚本)=白白 AutoCAD
http://nanocad.com/
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 自动生成流程图 flow.pl

#40

帖子 eexpress » 2012-06-06 14:03

才发现逻辑问题。改了,更新了。

提供一个例子。

代码: 全选

● cat sync.u1.bash 
#!/bin/bash

#///使用u1备份配置>
# ///备份全部配置
tar uPvf opera-setting-`date +%Y-%m-%d-%H-%M-%S`.tar `find ~/.opera -iname "*.adr" -or -iname "*.ini" -or -iname "wand.dat" -or -iname "eexp*"`
#///工作目录为sync.conf
d=`pwd`/sync.conf/
echo workdir: $d
#echo $d>/tmp/curdir
for f in `find ~/.opera/ -iname "eexp.*" -or -iname "*.pre_sync"`;do
# ///循环处理文件
echo -------
f=`echo $f|sed 's/\.pre_sync//'`
[ ! -f $f ] && continue # ///不是文件?下一个:
ff=`basename $f`
if [ ! -f $ff ]; then # ///当前目录没此文件?:比较文件节点
cp "$f" .   # ///复制文件到此
ln -f "$f" "`dirname $f`"   # ///原目录做成硬链接
echo cp & ln -f "$f" "`dirname $f`" #///显示cp&ln
continue # ///>下一个
fi
#///比较文件节点
i=`ls -i1 "$f"|cut -d' ' -f 1`
ii=`ls -i1 "$ff"|cut -d' ' -f 1`
if [ $i -ne $ii ]; then # ///文件节点不同?:显示文件名
ln -f "$f" "`dirname $f`"   # ///原目录做成硬链接。
echo ln -f "$f" "`dirname $f`" #///显示ln
else # ///>下一个
echo $f #///显示文件名
fi
done #///下一个
# ///循环处理文件
附件
sync.png
● 鸣学
shirazbj
帖子: 333
注册时间: 2010-01-30 18:38

Re: 自动生成流程图 flow.pl

#41

帖子 shirazbj » 2012-06-10 9:22

我说怎么排不出来呢。现在好了。

那几句支持英文空格的加了么?
免费NanoCAD=免费DraftSight+可API编程(用.net或者vbs和java脚本)=白白 AutoCAD
http://nanocad.com/
头像
lainme
论坛版主
帖子: 7805
注册时间: 2008-09-13 19:17
系统: Arch Linux (x86_64)
联系:

Re: 自动生成流程图 flow.pl

#42

帖子 lainme » 2012-07-27 15:45

ee这个还不错
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 自动生成流程图 flow.pl

#43

帖子 eexpress » 2012-09-26 16:04

代码: 全选

● git df1
diff --git a/flow.pl b/flow.pl
index ee8aaab..5717a71 100755
--- a/flow.pl
+++ b/flow.pl
@@ -30,6 +30,7 @@ for $j (0 .. $#v){
        $i=$v[$j];
        next if $i eq "";
        $i=~s/[\ -\.]/_/g;
+       $i=~s/;/->/g;   #增加;分割的写法
        if($i=~/>$/){ #入口
                $out=~s/->$//g; push @output,$out.$end if $out=~/->/;
                push @output,"}\n" if $cc;
加了一行。

代码: 全选

///无效数据?停止T0;退出:
有时候,这样写方便些。
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 自动生成流程图 flow.pl

#44

帖子 eexpress » 2013-08-19 22:17

● gitup flow.pl-1.5
[master c35bc0f] flow.pl-1.5
1 file changed, 34 insertions(+), 23 deletions(-)

Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 865 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
To [email protected]:eexpress/eexp-bin.git
a79979f..c35bc0f master -> master
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 自动生成流程图 flow.pl

#45

帖子 eexpress » 2013-08-21 16:16

1.6
大改了2天。逻辑搞死人。
增加行号。跳转用行号表示了。

代码: 全选

● flow.pl 
AUTHOR:		eexpress
VERSION:	1.6
USAGE:		flow.pl source_file
DESCRIPTION:
自动根据注释里面的///后面的内容,生成流程图。依赖graphviz。
flow.pl 文件【各类语法的源码,只要注释不和///冲突】
语法说明:
	>xxx 表示函数入口。通常是函数名。第一行缺省为入口。不能带;
	xxx?yyy:zzz 条件判断语句。yyy为真,zzz为假。可省略其一,如:xxx?yyy 或者 xxx?:zzz。省略的直接接下一句;都不省略的短语,2个条件都接下一句。
	跳转到某行使用数字表示。比如 xxx?23。使用0表示退出/return/exit。
	使用;连接多句。

测试输入文件

代码: 全选

///>函数入口
///初始化
///jump to?YY
///jump to?:NN
///jump to?YY;ZZ
///jump to?YY;4
///jump to?:NN;XX
///0
///>函数入口
///jump to?:NN;0
///jump to?YY:here to check;14
///jump to?YY;ZZ:NN;XX
///jump to?YY;0:NN;XX
///jump to?YY;ZZ:NN;0
///使用0.1秒完成
///0
///>函数入口
///jump to?:0
///jump to?0
///jump to?YY;ZZ:NN;0
///使用
///0
测试结果。应该测试了所有可能性。
irsender.dot.png
● 鸣学
回复