ab.com コミュニティ https://www.activebasic.com/forum/ |
|
自己表示プログラム https://www.activebasic.com/forum/viewtopic.php?t=2396 |
ページ 1 / 1 |
作成者: | konisi [ 2008年5月31日(土) 16:59 ] |
記事の件名: | 自己表示プログラム |
自己表示プログラムを書いてみました [ここをクリックすると内容が表示されます] 4.23で動作を確認しました。コード: #console Sub a(b As String) Print b+Ex"\na(Ex\q"+c(b)+Ex"\q)\nSleep(-1)" End Sub Function c(a As String) As String Dim i As Long,j As Long,k=0 As Long,h As *Byte j=Len(a) h=calloc(j*2) For i=0 To j If a=10 then h[k]=92 h[k+1]=110 k++ Else If a=34 then h[k]=92 h[k+1]=113 k++ Else If a=92 then h[k]=92 h[k+1]=92 k++ Else h[k]=a End If k++ Next c=MakeStr(h) free(h) End Function a(Ex"#console\nSub a(b As String)\n Print b+Ex\q\\na(Ex\\q\q+c(b)+Ex\q\\q)\\nSleep(-1)\q\nEnd Sub\nFunction c(a As String) As String\n Dim i As Long,j As Long,k=0 As Long,h As *Byte\n j=Len(a)\n h=calloc(j*2)\n For i=0 To j\n If a=10 then\n h[k]=92\n h[k+1]=110\n k++\n Else If a=34 then\n h[k]=92\n h[k+1]=113\n k++\n Else If a=92 then\n h[k]=92\n h[k+1]=92\n k++\n Else\n h[k]=a\n End If\n k++\n Next\n c=MakeStr(h)\n free(h)\nEnd Function") Sleep(-1) どうやら定数文字列の文字数に何らかの制限がある模様で、それの回避に苦労しました。 誰かもっと短い奴か、又は異なる方法を用いた奴書いてください(メモリリークを無視するような短縮方法は遠慮してください) |
作成者: | イグトランス [ 2008年6月01日(日) 11:11 ] |
記事の件名: | |
私も以前やりました:自分自身を出力するプログラム。 ただ、当時のAB5用なので、今のAB5ではできませんでした。 というわけで修正版です。 コード: #console Dim s = "Print Ex'#console\r\nDim s = \q' + s + Ex'\q, t = \q' + t + Ex'\q' : Print s.Replace(Asc(t), Asc(Ex'\q'))", t = "'" Print Ex"#console\r\nDim s = \q" + s + Ex"\q, t = \q" + t + Ex"\q" : Print s.Replace(Asc(t), Asc(Ex"\q"))AB4は文字列置換のサブルーチンがないのがつらいです。上のコードをAB4.24に移してみましたが、まだReplaceChrサブルーチン部分を出力しない不完全な出来です。 コード: #console Sub ReplaceChr(ByRef s As String, oldChar As Byte, newChar As Byte) Dim i As Long For i = 0 To Len(s) - 1 If s = oldChar Then s = newChar Next End Sub Dim s As String, t As String s = "Print Ex'#prompt\r\nDim s As String, t As String\r\ns = \q' + s + Ex'\q\r\nt = \q' + t + Ex'\q' : ReplaceChr(s, Asc(t), Asc(Ex'\q')) : Print s" t = "'" Print Ex"#prompt\r\nDim s As String, t As String\r\ns = \q" + s + Ex"\q\r\nt = \q" + t + Ex"\q" : ReplaceChr(s, Asc(t), Asc(Ex"\q")) : Print s |
ページ 1 / 1 | 全ての表示時間は UTC+09:00 です |
Powered by phpBB® Forum Software © phpBB Limited https://www.phpbb.com/ |