source: trunk/SRC/Utilities/report.pro @ 269

Last change on this file since 269 was 269, checked in by pinsard, 17 years ago

add revision in report message. see 65.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1;+
2;
3; @file_comments
4; Like <proidl>DIALOG_MESSAGE</proidl> if there is already some widget
5; active or like <proidl>MESSAGE</proidl> if there is not any widget active.
6; To ask a question whose answer is not yes/no, use <pro>xquestion</pro>.
7;
8; @param TEXT {in}{required} {type=scalar string or arrays of string}
9; If TEXT is a scalar string, we look for the line feed character "!C".
10; If TEXT is set to an array of strings, each
11; array element is displayed as a separate line of text.
12;
13; @keyword SIMPLE
14; activate to print only the message without the name
15; and the line of the routine (defined by calling <pro>routine_name</pro>)
16; or++
17; Activate to print the error message without printing the routine name with
18; its full path.
19;
20; @keyword PARENT
21; same as DIALOG_PARENT of <proidl>DIALOG_MESSAGE</proidl>
22;
23; @keyword QUESTION {default="Warning"}
24; Set this keyword to create a "Question" dialog.
25;
26; @keyword DEFAULT_NO {default="Yes"}
27; Set this keyword to make the "No" button the default selection for
28; "Question" dialog.
29;
30; @keyword _EXTRA
31; Used to pass keywords to <proidl>DIALOG_MESSAGE</proidl> and
32; <proidl>MESSAGE</proidl>
33;
34; @returns
35; -1 if the keyword QUESTION is not activated
36; If the keyword QUESTION is activated, return 1 for yes and 0 for no.
37;
38; @examples
39; If there is not any widget activated:
40;
41; IDL> help, report('toto tata')
42; % $MAIN$: toto tata
43; <Expression>    INT       =       -1
44; IDL> help, report('does it works ?',/question)
45; does it works ? y/n (default answer is y)
46; <Expression>    BYTE      =    1
47; IDL> help, report('question1: !C does it works ?',/question)
48; question1:
49; does it works ? y/n (default answer is y)
50; <Expression>    BYTE      =    1
51;
52; If widgets are already activated, it is the same thing but with widgets!
53;
54; @history
55; Sebastien Masson (smasson\@lodyc.jussieu.fr)
56;                      21/10/1999
57;
58; @version
59; $Id$
60;
61;-
62;
63FUNCTION report, text, DEFAULT_NO = default_no, PARENT = parent, QUESTION = question, SIMPLE = simple, _EXTRA = ex
64;
65  compile_opt idl2, strictarrsubs
66;
67  res = -1                      ;
68; we separate the text in different lines (separated by !C) if it is not already done...
69  if n_elements(text) EQ 1 then text = str_sep(text, '!C', /trim)
70; there is some widgets activated, it is easy, we call dialog_massage
71  if (widget_info(/managed))[0] NE 0 then BEGIN
72    res = dialog_message(text, dialog_parent = parent, QUESTION = question $
73                         , title = routine_name(1), DEFAULT_NO = default_no, _extra = ex)
74    if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1
75  ENDIF ELSE BEGIN
76; there is not any widget activated
77; do we ask a question ?
78    if keyword_set(question) then BEGIN
79; what is the answer by default ?
80      if keyword_set(default_no) then answer = 'n' ELSE answer = 'y'
81      default_answer = answer
82      if n_elements(text) GT 1 THEN $
83        for i = 0, n_elements(text)-2 do print, text[i]
84      read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer
85      answer = strlowcase(answer) ;
86; if the answer is not appropriated
87      while answer NE '' and answer NE 'y' and answer NE 'n' do begin
88        read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer
89        answer = strlowcase(answer)
90      ENDWHILE                  ;
91; we adjust res in function of the answer
92      case answer of
93        '':res = default_answer EQ 'y'
94        'y':res = 1
95        'n':res = 0
96      endcase
97    ENDIF
98  ENDELSE
99; If we do not ask any question, we just make a print
100  IF NOT keyword_set(question) THEN BEGIN
101    IF keyword_set(simple) THEN prefix = '' ELSE BEGIN
102;    Look for the revsion in the code of the procedure/function calling this
103;    report function (ie the one where an problem was detected) in the first
104;    occurence of the form :
105;    "; $Id$"
106     split=STRSPLIT(routine_name(1), ' ', /EXTRACT) 
107     fileroutine=split[1]
108     coderoutine = getfile(fileroutine)
109     idline = where(stregex(coderoutine,'^; \$Id: .* .* .* .* \$', /boolean) EQ 1, cnt1)
110     IF (idline GT 0) THEN BEGIN
111       split=STRSPLIT(coderoutine[idline],' ', /EXTRACT)
112       revision=split[3]
113       prefix = '% '+routine_name(1)+ ' ' + revision + ': '
114     ENDIF ELSE BEGIN
115       prefix = '% '+routine_name(1)+': '
116     ENDELSE
117    ENDELSE
118    IF n_elements(text) GT 1 THEN $
119      for i = 0, n_elements(text)-2 do print, prefix+text[i]
120      print, prefix+text[n_elements(text)-1]
121    ENDIF
122
123   return,  res
124end
Note: See TracBrowser for help on using the repository browser.