;+ ; NAME: ; www_help_verify_name ; PURPOSE: ; Checks whether a string is a valid name for an IDL procedure ; CATEGORY: ; www_help ; CALLING SEQUENCE: PRO www_help_verify_name, name, source ; INPUTS: ; name scalar; type: string ; name of procedure ; source scalar; type: string ; name of source file containing code for 'name' ; OUTPUTS: ; name scalar; type: string ; blank string if input name is invalid; otherwise unmodified ; INCLUDE: @compile_opt.pro ; On error, return to caller ; PROCEDURE: ; The purpose of this routine is to intercept any weird mistakes in IDL ; headers. Current checks are pretty kludgy, Needs work. ; ; > Leading and trailing whitespace is trimmed. ; > Extension .pro is trimmed ; > Only letters, digits and a few other characters (underscore, space) are permitted ; MODIFICATION HISTORY: ; JULY-2001, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- old_name = name name = strtrim(name,2) ; Remove leading and trailing whitespace good = strlen(name) GT 0 IF good THEN BEGIN ; Remove trailing '.pro' pos = strlen(name) IF pos GT 4 THEN IF strmid(strlowcase(name),pos-4,4) EQ '.pro' then name = strmid(name,0,pos-4) name = strtrim(name,2) ; Remove leading and trailing whitespace good = strlen(name) GT 0 ENDIF IF good THEN BEGIN ; List of acceptable characters in 'name': letters, digits, space, underscore, ; and ... (anyything else???). Remove all characters that are not on the list. letters = byte('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_ ') name = byte(name) pos = where_common(name,letters) good = pos[0] NE -1 IF good THEN name = string(name[pos]) ELSE name = '' name = strtrim(name,2) ; Remove leading and trailing whitespace good = strlen(name) GT 0 ENDIF IF good THEN BEGIN ; Name should not contain whitespace ; Names containing white space are probably not names but some sort of ; functional description. For the time begin these are rejected. I tried ; using the first word. That doesn't work very satisfactory. ; good = strlen(strcompress(name,/rem)) EQ strlen(name) ; IF NOT good THEN BEGIN ; Whitespace found ; pos = [strpos(name, string( 9B)), strpos(name, string(32B))] ; First tab, first space ; good = (where(pos NE -1))[0] NE -1 ; IF good THEN BEGIN ; pos = pos[where(pos ne -1)] ; pos = min(pos) ; name = strmid(name,0,pos) ; Extract first fragment ; ENDIF ; ENDIF ENDIF ; If anything went wrong, clear and return IF NOT good THEN BEGIN IF strlen(old_name) GT 0 THEN BEGIN message, /info, source message, /info, 'invalid name rejected: '+old_name ENDIF name = '' ENDIF RETURN & END