~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/clients/qmon/qmon_file.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 * 
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
 
 
33
#include <stdio.h>
 
34
#include <errno.h>
 
35
 
 
36
#include <Xm/Xm.h>
 
37
 
 
38
#include "uti/sge_stdio.h"
 
39
#include "uti/sge_unistd.h"
 
40
 
 
41
#include "sgeobj/sge_answer.h"
 
42
 
 
43
#include "qmon_rmon.h"
 
44
#include "qmon_cull.h"
 
45
#include "qmon_browser.h"
 
46
#include "qmon_file.h"
 
47
 
 
48
#include "msg_common.h"
 
49
#include "msg_utilib.h"
 
50
 
 
51
lList* qmonReadFile(const char *filename)
 
52
{
 
53
   char *text = NULL;
 
54
   lList *alp = NULL;
 
55
 
 
56
   DENTER(GUI_LAYER, "qmonReadFile");
 
57
 
 
58
   text = qmonReadText(filename, &alp);
 
59
 
 
60
   /* insert file contents in browser */
 
61
   qmonBrowserShow(text);
 
62
 
 
63
   /* free all allocated space and close */
 
64
   XtFree(text);
 
65
 
 
66
   DRETURN(alp);
 
67
}   
 
68
 
 
69
char *qmonReadText(const char *filename, lList **alpp)
 
70
{
 
71
   char *text = NULL;
 
72
   SGE_STRUCT_STAT statb;
 
73
   FILE *fp = NULL;
 
74
 
 
75
   DENTER(GUI_LAYER, "qmonReadText");
 
76
 
 
77
   if (filename == NULL) {
 
78
      answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
 
79
                              "No filename specified");
 
80
      DRETURN(NULL);
 
81
   }
 
82
 
 
83
   /* 
 
84
   ** make sure the file is a regular text file and open it 
 
85
   */
 
86
   if (SGE_STAT(filename, &statb) == -1 
 
87
       || (statb.st_mode & S_IFMT) != S_IFREG 
 
88
       || !(fp = fopen(filename, "r"))) {
 
89
      answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
 
90
                      MSG_FILE_OPENFAILED_S, filename);
 
91
      DRETURN(NULL);
 
92
   }
 
93
 
 
94
   /* 
 
95
   ** put the contents of the file in the Text widget by allocating
 
96
   ** enough space for the entire file, reading the file into the
 
97
   ** allocated space, and using XmTextFieldSetString() to show the file.
 
98
   */
 
99
   if ((text = XtMalloc((unsigned)(statb.st_size + 1))) == NULL) {
 
100
      answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
 
101
                              MSG_MEMORY_MALLOCFAILED);
 
102
      FCLOSE(fp);
 
103
      DRETURN(NULL);
 
104
   }
 
105
 
 
106
   if (!fread(text, sizeof (char), statb.st_size + 1, fp)) {
 
107
      answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
 
108
                              MSG_FILE_FREADFAILED_SS, filename, strerror(errno));
 
109
   }
 
110
 
 
111
   text[statb.st_size] = 0; /* be sure to NULL-terminate */
 
112
 
 
113
   FCLOSE(fp);
 
114
   DRETURN(text);
 
115
 
 
116
FCLOSE_ERROR:
 
117
   XtFree(text);
 
118
   answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
 
119
                           MSG_FILE_NOCLOSE_SS, filename, strerror(errno));
 
120
   DRETURN(NULL);
 
121
}