1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
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
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.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
37
#include "uti/sge_stdio.h"
40
#include "sge_ja_task.h"
41
#include "sge_answer.h"
42
#include "sge_string.h"
44
#include "parse_qsubL.h"
47
#include "sge_job_refL.h"
49
#include "unparse_job_cull.h"
50
#include "write_job_defaults.h"
52
#include "msg_common.h"
54
static lList *write_defaults_file(lList *lp, char *filename, int flags);
58
** write_job_defaults - defaults file from job structure
61
** filename - file to write defaults to
62
** flags - FLG_FULL_CMDLINE or 0
65
** answer list, AN_Type, or NULL if everything ok,
66
** the following stati can occur:
71
** unparses a job element into a default file
72
** containing the option switches
74
lList *write_job_defaults(
75
sge_gdi_ctx_class_t *ctx,
82
lList *cmdline = NULL;
86
DENTER(TOP_LAYER, "write_job_defaults");
88
alp = cull_unparse_job_parameter(ctx, &cmdline, job, flags);
90
answer_exit_if_not_recoverable(aep);
91
status = answer_get_status(aep);
92
if ((status != STATUS_OK) && (status != STATUS_EEXIST)) {
101
alp = write_defaults_file(cmdline, filename, flags);
103
answer_exit_if_not_recoverable(aep);
104
status = answer_get_status(aep);
105
if ((status != STATUS_OK) && (status != STATUS_EEXIST)) {
119
** write_defaults_file - writing job options
121
** lp - list of options, SPA_Type
122
** filename - name of file to write options to,
123
** or NULL, in this case stdout is used
124
** flags - FLG_FULL_CMDLINE or 0
127
** answer list, AN_Type, or NULL if everything ok,
128
** the following stati can occur:
129
** STATUS_EDISK - error opening or writing to filename
130
** STATUS_ESYNTAX - the original command line string was
136
** this function writes the given options to a file without
137
** unparsing them. The following fields are written:
138
** SPA_switch, then a blank (except for -l) and then
139
** SPA_switch_arg, if the option had an argument on the commandline.
140
** The switch -l is recognised separately, and no blank is
141
** inserted between -l and the argument. This is a restriction to
142
** the general usability of this function.
144
static lList *write_defaults_file(
152
lList *answer = NULL;
156
DENTER(BASIS_LAYER, "write_defaults_file");
162
fp = fopen(filename, "w");
164
sprintf(str, MSG_FILE_ERROROPENFILEXFORWRITING_S, filename);
165
answer_list_add(&answer, str, STATUS_EDISK, ANSWER_QUALITY_ERROR);
170
cp = lGetString(ep, SPA_switch);
172
** only real options are written to file
173
** except if the caller asks for full commandline
178
if ((*cp != '-') && !(flags & FLG_FULL_CMDLINE)) {
182
** problem: exception for -l makes this function slightly
183
** less generally appliccable
186
if ((strlen(cp) > 1) && !strncmp(cp, "-l", 2)) {
187
i = fprintf(fp, "%s", cp);
193
i = fprintf(fp, "%s ", cp);
195
if ((*cp == '-') && (i != (int) strlen(cp) + 1)) {
196
sprintf(str, MSG_FILE_ERRORWRITETOFILEX_S, filename);
197
answer_list_add(&answer, str, STATUS_EDISK, ANSWER_QUALITY_ERROR);
204
if (lGetUlong(ep, SPA_occurrence) & BIT_SPA_OCC_ARG) {
205
cp = lGetString(ep, SPA_switch_arg);
207
sprintf(str, MSG_ANSWER_ARGUMENTMISSINGFORX_S ,
208
lGetString(ep, SPA_switch));
209
answer_list_add(&answer, str, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR);
216
i = fprintf(fp, "%s ", cp);
217
if (i != (int) strlen(cp) + 1) {
218
sprintf(str, MSG_FILE_ERRORWRITETOFILEX_S, filename);
219
answer_list_add(&answer, str, STATUS_EDISK, ANSWER_QUALITY_ERROR);
238
answer_list_add_sprintf(&answer, STATUS_EDISK, ANSWER_QUALITY_ERROR,
239
MSG_FILE_ERRORCLOSEINGXY_SS, filename, strerror(errno));
245
#include "sge_all_listsL.h"
246
int main(int argc, char **argv, char **envp);
253
lList *cmdline = NULL;
254
lListElem *job = NULL;
257
u_long32 status = STATUS_OK;
260
DENTER_MAIN(TOP_LAYER, "test_write_defaults");
262
#ifdef __SGE_COMPILE_WITH_GETTEXT__
263
/* init language output for gettext() , it will use the right language */
264
sge_init_language_func((gettext_func_type) gettext,
265
(setlocale_func_type) setlocale,
266
(bindtextdomain_func_type) bindtextdomain,
267
(textdomain_func_type) textdomain);
268
sge_init_language(NULL,NULL);
269
#endif /* __SGE_COMPILE_WITH_GETTEXT__ */
274
alp = cull_parse_cmdline(argv + 1, envp, &cmdline, FLG_USE_PSEUDOS);
276
answer_exit_if_not_recoverable(aep);
277
status = answer_get_status(aep);
278
if ((status != STATUS_OK) && (status != STATUS_EEXIST)) {
279
fprintf(stderr, "%s", lGetString(aep, AN_text));
283
printf("%s\n", lGetString(aep, AN_text));
291
alp = cull_parse_job_parameter(cmdline, &job);
293
answer_exit_if_not_recoverable(aep);
294
status = answer_get_status(aep);
295
if (status != STATUS_OK) {
296
fprintf(stderr, "%s", lGetString(aep, AN_text));
300
printf("%s\n", lGetString(aep, AN_text));
308
alp = write_job_defaults(job, "wdtest.dat", FLG_FULL_CMDLINE);
310
answer_exit_if_not_recoverable(aep);
311
status = answer_get_status(aep);
312
if (status != STATUS_OK) {
313
fprintf(stderr, "%s", lGetString(aep, AN_text));
317
printf("%s\n", lGetString(aep, AN_text));
331
#include "sge_all_listsL.h"
332
int main(int argc, char **argv, char **envp);
343
#ifdef __SGE_COMPILE_WITH_GETTEXT__
344
/* init language output for gettext() , it will use the right language */
345
install_language_func((gettext_func_type) gettext,
346
(setlocale_func_type) setlocale,
347
(bindtextdomain_func_type) bindtextdomain,
348
(textdomain_func_type) textdomain);
349
sge_lang_init(NULL,NULL);
350
#endif /* __SGE_COMPILE_WITH_GETTEXT__ */
355
answer = parse_script_file(*(argv + 1), "", &cmdline, envp, FLG_USE_NO_PSEUDOS);
357
lDumpList(stdout, answer, 0);
360
lDumpList(stdout, cmdline, 4);
362
answer = write_defaults_file(cmdline, NULL, 0);
364
lDumpList(stdout, answer, 0);