0010 REM NewtWap - Apple MP WAP Client Copyright (c) 2000 Eric M. Schneck, Inc 0020 LET appSpec={goto:'endProgram,title:""} 0030 window app,appSpec,"APP" 0040 show app 0050 widgetdef Layout_0:={lbURL:{widgetType:"labelInput",order:0,B currLabelCommand:0,entryFlags:14849,labelFont:{family:'espyB ,face:1,size:9},indent:40,labelCommands:[],viewBounds:{top:B 16,bottom:57,left:3,right:242},label:"URL",text:""},btnBackB :{widgetType:"textButton",order:1,gosub:'goBack,viewBounds:B {left:7,top:58,right:34,bottom:73},viewFlags:514,text:"<",vB iewFont:{family:'espy,face:1,size:14},viewFormat:67109456},B btnGo:{widgetType:"textButton",order:2,gosub:'go,viewBoundsB :{left:40,top:58,right:80,bottom:73},viewFlags:514,text:"GoB ",viewFont:{family:'espy,face:1,size:12},viewFormat:6710945B 6},Widget_9:{widgetType:"textButton",order:3,gosub:'stopLoaB ding,viewBounds:{left:85,top:58,right:125,bottom:73},viewFlB ags:514,text:"Stop",viewFont:{family:'espy,face:1,size:12},B viewFormat:67109456},txtCardTitle:{widgetType:"title",orderB :4,viewBounds:{top:1,bottom:20,left:4,right:240},viewJustifB y:2,viewFont:{family:'espy,face:1,size:10},viewFlags:1,textB :"Wapple",viewFormat:0},btnLink:{widgetType:"textButton",orB der:5,gosub:'URLClicked,viewBounds:{top:80,bottom:93,left:1B 53,right:210},viewFlags:514,text:"Open Link",viewFont:{famiB ly:'espy,face:1,size:9},viewFormat:67109456},btnKbd:{widgetB Type:"pictureButton",order:6,viewBounds:{top:58,bottom:73,lB eft:130,right:167},viewFlags:514,icon:NIL,gosub:'OpenKeyboaB rd},txtMain:{widgetType:"text",order:7,viewClass:81,viewBouB nds:{left:3,top:98,right:320,bottom:402},viewFlags:47616,viB ewFormat:12625,viewJustify:0,viewLineSpacing:16,text:"",vieB wFont:{family:'geneva,face:0,size:10},tabs:[20,40,60,80,120B ,140,160,180]},lblInstructions:{widgetType:"title",order:8,B viewBounds:{left:2,top:80,right:150,bottom:90},viewJustify:B 2,viewFont:{family:'espy,face:2,size:9},viewFlags:1,text:"CB lick a [Link], then press Open Link",viewFormat:0},btnExit:B {widgetType:"LargeCloseBox",order:9,declareSelf:'base,viewJB ustify:6,viewFlags:514,viewBounds:{left:174,top:58,right:19B 7,bottom:73},gosub:'endProgram},scrollbar:{widgetType:"slidB er",order:10,viewFlags:512,viewBounds:{top:58,bottom:73,lefB t:204,right:242},viewValue:1,minValue:0,maxValue:95,gaugeDrawLimits:TRUE,gosub:' DrawText}} 0060 window wlist,Layout_0 0070 show wlist 0080 gosub Initialize // 0090 wait -1 //indefinitely 1000 Initialize: REM 1010 let crlf=chr(13)&chr(10) 1020 let hist:=[] 1030 let histidx=-1 1040 let URL={entire:"",addr:"",file:"",anchor:""} 1050 let bit:=getroot().|bit:nsbasic| 1060 setvalue(layout_0.btnKbd,'icon,@434.icon) 1070 gosub LoadBookmarks // 1080 return 1090 initDeck: REM 1100 setvalue(layout_0.txtMain,'text,clone(XML)) 1110 setvalue(layout_0.scrollbar,'viewValue,1) 1115 let screenOffset = 1 1120 return 1180 go: REM 1190 let bLoading=TRUE 1200 let PrevURL=URL // see if same deck 1210 gosub ParseURL // 1220 if URL.addr<> PrevURL.addr OR URL.file<>PrevURL.file then 1230 gosub getXML // 1240 endif 1250 if bLoading=nil then return 1260 if URL.anchor = "" then 1270 gosub GetFirstCard // 1280 else 1290 gosub GetSpecifiedCard // 1300 endif 1310 gosub InitDeck // 1320 gosub DisplayCard // 1330 LET bLoading =nil 1340 return 1350 getXML: REM 1360 let bit.fconfigRAddr=url.addr 1370 LET bit.fconfigRPort=80 1380 let histidx=histidx+1 1390 if histidx >= length(hist) then addarrayslot(hist,"") 1400 let hist[histidx]=URL.entire 1410 gosub waitForConnect // 1420 if bLoading=nil then return 1430 gosub waitForInputComplete // 1440 let cmd="GET " &"/"& URL.file 1450 let cmd=cmd&" HTTP/1.1"&crlf 1460 let cmd=cmd&"Accept: text/VND.WAP.WML; */*"&crlf 1470 let cmd=cmd&"Accept-Language: en-us"&crlf 1480 let cmd=cmd&"Accept-Encoding: gzip, deflate"&crlf 1490 let cmd=cmd&"User-Agent: WapIDE-SDK/2.0;(R320s(Arial))"&crlf 1500 let cmd=cmd&"Host:"& URL.Addr &crlf 1510 let cmd=cmd&"Connection: Keep-Alive"&crlf 1520 let cmd=cmd&""&crlf 1530 u.bit:send(cmd) 1540 gosub waitForInputStart // 1550 gosub waitForInputComplete // 1560 let XML=bit.fReceiveBuffer 1570 u.bit:cleanup() 1580 return 1590 rem 1600 stopLoading: REM 1610 Setvalue(Layout_0.txtCardTitle,'text,"Stopped") 1620 let bLoading=nil 1630 return 1640 goBack: REM 1650 if histidx <= 0 then return 1660 let histidx=histidx - 1 1670 setvalue(layout_0.lbURL,'text,clone(hist[histidx])) 1680 u.Layout_0.lbURL:updateText(Hist[histidx]) 1690 gosub go // 1700 return 1710 parseURL: REM 1720 LET URL.entire:=clone( u.layout_0.lbURL.windowspec.text) 1730 rem Make sure URL starts with http 1740 let elen=strlen(URL.entire) 1750 if strpos(URL.entire,"http:",0) = nil then let URL.entire="http:/" &"/"&UR L.entire 1760 let elen=strlen(URL.entire) 1770 rem find slash separating addr and page 1780 LET slashPos=strpos(URL.entire,"/",8) 1782 if slashPos=nil then 1784 let URL.Entire=URL.Entire&"/" 1786 LET slashPos=strpos(URL.entire,"/",8) 1788 end if 1790 if slashPos<>nil then LET hashPos= strpos(URL.Entire,"#",slashPos) 1800 if hashPos=nil then hashPos=strlen(URL.Entire) 1810 LET URL.addr=substr(URL.entire,7,slashPos-7) 1820 LET URL.file=substr(URL.entire,slashpos+1,hashPos-slashPos-1) 1830 LET URL.anchor=substr(URL.entire,hashPos+1,strlen(URL.entire)) 1840 return 1850 rem 1860 GetFirstCard: REM 1870 let card="" 1880 let cardStart=strPos(XML,"",cardStart) = nil then let XML=XML&"" 1940 let cardEnd =strPos(XML,"",cardStart) 1950 let card = substr(XML,cardStart,cardEnd-CardStart-1)&"" 1960 return 1970 rem 1980 GetSpecifiedCard: REM 1990 let card="" 2000 let idStart=strPos(XML,"ID=\""&URL.anchor,0) 2010 if idStart=nil then return 2020 let cardStart=strpos(XML,"",cardStart)=nil then let XML=XML&"" 2050 let cardEnd =strPos(XML,"",cardStart) 2060 if cardEnd=nil then cardEnd=strlen(XML) 2070 let card = substr(XML,cardStart,cardEnd-CardStart-1)&"" 2080 return 2090 DisplayCard: REM 2100 if card="" then 2105 let txtline=XML 2110 setvalue(layout_0.txtCardTitle,'Text,"404 Card Not Found") 2120 return 2130 endif 2140 Setvalue(Layout_0.txtCardTitle,'text,"Processing Card") 2145 let cardTitle=URL.addr 2150 let titleStart=strpos(card,"title=",0) 2160 if titleStart<>nil then 2170 let titleEnd=strpos(card,"\"",titlestart+7) 2180 if titleEnd <> nil then let CardTitle=substr(card,titlestart+7,titleEnd- TitleStart-7) 2190 endif 2200 let Links=[] 2210 let LinkStarts=[] 2220 let nextLineNumber=0 2230 let txtLine="" 2240 let charPtr=strPos(card,">",0)+1 2250 do while charPtr < strlen(card) 2252 wait 1 2255 if bLoading=nil then exit do 2260 let c=substr(card,charPtr,1) 2270 let c2=substr(card,charPtr+1,1) 2280 if c="<" then 2290 if c2="/" then gosub ProcessEndTag 2300 if c2="!" then gosub ProcessComment 2310 if c2="a" then gosub ProcessAnchor 2320 if c2="b" then gosub ProcessBreak 2330 if c2="d" then gosub ProcessDo 2340 if c2="g" then gosub ProcessAnchor 2350 if c2="p" then gosub ProcessBreak 2355 if c2="s" then gosub ProcessSmall 2360 if c2="i" then gosub ProcessImage 2370 endif 2380 if c="&" then gosub ProcessAmpersand 2390 if c<>"<" then if c<>"&" then gosub ProcessChar 2400 if charPtr=nil then exit do 2410 let charPtr=charPtr+1 2420 loop 2425 setvalue(Layout_0.txtCardTitle,'text,cardtitle) 2430 setvalue(layout_0.txtMain,'text,clone(txtLine)) 2440 AddArraySlot(LinkStarts,strlen(txtLine)) 2450 return 2460 ProcessComment: REM 2470 let charPtr=strpos(card, "->",charPtr)+1 2480 return 2490 ProcessAnchor: REM 2500 AddArraySlot(LinkStarts,strlen(txtLine)) 2510 let txtLine=txtLine&"["&"link"&"]'" 2520 let addrPtr=strpos(card,"href",charPtr) 2530 let addrPtr=strpos(card,"\"",addrPtr) 2540 if addrPtr=nil then let addrPtr=strpos(card,"href",charPtr)+5 2550 let charPtr=strpos(card,">",charPtr) 2560 let href=substr(card,addrPtr+1,charPtr-addrPtr-2) 2570 for slashpos=elen to 1 step -1 2580 if substr(URL.entire,slashpos-1,1)="/" then exit for 2590 next slashpos 2600 if substr(href,0,5)<>"http:" then let href=substr(URL.entire,0,slashpos)&h ref 2610 AddArraySlot(Links,href) 2620 return 2630 ProcessDo: REM 2640 let charPtr=strpos(card,">",charPtr) 2650 return 2660 ProcessImage: REM 2670 let addrPtr=strpos(card,"alt",charptr) 2680 if addrPtr=nil then let txtLine=txtLine&"" 2690 else 2700 let endPtr=strpos(card,"\"",charPtr) 2710 let txtLine=txtLine&"" 2720 end if 2730 let charPtr=strpos(card,">",charPtr) 2740 return 2750 ProcessAmpersand: REM 2760 if c2="q" then let txtLine=txtLine & "\"" 2770 if c2="a" then let txtLine=txtLine & "&" 2780 if c2="l" then let txtLine=txtLine & "<" 2785 if c2="n" then let txtLine=txtLine & " " 2790 if c2="g" then let txtLine=txtLine & ">" 2800 if c2="s" then let txtLine=txtLine & "-" 2810 let semiPtr=strpos(card,";",charPtr) 2820 if c2="#" then 2822 let c3 = substr(card,charPtr+2,1) 2824 if c3="x" then 2826 let txtLine=txtLine&"?" 2827 else 2828 let txtLine=txtLine&chr(ceiling(StringToNumber(substr(card,charPtr+2,s emiptr-charptr-2)))) 2829 endif 2835 endif 2838 let charPtr=semiPtr 2840 return 2850 ProcessChar: REM 2860 if ord(c[0])<32 or ord(c[0])>127 then let c=" " 2870 let txtLine=txtLine&c 2880 return 2890 ProcessEndTag: REM 2900 let charPtr=strpos(card,">",charPtr) 2910 return 2920 ProcessBreak: REM 2930 let charPtr=strpos(card,">",charptr) 2940 let txtLine=txtLine&"\n" 2950 return 2952 ProcessSmall: REM 2954 let charPtr=strpos(card,">",charptr) 2956 return 2960 URLClicked: REM 2970 let clickPtr=screenOffset + getcaretinfo().info.offset - 1 2970 let clickPtr=getcaretinfo().info.offset 2980 if clickPtr=nil then return 2990 for i=0 to length(LinkStarts)-2 3000 if clickPtr>=LinkStarts[i] AND clickPtr1 then gosub StopLoading 3210 return 3220 waitForInputComplete: REM 3230 Setvalue(Layout_0.txtCardTitle,'text,"Site found, waiting for page") 3240 do 3250 if bLoading=nil then exit do 3260 let l =strlen(bit.fReceiveBuffer) 3270 wait 1000 3280 loop until l=strlen(bit.fReceiveBuffer) 3290 return 3300 waitForInputStart: REM 3310 Setvalue(Layout_0.txtCardTitle,'text,"Waiting...") 3320 do while strlen(bit.fReceiveBuffer)=0 3330 if bLoading=nil then exit do 3340 wait 1000 3350 loop 3360 return 3370 LoadBookmarks: REM 3380 let bkmks=[] 3390 AddArraySlot(bkmks,"mobile.rediff.com/index.wml") 3400 AddArraySlot(bkmks,"www.spyglassmobile.com/default.asp") 3410 AddArraySlot(bkmks,"wap.yehey.com/") 3420 AddArraySlot(bkmks,"wap.countrybookshop.co.uk/") 3430 AddArraySLot(bkmks,"wap.eco.hu/") 3440 AddArraySlot(bkmks,"mobile.iii.co.uk/index.wml#index") 3450 LET AddArraySlot(bkmks,"wap.diax.ch/portal.cfm?language=de") 3460 AddArraySlot(bkmks,"www.pantterithki.fi/wap/index.php3") 3470 AddArraySlot(bkmks, "134.100.11.181/wap/index.wml") 3480 AddArraySlot(bkmks, "oa.europe.yahoo.com/yahooworld.wml ") 3485 AddArraySlot(bkmks, "wap.mobil.nu/") 3486 AddArraySlot(bkmks, "wap.heise.de/") 3490 setvalue( Layout_0.lbURL,'labelCommands,clone(bkmks)) 3500 u.Layout_0.lbURL:updateText(clone(bkmks[0])) 3510 return 3520 DrawText: REM 3530 let screenOffset=ceiling((Layout_0.scrollbar.viewValue/100.0)*strlen(txtLi ne)) 3540 setvalue(layout_0.txtmain,'text,substr(txtline,screenOffset,999999)) 3550 return 9000 endProgram: rem 9020 hide 9030 bye