[futurebasic] RE: [FB] Benchmark Challenge #3 - WFC

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2000 : Group Archive : Group : All Groups

From: Ken Shmidheiser <k.shmidheiser@...>
Date: Thu, 14 Sep 2000 09:53:29 -0400
Dear List Members,

Feeling guilty for having started this FB^3/RB challenge with my post 
the other day, as penance this morning before heading to work I put 
together this engine which I hope follows Bill's parameters for the 
challenge.

In its current state, the program should handle: menus, windows 
(including using the file name as the window name in the input 
window); opening the text file either with the menu command, or by 
drag and drop onto the icon; scrollable static edit fields; the 
necessary processing timing called for in the challenge... and of 
course the spinning beachball cursor.

Very little error testing here. The code undoubtedly can be 
optimized. And the difficult part-- the text parsing algorithm-- 
remains to be completed by the real brains of this list. But this 
shell may free you for the more difficult work. In its current form 
it is a standalone app and basic TEXT reader.

Speaking of work, I have to go.

Happy coding,

Ken Shmidheiser

p.s. Hey, Geoff, remember this code was completed within a couple 
hours of Bill's initial post. I will answer your e-mail ASAP.

Please be sure to adjust for e-mail line breaks.

Ken Shmidheiser

'------- Begin FB^3 Code -------
/*
FB^3 vs. RB compiler challenge engine.
(This version in FB^3, of course!)

Ken Shmidheiser
Somerset, KY
9-14-00

*/

'RESOURCES "challenge.rsrc"

BEGIN GLOBALS
DIM gTimer$
DIM gInputWindowName$
DIM gCycleCursor
END GLOBALS

LOCAL FN initializeMenus
APPLE MENU "(The Great FB^3 versus RB Challenge."
MENU 1,0,_enable,"File"
MENU 1,1,_enable,"Open/O"
MENU 1,2,_enable,"Close/W"
MENU 1,3,_disable,"-"
MENU 1,4,_enable,"Save Results/S"
MENU 1,5,_disable,"-"
MENU 1,6,_enable,"Count"
MENU 1,7,_disable,"-"
MENU 1,8,_enable,"Quit/Q"
END FN

LOCAL FN inputWindow
WINDOW -1,gInputWindowName$,(0,0)-(500,400),_docNoGrow
EDIT FIELD -1, "Use ""Open"" Menu to retrieve the test text file.", 
(10, 10)-(474,390), _framed,_leftJust
SCROLL BUTTON -1, 1, , , ,(474, 9)-(490,391) , _scrollOther
WINDOW 1
EDIT FIELD 0
END FN

LOCAL FN outputWindow
WINDOW -2,"Output results",(0,0)-(500,400),_docNoGrow
EDIT FIELD -2, "", (10, 10)-(474,390), _framed,_leftJust
SCROLL BUTTON -2, 1, , , ,(474, 9)-(490,391) , _scrollOther
WINDOW 2
EDIT FIELD 0
END FN

