Ignore:
Timestamp:
03/28/07 08:50:03 (17 years ago)
Author:
smasson
Message:

cleaning + minor bugfix related to the path definition

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SRC/Utilities/xhelp.pro

    r232 r239  
    99; @param FILENAME {in}{required} 
    1010; A scalar string that contains the filename of the file to display. 
    11 ; If FILENAME does not include a complete path specification, xhelp will 
    12 ; search for the file in the current working directory and then each of the 
    13 ; directories listed in !PATH environment variable.  The 
    14 ; ".pro" file suffix will be appended if it is not supplied. 
     11; Filename should be located in !path. 
     12; ".pro" suffix will be appended if needed. 
    1513; 
    1614; @keyword _EXTRA 
    17 ; Used to pass keywords 
     15; Used to pass keywords to <proidl>xdisplayfile</proidl> 
    1816; 
    1917; @restrictions 
     
    4543 
    4644; Are we sure filename is a string? 
    47    cquoidonc = size(filename, /type) 
    48    if cquoidonc NE 7 then begin 
    49       ras = report('Input parameter must be a string and not a '+size(filename, /tname)) 
     45   intype = size(filename, /type) 
     46   if intype NE 7 then begin 
     47      dummy = report('Input parameter must be a string and not a '+size(filename, /tname)) 
    5048      return 
    5149   endif 
    52 ; We have to find the full name 
    53    pfile=FILENAME 
    54    if strpos(pfile,".pro") lt 0 then pfile=pfile+".pro" 
    55    thisOS = strupcase(strmid(!version.os_family, 0, 3)) 
    56    CASE thisOS of 
    57       'MAC':BEGIN & sep = ':' & pathsep = ',' & end 
    58       'WIN':BEGIN & sep = '\' & pathsep = ';' & end 
    59       ELSE: BEGIN & sep = '/' & pathsep = ':' & end 
    60    ENDCASE 
    61    cd, current = current 
    62    if strpos(pfile,sep) lt 0 then BEGIN 
    63       if rstrpos(current,sep) NE strlen(current)-1 then current = current+sep 
    64       multipath = str_sep(!path,pathsep) 
    65       if rstrpos(multipath[0],sep) NE strlen(multipath[0])-1 then multipath = multipath +sep 
    66       pfile = [current, multipath]+ pfile 
    67    ENDIF 
    68 ; We test each possible name to find where the file is. 
    69    nfile=n_elements(pfile) 
    70    n = 0 
    71    repeat begin 
    72       res = findfile(pfile[n]) 
    73       n = n+1 
    74    endrep until res[0] NE '' OR n EQ n_elements(pfile) 
    75    if res[0] NE '' then BEGIN 
    76       openr, unit,pfile[n-1], /get_lun ; opening of the file 
    77 ; we select the heading piece 
    78       a = strarr(1000)          ;Maximum # of lines 
    79       xsize=0 
    80       i = 0 
    81       c = '' 
    82       readon=0 
    83       while not eof(unit) do begin 
    84          readf,unit,c 
    85          if strpos(c,';-') eq 0 then readon=0 
    86          if readon then BEGIN 
    87             dum=where(byte(c) eq 9b,ntab) ; count tab characters 
    88             xsize=xsize > (strlen(c)+8*ntab) 
    89             a[i] = strmid(c,1,200) 
    90             i = i + 1 
    91          endif 
    92          if strpos(c,';+') eq 0 then readon=1 
    93       endwhile 
    94       if i EQ 0 then $ 
    95          ras = report('file is badly written, no header ... Use xfile') ELSE BEGIN 
    96          a = a[0:i-1] 
    97 ; we wrote the a's content in a widget 
    98          xdisplayfile,'toto',text = a,title=pfile[n-1], _extra = ex 
    99       ENDELSE 
    100       FREE_LUN, unit         ;free the file unit. 
    101    ENDIF ELSE ras = report(filename + ' does not exist ...') 
     50; find the file and display it! 
     51   pfile = (find(filename, /first_found))[0] 
     52; read it 
     53   IF pfile NE 'NOT_FOUND' THEN BEGIN  
     54     fulltext = getfile(pfile) 
     55; find the ";+"and ";-" 
     56     start = where(stregex(fulltext,'^ *;\+ *$', /boolean) EQ 1, cnt1) 
     57     ending = where(stregex(fulltext,'^ *;- *$', /boolean) EQ 1, cnt2) 
     58     IF cnt1 EQ 0 OR cnt1 NE cnt2 THEN BEGIN 
     59       dummy = report('file '+pfile+' is badly written, no proper header found... Use xfile') 
     60       return 
     61     ENDIF 
     62; do we have hidden parts? 
     63     hide = where(stregex(fulltext, '^ *; *@hidden *$', /boolean) EQ 1) 
     64; buid the text to display 
     65     header = '' 
     66     sepbloc = ['', string(replicate(byte('='), 60)), ''] 
     67     FOR i = 0, cnt1-1 DO BEGIN 
     68; is this part hidden ? 
     69       st = start[i] 
     70       ed = ending[i] 
     71       IF st NE ed +1 THEN BEGIN ; non-empty bloc 
     72         dummy = where(hide GT st AND hide LT ed, cnt) 
     73       IF cnt EQ 0 THEN header = [header, '', sepbloc, fulltext[st+1:ed-1]] 
     74       ENDIF 
     75     ENDFOR 
     76; remove the fisrt useless lines 
     77     IF n_elements(header) GT 1 THEN header = header[4:*] ELSE BEGIN  
     78       dummy = report('file '+pfile+' has empty header... Use xfile') 
     79       return 
     80     ENDELSE 
     81;      
     82     xdisplayfile, 'dummy', text = header[1:*], title = pfile, _extra = ex 
     83; 
     84   ENDIF ELSE dummy = report(filename + ' does not exist ...') 
    10285 
    10386   return 
Note: See TracChangeset for help on using the changeset viewer.