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

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

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

  • 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 textin {in}{required} {type=scalar string or arrays of string}
9; If textin is a scalar string, we look for the line feed character "!C".
10; If textin 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;-
62FUNCTION report, textin, DEFAULT_NO=default_no, PARENT=parent $
63               , 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(textin) EQ 1 then text = '% ' + str_sep(textin, '!C', /trim) ELSE text = '% ' + textin
70; we get the line, routine name ad revision version
71  IF NOT keyword_set(simple) THEN BEGIN
72;    Look for the revsion in the code of the procedure/function calling this
73;    report function (ie the one where an problem was detected) in the first
74;    occurence of the form :
75;    "; $Id$"
76    prefix = routine_name(1)
77    split = STRSPLIT(prefix, ' ', /EXTRACT, count = cnt) 
78    IF cnt GT 1 THEN BEGIN
79      coderoutine = getfile(split[1])
80      idline = (where(stregex(coderoutine, '^; \$Id: .* .* .* .* \$', /boolean) EQ 1))[0]
81      IF (idline GT 0) THEN BEGIN
82        split = STRSPLIT(coderoutine[idline], ' ', /EXTRACT)
83        prefix = '% '+prefix+ ' rev. ' + split[3] + ': '
84      ENDIF ELSE BEGIN
85        prefix = '% '+prefix+': '
86      ENDELSE
87    ENDIF
88    text = [prefix, text]
89  ENDIF
90; there is some widgets activated, it is easy, we call dialog_massage
91  if (widget_info(/managed))[0] NE 0 then BEGIN
92    res = dialog_message(text, dialog_parent = parent, QUESTION = question $
93                         , title = routine_name(1), DEFAULT_NO = default_no, _extra = ex)
94    if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1
95  ENDIF ELSE BEGIN
96; there is not any widget activated
97; do we ask a question ?
98    IF keyword_set(question) THEN BEGIN
99; what is the answer by default ?
100      if keyword_set(default_no) then answer = 'n' ELSE answer = 'y'
101      default_answer = answer
102      if n_elements(text) GT 1 THEN $
103         for i = 0, n_elements(text)-2 do print, text[i]
104      read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer
105      answer = strlowcase(answer) ;
106; if the answer is not appropriated
107      while answer NE '' and answer NE 'y' and answer NE 'n' do begin
108        read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer
109        answer = strlowcase(answer)
110      ENDWHILE                  ;
111; we adjust res in function of the answer
112      case answer of
113        '':res = default_answer EQ 'y'
114        'y':res = 1
115        'n':res = 0
116      endcase
117    ENDIF
118  ENDELSE
119; If we do not ask any question, we just make a print
120  IF NOT keyword_set(question) THEN BEGIN
121    FOR i = 0, n_elements(text)-1 do print, text[i]
122  ENDIF
123
124  return,  res
125end
Note: See TracBrowser for help on using the repository browser.