;+ ; NAME: ; ERROR_MESSAGE ; ; PURPOSE: ; ; The purpose of this function is to have a device-independent ; error messaging function. The error message is reported ; to the user by using DIALOG_MESSAGE if widgets are ; supported and MESSAGE otherwise. ; ; AUTHOR: ; ; FANNING SOFTWARE CONSULTING ; David Fanning, Ph.D. ; 1645 Sheely Drive ; Fort Collins, CO 80526 USA ; Phone: 970-221-0438 ; E-mail: davidf@dfanning.com ; Coyote's Guide to IDL Programming: http://www.dfanning.com/ ; ; CATEGORY: ; ; Utility. ; ; CALLING SEQUENCE: ; ; ok = Error_Message(the_Error_Message) ; ; INPUTS: ; ; the_Error_Message: This is a string argument containing the error ; message you want reported. If undefined, this variable is set ; to the string in the !Error_State.Msg system variable. ; ; KEYWORDS: ; ; NONAME: If this keyword is set the name of the calling routine ; is not printed along with the message. ; ; TRACEBACK: Setting this keyword results in an error traceback ; being printed to standard output with the PRINT command. ; ; In addition, any keyword appropriate for the MESSAGE or DIALOG_MESSAGE ; routines can also be used. ; ; OUTPUTS: ; ; Currently the only output from the function is the string "OK". ; ; RESTRICTIONS: ; ; The "Warning" Dialog_Message dialog is used by default. Use keywords ; /ERROR or /INFORMATION to select other dialog behaviors. ; ; EXAMPLE: ; ; To handle an undefined variable error: ; ; If N_Elements(variable) EQ 0 Then $ ; ok = Error_Message('Variable is undefined', /Traceback) ; ; MODIfICATION HISTORY: ; ; Written by: David Fanning, 27 April 1999. ; Added the calling routine's name in the message and NoName keyword. 31 Jan 2000. DWF. ; Added _Extra keyword. 10 February 2000. DWF. ; Forgot to add _Extra everywhere. Fixed for MAIN errors. 8 AUG 2000. DWF. ; Adding call routine's name to Traceback Report. 8 AUG 2000. DWF. ; Switched default value for Dialog_Message to "Error" from "Warning". 7 OCT 2000. DWF. ;- ;########################################################################### ; ; LICENSE ; ; This software is OSI Certified Open Source Software. ; OSI Certified is a certification mark of the Open Source Initiative. ; ; Copyright © 1999-2000 Fanning Software Consulting ; ; This software is provided "as-is", without any express or ; implied warranty. In no event will the authors be held liable ; for any damages arising from the use of this software. ; ; Permission is granted to anyone to use this software for any ; purpose, including commercial applications, and to alter it and ; redistribute it freely, subject to the following restrictions: ; ; 1. The origin of this software must not be misrepresented; you must ; not claim you wrote the original software. If you use this software ; in a product, an acknowledgment in the product documentation ; would be appreciated, but is not required. ; ; 2. Altered source versions must be plainly marked as such, and must ; not be misrepresented as being the original software. ; ; 3. This notice may not be removed or altered from any source distribution. ; ; For more information on Open Source Software, visit the Open Source ; web site: http://www.opensource.org. ; ;########################################################################### FUNCTION ERROR_MESSAGE, theMessage, Traceback=traceback, NoName=noName, _Extra=extra On_Error, 2 ; Check for presence and type of message. If N_Elements(theMessage) EQ 0 Then theMessage = !Error_State.Msg s = Size(theMessage) messageType = s[s[0]+1] If messageType NE 7 Then Begin Message, "The message parameter must be a string.", _Extra=extra Endif ; Get the call stack and the calling routine's name. Help, Calls=callStack callingRoutine = (Str_Sep(StrCompress(callStack[1])," "))[0] ; Are widgets supported? Doesn't matter in IDL 5.3 and higher. widgetsSupported = ((!D.Flags AND 65536L) NE 0) OR Float(!Version.Release) GE 5.3 If widgetsSupported Then Begin If Keyword_Set(noName) Then answer = Dialog_Message(theMessage, _Extra=extra) Else Begin If StrUpCase(callingRoutine) EQ "$MAIN$" Then answer = Dialog_Message(theMessage, _Extra=extra) Else $ answer = Dialog_Message(StrUpCase(callingRoutine) + ": " + theMessage, _Extra=extra) Endelse Endif Else Begin Message, theMessage, /Continue, /NoPrint, /NoName, /NoPrefix, _Extra=extra Print, '%' + callingRoutine + ': ' + theMessage answer = 'OK' Endelse ; Provide traceback information if requested. If Keyword_Set(traceback) Then Begin Help, /Last_Message, Output=traceback Print,'' Print, 'Traceback Report from ' + StrUpCase(callingRoutine) + ':' Print, '' FOR j=0,N_Elements(traceback)-1 DO Print, " " + traceback[j] Endif RETURN, answer End PRO TNN_Cleanup, base COMMON TN, delay_secs, out_dir If !Version.OS EQ 'Win32' Then Begin del_cmd = 'DEL ' + out_dir + '\TNN_default.htm' ; WINDOWS SPAWN,del_cmd Endif Else Begin del_cmd = 'rm -f ' + out_dir + '/TNN_default.htm' ; LINUX Spawn,del_cmd Endelse Widget_control,base,/Destroy End PRO OZ_STUFF, all_text,hdr,title ;... Parse the nice, simple text format used by Australia's ABC network ;... COMMON TN, delay_secs, out_dir COMMON TN1, text_id,delay_id, show_on_update, bell COMMON TN2, delay0_id,delay1_id,delay2_id,delay3_id,delay4_id,delay5_id,delay_ids COMMON TN3, opt2_id,opt3_id,delay_text,delay_values COMMON TN4, old_hdr COMMON TN5,mem_id COMMON TN6, reuters,ap_international,ap_australia,source1_id,source2_id,source3_id,$ Source_URL, International_URL,American_URL,Australian_URL,source_text ; Handles the format of Australia's www.abc.net/news/justin/default.html OZ_start_text = '' OZ_end_text = '' start = Where(Strtrim(all_text(*),2) EQ OZ_start_text) end_line = Where(Strtrim(all_text(*),2) EQ OZ_end_text) end_line = end_line(0) ; IDL v5.4 is very fussy about this - v5.5 isn't!! start = start(0) If start EQ -1 OR end_line EQ -1 Then Begin Widget_control,text_id,timer = Fix(delay_secs) print,'********** OZ News start or end buggared -> RETURN...****************' Xdisplayfile,Title='TNN : Error',$ Text = 'Unable to find Start or End of News in Australian text',$ Done_button = 'Exit Error Message' title="Teste's Nifty News" RETURN Endif all_text = all_text(start:end_line) post_idx = Where(strpos(all_text(*),'posted') NE -1) postings = all_text(Where(strpos(all_text(*),'posted') NE -1)) N_Postings = N_Elements(postings) Post_pos = Strpos(postings(*),'posted') AEST = Strpos(postings(*),'AE') Widget_control,text_id,set_text_top_line = 0 ; Can't let it grow in size forever. Assume a posting every 3 minutes ; and print up to a max of 480 = 20 per hour by 24 hours FOR i = 0, N_Postings - 1 < 480 DO Begin hdr_line = post_idx(i) + 2 this_hdr = all_text(hdr_line) hdr_s = Strpos(this_hdr,'htm">') hdr_e = Strpos(this_hdr,'') ; Some browsers wrap the text, such that the header is split over 2 lines. ; In this case we concatenate 3 lines of text before searching for the strings ; indicating the start/end of the header If hdr_s EQ -1 Then Begin this_hdr = this_hdr + all_text(hdr_line+1) + all_text(hdr_line + 2) hdr_s = Strpos(this_hdr,'htm">') hdr_e = Strpos(this_hdr,'') Endif hdr = Strmid(this_hdr,hdr_s+5,hdr_e - hdr_s-5) If i EQ 0 Then Begin title = hdr Endif time_str = Strmid(postings(i),AEST(i)-8,7) hour = Fix(Strmid(time_str,0,2)) pm = Strpos(time_str,'pm') ; Convert from Eastern States time to South Australian time, ; e.g. -30 minutes from Sydney time on wwhich the posting times are based. If pm(0) NE -1 AND hour LE 11 Then hour = hour + 12 mins = Fix(Strmid(time_str,3,2)) If mins GE 30 Then Begin mins = mins - 30 Endif Else Begin mins = 60 + (mins-30) ; If 00:00 to 00:30 a.m. can't have 0-1 -> -1 hours, so go back to 23:00 If hour EQ 0 Then Begin hour = 23 Endif Else Begin hour = hour - 1 Endelse Endelse time_text = 'Posted: ' + String(hour,mins,FORM="(i2.2,':',i2.2)") If i EQ 0 Then append = 0 Else append = 1 Widget_control,text_id,set_value=time_text+' '+hdr,append = append End End PRO International_STUFF, all_text,hdrs,title, Reuter=reuter,American=american ; Parse the Reuters international feed from news.excite.com COMMON TN, delay_secs, out_dir COMMON TN1, text_id,delay_id, show_on_update, bell COMMON TN2, delay0_id,delay1_id,delay2_id,delay3_id,delay4_id,delay5_id,delay_ids COMMON TN3, opt2_id,opt3_id,delay_text,delay_values COMMON TN4, old_hdr COMMON TN5,mem_id COMMON TN6, reuters,ap_international,ap_australia,source1_id,source2_id,source3_id,$ Source_URL, International_URL,American_URL,Australian_URL,source_text ; Handles the format of Excite.Com's reuters International page ; 29-Jan-2002 Comment out the "American" stuff which used to access the ; Associated Press (AP) page at excite.com. ; Text no longer retrievable. reuters_start_text = '|world|' start_text = reuters_start_text ; american_start_text = '|ap|' If Keyword_set(reuter) NE 0 Then start_text = reuters_start_text ; If Keyword_set(reuter) NE 0 Then start_text = reuters_start_text ; If Keyword_set(american) NE 0 Then start_text = american_start_text ; If Keyword_set(american) NE 0 Then Begin ; stop ; endif print," '|world|' is the start text start = Where(Strpos(all_text(*),start_text) NE -1)" ;stop start = Where(Strpos(all_text(*),start_text) NE -1) start = start(0) If start EQ -1 Then Begin Widget_control,text_id,timer = Fix(delay_secs) print,'********** Reuters News start buggared -> RETURN...****************' Xdisplayfile,Title='TNN : Error', $ Text = 'Unable to find Start or End of News in Reuters International text',$ Done_button = 'Exit Error Message' title="Teste's Nifty News" RETURN Endif text = all_text(start) hdrs = [' '] times = [' '] earlier_pos = Strpos(text,'Earlier News') text = Strmid(text,0,earlier_pos-1) world_pos = Strpos(text,'|world|') help,text print,'earlier_pos = ',earlier_pos print,'world_pos = ',world_pos ;stop WHILE world_pos NE -1 DO Begin time = Strmid(text,world_pos+8,16) clip_pos = world_pos+8+16+18 text = Strmid(text,clip_pos,Strlen(text)) color_pos_a = Strpos(Strmid(text,0,250),'color=black>') color_pos_b = Strpos(Strmid(text,0,250),'color="#') ; 'color="#000000">' IF color_pos_a(0) NE -1 Then Begin black_pos = color_pos_a text = Strmid(text,black_pos+12,Strlen(text)) Endif IF color_pos_b(0) NE -1 Then begin black_pos = color_pos_b text = Strmid(text,black_pos+16,Strlen(text)) Endif end_a = Strpos(text,'') end_b = Strpos(text,'...') endb = end_a < end_b hdr = Strmid(text,0,endb) hdrs = [hdrs,hdr] times = [times,time] clip_pos = endb text = Strmid(text,endb,Strlen(text)) world_pos = Strpos(text,'|world|') End hdrs = hdrs(1:*) times = times(1:*) N_Postings = N_Elements(hdrs) For i = 0,N_Postings-1 Do Begin If i EQ 0 Then append = 0 Else append = 1 Widget_control,text_id,set_value=times(i) + ' ' + hdrs(i),append = append End Title = hdrs(0) End PRO TNN_Error_handler COMMON TN, delay_secs, out_dir HELP,CALLS=calls HELP,/Structure,!ERROR_STATE,OUT=error_state outfile = out_dir + '\TNN_ERROR.TXT' OpenW,lun,outfile,/GET PRINTF,lun, SYSTIME() PRINTF,lun,'------ !ERR_STRING MESSAGE -------------------' PRINTF,lun,!ERR_STRING PRINTF,lun,'------ !ERROR_STATE STRUCTURE -------------------' PRINTF,lun,error_state,FORMAT='(a)' PRINTF,lun,'------ !ERROR_STATE SYS_CODE -------------------' PRINTF,lun,!ERROR_STATE.SYS_CODE,FORMAT='(2(i6))' PRINTF,lun,'------ CALLS TRACEBACK -------------------' PRINTF,lun,calls,FORMAT='(a)' FREE_LUN,lun CLOSE,lun ; Widget_control,base_id,tlb_set_title = 'TNN:' + !ERR_STRING Xdisplayfile,Title='TNN : Error', $ Text = ['Please email this text to the Author and',$ 'also the file ' + outfile,$ 'Send to andrew.cool@dsto.defence.gov.au ',$ ' ',$ !ERR_STRING,$ ' ',$ calls],$ Done_button = 'Exit Error Message' End PRO TNN_event, ev COMMON TN, delay_secs, out_dir COMMON TN1, text_id,delay_id, show_on_update, bell COMMON TN2, delay0_id,delay1_id,delay2_id,delay3_id,delay4_id,delay5_id,delay_ids COMMON TN3, opt2_id,opt3_id,delay_text,delay_values COMMON TN4, old_hdr COMMON TN5,mem_id COMMON TN6, reuters,ap_international,ap_australia,source1_id,source2_id,source3_id,$ Source_URL, International_URL,American_URL,Australian_URL,source_text ; David Fanning's new Traceback error message routine Catch, theError If theError NE 0 Then Begin Catch, /Cancel ; ok = Error_Message(Traceback=1) TNN_error_handler If N_Elements(info) NE 0 Then Widget_Control, event.top, Set_UValue=info, /No_Copy Return Endif type = Tag_Names(ev,/Structure) If type NE 'WIDGET_TIMER' Then Begin Widget_control,ev.id,get_uvalue=UV Widget_control,ev.id,get_value=value old_delay_secs = delay_secs Case UV OF 'UPDATE' : Begin Widget_control,ev.top,/Clear_events Widget_control,text_id,TIMER=0.0 End 'SHOW' : Begin show_on_update = NOT show_on_update If NOT show_on_update Then Begin Widget_control,opt2_id,set_value='(N) Show on Update' Endif Else Begin Widget_control,opt2_id,set_value='(Y) Show on Update' Widget_control,ev.top,ICONIfY = 1 Endelse End 'BELL' : Begin bell = NOT bell If NOT bell Then Begin Widget_control,opt3_id,set_value='(N) Bell on Update' Endif Else Begin Widget_control,opt3_id,set_value='(Y) Bell on Update' Endelse End 'REFRESH MENU' : Begin FOR btn = 0,N_Elements(delay_ids) -1 DO Begin Widget_control,delay_ids(btn),set_value = delay_text(btn) End delay_secs = delay_values(ev.value) Widget_control,delay_ids(ev.value),set_value = '*' + delay_text(ev.value) Widget_control,ev.top,/Clear_events End ; Make this a tad more elegant one day, Andrew! 'SOURCE REUTERS' : Begin Source_URL = International_URL Widget_control,source1_id,set_value = '*' + source_text(0) ; Widget_control,source2_id,set_value = ' ' + source_text(1) Widget_control,source3_id,set_value = ' ' + source_text(2) Widget_control,ev.top,/Clear_events Widget_control,text_id,TIMER=0.0 End 'SOURCE AMERICAN' : Begin Source_URL = American_URL Widget_control,source1_id,set_value = ' ' + source_text(0) ; Widget_control,source2_id,set_value = '*' + source_text(1) Widget_control,source3_id,set_value = ' ' + source_text(2) Widget_control,ev.top,/Clear_events Widget_control,text_id,TIMER=0.0 End 'SOURCE AUSTRALIA' : Begin Source_URL = Australian_URL Widget_control,source1_id,set_value = ' ' + source_text(0) ; Widget_control,source2_id,set_value = ' ' + source_text(1) Widget_control,source3_id,set_value = '*' + source_text(2) Widget_control,ev.top,/Clear_events Widget_control,text_id,TIMER=0.0 End 'EXIT' : Begin TNN_Cleanup, ev.top RETURN End Else : Widget_control,text_id,set_value= 'Invalid UV = ' + STRING(uv) Endcase Widget_control,text_id,TIMER=delay_secs Endif Else Begin ; UPDATE ! Widget_control,ev.top,tlb_set_title = 'TNN: Updating...' If !Version.OS NE 'Win32' Then Begin del_cmd = 'rm -f ' + out_dir + '/TNN_default.htm' SPAWN,del_cmd Endif Else Begin del_cmd = 'DEL ' + out_dir + '\TNN_default.htm' SPAWN,del_cmd,/HIDE,/LOG,/NOWAIT Endelse Close,/ALL ; ************************************************************************** ; ; Amend the proxy URL to be that via which you access the Internet. ; Proxy_URL = 'www-sa.dsto.defence.gov.au' ; ************************************************************************** ; Here's the real business of opening a Socket and sucking down some "stuff" ; Note that "stuff" can be anything, from an HTML page to a .exe file to a .zip ; file to Wav files, etc. Warning - by sucking in stuff in this manner you might ; bypass any Virus checking & protection utilities you have installed. That might ; not be good for you. t = SYSTIME(1) SOCKET, unit, Proxy_URL, 8080, /GET_LUN, ERR=err ; At the moment, if opening a Socket times out, then we drop back to the ; event handler and wait for the next scheduled update in a few minutes. ; This could be altered such that we loop around here N times with a short ; wait in between until either a Socket connection is made or we hit N ; attempts, at which point we drop back to the event handler... If err NE 0 Then Begin Widget_control,ev.top,tlb_set_title='No Socket Avail... ' + String(err) Goto, NO_SOCKET_AVAILABLE Endif Get_cmd = 'GET ' + Source_URL Printf, unit, get_cmd If !Version.OS NE 'Win32' Then Begin OpenW,lun,out_dir + '/TNN_default.htm',/GET ; LINUX Endif Else Begin OpenW,lun,out_dir + '\TNN_default.htm',/GET ; WINDOWS Endelse txt=' ' While EOF(unit) EQ 0 Do Begin ReadF, unit, txt & PrintF,lun,txt Endwhile Flush,lun Free_Lun,lun,unit Close,/ALL ; print,'Socket open for ',SYSTIME(1)-t,' seconds' If !Version.OS NE 'Win32' Then Begin OpenR,lun1,out_dir + '\TNN_default.htm',/get ; LINUX Endif Else Begin OpenR,lun1,out_dir + '/TNN_default.htm',/get ; WINDOWS Endelse all_text='' all_text = strarr(5000) line='' On_IOerror,close_it ReadF,lun1,all_text close_it: free_lun,lun1 close,lun1 On_IOerror,null process: post_idx = '' postings = '' time_text='' reuters_text = '|reuters.html' ap_text = 'news/ap/' OZ_text = '