<?xml version="1.0" encoding="utf-8" ?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" 
			xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" 
			xmlns:cc="http://web.resource.org/cc/" xml:lang="ja">
<channel rdf:about="http://kemeconoajito.blog88.fc2.com/?xml">
<title>けめこのあじと</title>
<link>http://kemeconoajito.blog88.fc2.com/</link>
<description>Linux超初心者がLinuxで遊んでる様子です。あざ笑っていいよ…　主に自分用の覚え書き。</description>
<dc:language>ja</dc:language>
<items>
<rdf:Seq>
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-64.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-63.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-62.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-61.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-60.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-58.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-57.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-56.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-54.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-53.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-52.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-51.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-50.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-49.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-48.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-47.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-46.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-44.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-42.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-41.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-40.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-37.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-36.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-31.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-35.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-34.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-33.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-32.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-30.html" />
<rdf:li rdf:resource="http://kemeconoajito.blog88.fc2.com/blog-entry-29.html" />
</rdf:Seq>
</items>
</channel>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-64.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-64.html</link>
<title>って、うわーー</title>
<description> 古い原稿整理してたら懐かしいのが出てきた。…アホや。そりゃぁボツにもなるわ…ｗ
 </description>
<content:encoded>
<![CDATA[ <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/yuribotu.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/yuribotus.jpg" alt="yuribotu.jpg" border="0" width="192" height="139" /></a><br /><br />古い原稿整理してたら懐かしいのが出てきた。<br /><br />…アホや。そりゃぁボツにもなるわ…ｗ ]]>
</content:encoded>
<dc:subject>未分類</dc:subject>
<dc:date>2010-02-01T06:04:51+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-63.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-63.html</link>
<title>キリッ</title>
<description> 
 </description>
<content:encoded>
<![CDATA[ <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/a.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/as.jpg" alt="a.jpg" border="0" width="176" height="192" /></a><br /><br /> ]]>
</content:encoded>
<dc:subject>絵関係</dc:subject>
<dc:date>2010-01-31T02:11:02+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-62.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-62.html</link>
<title></title>
<description> 自分のヘタさにムカついてくる
 </description>
<content:encoded>
<![CDATA[ 自分のヘタさにムカついてくる ]]>
</content:encoded>
<dc:subject>未分類</dc:subject>
<dc:date>2010-01-29T00:16:14+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-61.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-61.html</link>
<title>1/48スケール SV000/o 箱絵</title>
<description> メタルスラッグにでてくるフチコマです。（フチコマて…！）プラモの箱絵ふうに。ロクに資料見ないでうろおぼえで描いたので、キャタピラがフィン状になってます…ｗ　ほんとうは爪状が正解。だからプロトタイプなのであ～る…（汗orzタンクのくせしてサスがしなやかです。ロールしております。床下スカスカ、おまいはクラシックカーか！（いや、ロマンですｗ）追伸：メーカーは”たいヴぃーや模型”という設定でおねがいします。くれぐ
 </description>
<content:encoded>
<![CDATA[ <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/sv000o.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/sv000os.jpg" alt="sv000o.jpg" border="0" width="192" height="119" /></a><br /><br />メタルスラッグにでてくるフチコマです。（フチコマて…！）<br />プラモの箱絵ふうに。<br /><br />ロクに資料見ないでうろおぼえで描いたので、キャタピラがフィン状になってます…ｗ　ほんとうは爪状が正解。だからプロトタイプなのであ～る…（汗orz<br />タンクのくせしてサスがしなやかです。ロールしております。床下スカスカ、おまいはクラシックカーか！（いや、ロマンですｗ）<br /><br />追伸：<br />メーカーは”たいヴぃーや模型”という設定でおねがいします。くれぐれも某★★模型とは無関係という設定でおねがいしまっす！（・＿；／おろおろ<br /> ]]>
</content:encoded>
<dc:subject>絵関係</dc:subject>
<dc:date>2010-01-25T21:07:52+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-60.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-60.html</link>
<title>ノーボーダー</title>
<description> このお姉さんはチーズケーキを１ホールいっき食いするつもりなのでしょうか…　一人で。なんたるブルジョワ…そしてどっさりクッキー。太るぞ。末はでぶちんでしょう。あぁ、おそろしや。だが、そこがいい♪（なにっ！？
 </description>
<content:encoded>
<![CDATA[ <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/noboder_t.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/noboder_ts.jpg" alt="noboder_t.jpg" border="0" width="192" height="127" /></a><br /><br />このお姉さんはチーズケーキを１ホールいっき食いするつもりなのでしょうか…　一人で。<br />なんたるブルジョワ…<br />そしてどっさりクッキー。<br />太るぞ。末はでぶちんでしょう。あぁ、おそろしや。だが、そこがいい♪（なにっ！？<br /> ]]>
</content:encoded>
<dc:subject>絵関係</dc:subject>
<dc:date>2010-01-21T02:23:57+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-58.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-58.html</link>
<title>人の描いた線画を塗って練習しよう</title>
<description> ある人が、塗り絵用に線画を公開してらっしゃったので、かってに塗ってみたですよ。無許可ですよ。こういう絵の髪の塗り方がわかんない。
 </description>
<content:encoded>
<![CDATA[ <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20100108_01xx.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20100108_01xxs.jpg" alt="20100108_01xx.jpg" border="0" width="133" height="192" /></a><br /><br /><br />ある人が、塗り絵用に線画を公開してらっしゃったので、かってに塗ってみたですよ。無許可ですよ。<br /><br />こういう絵の髪の塗り方がわかんない。 ]]>
</content:encoded>
<dc:subject>絵関係</dc:subject>
<dc:date>2010-01-08T23:31:31+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-57.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-57.html</link>
<title>ブラック★ロックシューター</title>
<description> 『ロック・カノン！』とか『ブラック・スウォ～～ド』とか♪　中２全開なネーミングが逆にイカス！！あれってワザとやってるんだろうけど。あ～いう感覚って大切よね…けっこう。世界観を創る上で。
 </description>
<content:encoded>
<![CDATA[ <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20100107_brs.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20100107_brss.jpg" alt="20100107_brs.jpg" border="0" width="145" height="192" /></a><br /><br />『ロック・カノン！』とか『ブラック・スウォ～～ド』とか♪　中２全開なネーミングが逆にイカス！！<br />あれってワザとやってるんだろうけど。あ～いう感覚って大切よね…けっこう。世界観を創る上で。 ]]>
</content:encoded>
<dc:subject>絵関係</dc:subject>
<dc:date>2010-01-08T02:46:33+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-56.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-56.html</link>
<title>teto (0.1.0)</title>
<description> チラチラしなくしたteto010.mp3( mp3 -&gt; zip )起動方法win:efg01.exe teto.g01linux:./t
 </description>
<content:encoded>
<![CDATA[ チラチラしなくした<br /><a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/teto010.mp3" target="_blank">teto010.mp3</a><br />( mp3 -> zip )<br /><br />起動方法<br />win:<br />efg01.exe teto.g01<br /><br />linux:<br />./t<br /> ]]>
</content:encoded>
<dc:subject>OSASK関係</dc:subject>
<dc:date>2010-01-04T00:00:00+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-54.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-54.html</link>
<title>アバンチュちゃん</title>
<description> あばんちゅカラーはおちつくなぁ～…（＾＿＾…あ、ほんとはubuntuはウブンツって読むのが正解らしいです。し、しらなかた…（・＿；ほろりあとボク今までAMDはアンドって呼んでました…あ、アムドが正解らしいです…　し、しらなかた…（・＿；は、はずぅい…ほろり
 </description>
<content:encoded>
<![CDATA[ <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091231_01.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091231_01s.jpg" alt="20091231_01.jpg" border="0" width="139" height="192" /></a><br /><br /><br />あばんちゅカラーはおちつくなぁ～…（＾＿＾<br /><br />…あ、<br />ほんとはubuntuはウブンツって読むのが正解らしいです。<br />し、しらなかた…（・＿；ほろり<br />あとボク今までAMDはアンドって呼んでました…あ、アムドが正解らしいです…　し、しらなかた…（・＿；は、はずぅい…ほろり ]]>
</content:encoded>
<dc:subject>絵関係</dc:subject>
<dc:date>2009-12-31T02:17:39+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-53.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-53.html</link>
<title>メリーメリー</title>
<description> 
 </description>
<content:encoded>
<![CDATA[ <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091218_01.png" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091218_01.png" alt="20091218_01.png" border="0" width="1133" height="719" /></a><br /><br /><a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091218_02.png" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091218_02.png" alt="20091218_02.png" border="0" width="568" height="647" /></a><br /><br /> ]]>
</content:encoded>
<dc:subject>絵関係</dc:subject>
<dc:date>2009-12-29T10:31:27+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-52.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-52.html</link>
<title>teto (0.0.8)</title>
<description> いちおう遊べる感じにはなってきた。まだゲーム的な点数とかレベルとか、そういう部分はまだ作ってないですが&amp;hellip; linux ネイティブ : teto008linux.mp3win (efg01使用) : teto008win.mp3（拡張子を mp3 から zip に書き換えて解凍してください）操作方法：J：左移動　K：右移動　N:下移動 F：右回転　D：左回転スペース：ハードドロップQ：終了linuxの場合、コンソール表示にして実行した方がレスポンスがマシです。tty?表示
 </description>
<content:encoded>
<![CDATA[ いちおう遊べる感じにはなってきた。<br />まだゲーム的な点数とかレベルとか、そういう部分はまだ作ってないですが&hellip;<br /><br /><a target="_blank" href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/teto008.jpg"><img border="0" width="722" height="491" alt="teto008.jpg" src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/teto008.jpg" /></a> <br /><br />linux ネイティブ : <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/teto008linux.mp3" target="_blank">teto008linux.mp3</a><br /><br />win (efg01使用) : <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/teto008win.mp3" target="_blank">teto008win.mp3</a><br />（拡張子を mp3 から zip に書き換えて解凍してください）<br /><br />操作方法：<br />J：左移動　K：右移動　N:下移動 <br />F：右回転　D：左回転<br />スペース：ハードドロップ<br />Q：終了<br /><br />linuxの場合、コンソール表示にして実行した方がレスポンスがマシです。<br />tty?表示に移動：（Ctrl + Alt + F1～F6)<br />gnome表示に戻る：　（Cttl + Alt + F7)<br /><br />コンパイル方法：<br />linux:<br />gcc -o t teto.c -lc -lpthread<br /><br />efg01:<br />１行目の#define __OSASK__ を有効にして<br />tolset を使用<br /><br />linux vga（おまけ、efg01 にVRAMへのピクセル書き込みがサポートされた場合は、この部分で対応する予定）<br />２行目#define __LINUX_VGA__を有効にして<br />gcc -o t teto.c -lc -lpthread -lvga -lvgagl<br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>teto.c (0.0.8)</td></tr><tr><td>//#define __OSASK__<br />//#define __LINUX_VGA__<br /><br />#ifdef __OSASK__<br /><br />#include &lt;guigui01.h&gt;<br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br /><br />#define _COLOR_BLACK &nbsp;&nbsp;&nbsp; 0<br />#define _COLOR_RED &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 4<br />#define _COLOR_GREEN&nbsp;&nbsp;&nbsp; 2<br />#define _COLOR_YELLO&nbsp;&nbsp;&nbsp; 6<br />#define _COLOR_BLUE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 1<br />#define _COLOR_PARPLE&nbsp;&nbsp;&nbsp; 13<br />#define _COLOR_LBLUE&nbsp;&nbsp;&nbsp; 3<br />#define _COLOR_WHITE&nbsp;&nbsp;&nbsp; 15<br />#define _COLOR_ORENGE&nbsp;&nbsp;&nbsp; 5<br /><br />void vsync(int w)<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;w;i++){<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; jg01_sleep1(32-5, 1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // x = 32-5 = 27,&nbsp;&nbsp; weit_time = 2^(x-32) = 2^(27-32) = 2^(-5) = 1/32<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; jg01_sleep1(32-6, 1);<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />static int old_set_put_c_s_color&nbsp; = 0;<br />static int old_set_put_c_bg_color = 0;<br />void set_put_c_color( int s_color, int bg_color )<br />{<br />&nbsp;&nbsp;&nbsp; jg01_consctrl2( s_color, bg_color );<br />&nbsp;&nbsp;&nbsp; old_set_put_c_s_color&nbsp; = s_color;&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = bg_color;<br />}<br /><br />static int old_set_cur_x=0;<br />static int old_set_cur_y=0;<br />void set_cur( int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; if((x&gt;=0&amp;&amp;x&lt;80)&amp;&amp;(y&gt;=0&amp;&amp;y&lt;25)){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; jg01_consctrl1(x,y);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; jg01_consctrl1(0,0);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; old_set_cur_x=x;&nbsp;&nbsp;&nbsp; old_set_cur_y=y;<br />}<br /><br />void put_c( unsigned char c )<br />{<br />&nbsp;&nbsp;&nbsp; if((old_set_cur_x&gt;=0&amp;&amp;old_set_cur_x&lt;80)&amp;&amp;(old_set_cur_y&gt;=0&amp;&amp;old_set_cur_y&lt;25)){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g01_putc(c);<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />unsigned char get_c( void )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char c = jg01_inkey2();<br />&nbsp;&nbsp;&nbsp; if(c==0){return(0xFF);}else{return(c);}<br />}<br /><br />void clr_scr(void)<br />{<br />&nbsp;&nbsp;&nbsp; jg01_consctrl3();<br />}<br /><br />void init_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; srand(jg01_randomseed());<br /><br />&nbsp;&nbsp;&nbsp; jg01_consctrl4(80,25);<br />&nbsp;&nbsp;&nbsp; jg01_consctrl2(15,0);<br />}<br /><br />void close_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; clr_scr();<br />&nbsp;&nbsp;&nbsp; set_put_c_color( 7, 0 );<br />}<br /><br />#endif // __OSASK__<br /><br />#ifndef __OSASK__<br /><br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br /><br />#include &lt;linux/input.h&gt;<br />#include &lt;unistd.h&gt;<br />#include &lt;termios.h&gt;<br />#include &lt;sys/types.h&gt;<br />#include &lt;sys/ipc.h&gt;<br />#include &lt;sys/shm.h&gt;<br />#include &lt;sys/time.h&gt;<br />#include &lt;sys/wait.h&gt;<br />#include &lt;time.h&gt;<br />#include &lt;pthread.h&gt;<br /><br />#ifdef __LINUX_VGA__<br />#include &lt;vga.h&gt;<br />#include &lt;vgagl.h&gt;<br />#endif //__LINUX_VGA<br /><br />#define _COLOR_BLACK &nbsp;&nbsp;&nbsp; 1<br />#define _COLOR_RED &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 2<br />#define _COLOR_GREEN&nbsp;&nbsp;&nbsp; 3<br />#define _COLOR_YELLO&nbsp;&nbsp;&nbsp; 4<br />#define _COLOR_BLUE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 5<br />#define _COLOR_PARPLE&nbsp;&nbsp;&nbsp; 6<br />#define _COLOR_LBLUE&nbsp;&nbsp;&nbsp; 7<br />#define _COLOR_WHITE&nbsp;&nbsp;&nbsp; 8<br />#ifdef __LINUX_VGA__<br />#define _COLOR_ORENGE&nbsp;&nbsp;&nbsp; 9<br />#else<br />#define _COLOR_ORENGE&nbsp;&nbsp;&nbsp; _COLOR_WHITE<br />#endif //__LINUX_VGA_\<br /><br />static int &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; flg_init_termios = 0;<br />static struct termios &nbsp;&nbsp;&nbsp; save_term;<br />static struct termios &nbsp;&nbsp;&nbsp; temp_term;<br />static struct timeval&nbsp;&nbsp;&nbsp; old_tv;<br />static struct timezone&nbsp;&nbsp;&nbsp; old_tz;<br /><br />void* __vsync(void* pParam )<br />{<br />&nbsp;&nbsp;&nbsp; static struct timeval&nbsp;&nbsp;&nbsp; tv;<br />&nbsp;&nbsp;&nbsp; static struct timezone&nbsp;&nbsp;&nbsp; tz;<br />&nbsp;&nbsp;&nbsp; gettimeofday(&amp;tv, &amp;tz);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; static struct timespec &nbsp;&nbsp;&nbsp; req;<br />&nbsp;&nbsp;&nbsp; static struct timespec &nbsp;&nbsp;&nbsp; rem;<br />&nbsp;&nbsp;&nbsp; req.tv_sec&nbsp; = 0;<br />//&nbsp;&nbsp;&nbsp; req.tv_nsec = 31250000 - (tv.tv_usec - old_tv.tv_usec);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 1/32(s)<br />&nbsp;&nbsp;&nbsp; req.tv_nsec = 15625000 - (tv.tv_usec - old_tv.tv_usec);<br /><br />&nbsp;&nbsp;&nbsp; nanosleep(&amp;req,&amp;rem);<br /><br />&nbsp;&nbsp;&nbsp; old_tv.tv_usec = tv.tv_usec;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return(0);<br />}<br /><br />void vsync(int w)<br />{<br />&nbsp;&nbsp;&nbsp; fflush(stdout);<br /><br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; pthread_t pt;<br /><br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;w;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pthread_create(&amp;pt, NULL, __vsync, NULL );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pthread_join(pt,NULL);<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />#ifdef __LINUX_VGA__<br />static int old_set_put_c_s_color&nbsp; = 0;<br />static int old_set_put_c_bg_color = 0;<br />void set_put_c_color( int s_color, int bg_color )<br />{<br />/*<br />&nbsp;&nbsp;&nbsp; switch(s_color){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 0x00; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_RED:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 0xF0; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_GREEN:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 0xCC; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_YELLO:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 0xFC; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLUE:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 0xC3; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_PARPLE:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 0xF3; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_LBLUE:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 0xCF; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_WHITE:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 0xFF; break;<br />&nbsp;&nbsp;&nbsp; default: &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 0x00; break;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; switch(bg_color){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 0x00; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_RED:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 0xF0; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_GREEN:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 0xCC; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_YELLO:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 0xFC; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLUE:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 0xC3; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_PARPLE:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 0xF3; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_LBLUE:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 0xCF; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_WHITE:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 0xFF; break;<br />&nbsp;&nbsp;&nbsp; default: &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 0x00; break;<br />&nbsp;&nbsp;&nbsp; }<br />*/<br />&nbsp;&nbsp;&nbsp; switch(s_color){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 0; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_RED:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 4;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_GREEN:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 2;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_YELLO:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 6;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLUE:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 1;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_PARPLE:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 13;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_LBLUE:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 3;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_ORENGE:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 5;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_WHITE:&nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 15;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; default: &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; old_set_put_c_s_color = 0;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; switch(bg_color){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 0; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_RED:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 4;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_GREEN:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 2;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_YELLO:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 6;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLUE:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_PARPLE:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 13;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_LBLUE:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 3;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_ORENGE:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 5;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_WHITE:&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 15;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; default: &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = 0;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; vga_setcolor(old_set_put_c_bg_color);<br />}<br />#else<br />static int old_set_put_c_s_color&nbsp; = 0;<br />static int old_set_put_c_bg_color = 0;<br />void set_put_c_color( int s_color, int bg_color )<br />{<br />&nbsp;&nbsp;&nbsp; switch(s_color){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 30 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_RED:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 31 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_GREEN:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 32 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_YELLO:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 33 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 34 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_PARPLE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 35 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_LBLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 36 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_WHITE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 37 ); break;<br />&nbsp;&nbsp;&nbsp; default: &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 0&nbsp; ); break;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; switch(bg_color){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 40 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_RED:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 41 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_GREEN:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 42 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_YELLO:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 43 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 44 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_PARPLE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 45 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_LBLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 46 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_WHITE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 47 ); break;<br />&nbsp;&nbsp;&nbsp; default: &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 0&nbsp; ); break;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; old_set_put_c_s_color&nbsp; = s_color;&nbsp;&nbsp;&nbsp; old_set_put_c_bg_color = bg_color;<br />}<br />#endif // __LINUX_VGA__<br /><br />#ifdef __LINUX_VGA__<br />static int old_set_cur_x = 0;<br />static int old_set_cur_y = 0;<br />void set_cur( int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; old_set_cur_x=x;&nbsp;&nbsp;&nbsp; old_set_cur_y=y;<br />}<br />#else<br />static int old_set_cur_x = 0;<br />static int old_set_cur_y = 0;<br />void set_cur( int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; if((x&gt;=0&amp;&amp;x&lt;80)&amp;&amp;(y&gt;=0&amp;&amp;y&lt;25)){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%c[%d;%dH&quot;,0x1b, y+1, x+1 );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%c[%d;%dH&quot;,0x1b, 1, 1 );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; old_set_cur_x=x;&nbsp;&nbsp;&nbsp; old_set_cur_y=y;<br />}<br />#endif //__LINUX_VGA__<br /><br />#ifdef __LINUX_VGA__<br />void clr_scr(void)<br />{<br />&nbsp;&nbsp;&nbsp; vga_clear();<br />}<br />#else<br />void clr_scr(void)<br />{<br />&nbsp;&nbsp;&nbsp; printf(&quot;%c[2J&quot;,0x1B );<br />}<br />#endif //__LINUX_VGA__<br /><br />#ifdef __LINUX_VGA__<br />void put_c( unsigned char c )<br />{<br />&nbsp;&nbsp;&nbsp; if((old_set_cur_x&gt;=0&amp;&amp;old_set_cur_x&lt;80)&amp;&amp;(old_set_cur_y&gt;=0&amp;&amp;old_set_cur_y&lt;25)){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #define PUT_C_W 8<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #define PUT_C_H 16<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(j=0;j&lt;PUT_C_H;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;PUT_C_W;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vga_drawpixel(old_set_cur_x*PUT_C_W+i, old_set_cur_y*PUT_C_H+j);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br />#else<br />void put_c( unsigned char c )<br />{<br />&nbsp;&nbsp;&nbsp; if((old_set_cur_x&gt;=0&amp;&amp;old_set_cur_x&lt;80)&amp;&amp;(old_set_cur_y&gt;=0&amp;&amp;old_set_cur_y&lt;25)){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; putchar((int)c);<br />&nbsp;&nbsp;&nbsp; }<br />}<br />#endif //__LINUX_VGA__<br /><br />/*<br />static unsigned char&nbsp;&nbsp;&nbsp; old_get_k=0;<br />unsigned char get_k( void )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char c;<br />&nbsp;&nbsp;&nbsp; c = getchar();<br />&nbsp;&nbsp;&nbsp; if( c == 0xFF){ c = old_get_k; }else{ old_get_k = c; }<br />&nbsp;&nbsp;&nbsp; return(c);<br />}<br />*/<br /><br />unsigned char get_c( void )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char c;<br />&nbsp;&nbsp;&nbsp; c = getchar();<br />&nbsp;&nbsp;&nbsp; return(c);<br />}<br /><br />#ifdef __LINUX_VGA__<br />void init_sys(void)<br />{<br />// &nbsp;&nbsp;&nbsp; int vgamode=G1024x768x256;<br />&nbsp; &nbsp;&nbsp;&nbsp; int vgamode=G640x480x256;<br />&nbsp;&nbsp;&nbsp; vga_init();<br />&nbsp;&nbsp;&nbsp; vga_setmode(vgamode);<br />&nbsp;&nbsp;&nbsp; gl_setcontextvga(vgamode);<br /><br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcgetattr(fileno(stdin), &amp;save_term);<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term = save_term;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_iflag &amp;= ~IGNCR;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ICANON;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ECHO;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ISIG;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VMIN]=0;<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VMIN]=1;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VTIME]=0;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;temp_term);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; flg_init_termios += 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ユニークカウンタ（これでシステム全体での起動数を把握しておく）<br /><br />&nbsp;&nbsp;&nbsp; srand((unsigned int)time(0));<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; gettimeofday(&amp;old_tv, &amp;old_tz);<br />}<br />#else<br />void init_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcgetattr(fileno(stdin), &amp;save_term);<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term = save_term;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_iflag &amp;= ~IGNCR;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ICANON;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ECHO;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ISIG;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VMIN]=0;<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VMIN]=1;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VTIME]=0;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;temp_term);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; flg_init_termios += 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ユニークカウンタ（これでシステム全体での起動数を把握しておく）<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; srand((unsigned int)time(0));<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; gettimeofday(&amp;old_tv, &amp;old_tz);<br />}<br />#endif //__LINUX_VGA__<br /><br />#ifdef __LINUX_VGA__<br />void close_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; flg_init_termios -= 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ユニークカウンタを一つ減らす<br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;save_term );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // すべては、これを複数回起動してしまうのを防止するため。（ユニークカウンタ<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; clr_scr();<br />&nbsp;&nbsp;&nbsp; set_put_c_color( 0, 0 );<br />&nbsp;&nbsp;&nbsp; put_c( '\n');<br />}<br />#else<br />void close_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; flg_init_termios -= 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ユニークカウンタを一つ減らす<br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;save_term );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // すべては、これを複数回起動してしまうのを防止するため。（ユニークカウンタ<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; clr_scr();<br />&nbsp;&nbsp;&nbsp; set_put_c_color( 0, 0 );<br />&nbsp;&nbsp;&nbsp; put_c( '\n');<br />}<br />#endif //__LINUX_VGA__<br /><br />#endif // __OSASK__<br /><br /><br /><br /><br /><br />#define PAD_R_UP&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 1<br />#define PAD_R_DOWN&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 2<br />#define PAD_R_RIGHT&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 4<br />#define PAD_R_LEFT&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 8<br />#define PAD_L_UP&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 16<br />#define PAD_L_DOWN&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 32<br />#define PAD_L_RIGHT&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 64<br />#define PAD_L_LEFT&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 128<br />#define PAD_START&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 256<br />#define PAD_SELECT&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 512<br />#define PAD_L1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 1024<br />#define PAD_L2&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 2048<br />#define PAD_R1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 4096<br />#define PAD_R2&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 8192<br /><br />static unsigned short PAD1;<br />static unsigned short PAD2;<br /><br />typedef struct tagPOS {<br />&nbsp;&nbsp;&nbsp; int x;<br />&nbsp;&nbsp;&nbsp; int y;<br />} POS;<br /><br />typedef struct tagBLOCK {<br />&nbsp;&nbsp;&nbsp; unsigned char &nbsp;&nbsp;&nbsp; b[2];<br />&nbsp;&nbsp;&nbsp; POS&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; str_col;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bg_col;<br />} BLOCK;<br /><br />#define PANEL_W&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 12<br />#define PANEL_H&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 25<br />typedef struct tagPANEL {<br />&nbsp;&nbsp;&nbsp; BLOCK &nbsp;&nbsp;&nbsp; b[PANEL_W*PANEL_H*2];<br />&nbsp;&nbsp;&nbsp; POS&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p;<br />} PANEL;<br /><br />#define NPANEL_W&nbsp;&nbsp;&nbsp; 5<br />#define NPANEL_H&nbsp;&nbsp;&nbsp; 6<br />typedef struct tagNPANEL {<br />&nbsp;&nbsp;&nbsp; BLOCK&nbsp;&nbsp;&nbsp; b[NPANEL_W*NPANEL_H*2];<br />&nbsp;&nbsp;&nbsp; POS&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p;<br />} NPANEL;<br /><br />typedef struct tagMINO {<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; t;<br />&nbsp;&nbsp;&nbsp; BLOCK &nbsp;&nbsp;&nbsp; b[4];<br />&nbsp;&nbsp;&nbsp; POS&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p;<br />&nbsp;&nbsp;&nbsp; POS&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cp;<br />} MINO;<br /><br />typedef struct tagAI {<br />&nbsp;&nbsp;&nbsp; PANEL &nbsp;&nbsp;&nbsp; CPP;<br />&nbsp;&nbsp;&nbsp; MINO&nbsp; &nbsp;&nbsp;&nbsp; CPM;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CTV,CTH,CTR;<br />} __AI;<br /><br />#define NINGEN &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0<br />#define KIKAI&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 1<br />#define MUJINKUN&nbsp;&nbsp;&nbsp; 2<br />typedef struct tagTETO{<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pmd;<br />&nbsp;&nbsp;&nbsp; POS&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; nmp;<br />&nbsp;&nbsp;&nbsp; POS&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cmp;<br />&nbsp;&nbsp;&nbsp; PANEL &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; P;<br />&nbsp;&nbsp;&nbsp; NPANEL&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; NP;<br />&nbsp;&nbsp;&nbsp; int &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comp_line[PANEL_H]; // = {0,0,0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,0,0,&nbsp;&nbsp;&nbsp; 0,0};<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_flsP;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // =0;<br />&nbsp;&nbsp;&nbsp; #define DM_LEN 7<br />&nbsp;&nbsp;&nbsp; MINO&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DM[DM_LEN];<br />&nbsp;&nbsp;&nbsp; MINO&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GM[DM_LEN];<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rand_box[DM_LEN*2];&nbsp;&nbsp;&nbsp; //={0,1,2,3,4,5,6,0,1,2,3,4,5,6};<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_rand_box_len;&nbsp;&nbsp;&nbsp; //=DM_LEN*2;<br />&nbsp;&nbsp;&nbsp; __AI &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AI;<br />&nbsp;&nbsp;&nbsp; int &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snc;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //=0;<br />&nbsp;&nbsp;&nbsp; int &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; f;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //=0;<br />&nbsp;&nbsp;&nbsp; MINO &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_mino;<br />&nbsp;&nbsp;&nbsp; MINO &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next_mino;<br />&nbsp;&nbsp;&nbsp; MINO&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_ghost_mino;<br />&nbsp;&nbsp;&nbsp; MINO&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next_ghost_mino;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ojl;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ojls;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; awt;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cawt;<br />} TETO;<br /><br />/*<br />// a^inv<br />int _pow(int a, int inv )<br />{<br />&nbsp;&nbsp;&nbsp; int r=a;<br /><br />&nbsp;&nbsp;&nbsp; if(inv==0) r=1;<br />&nbsp;&nbsp;&nbsp; if(inv==1) r=a;<br /><br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=2;i&lt;=inv;i++){r*=a;}<br /><br />&nbsp;&nbsp;&nbsp; return(r);<br />}<br /><br />// 基数による桁数<br />int _dig(int a, int cardinal )<br />{<br />&nbsp;&nbsp;&nbsp; if( cardinal ==0 ){printf(&quot;err: dig() cardinal&yen;n&quot;);exit(1);}<br /><br />&nbsp;&nbsp;&nbsp; int count=0;<br /><br />&nbsp;&nbsp;&nbsp; while(a&gt;0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; a/=cardinal;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( a &lt;= 0 ) { break; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return(count);<br />}<br /><br />// 数値型から文字列型<br />void itos( char* dst, int src )<br />{<br />&nbsp;&nbsp;&nbsp; if(src &gt; 0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int p;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int unit;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int sub=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int dig=_dig(src,10);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;dig;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p=_pow(10,i+1);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sub+=((src%p)-sub);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unit=sub / _pow(10, i);<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(unit){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0:dst[dig-1-i]='0';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 1:dst[dig-1-i]='1';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 2:dst[dig-1-i]='2';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 3:dst[dig-1-i]='3';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 4:dst[dig-1-i]='4';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 5:dst[dig-1-i]='5';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 6:dst[dig-1-i]='6';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 7:dst[dig-1-i]='7';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 8:dst[dig-1-i]='8';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 9:dst[dig-1-i]='9';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default:printf(&quot;err: itos() dst[%d]&yen;n&quot;,dig-1-i ); exit(1); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[dig]='\0';<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0]='0';<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1]='\0';<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />double factoriol( long a )<br />{<br />&nbsp;&nbsp;&nbsp; double v = 1;<br /><br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i = 1; i &lt;= a; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v *= (double)i;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( v );<br />}<br /><br />double pow_f( double a, long inv )<br />{<br />&nbsp;&nbsp;&nbsp; double r=a;<br /><br />&nbsp;&nbsp;&nbsp; if(inv==0){r=1;}<br />&nbsp;&nbsp;&nbsp; if(inv==1){r=a;}<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=2; i &lt;= inv; i++ ){ r *= a; }<br /><br />&nbsp;&nbsp;&nbsp; return(r);<br />&nbsp;&nbsp;&nbsp; <br />}<br /><br />double exp_taylor( double a )<br />{<br />&nbsp;&nbsp;&nbsp; double v=0;<br /><br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i = 0; i &lt; 10; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v += ( 1.0 / factoriol(i) ) * pow_f(a,i);<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return( v );<br />}<br /><br />double sin_taylor( double a )<br />{<br />&nbsp;&nbsp;&nbsp; double v=0;<br />&nbsp;&nbsp;&nbsp; double fugou=1.0;<br /><br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=1; i&lt;20; i+=2 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v += fugou * ( ( 1.0 / factoriol(i) ) * pow_f(a, i) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou=-fugou;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( v );<br />}<br />*/<br />/*<br />static double ETC_MATH_t_table_rd( ( (double)ETC_MATH_TABLE_SIZE / 2 ) / 3.14159265358979 );<br />double sin_t( double a )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned long l = (unsigned long)( a * ETC_MATH_t_table_rd );<br />&nbsp;&nbsp;&nbsp; l %= ETC_MATH_TABLE_SIZE;<br />&nbsp;&nbsp;&nbsp; return( ETC_MATHsin_table[l]);<br />}<br /><br />double cos_t( double a )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned long l = (unsigned long)( a * ETC_MATH_t_table_rd );<br />&nbsp;&nbsp;&nbsp; l %= ETC_MATH_TABLE_SIZE;<br />&nbsp;&nbsp;&nbsp; return( ETC_MATHcos_table[l]);<br />}<br /><br />double tan_t( double a )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned long l = (unsigned long)( a * ETC_MATH_t_table_rd );<br />&nbsp;&nbsp;&nbsp; l %= ETC_MATH_TABLE_SIZE;<br />&nbsp;&nbsp;&nbsp; return( ETC_MATHtan_table[l]);<br />}<br />*/<br /><br /><br /><br /><br /><br />void syncPAD(void)<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; unsigned char c;<br />&nbsp;&nbsp;&nbsp; unsigned short pad_l_nl&nbsp; = PAD_L_RIGHT | PAD_L_LEFT;<br /><br />&nbsp;&nbsp;&nbsp; if( ((PAD1&amp;PAD_L1)!=0) || ((PAD1&amp;PAD_R1)!=0) ) { PAD1 = 0; } else { PAD1 &amp;= pad_l_nl; }<br />&nbsp;&nbsp;&nbsp; PAD2 =&nbsp; 0;<br /><br />&nbsp;&nbsp;&nbsp; do {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c=get_c();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(c){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'k': case 'K':&nbsp;&nbsp;&nbsp; PAD1 |= PAD_R1; &nbsp;&nbsp;&nbsp; PAD1|=PAD_L_RIGHT;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'j': case 'J':&nbsp;&nbsp;&nbsp; PAD1 |= PAD_L1; &nbsp;&nbsp;&nbsp; PAD1|=PAD_L_LEFT;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'n': case 'N':&nbsp;&nbsp;&nbsp; PAD1 |= PAD_L_DOWN;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'i': case 'I':&nbsp;&nbsp;&nbsp; PAD1 &amp;= ~pad_l_nl; &nbsp;&nbsp;&nbsp; PAD1|=PAD_L_RIGHT;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'u': case 'U':&nbsp;&nbsp;&nbsp; PAD1 &amp;= ~pad_l_nl; &nbsp;&nbsp;&nbsp; PAD1|=PAD_L_LEFT;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case ' ':&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; PAD1 |= PAD_L_UP;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'f': case 'F':&nbsp;&nbsp;&nbsp; PAD1 |= PAD_R_UP;&nbsp;&nbsp;&nbsp; PAD1 &amp;= ~pad_l_nl; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'd': case 'D':&nbsp;&nbsp;&nbsp; PAD1 |= PAD_R_LEFT;&nbsp;&nbsp;&nbsp; PAD1 &amp;= ~pad_l_nl; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'q': case 'Q':&nbsp;&nbsp;&nbsp; PAD1 |= PAD_START;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; } while(c!=0xFF);<br />}<br /><br /><br /><br /><br /><br />void initB(BLOCK* B)<br />{<br />&nbsp;&nbsp;&nbsp; B-&gt;b[0]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =' ';<br />&nbsp;&nbsp;&nbsp; B-&gt;b[1]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =' ';<br />&nbsp;&nbsp;&nbsp; B-&gt;p.x&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =0;<br />&nbsp;&nbsp;&nbsp; B-&gt;p.y&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =0;<br />&nbsp;&nbsp;&nbsp; B-&gt;str_col&nbsp;&nbsp;&nbsp; =0;<br />&nbsp;&nbsp;&nbsp; B-&gt;bg_col &nbsp;&nbsp;&nbsp; =0;<br />}<br /><br />void cpyB(BLOCK* dst, BLOCK* src )<br />{<br />&nbsp;&nbsp;&nbsp; dst-&gt;b[0]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = src-&gt;b[0];<br />&nbsp;&nbsp;&nbsp; dst-&gt;b[1]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = src-&gt;b[1];<br />&nbsp;&nbsp;&nbsp; dst-&gt;p.x &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = src-&gt;p.x;<br />&nbsp;&nbsp;&nbsp; dst-&gt;p.y &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = src-&gt;p.y;<br />&nbsp;&nbsp;&nbsp; dst-&gt;str_col &nbsp;&nbsp;&nbsp; = src-&gt;str_col;<br />&nbsp;&nbsp;&nbsp; dst-&gt;bg_col &nbsp;&nbsp;&nbsp; = src-&gt;bg_col;<br />}<br /><br />void posB(BLOCK* b, int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; b-&gt;p.x=x;<br />&nbsp;&nbsp;&nbsp; b-&gt;p.y=y;<br />}<br /><br />void colB(BLOCK* b, int col)<br />{<br />&nbsp;&nbsp;&nbsp; switch(col){<br />&nbsp;&nbsp;&nbsp; case 0:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_BLACK;&nbsp;&nbsp;&nbsp; break;<br />//&nbsp;&nbsp;&nbsp; case 0:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_LBLUE;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 2:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_ORENGE;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_PARPLE;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 4:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_RED;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 5:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_GREEN;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 6:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_YELLO;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 7:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_BLUE;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 8:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_WHITE;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void colGB(BLOCK* b)<br />{<br />&nbsp;&nbsp;&nbsp; b-&gt;str_col = _COLOR_WHITE; b-&gt;bg_col = _COLOR_BLACK;<br />}<br /><br />void prtB(BLOCK* b, int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; set_put_c_color(b-&gt;str_col,b-&gt;bg_col);<br /><br />&nbsp;&nbsp;&nbsp; set_cur(2*(b-&gt;p.x+x)+0,b-&gt;p.y+y+0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; put_c(b-&gt;b[0]);<br />&nbsp;&nbsp;&nbsp; set_cur(2*(b-&gt;p.x+x)+1,b-&gt;p.y+y+0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; put_c(b-&gt;b[1]);<br /><br />&nbsp;&nbsp;&nbsp; set_put_c_color(0,0);&nbsp;&nbsp;&nbsp; <br />}<br /><br />void clrB(BLOCK* b, int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; set_put_c_color(_COLOR_BLACK,_COLOR_BLACK);<br /><br />&nbsp;&nbsp;&nbsp; set_cur(2*(b-&gt;p.x+x)+0,b-&gt;p.y+y+0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; put_c(b-&gt;b[0]);<br />&nbsp;&nbsp;&nbsp; set_cur(2*(b-&gt;p.x+x)+1,b-&gt;p.y+y+0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; put_c(b-&gt;b[1]);<br /><br />&nbsp;&nbsp;&nbsp; set_put_c_color(0,0);&nbsp;&nbsp;&nbsp; <br />}<br /><br /><br /><br /><br /><br />void initP(TETO*teto, int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; P-&gt;p.x=x;<br />&nbsp;&nbsp;&nbsp; P-&gt;p.y=y;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H;j++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp=&amp;(P-&gt;b[j*PANEL_W]);<br />&nbsp;&nbsp;&nbsp; &nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(j){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case PANEL_H-1:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=-0;i&lt;PANEL_W;i++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,8); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,8); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,0); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,8); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />}<br /><br />void initNP(TETO* teto, int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; NPANEL* NP = &amp;(teto-&gt;NP);<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; NP-&gt;p.x=x;<br />&nbsp;&nbsp;&nbsp; NP-&gt;p.y=y;<br /><br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;NPANEL_H;j++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp=&amp;(NP-&gt;b[j*NPANEL_W]);<br />&nbsp;&nbsp;&nbsp; &nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(j){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0: case NPANEL_H-1:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=-0;i&lt;NPANEL_W;i++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,8); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,8); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;NPANEL_W-1;i++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,0); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,8); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />}<br /><br />int chkP(TETO* teto)<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; int j,i;<br />&nbsp;&nbsp;&nbsp; int c;<br />&nbsp;&nbsp;&nbsp; int ret =0;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H-1;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp=&amp;(P-&gt;b[j*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( bp-&gt;bg_col != _COLOR_BLACK ){ c++; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(c==PANEL_W-1-1) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;comp_line[j]=1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;comp_line[j]=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return(ret);<br />}<br /><br />int flsP(TETO* teto)<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; int ret = 0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; int col;<br />&nbsp;&nbsp;&nbsp; switch(teto-&gt;cur_flsP) {<br />&nbsp;&nbsp;&nbsp; case 0: col=_COLOR_LBLUE;&nbsp;&nbsp;&nbsp; teto-&gt;cur_flsP=1;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 1: col=_COLOR_YELLO; &nbsp;&nbsp;&nbsp; teto-&gt;cur_flsP=0;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H-1;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(teto-&gt;comp_line[j]!=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp = &amp;(P-&gt;b[j*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;str_col = col;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;bg_col&nbsp; = col;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return(ret);<br />}<br /><br />void dllP(TETO* teto)<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H-1;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(teto-&gt;comp_line[j]!=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp = &amp;(P-&gt;b[j*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;str_col = _COLOR_BLACK;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;bg_col&nbsp; = _COLOR_BLACK;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />int dwnP(TETO* teto)<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P =&amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; BLOCK* ubp;<br />&nbsp;&nbsp;&nbsp; int c;<br />&nbsp;&nbsp;&nbsp; int ret=0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=PANEL_H-1-1; j&gt;0; j--){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp = &amp;(P-&gt;b[j*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( bp-&gt;bg_col == _COLOR_BLACK ) { c++; };<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(c==PANEL_W-1-1){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp&nbsp; = &amp;(P-&gt;b[(j+0)*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp = &amp;(P-&gt;b[(j-1)*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;str_col = ubp-&gt;str_col;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;bg_col&nbsp; = ubp-&gt;bg_col;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp-&gt;str_col = _COLOR_BLACK;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp-&gt;bg_col&nbsp; = _COLOR_BLACK;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return(ret);<br />}<br /><br />void ojlP(TETO* teto)<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P =&amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; BLOCK* ubp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=1;j&lt;PANEL_H;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp = &amp;(P-&gt;b[(j-1)*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp&nbsp; = &amp;(P-&gt;b[(j+0)*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp-&gt;str_col = bp-&gt;str_col;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp-&gt;bg_col&nbsp; = bp-&gt;bg_col;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; bp&nbsp; = &amp;(P-&gt;b[(PANEL_H-1-1)*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;str_col = _COLOR_WHITE;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;bg_col&nbsp; = _COLOR_WHITE;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br /><br />&nbsp;&nbsp;&nbsp; bp = &amp;(P-&gt;b[(PANEL_H-1-1)*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; bp += teto-&gt;ojls;<br />//&nbsp;&nbsp;&nbsp; bp += rand()%(PANEL_W-1-1);<br />&nbsp;&nbsp;&nbsp; bp-&gt;str_col&nbsp;&nbsp;&nbsp; = _COLOR_BLACK;<br />&nbsp;&nbsp;&nbsp; bp-&gt;bg_col&nbsp; = _COLOR_BLACK;<br />}<br /><br />void prtP(TETO* teto)<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp=&amp;(P-&gt;b[j*PANEL_W]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;PANEL_W;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; prtB(bp++,P-&gt;p.x, P-&gt;p.y);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void prtNP(TETO* teto)<br />{<br />&nbsp;&nbsp;&nbsp; PANEL*&nbsp;&nbsp;&nbsp; P&nbsp; = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; NPANEL*&nbsp;&nbsp;&nbsp; NP = &amp;(teto-&gt;NP);<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br /><br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;NPANEL_H;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp=&amp;(NP-&gt;b[j*NPANEL_W]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;NPANEL_W;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; prtB(bp++,P-&gt;p.x+NP-&gt;p.x, P-&gt;p.y+NP-&gt;p.y);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />int apB(TETO* teto, BLOCK* b,int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; int cx=b-&gt;p.x+x;<br />&nbsp;&nbsp;&nbsp; int cy=b-&gt;p.y+y;<br /><br />&nbsp;&nbsp;&nbsp; switch( P-&gt;b[cy*PANEL_W+cx].bg_col ){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; return(0);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; default:&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(1);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br /><br /><br /><br /><br />void initMINO(TETO* teto, MINO* m, int t)<br />{<br />&nbsp;&nbsp;&nbsp; register BLOCK* bp = m-&gt;b;<br /><br />&nbsp;&nbsp;&nbsp; m-&gt;p.x = teto-&gt;cmp.x;<br />&nbsp;&nbsp;&nbsp; m-&gt;p.y = teto-&gt;cmp.y;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; m-&gt;cp.x=0;<br />&nbsp;&nbsp;&nbsp; m-&gt;cp.y=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; initB(bp++);&nbsp;&nbsp;&nbsp; initB(bp++);&nbsp;&nbsp;&nbsp; initB(bp++);&nbsp;&nbsp;&nbsp; initB(bp++);<br /><br />&nbsp;&nbsp;&nbsp; bp = m-&gt;b;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; switch(t) {<br />&nbsp;&nbsp;&nbsp; case 0:&nbsp;&nbsp;&nbsp; colB(bp++,1);&nbsp;&nbsp;&nbsp; colB(bp++,1);&nbsp;&nbsp;&nbsp; colB(bp++,1);&nbsp;&nbsp;&nbsp; colB(bp++,1);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; colB(bp++,2);&nbsp;&nbsp;&nbsp; colB(bp++,2);&nbsp;&nbsp;&nbsp; colB(bp++,2);&nbsp;&nbsp;&nbsp; colB(bp++,2);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 2:&nbsp;&nbsp;&nbsp; colB(bp++,3);&nbsp;&nbsp;&nbsp; colB(bp++,3);&nbsp;&nbsp;&nbsp; colB(bp++,3);&nbsp;&nbsp;&nbsp; colB(bp++,3);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; colB(bp++,4);&nbsp;&nbsp;&nbsp; colB(bp++,4);&nbsp;&nbsp;&nbsp; colB(bp++,4);&nbsp;&nbsp;&nbsp; colB(bp++,4);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 4:&nbsp;&nbsp;&nbsp; colB(bp++,5);&nbsp;&nbsp;&nbsp; colB(bp++,5);&nbsp;&nbsp;&nbsp; colB(bp++,5);&nbsp;&nbsp;&nbsp; colB(bp++,5);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 5:&nbsp;&nbsp;&nbsp; colB(bp++,6);&nbsp;&nbsp;&nbsp; colB(bp++,6);&nbsp;&nbsp;&nbsp; colB(bp++,6);&nbsp;&nbsp;&nbsp; colB(bp++,6);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 6:&nbsp;&nbsp;&nbsp; colB(bp++,7);&nbsp;&nbsp;&nbsp; colB(bp++,7);&nbsp;&nbsp;&nbsp; colB(bp++,7);&nbsp;&nbsp;&nbsp; colB(bp++,7);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; bp = m-&gt;b;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; switch(t) {<br />&nbsp;&nbsp;&nbsp; case 0:&nbsp;&nbsp;&nbsp; posB(bp++,0,-1);&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,2);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ----<br />&nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // []<br />&nbsp;&nbsp;&nbsp; case 2:&nbsp;&nbsp;&nbsp; posB(bp++,-1,0);&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,-1);&nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // T<br />&nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; posB(bp++,-1,0);&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // N<br />&nbsp;&nbsp;&nbsp; case 4:&nbsp;&nbsp;&nbsp; posB(bp++,-1,1);&nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // !N<br />&nbsp;&nbsp;&nbsp; case 5:&nbsp;&nbsp;&nbsp; posB(bp++,0,-1);&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // L<br />&nbsp;&nbsp;&nbsp; case 6:&nbsp;&nbsp;&nbsp; posB(bp++,0,-1);&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,-1,1);&nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // !L<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; m-&gt;t=t;<br />}<br /><br />void initGHOSTMINO(TETO* teto, MINO* m, int t)<br />{<br />&nbsp;&nbsp;&nbsp; initMINO(teto,m,t);<br /><br />&nbsp;&nbsp;&nbsp; register BLOCK* bp = m-&gt;b;<br />&nbsp;&nbsp;&nbsp; colGB(bp);&nbsp;&nbsp;&nbsp; bp-&gt;b[0]='[';&nbsp;&nbsp;&nbsp; bp-&gt;b[1]=']';&nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; colGB(bp);&nbsp;&nbsp;&nbsp; bp-&gt;b[0]='[';&nbsp;&nbsp;&nbsp; bp-&gt;b[1]=']';&nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; colGB(bp);&nbsp;&nbsp;&nbsp; bp-&gt;b[0]='[';&nbsp;&nbsp;&nbsp; bp-&gt;b[1]=']';&nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; colGB(bp);&nbsp;&nbsp;&nbsp; bp-&gt;b[0]='[';&nbsp;&nbsp;&nbsp; bp-&gt;b[1]=']';&nbsp;&nbsp;&nbsp; bp++;<br />}<br /><br />void cpyMINO( MINO* dst, MINO* src )<br />{<br />&nbsp;&nbsp;&nbsp; dst-&gt;t = src-&gt;t;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; dst-&gt;p.x = src-&gt;p.x;<br />&nbsp;&nbsp;&nbsp; dst-&gt;p.y = src-&gt;p.y;<br /><br />&nbsp;&nbsp;&nbsp; dst-&gt;cp.x = src-&gt;cp.x;<br />&nbsp;&nbsp;&nbsp; dst-&gt;cp.y = src-&gt;cp.y;<br /><br />&nbsp;&nbsp;&nbsp; BLOCK* dbp = dst-&gt;b;<br />&nbsp;&nbsp;&nbsp; BLOCK* sbp = src-&gt;b;<br />&nbsp;&nbsp;&nbsp; cpyB(dbp++,sbp++);&nbsp;&nbsp;&nbsp; cpyB(dbp++,sbp++);&nbsp;&nbsp;&nbsp; cpyB(dbp++,sbp++);&nbsp;&nbsp;&nbsp; cpyB(dbp++,sbp++);<br />}<br /><br />int apMINO(TETO* teto, MINO* m)<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; int x=m-&gt;p.x+m-&gt;cp.x;<br />&nbsp;&nbsp;&nbsp; int y=m-&gt;p.y+m-&gt;cp.y;<br />&nbsp;&nbsp;&nbsp; int ret=0;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp = m-&gt;b;<br />&nbsp;&nbsp;&nbsp; ret+=apB(teto, bp++,x,y);&nbsp;&nbsp;&nbsp; ret+=apB(teto, bp++,x,y);&nbsp;&nbsp;&nbsp; ret+=apB(teto, bp++,x,y);&nbsp;&nbsp;&nbsp; ret+=apB(teto, bp++,x,y);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return(ret);<br />}<br /><br />void __rotMINO( MINO* m, int r )<br />{<br />&nbsp;&nbsp;&nbsp; BLOCK* bp = m-&gt;b;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(r &gt;= +1){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, +bp-&gt;p.y,-bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, +bp-&gt;p.y,-bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, +bp-&gt;p.y,-bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, +bp-&gt;p.y,-bp-&gt;p.x );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if( r &lt;= -1){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, -bp-&gt;p.y,+bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, -bp-&gt;p.y,+bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, -bp-&gt;p.y,+bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, -bp-&gt;p.y,+bp-&gt;p.x );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />int __movMINO(TETO* teto, MINO* m, int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; m-&gt;p.x += x;<br />&nbsp;&nbsp;&nbsp; m-&gt;p.y += y;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(apMINO(teto,m)!=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;p.x -= x;&nbsp;&nbsp;&nbsp; m-&gt;p.y -= y;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(1);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; m-&gt;p.x += m-&gt;cp.x;&nbsp;&nbsp;&nbsp; m-&gt;p.y += m-&gt;cp.y;<br />&nbsp;&nbsp;&nbsp; m-&gt;cp.x=0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.y=0;<br />&nbsp;&nbsp;&nbsp; return(0);<br />}<br /><br />void rot_rMINO( TETO* teto, MINO* m )<br />{<br />&nbsp;&nbsp;&nbsp; if(m-&gt;t==1){return;}<br /><br />&nbsp;&nbsp;&nbsp; __rotMINO( m, -1 );<br /><br />&nbsp;&nbsp;&nbsp; m-&gt;cp.x=0;&nbsp;&nbsp;&nbsp; m-&gt;cp.y=0;<br />&nbsp;&nbsp;&nbsp; if(apMINO(teto,m)!=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.y=-1; if(apMINO(teto,m)==0){ return; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.y=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=+1; if(apMINO(teto,m)==0){ return; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=-1; if(apMINO(teto,m)==0){ return; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(m-&gt;t==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.y=-2; if(apMINO(teto,m)==0){ return; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.y=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=+2; if(apMINO(teto,m)==0){ return; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=-2; if(apMINO(teto,m)==0){ return; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=0;&nbsp;&nbsp;&nbsp; m-&gt;cp.y=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __rotMINO( m, +1 );<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void rot_lMINO( TETO* teto, MINO* m )<br />{<br />&nbsp;&nbsp;&nbsp; if(m-&gt;t==1){return;}<br />&nbsp; <br />&nbsp;&nbsp;&nbsp; __rotMINO( m, +1 );&nbsp;&nbsp;&nbsp; <br /><br />&nbsp;&nbsp;&nbsp; m-&gt;cp.x=0;&nbsp;&nbsp;&nbsp; m-&gt;cp.y=0;<br />&nbsp;&nbsp;&nbsp; if(apMINO(teto, m)!=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.y=-1; if(apMINO(teto,m)==0){ return; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.y=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=+1; if(apMINO(teto,m)==0){ return; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=-1; if(apMINO(teto,m)==0){ return; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(m-&gt;t==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.y=-2; if(apMINO(teto,m)==0){ return; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.y=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=+2; if(apMINO(teto,m)==0){ return; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=-2; if(apMINO(teto,m)==0){ return; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;cp.x=0;&nbsp;&nbsp;&nbsp; m-&gt;cp.y=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __rotMINO( m, -1 );<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />int mov_dMINO(TETO* teto, MINO* m)<br />{<br />&nbsp;&nbsp;&nbsp; return(__movMINO(teto,m,0,1));<br />}<br /><br />int mov_rMINO(TETO* teto, MINO* m)<br />{<br />&nbsp;&nbsp;&nbsp; return(__movMINO(teto,m,+1,0));<br />}<br /><br />int mov_lMINO(TETO* teto, MINO* m)<br />{<br />&nbsp;&nbsp;&nbsp; return(__movMINO(teto,m,-1,0));<br />}<br /><br />void prtMINO( TETO* teto, MINO* m )<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; BLOCK* mbp = m-&gt;b;<br />&nbsp;&nbsp;&nbsp; int x = P-&gt;p.x + m-&gt;p.x + m-&gt;cp.x;<br />&nbsp;&nbsp;&nbsp; int y = P-&gt;p.y + m-&gt;p.y + m-&gt;cp.y;<br /><br />&nbsp;&nbsp;&nbsp; prtB(mbp,x,y); mbp++;<br />&nbsp;&nbsp;&nbsp; prtB(mbp,x,y); mbp++;<br />&nbsp;&nbsp;&nbsp; prtB(mbp,x,y); mbp++;<br />&nbsp;&nbsp;&nbsp; prtB(mbp,x,y); mbp++;<br />}<br /><br />void clrMINO( TETO* teto, MINO* m )<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; BLOCK* mbp = m-&gt;b;<br />&nbsp;&nbsp;&nbsp; int x = P-&gt;p.x + m-&gt;p.x + m-&gt;cp.x;<br />&nbsp;&nbsp;&nbsp; int y = P-&gt;p.y + m-&gt;p.y + m-&gt;cp.y;<br /><br />&nbsp;&nbsp;&nbsp; clrB(mbp,x,y); mbp++;<br />&nbsp;&nbsp;&nbsp; clrB(mbp,x,y); mbp++;<br />&nbsp;&nbsp;&nbsp; clrB(mbp,x,y); mbp++;<br />&nbsp;&nbsp;&nbsp; clrB(mbp,x,y); mbp++;<br />}<br /><br />void prtGHOSTMINO( TETO* teto, MINO* gm )<br />{<br />&nbsp;&nbsp;&nbsp; clrMINO(teto,gm);<br />&nbsp; <br />&nbsp;&nbsp;&nbsp; gm-&gt;p.x&nbsp; = teto-&gt;cur_mino.p.x + teto-&gt;cur_mino.cp.x;<br />&nbsp;&nbsp;&nbsp;&nbsp; gm-&gt;p.y&nbsp;&nbsp;&nbsp; &nbsp;= teto-&gt;cur_mino.p.y + teto-&gt;cur_mino.cp.y;<br />&nbsp;&nbsp;&nbsp; gm-&gt;cp.x = 0;<br />&nbsp;&nbsp;&nbsp; gm-&gt;cp.y = 0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(i=0; i&lt;PANEL_H; i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(mov_dMINO(teto,gm)!=0){break;}<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; prtMINO(teto,gm);<br />}<br /><br />void initDM(TETO* teto)<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;DM_LEN;i++){ initMINO(teto, &amp;(teto-&gt;DM[i]),i); }<br />}<br /><br />void initGM(TETO* teto)<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;DM_LEN;i++){ initGHOSTMINO(teto, &amp;(teto-&gt;GM[i]),i); }<br />}<br /><br />void newMINO( TETO* teto, MINO* m, MINO* gm)<br />{<br />&nbsp;&nbsp;&nbsp; int i; <br />&nbsp;&nbsp;&nbsp; if(teto-&gt;cur_rand_box_len&lt;=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;DM_LEN;i++){teto-&gt;rand_box[i+0]=i; teto-&gt;rand_box[i+DM_LEN]=i;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_rand_box_len=DM_LEN;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; int rnd = rand()%(teto-&gt;cur_rand_box_len);<br />&nbsp;&nbsp;&nbsp; cpyMINO(&nbsp; m, &amp;(teto-&gt;DM[(teto-&gt;rand_box[rnd])]) );<br />&nbsp;&nbsp;&nbsp; cpyMINO( gm, &amp;(teto-&gt;GM[(teto-&gt;rand_box[rnd])]) );<br /><br />&nbsp;&nbsp;&nbsp; for(i=rnd;i&lt;teto-&gt;cur_rand_box_len-1;i++){teto-&gt;rand_box[i]=teto-&gt;rand_box[i+1];}<br />&nbsp;&nbsp;&nbsp; teto-&gt;cur_rand_box_len--;<br />}<br /><br />void M2P( TETO* teto, MINO* m )<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; BLOCK* mbp = m-&gt;b;<br />&nbsp;&nbsp;&nbsp; BLOCK* pbp;<br /><br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;4;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mbp = &amp;(m-&gt;b[i]);<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mbp-&gt;p.x += m-&gt;p.x + m-&gt;cp.x;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mbp-&gt;p.y += m-&gt;p.y + m-&gt;cp.y;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pbp = &amp;(P-&gt;b[ mbp-&gt;p.y*PANEL_W +mbp-&gt;p.x ]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpyB(pbp, mbp);<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br /><br /><br /><br /><br />int stAI(TETO* teto)<br />{<br />&nbsp;&nbsp;&nbsp; PANEL* P = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; int sc=0;<br />&nbsp;&nbsp;&nbsp; int h;<br />&nbsp;&nbsp;&nbsp; int nl=_COLOR_BLACK;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; BLOCK* lbp;<br />&nbsp;&nbsp;&nbsp; BLOCK* rbp;<br />&nbsp;&nbsp;&nbsp; BLOCK* ubp;<br />&nbsp;&nbsp;&nbsp; BLOCK* dbp;<br />&nbsp;&nbsp;&nbsp; for(j=1;j&lt;PANEL_H-1;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp=&amp;(P-&gt;b[j*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lbp=bp-1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rbp=bp+1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp=bp-PANEL_W;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dbp=bp+PANEL_W;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(j&gt;PANEL_H-6){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(bp-&gt;bg_col!=nl){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; h=(PANEL_H-j);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sc+=h;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl){if(i&gt;=2&amp;&amp;i&lt;=PANEL_W-1){sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl){if(i&gt;=1&amp;&amp;i&lt;=PANEL_W-2){sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl){if(i==1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {sc-=1;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl){if(i==PANEL_W-1){sc-=1;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(dbp-&gt;bg_col==nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(bp-&gt;bg_col==nl){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col!=nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col!=nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col==nl){sc-=1;};<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col==nl&amp;&amp;dbp-&gt;bg_col==nl){sc-=1;};<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(bp-&gt;bg_col!=nl){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; h=(PANEL_H-j);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sc+=h*2;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl){if(i&gt;=2&amp;&amp;i&lt;=PANEL_W-1){sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl){if(i&gt;=1&amp;&amp;i&lt;=PANEL_W-2){sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl){if(i==1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl){if(i==PANEL_W-1){sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(dbp-&gt;bg_col==nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(bp-&gt;bg_col==nl){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col!=nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col!=nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl&amp;&amp;lbp-&gt;bg_col!=nl){sc+=5;}<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col==nl){sc-=1;};<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col==nl&amp;&amp;dbp-&gt;bg_col==nl){sc-=1;};<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lbp=bp-1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rbp=bp+1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp=bp-PANEL_W;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dbp=bp+PANEL_W;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return(sc);<br />}<br /><br />void sncAI(TETO* teto, MINO* cm)<br />{<br />&nbsp; &nbsp;&nbsp;&nbsp; PANEL* CPP = &amp;(teto-&gt;AI.CPP);<br />&nbsp;&nbsp;&nbsp; MINO* CPM = &amp;(teto-&gt;AI.CPM);<br />&nbsp;&nbsp;&nbsp; int* CTV = &amp;(teto-&gt;AI.CTV);<br />&nbsp;&nbsp;&nbsp; int* CTH = &amp;(teto-&gt;AI.CTH);<br />&nbsp;&nbsp;&nbsp; int* CTR = &amp;(teto-&gt;AI.CTR);<br />&nbsp;&nbsp;&nbsp; PANEL* P = &amp;(teto-&gt;P);<br />&nbsp;&nbsp;&nbsp; int i,j,k,l;<br />&nbsp;&nbsp;&nbsp; int ls=0xFFFFFFF;<br />&nbsp;&nbsp;&nbsp; int sp=cm-&gt;p.x;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; tv=0,th=0,tr=0;<br />&nbsp;&nbsp;&nbsp; BLOCK* pbp=P-&gt;b;<br />&nbsp;&nbsp;&nbsp; BLOCK* cbp=CPP-&gt;b;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;PANEL_H*PANEL_W;i++){*cbp++ = *pbp++;}<br />&nbsp;&nbsp;&nbsp; cpyMINO( CPM, cm );<br /><br />&nbsp;&nbsp;&nbsp; for(l=0;l&lt;4;l++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(k=1;k&lt;PANEL_W-1;k++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pbp=P-&gt;b;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cbp=CPP-&gt;b;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;PANEL_H*PANEL_W;i++){*pbp++ = *cbp++;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpyMINO( cm, CPM );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;l;i++){ tr=l; rot_lMINO(teto,cm); }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int hm=k-sp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; th=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(hm&lt;0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; hm=-hm;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;hm;i++){ th--; mov_lMINO(teto,cm); }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;hm;i++){ th++; mov_rMINO(teto,cm); }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tv=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H-1;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tv++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(mov_dMINO(teto,cm)!=0){break;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; M2P(teto,cm);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int st=stAI(teto);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(st&lt;ls){ls=st;*CTH=th;*CTV=tv;*CTR=tr;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp; <br />&nbsp;&nbsp;&nbsp; pbp=P-&gt;b;<br />&nbsp;&nbsp;&nbsp; cbp=CPP-&gt;b;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;PANEL_H*PANEL_W;i++){*pbp++ = *cbp++;}<br />&nbsp;&nbsp;&nbsp; cpyMINO( cm, CPM );<br />}<br /><br /><br /><br /><br /><br /><br />void initTETO(TETO* teto, int pmd, int x, int y, int nx, int ny )<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;PANEL_H;i++){teto-&gt;comp_line[i]=0;}<br />&nbsp;&nbsp;&nbsp; teto-&gt;cur_flsP=0;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;DM_LEN*2;i++){teto-&gt;rand_box[i]=i%7;}&nbsp;&nbsp;&nbsp; //={0,1,2,3,4,5,6,0,1,2,3,4,5,6};<br />&nbsp;&nbsp;&nbsp; teto-&gt;cur_rand_box_len=DM_LEN*2;<br />&nbsp;&nbsp;&nbsp; teto-&gt;snc=0;<br />&nbsp;&nbsp;&nbsp; teto-&gt;f=0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; teto-&gt;pmd=pmd;<br />&nbsp;&nbsp;&nbsp; teto-&gt;nmp.x=nx; teto-&gt;nmp.y=ny;<br />&nbsp;&nbsp;&nbsp; teto-&gt;cmp.x=6;&nbsp; teto-&gt;cmp.y=3;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; initP(teto,x,y);<br />&nbsp;&nbsp;&nbsp; initNP(teto,nx-2,ny-2);<br />&nbsp;&nbsp;&nbsp; initDM(teto);<br />&nbsp;&nbsp;&nbsp; initGM(teto);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; newMINO( teto, &amp;teto-&gt;next_mino, &amp;teto-&gt;next_ghost_mino);<br />&nbsp;&nbsp;&nbsp; cpyMINO( &amp;teto-&gt;cur_mino, &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &amp;teto-&gt;next_mino );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_mino.p.x= teto-&gt;cmp.x;&nbsp;&nbsp;&nbsp; teto-&gt;cur_mino.p.y= teto-&gt;cmp.y;<br />&nbsp;&nbsp;&nbsp; cpyMINO( &amp;teto-&gt;cur_ghost_mino,&nbsp;&nbsp;&nbsp; &amp;teto-&gt;next_ghost_mino );<br /><br />&nbsp;&nbsp;&nbsp; newMINO( teto, &amp;teto-&gt;next_mino, &amp;teto-&gt;next_ghost_mino);&nbsp;&nbsp;&nbsp; teto-&gt;next_mino.p.x= teto-&gt;nmp.x;&nbsp;&nbsp;&nbsp; teto-&gt;next_mino.p.y= teto-&gt;nmp.y;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; teto-&gt;ojl=0;<br />&nbsp;&nbsp;&nbsp; teto-&gt;ojls=rand()%(PANEL_W-1-1);<br /><br />&nbsp;&nbsp;&nbsp; teto-&gt;awt&nbsp; = 60;&nbsp;&nbsp;&nbsp; // 1s<br />&nbsp;&nbsp;&nbsp; teto-&gt;cawt = 0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; PAD1=0;<br />&nbsp;&nbsp;&nbsp; PAD2=0;<br />}<br /><br />int calcTETO(TETO* teto, unsigned short pad, int dp)<br />{<br />&nbsp;&nbsp;&nbsp; int ret = 0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(teto-&gt;pmd==MUJINKUN){return(0);}<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.p.y&nbsp; = teto-&gt;cur_mino.p.y;<br />&nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.p.x&nbsp; = teto-&gt;cur_mino.p.x;<br />&nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.cp.y = teto-&gt;cur_mino.cp.y;<br />&nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.cp.x = teto-&gt;cur_mino.cp.x;<br />&nbsp;&nbsp;&nbsp; prtGHOSTMINO(teto, &amp;teto-&gt;cur_ghost_mino);<br />&nbsp;&nbsp;&nbsp; prtMINO(teto,&amp;teto-&gt;cur_mino);<br /><br />&nbsp;&nbsp;&nbsp; if(teto-&gt;pmd==KIKAI){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(teto-&gt;f==0&amp;&amp;teto-&gt;snc==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sncAI(teto,&amp;teto-&gt;cur_mino);teto-&gt;snc=1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(teto-&gt;snc==1){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(teto-&gt;AI.CTR&gt;=1){ teto-&gt;AI.CTR--; pad|=PAD_R_LEFT;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if(teto-&gt;AI.CTH&gt;=+1){ teto-&gt;AI.CTH--; pad|=PAD_L_RIGHT;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if(teto-&gt;AI.CTH&lt;=-1){ teto-&gt;AI.CTH++; pad|=PAD_L_LEFT;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else { pad|=PAD_L_DOWN;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(teto-&gt;f==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( ((pad&amp;PAD_L_DOWN)!=0) || dp==1 || ((pad&amp;PAD_L_UP)!=0) ){ <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clrMINO(teto,&amp;teto-&gt;cur_mino);&nbsp;&nbsp;&nbsp; <br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( (pad&amp;PAD_L_UP)!=0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while(mov_dMINO(teto,&amp;teto-&gt;cur_mino)==0){;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(mov_dMINO(teto,&amp;teto-&gt;cur_mino)!=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cawt++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if((pad&amp;PAD_L_UP)!=0){ teto-&gt;cawt = teto-&gt;awt; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtMINO(teto,&amp;teto-&gt;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(teto-&gt;cawt &gt; 0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clrMINO(teto,&amp;teto-&gt;cur_mino);&nbsp;&nbsp;&nbsp; <br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(mov_dMINO(teto,&amp;teto-&gt;cur_mino)!=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(teto-&gt;cawt &gt;= teto-&gt;awt){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cawt=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(teto-&gt;ojl&gt;0){teto-&gt;f=30;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;snc=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; M2P(teto,&amp;teto-&gt;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtP(teto);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clrMINO(teto,&amp;teto-&gt;next_mino);&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpyMINO( &amp;teto-&gt;cur_mino, &amp;teto-&gt;next_mino );&nbsp;&nbsp;&nbsp; teto-&gt;cur_mino.p.x = teto-&gt;cmp.x;&nbsp;&nbsp;&nbsp; teto-&gt;cur_mino.p.y = teto-&gt;cmp.y;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpyMINO( &amp;teto-&gt;cur_ghost_mino, &amp;teto-&gt;next_ghost_mino );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; newMINO( teto, &amp;teto-&gt;next_mino, &amp;teto-&gt;next_ghost_mino );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;next_mino.p.x= teto-&gt;nmp.x;&nbsp;&nbsp;&nbsp; teto-&gt;next_mino.p.y= teto-&gt;nmp.y;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtMINO(teto,&amp;teto-&gt;next_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else{<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cawt++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else{<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cawt=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtMINO(teto,&amp;teto-&gt;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(pad&amp;PAD_L_LEFT ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clrMINO(teto, &amp;teto-&gt;cur_mino);&nbsp;&nbsp;&nbsp; mov_lMINO(teto, &amp;teto-&gt;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtGHOSTMINO(teto, &amp;teto-&gt;cur_ghost_mino);&nbsp;&nbsp;&nbsp; prtMINO(teto,&amp;teto-&gt;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(pad&amp;PAD_L_RIGHT){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clrMINO(teto, &amp;teto-&gt;cur_mino);&nbsp;&nbsp;&nbsp; mov_rMINO(teto, &amp;teto-&gt;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtGHOSTMINO(teto, &amp;teto-&gt;cur_ghost_mino);&nbsp;&nbsp;&nbsp; prtMINO(teto,&amp;teto-&gt;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(pad&amp;PAD_R_UP&nbsp;&nbsp; ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clrMINO(teto, &amp;teto-&gt;cur_mino);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clrMINO(teto, &amp;teto-&gt;cur_ghost_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.p.y&nbsp; = teto-&gt;cur_mino.p.y;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.p.x&nbsp; = teto-&gt;cur_mino.p.x;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.cp.y = teto-&gt;cur_mino.cp.y;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.cp.x = teto-&gt;cur_mino.cp.x;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rot_rMINO(teto, &amp;teto-&gt;cur_mino);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rot_rMINO(teto, &amp;teto-&gt;cur_ghost_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtGHOSTMINO(teto, &amp;teto-&gt;cur_ghost_mino);&nbsp;&nbsp;&nbsp; prtMINO(teto,&amp;teto-&gt;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(pad&amp;PAD_R_LEFT ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clrMINO(teto, &amp;teto-&gt;cur_mino);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clrMINO(teto, &amp;teto-&gt;cur_ghost_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.p.y&nbsp; = teto-&gt;cur_mino.p.y;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.p.x&nbsp; = teto-&gt;cur_mino.p.x;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.cp.y = teto-&gt;cur_mino.cp.y;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.cp.x = teto-&gt;cur_mino.cp.x;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rot_lMINO(teto, &amp;teto-&gt;cur_mino);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rot_lMINO(teto, &amp;teto-&gt;cur_ghost_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtGHOSTMINO(teto, &amp;teto-&gt;cur_ghost_mino);&nbsp;&nbsp;&nbsp; prtMINO(teto,&amp;teto-&gt;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(teto-&gt;f==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret=chkP(teto); if(ret!=0){teto-&gt;f=1;}<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if(teto-&gt;f&gt;=1&amp;&amp;teto-&gt;f&lt;=6){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; flsP(teto);teto-&gt;f++; prtP(teto); prtMINO(teto,&amp;teto-&gt;cur_mino);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if(teto-&gt;f==7) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dllP(teto); prtP(teto); prtMINO(teto,&amp;teto-&gt;cur_mino); teto-&gt;f++;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if(teto-&gt;f&gt;=8&amp;&amp;teto-&gt;f&lt;=11) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dwnP(teto); prtP(teto); prtMINO(teto,&amp;teto-&gt;cur_mino); teto-&gt;f++;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if(teto-&gt;f==12){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtP(teto);<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.p.y&nbsp; = teto-&gt;cur_mino.p.y;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.p.x&nbsp; = teto-&gt;cur_mino.p.x;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.cp.y = teto-&gt;cur_mino.cp.y;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;cur_ghost_mino.cp.x = teto-&gt;cur_mino.cp.x;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtGHOSTMINO(teto, &amp;teto-&gt;cur_ghost_mino);&nbsp;&nbsp;&nbsp; prtMINO(teto,&amp;teto-&gt;cur_mino);<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;f=0;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(teto-&gt;f==30){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ojlP(teto);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtP(teto);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtMINO(teto,&amp;teto-&gt;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; teto-&gt;ojl--;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(teto-&gt;ojl&lt;=0){teto-&gt;f=0;}<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret=chkP(teto);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(ret!=0){teto-&gt;f=1;}<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return(ret);<br />}<br /><br /><br /><br /><br />#ifdef __OSASK__<br />int G01Main()<br />#else<br />int main()<br />#endif //__OSASK__<br />{<br />&nbsp;&nbsp;&nbsp; int e = 0;<br />&nbsp;&nbsp;&nbsp; int i;<br /><br />&nbsp;&nbsp;&nbsp; TETO &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; t[2];<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dll[2];<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; wt=20;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cwt=0;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dp=0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; init_sys();<br />&nbsp;&nbsp;&nbsp; initTETO(&amp;t[0], NINGEN,&nbsp;&nbsp; 1, -4,&nbsp;&nbsp; 15,7 );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initTETO(&amp;t[1], KIKAI,&nbsp;&nbsp; 27, -4,&nbsp;&nbsp; -4,7 );<br />// &nbsp;&nbsp; initTETO(&amp;t[0], KIKAI,&nbsp;&nbsp;&nbsp; 1, -4,&nbsp;&nbsp; 15,7 );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initTETO(&amp;t[1], KIKAI,&nbsp;&nbsp; 27, -4,&nbsp;&nbsp; -4,7 );<br />//&nbsp;&nbsp;&nbsp; initTETO(&amp;t[0], NINGEN,&nbsp;&nbsp; 1, -4,&nbsp;&nbsp; 15,7 );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initTETO(&amp;t[1], MUJINKUN,27, -4,&nbsp;&nbsp; -4,7 );<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; clr_scr();<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; prtP(&amp;t[0]);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtP(&amp;t[1]);<br />&nbsp;&nbsp;&nbsp; prtNP(&amp;t[0]);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtNP(&amp;t[1]);<br />&nbsp;&nbsp;&nbsp; prtMINO(&amp;t[0],&amp;t[0].next_mino);&nbsp;&nbsp;&nbsp; prtMINO(&amp;t[1],&amp;t[1].next_mino);&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; do{<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dll[0] = calcTETO(&amp;t[0],PAD1,dp);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dll[1] = calcTETO(&amp;t[1],PAD2,dp);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( dll[0] &gt;= 1 ){ t[1].ojl += dll[0]-1; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( dll[1] &gt;= 1 ){ t[0].ojl += dll[1]-1; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vsync(1);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; syncPAD();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dp=0;if(cwt++&gt;=wt){dp=1;cwt=0;}<br />&nbsp;&nbsp;&nbsp; } while((PAD1&amp;PAD_START)==0);<br /><br />&nbsp;&nbsp;&nbsp; close_sys();<br />&nbsp;&nbsp;&nbsp; return(0);<br />}<br /></td></tr></tbody></table><br /><br /><br /> ]]>
</content:encoded>
<dc:subject>OSASK関係</dc:subject>
<dc:date>2009-12-27T18:03:46+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-51.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-51.html</link>
<title>teto (0.0.3)</title>
<description> なんか efg01 にタイマーあるみたいなんでテトリスつくろうと思った。えっ？クリスマス？　なんすか？それ（まさに自分とのたたかい・＿；ほろり 「どうせなら、CPU対戦できるように、AIを書いちゃおうかなぁ&amp;hellip;（＾＿＾；だれもやってなさそうだし」って思ってとりあえずAI書いたんだけど、なんか、ことのほか強くなってしまって、なんか「これ・・・勝てる人間いるのか・・・？（涙orz」みたいな&amp;hellip;wアルゴリズムはチ
 </description>
<content:encoded>
<![CDATA[ なんか efg01 にタイマーあるみたいなんでテトリスつくろうと思った。<br />えっ？クリスマス？　なんすか？それ（まさに自分とのたたかい・＿；ほろり<br /><br /><a target="_blank" href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091223_01.jpg"><img border="0" width="722" height="498" alt="20091223_01.jpg" src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091223_01.jpg" /></a> <br /><br />「どうせなら、CPU対戦できるように、AIを書いちゃおうかなぁ&hellip;（＾＿＾；だれもやってなさそうだし」<br />って思ってとりあえずAI書いたんだけど、なんか、ことのほか強くなってしまって、なんか<br /><br />「これ・・・勝てる人間いるのか・・・？（涙orz」<br /><br />みたいな&hellip;w<br /><br />アルゴリズムはチェスのAIとかでお馴染みの、基本的な「総当たりして最適解をみつける」って方法なんですが、<br />実は「現在のミノ」だけで最適解を考慮してて、まだ「次の予定のミノ」は考慮してないので、ほんとうはこれをやれば<br />さらに強くなる余地が有ります&hellip;（処理ステップが指数関数的に増えますが）<br /><br />いや・・・すでにもぅ人間じゃ勝てなさそうなレベルだし、もぅ充分でしょうけど&hellip;ははw（orz<br /><br /><br /><br />コンパイル済みのバイナリコードです。（操作方法、何かキーを押しっぱなしで動きます。　終了は q です）<br />linux用 <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/teto_linux.mp3" target="_blank">teto_linux.mp3</a>&nbsp;  実行方法は ./t<br />win用（OSASKバイナリー）<a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/teto_win.mp3" target="_blank">teto_win.mp3</a> 実行方法は efg01.exe teto.g01<br />（＊：拡張子を mp3 から zip に書き換えて、zip解凍してください。）（&larr;fc2はzipをアップロードできないので）<br /><br />ソースです。<br />コンパイルはlinuxで gcc -o t teto.c -lc<br />./t<br />です。<br />OSASKのtolsetでもコンパイルできます。その場合一行目の#define__OSASK__を有効にしてね。<br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>teto.c (0.0.3)</td></tr><tr><td>//#define __OSASK__<br /><br />#ifdef __OSASK__<br /><br />#include &lt;guigui01.h&gt;<br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br /><br />#define _COLOR_BLACK &nbsp;&nbsp;&nbsp; 0<br />#define _COLOR_RED &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 2<br />#define _COLOR_GREEN&nbsp;&nbsp;&nbsp; 3<br />#define _COLOR_YELLO&nbsp;&nbsp;&nbsp; 4<br />#define _COLOR_BLUE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 5<br />#define _COLOR_PARPLE&nbsp;&nbsp;&nbsp; 6<br />#define _COLOR_LBLUE&nbsp;&nbsp;&nbsp; 7<br />#define _COLOR_WHITE&nbsp;&nbsp;&nbsp; 8<br /><br />void vsync(int w)<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;w;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; jg01_sleep1(32-5, 1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // x = 32-5 = 27,&nbsp;&nbsp; weit_time = 2^(x-32) = 2^(27-32) = 2^(-5) = 1/32<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void set_put_c_color( int s_color, int bg_color )<br />{<br />&nbsp;&nbsp;&nbsp; jg01_consctrl2( s_color, bg_color );<br />}<br /><br />void put_c( unsigned char c )<br />{<br />&nbsp;&nbsp;&nbsp; g01_putc(c);<br />}<br /><br />unsigned char get_c( void )<br />{<br />&nbsp;&nbsp;&nbsp; return( (unsigned char)jg01_inkey3() );<br />}<br /><br />void set_cur( int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; jg01_consctrl1(x,y);<br />}<br /><br />void clr_scr(void)<br />{<br />&nbsp;&nbsp;&nbsp; jg01_consctrl3();<br />}<br /><br />void init_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; srand(jg01_randomseed());<br /><br />&nbsp;&nbsp;&nbsp; jg01_consctrl4(80,25);<br />&nbsp;&nbsp;&nbsp; jg01_consctrl2(15,0);<br />}<br /><br />void close_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; clr_scr();<br />&nbsp;&nbsp;&nbsp; set_put_c_color( 7, 0 );<br />}<br /><br />#endif // __OSASK__<br /><br />#ifndef __OSASK__<br /><br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;time.h&gt;<br /><br />#include &lt;unistd.h&gt;<br />#include &lt;termios.h&gt;<br />#include &lt;sys/time.h&gt;<br /><br />#define _COLOR_BLACK &nbsp;&nbsp;&nbsp; 1<br />#define _COLOR_RED &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 2<br />#define _COLOR_GREEN&nbsp;&nbsp;&nbsp; 3<br />#define _COLOR_YELLO&nbsp;&nbsp;&nbsp; 4<br />#define _COLOR_BLUE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 5<br />#define _COLOR_PARPLE&nbsp;&nbsp;&nbsp; 6<br />#define _COLOR_LBLUE&nbsp;&nbsp;&nbsp; 7<br />#define _COLOR_WHITE&nbsp;&nbsp;&nbsp; 8<br /><br />static int flg_init_termios = 0;<br />static struct termios save_term;<br />static struct termios temp_term;<br /><br />void vsync(int w)<br />{<br />&nbsp;&nbsp;&nbsp; getchar();<br />}<br /><br />void set_put_c_color( int s_color, int bg_color )<br />{<br />&nbsp;&nbsp;&nbsp; switch(s_color){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 30 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_RED:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 31 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_GREEN:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 32 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_YELLO:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 33 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 34 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_PARPLE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 35 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_LBLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 36 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_WHITE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 37 ); break;<br />&nbsp;&nbsp;&nbsp; default: &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 0&nbsp; ); break;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; switch(bg_color){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 40 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_RED:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 41 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_GREEN:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 42 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_YELLO:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 43 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 44 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_PARPLE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 45 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_LBLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 46 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_WHITE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 47 ); break;<br />&nbsp;&nbsp;&nbsp; default: &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 0&nbsp; ); break;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void put_c( unsigned char c )<br />{<br />&nbsp;&nbsp;&nbsp; putchar((int)c);<br />}<br /><br />unsigned char get_c( void )<br />{<br />&nbsp;&nbsp;&nbsp; return( (unsigned char)getchar() );<br />}<br /><br />void set_cur( int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; printf(&quot;%c[%d;%dH&quot;,0x1b, y+1, x+1 );<br />}<br /><br />void clr_scr(void)<br />{<br />&nbsp;&nbsp;&nbsp; printf(&quot;%c[2J&quot;,0x1B );<br />}<br /><br />void init_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcgetattr(fileno(stdin), &amp;save_term);<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term = save_term;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_iflag &amp;= IGNCR;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ICANON;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ECHO;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ISIG;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VMIN]=1;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VTIME]=0;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;temp_term);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; flg_init_termios += 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ユニークカウンタ（これでシステム全体での起動数を把握しておく）<br /><br />&nbsp;&nbsp;&nbsp; srand((unsigned int)time(0));<br />}<br /><br />void close_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; flg_init_termios -= 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ユニークカウンタを一つ減らす<br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;save_term );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // すべては、これを複数回起動してしまうのを防止するため。（ユニークカウンタ<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; clr_scr();<br />&nbsp;&nbsp;&nbsp; set_put_c_color( 0, 0 );<br />&nbsp;&nbsp;&nbsp; put_c( '\n');<br />}<br /><br />#endif // __OSASK__<br /><br /><br /><br /><br />typedef struct tagPOS {<br />&nbsp;&nbsp;&nbsp; int x;<br />&nbsp;&nbsp;&nbsp; int y;<br />} POS;<br /><br />typedef struct tagBLOCK {<br />&nbsp;&nbsp;&nbsp; unsigned char &nbsp;&nbsp;&nbsp; b[2];<br />&nbsp;&nbsp;&nbsp; POS&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; str_col;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bg_col;<br />} BLOCK;<br /><br />void initB(BLOCK* B)<br />{<br />&nbsp;&nbsp;&nbsp; B-&gt;b[0]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =' ';<br />&nbsp;&nbsp;&nbsp; B-&gt;b[1]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =' ';<br />&nbsp;&nbsp;&nbsp; B-&gt;p.x&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =0;<br />&nbsp;&nbsp;&nbsp; B-&gt;p.y&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =0;<br />&nbsp;&nbsp;&nbsp; B-&gt;str_col&nbsp;&nbsp;&nbsp; =0;<br />&nbsp;&nbsp;&nbsp; B-&gt;bg_col &nbsp;&nbsp;&nbsp; =0;<br />}<br /><br />void cpyB(BLOCK* dst, BLOCK* src )<br />{<br />&nbsp;&nbsp;&nbsp; dst-&gt;b[0]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = src-&gt;b[0];<br />&nbsp;&nbsp;&nbsp; dst-&gt;b[1]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = src-&gt;b[1];<br />&nbsp;&nbsp;&nbsp; dst-&gt;p.x &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = src-&gt;p.x;<br />&nbsp;&nbsp;&nbsp; dst-&gt;p.y &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = src-&gt;p.y;<br />&nbsp;&nbsp;&nbsp; dst-&gt;str_col &nbsp;&nbsp;&nbsp; = src-&gt;str_col;<br />&nbsp;&nbsp;&nbsp; dst-&gt;bg_col &nbsp;&nbsp;&nbsp; = src-&gt;bg_col;<br />}<br /><br />void posB(BLOCK* b, int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; b-&gt;p.x=x;<br />&nbsp;&nbsp;&nbsp; b-&gt;p.y=y;<br />}<br /><br />void colB(BLOCK* b, int col)<br />{<br />&nbsp;&nbsp;&nbsp; switch(col){<br />&nbsp;&nbsp;&nbsp; case 0:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_BLACK;&nbsp;&nbsp;&nbsp; break;<br />//&nbsp;&nbsp;&nbsp; case 0:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_WHITE;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 2:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_RED;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_GREEN;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 4:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_BLUE;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 5:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_YELLO;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 6:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_LBLUE;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 7:&nbsp;&nbsp;&nbsp; b-&gt;str_col = b-&gt;bg_col = _COLOR_PARPLE;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void prtB(BLOCK* b, int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; set_put_c_color(b-&gt;str_col,b-&gt;bg_col);<br /><br />&nbsp;&nbsp;&nbsp; set_cur(2*(b-&gt;p.x+x)+0,b-&gt;p.y+y+0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; put_c(b-&gt;b[0]);<br />&nbsp;&nbsp;&nbsp; set_cur(2*(b-&gt;p.x+x)+1,b-&gt;p.y+y+0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; put_c(b-&gt;b[1]);<br /><br />&nbsp;&nbsp;&nbsp; set_put_c_color(0,0);&nbsp;&nbsp;&nbsp; <br />}<br /><br />void clrB(BLOCK* b, int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; set_put_c_color(_COLOR_BLACK,_COLOR_BLACK);<br /><br />&nbsp;&nbsp;&nbsp; set_cur(2*(b-&gt;p.x+x)+0,b-&gt;p.y+y+0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; put_c(b-&gt;b[0]);<br />&nbsp;&nbsp;&nbsp; set_cur(2*(b-&gt;p.x+x)+1,b-&gt;p.y+y+0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; put_c(b-&gt;b[1]);<br /><br />&nbsp;&nbsp;&nbsp; set_put_c_color(0,0);&nbsp;&nbsp;&nbsp; <br />}<br /><br />#define PANEL_W&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 11<br />#define PANEL_H&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 22<br />typedef struct tagPANEL {<br />&nbsp;&nbsp;&nbsp; BLOCK &nbsp;&nbsp;&nbsp; b[PANEL_W*PANEL_H*10];<br />&nbsp;&nbsp;&nbsp; POS&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p;<br />} PANEL;<br /><br />static PANEL P;<br /><br />void initP(int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; P.p.x=x;<br />&nbsp;&nbsp;&nbsp; P.p.y=y;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H;j++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp=&amp;(P.b[j*PANEL_W]);<br />&nbsp;&nbsp;&nbsp; &nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(j){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case PANEL_H-1:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=-0;i&lt;PANEL_W;i++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,1); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,1); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,0); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initB(bp); posB(bp,i,j); colB(bp,1); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />}<br /><br />static int comp_line[PANEL_H] = {0,0,0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,0,0,&nbsp;&nbsp;&nbsp; 0,0};<br />int chkP(void)<br />{<br />&nbsp;&nbsp;&nbsp; int j,i;<br />&nbsp;&nbsp;&nbsp; int c;<br />&nbsp;&nbsp;&nbsp; int ret =0;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H-1;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp=&amp;(P.b[j*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( bp-&gt;bg_col != _COLOR_BLACK ){ c++; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(c==PANEL_W-1-1) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comp_line[j]=1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comp_line[j]=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return(ret);<br />}<br /><br />static int cur_flsP=0;<br />int flsP(void)<br />{<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; int ret = 0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; int col;<br />&nbsp;&nbsp;&nbsp; switch(cur_flsP) {<br />&nbsp;&nbsp;&nbsp; case 0: col=_COLOR_LBLUE;&nbsp;&nbsp;&nbsp; cur_flsP=1;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 1: col=_COLOR_YELLO; &nbsp;&nbsp;&nbsp; cur_flsP=0;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H-1;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(comp_line[j]!=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp = &amp;(P.b[j*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;str_col = col;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;bg_col&nbsp; = col;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return(ret);<br />}<br /><br />void dllP(void)<br />{<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H-1;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(comp_line[j]!=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp = &amp;(P.b[j*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;str_col = _COLOR_BLACK;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;bg_col&nbsp; = _COLOR_BLACK;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />int dwnP(void)<br />{<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; BLOCK* ubp;<br />&nbsp;&nbsp;&nbsp; int c;<br />&nbsp;&nbsp;&nbsp; int ret=0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=PANEL_H-1-1; j&gt;0; j--){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp = &amp;(P.b[j*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( bp-&gt;bg_col == _COLOR_BLACK ) { c++; };<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(c==PANEL_W-1-1){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp&nbsp; = &amp;(P.b[(j+0)*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp = &amp;(P.b[(j-1)*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;str_col = ubp-&gt;str_col;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp-&gt;bg_col&nbsp; = ubp-&gt;bg_col;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp-&gt;str_col = _COLOR_BLACK;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp-&gt;bg_col&nbsp; = _COLOR_BLACK;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return(ret);<br />}<br /><br />void prtP(void)<br />{<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp=&amp;(P.b[j*PANEL_W]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;PANEL_W;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; prtB(bp++,P.p.x, P.p.y);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />int apB(BLOCK* b,int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; int cx=b-&gt;p.x+x;<br />&nbsp;&nbsp;&nbsp; int cy=b-&gt;p.y+y;<br /><br />&nbsp;&nbsp;&nbsp; switch( P.b[cy*PANEL_W+cx].bg_col ){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; return(0);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; default:&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(1);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br /><br />typedef struct tagMINO {<br />&nbsp;&nbsp;&nbsp; BLOCK &nbsp;&nbsp;&nbsp; b[4];<br />&nbsp;&nbsp;&nbsp; POS&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p;<br />} MINO;<br /><br />void initMINO(MINO* m, int t)<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; register BLOCK* bp = m-&gt;b;<br /><br />&nbsp;&nbsp;&nbsp; m-&gt;p.x = 3;<br />&nbsp;&nbsp;&nbsp; m-&gt;p.y = 2;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; initB(bp++);&nbsp;&nbsp;&nbsp; initB(bp++);&nbsp;&nbsp;&nbsp; initB(bp++);&nbsp;&nbsp;&nbsp; initB(bp++);<br /><br />&nbsp;&nbsp;&nbsp; bp = m-&gt;b;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; switch(t) {<br />&nbsp;&nbsp;&nbsp; case 0:&nbsp;&nbsp;&nbsp; colB(bp++,1);&nbsp;&nbsp;&nbsp; colB(bp++,1);&nbsp;&nbsp;&nbsp; colB(bp++,1);&nbsp;&nbsp;&nbsp; colB(bp++,1);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; colB(bp++,2);&nbsp;&nbsp;&nbsp; colB(bp++,2);&nbsp;&nbsp;&nbsp; colB(bp++,2);&nbsp;&nbsp;&nbsp; colB(bp++,2);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 2:&nbsp;&nbsp;&nbsp; colB(bp++,3);&nbsp;&nbsp;&nbsp; colB(bp++,3);&nbsp;&nbsp;&nbsp; colB(bp++,3);&nbsp;&nbsp;&nbsp; colB(bp++,3);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; colB(bp++,4);&nbsp;&nbsp;&nbsp; colB(bp++,4);&nbsp;&nbsp;&nbsp; colB(bp++,4);&nbsp;&nbsp;&nbsp; colB(bp++,4);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 4:&nbsp;&nbsp;&nbsp; colB(bp++,5);&nbsp;&nbsp;&nbsp; colB(bp++,5);&nbsp;&nbsp;&nbsp; colB(bp++,5);&nbsp;&nbsp;&nbsp; colB(bp++,5);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 5:&nbsp;&nbsp;&nbsp; colB(bp++,6);&nbsp;&nbsp;&nbsp; colB(bp++,6);&nbsp;&nbsp;&nbsp; colB(bp++,6);&nbsp;&nbsp;&nbsp; colB(bp++,6);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 6:&nbsp;&nbsp;&nbsp; colB(bp++,7);&nbsp;&nbsp;&nbsp; colB(bp++,7);&nbsp;&nbsp;&nbsp; colB(bp++,7);&nbsp;&nbsp;&nbsp; colB(bp++,7);&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; bp = m-&gt;b;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; switch(t) {<br />&nbsp;&nbsp;&nbsp; case 0:&nbsp;&nbsp;&nbsp; posB(bp++,0,-1);&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,2);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ----<br />&nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // []<br />&nbsp;&nbsp;&nbsp; case 2:&nbsp;&nbsp;&nbsp; posB(bp++,-1,0);&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,-1);&nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // T<br />&nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; posB(bp++,-1,0);&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // N<br />&nbsp;&nbsp;&nbsp; case 4:&nbsp;&nbsp;&nbsp; posB(bp++,-1,1);&nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // !N<br />&nbsp;&nbsp;&nbsp; case 5:&nbsp;&nbsp;&nbsp; posB(bp++,0,-1);&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,1,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // L<br />&nbsp;&nbsp;&nbsp; case 6:&nbsp;&nbsp;&nbsp; posB(bp++,0,-1);&nbsp;&nbsp;&nbsp; posB(bp++,0,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,0,1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp++,-1,1);&nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // !L<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void cpyMINO( MINO* dst, MINO* src )<br />{<br />&nbsp;&nbsp;&nbsp; dst-&gt;p.x = src-&gt;p.x;<br />&nbsp;&nbsp;&nbsp; dst-&gt;p.y = src-&gt;p.y;<br /><br />&nbsp;&nbsp;&nbsp; BLOCK* dbp = dst-&gt;b;<br />&nbsp;&nbsp;&nbsp; BLOCK* sbp = src-&gt;b;<br />&nbsp;&nbsp;&nbsp; cpyB(dbp++,sbp++);&nbsp;&nbsp;&nbsp; cpyB(dbp++,sbp++);&nbsp;&nbsp;&nbsp; cpyB(dbp++,sbp++);&nbsp;&nbsp;&nbsp; cpyB(dbp++,sbp++);<br />}<br /><br />int apMINO(MINO* m)<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; int x=m-&gt;p.x;<br />&nbsp;&nbsp;&nbsp; int y=m-&gt;p.y;<br />&nbsp;&nbsp;&nbsp; int ret=0;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp = m-&gt;b;<br />&nbsp;&nbsp;&nbsp; ret+=apB(bp++,x,y);&nbsp;&nbsp;&nbsp; ret+=apB(bp++,x,y);&nbsp;&nbsp;&nbsp; ret+=apB(bp++,x,y);&nbsp;&nbsp;&nbsp; ret+=apB(bp++,x,y);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return(ret);<br />}<br /><br />void __rotMINO( MINO* m, int r )<br />{<br />&nbsp;&nbsp;&nbsp; BLOCK* bp = m-&gt;b;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(r &gt;= +1){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, +bp-&gt;p.y,-bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, +bp-&gt;p.y,-bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, +bp-&gt;p.y,-bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, +bp-&gt;p.y,-bp-&gt;p.x );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if( r &lt;= -1){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, -bp-&gt;p.y,+bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, -bp-&gt;p.y,+bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, -bp-&gt;p.y,+bp-&gt;p.x ); bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; posB(bp, -bp-&gt;p.y,+bp-&gt;p.x );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void rot_rMINO( MINO* m )<br />{<br />&nbsp;&nbsp;&nbsp; __rotMINO( m, -1 );&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(apMINO(m)!=0){ __rotMINO( m, +1 ); }<br />}<br /><br />void rot_lMINO( MINO* m )<br />{<br />&nbsp;&nbsp;&nbsp; __rotMINO( m, +1 );&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(apMINO(m)!=0){ __rotMINO( m, -1 ); }<br />}<br /><br />int __movMINO(MINO* m, int x, int y)<br />{<br />&nbsp;&nbsp;&nbsp; m-&gt;p.x+=x;&nbsp;&nbsp;&nbsp; m-&gt;p.y+=y;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(apMINO(m)!=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m-&gt;p.x-=x;&nbsp;&nbsp;&nbsp; m-&gt;p.y-=y;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(1);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; return(0);<br />}<br /><br />int mov_dMINO(MINO* m)<br />{<br />&nbsp;&nbsp;&nbsp; return(__movMINO(m,0,1));<br />}<br /><br />int mov_rMINO(MINO* m)<br />{<br />&nbsp;&nbsp;&nbsp; return(__movMINO(m,+1,0));<br />}<br /><br />int mov_lMINO(MINO* m)<br />{<br />&nbsp;&nbsp;&nbsp; return(__movMINO(m,-1,0));<br />}<br /><br />void prtMINO( MINO* m )<br />{<br />&nbsp;&nbsp;&nbsp; BLOCK* mbp = m-&gt;b;<br />&nbsp;&nbsp;&nbsp; int x = P.p.x + m-&gt;p.x;<br />&nbsp;&nbsp;&nbsp; int y = P.p.y + m-&gt;p.y;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; prtB(mbp++,x,y);&nbsp;&nbsp;&nbsp; prtB(mbp++,x,y);&nbsp;&nbsp;&nbsp; prtB(mbp++,x,y);&nbsp;&nbsp;&nbsp; prtB(mbp++,x,y);<br />}<br /><br />void clrMINO( MINO* m )<br />{<br />&nbsp;&nbsp;&nbsp; BLOCK* mbp = m-&gt;b;<br />&nbsp;&nbsp;&nbsp; int x = P.p.x + m-&gt;p.x;<br />&nbsp;&nbsp;&nbsp; int y = P.p.y + m-&gt;p.y;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; clrB(mbp++,x,y);&nbsp;&nbsp;&nbsp; clrB(mbp++,x,y);&nbsp;&nbsp;&nbsp; clrB(mbp++,x,y);&nbsp;&nbsp;&nbsp; clrB(mbp++,x,y);<br />}<br /><br />#define DM_LEN 7<br />static MINO DM[DM_LEN];<br />void initDM(void)<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;DM_LEN;i++){ initMINO(&amp;DM[i],i); }<br />}<br /><br />static int rand_box[DM_LEN*2]={0,1,2,3,4,5,6,0,1,2,3,4,5,6};<br />static int cur_rand_box_len=DM_LEN*2;<br />void newMINO( MINO* m )<br />{<br />&nbsp;&nbsp;&nbsp; int i; <br />&nbsp;&nbsp;&nbsp; if(cur_rand_box_len&lt;=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;DM_LEN;i++){rand_box[i+0]=i; rand_box[i+DM_LEN]=i;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_rand_box_len=DM_LEN;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; int rnd = rand()%(cur_rand_box_len);<br />&nbsp;&nbsp;&nbsp; cpyMINO( m, &amp;DM[rand_box[rnd]] );<br /><br />&nbsp;&nbsp;&nbsp; for(i=rnd;i&lt;cur_rand_box_len-1;i++){rand_box[i]=rand_box[i+1];}<br />&nbsp;&nbsp;&nbsp; cur_rand_box_len--;<br />}<br /><br />void M2P( MINO* m )<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; BLOCK* mbp = m-&gt;b;<br />&nbsp;&nbsp;&nbsp; BLOCK* pbp;<br /><br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;4;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mbp = &amp;(m-&gt;b[i]);<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mbp-&gt;p.x += m-&gt;p.x;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mbp-&gt;p.y += m-&gt;p.y;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pbp = &amp;(P.b[ mbp-&gt;p.y*PANEL_W +mbp-&gt;p.x ]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpyB(pbp, mbp);<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br /><br /><br /><br /><br /><br /><br />typedef struct tagAI {<br />} __AI;<br />//struct __AI AI;<br />static PANEL &nbsp;&nbsp;&nbsp; CPP;<br />static MINO&nbsp; &nbsp;&nbsp;&nbsp; CPM;<br />static int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CTV,CTH,CTR;<br />int stAI()<br />{<br />&nbsp;&nbsp;&nbsp; int i,j;<br />&nbsp;&nbsp;&nbsp; int sc=0;<br />&nbsp;&nbsp;&nbsp; int h;<br />&nbsp;&nbsp;&nbsp; int nl=_COLOR_BLACK;<br />&nbsp;&nbsp;&nbsp; BLOCK* bp;<br />&nbsp;&nbsp;&nbsp; BLOCK* lbp;<br />&nbsp;&nbsp;&nbsp; BLOCK* rbp;<br />&nbsp;&nbsp;&nbsp; BLOCK* ubp;<br />&nbsp;&nbsp;&nbsp; BLOCK* dbp;<br />&nbsp;&nbsp;&nbsp; for(j=1;j&lt;PANEL_H-1;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp=&amp;(P.b[j*PANEL_W+1]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lbp=bp-1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rbp=bp+1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp=bp-PANEL_W;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dbp=bp+PANEL_W;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=1;i&lt;PANEL_W-1;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(j&gt;PANEL_H-6){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(bp-&gt;bg_col!=nl){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; h=(PANEL_H-j);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sc+=h;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl){if(i&gt;=2&amp;&amp;i&lt;=PANEL_W-1){sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl){if(i&gt;=1&amp;&amp;i&lt;=PANEL_W-2){sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl){if(i==1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {sc-=1;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl){if(i==PANEL_W-1){sc-=1;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(dbp-&gt;bg_col==nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(bp-&gt;bg_col==nl){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col!=nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col!=nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col==nl){sc-=1;};<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col==nl&amp;&amp;dbp-&gt;bg_col==nl){sc-=1;};<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(bp-&gt;bg_col!=nl){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; h=(PANEL_H-j);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sc+=h*2;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl){if(i&gt;=2&amp;&amp;i&lt;=PANEL_W-1){sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl){if(i&gt;=1&amp;&amp;i&lt;=PANEL_W-2){sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl){if(i==1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl){if(i==PANEL_W-1){sc-=2;}}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(dbp-&gt;bg_col==nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(bp-&gt;bg_col==nl){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col!=nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col!=nl){sc+=10;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(rbp-&gt;bg_col!=nl&amp;&amp;lbp-&gt;bg_col!=nl){sc+=5;}<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col==nl){sc-=1;};<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(lbp-&gt;bg_col!=nl&amp;&amp;rbp-&gt;bg_col!=nl&amp;&amp;ubp-&gt;bg_col==nl&amp;&amp;dbp-&gt;bg_col==nl){sc-=1;};<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bp++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lbp=bp-1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rbp=bp+1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ubp=bp-PANEL_W;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dbp=bp+PANEL_W;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return(sc);<br />}<br /><br />void sncAI(MINO* cm)<br />{<br />&nbsp;&nbsp;&nbsp; int i,j,k,l;<br />&nbsp;&nbsp;&nbsp; int ls=0xFFFFFFF;<br />&nbsp;&nbsp;&nbsp; int sp=cm-&gt;p.x;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; tv=0,th=0,tr=0;<br />&nbsp;&nbsp;&nbsp; BLOCK* pbp=P.b;<br />&nbsp;&nbsp;&nbsp; BLOCK* cbp=CPP.b;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;PANEL_H*PANEL_W;i++){*cbp++ = *pbp++;}<br />&nbsp;&nbsp;&nbsp; cpyMINO( &amp;CPM, cm );<br /><br />&nbsp;&nbsp;&nbsp; for(l=0;l&lt;4;l++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(k=1;k&lt;PANEL_W-1;k++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pbp=P.b;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cbp=CPP.b;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;PANEL_H*PANEL_W;i++){*pbp++ = *cbp++;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpyMINO( cm, &amp;CPM );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;l;i++){ tr=l; rot_lMINO(cm); }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int hm=k-sp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; th=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(hm&lt;0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; hm=-hm;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;hm;i++){ th--; mov_lMINO(cm); }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;hm;i++){ th++; mov_rMINO(cm); }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tv=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(j=0;j&lt;PANEL_H-1;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tv++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(mov_dMINO(cm)!=0){break;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; M2P(cm);<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clr_scr();<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtP();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int st=stAI();<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(0,3);<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_put_c_color(0,0);<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;st=%d, &quot;,st);<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; get_c();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(st&lt;ls){ls=st;CTH=th;CTV=tv;CTR=tr;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp; <br />&nbsp;&nbsp;&nbsp; pbp=P.b;<br />&nbsp;&nbsp;&nbsp; cbp=CPP.b;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;PANEL_H*PANEL_W;i++){*pbp++ = *cbp++;}<br />&nbsp;&nbsp;&nbsp; cpyMINO( cm, &amp;CPM );<br />&nbsp;&nbsp;&nbsp; <br />//&nbsp;&nbsp;&nbsp; CTR=3;<br />//&nbsp;&nbsp;&nbsp; CTH=5;<br />}<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />#ifdef __OSASK__<br />int G01Main()<br />#else<br />int main()<br />#endif //__OSASK__<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char ky;<br />&nbsp;&nbsp;&nbsp; int e = 0;<br />&nbsp;&nbsp;&nbsp; int f=0;<br />&nbsp;&nbsp;&nbsp; int snc=0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; init_sys();<br />&nbsp;&nbsp;&nbsp; initP(10,1);<br />&nbsp;&nbsp;&nbsp; initDM();<br /><br />&nbsp;&nbsp;&nbsp; clr_scr();<br /><br />&nbsp;&nbsp;&nbsp; MINO cur_mino;<br />&nbsp;&nbsp;&nbsp; MINO next_mino;&nbsp;&nbsp;&nbsp; newMINO( &amp;next_mino );<br />&nbsp;&nbsp;&nbsp; cpyMINO( &amp;cur_mino, &amp;next_mino );<br />&nbsp;&nbsp;&nbsp; newMINO( &amp;next_mino ); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next_mino.p.x= 14;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtMINO(&amp;next_mino);<br /><br />&nbsp;&nbsp;&nbsp; prtP();<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; do{<br />//clr_scr();<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; M2P(&amp;DM[2]);<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtP();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtMINO(&amp;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ky=get_c();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(f==0&amp;&amp;snc==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sncAI(&amp;cur_mino);snc=1;<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(0,0);<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_put_c_color(0,0);<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;CTH=%d, CTV=%d, CTR=%d&quot;,CTH,CTV,CTR);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(snc==1){<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(0,1);<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_put_c_color(0,0);<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;CTH=%d, CTV=%d, CTR=%d&quot;,CTH,CTV,CTR);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(ky=='q'){break;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(CTR&gt;=1){ CTR--; ky='u';}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if(CTH&gt;=+1){ CTH--; ky='l';}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if(CTH&lt;=-1){ CTH++; ky='j';}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else { ky='k';}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(ky){<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'n':<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpyMINO( &amp;cur_mino, &amp;next_mino );<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; newMINO( &amp;next_mino );<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'k': <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clrMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(mov_dMINO(&amp;cur_mino)!=0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snc=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; M2P(&amp;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtP();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpyMINO( &amp;cur_mino, &amp;next_mino );&nbsp;&nbsp;&nbsp; cur_mino.p.x = 6;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; newMINO( &amp;next_mino ); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next_mino.p.x= 14;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtMINO(&amp;next_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtMINO(&amp;cur_mino);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'j': clrMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; mov_lMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; prtMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'l': clrMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; mov_rMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; prtMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'i': clrMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; rot_rMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; prtMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'u': clrMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; rot_lMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; prtMINO(&amp;cur_mino);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'q':e=1; close_sys(); return(0);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(f==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(chkP()!=0){f=1;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if(f&gt;=1&amp;&amp;f&lt;=6){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; flsP();f++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtP();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if(f==7) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dllP();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtP();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; f++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if(f&gt;=8&amp;&amp;f&lt;=11) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dwnP();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtP();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; f++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; prtP();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; f=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; } while(e==0);<br /><br />&nbsp;&nbsp;&nbsp; close_sys();<br />&nbsp;&nbsp;&nbsp; return(0);<br />}</td></tr></tbody></table> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-12-23T01:02:45+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-50.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-50.html</link>
<title>数独(0.0.1)</title>
<description> OSASKという自作OSがあって、それのコミュニティにて次世代のOSASKの開発がゆっくり進んでます。現在はネイティブなOSではなくて、既存のOS上で動作する関数セットのような状態ですが、いちおう動作可能な状態です。要するにJAVAの仮想マシンみたいなものだとボクは認識してます。現在の実行環境としては、WindowsとLinux上で同様に動作する efg01 というプログラムに引数として与える形で実行します。efg01は、現時点ではコンソー
 </description>
<content:encoded>
<![CDATA[ <a target="_blank" href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091220_sd.jpg"><img border="0" width="720" height="481" alt="20091220_sd.jpg" src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091220_sd.jpg" /></a> <br /><br />OSASKという自作OSがあって、それのコミュニティにて次世代のOSASKの開発がゆっくり進んでます。<br />現在はネイティブなOSではなくて、既存のOS上で動作する関数セットのような状態ですが、いちおう動作可能な状態です。<br /><br />要するにJAVAの仮想マシンみたいなものだとボクは認識してます。<br />現在の実行環境としては、WindowsとLinux上で同様に動作する efg01 というプログラムに引数として与える形で実行します。<br /><br />efg01は、現時点ではコンソールへの文字出力と、ファイル入出力、独自形式圧縮ファイルの入出力、<br />くらいしかサポートしてなくて、<br />まだグラフィック関連、サウンド関連、通信関連、その他雑多なIO諸々の関数は、まだ作られてない状態みたいです。　<br />画面に１ドットの点を打つことすらできません。<br />だから当然、ウインドウマネージャーなどまだ乗ってません。<br />あと、多バイト文字もサポートされてないので、日本語を表示できません。 UTF8もシフトJISすら表示できません。<br />まだ文字コードの変換テーブルが実装されてないみたいです。<br /><br />と、まぁ、要するに今現在、efg01 でサポートしてる処理は「コンソールにAと打つ」って程度です。USBとかDVDRWとか、そういう機器も一切使えません。<br /><br />この極端に貧弱な命令セットで、いったい何がつくれるの？　と疑問に思ってたのですが、<br />OSASKのコミュニティーを見てると efg01 上で動くゲームを何点か公開してる人がいました。　「これはおもしろいかも&hellip;」<br /><br />なんかDOSみたいで萌えました。いやマジで。<br /><br /><br />というわけで、何か efg01上で動くプログラムを書いて貢献しようと思いました。<br />「とりあえずテトリスでも書くか？」<br />って思ったんですが、どうやらタイマー（時間による制御）関連の使い方がよくわからないので、<br />タイマーを使わずに作れるゲームにしようと思いました。<br />そのうち誰かがタイマーを活用したコードを公開するでしょうから、それまで待ちます&hellip;w<br /><br />というわけで数独。<br /><br />問題のジェネレートは、あらかじめ自力で作った問題を、行列操作で混ぜるだけです。<br />ほんとうは、自分が問題を作ってるときの思考パターンをプログラムに置き換えて、それによって完全に（種なしで）ジェネレートするアルゴリズムを考える方が有意義なのでしょうけど、<br />ことのほか自分の自力で問題作るときの方法論は『確実性』がいまいちで、かならずしも毎回生成に成功するわけじゃないんですよね&hellip;　無限級数みたいな状態になったりして。<br />そういう『例外』が「なぜか？」がわかれば、それを糸口にアルゴリズムに確実性を持たせられるんでしょうけど、<br />どうにもボクの頭じゃ難しいです。<br />こういう時、数学に詳しい人はいいなぁ～&hellip;ってうらやましく思います。<br />ルービックキューブの解法を群論で解いたりできる人って、こういうのも余裕でアルゴリズム思いつくんだろうなぁ&hellip;と。<br /><br />もっとも、『ものすごく単純な方法』で、種をジェネレートすることは可能ですが、<br />その種は規則性が分かり易すぎて、あまり問題としてはおもしろくないんですよね。　反復が見え見えだったりして。<br />やっぱ、数独の問題は、人間が考えたものの方が面白いと思います。規則性がわかりにくくて。<br /><br />この、『人間が作る』ってときの、思考パターンをアルゴリズムにできればなぁ&hellip;と。<br />いや、まぁ、ことのほか強敵っぽいので当分保留しときます&hellip;w（orz<br /><br />あと、まだ判定とか、そういうゲーム的な部分が何も書かれてないです。<br />まぁ、おいおい直してきます。<br />それなりにゲームの体裁が整い次第、OSASKのコミュに投下でもしようかなぁ～&hellip;と思ってます。いまのところ。<br />まぁ当分先でしょうけど。<br /><br /><br /><br />コンパイル：<br /><br />linux の gcc でコンパイルして実行できます。　gcc -o sd sd.c -lc<br />./sd<br />です。<br /><br />efg01　用にコンパイルする場合は、efg01のtoolsetでコンパイルします。　その際、sd.c ソースコードの一行目のコメントアウト // #define __OSASK__ を解除して有効にしてください。<br /><br /><br /><br />操作方法：<br /><br />J カーソル右<br />K カーソル下<br />L カーソル左<br />I　カーソル上<br /><br />H　カーソル位置の数を増やす<br />N　カーソル位置の数を減らす<br /><br />QQQ　終了（Qを３回押す）<br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>sd.c (0.0.1)</td></tr><tr><td>//#define __OSASK__<br /><br />#ifdef __OSASK__<br /><br />#include &lt;guigui01.h&gt;<br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br /><br />#define _COLOR_BLACK &nbsp;&nbsp;&nbsp; 0<br />#define _COLOR_RED &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 2<br />#define _COLOR_GREEN&nbsp;&nbsp;&nbsp; 3<br />#define _COLOR_YELLO&nbsp;&nbsp;&nbsp; 4<br />#define _COLOR_BLUE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 5<br />#define _COLOR_PARPLE&nbsp;&nbsp;&nbsp; 6<br />#define _COLOR_LBLUE&nbsp;&nbsp;&nbsp; 7<br />#define _COLOR_WHITE&nbsp;&nbsp;&nbsp; 8<br /><br />void set_put_c_color( int s_color, int bg_color )<br />{<br />&nbsp;&nbsp;&nbsp; jg01_consctrl2( s_color, bg_color );<br />}<br /><br />void put_c( unsigned char c )<br />{<br />&nbsp;&nbsp;&nbsp; g01_putc(c);<br />}<br /><br />unsigned char get_c( void )<br />{<br />&nbsp;&nbsp;&nbsp; return( (unsigned char)jg01_inkey3() );<br />}<br /><br />void set_cur( int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; jg01_consctrl1(x,y);<br />}<br /><br />void clr_scr(void)<br />{<br />&nbsp;&nbsp;&nbsp; jg01_consctrl3();<br />}<br /><br />void init_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; srand(jg01_randomseed());<br /><br />&nbsp;&nbsp;&nbsp; jg01_consctrl4(80,25);<br />&nbsp;&nbsp;&nbsp; jg01_consctrl2(15,0);<br />}<br /><br />void close_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; clr_scr();<br />&nbsp;&nbsp;&nbsp; set_put_c_color( 7, 0 );<br />}<br /><br />#endif // __OSASK__<br /><br />#ifndef __OSASK__<br /><br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;time.h&gt;<br /><br />#include &lt;unistd.h&gt;<br />#include &lt;termios.h&gt;<br />#include &lt;sys/time.h&gt;<br /><br />#define _COLOR_BLACK &nbsp;&nbsp;&nbsp; 1<br />#define _COLOR_RED &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 2<br />#define _COLOR_GREEN&nbsp;&nbsp;&nbsp; 3<br />#define _COLOR_YELLO&nbsp;&nbsp;&nbsp; 4<br />#define _COLOR_BLUE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 5<br />#define _COLOR_PARPLE&nbsp;&nbsp;&nbsp; 6<br />#define _COLOR_LBLUE&nbsp;&nbsp;&nbsp; 7<br />#define _COLOR_WHITE&nbsp;&nbsp;&nbsp; 8<br /><br />static int flg_init_termios = 0;<br />static struct termios save_term;<br />static struct termios temp_term;<br /><br />void set_put_c_color( int s_color, int bg_color )<br />{<br />&nbsp;&nbsp;&nbsp; switch(s_color){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 30 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_RED:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 31 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_GREEN:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 32 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_YELLO:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 33 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 34 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_PARPLE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 35 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_LBLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 36 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_WHITE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 37 ); break;<br />&nbsp;&nbsp;&nbsp; default: &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 0&nbsp; ); break;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; switch(bg_color){<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLACK:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 40 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_RED:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 41 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_GREEN:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 42 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_YELLO:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 43 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_BLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 44 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_PARPLE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 45 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_LBLUE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 46 ); break;<br />&nbsp;&nbsp;&nbsp; case _COLOR_WHITE:&nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 47 ); break;<br />&nbsp;&nbsp;&nbsp; default: &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%c[%dm&quot;,0x1b, 0&nbsp; ); break;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void put_c( unsigned char c )<br />{<br />&nbsp;&nbsp;&nbsp; putchar((int)c);<br />}<br /><br />unsigned char get_c( void )<br />{<br />&nbsp;&nbsp;&nbsp; return( (unsigned char)getchar() );<br />}<br /><br />void set_cur( int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; printf(&quot;%c[%d;%dH&quot;,0x1b, y+1, x+1 );<br />}<br /><br />void clr_scr(void)<br />{<br />&nbsp;&nbsp;&nbsp; printf(&quot;%c[2J&quot;,0x1B );<br />}<br /><br />void init_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcgetattr(fileno(stdin), &amp;save_term);<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term = save_term;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_iflag &amp;= IGNCR;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ICANON;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ECHO;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ISIG;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VMIN]=1;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VTIME]=0;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;temp_term);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; flg_init_termios += 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ユニークカウンタ（これでシステム全体での起動数を把握しておく）<br /><br />&nbsp;&nbsp;&nbsp; srand((unsigned int)time(0));<br />}<br /><br />void close_sys(void)<br />{<br />&nbsp;&nbsp;&nbsp; flg_init_termios -= 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ユニークカウンタを一つ減らす<br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;save_term );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // すべては、これを複数回起動してしまうのを防止するため。（ユニークカウンタ<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; clr_scr();<br />&nbsp;&nbsp;&nbsp; set_put_c_color( 0, 0 );<br />&nbsp;&nbsp;&nbsp; put_c( '\n');<br />}<br /><br />#endif // __OSASK__<br /><br /><br /><br />#define P00 0<br />#define P01 3<br />#define P02 6<br />#define P10 27<br />#define P11 30<br />#define P12 33<br />#define P20 54<br />#define P21 57<br />#define P22 60<br /><br />typedef struct tagPOS {<br />&nbsp;&nbsp;&nbsp; unsigned char x;<br />&nbsp;&nbsp;&nbsp; unsigned char y;<br />} POS;<br /><br />char defPseed[82]={<br />&nbsp;&nbsp;&nbsp; 2,8,3,&nbsp;&nbsp;&nbsp; 6,5,4,&nbsp;&nbsp;&nbsp; 7,1,9,<br />&nbsp;&nbsp;&nbsp; 4,7,6,&nbsp;&nbsp;&nbsp; 9,8,1,&nbsp;&nbsp;&nbsp; 2,3,5,<br />&nbsp;&nbsp;&nbsp; 9,5,1,&nbsp;&nbsp;&nbsp; 2,7,3,&nbsp;&nbsp;&nbsp; 6,4,8,<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; 1,3,9,&nbsp;&nbsp;&nbsp; 4,6,7,&nbsp;&nbsp;&nbsp; 8,5,2,<br />&nbsp;&nbsp;&nbsp; 6,2,5,&nbsp;&nbsp;&nbsp; 1,3,8,&nbsp;&nbsp;&nbsp; 4,9,7,<br />&nbsp;&nbsp;&nbsp; 7,4,8,&nbsp;&nbsp;&nbsp; 5,2,9,&nbsp;&nbsp;&nbsp; 1,6,3,<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; 5,1,2,&nbsp;&nbsp;&nbsp; 7,9,6,&nbsp;&nbsp;&nbsp; 3,8,4,<br />&nbsp;&nbsp;&nbsp; 3,9,4,&nbsp;&nbsp;&nbsp; 8,1,2,&nbsp;&nbsp;&nbsp; 5,7,6,<br />&nbsp;&nbsp;&nbsp; 8,6,7,&nbsp;&nbsp;&nbsp; 3,4,5,&nbsp;&nbsp;&nbsp; 9,2,1,<br />};<br /><br />static unsigned char MP[82];<br />static unsigned char UNITP[82]={<br />&nbsp;&nbsp;&nbsp; 0xFF,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,<br />&nbsp;&nbsp;&nbsp; 0,0xFF,0,&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,<br />&nbsp;&nbsp;&nbsp; 0,0,0xFF,&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0xFF,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,<br />&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0,0xFF,0,&nbsp;&nbsp;&nbsp; 0,0,0,<br />&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0xFF,&nbsp;&nbsp;&nbsp; 0,0,0,<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0xFF,0,0,<br />&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0,0xFF,0,<br />&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0,&nbsp;&nbsp;&nbsp; 0,0,0xFF,<br />};<br />static unsigned char BP[82];<br /><br /><br /><br />void tm33(char* m)<br />{<br />&nbsp;&nbsp;&nbsp; char b[9];<br /><br />&nbsp;&nbsp;&nbsp; register char* bp = b;<br />&nbsp;&nbsp;&nbsp; register char* mp = m;<br />&nbsp;&nbsp;&nbsp; *bp++=*mp++;*bp++=*mp++;*bp++=*mp++;mp+=6;<br />&nbsp;&nbsp;&nbsp; *bp++=*mp++;*bp++=*mp++;*bp++=*mp++;mp+=6;<br />&nbsp;&nbsp;&nbsp; *bp++=*mp++;*bp++=*mp++;*bp++=*mp++;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; bp=b;<br />&nbsp;&nbsp;&nbsp; mp=m;<br />&nbsp;&nbsp;&nbsp; *mp++=*(bp+6);*mp++=*(bp+3);*mp++=*(bp+0);mp+=6;<br />&nbsp;&nbsp;&nbsp; *mp++=*(bp+7);*mp++=*(bp+4);*mp++=*(bp+1);mp+=6;<br />&nbsp;&nbsp;&nbsp; *mp++=*(bp+8);*mp++=*(bp+5);*mp++=*(bp+2);<br />}<br /><br />void swpm33n(char* m, char a_, char b_ )<br />{<br />&nbsp;&nbsp;&nbsp; register char* mp = m;<br />&nbsp;&nbsp;&nbsp; register char a = a_;<br />&nbsp;&nbsp;&nbsp; register char b = b_;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(*mp==a){*mp=b;}else if(*mp==b){*mp=a;} mp++;<br />&nbsp;&nbsp;&nbsp; if(*mp==a){*mp=b;}else if(*mp==b){*mp=a;} mp++;<br />&nbsp;&nbsp;&nbsp; if(*mp==a){*mp=b;}else if(*mp==b){*mp=a;} mp++; mp+=6;<br /><br />&nbsp;&nbsp;&nbsp; if(*mp==a){*mp=b;}else if(*mp==b){*mp=a;} mp++;<br />&nbsp;&nbsp;&nbsp; if(*mp==a){*mp=b;}else if(*mp==b){*mp=a;} mp++;<br />&nbsp;&nbsp;&nbsp; if(*mp==a){*mp=b;}else if(*mp==b){*mp=a;} mp++; mp+=6;<br /><br />&nbsp;&nbsp;&nbsp; if(*mp==a){*mp=b;}else if(*mp==b){*mp=a;} mp++;<br />&nbsp;&nbsp;&nbsp; if(*mp==a){*mp=b;}else if(*mp==b){*mp=a;} mp++;<br />&nbsp;&nbsp;&nbsp; if(*mp==a){*mp=b;}else if(*mp==b){*mp=a;} mp++;<br />}<br /><br />void pP(char* P, POS* cp )<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; const unsigned char&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; o='0';<br />&nbsp;&nbsp;&nbsp; const unsigned char&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s=' ';<br />&nbsp;&nbsp;&nbsp; unsigned char &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpx=cp-&gt;x;<br />&nbsp;&nbsp;&nbsp; unsigned char &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpy=cp-&gt;y;<br /><br />&nbsp;&nbsp;&nbsp; register unsigned char*&nbsp;&nbsp;&nbsp; pp = P;<br />&nbsp;&nbsp;&nbsp; register unsigned char*&nbsp;&nbsp;&nbsp; mp = MP;<br /><br />&nbsp;&nbsp;&nbsp; set_put_c_color( _COLOR_GREEN, _COLOR_WHITE );<br />&nbsp;&nbsp;&nbsp; int c = 0;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;12;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(c++&gt;=3){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpy++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpx=cp-&gt;x;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx,cpy);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++!=0){put_c(s);put_c(o+*pp);put_c(s);} pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++!=0){put_c(s);put_c(o+*pp);put_c(s);} pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++!=0){put_c(s);put_c(o+*pp);put_c(s);} pp++; cpx++; cpx++; <br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++!=0){put_c(s);put_c(o+*pp);put_c(s);} pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++!=0){put_c(s);put_c(o+*pp);put_c(s);} pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++!=0){put_c(s);put_c(o+*pp);put_c(s);} pp++; cpx++; cpx++; <br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++!=0){put_c(s);put_c(o+*pp);put_c(s);} pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++!=0){put_c(s);put_c(o+*pp);put_c(s);} pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++!=0){put_c(s);put_c(o+*pp);put_c(s);} pp++; cpx++; cpx++; <br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpy+=2;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; set_put_c_color( 0, 0 );<br /><br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; pp = P;<br />&nbsp;&nbsp;&nbsp; mp = MP;<br />&nbsp;&nbsp;&nbsp; cpy=cp-&gt;y;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; set_put_c_color( _COLOR_BLACK, _COLOR_WHITE );<br />&nbsp;&nbsp;&nbsp; c = 0;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;12;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(c++&gt;=3){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpy++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpx=cp-&gt;x;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx,cpy);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++==0){ if(*pp!=0){put_c(s);put_c(o+*pp);put_c(s);}else{put_c(s);put_c(s);put_c(s);} } pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++==0){ if(*pp!=0){put_c(s);put_c(o+*pp);put_c(s);}else{put_c(s);put_c(s);put_c(s);} } pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++==0){ if(*pp!=0){put_c(s);put_c(o+*pp);put_c(s);}else{put_c(s);put_c(s);put_c(s);} } pp++; cpx++; cpx++;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++==0){ if(*pp!=0){put_c(s);put_c(o+*pp);put_c(s);}else{put_c(s);put_c(s);put_c(s);} } pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++==0){ if(*pp!=0){put_c(s);put_c(o+*pp);put_c(s);}else{put_c(s);put_c(s);put_c(s);} } pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++==0){ if(*pp!=0){put_c(s);put_c(o+*pp);put_c(s);}else{put_c(s);put_c(s);put_c(s);} } pp++; cpx++; cpx++;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++==0){ if(*pp!=0){put_c(s);put_c(o+*pp);put_c(s);}else{put_c(s);put_c(s);put_c(s);} } pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++==0){ if(*pp!=0){put_c(s);put_c(o+*pp);put_c(s);}else{put_c(s);put_c(s);put_c(s);} } pp++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(2*cpx++,cpy);if(*mp++==0){ if(*pp!=0){put_c(s);put_c(o+*pp);put_c(s);}else{put_c(s);put_c(s);put_c(s);} } pp++; cpx++; cpx++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cpy+=2;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; set_put_c_color( 0, 0 );<br />}<br /><br />void swpP(char* P, int a, int b )<br />{<br />&nbsp;&nbsp;&nbsp; register char* ap=P+a;<br />&nbsp;&nbsp;&nbsp; register char* bp=P+b;<br />&nbsp;&nbsp;&nbsp; register char&nbsp; c;<br /><br />&nbsp;&nbsp;&nbsp; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c; ap+=6; bp+=6;<br />&nbsp;&nbsp;&nbsp; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c; ap+=6; bp+=6;<br />&nbsp;&nbsp;&nbsp; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c;<br />}<br /><br />void swpPh(char*P, int la, int lb )<br />{<br />&nbsp;&nbsp;&nbsp; register char* ap=P+9*la;<br />&nbsp;&nbsp;&nbsp; register char* bp=P+9*lb;<br />&nbsp;&nbsp;&nbsp; register char c;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c;<br />&nbsp;&nbsp;&nbsp; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c;<br />&nbsp;&nbsp;&nbsp; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c; c=*ap;*ap++=*bp;*bp++=c;<br />}<br /><br />void swpPv(char*P, int la, int lb )<br />{<br />&nbsp;&nbsp;&nbsp; register char* ap=P+la;<br />&nbsp;&nbsp;&nbsp; register char* bp=P+lb;<br />&nbsp;&nbsp;&nbsp; register char c;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; c=*ap;*ap=*bp;*bp=c; ap+=9;bp+=9; c=*ap;*ap=*bp;*bp=c; ap+=9;bp+=9;&nbsp;&nbsp;&nbsp; c=*ap;*ap=*bp;*bp=c; ap+=9;bp+=9;<br />&nbsp;&nbsp;&nbsp; c=*ap;*ap=*bp;*bp=c; ap+=9;bp+=9; c=*ap;*ap=*bp;*bp=c; ap+=9;bp+=9;&nbsp;&nbsp;&nbsp; c=*ap;*ap=*bp;*bp=c; ap+=9;bp+=9;<br />&nbsp;&nbsp;&nbsp; c=*ap;*ap=*bp;*bp=c; ap+=9;bp+=9; c=*ap;*ap=*bp;*bp=c; ap+=9;bp+=9;&nbsp;&nbsp;&nbsp; c=*ap;*ap=*bp;*bp=c; ap+=9;bp+=9;<br />}<br /><br />void swpPn(char* P, char a, char b )<br />{<br />&nbsp;&nbsp;&nbsp; swpm33n(P+P00,a,b); swpm33n(P+P01,a,b); swpm33n(P+P02,a,b);<br />&nbsp;&nbsp;&nbsp; swpm33n(P+P10,a,b); swpm33n(P+P11,a,b); swpm33n(P+P12,a,b);<br />&nbsp;&nbsp;&nbsp; swpm33n(P+P20,a,b); swpm33n(P+P21,a,b); swpm33n(P+P22,a,b);<br />}<br /><br />void tP(char* P)<br />{<br />&nbsp;&nbsp;&nbsp; tm33(P+P00);tm33(P+P01);tm33(P+P02);<br />&nbsp;&nbsp;&nbsp; tm33(P+P10);tm33(P+P11);tm33(P+P12);<br />&nbsp;&nbsp;&nbsp; tm33(P+P20);tm33(P+P21);tm33(P+P22);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; swpP(P,P00,P02); swpP(P,P20,P22); swpP(P,P00,P22);<br />&nbsp;&nbsp;&nbsp; swpP(P,P01,P12); swpP(P,P10,P21); swpP(P,P01,P21);<br />}<br /><br />void sflP(char* P )<br />{<br />&nbsp;&nbsp;&nbsp; register int i;<br />&nbsp;&nbsp;&nbsp; register int j;<br />&nbsp;&nbsp;&nbsp; register int r;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;27;j++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;3;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; r=rand()%3;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(r){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0: swpPh(P,(i*3)+0,(i*3)+1);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 1: swpPh(P,(i*3)+1,(i*3)+2);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 2: swpPh(P,(i*3)+2,(i*3)+0);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; r=rand()%3;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(r){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0: swpPv(P,(i*3)+0,(i*3)+1);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 1: swpPv(P,(i*3)+1,(i*3)+2);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 2: swpPv(P,(i*3)+2,(i*3)+0);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; r=rand()%3;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(r){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0: swpP(P,P00,P10); swpP(P,P01,P11); swpP(P,P02,P12);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 1: swpP(P,P10,P20); swpP(P,P11,P21); swpP(P,P12,P22);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 2: swpP(P,P20,P00); swpP(P,P21,P01); swpP(P,P22,P02);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; r=rand()%3;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(r){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0: swpP(P,P00,P01); swpP(P,P10,P11); swpP(P,P20,P21);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 1: swpP(P,P01,P02); swpP(P,P11,P12); swpP(P,P21,P22);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 2: swpP(P,P02,P00); swpP(P,P12,P10); swpP(P,P22,P20);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; swpPn(P,(rand()%9)+1,(rand()%9)+1);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; r=rand()%2;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(r) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0: tP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void genMP(int lv)<br />{<br />&nbsp;&nbsp;&nbsp; if(lv&lt; 0){lv=1;}<br />&nbsp;&nbsp;&nbsp; if(lv&gt;=9){lv=8;}<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; int s,i,l;<br />&nbsp;&nbsp;&nbsp; register unsigned char* cbp=BP;<br />&nbsp;&nbsp;&nbsp; register unsigned char* cup=UNITP;<br />&nbsp;&nbsp;&nbsp; register unsigned char* cmp=MP;<br />&nbsp;&nbsp;&nbsp; for(l=0;l&lt;1+8*2-lv*2;l++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cbp=BP;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cup=UNITP;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;81;i++){*cbp++ = *cup++;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(s=0;s&lt;27;s++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; swpPv(BP,rand()%9,rand()%9);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cbp=BP;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cmp=MP;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;81;i++){*cmp++ |= *cbp++;}<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void genP(char* P, int lv)<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; register unsigned char* pp = P;<br />&nbsp;&nbsp;&nbsp; register unsigned char* dp = defPseed;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;82;i++){*pp++ = *dp++;}<br />&nbsp;&nbsp;&nbsp; sflP(P);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; genMP(lv);<br />&nbsp;&nbsp;&nbsp; register unsigned char* mp = MP;<br />&nbsp;&nbsp;&nbsp; pp = P;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;82;i++){*pp++ &amp;= *mp++;}<br />}<br /><br />void snP(char* P, POS* cp, unsigned char n)<br />{<br />&nbsp;&nbsp;&nbsp; P[cp-&gt;y*9+cp-&gt;x]=n;<br />}<br /><br />void siP(char* P, POS* cp )<br />{<br />&nbsp;&nbsp;&nbsp; if(MP[9*cp-&gt;y+cp-&gt;x]==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned char* ap = &amp;(P[cp-&gt;y*9+cp-&gt;x]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(*ap&lt;=9-1){(*ap)++;}<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void sdP(char* P, POS* cp )<br />{<br />&nbsp;&nbsp;&nbsp; if(MP[9*cp-&gt;y+cp-&gt;x]==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned char* ap = &amp;(P[cp-&gt;y*9+cp-&gt;x]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(*ap&gt;=0+1){(*ap)--;}&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br /><br /><br /><br /><br />typedef struct tagUNDOP{<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ci;<br />&nbsp;&nbsp;&nbsp; unsigned char &nbsp;&nbsp;&nbsp; P[0x4FFFF];<br />}UNDOP;<br />static UNDOP _up={0};<br />void wUP( unsigned char* P )<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; register unsigned char* cup = &amp;(_up.P[_up.ci*81]); <br />&nbsp;&nbsp;&nbsp; register unsigned char* p&nbsp;&nbsp; = P; <br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;81;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp; *cup++ = *p++;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; _up.ci++;<br />}<br />void rUP( unsigned char* P, int sk )<br />{<br />&nbsp;&nbsp;&nbsp; if(sk&gt;=0){return;}<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; int csk = _up.ci+sk;<br />&nbsp;&nbsp;&nbsp; if(csk&lt;0) {return;}<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; register unsigned char* cup = &amp;(_up.P[csk*81]);<br />&nbsp;&nbsp;&nbsp; register unsigned char* p&nbsp;&nbsp; = P;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;81;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *p++ = *cup++;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; wUP(P);<br />}<br /><br /><br /><br />void mvcp(POS* cp, int tx, int ty)<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char nx=cp-&gt;x+tx;<br />&nbsp;&nbsp;&nbsp; unsigned char ny=cp-&gt;y+ty;<br />&nbsp;&nbsp;&nbsp; if(nx&gt;=9||nx&lt;0){;}else{cp-&gt;x=nx;}<br />&nbsp;&nbsp;&nbsp; if(ny&gt;=9||ny&lt;0){;}else{cp-&gt;y=ny;}<br />}<br /><br /><br />static POS Scp;<br />void pScp(void)<br />{ <br />&nbsp;&nbsp;&nbsp; const unsigned char hl=' ';<br />&nbsp;&nbsp;&nbsp; const unsigned char vl=' ';<br />&nbsp;&nbsp;&nbsp; register POS* cp = &amp;Scp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; set_put_c_color(_COLOR_YELLO,_COLOR_YELLO);<br /><br />&nbsp;&nbsp;&nbsp; int cpx=cp-&gt;x-1; int cpy=cp-&gt;y-1;<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br /><br />&nbsp;&nbsp;&nbsp; cpx=cp-&gt;x-1; cpy++; set_cur(cpx, cpy);put_c(vl); cpx+=4; set_cur(cpx, cpy);set_cur(cpx, cpy);put_c(vl);<br /><br />&nbsp;&nbsp;&nbsp; cpx=cp-&gt;x-1; cpy=cp-&gt;y+1;<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br /><br />&nbsp;&nbsp;&nbsp; set_put_c_color(0,0);<br />}<br />void clrScp(void)<br />{ <br />&nbsp;&nbsp;&nbsp; const unsigned char hl=' ';<br />&nbsp;&nbsp;&nbsp; const unsigned char vl=' ';<br />&nbsp;&nbsp;&nbsp; register POS* cp = &amp;Scp;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; set_put_c_color(0,0);<br /><br />&nbsp;&nbsp;&nbsp; int cpx=cp-&gt;x-1; int cpy=cp-&gt;y-1;<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br /><br />&nbsp;&nbsp;&nbsp; cpx=cp-&gt;x-1; cpy++; set_cur(cpx, cpy);put_c(vl); cpx+=4; set_cur(cpx, cpy);set_cur(cpx, cpy);put_c(vl);<br /><br />&nbsp;&nbsp;&nbsp; cpx=cp-&gt;x-1; cpy=cp-&gt;y+1;<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br />&nbsp;&nbsp;&nbsp; set_cur(cpx++, cpy);put_c(hl);<br /><br />&nbsp;&nbsp;&nbsp; set_put_c_color(0,0);<br />}<br /><br /><br /><br /><br />#ifdef __OSASK__<br />int G01Main()<br />#else<br />int main()<br />#endif //__OSASK__<br />{<br />//&nbsp; put_c(0x82);<br />//&nbsp; put_c(0x4F);<br />//&nbsp; get_c();return 0;<br />&nbsp; <br />&nbsp;&nbsp;&nbsp; unsigned char P[82];<br />&nbsp;&nbsp;&nbsp; POS Pcp={10, 1};<br />&nbsp;&nbsp;&nbsp; POS cp={0.0};<br />&nbsp;&nbsp;&nbsp; unsigned char ky;<br />&nbsp;&nbsp;&nbsp; int e=0;<br />&nbsp;&nbsp;&nbsp; int u=0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; init_sys();<br />&nbsp;&nbsp;&nbsp; clr_scr();<br /><br />&nbsp;&nbsp;&nbsp; genP(P,1);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; do{<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; clrScp();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Scp.x=2*(Pcp.x+(cp.x/3)*7+(cp.x%3)*2);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Scp.y=(Pcp.y+((cp.y/3)*6)+((cp.y%3)*2)+(cp.y/3));<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pP(P,&amp;Pcp);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pScp();<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set_cur(Scp.x, Scp.y);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ky=get_c();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(ky){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'j': case 'J': case 's': case 'S': mvcp(&amp;cp,-1,0); set_cur(cp.x,cp.y);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'l': case 'L': case 'f': case 'F': mvcp(&amp;cp,+1,0); set_cur(cp.x,cp.y);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'i': case 'I': case 'e': case 'E': mvcp(&amp;cp,0,-1); set_cur(cp.x,cp.y);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'k': case 'K': case 'd': case 'D': mvcp(&amp;cp,0,+1); set_cur(cp.x,cp.y);break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'u': case 'U': case 't': case 'T': u++; break;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '0': snP(P,&amp;cp,0); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '1': snP(P,&amp;cp,1); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '2': snP(P,&amp;cp,2); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '3': snP(P,&amp;cp,3); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '4': snP(P,&amp;cp,4); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '5': snP(P,&amp;cp,5); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '6': snP(P,&amp;cp,6); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '7': snP(P,&amp;cp,7); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '8': snP(P,&amp;cp,8); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '9': snP(P,&amp;cp,9); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'h': case 'H': case 'g': case 'G':&nbsp;&nbsp;&nbsp; case ' ':&nbsp;&nbsp;&nbsp; siP(P,&amp;cp); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'n': case 'N': case 'v': case 'V':&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sdP(P,&amp;cp); wUP(P); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(ky){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'u': case 'U': case 't': case 'T': if(u&gt;0){rUP(P,-(u*2-1));} put_c('A');continue; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default: u=0; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(ky){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'q': case 'Q': e++; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default: e = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; } while(e&lt;3);<br /><br />&nbsp;&nbsp;&nbsp; close_sys();<br />&nbsp;&nbsp;&nbsp; return(0);<br />}</td></tr></tbody></table><br /><br /><br /><br /><br /><br /><br /> ]]>
</content:encoded>
<dc:subject>OSASK関係</dc:subject>
<dc:date>2009-12-20T23:13:58+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-49.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-49.html</link>
<title>Chromium OS のコンパイル方法</title>
<description> Chromium OS のコンパイル方法まずソースコードを入手します。そのためには git と、 Subversion というツールが必要なので、インストールしておきます。sudo apt-get install git-coresudo apt-get install subversion次に、コンパイルのためのツールをダウンロードしますhttp://src.chromium.org/svn/trunk/tools/depot_tools.tar.gzこれを解凍して、できあがったフォルダ depot_tools をホームディレクトリに置きます。ちなみに
 </description>
<content:encoded>
<![CDATA[ Chromium OS のコンパイル方法<br /><br /><a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/chromiumos_op.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/chromiumos_op.jpg" alt="chromiumos_op.jpg" border="0" width="718" height="609" /></a><br /><br /><br /><br />まずソースコードを入手します。<br /><br /><br /><br /><git と subbersion のインストール><br />そのためには git と、 Subversion というツールが必要なので、インストールしておきます。<br /><br />sudo apt-get install git-core<br />sudo apt-get install subversion<br /><br /><br /><br /><br /><depot_toolsの入手><br />次に、コンパイルのためのツールをダウンロードします<br />http://src.chromium.org/svn/trunk/tools/depot_tools.tar.gz<br /><br />これを解凍して、できあがったフォルダ depot_tools をホームディレクトリに置きます。<br />ちなみに、ホームディレクトリってのは、<br />cd $HOME<br />としたときの移動先のことです。普通は /home/ユーザー名/ のフォルダを指し示します。<br /><br /><br /><br /><depot_toolsの初期設定><br />bash にdepot_toolsの場所（パス）を追加設定します。<br />まず、ホームディレクトリに、普段は隠し表示に設定されてるファイルで<br />.bashrc<br />というテキストファイルがあります。　このテキストファイルに設定を追加して書きます。<br /><br />.bashrc をメモ帳で開いて、最後の以降に、以下の文字列をコピペしてください。<br />（このまま張り付けるだけです。）<br /><br />export PATH=`pwd`/depot_tools:"$PATH"<br /><br /><br /><br /><gitを使って、Chromium OS のソースファイルをダウンロードします><br />まず、ホームディレクトリ上に、ダウンロードするためのディレクトリを作ります。<br /><br />ホームディレクトリってのは cd $HOME とした時の移動先のことです。<br /><br />cd $HOME<br />mkdir chromiumos<br /><br />つぎに git でダウンロードします。<br />まず、さっき作成したディレクトリ chromiumos に移動します。<br /><br />cd chromiumos<br /><br />つぎに、chromiumos ディレクトリに、ソースファイルのあるURLを登録します。（リポジトリを得る）<br /><br />gclient config http://src.chromium.org/git/chromiuos.git<br /><br />（すでにリポジトリが設定されてた場合は、『もうありますよ』というエラーが表示されます。問題ありません）<br /><br />つぎに、リポジトリの同期をとります。（ダウンロード時間は３０分～１時間くらい）<br /><br />gclient sync<br /><br />これであとは１時間ほど待ってればソースファイルがダウンロードされてるはずです。<br />（一見、止まってるかのように見えますが、さわらないで待っててください）<br /><br /><br /><br /><コンパイルのための設定><br />ソースがダウンロードできたら、次はコンパイルですが、その前にシステムの設定をします。<br /><br />まず、リンクを設定します。（なんで必要なのかよくわかりませんが...）<br />ln -s /usr/local/chromiumos/chromiumos.git ~/chromiumos<br />ln -s /usr/local/chromium/trunk ~/chromium<br /><br />スクリプトのあるディレクトリに移動します<br />cd ~/chromiumos/chromiumos.git/src/scripts<br /><br />ローカルレポジトリを作成します（３０分くらい）<br />./make_local_repo.sh<br /><br />ビルドに必要なファイルを用意します（３０分くらい）<br />./make_chroot.sh<br />または<br />./make_chroot.sh --mirror=http://build.chromium.org/buildbot/packages --suite=chromeos_dev<br /><br /><br /><br /><コンパイル><br />作業場所をマウントします<br />./build_chrome.sh --chrome_dir ~/chromium<br />./enter_chroot.sh<br /><br /><br /><br />OSにバックドアを設定します（設定しなくてもいいですが、設定した方が便利です）<br /><br />バックドアのユーザー名を設定します。<br />以下の文字列の USERNAME のところを、適当な文字に書き換えて入力してください。<br />( cd ../platform/pam_google && ./enable_localaccount.sh USERNAME )<br /><br />バックドアのパスワードを設定します<br />./set_shared_user_password.sh<br />設定したいパスワードを聞かれるので、なにか考えて入力してください。<br /><br /><br /><br />カーネルをコンパイルします（３０分くらい）<br />./build_platform_packages.sh<br />./build_kernel.sh<br /><br /><br /><br />コンパイル結果をイメージファイルにまとめます<br />./build_image.sh<br /><br />コンソールを閉じて終了します。<br /><br /><br />これでとりあえず完成です。<br /><br /><br /><br /><仮想マシンへのインストール><br />本当はUSBメモリにインストールして、ネットブックという特殊なノートパソコンで、実機で動作確認するのが速度的にベストなんですが、<br />当方、そんな高価な機械は持ってないんで、仮想マシンで動作確認することにします。<br />仮想マシンには VirtualBox というオープンソースのソフトを使います。<br />あと、イメージデータの変換のためにQemu というツールも必要です。これもオープンソースです。<br /><br />VirtualBox と Qemu のインストール<br />sudo apt-get install virtualbox-ose<br />sudo apt-get install qemu <br /><br /><br /><br />イメージファイルの内容を編集したい場合は、イメージファイルをマウントして行います。<br />まずイメージファイルのあるディレクトリに移動します。<br />以下の文字列の、SUBDIR のところを実際のディレクトリ名に書き換えて入力してください。（おそらくビルドバージョン毎に名前が異なるとおもいます。）<br />ちなみに私は今回は cd ~/chromiumos/chromiumos.git/src/build/images/0.5.25.0-a1 でした。<br /><br />cd ~/chromiumos/chromiumos.git/src/build/images/SUBDIR<br /><br />そしてマウントします<br />sudo mount -o loop rootfs.image rootfs<br /><br />デスクトップにハードディスクのアイコンが表示されます。この中身を好きに書き換えてもOKです。<br />ディレクトリ構成はみるからに、あきらかにunixですw。　/bin/ には普通に vi などのアプリケーションが用意されてます。<br />python や perl のインタープリタも用意されてるみたいです。カーネルはlinuxの2.6.31が入ってますね。<br />多言語入力は iBus が用意されてるので、コンソールでsetupすれば日本語入力も使えるようになります。<br /><br /><span style="color:#CC0000">追記：</span><br />キーボードを日本語配置に設定する方法<br />まず、マウントしたイメージ rootfs がマウントイメージとしてデスクトップに表示されるので、それを開き、<br />/etc/X11/ に移動し、<br />xorg.conf というファイルを管理者権限で開きます。<br />その中の以下の構造体<br /><br />Section "InputDevice"<br />    Identifier "Keyboard1"<br />    Driver     "kbd"<br />    Option     "AutoRepeat" "250 30"<br />    Option     "XkbRules"   "xorg"<br />    Option     "XkbModel"   "pc104"<br />    Option     "CoreKeyboard"<br />EndSection<br /><br />に<br />    Option     "XkbLayout"  "jp"<br />というメンバを追加します。つまり以下のように書き変えます。<br /><br />Section "InputDevice"<br />    Identifier "Keyboard1"<br />    Driver     "kbd"<br />    Option     "AutoRepeat" "250 30"<br />    Option     "XkbRules"   "xorg"<br />    Option     "XkbModel"   "pc104"<br />    Option     "XkbLayout"  "jp"<br />    Option     "CoreKeyboard"<br />EndSection<br /><br />これでキーボードの配置が日本語配置になります。（@とかも、ちゃんと打てるようになりますw）<br /><br /><br /><br /><仮想マシン用にイメージファイルを変換><br />VirtualBoxで読み込むために、イメージファイルの形式を変換します。（VMWare形式に変換します）<br /><br />まず、script ディレクトリに移動します。<br />cd /$HOME/chromiumos/chromiumos.git/src/scripts/<br /><br />以下の文字列を入力します。<br />SUBDIR はさっきと同じです。実際のディレクトリ名に書き換えて入力してください。<br />ちなみに私は今回は 0.5.25.0-a1 なので、 <br />image_to_virtualbox.sh --from=~/chromiumos/chromiumos.git/src/build/images/0.5.25.0-a1 --to=~/chromiumos/chromiumos.git/src/build/images/0.5.25.0-a1/os.vdi でした。<br /><br />./image_to_virtualbox.sh --from=~/chromiumos/src/build/images/SUBDIR --to=~/chromiumos/src/build/images/SUBDIR/os.vdi<br /><br /><br /><VirtualBoxでChromiumOSを起動する><br />まずVirtualBoxを起動します。<br />virtualbox<br /><br />メニューから<br />ファイル　→　仮想メディアマネージャー<br />を選択します。<br /><br />『追加』を押します。<br /><br />さっき作った ChromiumOS のイメージファイルの場所へ移動して、 ide.vmdk というファイルを選択します。<br />ちなみにさっきの場所は /$HOME/chromiumos/chromiumos.git/src/build/images/SUBDIR/ でしたよね。<br /><br />これで、仮想ハードディスクが一覧に登録されました。<br /><br />つぎに仮想マシンを設定します。<br />メインウインドウの　『新規』　と書いてあるボタンを押します。質問に答えて行きます。<br />名前は適当でいいです。<br />オペレーティングシステムのタイプは Linux にします。<br />バージョンは Linux2.6 です<br /><br />メモリは１Gもあれば充分です。<br /><br />機動ディスクです。<br />既存のハードディスクを使用です。一覧から、さっき登録した os.vdi を選択します。<br /><br />これで仮想マシンが作られ、一覧に登録されました。<br />これをダブルクリックすれば仮想マシンが起動して、 Chromium OS が仮想マシン上で動きます。<br /><br /><br /><br /><Chromium OSへのログイン><br />gmail のアカウントを持ってる人は、gmail の『本物のアカウント』でログインできます。　本当はこの方法が正式。また、安定してます。<br />さっきのコンパイルの時に作ったバックドアでもログインできます。ただしこちらは不安定です。<br /><br />あと、VirtualBoxの基本操作ですが、『右側のCtrlキー』を押すと、マウスカーソルが仮想マシンから戻ってきます。これ重要w<br /><br /><br /><br />ChromiumOSで日本語を入力できるように設定する<br /><br />デフォルトでは日本語入力ができませんが、ChromiumOSのコンソールで Linux のコマンドを打てば、iBus という多言語入力ツールの設定ができます。<br />これによって Anthy 日本語入力が使えるようになります。<br />まず、コンソール画面を表示します。<br /><br />Alt + Ctrl + t<br /><br />そして<br />cd /usr/bin/<br />に移動して<br />ibus-setup<br />を実行します。<br /><br />Input Method タグへ移動し、Select an input method 一覧から Japanise -> Anthy を選択し Add ボタンを押します。<br />これで日本語入力ができるように設定できました。<br /><br />テキストボックスなどで入力する際に、<br />キーボードの『半角/全角』キーで、入力モードを切り替えられるようになります。<br /><br /><br /><br />ファイルの操作について<br /><br />Ctrl + o <br /><br />で、ファイルマネージャーが起動します。<br />また、コンソールで Linux のコマンドが普通に使えるので、 cp や rm などのコマンドでファイル操作することも可能です。<br /><br /><br /><br />コンソールを見た感じだと、/bin/ や /usr/bin/ などに一通りのツールが用意されてるので、linuxの端末としても普通に使えると思います。<br />python や perl が用意されてます。もちろん普通に動きます。　テキストエディタには vi が用意されてます。　いたれりつくせりですね。<br /><br />試してませんが、おそらく 第二世代OSASKも、このコンソール上で普通に動きそうな気がします。  <br />けっこういろいろ遊べそうで楽しそうです。おもにコンソールがw　（そっちかい！！<br /><br /><br /><br />ウインドウの切り替え<br />F12<br /><br />一覧表示になるのでマウスで選択します。カーソルキーでも選択できます。<br /><br /><br /><br />終了方法について<br />よくわからないですが、おそらく ACPIシャットダウンでOKだとおもいます。ようするに電源ボタン直押しです。<br />ACPIシャットダウンじゃなくて、突発的なシャットダウンだとダメみたいです。　だから、必然的にインストールできるPCの種類が限定されてきますね。<br /><br /><br /><br /> ]]>
</content:encoded>
<dc:subject>メモ</dc:subject>
<dc:date>2009-12-15T00:24:42+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-48.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-48.html</link>
<title>search.c (0.0.1)</title>
<description> とりあえず組んでみました。任意の検索文字列（今回は　[(123)4]?5　）を、順序木によってツリー構造に変換してます。インデントがノードの深さを意味します。 NODE[0x????]は、直上のノードのユニーク値です。（実際はポインタ）直上がNODE[0x0]のノードは、ルートを意味してます。次に文字列 TEXT 中から、 [(123)4]?5 に一致する単語を検索し、一致した結果を表示してます。[ ] は、この中での　いずれか１文字　を意味し、( ) 
 </description>
<content:encoded>
<![CDATA[ とりあえず組んでみました。<br /><br />任意の検索文字列（今回は　[(123)4]?5　）を、順序木によってツリー構造に変換してます。<br />インデントがノードの深さを意味します。 NODE[0x????]は、直上のノードのユニーク値です。（実際はポインタ）<br />直上がNODE[0x0]のノードは、ルートを意味してます。<br /><br />次に文字列 TEXT 中から、 [(123)4]?5 に一致する単語を検索し、一致した結果を表示してます。<br />[ ] は、この中での　いずれか１文字　を意味し、<br />( ) は、この中の　文字列を１文字として扱う　を意味し、<br />? は、直前の１文字の ０ ～ ２ 回の繰り返しを意味します。　（０～１じゃなくて、０～２です、　＊を組む時の練習しましたw）<br /><br />ちなみに、 [(123)4]?5 が意味する単語は<br />1235<br />45<br />12345<br />41235<br />1231235<br />445<br />5<br />のいずれかですね。<br />TEXT中から、この単語を検索する形になります。<br /><br /><a target="_blank" href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/search001test.png"><img border="0" width="578" height="674" alt="search001test.png" src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/search001test.png" /></a> <br />あ、NODE[875C008]がかぶってますね&hellip;<br />ソース見たら、ins_NODE() 関数の定義の最後に nn-&gt;d[0]-&gt;u =　nn; の式が必要な気がしました&hellip;単純に書き忘れてた。w<br />たぶんそれで治ると思います。（まだ試してないのでわかりませんが&hellip;w） <br /><br />一応ソースです。<br />コンパイル方法はいつもどうりです。Linuxで gcc -o s search.c -lc です。 <br />この場合、コンパイル結果の s が実行ファイルです。　./s と入力すれば実行できます。<br />（ s じゃなくて任意の名前でも当然OKです）<br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>search.c (0.0.1)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br /><br /><br />#define d_len_max 0xFF<br />typedef struct tagNODE {<br />&nbsp;&nbsp;&nbsp; struct tagNODE* u;<br />&nbsp;&nbsp;&nbsp; struct tagNODE* d[d_len_max];<br />&nbsp;&nbsp;&nbsp; int cur_dnode;<br />&nbsp;&nbsp;&nbsp; char c;<br />} _NODE;<br /><br />_NODE* new_NODE( void )<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; _NODE* n = (_NODE*)malloc(sizeof(_NODE));<br />&nbsp;&nbsp;&nbsp; n-&gt;cur_dnode = -1;<br />&nbsp;&nbsp;&nbsp; n-&gt;u = 0;<br />&nbsp;&nbsp;&nbsp; for(i=0; i&lt; d_len_max ;i++){ n-&gt;d[i] = 0; }<br />&nbsp;&nbsp;&nbsp; n-&gt;c = 0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return( n );<br />}<br /><br />void add_NODE( _NODE* n )<br />{<br />&nbsp;&nbsp;&nbsp; n-&gt;cur_dnode++;<br />&nbsp;&nbsp;&nbsp; n-&gt;d[n-&gt;cur_dnode] = new_NODE();<br />&nbsp;&nbsp;&nbsp; n-&gt;d[n-&gt;cur_dnode]-&gt;u = n;<br />}<br /><br />void ins_NODE( _NODE* n )<br />{<br />&nbsp;&nbsp;&nbsp; _NODE* nn = new_NODE();<br />&nbsp;&nbsp;&nbsp; nn-&gt;cur_dnode=0;<br />&nbsp;&nbsp;&nbsp; nn-&gt;u = n;<br />&nbsp;&nbsp;&nbsp; nn-&gt;d[0] = n-&gt;d[n-&gt;cur_dnode];<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; n-&gt;d[n-&gt;cur_dnode] = nn;<br />}<br /><br />int trans_str2NODE( _NODE* n, char* str )<br />{<br />&nbsp;&nbsp;&nbsp; int len = strlen(str);<br />//printf(&quot;strlen=%d\n&quot;,len);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if( len&lt;=0 ){<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char c = str[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch( c ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '[':<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; add_NODE( n );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; n-&gt;d[n-&gt;cur_dnode]-&gt;c = c;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; trans_str2NODE( n-&gt;d[n-&gt;cur_dnode], (str+1) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case ']':<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; trans_str2NODE( n-&gt;u, (str+1) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '(':<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; add_NODE( n );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; n-&gt;d[n-&gt;cur_dnode]-&gt;c = c;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; trans_str2NODE( n-&gt;d[n-&gt;cur_dnode], (str+1) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case ')':<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; trans_str2NODE( n-&gt;u, (str+1) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '?':<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ins_NODE( n );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; n-&gt;d[n-&gt;cur_dnode]-&gt;c = c;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; trans_str2NODE( n, (str+1) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; add_NODE( n );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; n-&gt;d[n-&gt;cur_dnode]-&gt;c = c;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; trans_str2NODE( n, (str+1) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void print_NODE( _NODE* n, int depth )<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; char space[0xFF]; for( i = 0; i &lt; depth; i++ ) { space[i] = '\t'; } space[depth] = '\0';<br />&nbsp;&nbsp;&nbsp; printf(&quot;%sNODE[0x%x] char=%c int=%d\n&quot;, space, (int)(n-&gt;u), n-&gt;c, (int)(n-&gt;c) );<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(i=0; i&lt;=n-&gt;cur_dnode; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print_NODE( n-&gt;d[i], depth+1 );<br />&nbsp;&nbsp;&nbsp; }<br />}<br />void print_TREE( _NODE* r )<br />{<br />&nbsp;&nbsp;&nbsp; print_NODE( r, 0 );<br />}<br /><br />char dst[0xFFFF];<br />int&nbsp; cur_dst;<br /><br />int search_at_NODE( _NODE* n, char* str, int* index )<br />{<br />&nbsp;&nbsp;&nbsp; int len = strlen(str);<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; int ret=0;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if(len &lt;= *index){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(0);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch( n-&gt;c ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret = 1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0; i&lt;=n-&gt;cur_dnode; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret &amp;= search_at_NODE( n-&gt;d[i], str, index );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( ret );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '[':<br />//printf(&quot;[\n&quot;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0; i&lt;=n-&gt;cur_dnode; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret |= search_at_NODE( n-&gt;d[i], str, index );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(ret!=0){break;}<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( ret );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '(':<br />//printf(&quot;(\n&quot;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret = 1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int old_index = *index;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0; i&lt;=n-&gt;cur_dnode; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( *index &gt;= len ) { ret=0; break; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret &amp;= search_at_NODE( n-&gt;d[i], str, index );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(ret==0){ *index = old_index; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( ret );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '?':<br />//printf(&quot;?\n&quot;);<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret = search_at_NODE( n-&gt;d[0], str, index );<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(ret); <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret = 1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int ret_buf;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0; i&lt;2; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int old_index = *index;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret_buf = search_at_NODE( n-&gt;d[0], str, index );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(ret_buf==0){ *index = old_index; return(ret); }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret=ret_buf;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(ret);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default:<br />printf(&quot;%c=%c &quot;,n-&gt;c, str[*index]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( n-&gt;c == str[*index] ) {<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch( n-&gt;u-&gt;c ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '[':&nbsp;&nbsp;&nbsp; dst[cur_dst] = n-&gt;c; &nbsp;&nbsp;&nbsp; cur_dst++;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '(':&nbsp;&nbsp;&nbsp; dst[cur_dst] = n-&gt;c;&nbsp;&nbsp;&nbsp; cur_dst++;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case '?':&nbsp;&nbsp;&nbsp; dst[cur_dst] = n-&gt;c;&nbsp;&nbsp;&nbsp; cur_dst++;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0&nbsp; :&nbsp;&nbsp;&nbsp; dst[cur_dst] = n-&gt;c;&nbsp;&nbsp;&nbsp; cur_dst++;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (*index)++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(1);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(0);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void search_at_TREE( _NODE* r, char* str )<br />{<br />&nbsp;&nbsp;&nbsp; int ret;<br />&nbsp;&nbsp;&nbsp; int index = 0;<br />&nbsp;&nbsp;&nbsp; int len = strlen(str);<br />&nbsp;&nbsp;&nbsp; while(len&gt;index){<br />printf(&quot;\n&quot;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;0xFFFF;i++) {dst[i]=0;} cur_dst=0;<br /><br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;ret=%d : [%s]\n&quot;, search_at_NODE( r, str, &amp;index ), dst );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret = search_at_NODE( r, str, &amp;index );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(ret==1){;}else{ index++; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(ret==1){printf(&quot;match [%s]&quot;, &amp;dst[0] );}<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />int main()<br />{<br />printf(&quot;\n&quot;);<br />printf(&quot;search.cpp testVersion0.0.1\n&quot;);<br />printf(&quot;\n&quot;);<br />printf(&quot;\n&quot;);<br />&nbsp; <br />&nbsp;&nbsp;&nbsp; _NODE* r = new_NODE();<br />//&nbsp;&nbsp;&nbsp; char str[0xFFFF] = &quot;[(AB)C]DE&quot;;<br />&nbsp;&nbsp;&nbsp; char str[0xFFFF] = &quot;[(123)4]?5&quot;;<br />//&nbsp;&nbsp;&nbsp; char text[0xFFFF] = &quot;_ABD_ABDE_CD_CDE_ABCDE_&quot;;<br />&nbsp;&nbsp;&nbsp; char text[0xFFFF] = &quot;__1235__45__12345__1231235__445__5__&quot;;<br /><br />printf(&quot;TREE view\n\n&quot;);<br />&nbsp;&nbsp;&nbsp; trans_str2NODE( r, str );<br />&nbsp;&nbsp;&nbsp; print_TREE( r );<br /><br />printf(&quot;SEARCH\n\n&quot;);<br />&nbsp;&nbsp;&nbsp; printf(&quot;TEXT = %s : SEARCH = %s\n&quot;, text, str );<br />&nbsp;&nbsp;&nbsp; search_at_TREE( r, text );<br /><br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; putchar('\n');<br />&nbsp;&nbsp;&nbsp; return(0);<br />}<br /><br /></td></tr></tbody></table><br /> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-12-13T02:01:58+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-47.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-47.html</link>
<title>linux カーネル 2.6.32 がリリースされたそうなので...</title>
<description> さっそくソースをダウンロードしてコンパイルしてみた。なんか意外と簡単なのね…カーネルコンパイルって、もっとツマヅキまくりで難しいのかと思ってたわ。
 </description>
<content:encoded>
<![CDATA[ さっそくソースをダウンロードしてコンパイルしてみた。<br /><a target="_blank" href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/linux2_6_32.jpg"><img border="0" width="687" height="507" alt="" src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/linux2_6_32.jpg" /></a><br /><br />なんか意外と簡単なのね…<br />カーネルコンパイルって、もっとツマヅキまくりで難しいのかと思ってたわ。 ]]>
</content:encoded>
<dc:subject>メモ</dc:subject>
<dc:date>2009-12-12T00:35:19+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-46.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-46.html</link>
<title>class _TREE および class _NODE によって順序木構造を書けば可能かもしれない</title>
<description> 文字列検索の際の記述方法の一つとして正規表現がある。正規表現を実現するにはどういうアルゴリズムが必要だろうか？　と、興味の矛先が向いたので考えてます。正式な正規表現とは違うけど、簡易的なルールを決めて、それを実現する方法をとりあえず考えてみようと思う。簡易ルール. は任意の一文字をあらわす。? は、その手前の１文字の0回or1回の繰り返しをあらわす。（例： xA? なら、 x か xA の意味）[ ] によって囲まれた各
 </description>
<content:encoded>
<![CDATA[ 文字列検索の際の記述方法の一つとして正規表現がある。<br />正規表現を実現するにはどういうアルゴリズムが必要だろうか？　と、興味の矛先が向いたので考えてます。<br /><br />正式な正規表現とは違うけど、簡易的なルールを決めて、それを実現する方法をとりあえず考えてみようと思う。<br /><br />簡易ルール<br /><ul><li>. は任意の一文字をあらわす。</li><li>? は、その手前の１文字の0回or1回の繰り返しをあらわす。（例： xA? なら、 x か xA の意味）</li><li>[ ] によって囲まれた各文字のいずれか１文字に一致することをあらわす。（例： [ABC]X なら、 AX か BX か CX の意味）</li><li>( ) によって囲まれた文字列は、１文字として解釈する。（例： x(ABC)? は、x か xABC の意味）<br /></li></ul>というルールによって、任意の文字列から（文字配列）から一致を検索するには、どういうアルゴリズムで可能だろうか？<br /><br />とりあえず、詳細は抜きに、大まかな枠組みとしては、まずパーサーが必要になるのはとうぜんとして、<br />そのパーサーによって分割された命令群をどう実行するか？並べるか？を考えたら、おそらく木構造が適してるのではないだろうか&hellip;？と。<br /><br />たとえば以下のような検索文字列があったとする。<br /><br />[(AB)C]?DE<br /><br />ルールを当てはめて解釈すると、これが意味する文字列は<br /><ul><li>DE</li><li>ABDE</li><li>CDE</li></ul>のいずれかになるけど、これをはたして、どうやってコンピューターに理解させるか？そして実行させるか。<br /><br />まず、 [(AB)C]?DE の最初の [ をルートから、最初のノードに登録する。（注：順序のある木です）<br />つぎに、このノード『 [ 』の、最初のノードに ( を登録する。<br />つぎに、『 ( 』のノードの、最初のノードに A、次のノードに B を登録する。<br />つぎに、 ) が現れたので、『 ( 』のノードの親ノードまで戻る。　親ノードは『 [ 』<br />つぎに、『 [ 』のノードの２番目に C を登録する。<br />つぎに、 ] が現れたので、『 [ 』のノードの親ノードまで戻る。　親ノードはルート。<br />つぎに、ルートの２番目に D、３番目に E を登録する。<br />以上。<br /><br />これによって、以下のような木構造のグラフが完成する。<br /><br /><table cellspacing="0" cellpadding="0" border="0" align="" width="" summary=""><tbody><tr><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5"><span style="background-color: rgb(0, 255, 0);">&radic;</span></font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td></tr><tr><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">／</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">＼</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">＼</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td></tr><tr><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5"><span style="background-color: rgb(255, 102, 0);">[</span></font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(51, 204, 204);"><font size="5">D</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(51, 204, 204);"><font size="5">E</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td></tr><tr><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">|</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">＼</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td></tr><tr><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 102, 0);"><font size="5">(</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5"><span style="background-color: rgb(51, 204, 204);">C</span></font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td></tr><tr><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">／</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">＼</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td></tr><tr><td style="background-color: rgb(255, 255, 153);"><font size="5"><span style="background-color: rgb(51, 204, 204);">A</span></font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(51, 204, 204);"><font size="5">B</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td></tr><tr><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td><td style="background-color: rgb(255, 255, 153);"><font size="5">&nbsp;</font></td></tr></tbody></table><br />さて、グラフは作れたものの、これをどうやってコンピューターに解釈させるか？という問題。<br />各ノードに関数を持たせて、各ノードは自分の関数を実行する責任だけを考えるようにしてみてはどうか？と思った。<br /><br />つまり、例えば　『 [ 』のノードは、自分の子ノード群から上がってくる『一致した』という信号のみを解釈する。そして、その結果を OR演算によって親ノード（今回の例ではルート）に返す。これのみ。<br /><br />同様に、『 ( 』のノードは、自分の子ノード群から上がってくる『一致した』という信号を受け取ることだけを考えて動作すれば良い。そして、その結果をAND演算によって親ノード（今回の例では『 [ 』）に返す。これのみ。<br /><br />特殊記号では無い、単純な１文字（ABCDE）の場合は、リーフである。（ノードを持たない）<br />実際に文字列に対して比較関数を実施して、なんらかの一致・非一致を試験する能力があるのはリーフのみである。<br />ノードには、その能力は無い。（ノードはあくまで、子ノードの演算結果を論理演算する装置に過ぎない）<br /><br />これらの方法を実現するには、各ノード（そしてリーフ）を再帰によって連鎖的に処理していく方法で組めば、ロジックを簡単に組めそうな気がするのだが、はて？　どうだろうか。<br />まだ実際には書いてない、試してない。<br /><br /><br /><br />あ、ツリーに？を含めるの忘れてた…<br />そのうち書き直します。もぅ寝ます。 ]]>
</content:encoded>
<dc:subject>メモ</dc:subject>
<dc:date>2009-12-12T00:04:04+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-44.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-44.html</link>
<title>_LIST (0.1.0) 他</title>
<description> とりあえずバグをいろいろ直して、コード整理してみて、それで気に入らなかったら捨てようと思ったんだけど、意外と読みやすいコードな気もしてきたので、やっぱ捨てないでしばらくこのまま進んでみようかと思う。まぁどうせ遊びだし。はは&amp;hellip;wif 文での比較用に、_LIST 型に比較関数を用意した。すると派生クラスである CHAR_LISTにも、わりと簡単に同様の機能をもった比較関数を敬称によって実装できるので、「あぁ、便利だ
 </description>
<content:encoded>
<![CDATA[ とりあえずバグをいろいろ直して、コード整理してみて、それで気に入らなかったら捨てようと思ったんだけど、<br />意外と読みやすいコードな気もしてきたので、やっぱ捨てないでしばらくこのまま進んでみようかと思う。まぁどうせ遊びだし。はは&hellip;w<br /><br />if 文での比較用に、_LIST 型に比較関数を用意した。<br />すると派生クラスである CHAR_LISTにも、わりと簡単に同様の機能をもった比較関数を敬称によって実装できるので、<br />「あぁ、便利だな&hellip;」と思った。C＋＋って、ときどき便利だから嫌いになりきれなくてこまる&hellip;<br /><br />あと、今までコード書くのに GNOME のメモ帳（GEDIT)を使ってたんだけど、メソッド名を自動で補完入力してくれる機能が欲しくなったので（C＋＋だと、それが無いときついw　おもに記憶力的に。）<br />統合開発環境の kDevelop と Anjuta ってのを Synaptic でインストールしてみた。（あ、久しぶりにLinuxブログっぽい話だっw）<br />で、AnjutaってのはGnome系、KDevelop ってのはKDE系のソフトなんだけど、どっちもGnomeで動くみたい。よかったよかった。<br /><br />で、やっぱ機能的にAnjutaの方は色々弱くて、正直あんまり使えないというか、GEDITで書いても大差ないかなぁ～&hellip;って程度。<br />一方、KDevelopってのは、もぅ、めっちゃ素晴らしい！！って感じ。コード書いてる時の感覚は VisualStudioで書いてるときに近い。（主に自動補完入力が）<br />これ、ぜったいインストールした方がいいですよ！！　まじでおすすめ。　っていうか、もぅGEDITには戻れませんわ&hellip;<br /><br />ただ、KDE系のソフトなんで、やっぱり若干重たい。全体的に動作がもっさりしてる。でも機能はすばらしい。<br />なんかペイント系のソフトでも Karte でしたっけ？　すごくクオリティーの高いペイントソフトがあったりと、KDE系（Qt系っていうの？）の方が、なんか全体的にソフトの質が一段上なのが多いですよね&hellip;<br /><br />&hellip;乗り換えようかなぁ、KDEに&hellip;って、ちょっと思ってしまう。<br />ただ、重いんだよなぁ～&hellip;<br />前に一度、試しにKDEの４.x系に変えてみたんだけど、どうにも重くて重くて、なんか486でWin95を使ってたころのような、尋常じゃない重さだったので「あぁ、こりゃアカン&hellip;見た目かっこいいけど」って思って、速攻でGNOMEに戻した経緯がありまして&hellip;<br />GNOMEは軽いよねぇ&hellip;軽いだけとか言ってませんよ！言ってませんよ！んがんぐ<br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>_SEED.h (0.1.0)</td></tr><tr><td>#pragma once<br /><br />class _SEED {<br />protected:<br />&nbsp;&nbsp;&nbsp; _SEED*&nbsp;&nbsp;&nbsp; next;<br />&nbsp;&nbsp;&nbsp; _SEED*&nbsp;&nbsp;&nbsp; back;<br /><br />public:<br />&nbsp;&nbsp;&nbsp; _SEED();<br />&nbsp;&nbsp;&nbsp; virtual ~_SEED();<br /><br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; read_SEED ( _SEED* dst ) { return(0); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 派生したクラスの、ぶら下げたデータへの読み書きを、これら関数内で行う<br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; write_SEED( _SEED* src ) { return(0); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ...<br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comparison_SEED( _SEED* seed ) { return(0); }<br /><br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; add_next( _SEED* seed );<br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; add_back( _SEED* seed );<br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; del_next( void );<br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; del_back( void );<br /><br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; get_next( void );<br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; get_back( void );<br />};</td></tr><tr><td>_SEED.cpp (0.1.0)</td></tr><tr><td>#include &quot;_SEED.h&quot;<br /><br />_SEED::_SEED()<br />{<br />&nbsp;&nbsp;&nbsp; next = 0;<br />&nbsp;&nbsp;&nbsp; back = 0;<br />}<br /><br />_SEED::~_SEED()<br />{<br />}<br /><br />void _SEED::add_next( _SEED* seed )<br />{<br />&nbsp;&nbsp;&nbsp; if( seed == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;next = 0;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _SEED* next = this-&gt;next;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( next != 0 ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next = this-&gt;next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next-&gt;back = seed;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seed-&gt;next = next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seed-&gt;back = this;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;next = seed;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void _SEED::add_back( _SEED* seed )<br />{<br />&nbsp;&nbsp;&nbsp; if( seed == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;back = 0;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _SEED* back = this-&gt;back;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( back != 0 ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; back = this-&gt;back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; back-&gt;next = seed;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seed-&gt;next = this;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seed-&gt;back = back;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;back = seed;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />_SEED* _SEED::del_next( void )<br />{<br />&nbsp;&nbsp;&nbsp; _SEED* del = 0;<br /><br />&nbsp;&nbsp;&nbsp; if( this-&gt;next == 0 ) {<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; del = this-&gt;next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( del-&gt;next == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;next = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _SEED* new_next&nbsp;&nbsp;&nbsp; = del-&gt;next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;next = new_next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new_next-&gt;back = this;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( del );<br />}<br /><br />_SEED* _SEED::del_back( void )<br />{<br />&nbsp;&nbsp;&nbsp; _SEED* del = 0;<br /><br />&nbsp;&nbsp;&nbsp; if( this-&gt;back == 0 ) {<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; del = this-&gt;back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( del-&gt;back == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;back = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _SEED* new_back&nbsp;&nbsp;&nbsp; = del-&gt;back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;back = new_back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new_back-&gt;next = this;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( del );<br />}<br /><br />_SEED* _SEED::get_next( void )<br />{<br />&nbsp;&nbsp;&nbsp; return( next );<br />}<br /><br />_SEED* _SEED::get_back( void )<br />{<br />&nbsp;&nbsp;&nbsp; return( back );<br />}<br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>_LIST.h (0.1.0)</td></tr><tr><td>#pragma once<br /><br />#include &quot;_SEED.h&quot;<br /><br />// 派生させる場合に必要な設定について<br />// 新しい派生クラス x_LIST と、そのメンバ変数 x_SEED について、以下の設定が必須になります。<br />//<br />// ・x_SEED に、任意のメンバ変数を追加する。（任意）<br />//<br />// ・x_SEED に、任意のメンバ変数を追加した場合（ふつう追加するはず）、以下の２つの関数を再定義しなければならない<br />//&nbsp;&nbsp; void read( _SEED* dst ) {;//ここに、データの、『 this から dst へ』の『書き写し（ポインタのコピーではない!）』 に関する命令を書く }<br />//&nbsp;&nbsp; void write( _SEED* src ) {;// ...『src から this へ』の... }<br />//&nbsp;&nbsp; なお、引数の _SEED* dst および src は、どちらも『実体が存在するポインタ』が前提です。（_SEED&amp; dst および _SEED&amp; src だと考えてください）<br />//<br />// ・x_LIST の new_SEED() 関数の再定義<br />//&nbsp;&nbsp; これは _SEED 用の new オペレーターに相当する関数です。（ operator new による再定義はしてません。理由はよくわかんないからですw ） <br />//&nbsp;&nbsp; virtual _SEED* new_SEED( void ) { x_SEED* seed = new x_SEED; return( (_SEED*)seed ); }<br />//<br />// 以上<br />//<br />// 派生クラスでの、write 及び read の再定義に関する注意<br />// read および write で、リストの自動処理（たとえば自動伸長など）を期待するのなら、<br />// 最終的な_LISTへの read および write には必ず read_SEED() および write_SEED() で _SEED 型のポインタを渡すことによって行うこと<br />// 以上<br />class _LIST {<br />private:<br />&nbsp; &nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; seek( int index );<br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; seek_top( void ) { return( seed_top ); }<br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; seek_end( void ) { _SEED* end_seed = seek(list_len-1); return( end_seed ); }<br /><br />protected:<br />&nbsp;&nbsp;&nbsp; _SEED*&nbsp;&nbsp;&nbsp; seed_top;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list_len;<br /><br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; size_add( int add_len );<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; size_dec( int dec_len );<br /><br />&nbsp;&nbsp;&nbsp; virtual _SEED* new_SEED( void ){ _SEED* new_seed = new _SEED; &nbsp;&nbsp;&nbsp; return( (_SEED*)new_seed ); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // new の代わりにこれを使う<br /><br />public:<br />&nbsp;&nbsp;&nbsp; _LIST();<br />&nbsp;&nbsp;&nbsp; virtual ~_LIST();<br /><br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; size_set&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ( int len );<br /><br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; read_LIST&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ( int index, int width, _LIST* dst );<br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; write_LIST&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ( int index, int width, _LIST* src );<br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; read_SEED&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ( int index, _SEED* dst );<br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; write_SEED&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ( int index, _SEED* src );<br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; comparison_SEED&nbsp;&nbsp;&nbsp; ( int index, _SEED* seed );<br /><br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _list_len&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (void) {return(list_len);}<br /><br />//&nbsp;&nbsp;&nbsp; virtual int cut( int index, _SEED* dst );<br />//&nbsp;&nbsp;&nbsp; virtual int cut( int index, int width, _LIST* dst );<br />//&nbsp;&nbsp;&nbsp; virtual int paste( int index, _SEED* src );<br />//&nbsp;&nbsp;&nbsp; virtual int paste( int index, _LIST* src );<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; print_all_address(void);<br />};<br /></td></tr><tr><td>LIST.cpp (0.1.0)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &quot;_LIST.h&quot;<br /><br />_LIST::_LIST()<br />{<br />&nbsp;&nbsp;&nbsp; seed_top = new_SEED();<br />&nbsp;&nbsp;&nbsp; list_len = 1;<br />}<br /><br />_LIST::~_LIST()<br />{<br />&nbsp; for(int i = list_len -1; i &gt;= 0; i-- ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _SEED* del_seed = seek(i);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( del_seed !=0 ) { delete del_seed; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />_SEED* _LIST::seek( int index )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &gt; list_len - 1 ) { index = list_len - 1; }<br /><br />&nbsp;&nbsp;&nbsp; _SEED* cur_seed = seed_top;<br /><br />&nbsp;&nbsp;&nbsp; for( int i=1; i &lt;= index; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(cur_seed==0) {break;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 次が無ければ０を返す<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_seed = cur_seed-&gt;get_next();<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( cur_seed );<br />}<br /><br />void _LIST::size_add( int add_len )<br />{<br />&nbsp;&nbsp;&nbsp; _SEED* cur_seed = seek( list_len - 1 );<br />&nbsp;&nbsp;&nbsp; _SEED* new_seed;<br /><br />&nbsp;&nbsp;&nbsp; for(int i=0; i &lt; add_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new_seed = new_SEED();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_seed-&gt;add_next( new_seed );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_seed = new_seed;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; list_len += add_len;<br />}<br /><br />void _LIST::size_dec( int dec_len )<br />{<br />&nbsp;&nbsp;&nbsp; _SEED* cur_seed = seek( list_len - 1 );<br />&nbsp;&nbsp;&nbsp; _SEED* del_seed;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; dec_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_seed = cur_seed-&gt;get_back();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; del_seed = cur_seed-&gt;del_next();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete del_seed;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; list_len -= dec_len;<br />}<br /><br />void _LIST::size_set( int len )<br />{<br />&nbsp;&nbsp;&nbsp; if( len &lt;= 0 ) { len = 1; }<br /><br />&nbsp;&nbsp;&nbsp; int dif = len - list_len;<br />&nbsp;&nbsp;&nbsp; if( dif &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_add(dif);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if( dif &lt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dif = -dif;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_dec(dif);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />}<br /><br />int _LIST::read_SEED( int index, _SEED* dst )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { index = 0; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲アンダーなら最初<br />&nbsp;&nbsp;&nbsp; if( index &gt; list_len - 1 )&nbsp;&nbsp;&nbsp; { index = list_len - 1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲オーバーなら最後<br /><br />&nbsp;&nbsp;&nbsp; _SEED* src = seek( index );<br />&nbsp;&nbsp;&nbsp; return( dst-&gt;write_SEED( src ) );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // あくまでnext,back変数以外のデータのリードライトのみ<br />}<br /><br />int _LIST::write_SEED( int index, _SEED* src )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { index = 0; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲アンダーなら最初<br />&nbsp;&nbsp;&nbsp; if( index &gt; list_len - 1 )&nbsp;&nbsp;&nbsp; { size_set( index+1 ); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲オーバーならリストを伸ばす （+1は_LIST長という意味）<br /><br />&nbsp;&nbsp;&nbsp; _SEED* dst = seek( index );<br />&nbsp;&nbsp;&nbsp; return( dst-&gt;write_SEED( src ) );<br />}<br /><br />int _LIST::comparison_SEED( int index, _SEED* seed )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { index = 0; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲アンダーなら最初<br />&nbsp;&nbsp;&nbsp; if( index &gt; list_len - 1 )&nbsp;&nbsp;&nbsp; { index = list_len - 1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲オーバーなら最後<br /><br />&nbsp;&nbsp;&nbsp; _SEED* base = seek( index );<br />&nbsp;&nbsp;&nbsp; return( base-&gt;comparison_SEED( seed ) );<br />}<br /><br />int _LIST::read_LIST( int index, int width, _LIST* dst )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { index = 0; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲アンダーなら最初<br />&nbsp;&nbsp;&nbsp; if( index &gt; list_len - 1 )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { index = list_len - 1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲オーバーなら最後<br />&nbsp;&nbsp;&nbsp; if( index + width &gt; list_len )&nbsp;&nbsp;&nbsp; { width = list_len - index; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 最大でも src の len 幅まで<br />&nbsp;&nbsp;&nbsp; if( width &lt;= 0 )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { width = 1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 幅が０以下なら１<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; dst-&gt;size_set(width);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // dstの幅を index to width 区間と同じ幅に<br /><br />&nbsp;&nbsp;&nbsp; _SEED* buf = new_SEED();<br />&nbsp;&nbsp;&nbsp; for(int si=index, di=0 ; si &lt; index + width; si++, di++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;read_SEED( si, buf );&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;write_SEED( di, buf );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; delete buf;<br />}<br /><br />int _LIST::write_LIST( int index, int width, _LIST* src )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { index = 0; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲アンダーなら最初<br />&nbsp;&nbsp;&nbsp; if( width &gt; src-&gt;_list_len() )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { width = src-&gt;_list_len(); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 最大でも src の len 幅まで<br />&nbsp;&nbsp;&nbsp; if( width &lt;= 0 )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { width = 1; }<br />&nbsp;&nbsp;&nbsp; if( index + width &gt; list_len - 1 )&nbsp;&nbsp;&nbsp; { this-&gt;size_set( index + width ); }&nbsp;&nbsp;&nbsp; // 範囲オーバーならリストを伸ばす<br /><br />&nbsp;&nbsp;&nbsp; _SEED* buf = new_SEED();<br />&nbsp;&nbsp;&nbsp; for(int si=0, di=index ; di &lt; index + width; si++, di++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; src-&gt;read_SEED( si, buf );&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;write_SEED( di, buf );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; delete buf;<br />}<br /><br />void _LIST::print_all_address(void)<br />{<br />&nbsp;&nbsp;&nbsp; _SEED* cur_seed = seed_top;<br /><br />&nbsp;&nbsp;&nbsp; printf(&quot;list_len=%d\n&quot;, list_len);<br /><br />&nbsp;&nbsp;&nbsp; for(int i=0; i &lt; list_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%d:%d\n&quot;,i,(int)cur_seed);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_seed = cur_seed-&gt;get_next();<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />}<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CHAR_SEED.h (0.1.0)</td></tr><tr><td>#pragma once<br /><br />#include &quot;_SEED.h&quot;<br />#include &quot;CHAR.h&quot;<br /><br />class CHAR_SEED : public _SEED {<br />protected:<br />&nbsp;&nbsp;&nbsp; CHAR* ch;<br /><br />public:<br />&nbsp;&nbsp;&nbsp; CHAR_SEED() { ch = new CHAR; }<br />&nbsp;&nbsp;&nbsp; virtual ~CHAR_SEED() { delete ch; }<br /><br />&nbsp;&nbsp;&nbsp; virtual int read_SEED ( _SEED* seed ) { return( ((CHAR_SEED*)seed)-&gt;write_CHAR( ch ) ); }<br />&nbsp;&nbsp;&nbsp; virtual int write_SEED( _SEED* seed ) { return( ((CHAR_SEED*)seed)-&gt;read_CHAR ( ch ) ); }<br />&nbsp;&nbsp;&nbsp; virtual int comparison_SEED( _SEED* seed );<br /><br />&nbsp;&nbsp;&nbsp; virtual int read_char ( unsigned char* dst ) { return( ch-&gt;read_char ( dst ) ); }<br />&nbsp;&nbsp;&nbsp; virtual int write_char( unsigned char* src ) { return( ch-&gt;write_char( src ) ); }<br /><br />&nbsp;&nbsp;&nbsp; virtual int read_CHAR ( CHAR* dst ) { return( ch-&gt;read_CHAR ( dst ) ); }<br />&nbsp;&nbsp;&nbsp; virtual int write_CHAR( CHAR* src ) { return( ch-&gt;write_CHAR( src ) ); }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; virtual int comparison_char( unsigned char* src )&nbsp;&nbsp;&nbsp; { return( ch-&gt;comparison_char( src ) ); }<br />&nbsp;&nbsp;&nbsp; virtual int comparison_CHAR( CHAR* src )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { return( ch-&gt;comparison_CHAR( src ) ); }<br /><br />&nbsp;&nbsp;&nbsp; virtual int _mode(void){ return( ch-&gt;_mode() ); }<br />&nbsp;&nbsp;&nbsp; virtual int _step(void){ return( ch-&gt;_step() ); }<br />};</td></tr><tr><td>CHAR_SEED.cpp (0.1.0)</td></tr><tr><td>#include &quot;CHAR_SEED.h&quot;<br /><br />int CHAR_SEED::comparison_SEED( _SEED* seed )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR seed_ch;<br />&nbsp;&nbsp;&nbsp; ((CHAR_SEED*)seed)-&gt;read_CHAR( &amp;seed_ch );<br />&nbsp;&nbsp;&nbsp; return( comparison_CHAR( &amp;seed_ch ) );<br />}</td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CHAR_LIST.h (0.1.0)</td></tr><tr><td>#pragma once<br /><br />#include &quot;_LIST.h&quot;<br />#include &quot;CHAR_SEED.h&quot;<br /><br />class CHAR_LIST : public _LIST {<br />protected:<br />&nbsp;&nbsp;&nbsp; virtual _SEED* new_SEED( void ){ CHAR_SEED* new_seed = new CHAR_SEED; return( (_SEED*)new_seed ); } // new の代わりにこれを使う<br />&nbsp;&nbsp;&nbsp; <br />public:<br />&nbsp;&nbsp;&nbsp; CHAR_LIST() { delete seed_top; seed_top = new_SEED(); }&nbsp;&nbsp;&nbsp; // コンストラクタ直後は_SEED型なので、一旦そのメモリを開放してから。<br />&nbsp;&nbsp;&nbsp; virtual ~CHAR_LIST(){ ; }<br /><br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; read_char ( int index, unsigned char* dst );<br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; write_char( int index, unsigned char* src );<br /><br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; read_CHAR ( int index, CHAR* dst );<br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; write_CHAR( int index, CHAR* src );<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; read_CHAR_LIST ( int index, int width, CHAR_LIST* dst );<br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; write_CHAR_LIST( int index, int width, CHAR_LIST* src );<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; read_str ( unsigned char* dst, int len );<br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; write_str( unsigned char* src, int len );<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; virtual int comparison_char( int index, unsigned char* src );<br />&nbsp;&nbsp;&nbsp; virtual int comparison_CHAR( int index, CHAR* src );<br />&nbsp;&nbsp;&nbsp; virtual int comparison_CHAR_LIST( CHAR_LIST* src );<br /><br />&nbsp;&nbsp;&nbsp; virtual int _mode( int index );<br />&nbsp;&nbsp;&nbsp; virtual int _step( int index );<br />};</td></tr><tr><td>CHAR_LIST.cpp (0.1.0)</td></tr><tr><td>#include &quot;CHAR_LIST.h&quot;<br />&nbsp;<br />int CHAR_LIST::read_char( int index, unsigned char* dst )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* buf = new CHAR_SEED;<br />&nbsp;&nbsp;&nbsp; read_SEED( index, (_SEED*)buf );<br />&nbsp;&nbsp;&nbsp; int ret = buf-&gt;read_char( dst );<br />&nbsp;&nbsp;&nbsp; delete buf;<br />&nbsp;&nbsp;&nbsp; return( ret );<br />}<br />&nbsp;<br />int CHAR_LIST::write_char( int index, unsigned char* src )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* buf = new CHAR_SEED;<br />&nbsp;&nbsp;&nbsp; int ret = buf-&gt;write_char( src );<br />&nbsp;&nbsp;&nbsp; write_SEED( index, (_SEED*)buf );<br />&nbsp;&nbsp;&nbsp; delete buf;<br />&nbsp;&nbsp;&nbsp; return( ret );<br />}<br />&nbsp;<br />int CHAR_LIST::read_CHAR( int index, CHAR* dst )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* buf = new CHAR_SEED;<br />&nbsp;&nbsp;&nbsp; read_SEED( index, (_SEED*)buf );<br />&nbsp;&nbsp;&nbsp; int ret = buf-&gt;read_CHAR( dst );<br />&nbsp;&nbsp;&nbsp; delete buf;<br />&nbsp;&nbsp;&nbsp; return( ret );<br />}<br />&nbsp;<br />int CHAR_LIST::write_CHAR( int index, CHAR* src )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* buf = new CHAR_SEED;<br />&nbsp;&nbsp;&nbsp; int ret = buf-&gt;write_CHAR( src );<br />&nbsp;&nbsp;&nbsp; write_SEED( index, (_SEED*)buf );<br />&nbsp;&nbsp;&nbsp; delete buf;<br />&nbsp;&nbsp;&nbsp; return( ret );<br />}<br />&nbsp;<br />int CHAR_LIST::read_CHAR_LIST( int index, int width, CHAR_LIST* dst )<br />{<br />&nbsp;&nbsp;&nbsp; return( read_LIST( index, width, (_LIST*)dst ) );<br />}<br />&nbsp;<br />int CHAR_LIST::write_CHAR_LIST( int index, int width, CHAR_LIST* src )<br />{<br />&nbsp;&nbsp;&nbsp; return( write_LIST( index, width, (_LIST*)src ) );<br />}<br />&nbsp;<br />int CHAR_LIST::read_str( unsigned char* dst, int len )<br />{<br />&nbsp;&nbsp;&nbsp; int step = 0;<br />&nbsp;&nbsp;&nbsp; int total_step = 0;<br />&nbsp;&nbsp;&nbsp; int count = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; for ( int i=0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; step = read_char( count, &amp;dst[total_step] );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; total_step += step;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( count &gt; len - 1 ) { break; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; return( total_step );<br />}<br />&nbsp;<br />int CHAR_LIST::write_str( unsigned char* src, int len )<br />{<br />&nbsp;&nbsp;&nbsp; int step = 0;<br />&nbsp;&nbsp;&nbsp; int total_step = 0;<br />&nbsp;&nbsp;&nbsp; int count = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; for ( int i=0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; step = write_char( count, &amp;src[total_step] );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; total_step += step;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( count &gt; len - 1 ) { break; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; return( total_step );<br />}<br />&nbsp;<br />int CHAR_LIST::comparison_char( int index, unsigned char* src )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR src_ch;<br />&nbsp;&nbsp;&nbsp; src_ch.write_char( src );<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; int ret = comparison_CHAR( index, &amp;src_ch );<br />&nbsp;&nbsp;&nbsp; return( ret );<br />}<br />&nbsp;<br />int CHAR_LIST::comparison_CHAR( int index, CHAR* src )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED src_seed;<br />&nbsp;&nbsp;&nbsp; src_seed.write_CHAR( src );<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; CHAR_SEED base_seed;<br />&nbsp;&nbsp;&nbsp; read_SEED( index, (_SEED*)&amp;base_seed );<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; int ret = base_seed.comparison_SEED( (_SEED*)&amp;src_seed );<br />&nbsp;&nbsp;&nbsp; return( ret );<br />}<br />&nbsp;<br />// this に対する cl のマッチを調べる。<br />// 最初にマッチした位置の先頭インデックスを返す。　マッチした位置が無かった場合は -1　を返す。<br />int CHAR_LIST::comparison_CHAR_LIST( CHAR_LIST* src )<br />{<br />&nbsp;&nbsp;&nbsp; int cur_src_index = 0;<br />&nbsp;&nbsp;&nbsp; int max_src_index = src-&gt;_list_len();<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; int cur_base_index = 0;<br />&nbsp;&nbsp;&nbsp; int max_base_index = this-&gt;_list_len();<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; int ret = -1;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; CHAR_SEED cur_src_seed;<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; while( cur_base_index &lt; max_base_index ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; src-&gt;read_SEED( cur_src_index, (_SEED*)&amp;cur_src_seed );<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( comparison_SEED( cur_base_index, (_SEED*)&amp;cur_src_seed ) != 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_src_index++;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( cur_src_index &gt;= max_src_index ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_src_index = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret = cur_base_index - (max_src_index - 1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 最初に一致したインデックスをリターンして終了<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( ret );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_src_index = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_base_index++;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; return( ret );<br />}<br />&nbsp;<br />int CHAR_LIST::_mode( int index )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED buf;<br />&nbsp;&nbsp;&nbsp; read_SEED( index, (_SEED*)(&amp;buf) );<br />&nbsp;&nbsp;&nbsp; return( buf._mode() );<br />}<br />&nbsp;<br />int CHAR_LIST::_step( int index )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED buf;<br />&nbsp;&nbsp;&nbsp; read_SEED( index, (_SEED*)(&amp;buf) );<br />&nbsp;&nbsp;&nbsp; return( buf._step() );<br />}<br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CHAR.h (0.1.0)</td></tr><tr><td>#pragma once<br /><br />#include &quot;CURSOR_CONTROL.h&quot;<br /><br />class CHAR {<br />protected:<br />&nbsp;&nbsp;&nbsp; unsigned char* c;<br />&nbsp;&nbsp;&nbsp; int mode;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 現在CHARに格納されてる文字の、使用バイト数 (ASCII=1, MultiByte=2,3,4)<br />&nbsp;&nbsp;&nbsp; int step;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 現在CHARに格納されてる文字の、表示ブロック数 (ASCII=1, MultiByte=2)<br /><br />&nbsp;&nbsp;&nbsp; virtual void calc_step(void);<br />&nbsp;&nbsp;&nbsp; virtual void calc_mode(void);<br /><br />public:<br />&nbsp;&nbsp;&nbsp; CHAR(){ c = new unsigned char[4]; c[0]=' '; write_char(c); }<br />&nbsp;&nbsp;&nbsp; virtual ~CHAR(){ delete[] c; }<br /><br />&nbsp;&nbsp;&nbsp; // char[4] を読み込み UTF-8 に変換して格納する。<br />&nbsp;&nbsp;&nbsp; // リターンは使用してるバイト数。判別不能の時は０を返す。<br />&nbsp;&nbsp;&nbsp; virtual int write_char( unsigned char* src );<br />&nbsp;&nbsp;&nbsp; virtual int write_CHAR( CHAR* src ) { return( write_char( src-&gt;c ) ); }<br /><br />&nbsp;&nbsp;&nbsp; // char[4] に UTF-8 の先頭バイトから順に格納する。<br />&nbsp;&nbsp;&nbsp; // ただし、使用されるバイト数は、モードの必要分&rdquo;だけ&rdquo;であり、<br />&nbsp;&nbsp;&nbsp; // それ以降のバイトには一切触れない（値を変えない・アクセスすらしない）<br />&nbsp;&nbsp;&nbsp; // 戻り値には、使用しているバイト数が返される。０の場合はほぼエラーを意味する。<br />&nbsp;&nbsp;&nbsp; virtual int read_char( unsigned char* dst );<br />&nbsp;&nbsp;&nbsp; virtual int read_CHAR( CHAR* dst ) { return( read_char( dst-&gt;c ) ); }<br /><br />&nbsp;&nbsp;&nbsp; // 文字の比較を行う。同じ場合は１、違う場合は０<br />&nbsp;&nbsp;&nbsp; // なお、比較するバイト数は先頭から mode 数分だけ。以降のバイトは無視して比較する。<br />&nbsp;&nbsp;&nbsp; virtual int comparison_char( unsigned char* src );<br />&nbsp;&nbsp;&nbsp; virtual int comparison_CHAR( CHAR* src );<br /><br />&nbsp;&nbsp;&nbsp; // 指定したカーソル位置に一文字表示する<br />&nbsp;&nbsp;&nbsp; // 戻り値は、文字の表示に使用したブロック数。ASCII（半角文字）の場合は1ブロック、非ASCII（全角文字）の場合は2ブロック<br />&nbsp;&nbsp;&nbsp; // カーソル位置は、表示後も変わらない。（自動では進まない）<br />&nbsp;&nbsp;&nbsp; virtual int print( CURSOR_CONTROL* cc );<br /><br />&nbsp;&nbsp;&nbsp; virtual int _mode(void) { return( mode ); }<br />&nbsp;&nbsp;&nbsp; virtual int _step(void) { return( step ); }<br />};</td></tr><tr><td>CHAR.cpp (0.1.0)</td></tr><tr><td>#include &lt;stdio.h&gt;<br /><br />#include &quot;CHAR.h&quot;<br />#include &quot;CURSOR_CONTROL.h&quot;<br /><br />void CHAR::calc_step(void)<br />{<br />&nbsp;&nbsp;&nbsp; switch(mode){<br />&nbsp;&nbsp;&nbsp; case 0: step = 0; break;<br />&nbsp;&nbsp;&nbsp; case 1: step = 1; break;&nbsp;&nbsp;&nbsp; // ASCII 半角文字なら<br />&nbsp;&nbsp;&nbsp; case 2: step = 2; break;&nbsp;&nbsp;&nbsp; // 非ASCIIは全て全角文字として扱う。（半角カナなどは考慮しない）<br />&nbsp;&nbsp;&nbsp; case 3: step = 2; break;<br />&nbsp;&nbsp;&nbsp; case 4: step = 2; break;<br />&nbsp;&nbsp;&nbsp; default: step = 0; break;<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />}<br /><br />void CHAR::calc_mode( void )<br />{<br />&nbsp; &nbsp;&nbsp;&nbsp; unsigned char c0 = c[0];<br /><br />&nbsp;&nbsp;&nbsp; mode = 0;<br /><br />&nbsp;&nbsp;&nbsp; // 先頭バイトがEOFならEOF<br />&nbsp;&nbsp;&nbsp; if( (char)c0 == EOF ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mode = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; // 先頭bitが1ならマルチバイト文字、0ならASCII文字<br />&nbsp;&nbsp;&nbsp; else if( ( c0 &amp; 0x80 ) == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mode = 1;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 第2bitが0なら先頭以外の文字、1なら先頭文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x40 ) == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 第3bitが0なら２バイト文字、1なら３バイト以上の文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x20 ) == 0 )&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mode = 2;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ...かつ、第４bitが0なら３バイト文字、1なら４バイト文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x10 ) == 0 )&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mode = 3;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mode = 4;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; calc_step();<br />}<br /><br />// char[4] を読み込み UTF-8 に変換して格納する。<br />// リターンは使用してるバイト数。判別不能の時は０を返す。<br />int CHAR::write_char( unsigned char* src )<br />{<br />&nbsp;&nbsp;&nbsp; c[0] = src[0];&nbsp;&nbsp;&nbsp; //c[1] = src[1];&nbsp;&nbsp;&nbsp; c[2] = src[2];&nbsp;&nbsp;&nbsp; c[3] = src[3];<br />&nbsp;&nbsp;&nbsp; calc_mode();<br /><br />//&nbsp;&nbsp;&nbsp; switch( mode ){<br />//&nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; c[0] = src[0];&nbsp;&nbsp;&nbsp; c[1] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c[2] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c[3] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />//&nbsp;&nbsp;&nbsp; case 2:&nbsp;&nbsp;&nbsp; c[0] = src[0];&nbsp;&nbsp;&nbsp; c[1] = src[1];&nbsp;&nbsp;&nbsp; c[2] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c[3] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />//&nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; c[0] = src[0];&nbsp;&nbsp;&nbsp; c[1] = src[1];&nbsp;&nbsp;&nbsp; c[2] = src[2];&nbsp;&nbsp;&nbsp; c[3] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />//&nbsp;&nbsp;&nbsp; case 4:&nbsp;&nbsp;&nbsp; c[0] = src[0];&nbsp;&nbsp;&nbsp; c[1] = src[1];&nbsp;&nbsp;&nbsp; c[2] = src[2];&nbsp;&nbsp;&nbsp; c[3] = src[3];&nbsp;&nbsp;&nbsp; break;<br />//&nbsp;&nbsp;&nbsp; default: break;<br />//&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; switch( mode ){<br />&nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; c[0] = src[0];&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 2:&nbsp;&nbsp;&nbsp; c[0] = src[0];&nbsp;&nbsp;&nbsp; c[1] = src[1];&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; c[0] = src[0];&nbsp;&nbsp;&nbsp; c[1] = src[1];&nbsp;&nbsp;&nbsp; c[2] = src[2];&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 4:&nbsp;&nbsp;&nbsp; c[0] = src[0];&nbsp;&nbsp;&nbsp; c[1] = src[1];&nbsp;&nbsp;&nbsp; c[2] = src[2];&nbsp;&nbsp;&nbsp; c[3] = src[3];&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; default: break;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return( mode );<br />}<br /><br />// char[4] に UTF-8 の先頭バイトから順に格納する。<br />// ただし、使用されるバイト数は、モードの必要分&rdquo;だけ&rdquo;であり、<br />// それ以降のバイトには一切触れない（値を変えない・アクセスすらしない）<br />// 戻り値には、使用しているバイト数が返される。０の場合はほぼエラーを意味する。<br />int CHAR::read_char( unsigned char* dst )<br />{<br />&nbsp;&nbsp;&nbsp; calc_mode();<br />&nbsp;&nbsp;&nbsp; <br />//&nbsp;&nbsp;&nbsp; switch(mode){<br />//&nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; dst[0] = c[0];&nbsp;&nbsp;&nbsp; dst[1] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[2] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[3] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />//&nbsp;&nbsp;&nbsp; case 2:&nbsp;&nbsp;&nbsp; dst[0] = c[0];&nbsp;&nbsp;&nbsp; dst[1] = c[1];&nbsp;&nbsp;&nbsp; dst[2] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[3] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />//&nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; dst[0] = c[0];&nbsp;&nbsp;&nbsp; dst[1] = c[1];&nbsp;&nbsp;&nbsp; dst[2] = c[2];&nbsp;&nbsp;&nbsp; dst[3] = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />//&nbsp;&nbsp;&nbsp; case 4:&nbsp;&nbsp;&nbsp; dst[0] = c[0];&nbsp;&nbsp;&nbsp; dst[1] = c[1];&nbsp;&nbsp;&nbsp; dst[2] = c[2];&nbsp;&nbsp;&nbsp; dst[3] = c[3];&nbsp;&nbsp;&nbsp; break;<br />//&nbsp;&nbsp;&nbsp; default: break;<br />//&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; switch(mode){<br />&nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; dst[0] = c[0];&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 2:&nbsp;&nbsp;&nbsp; dst[0] = c[0];&nbsp;&nbsp;&nbsp; dst[1] = c[1];&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; dst[0] = c[0];&nbsp;&nbsp;&nbsp; dst[1] = c[1];&nbsp;&nbsp;&nbsp; dst[2] = c[2];&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; case 4:&nbsp;&nbsp;&nbsp; dst[0] = c[0];&nbsp;&nbsp;&nbsp; dst[1] = c[1];&nbsp;&nbsp;&nbsp; dst[2] = c[2];&nbsp;&nbsp;&nbsp; dst[3] = c[3];&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; default: break;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return( mode );<br />}<br /><br />// 文字の比較を行う。同じ場合は１、違う場合は０<br />// なお、比較するバイト数は先頭から mode 数分だけ。以降のバイトは無視して比較する。<br />int CHAR::comparison_char( unsigned char* src )<br />{<br />&nbsp;&nbsp;&nbsp; calc_mode();<br />&nbsp;&nbsp;&nbsp; int ret=0;<br /><br />&nbsp;&nbsp;&nbsp; switch(mode){<br />&nbsp;&nbsp;&nbsp; case 1: if(c[0]==src[0]) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret=1; break;<br />&nbsp;&nbsp;&nbsp; case 2: if(c[0]==src[0] &amp;&amp; c[1]==src[1]) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret=1; break;<br />&nbsp;&nbsp;&nbsp; case 3: if(c[0]==src[0] &amp;&amp; c[1]==src[1]&amp;&amp; c[2]==src[2]) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret=1; break;<br />&nbsp;&nbsp;&nbsp; case 4: if(c[0]==src[0] &amp;&amp; c[1]==src[1]&amp;&amp; c[2]==src[2]&amp;&amp; c[3]==src[3])&nbsp;&nbsp;&nbsp; ret=1; break;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( ret );<br />}<br /><br />int CHAR::comparison_CHAR( CHAR* src )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char buf[4];<br />&nbsp;&nbsp;&nbsp; src-&gt;read_char( buf );<br />&nbsp;&nbsp;&nbsp; return( comparison_char( buf ) );<br />}<br /><br />// 指定したカーソル位置に一文字表示する<br />// 戻り値は、文字の表示に使用したブロック数。ASCII（半角文字）の場合は1ブロック、非ASCII（全角文字）の場合は2ブロック<br />// カーソル位置は、表示後も変わらない。（自動では進まない）<br />int CHAR::print( CURSOR_CONTROL* cc )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char c[4];<br />&nbsp;&nbsp;&nbsp; read_char( c );<br /><br />&nbsp;&nbsp;&nbsp; cc-&gt;__setpos( cc-&gt;pos_x, cc-&gt;pos_y);&nbsp;&nbsp;&nbsp; // カーソル位置をセット<br />&nbsp;&nbsp;&nbsp; for( int i=0; i &lt; mode; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; putchar( c[i] );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; cc-&gt;__setpos( cc-&gt;pos_x, cc-&gt;pos_y );&nbsp;&nbsp;&nbsp; // putchar() の実行で変わったであろうカーソル位置を、元にもどす（自動での移動はさせない）<br /><br />&nbsp;&nbsp;&nbsp; return( step );&nbsp;&nbsp;&nbsp; <br />}</td></tr></tbody></table><br /><br /><br /><br /> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-12-05T20:57:43+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-42.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-42.html</link>
<title>_LIST (0.0.9) 他</title>
<description> _LISTtest.cpp (動作テスト用)   CHAR をメンバーにもつ CHAR_SEED　及び　CHAR_LIST  CHAR_LIST をメンバーにもつ LINE_SEED 及び LINE_LIST  これらクラスを適当に書いてみたところ、あっさり動いた。 たったこれっぽっちのコードで。  しかしながら、「わかりづらい」という問題。 どうもオブジェクト指向の多態性を利用して設計すると、処理が細かく分散して、 どうにも「アテ」を付けられないコードになるような気がする&amp;hell
 </description>
<content:encoded>
<![CDATA[ _LISTtest.cpp (動作テスト用) <br /> <br /> CHAR をメンバーにもつ CHAR_SEED　及び　CHAR_LIST <br /> CHAR_LIST をメンバーにもつ LINE_SEED 及び LINE_LIST <br /> これらクラスを適当に書いてみたところ、あっさり動いた。<br /> たったこれっぽっちのコードで。<br /> <br /> しかしながら、「わかりづらい」という問題。<br /> どうもオブジェクト指向の多態性を利用して設計すると、処理が細かく分散して、<br /> どうにも「アテ」を付けられないコードになるような気がする&hellip;（読みにくいコード）<br /> <br /> C（的な使い方）に抑えて書いたコードのような、読みやすさ、見通しのよさ、一つ一つのモジュールの局所性（いろんなとこ読まなくても、一ヶ所読めば読める的な）ってのは、<br /> 多態性を積極的に利用すると、どうも犠牲になっちゃうような気がする&hellip;<br /> &hellip;たしかに、「作った直後で、イメージが頭にある、理解してる状態」なら、多態性のコードでも<br /> 割と動作をイメージできてるものなんだけど、<br /> いざ、これを１年後に読み返して、はたして読めるか？　と自分に問えば、はっきり言って<br /> かなりシンドイと思う&hellip;<br /> <br /> 余談だけど、先日のフォトショップのプラグインのコードなんかは、まるっきり行き当たりばったりのスパゲッティーコードですけど、<br /> 一見、読みづらそうだけど、いざ読んでみると、上から順番に「書いたときの感覚」で読み直していけば、実は意外とすんなり頭に入ってくる。<br /> でも、多態性で「小賢く」しくみを作ってしまったようなコードだと、この「一年後でもすんなり読める」ってのは期待できない。　かならず「？？？」ってなるはず。<br /> どうも、多態性で型が状況に応じて変化するってのが、読みづらさの原因だと思う。<br /> どうにも読みながら「これはコードには○○って書いてあるけど、実際の動作時には●●として動いてるはずなので～&hellip;　え～と&hellip;」的なw　これをやりながら 読む必要があるから、だから多態性のコードは読みづらいし、最初の一読だけで理解なんて無理。なんども全体を反復的に読み返さないと、コードの意味をつか めない読みづらさ。<br /> <br /> 漠然とした印象だけど、どうも、あんまり多態性なんかはコードに入れ込まない方が、理解しやすいコードになると思う。個人的に。<br /> 理解しやすいってことは、あとあと改造しやすいってことだし。やっぱりC＋＋は単なるベターCとして素朴な書き方する方がいいのかもしれない&hellip;（0.0.8)あたりのコード程度の使い方が一番マシな気がする。個人的に。<br /> <br /> さて、(0.0.9)のCHAR_LISTはどうするべか&hellip;<br /> やっぱ捨てた方がいいんだろうな&hellip; 読めねぇもん、一年後に、これ&hellip;orz<br /> <br /><br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>_SEED.h (0.0.9)</td></tr><tr><td>#pragma once<br /><br />class _SEED {<br />protected:<br />&nbsp;&nbsp;&nbsp; _SEED*&nbsp;&nbsp;&nbsp; next;<br />&nbsp;&nbsp;&nbsp; _SEED*&nbsp;&nbsp;&nbsp; back;<br /><br />public:<br />&nbsp;&nbsp;&nbsp; _SEED();<br />&nbsp;&nbsp;&nbsp; virtual ~_SEED();<br /><br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; read( _SEED* dst ) {;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 派生したクラスの、ぶら下げたデータへの読み書きを、これら関数内で行う<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; write( _SEED* src ) {;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ...<br /><br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; add_next( _SEED* seed );<br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; add_back( _SEED* seed );<br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; del_next( void );<br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; del_back( void );<br /><br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; get_next( void );<br />&nbsp;&nbsp;&nbsp; virtual _SEED* get_back( void );<br />};<br /></td></tr><tr><td>_SEED.cpp (0.0.9)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &quot;_SEED.h&quot;<br /><br />_SEED::_SEED()<br />{<br />&nbsp;&nbsp;&nbsp; next = 0;<br />&nbsp;&nbsp;&nbsp; back = 0;<br />}<br /><br />_SEED::~_SEED()<br />{<br />}<br /><br />void _SEED::add_next( _SEED* seed )<br />{<br />&nbsp;&nbsp;&nbsp; if( seed == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;next = 0;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _SEED* next = this-&gt;next;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( next != 0 ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next = this-&gt;next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next-&gt;back = seed;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seed-&gt;next = next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seed-&gt;back = this;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;next = seed;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void _SEED::add_back( _SEED* seed )<br />{<br />&nbsp;&nbsp;&nbsp; if( seed == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;back = 0;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _SEED* back = this-&gt;back;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( back != 0 ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; back = this-&gt;back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; back-&gt;next = seed;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seed-&gt;next = this;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seed-&gt;back = back;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;back = seed;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />_SEED* _SEED::del_next( void )<br />{<br />&nbsp;&nbsp;&nbsp; _SEED* del = 0;<br /><br />&nbsp;&nbsp;&nbsp; if( this-&gt;next == 0 ) {<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; del = this-&gt;next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( del-&gt;next == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;next = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _SEED* new_next&nbsp;&nbsp;&nbsp; = del-&gt;next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;next = new_next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new_next-&gt;back = this;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( del );<br />}<br /><br />_SEED* _SEED::del_back( void )<br />{<br />&nbsp;&nbsp;&nbsp; _SEED* del = 0;<br /><br />&nbsp;&nbsp;&nbsp; if( this-&gt;back == 0 ) {<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; del = this-&gt;back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( del-&gt;back == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;back = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _SEED* new_back&nbsp;&nbsp;&nbsp; = del-&gt;back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;back = new_back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new_back-&gt;next = this;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( del );<br />}<br /><br />_SEED* _SEED::get_next( void )<br />{<br />&nbsp;&nbsp;&nbsp; return( next );<br />}<br /><br />_SEED* _SEED::get_back( void )<br />{<br />&nbsp;&nbsp;&nbsp; return( back );<br />}<br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>_LIST.h (0.0.9)</td></tr><tr><td>#pragma once<br /><br />#include &quot;_SEED.h&quot;<br /><br />// 派生させる場合に必要な設定について<br />// 新しい派生クラス x_LIST と、そのメンバ変数 x_SEED について、以下の設定が必須になります。<br />//<br />// ・x_SEED に、任意のメンバ変数を追加する。（任意）<br />//<br />// ・x_SEED に、任意のメンバ変数を追加した場合（ふつう追加するはず）、以下の２つの関数を再定義しなければならない<br />//&nbsp;&nbsp; void read( _SEED* dst ) {;//ここに、データの、『 this から dst へ』の『書き写し（ポインタのコピーではない!）』 に関する命令を書く }<br />//&nbsp;&nbsp; void write( _SEED* src ) {;// ...『src から this へ』の... }<br />//&nbsp;&nbsp; なお、引数の _SEED* dst および src は、どちらも『実体が存在するポインタ』が前提です。（_SEED&amp; dst および _SEED&amp; src だと考えてください）<br />//<br />// ・x_LIST の new_SEED() 関数の再定義<br />//&nbsp;&nbsp; これは _SEED 用の new オペレーターに相当する関数です。（ operator new による再定義はしてません。理由はよくわかんないからですw ） <br />//&nbsp;&nbsp; virtual _SEED* new_SEED( void ) { x_SEED* seed = new x_SEED; return( (_SEED*)seed ); }<br />//<br />// 以上<br />class _LIST {<br />protected:<br />&nbsp;&nbsp;&nbsp; _SEED*&nbsp;&nbsp;&nbsp; seed_top;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list_len;<br /><br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; size_add( int add_len );<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; size_dec( int dec_len );<br /><br />&nbsp;&nbsp;&nbsp; virtual _SEED* new_SEED( void ){ _SEED* seed = new _SEED; &nbsp;&nbsp;&nbsp; return( (_SEED*)seed ); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // new の代わりにこれを使う<br /><br />public:<br />&nbsp;&nbsp;&nbsp; _LIST();<br />&nbsp;&nbsp;&nbsp; virtual ~_LIST();<br /><br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; seek( int index );<br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; seek_top( void ) { return( seed_top ); }<br />&nbsp;&nbsp;&nbsp; virtual _SEED*&nbsp;&nbsp;&nbsp; seek_end( void ) { _SEED* end_seed = seek(list_len-1); return( end_seed ); }<br /><br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; size_set( int len );<br /><br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; read_LIST&nbsp;&nbsp;&nbsp; ( int index, int width, _LIST* dst );<br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; write_LIST&nbsp;&nbsp;&nbsp; ( int index, int width, _LIST* src );<br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; read_SEED&nbsp;&nbsp;&nbsp; ( int index, _SEED* dst );<br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; write_SEED&nbsp;&nbsp;&nbsp; ( int index, _SEED* src );<br /><br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; _list_len(void) {return(list_len);}<br /><br />//&nbsp;&nbsp;&nbsp; virtual int cut( int index, _SEED* dst );<br />//&nbsp;&nbsp;&nbsp; virtual int cut( int index, int width, _LIST* dst );<br />//&nbsp;&nbsp;&nbsp; virtual int paste( int index, _SEED* src );<br />//&nbsp;&nbsp;&nbsp; virtual int paste( int index, _LIST* src );<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; print_all_address(void);<br />};<br /></td></tr><tr><td>_LIST.cpp (0.0.9)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &quot;_LIST.h&quot;<br /><br />_LIST::_LIST()<br />{<br />&nbsp;&nbsp;&nbsp; seed_top = new_SEED();<br />&nbsp;&nbsp;&nbsp; list_len = 1;<br />}<br /><br />_LIST::~_LIST()<br />{<br />&nbsp;&nbsp;&nbsp; for(int i = list_len -1; i &gt;= 0; i-- ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _SEED* del_seed = seek(i);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( del_seed !=0 ) { delete del_seed; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />_SEED* _LIST::seek( int index )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &gt; list_len - 1 ) { index = list_len-1; }<br /><br />&nbsp;&nbsp;&nbsp; _SEED* cur_seed = seed_top;<br /><br />&nbsp;&nbsp;&nbsp; for( int i=1; i &lt;= index; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(cur_seed==0) {break;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 次が無ければ０を返す<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_seed = cur_seed-&gt;get_next();<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( cur_seed );<br />}<br /><br />void _LIST::size_add( int add_len )<br />{<br />&nbsp;&nbsp;&nbsp; _SEED* cur_seed = seek( list_len - 1 );<br />&nbsp;&nbsp;&nbsp; _SEED* new_seed;<br /><br />&nbsp;&nbsp;&nbsp; for(int i=0; i &lt; add_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new_seed = new_SEED();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_seed-&gt;add_next( new_seed );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_seed = new_seed;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; list_len += add_len;<br />}<br /><br />void _LIST::size_dec( int dec_len )<br />{<br />&nbsp;&nbsp;&nbsp; _SEED* cur_seed = seek( list_len - 1 );<br />&nbsp;&nbsp;&nbsp; _SEED* del_seed;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; dec_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_seed = cur_seed-&gt;get_back();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; del_seed = cur_seed-&gt;del_next();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete del_seed;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; list_len -= dec_len;<br />}<br /><br />void _LIST::size_set( int len )<br />{<br />&nbsp;&nbsp;&nbsp; if( len &lt;= 0 ) { len = 1; }<br /><br />&nbsp;&nbsp;&nbsp; int dif = len - list_len;<br />&nbsp;&nbsp;&nbsp; if( dif &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_add(dif);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if( dif &lt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dif = -dif;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_dec(dif);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />}<br /><br />int _LIST::read_SEED( int index, _SEED* dst )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { index = 0; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲アンダーなら最初<br />&nbsp;&nbsp;&nbsp; if( index &gt; list_len - 1 )&nbsp;&nbsp;&nbsp; { index = list_len - 1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲オーバーなら最後<br /><br />&nbsp;&nbsp;&nbsp; _SEED* buf = seek( index );<br />&nbsp;&nbsp;&nbsp; dst-&gt;write( buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // あくまでnext,back変数以外のデータのリードライトのみ<br />}<br /><br />int _LIST::write_SEED( int index, _SEED* src )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { index = 0; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲アンダーなら最初<br />&nbsp;&nbsp;&nbsp; if( index &gt; list_len - 1 )&nbsp;&nbsp;&nbsp; { size_set( index ); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲オーバーならリストを伸ばす<br /><br />&nbsp;&nbsp;&nbsp; _SEED* dst = seek( index );<br />&nbsp;&nbsp;&nbsp; dst-&gt;write( src );<br />}<br /><br />int _LIST::read_LIST( int index, int width, _LIST* dst )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { index = 0; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲アンダーなら最初<br />&nbsp;&nbsp;&nbsp; if( index &gt; list_len - 1 )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { index = list_len - 1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲オーバーなら最後<br />&nbsp;&nbsp;&nbsp; if( index + width &gt; list_len )&nbsp;&nbsp;&nbsp; { width = list_len; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 最大でも src の len 幅まで<br />&nbsp;&nbsp;&nbsp; if( width &lt;= 0 )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { width = 1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 幅が０以下なら１<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; dst-&gt;size_set(width);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // dstの幅をwidthと同じに<br /><br />&nbsp;&nbsp;&nbsp; _SEED* buf = new_SEED();<br />&nbsp;&nbsp;&nbsp; for(int si=index, di=0 ; si &lt; index + width; si++, di++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;read_SEED( si, buf );&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;write_SEED( di, buf );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; delete buf;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />}<br /><br />int _LIST::write_LIST( int index, int width, _LIST* src )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { index = 0; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲アンダーなら最初<br />&nbsp;&nbsp;&nbsp; if( width &gt; src-&gt;_list_len() )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { width = src-&gt;_list_len(); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 最大でも src の len 幅まで<br />&nbsp;&nbsp;&nbsp; if( width &lt;= 0 )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { width = 1; }<br />&nbsp;&nbsp;&nbsp; if( index + width &gt; list_len - 1 )&nbsp;&nbsp;&nbsp; { this-&gt;size_set( index + width ); }&nbsp;&nbsp;&nbsp; // 範囲オーバーならリストを伸ばす<br /><br />&nbsp;&nbsp;&nbsp; _SEED* buf = new_SEED();<br />&nbsp;&nbsp;&nbsp; for(int si=0, di=index ; di &lt; index + width; si++, di++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; src-&gt;read_SEED( si, buf );&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;write_SEED( di, buf );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; delete buf;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />}<br /><br />/*<br />int _LIST::cut( int index, _SEED* dst )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &gt; list_len - 1 ) &nbsp;&nbsp;&nbsp; { printf(&quot;err _SEED.cut() index\n&quot;); return(-1); }<br /><br />&nbsp;&nbsp;&nbsp; _<br />&nbsp;&nbsp;&nbsp; <br />}<br /><br />int _LIST::paste( int index, _SEED* src )<br />{<br />}<br /><br />int _LIST::cut( int index, int width, _LIST* dst )<br />{<br />&nbsp;&nbsp;&nbsp; if( width &lt;= 0 ) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { printf(&quot;err _LIST.cut() width\n&quot;); return(-1); }<br />&nbsp;&nbsp;&nbsp; if( index &gt; list_len - 1 ) &nbsp;&nbsp;&nbsp; { printf(&quot;err _LIST.cut() index\n&quot;); return(-1); }<br /><br />&nbsp;&nbsp;&nbsp; int s_index = index;<br />&nbsp;&nbsp;&nbsp; int e_index = index + width;<br />&nbsp;&nbsp;&nbsp; if( e_index &gt; list_len - 1 ) { e_index = list_len - 1; }<br /><br />&nbsp;&nbsp;&nbsp; int dst_size = e_index - s_index; if( dst_size &lt;= 0 ) { printf(&quot;err _LIST.cut() dst_size\n&quot;); return(-1);} <br />&nbsp;&nbsp;&nbsp; dst-&gt;size_set( dst_size );<br /><br />&nbsp;&nbsp;&nbsp; for( int si=s_index, di=0; si &lt; e_index; si++, di++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _SEED* src_seed = this-&gt;seek(si);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;add_<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst_seed-&gt;write( src_seed );<br />printf(&quot;dst_seed=%d\n&quot;,(int)dst_seed);<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return(0);<br />}<br /><br />int _LIST::paste( int index, _LIST* src )<br />{<br />}<br />*/<br /><br />void _LIST::print_all_address(void)<br />{<br />&nbsp;&nbsp;&nbsp; _SEED* cur_seed = seed_top;<br /><br />&nbsp;&nbsp;&nbsp; printf(&quot;list_len=%d\n&quot;, list_len);<br /><br />&nbsp;&nbsp;&nbsp; for(int i=0; i &lt; list_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;%d:%d\n&quot;,i,(int)cur_seed);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_seed = cur_seed-&gt;get_next();<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />}<br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>_LISTtest.cpp (動作テスト用) <br /><br />CHAR をメンバーにもつ CHAR_SEED　及び　CHAR_LIST <br />CHAR_LIST をメンバーにもつ LINE_SEED 及び LINE_LIST</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br /><br />#include &quot;_SEED.h&quot;<br />#include &quot;_LIST.h&quot;<br /><br />#include &quot;CHAR.h&quot;<br /><br />class CHAR_SEED : public _SEED {<br />protected:<br />&nbsp;&nbsp;&nbsp; CHAR*&nbsp;&nbsp;&nbsp; ch;<br /><br />public:<br />&nbsp;&nbsp;&nbsp; CHAR_SEED(){ ch = new CHAR;}<br />&nbsp;&nbsp;&nbsp; virtual ~CHAR_SEED(){ delete ch; }<br /><br />&nbsp;&nbsp;&nbsp; virtual void read( _SEED* dst ) &nbsp;&nbsp;&nbsp; { CHAR_SEED* seed = (CHAR_SEED*)dst; &nbsp;&nbsp;&nbsp; seed-&gt;ch-&gt;writeCHAR( ch ); }<br />&nbsp;&nbsp;&nbsp; virtual void write( _SEED* src )&nbsp;&nbsp;&nbsp; { CHAR_SEED* seed = (CHAR_SEED*)src; &nbsp;&nbsp;&nbsp; ch-&gt;writeCHAR( seed-&gt;ch ); }<br /><br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; write( CHAR* src ) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { return( ch-&gt;writeCHAR(src) );}<br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; write( unsigned char* src )&nbsp;&nbsp;&nbsp; { return( ch-&gt;write(src) );}<br /><br />&nbsp;&nbsp;&nbsp; virtual int print( CURSOR_CONTROL* cc ){ return( ch-&gt;print(cc) ); }<br />};<br /><br />class CHAR_LIST : public _LIST {<br />protected:<br />&nbsp;&nbsp;&nbsp; virtual _SEED* new_SEED( void ) { CHAR_SEED* seed = new CHAR_SEED; return( (_SEED*)seed ); }<br /><br />public:<br />&nbsp;&nbsp;&nbsp; CHAR_LIST() { seed_top = (_SEED*) new CHAR_SEED; }<br />&nbsp;&nbsp;&nbsp; virtual ~CHAR_LIST() {;}<br /><br />&nbsp;&nbsp;&nbsp; virtual int write_char( int index, unsigned char* str ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CHAR_SEED* seed = (CHAR_SEED*)seek(index);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( seed-&gt;write(str) );<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; virtual int write_CHAR( int index, CHAR* src ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CHAR_SEED* seed = (CHAR_SEED*)seek(index);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( seed-&gt;write( src ) );<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; virtual int write_str( unsigned char* str ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int str_len = strlen((char*)str);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int total_step = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int CHAR_count=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(int i=0; i&lt;str_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CHAR_count++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( CHAR_count &gt;&nbsp; list_len - 1 ) { size_set(CHAR_count); }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; total_step += write_char(i, &amp;(str[total_step]));<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( total_step &gt;= str_len ) { break; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(total_step);<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; virtual void print( CURSOR_CONTROL* cc ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; list_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CHAR_SEED* seed = (CHAR_SEED*)seek(i);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int step = seed-&gt;print(cc);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cc-&gt;pos_x += step;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />};<br /><br /><br /><br /><br /><br />class LINE_SEED : public _SEED {<br />protected:<br />&nbsp;&nbsp;&nbsp; CHAR_LIST*&nbsp;&nbsp;&nbsp; cl;<br /><br />public:<br />&nbsp;&nbsp;&nbsp; LINE_SEED(){ cl = new CHAR_LIST;}<br />&nbsp;&nbsp;&nbsp; virtual ~LINE_SEED(){ delete cl; }<br /><br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; read( _SEED* dst ) &nbsp;&nbsp;&nbsp; { LINE_SEED* seed = (LINE_SEED*)dst; &nbsp;&nbsp;&nbsp; seed-&gt;cl-&gt;write_LIST( 0, seed-&gt;cl-&gt;_list_len(), cl ); }<br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; write( _SEED* src )&nbsp;&nbsp;&nbsp; { LINE_SEED* seed = (LINE_SEED*)src; &nbsp;&nbsp;&nbsp; cl-&gt;write_LIST( 0, seed-&gt;cl-&gt;_list_len(), seed-&gt;cl ); }<br /><br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; write_char( int index, unsigned char* str ) &nbsp;&nbsp;&nbsp; {cl-&gt;write_char(index, str);}<br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; write_CHAR( int index, CHAR* str )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {cl-&gt;write_CHAR(index, str);}<br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; write_str ( unsigned char* str )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {cl-&gt;write_str(str);}<br /><br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; print( CURSOR_CONTROL* cc )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { cl-&gt;print(cc); }<br />};<br /><br />class LINE_LIST : public _LIST {<br />protected:<br />&nbsp;&nbsp;&nbsp; virtual _SEED* new_SEED( void ) { LINE_SEED* seed = new LINE_SEED; return( (_SEED*)seed ); }<br /><br />public:<br />&nbsp;&nbsp;&nbsp; LINE_LIST() { seed_top = (_SEED*) new LINE_SEED; }<br />&nbsp;&nbsp;&nbsp; virtual ~LINE_LIST() {;}<br /><br />&nbsp;&nbsp;&nbsp; virtual int write_char( int h, int w, unsigned char* str ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; LINE_SEED* seed = (LINE_SEED*)seek(h);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( seed-&gt;write_char( w, str ) );<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; virtual int write_CHAR( int h, int w, CHAR* src ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; LINE_SEED* seed = (LINE_SEED*)seek(h);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( seed-&gt;write_CHAR( w, src ) );<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; virtual int write_str( int h, unsigned char* str ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; LINE_SEED* seed = (LINE_SEED*)seek(h);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( seed-&gt;write_str( str ) );<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; virtual void print( CURSOR_CONTROL* cc ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; list_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; LINE_SEED* seed = (LINE_SEED*)seek(i);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seed-&gt;print(cc);<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cc-&gt;pos_x = 0; cc-&gt;pos_y++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />};<br /><br /><br /><br /><br /><br />int main()<br />{<br />&nbsp;&nbsp;&nbsp; CURSOR_CONTROL cc;<br />&nbsp;&nbsp;&nbsp; cc.clear_screen();<br />&nbsp;&nbsp;&nbsp; cc.setpos(0,0);<br /><br />&nbsp;&nbsp;&nbsp; unsigned char uc1[] = &quot;あいうえおかきくけこabcdefghij9876543210１２３４５６７８９０&quot;;<br />&nbsp;&nbsp;&nbsp; unsigned char uc2[] = &quot;aioananfwieofrjno;aignaoid;fngaiorfmnare;ofijao;finoadfna&quot;;<br />&nbsp;&nbsp;&nbsp; unsigned char uc3[] = &quot;！&rdquo;＃＄％＆&rsquo;（）０＝～｜&quot;;<br /><br />&nbsp;&nbsp;&nbsp; LINE_LIST* ll = new LINE_LIST;<br />&nbsp;&nbsp;&nbsp; ll-&gt;size_set(10);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; ll-&gt;write_str(0,uc1);<br />&nbsp;&nbsp;&nbsp; ll-&gt;write_str(1,uc2);<br />&nbsp;&nbsp;&nbsp; ll-&gt;write_str(2,uc3);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; ll-&gt;print(&amp;cc);<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; LINE_LIST* ll2 = new LINE_LIST;<br /><br />&nbsp;&nbsp;&nbsp; ll-&gt;read_LIST( 1, 1, ll2 );<br />&nbsp;&nbsp;&nbsp; cc.setpos( 0, cc.pos_y+2 );<br />&nbsp;&nbsp;&nbsp; ll2-&gt;print(&amp;cc); &nbsp;&nbsp;&nbsp; <br /><br />&nbsp;&nbsp;&nbsp; ll-&gt;write_LIST( 8, 1, ll2 );<br />&nbsp;&nbsp;&nbsp; cc.setpos( 0, cc.pos_y+2 );<br />&nbsp;&nbsp;&nbsp; ll-&gt;print(&amp;cc); &nbsp;&nbsp;&nbsp; <br /><br />&nbsp;&nbsp;&nbsp; getchar();<br />&nbsp;&nbsp;&nbsp; return(0);<br />}<br /><br /><br /><br /><br /></td></tr><tr><td>コンパイルのコマンドライン</td></tr><tr><td>gcc -o il _LISTtest.cpp _LIST.cpp _SEED.cpp CHAR.cpp CURSOR_CONTROL.cpp -lstdc++ -lc</td></tr></tbody></table><br /><br /> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-12-02T00:00:00+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-41.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-41.html</link>
<title>CHAR (0.0.8) 他</title>
<description> CHAR型を使って書き直すのをやってみて気づいたんだけど、以下の感じで途中まで書いて、「さて、次はLINE_LISTを書き直せば一段落だな&amp;hellip;」と思ったあたりで気づいたんですけど、どうも考え方としては、『文字を要素としたリスト構造』がCHAR_LIST型、『行を要素としたリスト構造』がLINE_LIST型、で、これらはどちらもリスト構造として、基本的なメカニズムがそっくりなことに気づいた。&amp;hellip;LINE_LISTを書き始めたぐらい
 </description>
<content:encoded>
<![CDATA[ CHAR型を使って書き直すのをやってみて気づいたんだけど、<br />以下の感じで途中まで書いて、「さて、次はLINE_LISTを書き直せば一段落だな&hellip;」と思ったあたりで気づいたんですけど、<br />どうも考え方としては、<br />『文字を要素としたリスト構造』がCHAR_LIST型、<br />『行を要素としたリスト構造』がLINE_LIST型、<br />で、これらはどちらもリスト構造として、基本的なメカニズムがそっくりなことに気づいた。<br />&hellip;LINE_LISTを書き始めたぐらいでこれに気づいた（苦笑orz）<br /><br />????_SEED 型に『なんらかのデータ』をぶら下げて、それを????_LIST型によって参照と追加削除を制御するっていう図式は、共通してるんですよね&hellip; CHAR_LIST型でも LINE_LIST型でも。<br /><br />だから、この２つの型から、共通した操作『要素』を抽出して、それを一つの抽象化の形にできるような気がした。<br />これは難しくするためじゃない。　これはより簡単にするため。<br /><br />まだ書いてなくて、構想だけだけど、おそらく『基本的なリスト構造』である ????_SEED と ????_LIST （まだ名前は考えてない）を、抽象的なリストクラスとして組んでみてはどうか？と思ってる。<br />当然、抽象的なので、データの実体は扱えない。　データの実体は ????_SEEDから派生したクラスにhas a関係で持たせる。<br />????_SEED をテンプレートを採るクラスとして作るやりかたはしない。<br />理由は単純に、書き方がよくわからないからです（苦笑<br />あと、テンプレートによる良い点と悪い点を、あまり考察したことが無いから、思わぬ副作用に悩まされかねないし、（いや、かならず悩まされるはず）で、つまり、めんどくさい&hellip;ってのもあります（汗<br /><br />とりあえず、『リスト的な構造』たりえる、最低限の要素は何か？　っていう考察による抽象化作業と、<br />あと、????_SEED と ????_LIST に「どんな名前をでっちあげるか（笑）」を考えて遊ぼうと思います&hellip;<br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CHAR.h (0.0.8)</td></tr><tr><td>#pragma once<br /><br />#include &quot;CURSOR_CONTROL.h&quot;<br /><br />class CHAR {<br />public:<br />//protected:<br />&nbsp;&nbsp;&nbsp; unsigned char c[4];<br />&nbsp;&nbsp;&nbsp; int mode;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 現在CHARに格納されてる文字の、使用バイト数 (ASCII=1, MultiByte=2,3,4)<br />&nbsp;&nbsp;&nbsp; int step;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 現在CHARに格納されてる文字の、表示ブロック数 (ASCII=1, MultiByte=2)<br /><br />&nbsp;&nbsp;&nbsp; virtual void calc_step(void);<br /><br />public:<br />&nbsp;&nbsp;&nbsp; CHAR(){ unsigned char c[4]=&quot; &quot;; write(c); }<br />&nbsp;&nbsp;&nbsp; virtual ~CHAR(){;}<br /><br />&nbsp;&nbsp;&nbsp; // char[4] を読み込み UTF-8 に変換して格納する。<br />&nbsp;&nbsp;&nbsp; // リターンは使用してるバイト数。判別不能の時は０を返す。<br />&nbsp;&nbsp;&nbsp; virtual int write&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ( unsigned char* src );<br />&nbsp;&nbsp;&nbsp; virtual int writeCHAR&nbsp;&nbsp;&nbsp; ( CHAR* src ){ return( write( src-&gt;c ) ); }<br /><br />&nbsp;&nbsp;&nbsp; // char[4] に UTF-8 の先頭バイトから順に格納する。<br />&nbsp;&nbsp;&nbsp; // ただし、使用されるバイト数は、モードの必要分&rdquo;だけ&rdquo;であり、<br />&nbsp;&nbsp;&nbsp; // それ以降のバイトには一切触れない（値を変えない・アクセスすらしない）<br />&nbsp;&nbsp;&nbsp; // 戻り値には、使用しているバイト数が返される。０の場合はほぼエラーを意味する。<br />&nbsp;&nbsp;&nbsp; virtual int read&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ( unsigned char* dst );<br />&nbsp;&nbsp;&nbsp; virtual int readCHAR&nbsp;&nbsp;&nbsp; ( CHAR* dst ){ return( read( dst-&gt;c ) ); }<br /><br />&nbsp;&nbsp;&nbsp; // 指定したカーソル位置に一文字表示する<br />&nbsp;&nbsp;&nbsp; // 戻り値は、文字の表示に使用したブロック数。ASCII（半角文字）の場合は1ブロック、非ASCII（全角文字）の場合は2ブロック<br />&nbsp;&nbsp;&nbsp; // カーソル位置は、表示後も変わらない。（自動では進まない）<br />&nbsp;&nbsp;&nbsp; virtual int print( CURSOR_CONTROL* cc );<br /><br />&nbsp;&nbsp;&nbsp; virtual int _mode(void){ return( mode ); }<br />&nbsp;&nbsp;&nbsp; virtual int _step(void){ return( step ); }<br />};<br /><br /><br /></td></tr><tr><td>CHAR.cpp (0.0.8)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &quot;CHAR.h&quot;<br />#include &quot;CURSOR_CONTROL.h&quot;<br /><br />void CHAR::calc_step(void)<br />{<br />&nbsp;&nbsp;&nbsp; switch(mode){<br />&nbsp;&nbsp;&nbsp; case 0: step = 0; break;<br />&nbsp;&nbsp;&nbsp; case 1: step = 1; break;&nbsp;&nbsp;&nbsp; // ASCII 半角文字なら<br />&nbsp;&nbsp;&nbsp; case 2: step = 2; break;&nbsp;&nbsp;&nbsp; // 非ASCIIは全て全角文字として扱う。（半角カナなどは考慮しない）<br />&nbsp;&nbsp;&nbsp; case 3: step = 2; break;<br />&nbsp;&nbsp;&nbsp; case 4: step = 2; break;<br />&nbsp;&nbsp;&nbsp; default: step = 0; break;<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />}<br /><br />// char[4] を読み込み UTF-8 に変換して格納する。<br />// リターンは使用してるバイト数。判別不能の時は０を返す。<br />int CHAR::write( unsigned char* src )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR* dst = this;<br /><br />&nbsp;&nbsp;&nbsp; dst-&gt;mode = 0;<br /><br />&nbsp;&nbsp;&nbsp; unsigned char c0 = src[0];<br />&nbsp;&nbsp;&nbsp; unsigned char c1;<br />&nbsp;&nbsp;&nbsp; unsigned char c2;<br />&nbsp;&nbsp;&nbsp; unsigned char c3;<br /><br />&nbsp;&nbsp;&nbsp; // 先頭bitが1ならマルチバイト文字、0ならASCII文字<br />&nbsp;&nbsp;&nbsp; if( ( c0 &amp; 0x80 ) == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[0] = c0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 1;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 第2bitが0なら先頭以外の文字、1なら先頭文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x40 ) == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[0] = c0;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 第3bitが0なら２バイト文字、1なら３バイト以上の文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x20 ) == 0 )&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = src[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 2;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ...かつ、第４bitが0なら３バイト文字、1なら４バイト文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x10 ) == 0 )&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = src[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = src[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 3;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = src[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = src[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = src[3];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 4;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; calc_step();<br /><br />&nbsp;&nbsp;&nbsp; return( dst-&gt;mode );<br />}<br /><br />// char[4] に UTF-8 の先頭バイトから順に格納する。<br />// ただし、使用されるバイト数は、モードの必要分&rdquo;だけ&rdquo;であり、<br />// それ以降のバイトには一切触れない（値を変えない・アクセスすらしない）<br />// 戻り値には、使用しているバイト数が返される。０の場合はほぼエラーを意味する。<br />int CHAR::read( unsigned char* dst )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR* src = this;<br /><br />&nbsp;&nbsp;&nbsp; switch(src-&gt;mode){<br />&nbsp;&nbsp;&nbsp; case 1:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(1);<br />&nbsp;&nbsp;&nbsp; case 2:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1] = src-&gt;c[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(2);<br />&nbsp;&nbsp;&nbsp; case 3:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1] = src-&gt;c[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[2] = src-&gt;c[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(3);<br />&nbsp;&nbsp;&nbsp; case 4:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1] = src-&gt;c[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[2] = src-&gt;c[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[3] = src-&gt;c[3];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(4);<br />&nbsp;&nbsp;&nbsp; default:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(0);<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />// 指定したカーソル位置に一文字表示する<br />// 戻り値は、文字の表示に使用したブロック数。ASCII（半角文字）の場合は1ブロック、非ASCII（全角文字）の場合は2ブロック<br />// カーソル位置は、表示後も変わらない。（自動では進まない）<br />int CHAR::print( CURSOR_CONTROL* cc )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char c[4];<br />&nbsp;&nbsp;&nbsp; read( c );<br /><br />&nbsp;&nbsp;&nbsp; cc-&gt;__setpos( cc-&gt;pos_x, cc-&gt;pos_y);&nbsp;&nbsp;&nbsp; // カーソル位置をセット<br />&nbsp;&nbsp;&nbsp; for( int i=0; i &lt; mode; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; putchar( c[i] );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; cc-&gt;__setpos( cc-&gt;pos_x, cc-&gt;pos_y );&nbsp;&nbsp;&nbsp; // putchar() の実行で変わったであろうカーソル位置を、元にもどす（自動での移動はさせない）<br /><br />&nbsp;&nbsp;&nbsp; return( step );&nbsp;&nbsp;&nbsp; <br />}<br /><br /><br /><br /><br /><br /><br /><br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CHAR_SEED.h (0.0.8)</td></tr><tr><td>#pragma once<br /><br />#include &quot;CHAR.h&quot;<br />&nbsp;<br />class CHAR_SEED {<br />protected:<br />&nbsp;&nbsp;&nbsp; CHAR &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c;<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* &nbsp;&nbsp;&nbsp; next;<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* &nbsp;&nbsp;&nbsp; back;<br /><br />public:<br />&nbsp;&nbsp;&nbsp; CHAR_SEED(){ next = 0; back = 0; }<br />&nbsp;&nbsp;&nbsp; virtual ~CHAR_SEED(){ ; }<br /><br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; add_next( CHAR_SEED* cs );<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; add_back( CHAR_SEED* cs );<br /><br />&nbsp;&nbsp;&nbsp; virtual CHAR_SEED*&nbsp;&nbsp;&nbsp; del_next( void );<br />&nbsp;&nbsp;&nbsp; virtual CHAR_SEED*&nbsp;&nbsp;&nbsp; del_back( void );<br /><br />&nbsp;&nbsp;&nbsp; virtual CHAR_SEED* get_next( void ) { return( next ); }<br />&nbsp;&nbsp;&nbsp; virtual CHAR_SEED* get_back( void ) { return( back ); }<br /><br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; write&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ( unsigned char* src )&nbsp;&nbsp;&nbsp; { return( c.write( src ) ); }<br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; writeCHAR&nbsp;&nbsp;&nbsp; ( CHAR* src )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { return( c.writeCHAR( src ) ); }<br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; read&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ( unsigned char* dst )&nbsp;&nbsp;&nbsp; { return( c.read( dst ) ); }<br />&nbsp;&nbsp;&nbsp; virtual int &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; readCHAR&nbsp;&nbsp;&nbsp; ( CHAR* dst )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { return( c.readCHAR( dst ) ); }<br /><br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print( CURSOR_CONTROL* cc )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { return( c.print( cc ) ); } <br />};<br /><br /><br /></td></tr><tr><td>CHAR_SEED.cpp (0.0.8)</td></tr><tr><td>#include &quot;CHAR_SEED.h&quot;<br /><br />void CHAR_SEED::add_next( CHAR_SEED* cs )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // next に cs を挿入<br />{<br />&nbsp;&nbsp;&nbsp; if( cs == 0 ) { this-&gt;next = 0; return; };&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // cs がNullならnextに０（終端記号）をセットしてリターン<br /><br />&nbsp;&nbsp;&nbsp; if( this-&gt;next != 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;next-&gt;back = cs;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; cs-&gt;next&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = this-&gt;next;<br />&nbsp;&nbsp;&nbsp; cs-&gt;back&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = this;<br /><br />&nbsp;&nbsp;&nbsp; this-&gt;next&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = cs;<br />}<br /><br />void CHAR_SEED::add_back( CHAR_SEED* cs )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // back に cs を挿入<br />{<br />&nbsp;&nbsp;&nbsp; if( cs == 0 ) { this-&gt;back = 0; return; };&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // cs がNullならbackに０（終端記号）をセットしてリターン<br /><br />&nbsp;&nbsp;&nbsp; if( this-&gt;back != 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;back-&gt;next = cs;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; cs-&gt;next&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = this;<br />&nbsp;&nbsp;&nbsp; cs-&gt;back&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = this-&gt;back;<br /><br />&nbsp;&nbsp;&nbsp; this-&gt;back&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = cs;<br />}<br /><br />CHAR_SEED* CHAR_SEED::del_next( void )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // next を１個除外（単にリストから除外されるだけ。メモリ開放は行われない）<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* del_cs = this-&gt;next;<br /><br />&nbsp;&nbsp;&nbsp; if( del_cs != 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( del_cs-&gt;next != 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; del_cs-&gt;next-&gt;back = this;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;next = del_cs-&gt;next;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;next = 0;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( del_cs );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 除外された cs のアドレスをリターン<br />}<br /><br />CHAR_SEED* CHAR_SEED::del_back( void )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // next を１個除外（単にリストから除外されるだけ。メモリ開放は行われない）<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* del_cs = this-&gt;back;<br /><br />&nbsp;&nbsp;&nbsp; if( del_cs != 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( del_cs-&gt;back != 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; del_cs-&gt;back-&gt;next = this;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;back = del_cs-&gt;back;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this-&gt;back = 0;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( del_cs );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 除外された cs のアドレスをリターン<br />}<br /><br /><br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CHAR_LIST.h (0.0.8)</td></tr><tr><td>#pragma once<br /><br />#include &quot;CHAR_SEED.h&quot;<br />#include &quot;STRING.h&quot;<br />&nbsp;<br />class CHAR_LIST {<br />private:<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_add( int add_len );<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_dec( int dec_len );<br /><br />protected:<br />&nbsp;&nbsp;&nbsp; CHAR_SEED*&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cs_top;<br />&nbsp;&nbsp;&nbsp; int &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list_len;<br /><br />&nbsp;&nbsp;&nbsp; virtual CHAR_SEED*&nbsp;&nbsp;&nbsp; seek( int index );<br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_set( int set_len );<br /><br />public:<br />&nbsp;&nbsp;&nbsp; CHAR_LIST();<br />&nbsp;&nbsp;&nbsp; virtual ~CHAR_LIST();<br /><br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; writeCHAR&nbsp;&nbsp;&nbsp; ( int index, CHAR* ch );<br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; writeSTRING&nbsp;&nbsp;&nbsp; ( STRING* str );<br />&nbsp;&nbsp;&nbsp; virtual void &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; readCHAR&nbsp;&nbsp;&nbsp; ( int index, CHAR* ch );<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; readSTRING&nbsp;&nbsp;&nbsp; ( STRING* str );<br /><br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ( CURSOR_CONTROL* cc );<br /><br />&nbsp;&nbsp;&nbsp; virtual int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _list_len&nbsp;&nbsp;&nbsp; (void){ return(list_len); }<br />};<br /><br /><br /><br /></td></tr><tr><td>CHAR_LIST.cpp (0.0.8)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &quot;CHAR_LIST.h&quot;<br />&nbsp;<br />CHAR_LIST::CHAR_LIST()<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char space[4] = &quot; &quot;;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; cs_top = new CHAR_SEED;<br />&nbsp;&nbsp;&nbsp; cs_top-&gt;write( space );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 初期値はスペース<br />&nbsp;&nbsp;&nbsp; list_len = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // リスト長は１文字<br />}<br /><br />CHAR_LIST::&oline;CHAR_LIST()<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* cs;<br />&nbsp;&nbsp;&nbsp; cs = this-&gt;seek( list_len - 1 );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // clの最後のcsのアドレス<br /><br />&nbsp;&nbsp;&nbsp; for( int i=list_len-1; i&gt;=1; i-- ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // cs が先頭になるまで繰り返す<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cs = cs-&gt;get_back();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // csをリストひとつ戻る<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete cs-&gt;get_next();<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; delete cs;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 最後に先頭のcsを開放<br />}<br /><br />CHAR_SEED* CHAR_LIST::seek( int index )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // csのシーク<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* seek_cs = cs_top;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; if( index &lt;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) { index = 0; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲アンダーなら最小値<br />&nbsp;&nbsp;&nbsp; if( index &gt;= list_len ) { index = list_len -1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲オーバーなら最大値<br /><br />&nbsp;&nbsp;&nbsp; while( index &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seek_cs = seek_cs-&gt;get_next();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; index--;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( seek_cs );<br />}<br /><br />void CHAR_LIST::size_add( int add_len )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 終端以降にcsをadd_len分だけ追加する<br />{<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* end_cs = seek(list_len-1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 終端のcs<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* new_cs;<br /><br />&nbsp;&nbsp;&nbsp; for(int i=0; i&lt;add_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new_cs = new CHAR_SEED;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 新しいcs一個分のメモリを確保&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end_cs-&gt;add_next( new_cs );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 終端に追加<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end_cs = end_cs-&gt;get_next();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 終点を次に進める<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; end_cs-&gt;add_next( (CHAR_SEED*)0 );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 最後にフタ<br /><br />&nbsp;&nbsp;&nbsp; list_len += add_len;<br />}<br /><br />void CHAR_LIST::size_dec( int dec_len )<br />{<br />&nbsp;&nbsp;&nbsp; int dif = list_len - dec_len;<br />&nbsp;&nbsp;&nbsp; if( dif &lt;= 0 ) { dec_len = list_len -1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // difが０以下になってしまう場合は、difが１になる数をセットする<br /><br />&nbsp;&nbsp;&nbsp; CHAR_SEED* end_cs = seek(list_len-1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 終端のcs<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* cur_cs = end_cs-&gt;get_back();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 終端の一個手前の位置<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* del_cs;<br /><br />&nbsp;&nbsp;&nbsp; for(int i=0; i&lt;dec_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; del_cs = cur_cs-&gt;del_next();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete del_cs;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_cs = cur_cs-&gt;get_back();<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; cur_cs-&gt;add_next( (CHAR_SEED*)0 );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 最後にフタ<br /><br />&nbsp;&nbsp;&nbsp; list_len -= dec_len;<br />}<br />&nbsp;<br />void CHAR_LIST::size_set( int set_len )<br />{<br />&nbsp;&nbsp;&nbsp; if( set_len &lt;= 0 ) { set_len = 1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ０以下の長さを指定されたら１に<br /><br />&nbsp;&nbsp;&nbsp; int dif = set_len - list_len;<br /><br />&nbsp;&nbsp;&nbsp; if( dif &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_add( dif );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if ( dif &lt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dif = -dif;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 絶対値に（ーだったはずなので）<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_dec( dif );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;<br />&nbsp;&nbsp;&nbsp; }<br />}<br />&nbsp;<br />void CHAR_LIST::writeCHAR( int index, CHAR* ch )<br />{<br />&nbsp;&nbsp;&nbsp; if ( index &lt; 0 ) { index = 0; } &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // index の範囲が０未満の場合、０にする。<br /><br />&nbsp;&nbsp;&nbsp; int dif = index - (list_len - 1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // index がリスト長を越えた場合、メモリー確保<br />&nbsp;&nbsp;&nbsp; if( dif &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_set( index + 1 );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* cs = seek( index );<br />&nbsp;&nbsp;&nbsp; cs-&gt;writeCHAR( ch );<br />}<br /><br />void CHAR_LIST::writeSTRING( STRING* src )<br />{<br />&nbsp;&nbsp;&nbsp; size_set( src-&gt;_len() );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // clをsrcの長さと同じにする<br />&nbsp;&nbsp;&nbsp; CHAR buf;<br /><br />&nbsp;&nbsp;&nbsp; for( int i = 0; i &lt; src-&gt;_len(); i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // srcの長さ分...<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; src-&gt;readCHAR( i, &amp;buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // srcから読み込み...<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; writeCHAR( i, &amp;buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // clに書き込む<br />&nbsp;&nbsp;&nbsp; }<br />}<br />&nbsp;<br />void CHAR_LIST::readCHAR( int index, CHAR* ch )<br />{<br />&nbsp;&nbsp;&nbsp; if ( index &lt;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) { index = 0; } &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // index の範囲が０未満の場合、０にする。<br />&nbsp;&nbsp;&nbsp; if ( index &gt;= list_len ) { index = list_len - 1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // index の範囲が最大値を越えた場合、最大値に。<br /><br />&nbsp;&nbsp;&nbsp; CHAR_SEED* cs = seek( index );<br />&nbsp;&nbsp;&nbsp; cs-&gt;readCHAR( ch );<br />}<br /><br />void CHAR_LIST::readSTRING( STRING* dst )<br />{<br />&nbsp;&nbsp;&nbsp; CHAR buf;<br />&nbsp;&nbsp;&nbsp; dst-&gt;size_set( list_len );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // dstをclと同じ長さにする<br /><br />&nbsp;&nbsp;&nbsp; for( int i = 0; i &lt; dst-&gt;_len(); i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; readCHAR( i, &amp;buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // clから読み込み...<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;writeCHAR( i, &amp;buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // dstに書き込む<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />int CHAR_LIST::print( CURSOR_CONTROL* cc )<br />{<br />&nbsp;&nbsp;&nbsp; CURSOR_CONTROL cur_cc = *cc;<br /><br />&nbsp;&nbsp;&nbsp; int total_step = 0;<br />&nbsp;&nbsp;&nbsp; int step;<br />&nbsp;&nbsp;&nbsp; CHAR_SEED* cur_cs = cs_top;<br /><br />&nbsp;&nbsp;&nbsp; for( int i=0; i&lt;list_len; i++ ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; step = cur_cs-&gt;print(&amp;cur_cc);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_cs = cur_cs-&gt;get_next();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_cc.pos_x += step;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; total_step += step; <br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; cc-&gt;setpos(cc-&gt;pos_x, cc-&gt;pos_y);<br />&nbsp;&nbsp;&nbsp; return( total_step );<br />}<br /><br />&nbsp;<br />&nbsp;<br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>STRING.h (0.0.8)</td></tr><tr><td>#pragma once<br /><br />#include &quot;CHAR.h&quot;<br />#include &quot;CURSOR_CONTROL.h&quot;<br /><br />class STRING {<br />protected:<br />&nbsp;&nbsp;&nbsp; CHAR*&nbsp;&nbsp;&nbsp; str;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; len;<br /><br />&nbsp;&nbsp;&nbsp; virtual void size_add( int add_len );<br />&nbsp;&nbsp;&nbsp; virtual void size_dec( int dec_len );<br /><br />public:<br />&nbsp;&nbsp;&nbsp; STRING();<br />&nbsp;&nbsp;&nbsp; virtual ~STRING();<br /><br />&nbsp;&nbsp;&nbsp; virtual void size_set( int set_len );<br /><br />&nbsp;&nbsp;&nbsp; virtual int write_char&nbsp;&nbsp;&nbsp; ( int index, &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned char* src );<br />&nbsp;&nbsp;&nbsp; virtual int write_str&nbsp;&nbsp;&nbsp; ( unsigned char* src );<br />&nbsp;&nbsp;&nbsp; virtual int writeCHAR &nbsp;&nbsp;&nbsp; ( int index, &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CHAR* src );<br />&nbsp;&nbsp;&nbsp; virtual int writeSTRING( STRING* src );<br /><br />&nbsp;&nbsp;&nbsp; virtual int read_char&nbsp;&nbsp;&nbsp; ( int index, &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned char* dst );<br />&nbsp;&nbsp;&nbsp; virtual int read_str&nbsp;&nbsp;&nbsp; ( unsigned char* dst );<br />&nbsp;&nbsp;&nbsp; virtual int readCHAR&nbsp; &nbsp;&nbsp;&nbsp; ( int index, &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CHAR* dst );<br />&nbsp;&nbsp;&nbsp; virtual int readSTRING&nbsp;&nbsp;&nbsp; ( STRING* dst );<br /><br />&nbsp;&nbsp;&nbsp; virtual void print( CURSOR_CONTROL* cc );<br /><br />&nbsp;&nbsp;&nbsp; virtual int _len(void) { return(len); }<br />};<br /><br /><br /><br /></td></tr><tr><td>STRING.cpp (0.0.8)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br />#include &quot;STRING.h&quot;<br />#include &quot;CHAR.h&quot;<br />#include &quot;CURSOR_CONTROL.h&quot;<br /><br />STRING::STRING()<br />{<br />&nbsp;&nbsp;&nbsp; len&nbsp;&nbsp;&nbsp; = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // lenには文字数が入る。データのバイト量ではないので注意。あくまで文字数。<br />&nbsp;&nbsp;&nbsp; str&nbsp;&nbsp;&nbsp; = new CHAR[len];<br />}<br /><br />STRING::~STRING()<br />{<br />&nbsp;&nbsp;&nbsp; delete[] str;<br />}<br /><br />void STRING::size_add( int add_len )<br />{<br />&nbsp;&nbsp;&nbsp; int new_len = len + add_len;<br />&nbsp;&nbsp;&nbsp; CHAR* buf = new CHAR[new_len];<br /><br />&nbsp;&nbsp;&nbsp; for( int i=0; i&lt;len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; readCHAR( i, &amp;(buf[i]) );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バッファに退避<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; delete[] str;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 古いメモリを開放<br /><br />&nbsp;&nbsp;&nbsp; str = buf;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バッファのポインタを書き込む<br />&nbsp;&nbsp;&nbsp; len = new_len;<br />}<br /><br />void STRING::size_dec( int dec_len )<br />{<br />&nbsp;&nbsp;&nbsp; int new_len = len - dec_len;<br /><br />&nbsp;&nbsp;&nbsp; CHAR* buf = new CHAR[len];<br />&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf[i] = str[i];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バッファに退避<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; delete[] str;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // メモリ開放...<br />&nbsp;&nbsp;&nbsp; str = new CHAR[new_len];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // メモリ確保<br /><br />&nbsp;&nbsp;&nbsp; for( int i=0; i &lt; new_len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; str[i] = buf[i];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 退避先から必要量だけ書きもどす<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; len = new_len;<br />}<br /><br />void STRING::size_set( int set_len )<br />{<br />&nbsp;&nbsp;&nbsp; if( set_len &lt;= 0 ) { set_len = 1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ０以下なら、１をセット（最低でも１になる）<br />&nbsp;&nbsp;&nbsp; int dif = set_len - len;<br /><br />&nbsp;&nbsp;&nbsp; if( dif &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_add( dif );&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if( dif &lt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dif = -dif;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_dec( dif );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />int STRING::write_char( int index, unsigned char* src )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) { index = 0; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // index の範囲丸め<br /><br />&nbsp;&nbsp;&nbsp; if( len &lt;= index ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // メモリが足りなかったら確保する<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int old_len = len;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; len = index + 1;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CHAR* old_str = str;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; str = new CHAR[len];<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(int i=0; i&lt;old_len; i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 古い内容のコピー<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; str[i] = old_str[i];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(int i=old_len; i&lt;len; i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 新規確保分はスペースで埋める<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned char buf[4] = &quot; &quot;;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; str[i].write( buf );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete[] old_str;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 古いメモリを開放<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( str[index].write(src) );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // srcをCHARに書き込み、使用したバイト数をリターンする&nbsp;&nbsp;&nbsp; <br />}<br /><br />int STRING::write_str( unsigned char* src )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 文字列srcの最後は必ず \0 であること<br />{<br />&nbsp;&nbsp;&nbsp; int byte_len = strlen((char*)src);<br />&nbsp;&nbsp;&nbsp; if( byte_len &lt;= 0 ) { return(0); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // srcのbyte長が０以下なら０でリターン<br /><br />&nbsp;&nbsp;&nbsp; int dif = byte_len - len;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 書き込み文字数に対する lenの不足文字数を得る（すべてASCIIと想定。十分量）<br />&nbsp;&nbsp;&nbsp; if( dif &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 不足分があるなら、足りない分を確保する<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete[] str;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; len = byte_len;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; str = new CHAR[len];<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; len = byte_len;<br /><br />&nbsp;&nbsp;&nbsp; int step=0;<br />&nbsp;&nbsp;&nbsp; int s=0;<br />&nbsp;&nbsp;&nbsp; for(int i=0; i&lt;len; i++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; step += s;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s = str[i].write( &amp;(src[step]) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( s==0 || src[step] == '\0' ){ len = i; return( step ); }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( step );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // srcをCHAR配列に書き込んだ際の、使用した総バイト数をリターンする<br />}<br /><br />int STRING::writeCHAR( int index, CHAR* src )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char buf[4];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バッファーの確保<br />&nbsp;&nbsp;&nbsp; for(int i=0; i&lt;4; i++ ){ buf[i] = ' '; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バッファーをスペース文字で初期化<br /><br />&nbsp;&nbsp;&nbsp; src-&gt;read( buf );<br />&nbsp;&nbsp;&nbsp; return( write_char( index, buf ) );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // bufをCHARに書き込み、使用したバイト数をリターンする&nbsp;&nbsp;&nbsp; <br />}<br /><br />int STRING::writeSTRING( STRING* src )<br />{<br />&nbsp;&nbsp;&nbsp; if( src-&gt;len &lt;= 0 ) { return(0); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 文字数が０以下なら０でリターン<br /><br />&nbsp;&nbsp;&nbsp; unsigned char* buf = new unsigned char[src-&gt;len * 4];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バッファーの確保<br />&nbsp;&nbsp;&nbsp; for(int i=0; i&lt;src-&gt;len * 4; i++ ){ buf[i] = ' '; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バッファーをスペース文字で初期化<br /><br />&nbsp;&nbsp;&nbsp; src-&gt;read_str( buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // src からバッファへ文字データを読み込み<br />&nbsp;&nbsp;&nbsp; int step = write_str( buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // bufをCHAR配列に書き込み、使用した総バイト数をリターンするため<br /><br />&nbsp;&nbsp;&nbsp; delete[] buf;<br />&nbsp;&nbsp;&nbsp; return(step);&nbsp;&nbsp;&nbsp; <br />}<br /><br />int STRING::read_char( int index, unsigned char* dst )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &gt;= len ) { return(-1); }<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) { return(-1); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲外だったら読まずにリターン<br /><br />&nbsp;&nbsp;&nbsp; return( str[index].read( dst ) );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // dstに一文字分を読み込み、使用バイト数をリターンする<br />}<br /><br />int STRING::read_str( unsigned char* dst )<br />{<br />&nbsp;&nbsp;&nbsp; if( len &lt;= 0 ) { return(-1); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 文字数が０なら何もせずー１でリターン<br /><br />&nbsp;&nbsp;&nbsp; int step=0;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(int i=0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; step += str[i].read( &amp;(dst[step]) );<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; dst[step]='\0';&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 生成した文字列の最後に \0 を付加する<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return( step );<br />}<br /><br />int STRING::readCHAR( int index, CHAR* dst )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &gt;= len ) { return(-1); }<br />&nbsp;&nbsp;&nbsp; if( index &lt; 0 ) { return(-1); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 範囲外だったら読まずにリターン<br /><br />&nbsp;&nbsp;&nbsp; unsigned char buf[4];<br />&nbsp;&nbsp;&nbsp; str[index].read( buf );<br />&nbsp;&nbsp;&nbsp; return( dst-&gt;write( buf ) );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // dstに一文字分を読み込み、使用バイト数をリターンする&nbsp;&nbsp;&nbsp; <br />}<br /><br />int STRING::readSTRING( STRING* dst )<br />{<br />&nbsp;&nbsp;&nbsp; return( dst-&gt;writeSTRING( this ) );<br />}<br /><br />void STRING::print( CURSOR_CONTROL* cc )<br />{<br />&nbsp;&nbsp;&nbsp; CURSOR_CONTROL old = *cc;<br />&nbsp;&nbsp;&nbsp; int step;<br /><br />&nbsp;&nbsp;&nbsp; for(int i=0; i&lt;len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cc-&gt;setpos(cc-&gt;pos_x, cc-&gt;pos_y);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; step = str[i].print(cc);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cc-&gt;pos_x += step;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; *cc = old;<br />&nbsp;&nbsp;&nbsp; cc-&gt;setpos(cc-&gt;pos_x, cc-&gt;pos_y);<br />}<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></td></tr></tbody></table><br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>FILE_IO.h (0.0.8)</td></tr><tr><td>#pragma once<br />&nbsp;<br />#include &lt;stdio.h&gt;<br />#include &quot;CHAR.h&quot;<br />&nbsp;<br />class FILE_IO {<br />public:<br />&nbsp;&nbsp;&nbsp; FILE* fp;<br />&nbsp;&nbsp;&nbsp; int open_flag;<br /><br />public:<br />&nbsp;&nbsp;&nbsp; FILE_IO( char* file_name );<br />&nbsp;&nbsp;&nbsp; virtual ~FILE_IO();<br /><br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; seek_set( long adrs );<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; seek_cur( long adrs );<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; seek_end( long adrs );<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; virtual long&nbsp;&nbsp;&nbsp; tell( void );<br /><br />&nbsp;&nbsp;&nbsp; // CHAR型へのファイルからの一文字読み込み、そしてファイルポインタを次の文字の先頭位置へ。<br />&nbsp;&nbsp;&nbsp; // ファイルエラー、またはファイル終了の場合は EOF を返す。通常は現在のファイルシークのアドレスを返す。<br />&nbsp;&nbsp;&nbsp; // （char[4] を読み込んで、状況に応じて読み込み、シーク調整を行ってる）<br />&nbsp;&nbsp;&nbsp; virtual long read_char( CHAR* ch );<br /><br />&nbsp;&nbsp;&nbsp; // CHAR型からのファイルへの一文字書き込み。そしてファイルポインタを次の文字の先頭位置へ。<br />&nbsp;&nbsp;&nbsp; // リターンは書き込んだバイト数を返す。UTF-8マルチバイトで帰ってくる可能性があるのは 1,2,3,4 のどれか。<br />&nbsp;&nbsp;&nbsp; // リターンが 0 の場合は文字が書き込まれなかったという意味。とうぜん、ファイルポインタも進まない。<br />&nbsp;&nbsp;&nbsp; virtual long write_char( CHAR* ch );<br />};<br />&nbsp;<br />&nbsp;<br /><br /></td></tr><tr><td>FILE_IO.cpp (0.0.8)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;string.h&gt;<br />#include &quot;FILE_IO.h&quot;<br />#include &quot;CHAR.h&quot;<br />&nbsp;<br />FILE_IO::FILE_IO( char* file_name )<br />{<br />&nbsp;&nbsp;&nbsp; fp = fopen( file_name, &quot;r+&quot; );<br />&nbsp;&nbsp;&nbsp; open_flag = 1;<br />}<br />&nbsp;<br />FILE_IO::~FILE_IO()<br />{<br />&nbsp;&nbsp;&nbsp; if( open_flag == 1 ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fclose( fp );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; open_flag=0;<br />&nbsp;&nbsp;&nbsp; }<br />}<br />&nbsp;<br />void FILE_IO::seek_set( long adrs )<br />{<br />&nbsp;&nbsp;&nbsp; fseek( fp, adrs, SEEK_SET );<br />}<br /><br />void FILE_IO::seek_cur( long adrs )<br />{<br />&nbsp;&nbsp;&nbsp; fseek( fp, adrs, SEEK_CUR );<br />}<br /><br />void FILE_IO::seek_end( long adrs )<br />{<br />&nbsp;&nbsp;&nbsp; fseek( fp, adrs, SEEK_END );<br />}<br />&nbsp;<br />long FILE_IO::tell( void )<br />{<br />&nbsp;&nbsp;&nbsp; return( ftell(fp) );<br />}<br /><br />// CHAR型へのファイルからの一文字読み込み、そしてファイルポインタを次の文字の先頭位置へ。<br />// ファイルエラー、またはファイル終了の場合は EOF を返す。通常は現在のファイルシークのアドレスを返す。<br />// （char[4] を読み込んで、状況に応じて読み込み、シーク調整を行ってる）<br />long FILE_IO::read_char( CHAR* ch )<br />{<br />&nbsp;&nbsp;&nbsp; long a = tell();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 読み込み開始位置の保存<br /><br />&nbsp;&nbsp;&nbsp; unsigned char c[4];<br />&nbsp;&nbsp;&nbsp; c[0] =<br />&nbsp;&nbsp;&nbsp; c[1] =<br />&nbsp;&nbsp;&nbsp; c[2] =<br />&nbsp;&nbsp;&nbsp; c[3] = 0;<br /><br />&nbsp;&nbsp;&nbsp; // 一文字ずつ c[] に読み込む、この際、EOF の文字の次以降は 0 になっているはず。<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for ( i = 0; i &lt; 4; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c[i] = (unsigned char)fgetc(fp);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( c[i] == EOF ) { break; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; // 先頭バイトがEOFじゃなければ CHAR に書き込み、結果、判別されたマルチバイト文字の<br />&nbsp;&nbsp;&nbsp; // バイト数に応じて、ファイルシークを調節する（次の文字の先頭バイトへ）<br />&nbsp;&nbsp;&nbsp; if ( c[0] != EOF ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch( ch-&gt;write( c ) ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0:&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seek_set( a + 1 );&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 1:&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seek_set( a + 1 );&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 2:&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seek_set( a + 2 );&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 3:&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; seek_set( a + 3 );&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 4:&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( EOF );<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( tell() );<br />}<br /><br />// CHAR型からのファイルへの一文字書き込み。そしてファイルポインタを次の文字の先頭位置へ。<br />// リターンは書き込んだバイト数を返す。UTF-8マルチバイトで帰ってくる可能性があるのは 1,2,3,4 のどれか。<br />// リターンが 0 の場合は文字が書き込まれなかったという意味。とうぜん、ファイルポインタも進まない。<br />long FILE_IO::write_char( CHAR* ch )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char c[4];<br />&nbsp;&nbsp;&nbsp; long len = ch-&gt;read( c );<br /><br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for( i = 0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fputc( c[i], fp );<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( len );<br />}<br />&nbsp;<br /><br /><br /><br /><br /><br /><br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CURSOR_CONTROL.h (0.0.8)</td></tr><tr><td>#pragma once<br /><br />class CURSOR_CONTROL {<br />public:<br />&nbsp;&nbsp;&nbsp; int pos_x;&nbsp;&nbsp;&nbsp; // カーソルの現在位置<br />&nbsp;&nbsp;&nbsp; int pos_y;<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; int scr_w;&nbsp;&nbsp;&nbsp; // スクリーンの幅・高さ<br />&nbsp;&nbsp;&nbsp; int scr_h;<br /><br />public:<br />&nbsp;&nbsp;&nbsp; CURSOR_CONTROL();<br />&nbsp;&nbsp;&nbsp; virtual &oline;CURSOR_CONTROL();<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; // 単純にカーソル位置を移動するのみ。内部処理的にプリント位置を調整する目的の時はこちら<br />&nbsp;&nbsp;&nbsp; virtual void __setpos( int x, int y );<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; // cc にカーソル位置情報を保存しつつ移動する。通常のカーソル移動はこちら<br />&nbsp;&nbsp;&nbsp; virtual void setpos( int x, int y );<br /><br />&nbsp;&nbsp;&nbsp; // カーソルを１マス移動する（画面の外周外に出た場合は、外周位置に留まる）<br />&nbsp;&nbsp;&nbsp; virtual void move_right( void );<br />&nbsp;&nbsp;&nbsp; virtual void move_left ( void );<br />&nbsp;&nbsp;&nbsp; virtual void move_up&nbsp;&nbsp; ( void );<br />&nbsp;&nbsp;&nbsp; virtual void move_down ( void );<br /><br />&nbsp;&nbsp;&nbsp; // キー入力を得る<br />&nbsp;&nbsp;&nbsp; virtual char get_key(void);<br /><br />&nbsp;&nbsp;&nbsp; // 画面をクリアーする<br />&nbsp;&nbsp;&nbsp; virtual void clear_screen( void );&nbsp;&nbsp;&nbsp; &nbsp;<br />};<br /><br /><br /></td></tr><tr><td>CURSOR_CONTROL.cpp (0.0.8)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br /><br />#include &quot;CURSOR_CONTROL.h&quot;<br /><br />&nbsp;<br />#include &lt;unistd.h&gt;<br />#include &lt;termios.h&gt;<br />#include &lt;sys/time.h&gt;<br /><br />static int flg_init_termios = 0;<br />static struct termios save_term;<br />static struct termios temp_term;<br /><br />CURSOR_CONTROL::CURSOR_CONTROL()<br />{<br />&nbsp;&nbsp;&nbsp; const int def_screen_w = 132;<br />&nbsp;&nbsp;&nbsp; const int def_screen_h = 43;<br /><br />&nbsp;&nbsp;&nbsp; pos_x = 0;<br />&nbsp;&nbsp;&nbsp; pos_y = 0;<br />&nbsp;&nbsp;&nbsp; scr_w = def_screen_w;<br />&nbsp;&nbsp;&nbsp; scr_h = def_screen_h;<br /><br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcgetattr(fileno(stdin), &amp;save_term);<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term = save_term;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_iflag &amp;= IGNCR;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ICANON;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ECHO;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ISIG;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VMIN]=1;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VTIME]=0;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;temp_term);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; flg_init_termios += 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ユニークカウンタ（これでシステム全体での起動数を把握しておく）<br />}<br /><br />CURSOR_CONTROL::~CURSOR_CONTROL()<br />{<br />&nbsp;&nbsp;&nbsp; flg_init_termios -= 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ユニークカウンタを一つ減らす<br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;save_term );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // すべては、これを複数回起動してしまうのを防止するため。（ユニークカウンタ<br />&nbsp;&nbsp;&nbsp; }<br />}<br />&nbsp;<br />void CURSOR_CONTROL::setpos( int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; pos_x = x;<br />&nbsp;&nbsp;&nbsp; pos_y = y;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; if(pos_x &gt;= scr_w){pos_x = scr_w-1;}<br />&nbsp;&nbsp;&nbsp; if(pos_y &gt;= scr_h){pos_y = scr_h-1;}<br /><br />&nbsp;&nbsp;&nbsp; if(pos_x &lt; 0){pos_x = 0;}<br />&nbsp;&nbsp;&nbsp; if(pos_y &lt; 0){pos_y = 0;}<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; __setpos( pos_x, pos_y );<br />}<br /><br />void CURSOR_CONTROL::clear_screen( void )<br />{<br />&nbsp;&nbsp;&nbsp; printf(&quot;%c[2J&quot;,0x1B );<br />}<br /><br />char CURSOR_CONTROL::get_key(void)<br />{<br />&nbsp;&nbsp;&nbsp; return( getchar() );<br />}<br /><br />// カーソルを１マス移動する（画面の外周外に出た場合は、外周位置に留まる）<br />void CURSOR_CONTROL::move_right( void )<br />{<br />&nbsp;&nbsp;&nbsp; pos_x++;<br />&nbsp;&nbsp;&nbsp; if ( pos_x &gt;= scr_w ) pos_x = scr_w - 1;<br /><br />&nbsp;&nbsp;&nbsp; setpos( pos_x, pos_y );&nbsp;&nbsp;&nbsp; <br />}<br /><br />void CURSOR_CONTROL::move_left( void )<br />{<br />&nbsp;&nbsp;&nbsp; pos_x--;<br />&nbsp;&nbsp;&nbsp; if ( pos_x &lt; 0 ) pos_x = 0;<br /><br />&nbsp;&nbsp;&nbsp; setpos( pos_x, pos_y );&nbsp;&nbsp;&nbsp; <br />}<br /><br />void CURSOR_CONTROL::move_up( void )<br />{<br />&nbsp;&nbsp;&nbsp; pos_y++;<br />&nbsp;&nbsp;&nbsp; if ( pos_y &gt;= scr_h ) pos_y = scr_h - 1;<br /><br />&nbsp;&nbsp;&nbsp; setpos( pos_x, pos_y );&nbsp;&nbsp;&nbsp; <br />}<br /><br />void CURSOR_CONTROL::move_down( void )<br />{<br />&nbsp;&nbsp;&nbsp; pos_y--;<br />&nbsp;&nbsp;&nbsp; if ( pos_y &lt; 0 ) pos_y = 0;<br /><br />&nbsp;&nbsp;&nbsp; setpos( pos_x, pos_y );&nbsp;&nbsp;&nbsp; <br />}<br /><br />void CURSOR_CONTROL::__setpos( int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; x+=1;<br />&nbsp;&nbsp;&nbsp; y+=1;&nbsp;&nbsp;&nbsp; <br /><br />&nbsp;&nbsp;&nbsp; printf(&quot;%c[%d;%dH&quot;,0x1b, y, x );<br />}<br /><br /><br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CHAR_SEEDmain.cpp (簡単なコンパイルテスト用）</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br />#include &quot;CHAR_LIST.h&quot;<br /><br />int main()<br />{<br />&nbsp;&nbsp;&nbsp; CURSOR_CONTROL cc;<br />&nbsp;&nbsp;&nbsp; cc.setpos(10,5);<br />&nbsp;&nbsp;&nbsp; cc.clear_screen();<br /><br />&nbsp;&nbsp;&nbsp; CHAR_LIST cl;<br /><br />&nbsp;&nbsp;&nbsp; STRING str;<br />&nbsp;&nbsp;&nbsp; CHAR ch;<br />&nbsp;&nbsp;&nbsp; unsigned char uc[]=&quot;あいうえおかきくけこ１２３４５６７８９０ABCDEFG&quot;;<br />&nbsp;&nbsp;&nbsp; unsigned char buf[1000];<br />&nbsp;&nbsp;&nbsp; ch.write( &amp;(uc[30]) );<br /><br />&nbsp;&nbsp;&nbsp; str.write_str( uc );<br />&nbsp;&nbsp;&nbsp; STRING s2;<br />&nbsp;&nbsp;&nbsp; str.readSTRING( &amp;s2 );<br />&nbsp;&nbsp;&nbsp; s2.size_set(10);<br />&nbsp;&nbsp;&nbsp; s2.print(&amp;cc);<br /><br />&nbsp;&nbsp;&nbsp; getchar();<br /><br />&nbsp;&nbsp;&nbsp; return(0);<br />}<br /></td></tr><tr><td>コンパイルのコマンドライン （linux / gcc)</td></tr><tr><td>gcc -o cs CHAR_SEEDmain.cpp CHAR_LIST.cpp CHAR_SEED.cpp CHAR.cpp STRING.cpp CURSOR_CONTROL.cpp -lstdc++</td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>LINE_LIST.h (0.0.6) 書き直しかけ</td></tr><tr><td>#pragma once<br />&nbsp;<br />#include &quot;CHAR_LIST.h&quot;<br />&nbsp;<br />typedef struct tagLINE_SEED {<br />&nbsp;&nbsp;&nbsp; CHAR_LIST cl;<br />&nbsp;&nbsp;&nbsp; struct tagLINE_SEED* next;<br />&nbsp;&nbsp;&nbsp; struct tagLINE_SEED* back;<br />} LINE_SEED;<br />&nbsp;<br />typedef struct tagLINE_LIST{<br />&nbsp;&nbsp;&nbsp; LINE_SEED* ls_top;<br />&nbsp;&nbsp;&nbsp; int list_len;<br />} LINE_LIST;<br />&nbsp;<br />extern void initLINE_LIST( LINE_LIST* ll, int len );<br />&nbsp;<br />// メモリー確保領域を伸ばす<br />// 最後尾に len 分だけメモリーを追加する<br />// 確保した領域のCHAR_LISTは１文字分だけ確保されてスペースで初期化される<br />extern void stretchLINE_LIST( LINE_LIST* ll, int len );<br />&nbsp;<br />// LISTを配列としてイメージした場合の、配列の添え字を意味する。 ０番からはじまる。<br />//<br />// 配列のLIST長よりも添え字が大きかった場合（ next = 0 の状態）の場合、最後の要素を返す。<br />// また、インデックスがマイナスの場合は、最初の要素を返す。<br />extern LINE_SEED* seekLINE_LIST( LINE_LIST* ll, int index );<br />&nbsp;<br />// LINE_LIST の連結<br />// center が真中のLINE_LIST の最前部をあらわす。 center_len で幅を指定する、これが center の最後部となる。<br />// center の前後に back の最後尾と next 最前部とが、それぞれ連結する。<br />//<br />// 0 ポインタは、それぞれ最後部、最前部をあらわす。next が 0 なら最後部、back が 0 なら最前部である。<br />extern void linkLINE_LIST( LINE_LIST* center, int center_len, LINE_LIST* back, LINE_LIST* next );<br />&nbsp;<br />// dst の dst_index 番目の手前の位置に、src の src_index 番目から len 分を挿入する。<br />// くわしくは __insertLINE_LIST() の説明を参照のこと。<br />// len は 1 以上の大きさを指定しなければならない。１行挿入なら len = 1 である。<br />// index が dst の長さを超えた場合は、最後からindex までの不足分のメモリ領域が確保されて、さらにその後ろのsrcがリンクされる。<br />extern void insertLINE_LIST( LINE_LIST* dst, int dst_index, LINE_LIST* src, int src_index, int len );<br />&nbsp;<br />&nbsp;<br />// row行、colum位置に文字列を len文字分書き込む。<br />// 行や列が足りなかった場合は、自動的にメモリー領域が新たに確保される<br />// row, colum にはマイナスを指定できない。マイナスの場合は何もせずに終了する。<br />extern void write_strLINE_LIST( LINE_LIST* top, int row, int colum, char* str, int len );<br />&nbsp;<br />// row行、colum位置から文字列を読み込む。<br />// 行が足りなかった場合、最後の行が読み込まれる。列が足りなかった場合、列の最後までが読み込まれる。<br />// row, colum にはマイナスを指定できない。マイナスの場合は何もせずに終了する。<br />extern void read_strLINE_LIST( LINE_LIST* top, int row, int colum, char* str, int len );<br />&nbsp;<br />// row行、colum位置に１文字を書き込む。<br />// くわしくは write_strLINE_LIST を参照<br />extern void write_LINE_LIST( LINE_LIST* top, int row, int colum, char c );<br />&nbsp;<br />// row行、colum位置から１文字読み込む。<br />// くわしくは read_strLINE_LIST を参照<br />extern char read_LINE_LIST( LINE_LIST* top, int row, int colum );<br />&nbsp;<br />&nbsp;<br /></td></tr><tr><td>LINE_LIST.cpp (0.0.6) 書き直しかけ</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br />#include &quot;LINE_LIST.h&quot;<br />#include &quot;CHAR_LIST.h&quot;<br />&nbsp;<br />extern void _insertLINE_LIST( LINE_LIST* ll, int index, int len );<br />extern void __insertLINE_LIST( LINE_LIST* dst, int index, LINE_LIST* src );<br />&nbsp;<br />void initLINE_LIST( LINE_LIST* ll, int len )<br />{<br />&nbsp;&nbsp;&nbsp; if (len &lt; 1 ) { printf(&quot;err initLINE_LIST() len&yen;n&quot;); exit(1); }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; ll-&gt;ls_top = (LINE_SEED*)malloc( sizeof(LINE_SEED) );&nbsp;&nbsp;&nbsp; // まず先頭１つ分を設定して作るってしまって...<br />&nbsp;&nbsp;&nbsp; ll-&gt;ls_top-&gt;back = 0;<br />&nbsp;&nbsp;&nbsp; ll-&gt;ls_top-&gt;next = 0;<br />&nbsp;&nbsp;&nbsp; initCHAR_LIST( &amp;(ll-&gt;ls_top-&gt;cl), 0x01 );<br />&nbsp;&nbsp;&nbsp; ll-&gt;list_len = 1;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; stretchLINE_LIST( ll, len - 1 );&nbsp;&nbsp;&nbsp; // ...それをストレッチすることで領域を確保する。<br />}<br />&nbsp;<br />// メモリー確保領域を伸ばす<br />// 最後尾に len 分だけメモリーを追加する<br />// 確保した領域のCHAR_LISTは１文字分だけ確保されてスペースで初期化される<br />void stretchLINE_LIST( LINE_LIST* ll, int len )<br />{<br />&nbsp;&nbsp;&nbsp; LINE_SEED* cur = seekLINE_LIST( ll, ll-&gt;list_len - 1 );<br />&nbsp;&nbsp;&nbsp; LINE_SEED* next;<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; for ( i = 0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur-&gt;next = (LINE_SEED*)malloc(sizeof(LINE_SEED) * len);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; initCHAR_LIST( &amp;(cur-&gt;next-&gt;cl), 0x01 );<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next = cur-&gt;next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next-&gt;back = cur;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur = next;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ll-&gt;list_len++;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; cur-&gt;next = 0;<br />}<br />&nbsp;<br />// LISTを配列としてイメージした場合の、配列の添え字を意味する。 ０番からはじまる。<br />//<br />// 配列のLIST長よりも添え字が大きかった場合（ next = 0 の状態）の場合、最後の要素を返す。<br />// また、インデックスがマイナスの場合は、最初の要素を返す。<br />LINE_SEED* seekLINE_LIST( LINE_LIST* ll, int index )<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; LINE_SEED* cur = ll-&gt;ls_top;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; if (index &lt; 0 ) { return( cur ); }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;index;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( cur-&gt;next != 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur = cur-&gt;next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i = index;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; return( cur );<br />}<br />&nbsp;<br />// insertLINE_LIST 用の準備<br />// LINE_LIST の index 番目から len 分だけ、LINE_SEED のメモリー領域を新規に確保して index の手前の位置に挿入する<br />// たとえば index が 0 で len が 10 ならば、新しい領域が0～9に作られ、今までの古い領域が10以降に押しやられる。<br />// len は 1 以上の大きさを指定しなければならない。１行挿入なら len = 1 である。<br />// ＊アルゴリズムが変わったので、今は insetrLINE_LIST() の内部処理では使われてない。<br />void _insertLINE_LIST( LINE_LIST* ll, int index, int len )<br />{<br />&nbsp;&nbsp;&nbsp; if (len &lt; 1 ) { printf(&quot;err : _insertLINE_LIST() len&yen;n&quot;); exit(1); }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; LINE_LIST nll;<br />&nbsp;&nbsp;&nbsp; initLINE_LIST( &amp;nll, len );<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; LINE_SEED* fast = seekLINE_LIST( &amp;nll, 0 );<br />&nbsp;&nbsp;&nbsp; LINE_SEED* end&nbsp; = seekLINE_LIST( &amp;nll, nll.list_len - 1 );<br />&nbsp;&nbsp;&nbsp; LINE_SEED* next = seekLINE_LIST( ll, index );<br />&nbsp;&nbsp;&nbsp; LINE_SEED* back = next-&gt;back;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; if ( index == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fast-&gt;back = 0;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end-&gt;next&nbsp; = next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next-&gt;back = end;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ll-&gt;ls_top = fast;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fast-&gt;back = back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; back-&gt;next = fast;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end-&gt;next&nbsp; = next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next-&gt;back = end;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; ll-&gt;list_len += len;<br />}<br />&nbsp;<br />// insertLINE_LIST 用の準備<br />// dst の index 番目の手前の位置に、src の０番目から list_len - 1 最目（つまり最後尾の要素）まですべてを挿入する。<br />// つまり dst のリンクを定義しなおすだけである。<br />// src の正体は insettLINK_LIST() 内で新たにメモリ確保されたバッファーである。これをdstのリンク先を修正することで挿入する。<br />// src の list_len （srcの長さ）が 1 以上の大きさでない場合は、なにもせずに終了する。<br />// index が dst の長さを超えた場合は、最後からindex までの不足分のメモリ領域が確保されて、さらにその後ろのsrcがリンクされる。<br />void __insertLINE_LIST( LINE_LIST* dst, int index, LINE_LIST* src )<br />{<br />&nbsp;&nbsp;&nbsp; if( src-&gt;list_len &lt; 1 ) { return; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; LINE_SEED* fast = seekLINE_LIST( src, 0 );<br />&nbsp;&nbsp;&nbsp; LINE_SEED* end&nbsp; = seekLINE_LIST( src, src-&gt;list_len - 1 );<br />&nbsp;&nbsp;&nbsp; LINE_SEED* next;<br />&nbsp;&nbsp;&nbsp; LINE_SEED* back;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; if ( index == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next = seekLINE_LIST( dst, index );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; back = 0;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;ls_top = fast;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fast-&gt;back = back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end-&gt;next&nbsp; = next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next-&gt;back = end;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if ( index &gt;= dst-&gt;list_len ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int dif = index - dst-&gt;list_len;<br />//printf(&quot;dif=%d&yen;n&quot;,dif);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; stretchLINE_LIST( dst, dif );<br />//printf(&quot;dst-&gt;list_len=%d&yen;n&quot;,dst-&gt;list_len);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; back = seekLINE_LIST( dst, index );<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fast-&gt;back = back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; back-&gt;next = fast;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end-&gt;next&nbsp; = next;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next = seekLINE_LIST( dst, index );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; back = next-&gt;back;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fast-&gt;back = back;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; back-&gt;next = fast;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end-&gt;next&nbsp; = next;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; next-&gt;back = end;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; dst-&gt;list_len += src-&gt;list_len;<br />}<br />&nbsp;<br />// dst の dst_index 番目の手前の位置に、src の src_index 番目から len 分を挿入する。<br />// くわしくは __insertLINE_LIST() の説明を参照のこと。<br />// len は 1 以上の大きさを指定しなければならない。１行挿入なら len = 1 である。<br />// index が dst の長さを超えた場合は、最後からindex までの不足分のメモリ領域が確保されて、さらにその後ろのsrcがリンクされる。<br />void insertLINE_LIST( LINE_LIST* dst, int dst_index, LINE_LIST* src, int src_index, int len )<br />{<br />&nbsp;&nbsp;&nbsp; // 引数が不正な場合は何もしないで即リターンする<br />&nbsp;&nbsp;&nbsp; if( dst_index&lt;0 || src_index&lt;0 ) {return;}<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; LINE_SEED* src_ls;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; char* buf = (char*)malloc(0xFFFF);<br />&nbsp;&nbsp;&nbsp; LINE_LIST llb; initLINE_LIST(&amp;llb, len);<br />&nbsp;&nbsp;&nbsp; LINE_SEED* llb_ls;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; int j;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; for( j = 0; j &lt; len; j++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; src_ls = seekLINE_LIST( src, src_index + j );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; llb_ls = seekLINE_LIST( &amp;llb, j );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; read_strCHAR_LIST(&nbsp; &amp;(src_ls-&gt;cl), 0, buf, src_ls-&gt;cl.list_len );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; write_strCHAR_LIST( &amp;(llb_ls-&gt;cl), 0, buf, src_ls-&gt;cl.list_len ); // src_ls なのはタイプミスではない<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; __insertLINE_LIST( dst, dst_index, &amp;llb );<br />&nbsp;&nbsp;&nbsp; free((void*)buf);<br />}<br />&nbsp;<br />// row行、colum位置に文字列を len文字分書き込む。<br />// 行や列が足りなかった場合は、自動的にメモリー領域が新たに確保される<br />// row, colum にはマイナスを指定できない。マイナスの場合は何もせずに終了する。<br />void write_strLINE_LIST( LINE_LIST* top, int row, int colum, char* str, int len )<br />{<br />&nbsp;&nbsp;&nbsp; // 領域がマイナス指定の場合は何もせず終了<br />&nbsp;&nbsp;&nbsp; if( row &lt; 0 || colum &lt; 0 ) { return; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; // 文字列長が１以下なら何もせず終了<br />&nbsp;&nbsp;&nbsp; if ( len &lt; 1 ) { return; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; // len が str長よりも大きい場合は、str長に修正して実行する<br />&nbsp;&nbsp;&nbsp; if ( len &gt; (int)strlen(str) ) { len = (int)strlen(str); }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; // もし行が足りなかった場合は新たに行を確保する<br />&nbsp;&nbsp;&nbsp; int dif = row - ( top-&gt;list_len - 1 );<br />&nbsp;&nbsp;&nbsp; if ( dif &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; stretchLINE_LIST(top,dif);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; LINE_SEED* lsp = seekLINE_LIST( top, row );<br />&nbsp;&nbsp;&nbsp; write_strCHAR_LIST( &amp;(lsp-&gt;cl), colum, str, len ); // colum が大きかった場合はこの関数内で新たに列が確保される<br />}<br />&nbsp;<br />// row行、colum位置から文字列を読み込む。<br />// 行が足りなかった場合、最後の行が読み込まれる。列が足りなかった場合、列の最後までが読み込まれる。<br />// row, colum にはマイナスを指定できない。マイナスの場合は何もせずに終了する。<br />void read_strLINE_LIST( LINE_LIST* top, int row, int colum, char* str, int len )<br />{<br />&nbsp;&nbsp;&nbsp; // 領域がマイナス指定の場合は何もせず終了<br />&nbsp;&nbsp;&nbsp; if( row &lt; 0 || colum &lt; 0 ) { return; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; // 文字列長が１以下なら何もせず終了<br />&nbsp;&nbsp;&nbsp; if ( len &lt; 1 ) { return; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; // len が str長よりも大きい場合は、str長に修正して実行する<br />&nbsp;&nbsp;&nbsp; if ( len &gt; (int)strlen(str) ) { len = (int)strlen(str); }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; // もしrowが最大行をオーバーした場合は、最大行に修正して実行する<br />&nbsp;&nbsp;&nbsp; int dif = row - ( top-&gt;list_len - 1 );<br />&nbsp;&nbsp;&nbsp; if ( dif &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; row -= dif;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; LINE_SEED* ls = seekLINE_LIST( top, row );<br />&nbsp;&nbsp;&nbsp; read_strCHAR_LIST( &amp;(ls-&gt;cl), colum, str, len ); // colum が大きかった場合はこの関数内で、列の最後までが読み込まれる<br />}<br />&nbsp;<br />// row行、colum位置に１文字を書き込む。<br />// くわしくは write_strLINE_LIST を参照<br />void write_LINE_LIST( LINE_LIST* top, int row, int colum, char c )<br />{<br />&nbsp;&nbsp;&nbsp; char str[2];<br />&nbsp;&nbsp;&nbsp; str[0] = c;<br />&nbsp;&nbsp;&nbsp; str[1] = '&yen;0';<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; write_strLINE_LIST( top, row, colum, str, 1 );<br />}<br />&nbsp;<br />// row行、colum位置から１文字読み込む。<br />// くわしくは read_strLINE_LIST を参照<br />char read_LINE_LIST( LINE_LIST* top, int row, int colum )<br />{<br />&nbsp;&nbsp;&nbsp; char str[2];<br />&nbsp;&nbsp;&nbsp; str[0] = '&yen;0';<br />&nbsp;&nbsp;&nbsp; str[1] = '&yen;0';<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; read_strLINE_LIST( top, row, colum, str, 1 );<br />&nbsp;&nbsp;&nbsp; return( str[0] );<br />}<br /><br /></td></tr></tbody></table><br /><br /><br /><br /><br /> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-11-29T17:54:51+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-40.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-40.html</link>
<title>ETC_MATH (0.0.7)</title>
<description> math.cのソースは読んだことないんで憶測ですが、おそらくアレのサイン、コサインはテイラーてんかいでやってんだろうな&amp;hellip;と。そんな気がする。あれだと精度もそれなりに出るし良いんだけど、いかんせん、除算と乗算を何回も繰り返す計算になるので、たぶんテーブルにしちゃった方が速いだろうな&amp;hellip;とおもった。&amp;hellip;まぁ、常套手段ですがw昔はメモリー資源が貴重だったんで、０～&amp;pi;／２までのテーブルを用意して
 </description>
<content:encoded>
<![CDATA[ math.cのソースは読んだことないんで憶測ですが、おそらくアレのサイン、コサインはテイラーてんかいでやってんだろうな&hellip;と。そんな気がする。<br />あれだと精度もそれなりに出るし良いんだけど、いかんせん、除算と乗算を何回も繰り返す計算になるので、たぶんテーブルにしちゃった方が速いだろうな&hellip;とおもった。<br /><br />&hellip;まぁ、常套手段ですがw<br /><br />昔はメモリー資源が貴重だったんで、０～&pi;／２までのテーブルを用意して、それをブロック毎に分岐して読み方を変えることで使いまわすような組み方が普通だったんだけど、<br />今の時代はメモリーが余りまくりなので（メモリーがギガとかマジありえねぇ～～w）、贅沢に無駄に、無駄というか、素直に作っても大丈夫な気がする。（変に小賢い工夫とかせずに）<br /><br />昔は浮動小数点数演算が遅かったので、固定小数点数を使って高速化をするのが普通でしたけど、最近は浮動小数点数型も整数型も、さして処理速度に昔ほどの大きな差はなくなってるので、無理して固定小数なんか使わなくても、素直に浮動小数で作ればいいだろうな&hellip;と考えた。<br /><br />ちなみに、PC９８なんかでゲーム作るときは、０～&pi;／２の範囲を２５６に分割したテーブルを用意して、その三角関数は２５６を１として扱う固定小数点数型を返したりしてた。そういうのが普通だった。<br />固定小数点数は足し算と引き算は普通にやっていいんだけど、掛け算の場合は計算後に＞＞してやる必要があって、その右シフト量がちょうど１を表す数、たとえば８ビット（２５６）なワケさ。<br />PSだともう少し少数の精度を増やして、４０９６を１として扱うのがハード的な仕様として？決められてた。GTEっていう行列演算専用のユニットであつかう行列はshort型（１６びっと）の３x３の正方行列で、これの単位が４０９６＝１だったわけで、小数部１２ビット、整数部４ビット（いや３＋符号だったか？わすれた）の固定小数点型だったりしました。<br /><br />で、もぅ現代のパソコンはアホみたいにメモリーがあり余ってるし、浮動小数点数でも計算そこそこ速いんで、テーブルは０～&pi;／２じゃなくて、０～２&pi;をフルに用意しちゃって、テーブル分割数は0x40000 （！？バカかよっw）、つまり１／４ブロック毎に64k分割してます。しかもそのテーブルには固定小数点数じゃなくて浮動小数点数型の数値が格納されてる。という仕様。<br />&hellip;たぶんPC９８時代だったら、まずまともには動かないレベルw（メモリー的にも処理速度的にも）<br /><br />でも、まぁとりあえず試しに組んでみて、速度比較のためにn&lt;20までのテイラータイプのsin関数を書いて、これと処理速度の比較をしてみたのですが、<br />テイラー展開型の sin だと、 sin(&pi;/4）を１０００万回計算するのに、指折り数えて６秒程度、<br />テーブル型の sin だと、同様の計算が一瞬でした。なので指折り数えられなかったので、１０倍の１億回計算させましたが、それでも１秒程度でした。<br />つまり、ざっと見積もっても５０倍くらいは速い。<br /><br />ただ、もちろん、速度重視の単純なテーブル型だと、線形の補間なんてのはしないで、単純に小数切り捨てで近くの箱を選択するだけなので、精度的には劣る。千分の１くらいまでは平気なんだけど、１万分の１くらいの精度になるともぅ無理。　ここを（速度を保ったまま）上げようと思ったら、単純にテーブルをもっと膨大にすればいいんだろうけど、現時点でも64*4*4で、テーブルだけでも１メガ越えてるし、（しかも sin, cos で共用せずに、それぞれ専用に用意してる（アホ過ぎるっw））、さすがに千分の１の精度が出れば、まぁ、当面ホビーには充分だろうし&hellip;ははw<br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>ETC_MATH.h (0.0.7)</td></tr><tr><td>#ifndef _ETC_MATH_H_<br />#define _ETC_MATH_H_<br />&nbsp;<br />// a^inv<br />extern int pow(int a, int inv );<br />&nbsp;<br />// 基数による桁数<br />extern int _dig(int a, int cardinal );<br />&nbsp;<br />// 数値型から文字列型<br />extern void itos( char* dst, int src );<br /><br />extern double factoriol( long a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 階乗<br />extern double pow_f( double a, long inv );&nbsp;&nbsp;&nbsp; // 累乗<br />extern double exp_taylor( double a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // expornent<br />extern double sin_taylor( double a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // sin（テイラー展開<br /><br />// テーブルによる三角関数<br />extern double sin_t( double a );<br />extern double cos_t( double a );<br />extern double tan_t( double a );<br /><br /><br /><br />&nbsp;<br />#endif // _ETC_MATH_H_<br />&nbsp;</td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>ETC_MATH.cpp (0.0.7)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &quot;ETC_MATH.h&quot;<br />#include &quot;ETC_MATH_TABLE.h&quot;<br />&nbsp;<br />// a^inv<br />int pow(int a, int inv )<br />{<br />&nbsp;&nbsp;&nbsp; int r=a;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; if(inv==0) r=1;<br />&nbsp;&nbsp;&nbsp; if(inv==1) r=a;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=2;i&lt;=inv;i++){r*=a;}<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; return(r);<br />}<br />&nbsp;<br />// 基数による桁数<br />int _dig(int a, int cardinal )<br />{<br />&nbsp;&nbsp;&nbsp; if( cardinal ==0 ){printf(&quot;err: dig() cardinal&yen;n&quot;);exit(1);}<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; int count=0;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; while(a&gt;0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; a/=cardinal;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( a &lt;= 0 ) { break; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; return(count);<br />}<br />&nbsp;<br />// 数値型から文字列型<br />void itos( char* dst, int src )<br />{<br />&nbsp;&nbsp;&nbsp; if(src &gt; 0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int p;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int unit;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int sub=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int dig=_dig(src,10);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;dig;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p=pow(10,i+1);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sub+=((src%p)-sub);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unit=sub / pow(10, i);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(unit){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0:dst[dig-1-i]='0';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 1:dst[dig-1-i]='1';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 2:dst[dig-1-i]='2';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 3:dst[dig-1-i]='3';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 4:dst[dig-1-i]='4';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 5:dst[dig-1-i]='5';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 6:dst[dig-1-i]='6';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 7:dst[dig-1-i]='7';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 8:dst[dig-1-i]='8';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 9:dst[dig-1-i]='9';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default:printf(&quot;err: itos() dst[%d]&yen;n&quot;,dig-1-i ); exit(1); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[dig]='&yen;0';<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0]='0';<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1]='&yen;0';<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />double factoriol( long a )<br />{<br />&nbsp;&nbsp;&nbsp; double v = 1;<br /><br />&nbsp;&nbsp;&nbsp; for(long i = 1; i &lt;= a; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v *= (double)i;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( v );<br />}<br /><br />double pow_f( double a, long inv )<br />{<br />&nbsp;&nbsp;&nbsp; double r=a;<br /><br />&nbsp;&nbsp;&nbsp; if(inv==0){r=1;}<br />&nbsp;&nbsp;&nbsp; if(inv==1){r=a;}<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; for(long i=2; i &lt;= inv; i++ ){ r *= a; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; return(r);<br />&nbsp;&nbsp;&nbsp; <br />}<br /><br />double exp_taylor( double a )<br />{<br />&nbsp;&nbsp;&nbsp; double v=0;<br /><br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; 10; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v += ( 1.0 / factoriol(i) ) * pow_f(a,i);<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return( v );<br />}<br /><br />double sin_taylor( double a )<br />{<br />&nbsp;&nbsp;&nbsp; double v=0;<br />&nbsp;&nbsp;&nbsp; double fugou=1.0;<br /><br />&nbsp;&nbsp;&nbsp; for(long i=1; i&lt;20; i+=2 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v += fugou * ( ( 1.0 / factoriol(i) ) * pow_f(a, i) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou=-fugou;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( v );<br />}<br /><br /><br /><br />static double ETC_MATH_t_table_rd( ( (double)ETC_MATH_TABLE_SIZE / 2 ) / 3.14159265358979 );<br />double sin_t( double a )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned long l = (unsigned long)( a * ETC_MATH_t_table_rd );<br />&nbsp;&nbsp;&nbsp; l %= ETC_MATH_TABLE_SIZE;<br />&nbsp;&nbsp;&nbsp; return( ETC_MATHsin_table[l]);<br />}<br /><br />double cos_t( double a )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned long l = (unsigned long)( a * ETC_MATH_t_table_rd );<br />&nbsp;&nbsp;&nbsp; l %= ETC_MATH_TABLE_SIZE;<br />&nbsp;&nbsp;&nbsp; return( ETC_MATHcos_table[l]);<br />}<br /><br />double tan_t( double a )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned long l = (unsigned long)( a * ETC_MATH_t_table_rd );<br />&nbsp;&nbsp;&nbsp; l %= ETC_MATH_TABLE_SIZE;<br />&nbsp;&nbsp;&nbsp; return( ETC_MATHtan_table[l]);<br />}<br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>ETC_MATH_make_TABLE.cpp (0.0.7) <br /><br />（これをコンパイルして実行すると ETC_MATH_TABLE.h が生成されます）<br />（それを ETC_MATH.cpp に #include して使います）</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;math.h&gt;<br /><br /><br /><br />#define TABLE_SIZE 0x40000<br /><br /><br /><br />int main()<br />{<br />///*<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; FILE* fp = fopen( &quot;ETC_MATH_TABLE.h&quot;,&quot;w+&quot; );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double rd=3.14159265358979 / (TABLE_SIZE / 2);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; long i;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;#ifndef _ETC_MATH_TABLE_H_\n&quot; );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;#define _ETC_MATH_TABLE_H_\n\n&quot; );<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;#define ETC_MATH_TABLE_SIZE %d\n\n&quot;, TABLE_SIZE );<br /><br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;static double ETC_MATHsin_table[ETC_MATH_TABLE_SIZE] = {\n&quot; );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0; i &lt; TABLE_SIZE; i++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf( fp, &quot;%f,\t &quot;,sin(rd*i) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if((i%8)==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;\n&quot;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;\n};\n\n&quot; );<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;static double ETC_MATHcos_table[ETC_MATH_TABLE_SIZE] = {\n&quot; );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0; i &lt; TABLE_SIZE; i++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf( fp, &quot;%f,\t &quot;,cos(rd*i) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if((i%8)==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;\n&quot;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;\n};\n\n&quot; );<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;static double ETC_MATHtan_table[ETC_MATH_TABLE_SIZE] = {\n&quot; );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0; i &lt; TABLE_SIZE; i++) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf( fp, &quot;%f,\t &quot;,tan(rd*i) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if((i%8)==0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;\n&quot;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;\n};\n\n&quot; );<br /><br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fprintf(fp,&quot;#endif // _ETC_MATH_TABLE_H_\n&quot; );<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fclose(fp);<br />&nbsp;&nbsp;&nbsp; }<br />//*/<br /><br />&nbsp;&nbsp;&nbsp; return(0);<br />}<br /></td></tr></tbody></table><br /><br /><br /><br /><br /><br /> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-11-28T00:00:00+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-37.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-37.html</link>
<title>INT (0.0.7)</title>
<description> 整数を格納するための int 型という標準型があるんだけど、これだと最大でも 32bit までしか格納できないので（ gcc の場合）、それよりも大きい数を代入すると桁溢れを起こしてしまう。通常型の int には、具体的には&amp;plusmn;20億程度の数まで格納できる。これは、桁数に直すと 10 ケタ。１６進数での桁数に直すと 8 ケタ。これをもっと、膨大な数でも、『ケタ溢れを心配しないで使える型』ってのがあれば、便利なんじゃないだろ
 </description>
<content:encoded>
<![CDATA[ 整数を格納するための int 型という標準型があるんだけど、これだと最大でも 32bit までしか格納できないので（ gcc の場合）、それよりも大きい数を代入すると桁溢れを起こしてしまう。<br /><br />通常型の int には、具体的には&plusmn;20億程度の数まで格納できる。<br />これは、桁数に直すと 10 ケタ。<br />１６進数での桁数に直すと 8 ケタ。<br /><br />これをもっと、膨大な数でも、『ケタ溢れを心配しないで使える型』ってのがあれば、便利なんじゃないだろうか？<br />と思った。<br />「そういう型は無いのかなぁ～？」と思ってC言語入門とか読んでみても、どうやら無いみたいなので、自分で作ることにしました。<br /><br />INT 型では、&plusmn;２億ケタ程度の数まで扱えます。（あくまで設計上）<br />初期状態では 32 ビット長です。　これが、演算によってケタ溢れを起こすと、自動的にビット数を増やします。<br />増やすビット数は８ビット単位です。たとえば３２ビットで +0x FF FF FF FF だったとして、これに１を加えると<br />、自動的サイズが変更されてに 0x 01 FF FF FF FF となります。<br /><br />INT同士での四則演算ができます。演算結果が桁溢れした場合も、自動的にサイズが増やされます。<br /><br />INTに対してのビット演算が可能です。<br /><br />INTに対してのシフト演算が可能です。シフト演算の場合は、自動的なサイズ拡張は『行いません』。<br />桁溢れした値は捨てられます。<br />（引数には、シフトするバイト数を渡します。正のlong型です。（&larr;つまり+２０億bit まで））<br /><br />シフト演算の前には、使用するバイト数を明示的に指定した方がいいです。<br />そのために size_set() を用意してあります。これでINTのバイト長を直接指定できます。<br />相対的にバイト長を指定したい時のために size_add() もしくは size_dec も用意してあります。<br />（引数にはいずれも正のlong型を渡します。）<br /><br /><br /><br />データ構造：<br />符号無char型の位置を記録するための配列に、<br />個々に定義したcharを、それぞれ個々にぶら下げる形です。<br />（注：charが連続した配列である保証はありません）<br /><br /><table cellspacing="0" cellpadding="0" border="0" align="" width="" summary=""><tbody><tr><td style="text-align: center; background-color: rgb(255, 255, 153);"><font size="3">0</font></td><td style="text-align: center; background-color: rgb(255, 255, 153);"><font size="3">1</font></td><td style="text-align: center; background-color: rgb(255, 255, 153);"><font size="3">2</font></td><td style="text-align: center; background-color: rgb(255, 255, 153);"><font size="3"></font></td><td style="text-align: center; background-color: rgb(255, 255, 153);"><font size="3"></font></td><td style="text-align: center; background-color: rgb(255, 255, 153);"><font size="3">len-1</font></td><td style="text-align: center; background-color: rgb(255, 255, 153);"><font size="3"></font></td></tr><tr><td style="color: rgb(255, 153, 0); text-align: center; background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="color: rgb(255, 153, 0); text-align: center; background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="color: rgb(255, 153, 0); text-align: center; background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="text-align: center; background-color: rgb(255, 255, 153);">...</td><td style="text-align: center; background-color: rgb(255, 255, 153);">&nbsp;...</td><td style="color: rgb(255, 153, 0); text-align: center; background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="color: rgb(255, 153, 0); text-align: left; background-color: rgb(255, 255, 153);"><font size="3">（&larr;CHAR＊型の配列）</font></td></tr><tr><td style="background-color: rgb(255, 255, 153);">&uarr;</td><td style="text-align: center; background-color: rgb(255, 255, 153);">&uarr;</td><td style="text-align: center; background-color: rgb(255, 255, 153);">&uarr;</td><td style="text-align: center; background-color: rgb(255, 255, 153);">&nbsp;</td><td style="text-align: center; background-color: rgb(255, 255, 153);">&nbsp;</td><td style="text-align: center; background-color: rgb(255, 255, 153);">&uarr;</td><td style="text-align: left; background-color: rgb(255, 255, 153);"><font size="3">（&larr;ポインタを登録）</font></td></tr><tr><td style="color: rgb(51, 153, 102); text-align: center; background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="color: rgb(51, 153, 102); text-align: center; background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="color: rgb(51, 153, 102); text-align: center; background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="text-align: center; background-color: rgb(255, 255, 153);">...</td><td style="text-align: center; background-color: rgb(255, 255, 153);">&nbsp;...</td><td style="color: rgb(51, 153, 102); text-align: center; background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="color: rgb(51, 153, 102); text-align: left; background-color: rgb(255, 255, 153);"><font size="3">（&larr;CHAR型の実データ）</font></td></tr></tbody></table><br /><br /><br />加算：<br />INT型のAに対して、INT型のBを加算する場合。<br /><br />Aの方が短い<br /><table cellspacing="0" cellpadding="0" border="0" align="" width="" summary=""><tbody><tr><td style="background-color: rgb(255, 255, 153);"><font size="3"></font></td><td style="background-color: rgb(255, 255, 153);"><font size="3">7</font></td><td style="background-color: rgb(255, 255, 153);"><font size="3">6</font></td><td style="background-color: rgb(255, 255, 153);"><font size="3">5</font></td><td style="background-color: rgb(255, 255, 153);"><font size="3">4</font></td><td style="background-color: rgb(255, 255, 153);"><font size="3">3</font></td><td style="background-color: rgb(255, 255, 153);"><font size="3">2</font></td><td style="background-color: rgb(255, 255, 153);"><font size="3">1</font></td><td style="background-color: rgb(255, 255, 153);"><font size="3">0</font></td><td style="background-color: rgb(255, 255, 153);"><font size="3">&nbsp;</font></td></tr><tr><td style="background-color: rgb(255, 255, 153);"><font size="4"><br /></font></td><td style="background-color: rgb(255, 255, 153);"><font size="4"><br /></font></td><td style="background-color: rgb(255, 255, 153);">&nbsp;</td><td style="background-color: rgb(255, 255, 153);"><font size="4"><br /></font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);">A</td></tr><tr><td style="background-color: rgb(255, 255, 153);"><font size="4"><br /></font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);">B</td></tr></tbody></table><br />&darr;<br /><br />長い方（B）の長さに合わせて、短い方（A）を伸ばす<br /><table cellspacing="0" cellpadding="0" border="0" align="" width="" summary=""><tbody><tr><td>&nbsp;</td><td style="background-color: rgb(255, 255, 153);">7</td><td style="background-color: rgb(255, 255, 153);">6</td><td style="background-color: rgb(255, 255, 153);">5</td><td style="background-color: rgb(255, 255, 153);">4</td><td style="background-color: rgb(255, 255, 153);">3</td><td style="background-color: rgb(255, 255, 153);">2</td><td style="background-color: rgb(255, 255, 153);">1</td><td style="background-color: rgb(255, 255, 153);">0</td><td style="background-color: rgb(255, 255, 153);">&nbsp;</td></tr><tr><td>&nbsp;</td><td style="color: rgb(255, 153, 0); background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4"><br /> </font></td><td style="background-color: rgb(255, 255, 153);"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4"><br /> </font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);">A</td></tr><tr><td>&nbsp;</td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153);">B</td></tr></tbody></table><br />&darr;<br /><br />描くバイトを ２バイトと解釈してA＋Bとして加算する<br /><table cellspacing="0" cellpadding="0" border="0" align="" style="width: 36px; height: 85px;" summary=""><tbody><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">0</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">A</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">+</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">B</td></tr></tbody></table><br />&darr;<br /><br />各バイトを２バイトに拡張した単位で加算した結果の、LSB側１バイトが、そのインデックスでの加算結果となる。<br />HSB１バイト側は、次のインデックスのバイトに加算される。<br />これを n<sub>-1</sub> まで単純に繰り返すだけです。<br /><table cellspacing="0" cellpadding="0" border="0" align="" width="" summary=""><tbody><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">n<sub>-1</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">3</td><td style="background-color: rgb(255, 255, 153); text-align: center;">2</td><td style="background-color: rgb(255, 255, 153); text-align: center;">1</td><td style="background-color: rgb(255, 255, 153); text-align: center;">0</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">A<sub>0</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">+</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">B<sub>0</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">=</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">A'<sub>0</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">+</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">A<sub>1</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">+</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">B<sub>1</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">=</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">A'<sub>1</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">+</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">A<sub>2</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">+</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">B<sub>2</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">=</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">A'<sub>2</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">+</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">A<sub>3</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">+</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">B<sub>3</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">=</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">A'<sub>3</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">+</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">A<sub>n-1</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">+</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">B<sub>n-1</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">=</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4" style="color: rgb(255, 153, 0);">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;"><font size="4">□</font></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">A'<sub>n-1</sub></td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td><td style="background-color: rgb(255, 255, 153); text-align: center;">&nbsp;</td></tr></tbody></table><br /><br /><br />減算：<br />加算と同じパターンです。<br />（ただし、Bを２の補数した数を加算します）<br /><br />補数について：<br /><br /><br /><br />乗算：<br /><br /><br /><br />除算：<br /><br /><br /><br /><br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>INT.h (0.0.7)</td></tr><tr><td>#pragma once<br /><br />class INT {<br />//protected:<br />public:<br />&nbsp;&nbsp;&nbsp; unsigned char**&nbsp;&nbsp;&nbsp; byte;<br />&nbsp;&nbsp;&nbsp; long&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; len;<br />&nbsp;&nbsp;&nbsp; long&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou;<br /><br />&nbsp;&nbsp;&nbsp; virtual unsigned char&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _byte(long index)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { if((index&lt;len) &amp;&amp; (index&gt;=0)) return(*(byte[index])); else return(0); }<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _set_b(long index, unsigned char c)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { if((index&lt;len) &amp;&amp; (index&gt;=0)) (*byte[index])=c; else return; }<br />&nbsp;&nbsp;&nbsp; virtual long&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _len(void) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { return(len); }<br />&nbsp;&nbsp;&nbsp; virtual long&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _b_len(void);<br />&nbsp;&nbsp;&nbsp; virtual long &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _fugou(void) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { return(fugou); }<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _set_fugou( long f )&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { if( f == +1 ) fugou = +1; else if( f == -1 ) fugou = -1; };<br /><br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _add( INT* a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 内部処理用<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _sub( INT* a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 内部処理用<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _mul( INT* a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 内部処理用<br />&nbsp;&nbsp;&nbsp; virtual void&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _deq( INT* a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 内部処理用<br />public:<br />&nbsp;&nbsp;&nbsp; INT(void);<br />&nbsp;&nbsp;&nbsp; virtual ~INT(void);<br />&nbsp;&nbsp;&nbsp; virtual void gc(void);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 余分な確保分のメモリー領域を開放して、len を正しい値に設定する。<br /><br />&nbsp;&nbsp;&nbsp; virtual void set( long l );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // long 型の値をセットできる。<br />&nbsp;&nbsp;&nbsp; virtual void copy( INT* a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a の内容を自分に書き込む（ようするにコピーです）<br /><br />&nbsp;&nbsp;&nbsp; virtual void size_set( long size );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 格納できる桁数をセットする（バイト単位）<br />&nbsp;&nbsp;&nbsp; virtual void size_add( long size );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 格納できる桁数を今より増やす（バイト単位）<br />&nbsp;&nbsp;&nbsp; virtual void size_dec( long size );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 格納できる桁数を今より減らす（バイト単位）<br /><br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; comparison( INT* a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 比較を行い、＝なら０、自分の方が大きい（＞）なら＋１、aの方が大きい（＜）なら-1を返す<br />&nbsp;&nbsp;&nbsp; virtual int&nbsp; comparison_abs( INT* a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 絶対値で比較。あとは comparison() と同じ<br /><br />&nbsp;&nbsp;&nbsp; virtual void r_shift( long s );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 右シフト演算<br />&nbsp;&nbsp;&nbsp; virtual void l_shift( long s );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 左シフト演算<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; virtual void b_and( INT* a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バイナリーAND &amp;<br />&nbsp;&nbsp;&nbsp; virtual void b_or ( INT* a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バイナリーOR&nbsp; |<br />&nbsp;&nbsp;&nbsp; virtual void b_xor( INT* a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バイナリーXOR ^<br />&nbsp;&nbsp;&nbsp; virtual void b_not( void );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バイナリーNOT ~<br />&nbsp;&nbsp;&nbsp; virtual void b_0( void );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バイナリーAll０（すべてのビットを０にする）<br />&nbsp;&nbsp;&nbsp; virtual void b_1( void );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バイナリーAll１（すべてのビットを１にする）<br />&nbsp;&nbsp;&nbsp; virtual void b_comprement( void );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バイナリー補数に変換<br /><br />&nbsp;&nbsp;&nbsp; virtual void add( INT* a );<br />&nbsp;&nbsp;&nbsp; virtual void sub( INT* a );<br />&nbsp;&nbsp;&nbsp; virtual void mul( INT* a );<br />&nbsp;&nbsp;&nbsp; virtual void deq( INT* a );<br /><br />&nbsp;&nbsp;&nbsp; virtual void print(void);<br />&nbsp;&nbsp;&nbsp; virtual void print0x( void );<br />};<br /><br /><br /><br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>INT.cpp (0.0.7)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &quot;INT.h&quot;<br /><br />INT::INT(void)<br />{<br />&nbsp;&nbsp;&nbsp; fugou &nbsp;&nbsp;&nbsp; = +1;<br />&nbsp;&nbsp;&nbsp; len &nbsp;&nbsp;&nbsp; = 4;<br />&nbsp;&nbsp;&nbsp; byte &nbsp;&nbsp;&nbsp; = new (unsigned char*[len]);<br />&nbsp;&nbsp;&nbsp; for( long i = 0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; byte[i] = new (unsigned char);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *byte[i] = 0;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />INT::~INT(void)<br />{<br />&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete byte[i];<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; delete[] byte;<br />}<br /><br />// 余分な確保分のメモリー領域を開放して、len を正しい値に設定する。<br />void INT::gc(void)<br />{<br />&nbsp;&nbsp;&nbsp; long old_len = len;<br />&nbsp;&nbsp;&nbsp; long new_len = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 最低でも1byteの長さは残すため。（ デフォルトで =1 にしてある理由）<br /><br />&nbsp;&nbsp;&nbsp; for(long i = len-1; i &gt;= 1; i-- ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( *(byte[i]) == 0x00 ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new_len = i+1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; for(long i = old_len-1; i &gt;= new_len; i-- ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // len の位置以上の、使わない余分なメモリを開放する<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete (byte[i]);<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; len = new_len;<br /><br />// ポインタの配列そのものは開放しない。（伸びたら、伸びっぱなし）<br />// 毎回いちいちこれまで再定義して縮めてると、char をぶら下げ直す処理時間がバカにならない気がするので。これだと気になって気分的に使い辛くなるから。伸ばしっぱなし。触れない。<br /><br />//&nbsp;&nbsp;&nbsp; unsigned char** list = new (unsigned char*[len]);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // charをぶら下げるための、新しい長さの、ポインタの配列を新たに確保。(スワップ用）<br />//&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; len; i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 新しいポインタの配列に、古いcharをぶら下げなおす。<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list[i] = byte[i];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ポインタのコピー（アドレスのコピー）<br />//&nbsp;&nbsp;&nbsp; }<br /><br />//&nbsp;&nbsp;&nbsp; delete[] byte;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 古いリストの開放<br />&nbsp;&nbsp;&nbsp; <br />//&nbsp;&nbsp;&nbsp; byte = new (unsigned char*[len]);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // charをぶら下げるための、新しい長さの、ポインタの配列を新たに確保。<br />//&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; len; i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 新しいポインタの配列に、古いcharをぶら下げなおす。<br />//&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; byte[i] = list[i];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ポインタのコピー（アドレスのコピー）<br />//&nbsp;&nbsp;&nbsp; }<br />//&nbsp;&nbsp;&nbsp; delete[] list;<br />}<br /><br />// a の内容を自分に書き込む（ようするにコピーです）<br />void INT::copy( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; size_set( a-&gt;_len() );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の byte長を、a のbyte長にあわせる<br /><br />&nbsp;&nbsp;&nbsp; for(long i=0; i &lt; len; i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a のbyte内容を、thisのbyteに全部書き写す<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) = a-&gt;_byte(i);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; fugou = a-&gt;_fugou();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 符号も書き写す<br />}<br /><br />// 格納できる桁数を今より増やす（バイト単位）<br />void INT::size_add( long size )<br />{<br />&nbsp;&nbsp;&nbsp; if( size &lt;= 0 ) {return;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // size が０以下なら処理しないでリターン<br /><br />&nbsp;&nbsp;&nbsp; unsigned char** buf = new (unsigned char*[len + size]);<br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf[i] = byte[i];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ポインタの書き写し（あくまでポインタ。実体ではない）<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; delete[] byte;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // とりあえず開放<br />&nbsp;&nbsp;&nbsp; byte = new (unsigned char*[len + size]);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // そして再確保（領域拡張）<br /><br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; byte[i] = buf[i];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ポインタの書き写し（あくまでポインタ。実体ではない）<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; for(long i = len; i &lt; len + size; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; byte[i] &nbsp;&nbsp;&nbsp; = new (unsigned char);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // あらたな伸ばした分の領域を確保<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) &nbsp;&nbsp;&nbsp; = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 0で内容を初期化<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; len += size;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 新しいサイズをメモ<br />&nbsp;&nbsp;&nbsp; delete[] buf;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バッファーを開放して終了<br />}<br /><br />// 格納できる桁数を今より減らす（バイト単位）<br />void INT::size_dec( long size )<br />{<br />&nbsp;&nbsp;&nbsp; if( size &lt;= 0 ) {return;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // size が０以上なら処理しないでリターン<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; if( ( len - size ) &lt;= 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size = len - 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // もしsizeが大きすぎてlenが０以下になってしまう場合、size は len - size = 1 の数に設定。（最低でも１byteの長さを保つ）<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; for(long i = len - size; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; delete byte[i];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // len-size（新サイズ）以降のbyteを全て開放<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; unsigned char** buf = new (unsigned char*[len - size]);<br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; len-size; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf[i] = byte[i];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ポインタの書き写し（あくまでポインタ。実体ではない）<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; delete[] byte;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // とりあえず開放<br />&nbsp;&nbsp;&nbsp; byte = new (unsigned char*[len - size]);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // そして再確保（領域拡張）<br /><br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; len-size; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; byte[i] = buf[i];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ポインタの書き写し（あくまでポインタ。実体ではない）<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; len -= size;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 新しいサイズをメモ<br />&nbsp;&nbsp;&nbsp; delete[] buf;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バッファーを開放して終了<br />}<br /><br />// 格納できる桁数を設定する（バイト単位）<br />void INT::size_set( long size )<br />{<br />&nbsp;&nbsp;&nbsp; if( size &lt;= 0 ) {return;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // size が０以下なら処理しないでリターン<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; long dif = size - len;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 新サイズに対する、旧サイズの不足分<br /><br />&nbsp;&nbsp;&nbsp; if( dif &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // サイズが足りなければ増やす<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_add( dif );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if( dif &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // サイズが多ければ減らす<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dif=-dif;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_dec( dif );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // サイズが同じなら何もしない<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />// bit長を返す（もっともHSB側のbitの番目までの長さを返す。たとえばLSBのみが１なら長さは１。１バイトすべてが１なら長さは８）<br />long INT::_b_len(void)<br />{<br />&nbsp;&nbsp;&nbsp; for(long i=len-1; i&gt;=0; i-- ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned char c = *(byte[i]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( c != 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( c &amp; ((unsigned char)(0x01&lt;&lt;7)) ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( (i*8) + 8 );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( c &amp; ((unsigned char)(0x01&lt;&lt;6)) ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( (i*8) + 7 );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( c &amp; ((unsigned char)(0x01&lt;&lt;5)) ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( (i*8) + 6 );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( c &amp; ((unsigned char)(0x01&lt;&lt;4)) ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( (i*8) + 5 );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( c &amp; ((unsigned char)(0x01&lt;&lt;3)) ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( (i*8) + 4 );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( c &amp; ((unsigned char)(0x01&lt;&lt;2)) ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( (i*8) + 3 );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( c &amp; ((unsigned char)(0x01&lt;&lt;1)) ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( (i*8) + 2 );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( c &amp; ((unsigned char)(0x01&lt;&lt;0)) ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( (i*8) + 1 );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void INT::r_shift( long s )<br />{<br />&nbsp;&nbsp;&nbsp; if( s &lt;= 0 ) {return;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // シフト量が０、もしくはマイナスの場合は処理しないでリターン<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; long &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sm = s % 8;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ビット単位でのスモールなシフト量<br />&nbsp;&nbsp;&nbsp; long &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sb = s / 8;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バイト単位でのビッグなシフト量<br /><br />&nbsp;&nbsp;&nbsp; for(long i = sb; i &lt; len; i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // とりあえず sb 単位での移動を終わらしちゃおう。<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i-sb]) = *(byte[i]);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 内容を直接書き写しちゃう。ようするに普通のコピー。<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; long edge = len - sb; <br />&nbsp;&nbsp;&nbsp; if ( edge &lt; 0 ){ edge=0; }<br />&nbsp;&nbsp;&nbsp; for(long i=edge; i &lt; len; i++) {&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // シフトで空になった分は 0 で埋めます。<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; (*(byte[0])) &gt;&gt;= sm;<br />&nbsp;&nbsp;&nbsp; for(long i=1; i &lt; len; i++) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 次に残りの sm 単位での移動を終わらせちゃおう。<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned short buf;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf = (unsigned short)(*(byte[i]));<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf &lt;&lt;= 8;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i-1]) |= (unsigned char)( ( (buf &gt;&gt; sm) &gt;&gt; 0 ) &amp; 0x00FF );&nbsp;&nbsp;&nbsp; // 一個手前の値にORで加える&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i-0])&nbsp; = (unsigned char)( ( (buf &gt;&gt; sm) &gt;&gt; 8 ) &amp; 0x00FF );&nbsp;&nbsp;&nbsp; // こちらは単純に代入<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void INT::l_shift( long s )<br />{<br />&nbsp;&nbsp;&nbsp; if( s &lt;= 0 ) {return;}&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // シフト量が０、もしくはマイナスの場合は処理しないでリターン<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; long &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sm = s % 8;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ビット単位でのスモールなシフト量。<br />&nbsp;&nbsp;&nbsp; long &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sb = s / 8;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // バイト単位でのビッグなシフト量。<br /><br />&nbsp;&nbsp;&nbsp; for(long i = len-1; i &gt;= sb; i-- ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // とりあえず sb 単位での移動を終わらしちゃおう。逆順だから、すこしややこしい。<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) = *(byte[i-sb]);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 内容を直接書き写しちゃう。ようするに普通のコピー。<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; long edge = sb-1; <br />&nbsp;&nbsp;&nbsp; if ( edge &gt; (len-1) ){ edge=(len-1); }<br />&nbsp;&nbsp;&nbsp; for(long i=edge; i &gt;= 0; i--) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // シフトで空になった分は 0 で埋めます。逆順だから、すこしややこしい。<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; (*(byte[len-1])) &lt;&lt;= sm;<br />&nbsp;&nbsp;&nbsp; for(long i=len-1-1; i &gt;= 0; i--) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 次に残りの sm 単位での移動を終わらせちゃおう。逆順だから、すこしややこしい。<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned short &nbsp;&nbsp;&nbsp; buf;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf = (unsigned short)(*(byte[i]));<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i+1]) |= (unsigned char)( ( (buf &lt;&lt; sm) &gt;&gt; 8 ) &amp; 0x00FF );&nbsp;&nbsp;&nbsp; // 一個次の値にORで加える&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i+0])&nbsp; = (unsigned char)( ( (buf &lt;&lt; sm) &gt;&gt; 0 ) &amp; 0x00FF );&nbsp;&nbsp;&nbsp; // こちらは単純に代入<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />// バイナリーAND &amp;<br />void INT::b_and( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; long s_len;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; s_len = ( len &lt;= a-&gt;_len() ) ? len : a-&gt;_len();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ２つのうち、短い方のbyte長<br /><br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; s_len; i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 短い方の長さにあわせて処理<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) = (*(byte[i])) &amp; a-&gt;_byte(i);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 仮に、自分同士で計算してる場合でも、バッファーを介さなくても問題ない<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; for(long i = s_len; i &lt; len; i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 残りはすべて０をセット（短い方の、足りないbyte分は、すべて０と解釈して計算する）<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) = 0;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />// バイナリーOR&nbsp; |<br />void INT::b_or ( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; long s_len;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; s_len = ( len &lt;= a-&gt;_len() ) ? len : a-&gt;_len();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ２つのうち、短い方のbyte長<br /><br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; s_len; i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 短い方の長さにあわせて処理<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) = (*(byte[i])) | a-&gt;_byte(i);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 仮に、自分同士で計算してる場合でも、バッファーを介さなくても問題ない<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 残りはすべて不変（短い方の、足りないbyte分は、すべて０と解釈して計算する）<br />}<br /><br />// バイナリーXOR ^<br />void INT::b_xor( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; long s_len;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; s_len = ( len &lt;= a-&gt;_len() ) ? len : a-&gt;_len();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ２つのうち、短い方のbyte長<br /><br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; s_len; i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 短い方の長さにあわせて処理<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) = (*(byte[i])) ^ a-&gt;_byte(i);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 仮に、自分同士で計算してる場合でも、バッファーを介さなくても問題ない<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 残りはすべて不変（短い方の、足りないbyte分は、すべて０と解釈して計算する）<br />}<br /><br />// バイナリーNOT !<br />void INT::b_not( void )<br />{<br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) = ~(*(byte[i]));&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 仮に、自分同士で計算してる場合でも、バッファーを介さなくても問題ない<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />// バイナリーAll０<br />// （すべてのビットを０にする）<br />void INT::b_0( void )<br />{<br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) = 0;<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />// バイナリーAll１<br />// （すべてのビットを１にする）<br />void INT::b_1( void )<br />{<br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *(byte[i]) = (unsigned char)(0xFF);<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />// バイナリー補数に変換<br />void INT::b_comprement(void)<br />{<br />&nbsp;&nbsp;&nbsp; INT one;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 内容が 0x01 の INT型のインスタンスを作成するため<br />&nbsp;&nbsp;&nbsp; long one_l = 1;<br />&nbsp;&nbsp;&nbsp; one.set( one_l );<br /><br />&nbsp;&nbsp;&nbsp; INT buf;<br />&nbsp;&nbsp;&nbsp; buf.copy( this );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this のコピーを作り...<br />&nbsp;&nbsp;&nbsp; buf.b_not();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ビットを反転し<br />&nbsp;&nbsp;&nbsp; long old_len = buf._len();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // この時点でのlenサイズをメモ<br />&nbsp;&nbsp;&nbsp; buf._add( &amp;one );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 符号無視で１を加算。（両者は符号も同じなので、符号解釈ありでも結果は同じだが、一応、本来の意味で）<br /><br />&nbsp;&nbsp;&nbsp; if( buf._len() &gt; old_len ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // もしlenが増えてたら<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf.size_dec( buf._len() - old_len );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 増えた分、縮める。（buf._len() - old_len は 1byteのはず。buf.set_dec(1)でも同じだが、一応、本来の意味で）<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; copy( &amp;buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // buf を this にコピー<br />}<br /><br />// 符号を考慮した加算<br />void INT::add( INT* a )<br />{<br />//&nbsp;&nbsp;&nbsp; a-&gt;gc();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 保険<br />//&nbsp;&nbsp;&nbsp; gc();<br /><br />&nbsp;&nbsp;&nbsp; if ( fugou &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( a-&gt;_fugou() &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // どちらもプラスなら、通常の加算<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _add( a );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( a-&gt;_fugou() &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this がプラス、a がマイナスのケース<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int comp = comparison_abs( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 絶対値で比較<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( comp &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の方が大きければ<br />//printf(&quot;t - a\n&quot;);<br />//this-&gt;print0x();<br />//a-&gt;print0x();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _sub( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this - a として計算<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( comp &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a の方が大きければ<br />//printf(&quot;a - t\n&quot;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; INT buf;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf.copy( a );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf._sub( this );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a - this として計算し<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; copy( &amp;buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 加算結果を this に入れ<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = -1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号を -1 にする<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 絶対値での比較結果が同じだった場合<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set(0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this は 0<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if ( fugou &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号がマイナスの場合<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( a-&gt;_fugou() &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // どちらもマイナスなら、通常の加算<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _add( a );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( a-&gt;_fugou() &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this はマイナス、aはプラスのケース<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int comp = comparison_abs( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 絶対値で比較<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( comp &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の方が大きければ<br />//printf(&quot;bbbb&quot;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _sub( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this - a として計算<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( comp &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a の方が大きければ<br />//printf(&quot;aaaa&quot;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; INT buf;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf.copy( a );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf._sub( this );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a - this として計算し<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; copy( &amp;buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 加算結果を this に入れ<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = +1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号を +1 にする<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 絶対値での比較結果が同じだった場合<br />//printf(&quot;cccc&quot;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set(0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this は 0<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />//&nbsp;&nbsp;&nbsp; gc();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // もし余ってるメモリがあるなら開放<br />}<br /><br />// 符号を考慮しない加算（内部処理用）<br />void INT::_add( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; long s_len;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ２つのうち、短い方のbyte長<br />&nbsp;&nbsp;&nbsp; long b_len;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ２つのうち、短い方のbyte長<br />&nbsp;&nbsp;&nbsp; if( len &gt;= a-&gt;_len() ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s_len = a-&gt;_len();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; b_len = len;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s_len = len;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; b_len = a-&gt;_len();<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; a-&gt;size_set( b_len );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 長い方のサイズにあわせてメモリ確保<br />&nbsp;&nbsp;&nbsp; size_set( b_len );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 同<br /><br />&nbsp;&nbsp;&nbsp; unsigned short co = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // キャリーオーバーのメモ用<br />&nbsp;&nbsp;&nbsp; for(long i = 0; i &lt; b_len; i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 長い方の長さにあわせて処理<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned short buf1, buf2, buf3;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf1 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = (unsigned short)(*(byte[i]));<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf2&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = (unsigned short)(a-&gt;_byte(i));<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf3 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = (buf1 + co) + buf2;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _set_b( i, (unsigned char)( buf3 &amp; 0x00FF ) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; co&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = (buf3 &gt;&gt; 8) &amp; 0x00FF;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 今回分のキャリーオーバー量をメモ<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; if( co != 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // もし、キャリーオーバーの値があれば、それを格納するために１バイト伸ばして記録。<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size_add(1);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _set_b( len - 1, (unsigned char)( co &amp; 0x00FF) );<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void INT::sub( INT* a ) <br />{<br />//&nbsp;&nbsp;&nbsp; a-&gt;gc();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 保険<br />//&nbsp;&nbsp;&nbsp; gc();<br /><br />&nbsp;&nbsp;&nbsp; if ( fugou &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( a-&gt;_fugou() &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // どちらもプラスなら、通常の減算<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int comp = comparison_abs( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 絶対値で比較<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( comp &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の方が大きければ...<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _sub( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 通常の減算<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号は変化しない&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( comp &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a の方が大きければ...<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; INT buf;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf.copy( a );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf._sub( this );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; copy( &amp;buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a - this での減算<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = -1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号を -1 にする<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 絶対値での比較結果が同じだった場合<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set(0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this は 0<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( a-&gt;_fugou() &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this がプラス、a がマイナスのケース<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _add( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 加算を行い...<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号は変化しない<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if ( fugou &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号がマイナスの場合<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( a-&gt;_fugou() &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // どちらもマイナスなら...<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int comp = comparison_abs( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 絶対値で比較<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( comp &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の方が大きければ...<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _sub( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 通常の減算<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号は変化しない&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( comp &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a の方が大きければ...<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; INT buf;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf.copy( a );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf._sub( this );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; copy( &amp;buf );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a - this での減算<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = +1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号を +1 にする<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 絶対値での比較結果が同じだった場合<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; set(0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this は 0<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( a-&gt;_fugou() &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this がマイナス、a がプラスのケース<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _add( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 加算を行い...<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号は変化しない<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />//&nbsp;&nbsp;&nbsp; gc();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // もし余ってるメモリがあるなら開放<br />}<br /><br />void INT::_sub( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; INT a_c;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a の補数用<br />&nbsp;&nbsp;&nbsp; a_c.copy( a );<br />&nbsp;&nbsp;&nbsp; a_c.size_set(len);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a_c を this の len と同じbyte長に設定<br />&nbsp;&nbsp;&nbsp; a_c.b_comprement();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 実際に a の補数を得る<br /><br />&nbsp;&nbsp;&nbsp; long old_len = len;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の、この時点でのbyte長をメモ<br />&nbsp;&nbsp;&nbsp; _add( &amp;a_c );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this に補数を加算する（減算）（符号は無視する）<br /><br />&nbsp;&nbsp;&nbsp; if( len &gt; old_len ) { size_set(old_len); }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // もしold_lenより伸びてたら、lenの長さまでちぢめる<br />}<br /><br />void INT::mul( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; _mul(a);<br /><br />&nbsp;&nbsp;&nbsp; if( fugou &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( a-&gt;_fugou() &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = +1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if( a-&gt;_fugou() &lt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = -1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if( fugou &lt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( a-&gt;_fugou() &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = -1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if( a-&gt;_fugou() &lt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = +1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void INT::_mul( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; a-&gt;gc();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 必要最小限のbyte長のlenを得る<br />&nbsp;&nbsp;&nbsp; gc();<br /><br />&nbsp;&nbsp;&nbsp; long old_fugou_a &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = a-&gt;_fugou();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 符号を一時的に保存<br />&nbsp;&nbsp;&nbsp; long old_fugou_this &nbsp;&nbsp;&nbsp; = fugou;<br /><br />&nbsp;&nbsp;&nbsp; a-&gt;_set_fugou(+1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 符号を一時的に＋に設定<br />&nbsp;&nbsp;&nbsp; fugou=+1;<br /><br />&nbsp;&nbsp;&nbsp; long b_len;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ２つのうち、長い方のbyte長<br />&nbsp;&nbsp;&nbsp; b_len = ( len &gt;= a-&gt;_len() ) ? len : a-&gt;_len();<br /><br />&nbsp;&nbsp;&nbsp; INT b;<br />&nbsp;&nbsp;&nbsp; b.copy( this );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 参照用バッファに、自分自身の値をコピー<br /><br />&nbsp;&nbsp;&nbsp; set( 0 );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 自分自身の内容を0にリセット<br /><br />&nbsp;&nbsp;&nbsp; INT sft;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; sft.copy( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // シフトには a をつかう。<br />&nbsp;&nbsp;&nbsp; sft.size_set( b_len * 2 );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // b_len の２倍のサイズを確保。<br /><br />&nbsp;&nbsp;&nbsp; long sft_count = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ループ中での、次のシフト量のカウント用<br /><br />&nbsp;&nbsp;&nbsp; for(long byte_i = 0;&nbsp; byte_i &lt; b_len; byte_i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 長い方のバイト長回数分だけ繰り返す<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(long bit_i = 0; bit_i &lt; 8; bit_i++ ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // １バイト中のビット数（８ビット）回数分だけ繰り返す<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned char bit_msk = (0x01 &lt;&lt; bit_i);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( ( b._byte( byte_i ) &amp; bit_msk ) != 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 現在の byte_i の bit_i 番目のビットが１なら<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sft.l_shift( sft_count );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // sht の内容を、シフトカウント分だけ左シフトする&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; add( &amp;sft );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // その sht を自分自身に加算<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sft_count = 0;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // カウンタリセット<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 直後ですぐ１になる。これを０で回してしまうと、仮にその回でシフトの必要が発生しても、シフト０に<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // なってしまう。（シフトされないバグになる）<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // シフト０が使われるのは最初の先頭一回目のみ。あとはシフトは必ず１以上。微妙に組み間違えやすいので注意。<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sft_count++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // カウンターを１回進める。<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br /><br />&nbsp;&nbsp;&nbsp; a-&gt;_set_fugou(old_fugou_a);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 一時的に変更した符号を、元に戻す<br />&nbsp;&nbsp;&nbsp; fugou = old_fugou_this;<br /><br />&nbsp;&nbsp;&nbsp; a-&gt;gc();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 無駄なbyte長を捨てる<br />&nbsp;&nbsp;&nbsp; gc();<br />}<br /><br />void INT::deq( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; _deq( a );<br /><br />&nbsp;&nbsp;&nbsp; if( fugou &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( a-&gt;_fugou() &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = +1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if( a-&gt;_fugou() &lt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = -1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if( fugou &lt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( a-&gt;_fugou() &gt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = -1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if( a-&gt;_fugou() &lt; 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fugou = +1;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />void INT::_deq( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; a-&gt;gc();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 必要最小限のbyte長のlenを得る<br />&nbsp;&nbsp;&nbsp; gc();<br /><br />&nbsp;&nbsp;&nbsp; long old_fugou_a &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = a-&gt;_fugou();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 符号を一時的に保存<br />&nbsp;&nbsp;&nbsp; long old_fugou_this &nbsp;&nbsp;&nbsp; = fugou;<br /><br />&nbsp;&nbsp;&nbsp; a-&gt;_set_fugou(+1);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 符号を一時的に＋に設定<br />&nbsp;&nbsp;&nbsp; fugou=+1;<br /><br /><br />&nbsp;&nbsp;&nbsp; long a_bitlen &nbsp;&nbsp;&nbsp; = a-&gt;_b_len();<br />&nbsp;&nbsp;&nbsp; long this_bitlen&nbsp;&nbsp;&nbsp; = _b_len();<br />&nbsp;&nbsp;&nbsp; long dif_bitlen = this_bitlen - a_bitlen;<br /><br />&nbsp;&nbsp;&nbsp; if( dif_bitlen &lt; 0 ){ set(0); return; }<br /><br /><br />&nbsp;&nbsp;&nbsp; INT ans;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 減算回数のカウント用（これが除算結果）<br />&nbsp;&nbsp;&nbsp; ans.size_set( len );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this と同じbyte長に<br /><br />&nbsp;&nbsp;&nbsp; INT buf;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 雑用<br />&nbsp;&nbsp;&nbsp; buf.size_set( len );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this と同じbyte長に<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; INT sft;<br />&nbsp;&nbsp;&nbsp; sft.copy( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // これをシフトしながら減算に使う<br />&nbsp;&nbsp;&nbsp; sft.size_set( len );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this と同じbyte長に<br /><br />&nbsp;&nbsp;&nbsp; sft.l_shift( dif_bitlen );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // bit長の差分だけ左シフト<br />&nbsp;&nbsp;&nbsp; for(long i=0; i &lt;= dif_bitlen; i++ ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( comparison_abs( &amp;sft ) &gt;= 0 ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sub( &amp;sft );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf.b_0();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf.set(0x01);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buf.l_shift( (dif_bitlen)-i );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ans.b_or(&amp;buf);&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sft.r_shift(1);<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; copy(&amp;ans);<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; a-&gt;_set_fugou(old_fugou_a);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 一時的に変更した符号を、元に戻す<br />&nbsp;&nbsp;&nbsp; fugou = old_fugou_this;<br /><br />&nbsp;&nbsp;&nbsp; a-&gt;gc();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 無駄なbyte長を捨てる<br />&nbsp;&nbsp;&nbsp; gc();<br />}<br /><br />// 比較を行い、＝なら０、自分の方が大きい（＞）なら＋１、aの方が大きい（＜）なら-1を返す<br />int INT::comparison( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; int comp =&nbsp; comparison_abs( a );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // とりあえず絶対値で符号無視による比較<br /><br />&nbsp;&nbsp;&nbsp; if( fugou &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号がプラス<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( a-&gt;_fugou() &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this も a もどちらもプラスのケース<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( comp );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 通常の比較<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if( a-&gt;_fugou() &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this がプラス、a がマイナスのケース<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( +1 );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this が大きいと判定<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else if( fugou &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this の符号がマイナス<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( a-&gt;_fugou() &lt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this も a もどちらもマイナスのケース<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( -comp );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 通常の比較の逆（*マイナス）&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( a-&gt; _fugou() &gt; 0 ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // this がマイナス、a がプラスのケース<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return( -1 );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // a が大きいと判定&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />// 絶対値で比較。あとは comparison() と同じ<br />int INT::comparison_abs( INT* a )<br />{<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret_large_s;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret_large_b;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret_equal = 0;<br /><br />&nbsp;&nbsp;&nbsp; INT*&nbsp;&nbsp;&nbsp; s_int;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ２つのうち、短い方のINTへのアドレス<br />&nbsp;&nbsp;&nbsp; INT*&nbsp;&nbsp;&nbsp; b_int;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ２つのうち、長い方のINTへのアドレス<br /><br />&nbsp;&nbsp;&nbsp; if ( len &gt;= a-&gt;_len() ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s_int = a;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; b_int = this;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret_large_s = -1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // s_int が大きかった場合に、-1を返す。（aが大きいの意味なので） <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret_large_b = +1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // b_int が大きかった場合に、+1を返す。（thisが大きいの意味なので）<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s_int = this;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; b_int = a;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret_large_s = +1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // s_int が大きかった場合に、+1を返す。（thisが大きいの意味なので） <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ret_large_b = -1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // b_int が大きかった場合に、-1を返す。（aが大きいの意味なので）<br />&nbsp;&nbsp;&nbsp; }<br /><br /><br />&nbsp;&nbsp;&nbsp; for(int i=b_int-&gt;_len(); i &gt; s_int-&gt;_len(); i-- ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 最後（一番大きい桁側）から読んでいき、s_int の最後に行き着くまでに 非０ の値があれば、こちらが大きい<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( b_int-&gt;_byte(i) != 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return ret_large_b;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // b_int の方が大きいと解釈してリターン<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; for(int i=s_int-&gt;_len(); i &gt;= 0; i-- ) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // s_int の最後（一番大きい桁側）から読んでいき、0に行き着くまで、どちらが大きいかを比較する<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unsigned char cs,cb;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cs = s_int-&gt;_byte(i);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cb = b_int-&gt;_byte(i);<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( cb &gt; cs ){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return ret_large_b;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // b_int の方が大きいと解釈してリターン<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ( cs &gt; cb ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return ret_large_s;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // s_int の方が大きいと解釈してリターン<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return ret_equal;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // b_int と s_int に違いが無かったので、同じ値だと解釈してリターン<br />}<br /><br />void INT::set( long l )<br />{<br />&nbsp;&nbsp;&nbsp; size_set(4);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // thisを4byteの長さに&nbsp;&nbsp;&nbsp; <br /><br />&nbsp;&nbsp;&nbsp; if( l &lt; 0 ) { l = -l; fugou = -1; } else { fugou = +1; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 符号<br /><br />&nbsp;&nbsp;&nbsp; *byte[0] = (unsigned char)( ( l &amp; 0x000000FF ) &gt;&gt; 0&nbsp; ); <br />&nbsp;&nbsp;&nbsp; *byte[1] = (unsigned char)( ( l &amp; 0x0000FF00 ) &gt;&gt; 8&nbsp; ); <br />&nbsp;&nbsp;&nbsp; *byte[2] = (unsigned char)( ( l &amp; 0x00FF0000 ) &gt;&gt; 16 ); <br />&nbsp;&nbsp;&nbsp; *byte[3] = (unsigned char)( ( l &amp; 0xFF000000 ) &gt;&gt; 24 ); <br />}<br /><br />void INT::print( void ) <br />{<br />&nbsp;&nbsp;&nbsp; long l;<br />&nbsp;&nbsp;&nbsp; l =<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;( ((unsigned long)(*byte[0]))&nbsp; &lt;&lt; 0&nbsp; ) |<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;( ((unsigned long)(*byte[1]))&nbsp; &lt;&lt; 8&nbsp; ) |<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;( ((unsigned long)(*byte[2]))&nbsp; &lt;&lt; 16 ) |<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;( ((unsigned long)(*byte[3]))&nbsp; &lt;&lt; 24 );<br /><br />&nbsp;&nbsp;&nbsp; if( fugou&lt;0 ){ l=-l; }<br /><br />&nbsp;&nbsp;&nbsp; printf( &quot;%ld&quot;, l );<br />}<br /><br />void INT::print0x( void ) <br />{<br />&nbsp;&nbsp;&nbsp; if ( fugou &lt; 0 ) putchar('-');<br /><br />&nbsp;&nbsp;&nbsp; printf(&quot;0x&quot;);<br /><br />&nbsp;&nbsp;&nbsp; for(long i = len-1; i &gt;= 0; i-- ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf( &quot;%02X&quot;, *byte[i] );<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( ( i % 4 ) == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; putchar(' ');<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( ( i % 32 ) == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; putchar('\n');<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; putchar(' ');<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; putchar(' ');<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br /></td></tr></tbody></table><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-11-25T22:53:53+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-36.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-36.html</link>
<title>ふぁむいり</title>
<description> たのしかたわるのりまた描いてるよコイツ…w泣いたうろおぼえコスモス
 </description>
<content:encoded>
<![CDATA[ たのしかた<br /><a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091123_02x.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091123_02x.jpg" alt="20091123_02x.jpg" border="0" width="1213" height="871" /></a><br /><br />わるのり<br /><a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091123_3x.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091123_3x.jpg" alt="20091123_3x.jpg" border="0" width="1115" height="916" /></a><br /><br />また描いてるよコイツ…w<br /><a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091123_5.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091123_5.jpg" alt="20091123_5.jpg" border="0" width="853" height="861" /></a><br /><br />泣いた<br /><a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091123_6x.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091123_6x.jpg" alt="20091123_6x.jpg" border="0" width="813" height="979" /></a><br /><br />うろおぼえコスモス<br /><a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091123_07x.jpg" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091123_07x.jpg" alt="20091123_07x.jpg" border="0" width="554" height="1136" /></a><br /><br /> ]]>
</content:encoded>
<dc:subject>絵チャット</dc:subject>
<dc:date>2009-11-23T01:47:51+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-31.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-31.html</link>
<title>チャー</title>
<description> 
 </description>
<content:encoded>
<![CDATA[ <a href="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091120_01x.png" target="_blank"><img src="http://blog-imgs-34-origin.fc2.com/k/e/m/kemeconoajito/20091120_01x.png" alt="20091120_01x.png" border="0" width="921" height="673" /></a><br /> ]]>
</content:encoded>
<dc:subject>絵関係</dc:subject>
<dc:date>2009-11-20T01:27:22+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-35.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-35.html</link>
<title>SCREEN　メモ (0.0.1)</title>
<description> スクリーンへの描画関係を担当。まだ全然プロトタイプ。大まかなアルゴリズムの確認で行き当たりばったりで組んだので、全体的に絡みがひどい、見通しの悪い、わかりずらい仕組みになってる。もっと単純・簡単な景色へと書き直さないとしないと、難しくて使えない&amp;hellip;使いたくない（orz具体的には今後、STRING型をCHAR型で書き直して、そのSTRING型でLINE_LIST型を書き直して、そのLINE_LIST型でSCREEN型を書き直したらどうか
 </description>
<content:encoded>
<![CDATA[ スクリーンへの描画関係を担当。<br />まだ全然プロトタイプ。<br />大まかなアルゴリズムの確認で行き当たりばったりで組んだので、全体的に絡みがひどい、見通しの悪い、わかりずらい仕組みになってる。<br />もっと単純・簡単な景色へと書き直さないとしないと、難しくて使えない&hellip;使いたくない（orz<br /><br />具体的には今後、STRING型をCHAR型で書き直して、そのSTRING型でLINE_LIST型を書き直して、そのLINE_LIST型でSCREEN型を書き直したらどうかなぁ&hellip;と考えてます。<br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>SCREEN.h (0.0.1)</td></tr><tr><td>/*<br />&nbsp;&nbsp;&nbsp; SCREEN<br />&nbsp;&nbsp;&nbsp; SCREENにはスクリーンへの文字バッファの描画を担当する。<br />&nbsp;&nbsp;&nbsp; ユーザーはSCREENの文字バッファに文字列を登録して、SCREENに描画を実行させる。<br />&nbsp;&nbsp;&nbsp; 文字バッファには文字情報が格納されてるが、ここはあくまで描画バッファなので、ここからデータを『取り出す』ような使い方はしてはいけない。<br />&nbsp;&nbsp;&nbsp; あくまでSCREENの仕事は与えられたバッファをスクリーンに描画するのみである。<br />&nbsp;&nbsp;&nbsp; ここを文字情報の格納場所として考えたような使い方は『しないように！！』。（これは各モジュール間の依存関係を極力なくすため作戦です）<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; SCREENの構造の説明<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; sl はポインタの配列である。ここにはデータの大本となる str 配列へのポインタが格納される。<br />&nbsp;&nbsp;&nbsp; sl の配列サイズは screen_h である。これは改行に依存せずに、純粋に行数で考えた場合を扱うために用意してある。<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; _bufは screen_w * screen_h の長さの配列である。<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; rb はポインタの配列である。これは_bufを２次元配列として扱い易くするために、_bufの各行の先頭にあたるアドレスを保存する。<br />&nbsp;&nbsp;&nbsp; これを用いて _buf にアクセスすれば計算量が減るし、扱いも簡単である。<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; rl はROW_LINK型の配列である。サイズはscreen_h<br />&nbsp;&nbsp;&nbsp; ROW_LINKの内容は to_line_link に rb の添え字番号、line_separete_index には行の分割番目を記録する。<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; これらを用いての、一連の使用法の例を説明する。<br />&nbsp;&nbsp;&nbsp; まず SCREEN に表示させたい文字列 str を用意する。この str の文字列長は、いくら長くてもよい。<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; 次に str を sl にリンクする。<br />&nbsp;&nbsp;&nbsp; これは、SCREEN の仮想行（文字列がscreen_wを超えた場合の改行を考慮しない、純粋な行数）で考えた場合の、表示させたい行数である。<br />&nbsp;&nbsp;&nbsp; たとえば、元のテキストの10行目を仮想行の１行目に表示させたいなら sl[0] である。３行目なら sl[2] という要領である。<br />&nbsp;&nbsp;&nbsp; sl には「文字列を screen_w の幅に収めて、あまった分は改行して&hellip;」という概念が無い。純粋な『行』という概念で考えてよい。<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; つぎに、slの指し示す内容を、 _buf に実際に書き込む。<br />&nbsp;&nbsp;&nbsp; 直接 _buf を操作すると煩雑になるので、_buf にリンクされた rb を用いる。<br />&nbsp;&nbsp;&nbsp; rb に行を書き込む操作は、常に他の行への影響の可能性があるので、常に全体での一連の操作が必要になる。<br />&nbsp;&nbsp;&nbsp; つまり、たとえば rb の10行目だけを書き換えることはできない。10行目だけで十分な場合でも rb[0] から screen_h 分の更新が必要である。<br />&nbsp;&nbsp;&nbsp; まず最初に、rb[0] に sl[0] の内容を書き込むことから始まる。<br />&nbsp;&nbsp;&nbsp; 具体的には sl[0] の指し示す str の（長さ / screen_w）が x &gt; 0 ならば複数行という意味であり、書き込みループ回数を表し、<br />&nbsp;&nbsp;&nbsp; この rb[0] の（ 書き込みループ回数 * screen_w ）が、そのループ回での書き込みに用いる str の先頭アドレスであり、<br />&nbsp;&nbsp;&nbsp; これらを用いて rb[0],rb[1],rb[2],,, と書き込んでいく。その際に用いたslのindexが、各行のto_line_linkであり、indexが link_separete_index である。<br />&nbsp;&nbsp;&nbsp; この一連の処理によって sl[0] を _buf の（指定行～必要行分）だけ書き込んだことになる。<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; たとえば例として sl[0] にリンクされた str の文字列長が 200 文字、screen_w が 80 ならば、rb の内容は、<br />&nbsp;&nbsp;&nbsp; rb[0] = sl[0] + 0-1&nbsp;&nbsp; ～ sl[0] + 80-1<br />&nbsp;&nbsp;&nbsp; rb[1] = sl[0] + 80-1&nbsp; ～ sl[0] + 160-1<br />&nbsp;&nbsp;&nbsp; rb[2] = sl[0] + 160-1 ～ sl[0] + 200-160-1<br />&nbsp;&nbsp;&nbsp; となり、<br />&nbsp;&nbsp;&nbsp; rl[0～2].to_line_link = 0<br />&nbsp;&nbsp;&nbsp; rl[0～2].line_separate_index = 80, 80, 40<br />&nbsp;&nbsp;&nbsp; となる。<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; この要領で、rb[screen_h-1]まで処理を繰り返すことにより、_bufへの登録が完了する。<br />&nbsp;&nbsp;&nbsp; 以上。<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; ROW_LINK について：<br />&nbsp;&nbsp;&nbsp; なぜこれが用意されてるかというと、スクリーン位置と、文字列の仮想行上での位置の対応を、簡単に計算するためである。<br />&nbsp;&nbsp;&nbsp; つまり、スクリーンカーソル位置を仮想行上での位置に簡単に変換するためである。また、その逆も。<br />&nbsp;<br />*/<br />&nbsp;<br />#ifndef _SCREEN_H_<br />#define _SCREEN_H_<br />&nbsp;<br />#include &lt;stdio.h&gt;<br />#include &quot;CURSOR_CONTROL.h&quot;<br />&nbsp;<br />#define DEF_SCREEN_W 132<br />#define DEF_SCREEN_H 43<br />&nbsp;<br />typedef struct tagROW_LINK {<br />&nbsp;&nbsp;&nbsp; int to_line_link;<br />&nbsp;&nbsp;&nbsp; int line_separete_index;<br />} ROW_LINK;<br />&nbsp;<br />typedef struct tagSCREEN {<br />&nbsp;&nbsp;&nbsp; int screen_w;<br />&nbsp;&nbsp;&nbsp; int screen_h;<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; ROW_LINK* rl;&nbsp;&nbsp;&nbsp; // 各行が、実際の行数の何行目に対応しているかのリンクを指す構造体の、配列<br />&nbsp;&nbsp;&nbsp; char* _buf;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // w * h の長さの１次元配列<br />&nbsp;&nbsp;&nbsp; char** rb;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // _bufの各行の先頭アドレスを指す、ポインタの配列。（いちいち h * screen_w + w しなくても簡単にアクセスできるように）<br />&nbsp;&nbsp;&nbsp; char** sl;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 大本の文字列strへのリンク<br />} SCREEN;<br />&nbsp;<br />extern void initSCREEN( SCREEN* scr );<br />extern void resizeSCREEN( SCREEN* scr, int w, int h );<br />&nbsp;<br />// 大本の行 sl の index に登録する。<br />// あくまでリンクにすぎない（実際の文字データのコピーは行われない。実際の_buf へのコピーは refresh_bufSCREEN()で行われる。）<br />// index が範囲外の場合は何もせずにリターンする。<br />extern void reg_strSCREEN( SCREEN* scr, int index, char* str );<br />&nbsp;<br />// sl にリンクされた文字列の内容で _buf を更新する。<br />extern void refresh_bufSCREEN( SCREEN* scr );<br /><br />// _bufの内容を画面に出力する<br />extern void printSCREEN( SCREEN* scr, CURSOR_CONTROL* cc );<br />&nbsp;<br />#endif // _SCREEN_H_<br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>SCREEN.c (0.0.1)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br />#include &quot;SCREEN.h&quot;<br />#include &quot;CURSOR_CONTROL.h&quot;<br />&nbsp;<br />extern void __link_buf2rbSCREEN( SCREEN* scr );<br />extern void __initSCREEN( SCREEN* scr );<br />&nbsp;<br />// buf と rb を結びつける<br />void __link_buf2rbSCREEN( SCREEN* scr )<br />{<br />&nbsp;&nbsp;&nbsp; int j;<br />&nbsp;&nbsp;&nbsp; for ( j=0; j&lt;scr-&gt;screen_h; j++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; scr-&gt;rb[j] = &amp;scr-&gt;_buf[scr-&gt;screen_w * j];<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />// 文字列バッファを初期値 ' ' で埋める<br />void __initSCREEN( SCREEN* scr )<br />{<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;scr-&gt;screen_h*scr-&gt;screen_w;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; scr-&gt;_buf[i]=' ';<br />&nbsp;&nbsp;&nbsp; }<br />}<br />&nbsp;<br />void initSCREEN( SCREEN* scr )<br />{<br />&nbsp;&nbsp;&nbsp; scr-&gt;screen_w = DEF_SCREEN_W;<br />&nbsp;&nbsp;&nbsp; scr-&gt;screen_h = DEF_SCREEN_H;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; scr-&gt;_buf&nbsp;&nbsp;&nbsp; = (char*)malloc( sizeof(char) * scr-&gt;screen_w * scr-&gt;screen_h );<br />&nbsp;&nbsp;&nbsp; scr-&gt;rl&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = (ROW_LINK*)malloc( sizeof(ROW_LINK) * scr-&gt;screen_h );<br />&nbsp;&nbsp;&nbsp; scr-&gt;rb&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = (char**)malloc( sizeof(char*) * scr-&gt;screen_h );<br />&nbsp;&nbsp;&nbsp; scr-&gt;sl&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = (char**)malloc( sizeof(char*) * scr-&gt;screen_h );<br /><br />&nbsp;&nbsp;&nbsp; __initSCREEN( scr );<br />&nbsp;&nbsp;&nbsp; __link_buf2rbSCREEN( scr );<br />}<br />&nbsp;<br />void resizeSCREEN( SCREEN* scr, int w, int h )<br />{<br />&nbsp;&nbsp;&nbsp; scr-&gt;screen_w = w;<br />&nbsp;&nbsp;&nbsp; scr-&gt;screen_h = h;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; scr-&gt;_buf&nbsp;&nbsp;&nbsp; = (char*)realloc( scr-&gt;_buf, sizeof(char) * scr-&gt;screen_w * scr-&gt;screen_h );<br />&nbsp;&nbsp;&nbsp; scr-&gt;rl&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = (ROW_LINK*)realloc( scr-&gt;rl, sizeof(ROW_LINK) * scr-&gt;screen_h ); &nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; scr-&gt;rb&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = (char**)realloc( scr-&gt;rb, sizeof(char*) * scr-&gt;screen_h );&nbsp;<br />&nbsp;&nbsp;&nbsp; scr-&gt;sl&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = (char**)realloc( scr-&gt;sl, sizeof(char*) * scr-&gt;screen_h );<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; __initSCREEN( scr );<br />&nbsp;&nbsp;&nbsp; __link_buf2rbSCREEN( scr );<br />}<br />&nbsp;<br />// 大本の行 sl の index に登録する。<br />// あくまでリンクにすぎない（実際の文字データのコピーは行われない。実際の_buf へのコピーは refresh_bufSCREEN()で行われる。）<br />// index が範囲外の場合は何もせずにリターンする。<br />//<br />// 注！！：引数で渡すstrは、文字の最後に必ず &yen;0 が付加されてること！！<br />void reg_strSCREEN( SCREEN* scr, int index, char* str )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &gt;= scr-&gt;screen_h || index &lt; 0 ) { return; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; scr-&gt;sl[index] = str;<br />}<br />&nbsp;<br />// sl にリンクされた文字列の内容で _buf を更新する。<br />void refresh_bufSCREEN( SCREEN* scr )<br />{<br />&nbsp;&nbsp;&nbsp; int j,jj;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; int cur_sh;<br />&nbsp;&nbsp;&nbsp; char* src = scr-&gt;sl[0];<br />&nbsp;&nbsp;&nbsp; char* cur_src_line_top;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp; cur_src_line_len;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; char* dst = scr-&gt;rb[0];<br />&nbsp;&nbsp;&nbsp; char* cur_dst_line_top;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; cur_sh=0; // 現在のスクリーンの書き込み行&nbsp;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; for(j=0;j&lt;scr-&gt;screen_h;j++){&nbsp;&nbsp;&nbsp; // 書き込み元の、最大書き込み可能行数の高さ分（スクリーンの高さと同じ）<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; src = scr-&gt;sl[j];&nbsp;&nbsp;&nbsp; // 書き込み元アドレスを sl から、現在の書き込み行番目を得る<br />//printf(&quot;sl=%s&quot;,src);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_src_line_len = ((int)strlen(src))/scr-&gt;screen_w; // 現在の書き込み行の、スクリーン書き込み用の仮想行数。<br />//printf(&quot;cur_src_line_len=%d &quot;,cur_src_line_len);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(jj=0; jj&lt;=cur_src_line_len; jj++){&nbsp;&nbsp;&nbsp; // 仮想行数分だけ繰り返す（cur_src_line_lenは１行の時は０なので &lt; ではなく &lt;= で結んでる）<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (cur_sh &gt;= scr-&gt;screen_h ) {<br />//printf(&quot;&yen;n単行複数行化ありcur_sh=%d&yen;n &quot;,cur_sh );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return;&nbsp;&nbsp;&nbsp; // スクリーン書き込み行が、スクリーン高さに達したらリターンして終了<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;<br />//printf(&quot;cur_sh=%d &quot;,cur_sh);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_src_line_top = &amp;(src[scr-&gt;screen_w * jj]);&nbsp;&nbsp;&nbsp; // 書き込み元の先頭アドレスを、仮想行の先頭に設定する(仮想行ｘスクリーン幅）<br />//printf(&quot;cur_src_line_top=%d &quot;,(int)cur_src_line_top);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_dst_line_top = scr-&gt;rb[cur_sh];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 書き込み先の先頭アドレス。こちらは文字位置ではなく、行そのものの移動。この違いに注意。<br />//printf(&quot;scr-&gt;rb[cur_sh]=%d&yen;n &quot;,(int)scr-&gt;rb[cur_sh]);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(jj &lt;= cur_src_line_len){ // 仮想的に分割した行の最後でなければ<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int len = scr-&gt;screen_w;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; strncpy( cur_dst_line_top, cur_src_line_top, len ); //(int)strlen(cur_src_line_top) ); // 実際に文字列をコピー<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_dst_line_top[len]='&yen;0';<br />//printf( &quot;%s&yen;n&quot;,cur_dst_line_top);<br />//printf(&quot; screen_w = %d ; strlen = %d &quot;,scr-&gt;screen_w, strlen(cur_dst_line_top) );&nbsp;<br />//printf(&quot;%d strcpy=%s&yen;n &quot;,(int)cur_dst_line_top, cur_dst_line_top );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else { //最後ならば<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int len = (int)strlen(cur_src_line_top);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; strncpy( cur_dst_line_top, cur_src_line_top, len );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_dst_line_top[len]='&yen;0';<br />//printf( &quot;%s&yen;n&quot;,cur_dst_line_top);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cur_sh++; // 現在のスクリーンの書き込み位置を次に進める<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />//printf(&quot;&yen;ncur_sh=%d&yen;n &quot;,cur_sh );<br />}<br /><br />// _bufの内容を画面に出力する<br />void printSCREEN( SCREEN* scr, CURSOR_CONTROL* cc )<br />{<br />&nbsp; //&nbsp;&nbsp;&nbsp; clear_screen();<br /><br />&nbsp;&nbsp;&nbsp; int row,colum;<br />&nbsp;&nbsp;&nbsp; for( row=0; row&lt;scr-&gt;screen_h; row++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for( colum=0; colum&lt;scr-&gt;screen_w; colum++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; __setposCURSOR_CONTROL( colum, row );<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char c = scr-&gt;rb[row][colum];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(c=='&yen;0' || c=='&yen;n') {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; putchar(c);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; __setposCURSOR_CONTROL( cc-&gt;pos_x, cc-&gt;pos_y );<br />}<br /></td></tr></tbody></table><br /><br /><br /><br /> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-11-20T00:00:05+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-34.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-34.html</link>
<title>ETC_MATH メモ (0.0.6)</title>
<description> その他、雑多な関数。int pow( int a, int inv )ainv 、ただしinvは正のみint _dig( int a, int cardinal )a の桁数を求める。　cardeinal には 10 と書けばいい。aもcardinalも正のみ。void itos( char* dst, int src )整数型 src から 文字列型 dst への変換。src は正の数字のみ。dst の長さは不定。十分に長いサイズのバッファを与えること。ETC_MATH.h (0.0.6)#ifndef _ETC_MATH_H_#define _ETC_MATH_H_&amp;nbsp;// a^invextern 
 </description>
<content:encoded>
<![CDATA[ その他、雑多な関数。<br /><br />int pow( int a, int inv )<br />a<sup>inv</sup> 、ただしinvは正のみ<br /><br />int _dig( int a, int cardinal )<br />a の桁数を求める。　cardeinal には 10 と書けばいい。<br />aもcardinalも正のみ。<br /><br />void itos( char* dst, int src )<br />整数型 src から 文字列型 dst への変換。<br />src は正の数字のみ。<br />dst の長さは不定。十分に長いサイズのバッファを与えること。<br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>ETC_MATH.h (0.0.6)</td></tr><tr><td>#ifndef _ETC_MATH_H_<br />#define _ETC_MATH_H_<br />&nbsp;<br />// a^inv<br />extern int pow(int a, int inv );<br />&nbsp;<br />// 基数による桁数<br />extern int _dig(int a, int cardinal );<br />&nbsp;<br />// 数値型から文字列型<br />extern void itos( char* dst, int src );<br />&nbsp;<br />#endif // _ETC_MATH_H_<br />&nbsp;</td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>ETC_MATH.c (0.0.6)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &quot;ETC_MATH.h&quot;<br />&nbsp;<br />// a^inv<br />int pow(int a, int inv )<br />{<br />&nbsp;&nbsp;&nbsp; int r=a;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; if(inv==0) r=1;<br />&nbsp;&nbsp;&nbsp; if(inv==1) r=a;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=2;i&lt;=inv;i++){r*=a;}<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; return(r);<br />}<br />&nbsp;<br />// 基数による桁数<br />int _dig(int a, int cardinal )<br />{<br />&nbsp;&nbsp;&nbsp; if( cardinal ==0 ){printf(&quot;err: dig() cardinal&yen;n&quot;);exit(1);}<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; int count=0;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; while(a&gt;0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; count++;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; a/=cardinal;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( a &lt;= 0 ) { break; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; return(count);<br />}<br />&nbsp;<br />// 数値型から文字列型<br />void itos( char* dst, int src )<br />{<br />&nbsp;&nbsp;&nbsp; if(src &gt; 0){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int p;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int unit;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int sub=0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int dig=_dig(src,10);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=0;i&lt;dig;i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; p=pow(10,i+1);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sub+=((src%p)-sub);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; unit=sub / pow(10, i);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(unit){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0:dst[dig-1-i]='0';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 1:dst[dig-1-i]='1';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 2:dst[dig-1-i]='2';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 3:dst[dig-1-i]='3';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 4:dst[dig-1-i]='4';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 5:dst[dig-1-i]='5';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 6:dst[dig-1-i]='6';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 7:dst[dig-1-i]='7';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 8:dst[dig-1-i]='8';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 9:dst[dig-1-i]='9';break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default:printf(&quot;err: itos() dst[%d]&yen;n&quot;,dig-1-i ); exit(1); break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[dig]='&yen;0';<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0]='0';<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1]='&yen;0';<br />&nbsp;&nbsp;&nbsp; }<br />}<br />&nbsp;</td></tr></tbody></table><br /><br /><br /><br /><br /> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-11-20T00:00:03+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-33.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-33.html</link>
<title>CURSOR_CONTROL(0.0.6) メモ</title>
<description> windows の getch() に相当する、get_key() を用意しようと思った。つまり、いちいちエンターを押さなくても、キーを押した瞬間に読み取ってくれるような関数。windowsとlinuxでは、初期設定の手続きが違うからマクロで書きわけてます。visual c++ だと、コンパイル時に普通は標準だと自動的に #define WIN32 が付加されるので、それを頼りに #ifdef WIN32 （&amp;larr;WIN32 が定義されてたら？という分岐）で処理を分岐させてます。l
 </description>
<content:encoded>
<![CDATA[ windows の getch() に相当する、get_key() を用意しようと思った。<br />つまり、いちいちエンターを押さなくても、キーを押した瞬間に読み取ってくれるような関数。<br /><br />windowsとlinuxでは、初期設定の手続きが違うからマクロで書きわけてます。<br />visual c++ だと、コンパイル時に普通は標準だと自動的に #define WIN32 が付加されるので、それを頼りに #ifdef WIN32 （&larr;WIN32 が定義されてたら？という分岐）で処理を分岐させてます。<br /><br />linuxだと、プログラムの終了時に、設定の復帰処理を行わないといけないので、main() の最後に必ず endCURSOR_CONTROL(void) を書くように。　windowsでコンパイルした場合、単純にこの関数は空になります。<br /><br />初期設定は、得に意識して行う必要はありません。 CURSOR_CONTROL型の変数を初期化する関数　initCURSOR_CONTROL()　を実行すると、（呼び出しがプログラム中の最初の一回目なら）自動的に初期化が行われます。<br />CURSOR_CONTROL 型の変数はいくらでも作れますが、initCURSOR_CONTROL() を実行した際に、初期設定を行うのは、プログラム中全体での最初の１個目の初期化時だけです。<br /><br /><table cellspacing="" cellpadding="" border="0" align="" width="" summary=""><tbody><tr><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td>&nbsp;</td></tr><tr><td style="text-align: center; background-color: rgb(255, 255, 153);">CURSOR_CONTROL型<br /><font size="5" style="color: rgb(255, 153, 0);"><span style="font-weight: bold;">□</span></font></td><td style="text-align: center;">&rarr;<br />初期化</td><td style="text-align: center; background-color: rgb(255, 255, 153);">initCURSOR_CONTROL()で初期化</td><td>&nbsp;</td></tr><tr><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&darr; <br />すでに以前に、<br />他のCURSOR_CONTROL型の<br />初期化を行ったことがある？　</td><td>&nbsp;</td></tr><tr><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&darr;　まだない。初　( flg_init_termios == 0 )</td><td>&nbsp;</td></tr><tr><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center; background-color: rgb(255, 255, 153);">termios の初期設定を行う<br />flg_init_termios　フラグを１に</td><td>&nbsp;</td></tr></tbody></table><br /><br />void setposCURSOR_CONTROL( CURSOR_CONTROL* cc, int pos_x, int ppos_y )<br />void __setposCURSOR_CONTROL(&nbsp; int pos_x, int ppos_y )<br /> <br />どちらもカーソルの位置をセットする関数。<br />この位置に、カーソルが移動する。（文字の描画位置）<br />__が付いた方は、現在位置を cc に保存する必要が無い場合などに使う。<br />通常版（ setposCURSOR() )だと、実行毎に cc に現在位置が保存される。（あと細かな範囲補正と）<br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td style="text-align: center; background-color: rgb(255, 153, 0);">setposCURSOR_CONTROL（）</td><td style="text-align: center; background-color: rgb(255, 153, 0);">__setposCURSOR_CONTROL（）</td></tr><tr><td style="text-align: center; background-color: rgb(255, 255, 153);">指定位置へとカーソルを移動する<br /><br />screenのサイズと比較し、指定位置がscreen範囲を飛び出してる場合は補正する。<br />その後、内部的に __setposCURSOR_CONTROL()を呼び出す。</td><td style="text-align: center; background-color: rgb(255, 255, 153);">指定位置へとカーソルを移動する<br /></td></tr></tbody></table><br /><br /><br /><br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CURSOR_CONTROL.h (0.0.6)</td></tr><tr><td>#ifndef _CURSOR_CONTROL_H_<br />#define _CURSOR_CONTROL_H_<br /><br />#ifdef WIN32<br />#include &lt;windows.h&gt;<br />#else<br />#include &lt;unistd.h&gt;<br />#include &lt;termios.h&gt;<br />#include &lt;sys/time.h&gt;<br />#endif // WIN32<br /><br />#ifdef WIN32<br />#else<br />extern struct termios save_term;<br />extern struct termios temp_term;<br />#endif // WIN32<br />&nbsp;<br />typedef struct tagCOUSOR_CONTROL {<br />&nbsp;&nbsp;&nbsp; int pos_x;&nbsp;&nbsp;&nbsp; // カーソルの現在位置<br />&nbsp;&nbsp;&nbsp; int pos_y;<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; int scr_w;&nbsp;&nbsp;&nbsp; // スクリーンの幅・高さ<br />&nbsp;&nbsp;&nbsp; int scr_h;<br />} CURSOR_CONTROL;<br />&nbsp;<br />extern void initCURSOR_CONTROL( CURSOR_CONTROL* cc );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // CURSOR_CONTROLのシステムの初期化も兼ねる。最初に必ず一回以上実行すること<br />extern void endCURSOR_CONTROL( void );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // CURSOR_CONTROLのシステムの終了処理。mainの最後で必ず一回実効すること。<br />&nbsp;<br />// 単純にカーソル位置を移動するのみ。内部処理的にプリント位置を調整する目的の時はこちら<br />extern void __setposCURSOR_CONTROL( int x, int y );<br />&nbsp;<br />// cc にカーソル位置情報を保存しつつ移動する。通常のカーソル移動はこちら<br />extern void setposCURSOR_CONTROL( CURSOR_CONTROL* cc, int x, int y );<br /><br />// カーソルを１マス移動する（画面の外周外に出た場合は、外周位置に留まる）<br />extern void move_rightCURSOR_CONTROL( CURSOR_CONTROL* cc );<br />extern void move_leftCURSOR_CONTROL( CURSOR_CONTROL* cc );<br />extern void move_upCURSOR_CONTROL( CURSOR_CONTROL* cc );<br />extern void move_downCURSOR_CONTROL( CURSOR_CONTROL* cc );<br /><br />// キー入力を得る<br />extern char get_key(void);<br /><br />// 画面をクリアーする<br />extern void clear_screen(void);<br />&nbsp;<br />#endif // _CURSOR_CONTROL_H_<br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CURSOR_CONTROL.c (0.0.6)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br />#include &quot;SCREEN.h&quot;<br />#include &quot;ETC_MATH.h&quot;<br />#include &quot;CURSOR_CONTROL.h&quot;<br />&nbsp;<br />#ifdef WIN32<br />#include &lt;windows.h&gt;<br />#else<br />#include &lt;unistd.h&gt;<br />#include &lt;termios.h&gt;<br />#include &lt;sys/time.h&gt;<br />#endif // WIN32<br />&nbsp;<br />#ifdef WIN32<br />HANDLE hConsole;<br />static int flg_init_hConsole = 0;<br />#else<br />struct termios save_term;<br />struct termios temp_term;<br />static int flg_init_termios = 0;<br />#endif // WIN32<br /><br />&nbsp;<br />void initCURSOR_CONTROL( CURSOR_CONTROL* cc )<br />{&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; cc-&gt;pos_x = 0;<br />&nbsp;&nbsp;&nbsp; cc-&gt;pos_y = 0;<br />&nbsp;&nbsp;&nbsp; cc-&gt;scr_w = DEF_SCREEN_W;<br />&nbsp;&nbsp;&nbsp; cc-&gt;scr_h = DEF_SCREEN_H;<br /><br />#ifdef WIN32<br />&nbsp;&nbsp;&nbsp; if( flg_init_hConsore == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; hConsole = GetStdHandle( STD_OUTPUT_HANDLE );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; flg_init_hConsore = 1;<br />&nbsp;&nbsp;&nbsp; }<br />#else<br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcgetattr(fileno(stdin), &amp;save_term);<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term = save_term;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_iflag &amp;= IGNCR;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ICANON;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ECHO;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_lflag &amp;= ~ISIG;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VMIN]=1;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; temp_term.c_cc[VTIME]=0;<br />&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;temp_term);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; flg_init_termios = 1;<br />&nbsp;&nbsp;&nbsp; }<br />#endif //WIN32<br />}<br /><br />void endCURSOR_CONTROL(void)<br />{<br />#ifdef WIN32<br />&nbsp;&nbsp;&nbsp; if( flg_init_hConsore == 1 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; flg_init_hConsore = 0;<br />&nbsp;&nbsp;&nbsp; }<br />#else<br />&nbsp;&nbsp;&nbsp; if( flg_init_termios == 1 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tcsetattr(fileno(stdin), TCSANOW, &amp;save_term );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; flg_init_termios = 0;<br />&nbsp;&nbsp;&nbsp; }<br />#endif //WIN32<br />}<br />&nbsp;<br />void setposCURSOR_CONTROL( CURSOR_CONTROL* cc, int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; cc-&gt;pos_x = (x&lt;0)?0:x;<br />&nbsp;&nbsp;&nbsp; cc-&gt;pos_y = (y&lt;0)?0:y;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; if(cc-&gt;pos_x &gt;= cc-&gt;scr_w){cc-&gt;pos_x = cc-&gt;scr_w-1;}<br />&nbsp;&nbsp;&nbsp; if(cc-&gt;pos_y &gt;= cc-&gt;scr_h){cc-&gt;pos_y = cc-&gt;scr_h-1;}<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; __setposCURSOR_CONTROL( cc-&gt;pos_x, cc-&gt;pos_y );<br />}<br /><br />void clear_screen(void)<br />{<br />#ifdef WIN32<br />#else<br />&nbsp; printf(&quot;%c[2J&quot;,0x1B );<br />#endif // WIN32<br />}<br /><br />char get_key(void)<br />{<br />#ifdef WIN32<br />&nbsp;&nbsp;&nbsp; return( (char)getch() );<br />#else<br />&nbsp;&nbsp;&nbsp; return( getchar() );<br />#endif // WIN32<br />}<br /><br /><br /><br /><br /><br />// カーソルを１マス移動する（画面の外周外に出た場合は、外周位置に留まる）<br />void move_rightCURSOR_CONTROL( CURSOR_CONTROL* cc )<br />{<br />&nbsp;&nbsp;&nbsp; cc-&gt;pos_x++;<br />&nbsp;&nbsp;&nbsp; if ( cc-&gt;pos_x &gt;= cc-&gt;scr_w ) cc-&gt;pos_x = cc-&gt;scr_w - 1;<br /><br />&nbsp;&nbsp;&nbsp; setposCURSOR_CONTROL( cc, cc-&gt;pos_x, cc-&gt;pos_y );&nbsp;&nbsp;&nbsp; <br />}<br /><br />void move_leftCURSOR_CONTROL( CURSOR_CONTROL* cc )<br />{<br />&nbsp;&nbsp;&nbsp; cc-&gt;pos_x--;<br />&nbsp;&nbsp;&nbsp; if ( cc-&gt;pos_x &lt; 0 ) cc-&gt;pos_x = 0;<br /><br />&nbsp;&nbsp;&nbsp; setposCURSOR_CONTROL( cc, cc-&gt;pos_x, cc-&gt;pos_y );&nbsp;&nbsp;&nbsp; <br />}<br /><br />void move_upCURSOR_CONTROL( CURSOR_CONTROL* cc )<br />{<br />&nbsp;&nbsp;&nbsp; cc-&gt;pos_y++;<br />&nbsp;&nbsp;&nbsp; if ( cc-&gt;pos_y &gt;= cc-&gt;scr_h ) cc-&gt;pos_y = cc-&gt;scr_h - 1;<br /><br />&nbsp;&nbsp;&nbsp; setposCURSOR_CONTROL( cc, cc-&gt;pos_x, cc-&gt;pos_y );&nbsp;&nbsp;&nbsp; <br />}<br /><br />void move_downCURSOR_CONTROL( CURSOR_CONTROL* cc )<br />{<br />&nbsp;&nbsp;&nbsp; cc-&gt;pos_y--;<br />&nbsp;&nbsp;&nbsp; if ( cc-&gt;pos_y &lt; 0 ) cc-&gt;pos_y = 0;<br /><br />&nbsp;&nbsp;&nbsp; setposCURSOR_CONTROL( cc, cc-&gt;pos_x, cc-&gt;pos_y );&nbsp;&nbsp;&nbsp; <br />}<br /><br /><br /><br /><br /><br />#ifdef WIN32<br />void __setposCURSOR_CONTROL( int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; COORD Pos;<br />&nbsp;&nbsp;&nbsp; Pos.X = x;<br />&nbsp;&nbsp;&nbsp; Pos.Y = y;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; SetConsoleCursorPosition(hConsole, Pos);&nbsp;<br />}<br />#endif // WIN32<br />&nbsp;<br />#ifndef WIN32<br />void __setposCURSOR_CONTROL( int x, int y )<br />{<br />&nbsp;&nbsp;&nbsp; x+=1;<br />&nbsp;&nbsp;&nbsp; y+=1;&nbsp;&nbsp;&nbsp; <br />&nbsp;<br />&nbsp;&nbsp;&nbsp; char str_x[0x0F];<br />&nbsp;&nbsp;&nbsp; char str_y[0x0F];<br />&nbsp;&nbsp;&nbsp; itos( str_x, x );<br />&nbsp;&nbsp;&nbsp; itos( str_y, y );<br />//printf(&quot;str_x=%s, str_y=%s\n&quot;,str_x, str_y );<br />&nbsp;&nbsp;&nbsp; int str_x_len = (int)strlen(str_x);<br />&nbsp;&nbsp;&nbsp; int str_y_len = (int)strlen(str_y);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; char command[0x1F];<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; command[0]=0x1b;<br />&nbsp;&nbsp;&nbsp; command[1]='[';<br />&nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; char* cp;<br />&nbsp;&nbsp;&nbsp; cp = &amp;command[2];<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;str_y_len;i++){ *cp=str_y[i]; cp++; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; command[2 + str_y_len] =';';<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; cp = &amp;command[2+str_y_len+1];<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;str_x_len;i++){ *cp=str_x[i]; cp++; }<br />&nbsp;<br />&nbsp;&nbsp;&nbsp; command[2 + str_y_len + 1 + str_x_len + 0] ='H';<br />&nbsp;&nbsp;&nbsp; command[2 + str_y_len + 1 + str_x_len + 1] ='\0';<br />&nbsp;<br />//&nbsp;&nbsp;&nbsp; puts(command);<br />&nbsp;&nbsp;&nbsp; for(i=0; i&lt;2 + str_y_len + 1 + str_x_len + 2; i++){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; putchar(command[i]);//putchar(' ');<br />&nbsp;&nbsp;&nbsp; }<br />//<br />//&nbsp;&nbsp;&nbsp; printf(&quot;%c[%d;%df&quot;,0x1b,x,y);<br />}<br />#endif // WIN32<br />&nbsp;</td></tr></tbody></table> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-11-20T00:00:02+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-32.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-32.html</link>
<title>CHAR(0.0.6) メモ</title>
<description> CHAR に、putchar に相当する関数を用意しようと思った。int printCHAR( CHAR* ch, CURSOR_CONTROL* cc )引数は CHAR と カーソルのコントローラーこのカーソル位置に、CHAR の文字を出力する。 ASCII の場合は半角、その他の場合は全角。（半角カナは考慮してません。&amp;larr;そのうち追加します。） 戻り値は、画面の表示ブロックの消費量。ASCIIなら１、全角なら２。CHAR.h (0.0.6)#ifndef _CHAR_H_#define _CHAR_H_#include &amp;quo
 </description>
<content:encoded>
<![CDATA[ CHAR に、putchar に相当する関数を用意しようと思った。<br /><br />int printCHAR( CHAR* ch, CURSOR_CONTROL* cc )<br />引数は CHAR と カーソルのコントローラー<br />このカーソル位置に、CHAR の文字を出力する。 <br />ASCII の場合は半角、その他の場合は全角。<br />（半角カナは考慮してません。&larr;そのうち追加します。）<br /> <br />戻り値は、画面の表示ブロックの消費量。ASCIIなら１、全角なら２。<br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CHAR.h (0.0.6)</td></tr><tr><td>#ifndef _CHAR_H_<br />#define _CHAR_H_<br /><br />#include &quot;CURSOR_CONTROL.h&quot;<br /><br />typedef struct tagCHAR {<br />&nbsp;&nbsp;&nbsp; unsigned char c[4];<br />&nbsp;&nbsp;&nbsp; int mode;<br />} CHAR;<br /><br />// char[4] を読み込み UTF-8 に変換して格納する。<br />// リターンは使用してるバイト数。判別不能の時は０を返す。<br />extern int writeCHAR( CHAR* dst, unsigned char* src );<br /><br />// char[4] に UTF-8 の先頭バイトから順に格納する。<br />// ただし、使用されるバイト数は、モードの必要分&rdquo;だけ&rdquo;であり、<br />// それ以降のバイトには一切触れない（値を変えない・アクセスすらしない）<br />// 戻り値には、使用しているバイト数が返される。０の場合はほぼエラーを意味する。<br />extern int readCHAR( CHAR* src, unsigned char* dst );<br /><br />// 指定したカーソル位置に一文字表示する<br />// 戻り値は、文字の表示に使用したブロック数。ASCII（半角文字）の場合は1ブロック、非ASCII（全角文字）の場合は2ブロック<br />// カーソル位置は、表示後も変わらない。（自動では進まない）<br />extern int printCHAR( CHAR* ch, CURSOR_CONTROL* cc );<br /><br />#endif // _CHAR_H_</td></tr></tbody></table><br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>CHAR.c (0.0.6)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &quot;CHAR.h&quot;<br />#include &quot;CURSOR_CONTROL.h&quot;<br /><br />// char[4] を読み込み UTF-8 に変換して格納する。<br />// リターンは使用してるバイト数。判別不能の時は０を返す。<br />int writeCHAR( CHAR* dst, unsigned char* src )<br />{<br />&nbsp;&nbsp;&nbsp; dst-&gt;mode = 0;<br /><br />&nbsp;&nbsp;&nbsp; unsigned char c0 = src[0];<br />&nbsp;&nbsp;&nbsp; unsigned char c1;<br />&nbsp;&nbsp;&nbsp; unsigned char c2;<br />&nbsp;&nbsp;&nbsp; unsigned char c3;<br /><br />&nbsp;&nbsp;&nbsp; // 先頭bitが1ならマルチバイト文字、0ならASCII文字<br />&nbsp;&nbsp;&nbsp; if( ( c0 &amp; 0x80 ) == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[0] = c0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 1;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 第2bitが0なら先頭以外の文字、1なら先頭文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x40 ) == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[0] = c0;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 第3bitが0なら２バイト文字、1なら３バイト以上の文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x20 ) == 0 )&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = src[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 2;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ...かつ、第４bitが0なら３バイト文字、1なら４バイト文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x10 ) == 0 )&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = src[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = src[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 3;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = src[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = src[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = src[3];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 4;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( dst-&gt;mode );<br />}<br /><br />// char[4] に UTF-8 の先頭バイトから順に格納する。<br />// ただし、使用されるバイト数は、モードの必要分&rdquo;だけ&rdquo;であり、<br />// それ以降のバイトには一切触れない（値を変えない・アクセスすらしない）<br />// 戻り値には、使用しているバイト数が返される。０の場合はほぼエラーを意味する。<br />int readCHAR( CHAR* src, unsigned char* dst )<br />{<br />&nbsp;&nbsp;&nbsp; switch(src-&gt;mode){<br />&nbsp;&nbsp;&nbsp; case 1:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(1);<br />&nbsp;&nbsp;&nbsp; case 2:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1] = src-&gt;c[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(2);<br />&nbsp;&nbsp;&nbsp; case 3:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1] = src-&gt;c[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[2] = src-&gt;c[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(3);<br />&nbsp;&nbsp;&nbsp; case 4:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1] = src-&gt;c[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[2] = src-&gt;c[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[3] = src-&gt;c[3];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(4);<br />&nbsp;&nbsp;&nbsp; default:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(0);<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br />// 指定したカーソル位置に一文字表示する<br />// 戻り値は、文字の表示に使用したブロック数。ASCII（半角文字）の場合は1ブロック、非ASCII（全角文字）の場合は2ブロック<br />// カーソル位置は、表示後も変わらない。（自動では進まない）<br />int printCHAR( CHAR* ch, CURSOR_CONTROL* cc )<br />{<br />&nbsp;&nbsp;&nbsp; unsigned char c[4];<br />&nbsp;&nbsp;&nbsp; readCHAR( ch, c );<br />&nbsp;&nbsp;&nbsp; int step;<br />&nbsp;&nbsp;&nbsp; int i;<br /><br /><br />&nbsp;&nbsp;&nbsp; __setposCURSOR_CONTROL( cc-&gt;pos_x, cc-&gt;pos_y);&nbsp;&nbsp;&nbsp; // カーソル位置をセット<br />&nbsp;&nbsp;&nbsp; for( i=0; i &lt; ch-&gt;mode; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; putchar( c[i] );<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; __setposCURSOR_CONTROL( cc-&gt;pos_x, cc-&gt;pos_y );&nbsp;&nbsp;&nbsp; // putchar() の実行で変わったであろうカーソル位置を、元にもどす（自動での移動はさせない）<br /><br /><br />&nbsp;&nbsp;&nbsp; switch(ch-&gt;mode){<br />&nbsp;&nbsp;&nbsp; case 0: step = 0; break;<br />&nbsp;&nbsp;&nbsp; case 1: step = 1; break;&nbsp;&nbsp;&nbsp; // ASCII 半角文字なら<br />&nbsp;&nbsp;&nbsp; case 2: step = 2; break;&nbsp;&nbsp;&nbsp; // 非ASCIIは全て全角文字として扱う。（半角カナなどは考慮しない）<br />&nbsp;&nbsp;&nbsp; case 3: step = 2; break;<br />&nbsp;&nbsp;&nbsp; case 4: step = 2; break;<br />&nbsp;&nbsp;&nbsp; default: step = 0; break;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( step );&nbsp;&nbsp;&nbsp; <br />}<br /></td></tr></tbody></table><br /><br /><br /><br /><br /> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-11-20T00:00:01+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-30.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-30.html</link>
<title>CHAR メモ</title>
<description> 「そもそも char型とは何か？」という、疑問。本来の char の意味を考えたら、char を補完する新たな CHAR 型の必要性を感じた。そしてそれを基本型として組むべきではないのか？と。もともと、C の char型とは、『キャラクタ型』という意味。　つまり、１つで１文字を表せる。そういう変数。変数とは、中に数をメモしとくための箱。　そもそも、なぜ変数で文字を表せるのか？実際のところ、char 自体に文字画像が入ってるワケじゃ
 </description>
<content:encoded>
<![CDATA[ 「そもそも char型とは何か？」<br />という、疑問。<br />本来の char の意味を考えたら、char を補完する新たな CHAR 型の必要性を感じた。そしてそれを基本型として組むべきではないのか？と。<br /><br /><br /><br />もともと、C の char型とは、『キャラクタ型』という意味。　つまり、１つで１文字を表せる。そういう変数。<br /><br />変数とは、中に数をメモしとくための箱。　そもそも、なぜ変数で文字を表せるのか？<br />実際のところ、char 自体に文字画像が入ってるワケじゃなくて、char に記録された数字は、あれは、単なる文字一覧表の中での、文字に対応した番号にすぎない。<br /><br />ASCIIコード対応表<br /><table cellspacing="0" cellpadding="0" border="0" align="" width="288" style="" summary=""><tbody><tr><td width="32" height="32" style="font-weight: bold; background-color: rgb(51, 204, 204); color: rgb(255, 255, 255); text-align: center;">&nbsp;</td><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;"><font size="2">0</font></td><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;"><font size="2">1</font></td><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;"><font size="2">2</font></td><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;"><font size="2">3</font></td><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;"><font size="2">4</font></td><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;"><font size="2">5</font></td><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;"><font size="2">6</font></td><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;"><font size="2">7</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">0</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">NUL</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">DLE</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">SP</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">0</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">@</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">P</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">`</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">p</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">1</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">SOH</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">DC1</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">!</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">1</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">A</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">Q</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">a</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">q</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">2</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">STX</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">DC2</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">&quot;</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">2</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">B</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">R</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">b</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">r</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">3</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">ETX</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">DC3</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">#</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">3</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">C</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">S</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">c</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">s</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">4</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">EOT</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">DC4</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">$</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">4</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">D</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">T</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">d</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">t</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">5</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">ENQ</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">NAK</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">%</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">5</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">E</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">U</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">e</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">u</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">6</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">ACK</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">SYN</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">&amp;</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">6</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">F</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">V</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">f</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">v</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">7</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">BEL</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">ETB</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">'</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">7</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">G</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">W</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">g</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">w</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">8</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">BS</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">CAN</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">(</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">8</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">H</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">X</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">h</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">x</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">9</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">HT</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">EM</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">)</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">9</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">I</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">Y</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">i</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">y</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">10</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">LF</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">SUB</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">*</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">:</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">J</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">Z</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">j</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">z</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">11</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">VT</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">ESC</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">+</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">;</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">K</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">[</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">k</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">{</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">12</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">FF</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">FS</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">,</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">&lt;</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">L</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">\</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">l</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">|</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">13</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">CR</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">GS</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">-</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">=</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">M</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">]</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">m</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">}</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">14</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">SO</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">RS</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">.</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">&gt;</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">N</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">^</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">n</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">~</font></td></tr><tr><td width="32" height="32" style="font-weight: bold; color: rgb(255, 255, 255); background-color: rgb(255, 102, 0); text-align: center;"><font size="2">15</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">SI</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">US</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">/</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">?</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">O</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">_</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">o</font></td><td width="32" height="32" style="font-weight: bold; background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><font size="2">DEL</font></td></tr></tbody></table><br />この表の文字の数は、全部で合計は　16 * 8 で 128個。<br />つまり０～１２7までの数字を表せる入れ物なら、十分。<br /><font size="4" style="color: rgb(0, 128, 128); font-weight: bold;"><table cellspacing="0" cellpadding="0" border="0" align="" width="" summary=""><tbody><tr><td><font size="1">HSB</font></td><td>&nbsp;</td><td><font size="1">LSB</font></td></tr><tr><td>&nbsp;</td><td><font size="5" style="color: rgb(0, 128, 128); font-weight: bold;">□</font><font size="5" style="color: rgb(0, 128, 128); font-weight: bold;">□</font><font size="5" style="color: rgb(0, 128, 128); font-weight: bold;">□</font><font size="5" style="color: rgb(0, 128, 128); font-weight: bold;">□</font><font size="5" style="color: rgb(255, 102, 0); font-weight: bold;">□</font><font size="5" style="color: rgb(255, 102, 0); font-weight: bold;">□</font><font size="5" style="color: rgb(255, 102, 0); font-weight: bold;">□</font><font size="5" style="color: rgb(255, 102, 0); font-weight: bold;">□</font></td><td>&nbsp;</td></tr></tbody></table><br /></font><br />この箱の１つ１つが、それぞれ、０か１かのどちらかを記録できる。<br />この箱１つのことを１ビットと呼ぶ。<br />で、この箱を８個まとめたものが１バイト。<br />１メガバイトってのは、この棒が１００万本使える状態。１ギガバイトってのは１０億本使える状態。<br /><br />この棒の、箱１つ１つは、０か１のどちらかしか記録できない。だから、箱１つに３とか５みたいな数字は記録できない。<br />数字は、この棒に２進数で記録する。<br />１０進数だと、０、１、２、３、、、８、９　と来て、繰り上がって１０になる。　で、１１、１２、１３、、、と続いてく。<br />この１０で繰り上がるってのが、２進数の場合２で繰り上がる。<br />つまり、０、１　と来たら、繰り上がって　１０　となる。　で、１１　で、また繰り上がって　１００で、１０１、<br />また繰り上がって　１１０、で１１１、また繰り上がって　１０００、で１００１、また繰り上がって１０１０、で１０１１、でまた繰り上がって　１１００、で１１０１、でまた繰り上がって１１１０、で１１１１。<br /><br />わかりやすくイメージ描くと、こんな感じ<br /><table cellspacing="0" cellpadding="0" border="0" align="" style="width: 512px; height: 107px;" summary=""><tbody><tr><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">&nbsp;</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">15</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">14</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">13</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">12</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">11</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">10</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">9</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">8</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">7</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">6</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">5</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">4</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">3</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">2</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">1</td><td width="32" height="32" style="color: rgb(255, 255, 255); background-color: rgb(51, 204, 204); text-align: center;">0</td></tr><tr><td width="32" height="32" style="background-color: rgb(51, 204, 204); color: rgb(255, 255, 255); text-align: center;">LSB</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td></tr><tr><td width="32" height="32" style="background-color: rgb(51, 204, 204); color: rgb(255, 255, 255); text-align: center;">&nbsp;</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;"><span style="color: rgb(255, 102, 0);">1</span></td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td></tr><tr><td width="32" height="32" style="background-color: rgb(51, 204, 204); color: rgb(255, 255, 255); text-align: center;">&nbsp;</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td></tr><tr><td width="32" height="32" style="background-color: rgb(51, 204, 204); color: rgb(255, 255, 255); text-align: center;">HSB</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(255, 102, 0); text-align: center;">1</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td><td width="32" height="32" style="background-color: rgb(255, 255, 153); color: rgb(0, 0, 0); text-align: center;">0</td></tr></tbody></table>LSB ってのは、一番下の桁って意味。　たとえば十進数で例えると　１２３４　の ４。　一の位 がLSB。<br />HSBってのは、一番上の桁って意味。　たとえば十進数で例えると　１２３４　の１。　千の位がHSB。<br /><br />上の例だと４つの箱、つまり４ビットによる数です。４ビットだと０～１５までの数字を表せる。<br /><br />この０～１５までを、一の位として扱えるのが１６進数。　これは０～９、そしてA、B、C、D、E、Fと続く。<br />Aは１０という意味、Bは１１という意味、Cは１２という意味、Dは１３という意味、Eは１４、Fは１５。<br />プログラムで書くときは頭に接頭詞で0xって書く。　0x0F と書いたら、これは 00001111 であり、15である。<br /><br />話を char に戻すと、<br />char ってのは要するに ASCII コードの対応表を保存するに十分なサイズ。っていう目的の数で、<br />だから 8bit という大きさに決められたんだと思う。　（8bitは0～２５５までの数字をあらわせる）<br /><br />だから昔は 『char 型　＝　文字を表せる』　の図式が成立してたんだろうけど、それは ASCII コードしか使わない国の人たちだけの話。<br />一方、日本だとひらがな、カタカナ、そして漢字があるからこまる。なにせ漢字は種類が多い。　とてもじゃないが 0 ～ 255の範囲になんて収まらない。<br />日本語を表すための表として shift-jis を用意したものの、char の１バイトでは足りなかったのである。<br />だから、w_char 型なんてのを使ったりしてた。このw_charってのは、ようするにchar[2]と同じで、２バイトのサイズである。<br />２バイトあれば、２の１６乗個まで表せる。つまり大体６４キロ。６万４千くらい。厳密には６５５３６種類。<br />もちろん、LSB側の7bitはASCIIと互換で、同じコード変換表になっているので、その兼ね合いで、実際には64000種類も対応は書けないのだけど、それでも char よりは、全然多くの文字を『指し示せる』<br /><br />最近だと UTF-8というエンコードをよくみかける。<br />これはユニコードというコード体系の一種で、いわく「地球上の全ての言語の文字を表す」っていう理念のもとに作りはじめられた対応表。<br />さすがに、すべての言語っていうと、使用するバイト数も多そうなもんだけど、当初は２バイトでこと足りると思ってたらしい。<br />&hellip;西洋人の感覚だと　「せいぜい２、３万種類くらいじゃね？　地球上の文字って」って感覚だったのだろう&hellip;<br />で、とうぜん「あれ？っていうか足りなくね？」となり、結局一文字を３バイトというルールに変更し、その後、結局４バイトになった。<br />一文字４バイトだと、ASCII文字でこと足りてたラテン文字文化圏の人たちはたまらない。１バイトで記録できるものを、わざわざ４バイト。<br />これではこまるので、UTF-8は、使用するバイト数が可変長になっている。文字の種類によって、使用するバイト数が変わる。<br />これが、妙なとっつきにくさの原因なのだろうけど、実際、その判別方法は全然簡単である。フラグを見てくだけ。<br />UTF-8でも、先頭１バイトの7bit分は、ASCIIコードとまったく同じである。ASCIIは０～１２７の数字を文字の対応表に使用してた。つまりHSBの 1bit が余ってる状態。これをフラグにして判断していくだけ。<br /><br />具体的にはこんな感じ。ぜんぜん簡単である。なにも難しいことなんて無い。<br /><br />＜UTF-8の読み方＞<br /><table cellspacing="0" cellpadding="0" border="0" align="" width="640" summary=""><tbody><tr><td style="background-color: rgb(255, 255, 153);">先頭バイトの<br />HSB側から１ビット目が<br />０なら１バイト文字（ASCII文字）、<br />１ならマルチバイト文字</td><td style="text-align: center;">&rarr;<br />０だった</td><td style="background-color: rgb(255, 255, 153); text-align: center;">１バイト文字<br />（ASCII文字）</td></tr><tr><td><br />&darr;　１だった<br /><br /></td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153);">先頭バイトの<br />HSB側から２ビット目が<br />１なら、先頭以外のバイト<br />０なら、このバイトが、マルチバイト文字の先頭バイト</td><td style="text-align: center;">&rarr;<br />１だった</td><td style="background-color: rgb(255, 255, 153); text-align: center;">なんだか<br />よくわかんねぇ<br />状態</td></tr><tr><td><br />&darr;　０だった<br /><br /></td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153);">先頭バイトの<br />HSB側から３ビット目が<br />０なら、このバイトと、次のバイトによる２バイト文字<br />１なら、３バイト以上の文字<br /></td><td style="text-align: center;">&rarr;<br />０だった</td><td style="background-color: rgb(255, 255, 153); text-align: center;">２バイト文字</td></tr><tr><td><br />&darr;　１だった<br /><br /></td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153);">先頭バイトの<br />HSB側から４ビット目が<br />０なら、このバイトと、次のバイトと、次々のバイトの３バイト文字<br />１なら、このバイトから、次々々バイトまでの４バイト文字</td><td style="text-align: center;">&rarr;<br />０だった</td><td style="background-color: rgb(255, 255, 153); text-align: center;">３バイト文字</td></tr><tr><td><br />&darr;　１だった<br /><br /></td><td style="text-align: center;">&nbsp;</td><td>&nbsp;</td></tr><tr><td style="background-color: rgb(255, 255, 153);"><br /><div style="text-align: center;">４バイト文字<br /><br /></div></td><td style="text-align: center;">&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></tbody></table><br />で、本題のもどると、<br />基本型を char じゃなくて、このUTF-8型に決め打ちした CHAR 型にして作り直した方が良いような気がした。<br />&hellip;ので、CHAR 型を作ることにしました。 <br /><br /><table cellspacing="" cellpadding="" border="1" align="" width="" summary=""><tbody><tr><td>CHAR.h (0.0.5)<br /></td></tr><tr><td>#ifndef _CHAR_H_<br />#define _CHAR_H_<br /><br />typedef struct tagCHAR {<br />&nbsp;&nbsp;&nbsp; unsigned char c[4];<br />&nbsp;&nbsp;&nbsp; int mode;<br />} CHAR;<br /><br />// char[4] を読み込み UTF-8 に変換して格納する。<br />// リターンは使用してるバイト数。判別不能の時は０を返す。<br />extern int writeCHAR( CHAR* dst, unsigned char* src );<br /><br />// char[4] に UTF-8 の先頭バイトから順に格納する。<br />// ただし、使用されるバイト数は、モードの必要分&rdquo;だけ&rdquo;であり、<br />// それ以降のバイトには一切触れない（値を変えない・アクセスすらしない）<br />// 戻り値には、使用しているバイト数が返される。０の場合はほぼエラーを意味する。<br />extern int readCHAR( CHAR* src, unsigned char* dst );<br /><br />#endif // _CHAR_H_<br /></td></tr></tbody></table><br /><table cellspacing="" cellpadding="" border="1" align="" width="" summary=""><tbody><tr><td>CHAR.cpp (0.0.5)<br /></td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &quot;CHAR.h&quot;<br /><br />// char[4] を読み込み UTF-8 に変換して格納する。<br />// リターンは使用してるバイト数。判別不能の時は０を返す。<br />int writeCHAR( CHAR* dst, unsigned char* src )<br />{<br />&nbsp;&nbsp;&nbsp; dst-&gt;mode = 0;<br /><br />&nbsp;&nbsp;&nbsp; unsigned char c0 = src[0];<br />&nbsp;&nbsp;&nbsp; unsigned char c1;<br />&nbsp;&nbsp;&nbsp; unsigned char c2;<br />&nbsp;&nbsp;&nbsp; unsigned char c3;<br /><br />&nbsp;&nbsp;&nbsp; // 先頭bitが1ならマルチバイト文字、0ならASCII文字<br />&nbsp;&nbsp;&nbsp; if( ( c0 &amp; 0x80 ) == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[0] = c0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 1;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 第2bitが0なら先頭以外の文字、1なら先頭文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x40 ) == 0 ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[0] = c0;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 第3bitが0なら２バイト文字、1なら３バイト以上の文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x20 ) == 0 )&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = src[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 2;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ...かつ、第４bitが0なら３バイト文字、1なら４バイト文字<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( ( c0 &amp; 0x10 ) == 0 )&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = src[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = src[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 3;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = 0;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[1] = src[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[2] = src[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c[3] = src[3];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;mode = 4;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; return( dst-&gt;mode );<br />}<br /><br />// char[4] に UTF-8 の先頭バイトから順に格納する。<br />// ただし、使用されるバイト数は、モードの必要分&rdquo;だけ&rdquo;であり、<br />// それ以降のバイトには一切触れない（値を変えない・アクセスすらしない）<br />// 戻り値には、使用しているバイト数が返される。０の場合はほぼエラーを意味する。<br />int readCHAR( CHAR* src, unsigned char* dst )<br />{<br />&nbsp;&nbsp;&nbsp; switch(src-&gt;mode){<br />&nbsp;&nbsp;&nbsp; case 1:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(1);<br />&nbsp;&nbsp;&nbsp; case 2:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1] = src-&gt;c[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(2);<br />&nbsp;&nbsp;&nbsp; case 3:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1] = src-&gt;c[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[2] = src-&gt;c[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(3);<br />&nbsp;&nbsp;&nbsp; case 4:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[0] = src-&gt;c[0];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[1] = src-&gt;c[1];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[2] = src-&gt;c[2];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst[3] = src-&gt;c[3];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(4);<br />&nbsp;&nbsp;&nbsp; default:<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return(0);<br />&nbsp;&nbsp;&nbsp; }<br />}<br /></td></tr></tbody></table> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-11-17T23:25:07+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
<item rdf:about="http://kemeconoajito.blog88.fc2.com/blog-entry-29.html">
<link>http://kemeconoajito.blog88.fc2.com/blog-entry-29.html</link>
<title>STRING メモ</title>
<description> char* 型での文字列操作だと、なんとなく微妙な部分で「どっちだっけか？」ってなったりしてややこしいので、STRING型として操作をまとめてしまおうと思った。STRING は文字列を一行格納するためのもの。STRINGに対しての行える操作は１文字書き込む : write_charSTRING()１文字読み込む : read_charSTRING()１行書き込む : write_strSTRING()１行読み込む : read_strSTRING()のみ。（あと、おまけで ・STRING を書き込む : write_
 </description>
<content:encoded>
<![CDATA[ char* 型での文字列操作だと、なんとなく微妙な部分で「どっちだっけか？」ってなったりしてややこしいので、STRING型として操作をまとめてしまおうと思った。<br /><br />STRING は文字列を一行格納するためのもの。<br />STRINGに対しての行える操作は<br /><ul><li>１文字書き込む : write_charSTRING()</li><li>１文字読み込む : read_charSTRING()</li><li>１行書き込む : write_strSTRING()</li><li>１行読み込む : read_strSTRING()</li></ul>のみ。（あと、おまけで ・STRING を書き込む : write_stringSTRING がある）<br /><br /><br />write_char は STRING の x 文字目に１文字書き込むが、<br />この際の x が STRING長より長かった場合は、以下のような処理になる。<br /><table cellspacing="" cellpadding="" border="0" align="" width="" summary=""><tbody><tr><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;"><font size="5" style="color: rgb(153, 51, 0);">□</font></td></tr><tr><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&darr;</td></tr><tr><td style="text-align: center;"><font size="5">□</font></td><td style="text-align: center;"><font size="5">□</font></td><td style="text-align: center;"><font size="5">□</font></td><td style="text-align: center;"><font size="5">□</font></td><td style="text-align: center;"><font size="5">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(204, 255, 255);">□</font></td></tr><tr><td style="text-align: center;">0</td><td style="text-align: center;">1</td><td style="text-align: center;">2</td><td style="text-align: center;">3</td><td style="text-align: center;">4</td><td style="text-align: center;">...</td><td style="text-align: center;">...</td><td style="text-align: center;">...</td><td style="text-align: center;">...</td><td style="text-align: center;">x</td></tr><tr><td colspan="10">STRING長 = 5</td></tr></tbody></table><br />&darr;<br /><br /><table cellspacing="" cellpadding="" border="0" align="" width="" summary=""><tbody><tr><td style="text-align: center;"><font size="5" style="color: rgb(0, 0, 0);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(0, 0, 0);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(0, 0, 0);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(0, 0, 0);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(0, 0, 0);">□</font></td><td style="color: rgb(0, 255, 0); text-align: center;"><font size="5" style="color: rgb(0, 255, 0);">□</font></td><td style="color: rgb(0, 255, 0); text-align: center;"><font size="5" style="color: rgb(0, 255, 0);">□</font></td><td style="color: rgb(0, 255, 0); text-align: center;"><font size="5" style="color: rgb(0, 255, 0);">□</font></td><td style="color: rgb(0, 255, 0); text-align: center;"><font size="5" style="color: rgb(0, 255, 0);">□</font></td><td style="color: rgb(153, 51, 0); text-align: center;"><font size="5" style="color: rgb(153, 51, 0);">□</font></td></tr><tr><td style="text-align: center;">0</td><td style="text-align: center;">1</td><td style="text-align: center;">2</td><td style="text-align: center;">3</td><td style="text-align: center;">4</td><td style="text-align: center;">...</td><td style="text-align: center;">...</td><td style="text-align: center;">...</td><td style="text-align: center;">...</td><td style="text-align: center;">x</td></tr><tr><td colspan="10">string長 = x + 1</td></tr></tbody></table>*<font size="5" style="color: rgb(0, 255, 0);">□</font>には文字としてスペースが書き込まれる<br /> <br />このように不足分の領域が自動的に再確保され、<br />STRING の最大長が伸ばされる。（メモリの再確保が行われる）<br /> その際、新たに確保した分のスキマはスペース（空白文字）で埋められる。<br /><br />書き込んだ１文字以外の文字列は、全て保持される。（破壊されない）<br /><br /><br /><br />write_string は、単純に char* 型による文字列を STRING にコピーするだけ。<br />その際に、書き込み位置は選べない。書き込み位置は常に先頭０番目から。<br />書き込み文字列は、char* と、その length で表現する。<br />STRING長よりも length が長い場合は、STRING長が伸ばされる（新たにメモリが確保される）<br /><br /><span style="color: rgb(153, 51, 0);">注：STRING.c には、文字列の最後に &yen;0 をとくに書き込むような『気の使い方』は一切していないので、<br />直接読み取りをする場合は、そこを意識して注意するように。<br />具体的には strlen が望みどうりの値を返さないケースが起きたりする。</span><br />（なるべく read_ 系の関数を介して読み取る方がいい。その方が簡単だし安全）<br />&uarr;<br />これは実際、どう組むべきか迷ってます。<br />へたに生データでの &yen;0 を保証しちゃうと、関数を介さないでアクセスするクセがついてしまうのが怖い。<br />&yen;0 が保証されないのであれば、面倒だし、関数を介するだろう&hellip;と。<br />もしも関数を介さずにアクセスした際に、len を無視して文字列を伸ばしたり縮めたりされると、read_、write_ともに、関数の動作に支障がでてくる。<br /><br />とにかく、STRING の生データには直接触らないっていう方針で使ってれば問題無い。　<br />常に関数を介するように。<br />生データに直接書き込みするのは、なるべく避けるように。<br /> <br /><br /><br />read_char は、STRING の任意の位置から1文字読み込む。<br />戻り値として char<br />位置が 0 より小さい（マイナス）場合は０、位置がSTRING長以上の場合は STRING長 - 1 の位置から読み込む。<br /><br /><table cellspacing="" cellpadding="" border="0" align="" width="" summary=""><tbody><tr align="center"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td><font size="5" style="color: rgb(153, 51, 0);">□</font></td></tr><tr align="center"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td style="text-align: center;">&uarr;</td></tr><tr align="center"><td><font size="5">□</font></td><td><font size="5">□</font></td><td><font size="5">□</font></td><td><font size="5">□</font></td><td><font size="5">□</font></td><td><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td><font size="5" style="color: rgb(204, 255, 255);">□</font></td></tr><tr align="center"><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>...</td><td>...</td><td>...</td><td>...</td><td>x</td></tr><tr><td colspan="10">STRING長 = 5</td></tr></tbody></table><br />&darr;<br /><br /><table cellspacing="" cellpadding="" border="0" align="" width="" summary=""><tbody><tr><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;"><font size="5" style="color: rgb(153, 51, 0);">□</font></td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td></tr><tr><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&uarr;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td><td style="text-align: center;">&nbsp;</td></tr><tr><td style="text-align: center;"><font size="5">□</font></td><td style="text-align: center;"><font size="5">□</font></td><td style="text-align: center;"><font size="5">□</font></td><td style="text-align: center;"><font size="5">□</font></td><td style="text-align: center;"><font size="5">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(204, 255, 255);">□</font></td><td style="text-align: center;"><font size="5" style="color: rgb(204, 255, 255);">□</font></td></tr><tr><td style="text-align: center;">0</td><td style="text-align: center;">1</td><td style="text-align: center;">2</td><td style="text-align: center;">3</td><td style="text-align: center;">4</td><td style="text-align: center;">...</td><td style="text-align: center;">...</td><td style="text-align: center;">...</td><td style="text-align: center;">...</td><td style="text-align: center;">x</td></tr><tr><td colspan="10">STRING長 = 5<br /></td></tr></tbody></table><br /><br /><br />read_str は STRING から char* に文字列を読み込みます。<br />読み込みは常に先頭０文字目からです。<br />読み込む文字列長は STRING の len 依存です。<br />つまり、char* には十分なメモリ領域を確保しとく必要があります。<br />（汎用的に使うバッファ変数を用いて読み込むケースがほとんどでしょうから、いっそのこと１メガくらい確保しといても良いかもしれません。最近のPCはメモリが有り余ってますし。）<br /><br />あと、この関数で読み込んだ文字列には、文字列の最後に必ず \0 が付加されます。（\0 保証）<br />つまり、この関数を介してで読み込んだ文字列なら、 strlen() が必ず動作します。（正常に動作します）<br /><br /><span style="color: rgb(153, 51, 0);">注意： char* のメモリが STRING長に満たない場合の動作は不定です。　とにかく char* には十分すぎるメモリを確保しといてください。</span><br /><br />read_str ボツ案１：<br />必要に応じて read_str 関数内部で　malloc して、ポインタをリターンする方法なら、メモリを動的に確保できるので、メモリ領域の問題は解決するのですが、その方法だと、結果的に read_str が一種の malloc として動作するのと同じ意味です。<br />これだと、malloc に関わる free の問題があらわれてしまいます。<br />常にシステムでほとんど最初から最後まで存在し続けることを望まれるメモリならば、とくに開放に神経質になる必要はそれほどありませんが、read_str の場合、おそらく、読み込んだ文字列の用途は一時バッファ的な使い方がほぼ大部分のケースだと予想されます。<br />この手のメモリーってのは、どんどん無駄に溜まるので、使用後の開放が必須ですが、手動の開放作業ってのは、往々にしてを忘れてしまうことが多い。<br />なぜなら、開放してもしなくても、これといってエラーが発生するワケでもないし、コンパイルも当然通る。<br />そこが怖い。（この手のエラーは、ものすごく見付けづらい、直しづらい）<br />だから、read_str を malloc の一種として実装する案はボツにしました。<br /><br />read_str ボツ案2：<br />STRING のプログラムブロックに、大域変数として char* 型の string_buf を用意する。<br />これをヘッダファイルで外部に公開して使えるようにする。<br />read_str は。この string_buf へとリード結果を書き込む。<br />そして、ユーザーは string_buf を読めば、常に、直近に実行した read_str の結果を得ることができる。<br />この方法だと、read_str というユニークなバッファを用意することで、両方の問題を解決できる。<br />現在案の、『メモリーを余分に確保しとかなくてはならない』という問題。<br />また、ボツ案１の、ゴミメモリー領域を、うっかり発生させてしまいかねない、という問題。<br />どちらも解決できる。<br />string_buf は、read_str関数が。完全に把握してコントロールすることができるバッファ。<br />だから動的にメモリーを確保してやれば、読み込みの問題は解決する。　うっかり忘れのゴミメモリ問題も無い。<br />でもこれは、デメリットとして、大域変数の問題があるのでボツにした。<br />つまり、関数内で完結させたい処理であっても、それが不可能である。というコーディング上の不安定要素が入り込んでしまう恐れがあるからボツ。<br />つまり、関数Aで使った結果が、関数Bで読むときにも影響する。　忘れたままBで『期待値』を頼りに string_buf を読むと、まったくおかしな値が入ってた&hellip;というケースが必ず起こりうる。<br />これを防止するためには、read_str 関数と、その結果の string_buf に対して行う作業を、必ずペアにして、それらの処理の間に、さらに再帰的に read_str 関数を使うなどの処理を挟み込まない。<br />この、『read_str と string_buf は、ペアで直後に使用すること』という制約が、意外とキツい。なぜなら再帰、もしくは再帰的なループ系の処理が、のきなみ、ほぼ全てアウトだから。再帰を書くためには、それなりのトリックなり用意が必要になってくる。<br />こういう複雑性を持ち込むのは、本末転倒だと思う。（元々、プログラムを簡単にするために STRING を用意してるのだからw）<br />なので、この大域変数でバッファを用意する案もボツにしました。<br /><br />結局、現在の、『無駄に大きめのバッファを用意して使ってね』　というパラダイムが一番マシな気がしたので、これを採用してます。<br />これが一番、『妙な作法的なもの』を意識せずに使えて、簡単だと思ったからです。<br />&hellip;もっと良い方法があれば、それに書き換えるつもりですが、ボツ案１が本当は理想なんですが、これを安全に実装するには、やはりガベージコレクションが保証されてる言語じゃないと不安です&hellip;<br />（Cでボツ案１を組むと、いわば手動ガベージコレクションを人間に要求することと同じ意味。　でも、人間は間違えるし、うっかり忘れもする。）<br /><br /><br /><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>STRING.h (0.0.5)</td></tr><tr><td>#ifndef _STRING_H_<br />#define _STRING_H_<br /><br />typedef struct tagSTRING {<br />&nbsp;&nbsp;&nbsp; char*&nbsp;&nbsp;&nbsp; c;<br />&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; len;<br />} STRING;<br /><br />#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br />#include &quot;STRING.h&quot;<br /><br />// 初期化<br />// インスタンスの作成直後に必ず最初にこの関数を通して初期化する必要がある。<br />extern void initSTRING( STRING* str );<br /><br />// char 型の文字列を len 文字分、STRINGに書き込む。この際、古いデータは破壊され、上書きによって置き換わる。（つまり感覚としては char -&gt; STRINGへのコピーに近い）<br />// STRING のメモリーが足りない場合は自動的に確保される<br />extern void write_strSTRING( STRING* dst, char* src, int len );<br /><br />// char １文字を dst の index 番目に書き込む。<br />// STRING のメモリーが足りない場合は自動的に確保される。確保された分はスペースで初期化される。<br />extern void write_charSTRING( STRING* dst, int index, char c );<br /><br />// src の文字列を dst に書き込む。<br />// STRING のメモリーが足りない場合は自動的に確保される<br />extern void write_stringSTRING( STRING* dst, STRING* src );<br /><br />// char 1文字を src の index 番めから読み込む。<br />// index が 0 以下の場合は 0 として読み込まれる。 index が STRING長 - 1 以上の場合、STRING長 - 1 として読み込まれる<br />extern char read_charSTRING( STRING* src, int index );<br /><br />// char 型の文字列 dst へ、STRING型 src から全文字を読み込む。　読み込んだ文字列の最後には必ず '&yen;0' が付加される。<br />//<br />// 注意：dst は十分すぎるほど十分な長さを確保しておくように。<br />//（Cにはガベージコレクションが無いので、使いやすくするために、あえて固定長配列の dst を引数にしてます。<br />//&nbsp; 開放忘れによるメモリの行方不明を防ぐため、char* を返す関数として内部で malloc するような作りにはあえてしてません。<br />// だからdstは十分な長さを確保して渡してください。<br />// 0xFFFFFF （１６メガw）くらいあれば、まぁ、絶対大丈夫だと思います。（一行の長さが１６００万文字のテキストファイルなんて、めったに存在しませんもんね...super_piの出力くらい？）<br />// 0xFFFF （６４キロ）くらいでも、実用、十分かと思いますが。（一行の長さが６万４千文字のテキストファイル&hellip;　まぁこれでも十分ですよね&hellip;　普通、一行は１００文字程度でしょうし。）<br />extern void read_strSTRING( STRING* src, char* dst );<br /><br />#endif // _STRING_H_<br /></td></tr></tbody></table><br /><table cellspacing="1" cellpadding="1" border="1" align="" width="" summary=""><tbody><tr><td>STRING.cpp (0.0.5)</td></tr><tr><td>#include &lt;stdio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &lt;string.h&gt;<br />#include &quot;STRING.h&quot;<br /><br />// 初期化<br />// インスタンスの作成直後に必ず最初にこの関数を通して初期化する必要がある。<br />void initSTRING( STRING* str )<br />{<br />&nbsp;&nbsp;&nbsp; str-&gt;c = (char*)malloc(sizeof(char));<br />&nbsp;&nbsp;&nbsp; str-&gt;len = 0;<br />}<br /><br />// char 型の文字列を len 文字分、STRINGに書き込む。この際、古いデータは破壊され、上書きによって置き換わる。（つまり感覚としては char -&gt; STRINGへのコピーに近い）<br />// STRING のメモリーが足りない場合は自動的に確保される<br />void write_strSTRING( STRING* dst, char* src, int len )<br />{<br />&nbsp;&nbsp;&nbsp; if( len &lt;= 0 ) { len = 0; }&nbsp;&nbsp;&nbsp; // len の範囲丸め<br /><br />&nbsp;&nbsp;&nbsp; // メモリが足りなかったら確保する<br />&nbsp;&nbsp;&nbsp; if( dst-&gt;len &lt; len ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;len = len;<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; free( (void*)(dst-&gt;c) );<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c = (char*)malloc( sizeof(char) * dst-&gt;len );<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; char* d = dst-&gt;c;<br />&nbsp;&nbsp;&nbsp; char* s = src;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;len;i++){ *d++ = *s++; }<br />&nbsp;&nbsp;&nbsp; dst-&gt;len = len;<br />}<br /><br />// char １文字を dst の index 番目に書き込む。<br />// STRING のメモリーが足りない場合は自動的に確保される。確保された分はスペースで初期化される。<br />void write_charSTRING( STRING* dst, int index, char c )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt;= 0 ) { index = 0; }&nbsp;&nbsp;&nbsp; // index の範囲丸め<br /><br />&nbsp;&nbsp;&nbsp; // メモリが足りなかったら確保する<br />&nbsp;&nbsp;&nbsp; // index の場合は、たとえば len が１０の配列では、実際に使用できるindexの最大値は９までなので、( dst-&gt;len - 1 ) と比較している<br />&nbsp;&nbsp;&nbsp; if( dst-&gt;len - 1 &lt; index ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int old_len = dst-&gt;len;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;len = index + 1;&nbsp;&nbsp;&nbsp; // len を index の値とした配列だと、index - 1 番目までしか書き込めないので、それだと１足りないので ( index + 1 ) としている。<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst-&gt;c = (char*)realloc( dst-&gt;c, sizeof(char) * dst-&gt;len );<br /><br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char* d = dst-&gt;c;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(i=old_len; i&lt;dst-&gt;len; i++ ) {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *d++ = ' ';&nbsp;&nbsp;&nbsp; // 新規確保したメモリーはスペースで初期化する<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; dst-&gt;c[index] = c;&nbsp;&nbsp;&nbsp; <br />}<br /><br />// src の文字列を dst に書き込む。<br />// STRING のメモリーが足りない場合は自動的に確保される<br />void write_stringSTRING( STRING* dst, STRING* src )<br />{<br />&nbsp;&nbsp;&nbsp; write_strSTRING( dst, src-&gt;c, src-&gt;len );<br />}<br /><br />// char 1文字を src の index 番めから読み込む。<br />// index が 0 以下の場合は 0 として読み込まれる。 index が STRING長 - 1 以上の場合、STRING長 - 1 として読み込まれる<br />char read_charSTRING( STRING* src, int index )<br />{<br />&nbsp;&nbsp;&nbsp; if( index &lt;= 0 ) { index = 0; }&nbsp;&nbsp;&nbsp; else if( index &gt;= src-&gt;len - 1 ) { index = src-&gt;len - 1; }&nbsp;&nbsp;&nbsp; // index の範囲丸め<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; return( src-&gt;c[index] );<br />}<br /><br />// char 型の文字列 dst へ、STRING型 src から全文字を読み込む。　読み込んだ文字列の最後には必ず '&yen;0' が付加される。<br />//<br />// 注意：dst は十分すぎるほど十分な長さを確保しておくように。<br />//（Cにはガベージコレクションが無いので、使いやすくするために、あえて固定長配列の dst を引数にしてます。<br />//&nbsp; 開放忘れによるメモリの行方不明を防ぐため、char* を返す関数として内部で malloc するような作りにはあえてしてません。<br />// だからdstは十分な長さを確保して渡してください。<br />// 0xFFFFFF （１６メガw）くらいあれば、まぁ、絶対大丈夫だと思います。（一行の長さが１６００万文字のテキストファイルなんて、めったに存在しませんもんね...super_piの出力くらい？）<br />// 0xFFFF （６４キロ）くらいでも、実用、十分かと思いますが。（一行の長さが６万４千文字のテキストファイル&hellip;　まぁこれでも十分ですよね&hellip;　普通、一行は１００文字程度でしょうし。）<br />void read_strSTRING( STRING* src, char* dst )<br />{<br />&nbsp;&nbsp;&nbsp; char* d = dst;<br />&nbsp;&nbsp;&nbsp; char* s = src-&gt;c;<br />&nbsp;&nbsp;&nbsp; int len = src-&gt;len;<br /><br />&nbsp;&nbsp;&nbsp; int i;<br />&nbsp;&nbsp;&nbsp; for(i=0;i&lt;len;i++){ *d++ = *s++; }<br /><br />&nbsp;&nbsp;&nbsp; switch( dst[len-1] ) {<br />&nbsp;&nbsp;&nbsp; case '\0':break;<br />&nbsp;&nbsp;&nbsp; default: dst[len] = '\0';<br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br /></td></tr></tbody></table><br /><br /><br /><br /><br /><br /> ]]>
</content:encoded>
<dc:subject>プラグイン</dc:subject>
<dc:date>2009-11-16T23:06:03+09:00</dc:date>
<dc:creator>竹内ケメ子</dc:creator>
<dc:publisher>FC2-BLOG</dc:publisher>
</item>
</rdf:RDF>