LOCAL FN openFile (EditID%)
DIM TextEditH as handle
DIM TextH as handle
DIM FileName$,Size&,OSErr%
DIM @vRefNum%
FileName$ = FILES$ (_fOpen, "TEXT", , vRefNum%)
LONG IF FileName$ <> ""
TextEditH = TEHANDLE(EditID%)
OPEN "I", #1, FileName$, , vRefNum%
gInputWindowName$ = FileName$
WINDOW 1, gInputWindowName$
SCROLL BUTTON -1
LONG IF (SYSERROR = _noErr)
Size& = LOF (1,1)
LONG IF Size& < 32000
TextH = FN NEWHANDLE (Size&)
LONG IF TextH
CALL HLOCK(TextH)
READ FILE #1, [TextH], Size&
CALL TESETTEXT ([TextH], Size&, TextEditH)
CALL INVALRECT (#[TextEditH]+_teViewRect)
CALL HUNLOCK (TextH)
CALL disposehandle (TextH)
XELSE
BEEP : BEEP
END IF
XELSE
BEEP : BEEP
END IF
CLOSE #1
XELSE
BEEP : BEEP
END IF
END IF
EDIT FIELD 1,,,_statFramed
SCROLL BUTTON 1
END FN

LOCAL FN caputureFile (fileName as str31, vRefNum, fType as LONG)
PRINT fileName, vRefNum
LONG IF (fType == _"TEXT")
LONG IF fileName <> ""
cTextEditH = TEHANDLE(1)
OPEN "I", #1, fileName, , vRefNum%
gInputWindowName$ = fileName
WINDOW 1, gInputWindowName$
SCROLL BUTTON -1
LONG IF (SYSERROR = _noErr)
Size& = LOF (1,1)
LONG IF Size& < 32000
cTextH = FN NEWHANDLE (Size&)
LONG IF cTextH
CALL HLOCK(cTextH)
READ FILE #1, [cTextH], Size&
CALL TESETTEXT ([cTextH], Size&, cTextEditH)
CALL INVALRECT (#[cTextEditH]+_teViewRect)
CALL HUNLOCK (cTextH)
CALL disposehandle (cTextH)
XELSE
BEEP:BEEP
END IF
XELSE
BEEP:BEEP
END IF
CLOSE #1
XELSE
BEEP:BEEP
END IF
END IF
XELSE
BEEP
END IF
EDIT FIELD 1,,,_statFramed
SCROLL BUTTON 1
END FN

LOCAL FN dragNdrop
DIM @ count,fileName as str31,fType as LONG,vRefNum,j
DIM action
count = 0
action = FINDERINFO (count, fileName, fType, vRefNum)
LONG IF ( count > 0 )
FOR j = -1 TO -count STEP -1
action = FINDERINFO (j, fileName, fType, vRefNum)
LONG IF ( action == _finderInfoOpen )
FN caputureFile (fileName, vRefNum, fType)
END IF
NEXT
FN ClearFinderInfo
END IF
END FN = count

LOCAL FN saveFile
'Save file to disk here
END FN

LOCAL MODE
DIM @ chdl&,currentCursor%
LOCAL FN AnimatedWatch (WhichCursor)
currentCursor% = WhichCursor
chdl& = FN GETCCURSOR(currentCursor%)
LONG IF chdl& > 0
CALL SETCCURSOR(chdl&)
END IF
DEF CYCLE (1001,1004,currentCursor%)
'DEF CYCLE (130,133,currentCursor%)
END FN = currentCursor%

LOCAL FN sortFileData
FN outputWindow
StartTime& = FN TICKCOUNT
'DO
'gCycleCursor = FN AnimatedWatch(gCycleCursor)
'Start your beach ball spinning
'Count and sort algorithm here
'Output results to WINDOW 2
'UNTIL
EndTime& = FN TICKCOUNT
timeResults% = EndTime&-StartTime&
gTimer$ = "Processing time was: " + STR$(timeResults%) + " ticks"
resultsFollow$ = "Here are the completed results: "
EDIT$(2,0,0) = gTimer$ + CHR$(13) + CHR$(13) + resultsFollow$
END FN

LOCAL FN doDialog
DIM evnt%
DIM id%
evnt% = DIALOG(0)
id% = DIALOG(evnt%)
SELECT CASE evnt%
CASE _wndClose
SELECT id%
CASE 1
END
CASE 2
WINDOW CLOSE 2
END SELECT
CASE _btnClick
SELECT id%
CASE 1
END SELECT
CASE _wndRefresh
SELECT id%
CASE 1
WINDOW 1
CASE 2
WINDOW 2
END SELECT
END SELECT
END FN

LOCAL FN doMenu
DIM menuID%
DIM itemID%
menuID% = MENU(_menuID)
itemID% = MENU(_itemID)
SELECT CASE menuID%
CASE 1                      'File menu
SELECT itemID%
CASE 1                      'Open
FN openFile(1)
CASE 2                      'Close
WINDOW CLOSE 1
CASE 4                      'Save results
FN saveFile
CASE 6                      'Count
FN sortFileData
CASE 8                      'Quit
END
END SELECT
END SELECT
MENU
END FN

ON DIALOG FN doDialog
ON MENU FN doMenu

FN initializeMenus
FN inputWindow

DO
HANDLEEVENTS
FN dragNdrop
UNTIL 0
END


'---- end code -------

Following is the beachball cursor resource:

(This file must be converted with BinHex 4.0)
:$Q0SB@aXC@jRC5jbFh*M!(*cFQ058d9%"3#3"`UqIa%!N!3"!*!$#MJ!!!Ni!*!
$KJ#3)!aMGA*cEh*c,R*cFQ0bC@jMCA-b)-4cD@pZBA*j)'&M!!"bFh*M8P0&4!8
!!'`!Q!#3#S!!N!HdF'6-!*!'#Vi!N()"!!Fi-6!`)%K%!*!)!AU!!3#3!f!!N!1
5!*!03!$!!)!'B!r`(q!I`"r!(q!Im!r`$r!(i!*!!!!(`"r`2rKrr(rmrrlrr[r
qrrlrrRrmIr`rq"r`"m!!N!-(!!F!N!b!#!#3"4!!%!#3#8J!N!0)!*!&"!!"!!3
!N!B"%J#3"Jrrr`#3"!ra%L,r!*!$qC%L-c2`!!m"%M13!fm!$`8cN!-`E`$`"@-
c-fCRm2"@CM-fCRI`m&CQBfCQGr$e9QBc0QCim29@Bc-cChM`$eBcN!-hM`!28c1
3!d12!!$c-c4%5[!!!!rd4+Vr!*!%$rrr!*!5#`!!rj!'!!'lZ`#3"3+)L!#3"30
hG`#3"34993#3"3AZN!B!"Yf3"J!(Zj!'!!LUN!B!#HlZ!*!&#L)L!*!&$`#3#!'
+J!%!N!0J!*!$NJ#3$8!!`!#!!8!$i!I!"m!(`!I!"q!$i!2J!F!"3!!!"m!Im$r
iIrarr2rqrrlrr[rqrrjrr(rm2rJIm!I!!*!$"`!(!*!-J!J!N!83!"!!N!P)!*!
$5!#3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