【以前のものです】
 解凍するといくつかフォルダができますが、tex2hex の中のものです。この演習問題はよくできていて、わざとプログラムに誤りが用意されています。生徒である私たちにデバックというものを演習させようとの配慮ですが、全くのしろうとにはこれさえも苦痛だったりします。実はバグのないものが Clean フォルダに用意されています。

 GCCのインストールの確認も含めて、まずは動くファイルでコンパイルしてみましょう。

 まずは、MD-DOSプロンプトを立ち上げてください。黒い画面のやつです。GCCでインストールしたチュートリアルのディレクトリに移動します。

  C:\WINDOWS> bash 

(GCCのインストールで bash が動くはずです。bashというはシェルの一種で、もともとUNIXでOS(カーネル)とのやり取りを仲介してくれる仕組みのことです)
     bash$ cd /GNU_Pilot_SDK_Tutorial/tutorial/Clean  (C:\ 直下で解凍した場合です)

 * を使って省略もできます。
     bash$ cd /GNU*/tu*/Cl*

   bash$ make

  結果として、4KB程度の tex2hex.prc ファイルが作成されれば、うまく動作していることになります。
 では早速、palm君にインストールして動作させてみます。どうでしょう動いたでしょうか?

 ここまで、できると開発環境は整ったことになります。これから心おきなくプログラミングできるというものです。

 それでは、バグを含んでる方のプログラムで make を実行してみてください。tutorial フォルダのものです

 どばー、っとエラーメッセージが出たと思います。この中には警告(warning)レベルのものも含まれていて、これらは修正しなくても動作する場合がありますが、きちんと直すくせを付けるようにした方がいいでしょう。

 ここでは、ドキュメントに従って4つのバグを修正していきます。

#pragma pack(2)
#include <Common.h>
#include <System/SysAll.h>
#include <UI/UIAll.h>

#include "tex2hex.h"
#define Tex2HexAppID    'TxHx'   // 0x74586858 in hexadecimal
#define Tex2HexDBType   'Data'   // 0x64415441 in hexadecimal

static int StartApplication(void);
static Boolean OpenDatabase(void);
static void EventLoop(void);
static void EventLoop(void);
static void StopApplication(void);
static Boolean tex2hex(EventPtr event);
static void Convert(void);
static void ChangeBitmap(void)   <= セミコロン ; が抜けてます

FieldPtr fieldptr_text;   // FieldPtr and DmOpenRef are defined in the PalmOS header files.
FieldPtr fieldptr_hex;    // See if you can find where they are defined.
DmOpenRef Tex2HexDB;
char            Tex2HexDBName[] = "Tex2HexDB";
char            hex[60];
int             WhichBitmap;
 

 これだけで、make の際のエラーががぐんと減ります。

bash$ make
m68k-palmos-coff-gcc -O1 -c tex2hex.c -o tex2hex.o
tex2hex.c: In function `EventLoop':
tex2hex.c:114: parse error before `}'
tex2hex.c: In function `ChangeBitmap':
tex2hex.c:217: warning: passing arg 1 of `WinDrawBitmap' from incompatible point
er type
make: *** [code0001.tex2hex.grc] Error 1

114行目あたりの以下の部分を修正します。
static void EventLoop(void)
{
  short err;
  int formID;
  FormPtr form;
  EventType event;

  do
  {

    EvtGetEvent(&event, 200);

    if (SysHandleEvent(&event)) continue;
    if (MenuHandleEvent((void *)0, &event, &err)) continue;

    if (event.eType == frmLoadEvent)
    {
      formID = event.data.frmLoad.formID;
      form = FrmInitForm(formID);
      FrmSetActiveForm(form);
      switch (formID)
      {
      case formID_tex2hex:
        FrmSetEventHandler(form, (FormEventHandlerPtr) tex2hex);
        break;
      }
    } while(event.eType != appStopEvent);   <= ここを消して
    FrmDispatchEvent(&event);
  } while(event.eType != appStopEvent);   <= ここに移動します
}
 

 また、make してみます。

ash$ make
m68k-palmos-coff-gcc -O1 -c tex2hex.c -o tex2hex.o
tex2hex.c: In function `ChangeBitmap':
tex2hex.c:217: warning: passing arg 1 of `WinDrawBitmap' from incompatible point
er type
m68k-palmos-coff-gcc -O1 tex2hex.o -o tex2hex
m68k-palmos-coff-obj-res tex2hex

pilrc v2.3a.  by Wes Cherry (wesc@ricochet.net)
        bitmap compression (pl2) by Hoshi Takanori (hoshi@sra.co.jp)

tex2hex.rcp(13) : warning : Duplicate form object id (error is on the previous l
ine)
Writing .\tFRM03e8.bin
240 bytes
Writing .\tver0001.bin
4 bytes
Writing .\tAIB03e8.bin
144 bytes
Writing .\Tbmp03e8.bin
656 bytes
Writing .\Tbmp03e9.bin
656 bytes
Writing .\MBAR03e8.bin
171 bytes
Writing .\Talt03e8.bin
62 bytes
Writing .\Talt03e9.bin
48 bytes
build-prc  tex2hex.prc "Text to Hex" TxHx *.grc *.bin
ls -l *.prc
-rw-r--r--   1 500      everyone     5530 Jun 29 01:02 tex2hex.prc
 

 エラーがなくなり、実行型ができてしまいました。今度はワーニングをなくします。

static void ChangeBitmap(void)
{
  VoidHand   bitmaphandle;
  BitmapPtr  bitmap;     <= 追加します

  WhichBitmap = (WhichBitmap + 1) % 2;
  if (WhichBitmap == 0) bitmaphandle = DmGet1Resource('Tbmp', bitmapID_text);
  else bitmaphandle = DmGet1Resource('Tbmp', bitmapID_hex);
  bitmap = MemHandleLock(bitmaphandle);  <= 追加します
  WinDrawBitmap(bitmaphandle, 20, 120);   <= bitmaphandle を bitmap に修正します
}

bash$ make
m68k-palmos-coff-gcc -O1 -c tex2hex.c -o tex2hex.o
m68k-palmos-coff-gcc -O1 tex2hex.o -o tex2hex
m68k-palmos-coff-obj-res tex2hex
build-prc  tex2hex.prc "Text to Hex" TxHx *.grc *.bin
ls -l *.prc
-rw-r--r--   1 500      everyone     5546 Jun 29 01:13 tex2hex.prc
 

 ワーニングが消えました。この実行型は、動くことは動くのですが、他のプログラムに移った後、再度実行すると異常終了してしまいます。

 以下の部分を修正します。

static void StopApplication(void)
{
  FldSetTextHandle(fieldptr_text, NULL);
  DmReleaseRecord(Tex2HexDB, 0, false);  <= この行を加えます
  DmCloseDatabase(Tex2HexDB);
}

 これで、make したものが完全版です。