#!/usr/bin/perl -w # pilot-template 1.31 : Create the template files for a PalmOS application # Copyright (C) 1998 Ian Goldberg # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA use strict 'vars'; print <<'EOC'; pilot-template 1.31 by Ian Goldberg EOC my $Usage = <= 0 && $ARGV[0] eq '-pbitm') { $iconext = 'pbitm'; shift @ARGV; } die $Usage unless $#ARGV == 3; my ($prcname, $appname, $iconname, $crid) = @ARGV; die $Usage unless length($crid) == 4 && length($appname) < 32; ## Strip the .prc, if any, from the prcname $prcname =~ s/\.prc$//; ## Make sure none of the files already exists my $f; foreach $f ("Makefile", $prcname.".c", $prcname.".".${iconext}, $prcname.".rcp", $prcname."Rsc.h", "callback.h") { die "File $f already exists - aborting.\n" if -e $f; } ## Create the files open(F, ">Makefile") or die "Cannot write Makefile: $!\n"; print F <${prcname}.c") or die "Cannot write ${prcname}.c: $!\n"; print F < #include "callback.h" #include "${prcname}Rsc.h" static Boolean MainFormHandleEvent (EventPtr e) { Boolean handled = false; FormPtr frm; CALLBACK_PROLOGUE switch (e->eType) { case frmOpenEvent: frm = FrmGetActiveForm(); FrmDrawForm(frm); handled = true; break; case menuEvent: MenuEraseStatus(NULL); switch(e->data.menu.itemID) { } handled = true; break; case ctlSelectEvent: switch(e->data.ctlSelect.controlID) { } break; default: break; } CALLBACK_EPILOGUE return handled; } static Boolean ApplicationHandleEvent(EventPtr e) { FormPtr frm; Word formId; Boolean handled = false; if (e->eType == frmLoadEvent) { formId = e->data.frmLoad.formID; frm = FrmInitForm(formId); FrmSetActiveForm(frm); switch(formId) { case MainForm: FrmSetEventHandler(frm, MainFormHandleEvent); break; } handled = true; } return handled; } /* Get preferences, open (or create) app database */ static Word StartApplication(void) { FrmGotoForm(MainForm); return 0; } /* Save preferences, close forms, close app database */ static void StopApplication(void) { FrmSaveAllForms(); FrmCloseAllForms(); } /* The main event loop */ static void EventLoop(void) { Word err; EventType e; do { EvtGetEvent(&e, evtWaitForever); if (! SysHandleEvent (&e)) if (! MenuHandleEvent (NULL, &e, &err)) if (! ApplicationHandleEvent (&e)) FrmDispatchEvent (&e); } while (e.eType != appStopEvent); } /* Main entry point; it is unlikely you will need to change this except to handle other launch command codes */ DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags) { Word err; if (cmd == sysAppLaunchCmdNormalLaunch) { err = StartApplication(); if (err) return err; EventLoop(); StopApplication(); } else { return sysErrParamErr; } return 0; } EOFILE close(F); open(F, ">${prcname}Rsc.h") or die "Cannot write ${prcname}Rsc.h: $!\n"; print F "#define MainForm 1000\n"; close(F); open(F, ">${prcname}.rcp") or die "Cannot write ${prcname}.rcp: $!\n"; print F <${prcname}.${iconext}") or die "Cannot write ${prcname}.${iconext}: $!\n"; if ($iconext eq 'pbitm') { print F <callback.h") or die "Cannot write callback.h: $!\n"; print F <<'EOFILE'; #ifndef __CALLBACK_H__ #define __CALLBACK_H__ /* This is a workaround for a bug in the current version of gcc: gcc assumes that no one will touch %a4 after it is set up in crt0.o. This isn't true if a function is called as a callback by something that wasn't compiled by gcc (like FrmCloseAllForms()). It may also not be true if it is used as a callback by something in a different shared library. We really want a function attribute "callback" which will insert this progloue and epilogoue automatically. - Ian */ register void *reg_a4 asm("%a4"); #define CALLBACK_PROLOGUE \ void *save_a4 = reg_a4; asm("move.l %%a5,%%a4; sub.l #edata,%%a4" : :); #define CALLBACK_EPILOGUE reg_a4 = save_a4; #endif EOFILE close(F); print "Done.\n";