Index: /trunk/pbs_drmaa/job.c
===================================================================
--- /trunk/pbs_drmaa/job.c	(revision 33)
+++ /trunk/pbs_drmaa/job.c	(revision 40)
@@ -203,10 +203,19 @@
 
 #ifndef PBS_PROFESSIONAL
-			fsd_log_error(("pbs_statjob error: %d, %s, %s", pbs_errno, pbse_to_txt(pbs_errno), pbs_strerror(pbs_errno)));
+			if ( pbs_errno != PBSE_UNKJOBID )
+				fsd_log_error(("pbs_statjob error: %d, %s, %s", pbs_errno, pbse_to_txt(pbs_errno), pbs_strerror(pbs_errno)));
+			else
+				fsd_log_debug(("pbs_statjob error: %d, %s, %s", pbs_errno, pbse_to_txt(pbs_errno), pbs_strerror(pbs_errno)));
 #else
 #  ifndef PBS_PROFESSIONAL_NO_LOG
-			fsd_log_error(("pbs_statjob error: %d, %s", pbs_errno, pbse_to_txt(pbs_errno)));
+			if ( pbs_errno != PBSE_UNKJOBID )
+				fsd_log_error(("pbs_statjob error: %d, %s", pbs_errno, pbse_to_txt(pbs_errno)));
+			else
+				fsd_log_debug(("pbs_statjob error: %d, %s", pbs_errno, pbse_to_txt(pbs_errno)));
 #  else
-			fsd_log_error(("pbs_statjob error: %d", pbs_errno));
+			if ( pbs_errno != PBSE_UNKJOBID )
+				fsd_log_error(("pbs_statjob error: %d", pbs_errno));
+			else
+				fsd_log_debug(("pbs_statjob error: %d", pbs_errno));
 #  endif
 #endif
@@ -439,5 +448,5 @@
 
 	if( pbssession->pbs_home != NULL && pbssession->super.wait_thread_started )
-		fsd_log_debug(("Job on missing but WT is running. Skipping...")); /* TODO: try to provide implementation that uses accounting/server log files */
+		fsd_log_info(("Job on missing but WT is running. Skipping...")); /* TODO: try to provide implementation that uses accounting/server log files */
 	else
 		pbsdrmaa_job_on_missing_standard( self );	
@@ -460,5 +469,5 @@
 		case FSD_IGNORE_QUEUED_MISSING_JOBS:  missing_mask = 0x13;  break;
 	}
-	fsd_log_debug(( "last job_ps: %s (0x%02x); mask: 0x%02x",
+	fsd_log_info(( "last job_ps: %s (0x%02x); mask: 0x%02x",
 				drmaa_job_ps_to_str(self->state), self->state, missing_mask ));
 
Index: /branches/2.0/.svnignore
===================================================================
--- /branches/2.0/.svnignore	(revision 12)
+++ /branches/2.0/.svnignore	(revision 12)
@@ -0,0 +1,34 @@
+configure
+Makefile.in
+config.log
+scripts
+config.status
+stamp-h1
+config.h
+config.h.in
+drmaa_utils
+libtool
+autom4te.cache
+Makefile
+aclocal.m4
+.libs
+.deps
+pbs_attrib.c
+del_all_jobs
+pbs_drmaa-1.0.2.tar.gz
+pbs_drmaa-1.0.3.tar.gz
+pbs_drmaa
+.svnignore
+configure.ac
+readme.html
+readme.pdf
+readme.tex
+ltsugar.m4
+libtool.m4
+ltversion.m4
+lt~obsolete.m4
+ltoptions.m4
+readme.toc
+readme.out
+readme.aux
+readme.log
Index: /branches/2.0/pbs_drmaa/pbs_drmaa.h
===================================================================
--- /branches/2.0/pbs_drmaa/pbs_drmaa.h	(revision 12)
+++ /branches/2.0/pbs_drmaa/pbs_drmaa.h	(revision 12)
@@ -0,0 +1,120 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2007  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __DRMAA__PBS_DRMAA_H
+#define __DRMAA__PBS_DRMAA_H
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include <time.h>
+#include <pbs_ifl.h>
+
+#include <drmaa_utils/common.h>
+#include <pbs_drmaa/pbs_attrib.h>
+
+
+/** PBS DRMAA specific session data. */
+struct drmaa_session_impl_s {
+	int                 pbs_conn;    /**< PBS connection (or -1). */
+	drmaa_mutex_t       conn_mutex;  /**< Mutex for PBS connection. */
+	drmaa_thread_t      wait_thread;
+	bool                wait_thread_started;
+	struct attrl       *status_attrl;
+};
+
+
+enum { PBS_ATTRIBS_BITSET_SIZE = (N_PBS_DRMAA_ATTRIBS+31) / 32 };
+struct drmaa_submit_impl_s {
+	struct attrl *pbs_attribs;
+	uint32_t pbs_attribs_bitset[ PBS_ATTRIBS_BITSET_SIZE ];
+	char *script_filename;
+};
+
+
+void *
+drmaa_wait_thread( void *arg );
+
+drmaa_submit_ctx_t *
+drmaa_create_submission_context(
+		const drmaa_job_template_t *jt, int bulk_no,
+		drmaa_err_ctx_t *err
+		);
+
+void
+drmaa_free_submission_context( drmaa_submit_ctx_t *c, drmaa_err_ctx_t* );
+
+void drmaa_set_job_defaults        ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_create_job_script       ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_job_submit_state    ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_job_files           ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_file_staging        ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_job_resources       ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_job_environment     ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_job_email_notif     ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_apply_native_spec       ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_apply_job_category      ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+char *drmaa_translate_staging( const char *stage, drmaa_err_ctx_t* );
+
+void
+drmaa_parse_qsub_args(
+		drmaa_submit_ctx_t *ctx, const char *string,
+		drmaa_err_ctx_t *err
+		);
+
+void
+drmaa_job_missing( drmaa_job_t *job, drmaa_err_ctx_t *err );
+
+void
+drmaa_add_pbs_attr(
+		drmaa_submit_ctx_t *c,
+		int attr, char *resource, char *value,
+		unsigned set,
+		drmaa_err_ctx_t *err
+		);
+
+char *
+drmaa_write_tmpfile(
+	 const char *content, size_t len,
+	 drmaa_err_ctx_t *err
+	 );
+
+struct attrl *
+drmaa_create_pbs_attrl( drmaa_err_ctx_t *err );
+
+void
+drmaa_log_attrl( const struct attrl *attribute_list, const char *prefix );
+
+void
+drmaa_free_attrl( struct attrl *attr );
+
+void
+drmaa_err_pbs_error( drmaa_err_ctx_t *err );
+
+int
+drmaa_err_map_pbs_error( int pbs_errcode );
+
+#define RAISE_PBS() \
+	drmaa_err_pbs_error( err )
+
+#endif /* __DRMAA__PBS_DRMAA_H */
+
Index: /branches/2.0/pbs_drmaa/pbs_attrib.h
===================================================================
--- /branches/2.0/pbs_drmaa/pbs_attrib.h	(revision 12)
+++ /branches/2.0/pbs_drmaa/pbs_attrib.h	(revision 12)
@@ -0,0 +1,198 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2009  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __PBS_DRMAA__PBS_ATTRIB_H
+#define __PBS_DRMAA__PBS_ATTRIB_H
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <drmaa_utils/common.h>
+
+fsd_template_t *pbsdrmaa_pbs_template_new(void);
+int pbsdrmaa_pbs_attrib_by_name( const char *name );
+
+#define PBSDRMAA_EXECUTION_TIME         "Execution_Time"
+#define PBSDRMAA_CHECKPOINT             "Checkpoint"
+#define PBSDRMAA_ERROR_PATH             "Error_Path"
+#define PBSDRMAA_GROUPS                 "group_list"
+#define PBSDRMAA_HOLD_TYPES             "Hold_Types"
+#define PBSDRMAA_JOIN_FILES             "Join_Path"
+#define PBSDRMAA_KEEP_FILES             "Keep_Files"
+/* #define PBSDRMAA_RESOURCES              "Resource_List" */
+#define PBSDRMAA_CPU_TIME_LIMIT         "Resource_List.cput"
+#define PBSDRMAA_FILE_SIZE_LIMIT        "Resource_List.file"
+#define PBSDRMAA_NICE                   "Resource_List.nice"
+#define PBSDRMAA_MEM_LIMIT              "Resource_List.mem"
+#define PBSDRMAA_VMEM_LIMIT             "Resource_List.vmem"
+#define PBSDRMAA_SINGLE_CPU_TIME_LIMIT  "Resource_List.pcput"
+#define PBSDRMAA_SINGLE_RSS_LIMIT       "Resource_List.pmem"
+#define PBSDRMAA_SINGLE_VMEM_LIMIT      "Resource_List.pvmem"
+#define PBSDRMAA_WALLTIME_LIMIT         "Resource_List.walltime"
+#define PBSDRMAA_ARCHITECTURE           "Resource_List.arch"
+#define PBSDRMAA_HOST                   "Resource_List.host"
+#define PBSDRMAA_NODES                  "Resource_List.nodes"
+#define PBSDRMAA_SOFTWARE               "Resource_List.software"
+#define PBSDRMAA_MAIL_POINTS            "Mail_Points"
+#define PBSDRMAA_OUTPUT_PATH            "Output_Path"
+#define PBSDRMAA_PRIORITY               "Priority"
+#define PBSDRMAA_DESITINATION           "destination"
+#define PBSDRMAA_RERUNABLE              "Rerunable"
+#define PBSDRMAA_BULK_REQ               "job_array_request"
+#define PBSDRMAA_BULK_IDX               "job_array_id"
+#define PBSDRMAA_USERS                  "User_List"
+#define PBSDRMAA_JOB_ENVIRONMENT        "Variable_List"
+#define PBSDRMAA_ACCOUNT_NAME           "Account_Name"
+#define PBSDRMAA_EMAIL                  "Mail_Users"
+#define PBSDRMAA_JOB_NAME               "Job_Name"
+#define PBSDRMAA_SHELL                  "Shell_Path_List"
+#define PBSDRMAA_DEPEND                 "depend"
+#define PBSDRMAA_INTERACTIVE            "interactive"
+#define PBSDRMAA_STAGEIN                "stagein"
+#define PBSDRMAA_STAGEOUT               "stageout"
+/* additional job and general attribute names */
+#define PBSDRMAA_EXECUTION_HOST         "exec_host"
+#define PBSDRMAA_JOB_OWNER              "Job_Owner"
+#define PBSDRMAA_RESOURCES_USED         "resources_used"
+#define PBSDRMAA_JOB_STATE              "job_state"
+#define PBSDRMAA_QUEUE                  "queue"
+#define PBSDRMAA_SERVER                 "server"
+#define PBSDRMAA_COMMENT                "comment"
+#define PBSDRMAA_EXIT_STATUS            "exit_status"
+#define PBSDRMAA_START_TIME             "start_time"
+#define PBSDRMAA_EXTENSION              "extension"
+#define PBSDRMAA_SUBMIT_ARGS		"submit_args"
+
+
+typedef enum {
+	PBSDRMAA_ATTR_EXECUTION_TIME,
+	PBSDRMAA_ATTR_CHECKPOINT,
+	PBSDRMAA_ATTR_ERROR_PATH,
+	PBSDRMAA_ATTR_GROUPS,
+	PBSDRMAA_ATTR_HOLD_TYPES,
+	PBSDRMAA_ATTR_JOIN_FILES,
+	PBSDRMAA_ATTR_KEEP_FILES,
+	/* PBSDRMAA_ATTR_RESOURCES, */
+	PBSDRMAA_ATTR_CPU_TIME_LIMIT,
+	PBSDRMAA_ATTR_FILE_SIZE_LIMIT,
+	PBSDRMAA_ATTR_NICE,
+	PBSDRMAA_ATTR_VMEM_LIMIT,
+	PBSDRMAA_ATTR_MEM_LIMIT,
+	PBSDRMAA_ATTR_SINGLE_CPU_TIME_LIMIT,
+	PBSDRMAA_ATTR_SINGLE_RSS_LIMIT,
+	PBSDRMAA_ATTR_SINGLE_VMEM_LIMIT,
+	PBSDRMAA_ATTR_WALLTIME_LIMIT,
+	PBSDRMAA_ATTR_ARCHITECTURE,
+	PBSDRMAA_ATTR_HOST,
+	PBSDRMAA_ATTR_NODES,
+	PBSDRMAA_ATTR_SOFTWARE,
+	PBSDRMAA_ATTR_MAIL_POINTS,
+	PBSDRMAA_ATTR_OUTPUT_PATH,
+	PBSDRMAA_ATTR_PRIORITY,
+	PBSDRMAA_ATTR_DESITINATION,
+	PBSDRMAA_ATTR_RERUNABLE,
+	PBSDRMAA_ATTR_BULK_REQ,
+	PBSDRMAA_ATTR_BULK_IDX,
+	PBSDRMAA_ATTR_USERS,
+	PBSDRMAA_ATTR_JOB_ENVIRONMENT,
+	PBSDRMAA_ATTR_ACCOUNT_NAME,
+	PBSDRMAA_ATTR_EMAIL,
+	PBSDRMAA_ATTR_JOB_NAME,
+	PBSDRMAA_ATTR_SHELL,
+	PBSDRMAA_ATTR_DEPEND,
+	PBSDRMAA_ATTR_INTERACTIVE,
+	PBSDRMAA_ATTR_STAGEIN,
+	PBSDRMAA_ATTR_STAGEOUT,
+	/* additional job and general attribute names */
+	PBSDRMAA_ATTR_EXECUTION_HOST,
+	PBSDRMAA_ATTR_JOB_OWNER,
+	PBSDRMAA_ATTR_RESOURCES_USED,
+	PBSDRMAA_ATTR_JOB_STATE,
+	PBSDRMAA_ATTR_QUEUE,
+	PBSDRMAA_ATTR_SERVER,
+	PBSDRMAA_ATTR_COMMENT,
+	PBSDRMAA_ATTR_EXIT_STATUS,
+	PBSDRMAA_ATTR_START_TIME,
+	PBSDRMAA_ATTR_EXTENSION,
+	PBSDRMAA_ATTR_SUBMIT_ARGS,
+	PBSDRMAA_ATTR_MTIME,
+
+#if 0
+	/* Additional Torque/OpenPBS attribs (not in DRMAA specification): */
+	/* Used by OpenPBS user commands: */
+	PBSDRMAA_ATTR_CHECKPOINT = DRMAA_N_ATTRIBUTES, /* MAX_DRMAA_ATTR+1, */
+	PBSDRMAA_ATTR_GROUP_LIST,
+	PBSDRMAA_ATTR_HOLD_TYPES,
+	PBSDRMAA_ATTR_KEEP_FILES,
+	PBSDRMAA_ATTR_RESOURCES,
+	PBSDRMAA_ATTR_MAIL_POINTS,
+	PBSDRMAA_ATTR_PRIORITY,
+	PBSDRMAA_ATTR_DESTINATION_QUEUE,
+	PBSDRMAA_ATTR_RERUNABLE,
+	PBSDRMAA_ATTR_USER_LIST,
+	PBSDRMAA_ATTR_ACCOUNT_NAME,
+	PBSDRMAA_ATTR_SHELL,
+	PBSDRMAA_ATTR_DEPENDENCIES,
+	PBSDRMAA_ATTR_INTERACTIVE,
+	PBSDRMAA_ATTR_STAGEIN,
+	PBSDRMAA_ATTR_STAGEOUT,
+
+	/* Additional job and general attribute names: */
+	PBSDRMAA_ATTR_JOB_STATE,
+	PBSDRMAA_ATTR_CTIME,
+	/* PBSDRMAA_ATTR_MTIME, moved to basic attributes - needed to determine job end time*/
+	PBSDRMAA_ATTR_QTIME,
+	PBSDRMAA_ATTR_ETIME,
+	PBSDRMAA_ATTR_RESOURCES_USED,
+	PBSDRMAA_ATTR_EXIT_STATUS,
+	PBSDRMAA_ATTR_JOB_OWNER,
+	PBSDRMAA_ATTR_EUSER,
+	PBSDRMAA_ATTR_EGROUP,
+	PBSDRMAA_ATTR_HOP_COUNT,
+	PBSDRMAA_ATTR_SECURITY,
+	PBSDRMAA_ATTR_SCHEDULER_HINT,
+	PBSDRMAA_ATTR_SERVER,
+	PBSDRMAA_ATTR_QUEUE,
+	PBSDRMAA_ATTR_QUEUE_RANK,
+	PBSDRMAA_ATTR_EXECUTION_HOST,
+	PBSDRMAA_ATTR_TOTAL_JOBS,
+	PBSDRMAA_ATTR_MAX_RUNNING,
+	PBSDRMAA_ATTR_COMMENT,
+	PBSDRMAA_ATTR_JOB_COOKIE,
+	PBSDRMAA_ATTR_HASHNAME,
+	PBSDRMAA_ATTR_SESSION_ID,
+	PBSDRMAA_ATTR_ALT_ID,
+
+	/* Reservation attributes */
+	PBSDRMAA_ATTR_RESERVATION_START,
+	PBSDRMAA_ATTR_RESERVATION_END,
+	PBSDRMAA_ATTR_RESERVATION_DURATION,
+	PBSDRMAA_ATTR_RESERVATION_STATE,
+	PBSDRMAA_ATTR_RESERVATION_SUBSTATE,
+
+	/* Pseudo PBS attributes */
+	PBSDRMAA_ATTR_RESERVATION_ID,
+#endif
+
+	PBSDRMAA_N_PBS_ATTRIBUTES
+} pbs_attribute_t;
+
+#endif /* __PBS_DRMAA__PBS_ATTRIB_H */
+
Index: /branches/2.0/pbs_drmaa/log_reader.c
===================================================================
--- /branches/2.0/pbs_drmaa/log_reader.c	(revision 20)
+++ /branches/2.0/pbs_drmaa/log_reader.c	(revision 20)
@@ -0,0 +1,771 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2007  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+ #ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/select.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <fcntl.h>
+
+#include <pbs_ifl.h>
+#include <pbs_error.h>
+
+#include <drmaa_utils/datetime.h>
+#include <drmaa_utils/drmaa.h>
+#include <drmaa_utils/iter.h>
+#include <drmaa_utils/conf.h>
+#include <drmaa_utils/session.h>
+#include <drmaa_utils/datetime.h>
+
+#include <pbs_drmaa/job.h>
+#include <pbs_drmaa/log_reader.h>
+#include <pbs_drmaa/session.h>
+#include <pbs_drmaa/submit.h>
+#include <pbs_drmaa/util.h>
+
+#include <errno.h>
+
+static void
+pbsdrmaa_read_log();
+
+static void
+pbsdrmaa_select_file_wait_thread ( pbsdrmaa_log_reader_t * self);
+
+static ssize_t
+pbsdrmaa_read_line_wait_thread ( pbsdrmaa_log_reader_t * self, char * line, char * buffer, ssize_t size, int * idx, int * end_idx, int * line_idx );
+
+static void
+pbsdrmaa_select_file_job_on_missing ( pbsdrmaa_log_reader_t * self );
+
+static ssize_t
+pbsdrmaa_read_line_job_on_missing ( pbsdrmaa_log_reader_t * self, char * line, char * buffer, ssize_t size, int * idx, int * end_idx, int * line_idx );
+
+int 
+fsd_job_id_cmp(const char *s1, const char *s2);
+
+int 
+pbsdrmaa_date_compare(const void *a, const void *b) ;
+
+pbsdrmaa_log_reader_t * 
+pbsdrmaa_log_reader_new ( fsd_drmaa_session_t *session, fsd_job_t *job )
+{
+	pbsdrmaa_log_reader_t *volatile self = NULL;
+
+	fsd_log_enter((""));
+	TRY
+	{
+		fsd_malloc(self, pbsdrmaa_log_reader_t );
+		
+		self->session = session;
+		
+		/* ~templete method pattern */
+		if(job != NULL) /* job on missing */
+		{
+			self->job = job;
+			self->name = "Job_on_missing";
+			self->select_file = pbsdrmaa_select_file_job_on_missing;
+			self->read_line = pbsdrmaa_read_line_job_on_missing;
+		}
+		else /* wait thread */
+		{
+			self->job = NULL;
+			self->name = "WT";
+			self->select_file = pbsdrmaa_select_file_wait_thread;
+			self->read_line = pbsdrmaa_read_line_wait_thread;
+		}		
+		self->read_log = pbsdrmaa_read_log;	
+		
+		self->log_files = NULL;
+		self->log_files_number = 0;
+		
+		self->run_flag = true;
+		self->fd = -1;
+		self->date_changed = true;
+		self->first_open = true;
+		
+		self->log_file_initial_size = 0;
+		self->log_file_read_size = 0;
+	}
+	EXCEPT_DEFAULT
+	{
+		if( self != NULL)
+			fsd_free(self);
+			
+		fsd_exc_reraise();
+	}
+	END_TRY
+	fsd_log_return((""));
+	return self;
+}
+
+void
+pbsdrmaa_log_reader_destroy ( pbsdrmaa_log_reader_t * self )
+{
+	fsd_log_enter((""));
+	TRY
+	{
+		if(self != NULL)
+		{
+			int i = -1;
+			for(i = 0; i < self->log_files_number ; i++)
+				fsd_free(self->log_files[i]);
+			fsd_free(self->log_files);
+			fsd_free(self);	
+		}			
+	}
+	EXCEPT_DEFAULT
+	{
+		fsd_exc_reraise();
+	}
+	END_TRY
+	
+	fsd_log_return((""));
+}
+
+enum field
+{ 
+	FLD_DATE = 0,
+	FLD_EVENT = 1,
+	FLD_OBJ = 2,
+	FLD_TYPE = 3,
+	FLD_ID = 4,
+	FLD_MSG = 5
+};
+
+enum field_msg
+{
+	FLD_MSG_EXIT_STATUS = 0,
+	FLD_MSG_CPUT = 1,
+	FLD_MSG_MEM = 2,
+	FLD_MSG_VMEM = 3,
+	FLD_MSG_WALLTIME = 4
+};
+
+#define FLD_MSG_STATUS "0010"
+#define FLD_MSG_STATE "0008"
+#define FLD_MSG_LOG "0002"
+
+void 
+pbsdrmaa_read_log( pbsdrmaa_log_reader_t * self )
+{
+	pbsdrmaa_job_t *pbsjob = (pbsdrmaa_job_t*) self->job;	
+	fsd_job_t *volatile temp_job = NULL;
+		
+	fsd_log_enter((""));
+	
+	if(self->job == NULL)
+		fsd_mutex_lock( &self->session->mutex );
+
+	TRY
+	{		
+		while( self->run_flag )
+		TRY
+		{
+			char line[4096] = "";
+			char buffer[4096] = "";
+			int idx = 0, end_idx = 0, line_idx = 0;
+			
+			self->select_file(self);
+
+			while ((self->read_line(self, line,buffer, sizeof(line), &idx,&end_idx,&line_idx)) > 0) 			
+			{
+				const char *volatile ptr = line;
+  				char field[256] = "";
+				char job_id[256] = "";
+				char event[256] = "";
+				int volatile field_n = 0;
+ 				int n;
+				
+				bool volatile job_id_match = false;
+				bool volatile event_match = false;
+				bool volatile log_event = false;
+				bool volatile log_match = false;
+				bool volatile older_job_found = false;
+				bool volatile job_found = false;
+  				char *  temp_date = NULL;
+				
+				struct batch_status status;
+				status.next = NULL;
+
+				while ( sscanf(ptr, "%255[^;]%n", field, &n) == 1 ) /* split current line into fields */
+				{
+					if(field_n == FLD_DATE)
+					{
+						temp_date = fsd_strdup(field);
+					}
+					else if(field_n == FLD_EVENT && (strcmp(field,FLD_MSG_STATUS) == 0 || 
+						     		    strcmp(field,FLD_MSG_STATE) == 0 ))
+					{
+						/* event described by log line*/
+						if(strlcpy(event, field,sizeof(event)) > sizeof(event)) {
+							fsd_log_error(("%s - strlcpy error",self->name));
+						}
+						event_match = true;									
+					}
+					else if(event_match && field_n == FLD_ID)
+					{	
+						TRY
+						{	
+							if(self->job == NULL) /* wait_thread */
+							{
+								temp_job = self->session->get_job( self->session, field );
+								pbsjob = (pbsdrmaa_job_t*) temp_job;
+
+								if( temp_job )
+								{
+									if(strlcpy(job_id, field,sizeof(job_id)) > sizeof(job_id)) {
+										fsd_log_error(("%s - strlcpy error",self->name));
+									}
+									fsd_log_debug(("%s - job_id: %s",self->name,job_id));
+									status.name = fsd_strdup(job_id);
+									job_id_match = true; /* job_id is in drmaa */	
+								}
+								else 
+								{
+									fsd_log_debug(("%s - Unknown job: %s", self->name,field));
+								}
+							}
+							else /* job_on_missing */
+							{
+								int diff = -1;
+								diff = fsd_job_id_cmp(self->job->job_id,field);
+								if( diff == 0)
+								{
+									/* read this file to the place we started and exit*/
+									fsd_log_debug(("Job_on_missing found job: %s",self->job->job_id));
+									job_found = true;
+									older_job_found = false;
+									self->run_flag = false;
+									job_id_match = true; 
+									status.name = fsd_strdup(self->job->job_id);									
+								}
+								else if ( !job_found && diff >= 1)
+								{
+									/* older job, find its beginning */
+									fsd_log_debug(("Job_on_missing found older job than %s : %s",self->job->job_id,field));
+									older_job_found = true;
+									job_id_match = true; 
+									status.name = fsd_strdup(self->job->job_id);
+								}
+								else  if( !job_found )
+								{
+									fsd_log_debug(("Job_on_missing found newer job than %s : %s",self->job->job_id,field));
+								}								
+							}
+						}
+						END_TRY	
+					}
+					else if(job_id_match && field_n == FLD_MSG)
+					{						
+						/* parse msg - depends on FLD_EVENT */
+						struct attrl struct_resource_cput,struct_resource_mem,struct_resource_vmem,
+							struct_resource_walltime, struct_status, struct_state, struct_start_time,struct_mtime, struct_queue, struct_account_name;	
+						
+						bool state_running = false;
+
+						memset(&struct_status,0,sizeof(struct attrl)); /**/
+						memset(&struct_state,0,sizeof(struct attrl));
+						memset(&struct_resource_cput,0,sizeof(struct attrl));
+						memset(&struct_resource_mem,0,sizeof(struct attrl));
+						memset(&struct_resource_vmem,0,sizeof(struct attrl));
+						memset(&struct_resource_walltime,0,sizeof(struct attrl));
+						memset(&struct_start_time,0,sizeof(struct attrl));
+						memset(&struct_mtime,0,sizeof(struct attrl));
+						memset(&struct_queue,0,sizeof(struct attrl));
+						memset(&struct_account_name,0,sizeof(struct attrl));
+								
+						if (strcmp(event,FLD_MSG_STATE) == 0) 
+						{
+							/* job run, modified, queued etc */
+							int n = 0;
+							status.attribs = &struct_state;
+							struct_state.next = NULL;
+							struct_state.name = "job_state";
+							if(field[0] == 'J') /* Job Queued, Job Modified, Job Run*/
+							{
+								n = 4;
+								if(older_job_found) /* job_on_missing - older job beginning - read this file and end */
+								{
+									self->run_flag = false;
+									fsd_log_debug(("Job_on_missing found older job beginning"));
+									fsd_free(status.name);
+									break;
+								}
+							}		
+							if(field[4] == 'M') { /* modified */
+								struct tm temp_time_tm;
+								memset(&temp_time_tm, 0, sizeof(temp_time_tm));
+								temp_time_tm.tm_isdst = -1;
+
+								if (strptime(temp_date, "%m/%d/%Y %H:%M:%S", &temp_time_tm) == NULL) 
+								 {
+								 	fsd_log_error(("failed to parse mtime: %s", temp_date));
+								 }
+								else
+								 {
+									time_t temp_time = mktime(&temp_time_tm);
+									status.attribs = &struct_mtime; 
+									struct_mtime.name = "mtime";
+									struct_mtime.next = NULL;
+									struct_mtime.value = fsd_asprintf("%lu",temp_time);
+								 }
+							}		
+							/* != Job deleted and Job to be deleted*/
+							#ifdef PBS_PROFESSIONAL
+							else if	(field[4] != 't' && field[10] != 'd') {
+							#else	 	
+							else if(field[4] != 'd') {
+							#endif 
+
+								if ((struct_state.value = fsd_asprintf("%c",field[n]) ) == NULL ) { /* 4 first letter of state */
+									fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"%s - Memory allocation wasn't possible",self->name);
+								}
+								if(struct_state.value[0] == 'R'){
+									state_running = true;
+								}
+							}
+							else { /* job terminated - pbs drmaa detects failed as completed with exit_status !=0, aborted with status -1*/
+								struct_status.name = "exit_status";
+								struct_status.value = fsd_strdup("-1");
+								struct_status.next = NULL;
+								struct_state.next = &struct_status;
+								struct_state.value = fsd_strdup("C");								
+							}
+						} 						     
+						else /*if (strcmp(event,FLD_MSG_STATUS) == 0 )*/
+						{
+							/* exit status and rusage */
+							const char *ptr2 = field;
+							char  msg[ 256 ] = "";
+							int n2;
+							int msg_field_n = 0;
+							
+							struct_resource_cput.name = "resources_used";
+							struct_resource_mem.name = "resources_used";
+							struct_resource_vmem.name = "resources_used";
+							struct_resource_walltime.name = "resources_used";
+							struct_status.name = "exit_status";
+							struct_state.name = "job_state";
+				
+							status.attribs = &struct_resource_cput;
+							struct_resource_cput.next = &struct_resource_mem;
+							struct_resource_mem.next = &struct_resource_vmem;
+							struct_resource_vmem.next = &struct_resource_walltime;
+							struct_resource_walltime.next =  &struct_status;
+							struct_status.next = &struct_state;
+							struct_state.next = NULL;
+
+							while ( sscanf(ptr2, "%255[^ ]%n", msg, &n2) == 1 )
+							 {						
+								switch(msg_field_n) 
+								{
+									case FLD_MSG_EXIT_STATUS:
+										struct_status.value = fsd_strdup(strchr(msg,'=')+1);
+										break;
+
+									case FLD_MSG_CPUT:
+										struct_resource_cput.resource = "cput";
+										struct_resource_cput.value = fsd_strdup(strchr(msg,'=')+1);
+										break;
+
+									case FLD_MSG_MEM:
+										struct_resource_mem.resource = "mem";
+										struct_resource_mem.value  = fsd_strdup(strchr(msg,'=')+1);
+										break;
+
+									case FLD_MSG_VMEM:
+										struct_resource_vmem.resource = "vmem";
+										struct_resource_vmem.value  = fsd_strdup(strchr(msg,'=')+1);
+										break; 
+
+									case FLD_MSG_WALLTIME:
+										struct_resource_walltime.resource = "walltime";
+										struct_resource_walltime.value  = fsd_strdup(strchr(msg,'=')+1);
+										break; 
+								}
+							      
+								ptr2 += n2; 
+								msg_field_n++;
+								if ( *ptr2 != ' ' )
+							      	 {
+									 break; 
+							  	 }
+							 	++ptr2;						
+							 }
+							struct_state.value = fsd_strdup("C");	/* we got exit_status so we say that it has completed */
+							fsd_log_info(("WT - job %s found as finished on %u", temp_job->job_id, (unsigned int)time(NULL)));
+						}						
+						 
+						if(self->job == NULL) /* wait_thread */
+						{ 
+							if ( state_running )
+							{
+								fsd_log_debug(("WT - forcing update of job: %s", temp_job->job_id ));
+								TRY
+								{
+									temp_job->update_status( temp_job );
+								}
+								EXCEPT_DEFAULT
+								{
+									/*TODO: distinguish between invalid job and internal errors */
+									fsd_log_debug(("Job finished just after entering running state: %s", temp_job->job_id));
+								}
+								END_TRY
+							}
+							else
+							{
+								fsd_log_debug(("%s - updating job: %s",self->name, temp_job->job_id ));							
+								pbsjob->update( temp_job, &status );
+							}
+						 }
+						 else if( job_found ) /* job_on_missing */
+						 {
+							fsd_log_debug(("Job_on_missing - updating job: %s", self->job->job_id ));							
+							pbsjob->update( self->job, &status );
+						 }
+						
+						if(self->job == NULL)
+						{
+							fsd_cond_broadcast( &temp_job->status_cond);
+							fsd_cond_broadcast( &self->session->wait_condition );
+						}
+						if ( temp_job )
+							temp_job->release( temp_job );
+	
+						fsd_free(struct_resource_cput.value);
+						fsd_free(struct_resource_mem.value);
+						fsd_free(struct_resource_vmem.value);
+						fsd_free(struct_resource_walltime.value);
+						fsd_free(struct_status.value);
+						fsd_free(struct_state.value);
+						fsd_free(struct_start_time.value);
+						fsd_free(struct_mtime.value);
+						fsd_free(struct_queue.value);
+						fsd_free(struct_account_name.value);
+
+						if ( status.name!=NULL ) 
+							fsd_free(status.name);
+					}
+					else if(field_n == FLD_EVENT && strcmp(field,FLD_MSG_LOG) == 0)
+					{
+						log_event = true;					
+					}
+					else if (log_event && field_n == FLD_ID && strcmp(field,"Log") == 0 )
+					{
+						log_match = true;
+						log_event = false;
+					}
+					else if( self->job == NULL && log_match && field_n == FLD_MSG && strncmp(field,"Log closed",10) == 0) 
+					{
+						fsd_log_debug(("%s - Date changed. Closing log file",self->name));
+						self->date_changed = true;
+						log_match = false;
+					}
+					
+					ptr += n; 
+					if ( *ptr != ';' )
+					{
+						break; /* end of line */
+					}
+					field_n++;
+					++ptr;
+				}		
+
+				fsd_free(temp_date);			
+			} /* end of while getline loop */			
+			
+			if(self->job == NULL)
+			{
+				struct timeval timeout_tv;
+				fd_set log_fds;
+	
+				fsd_mutex_unlock( &self->session->mutex );			
+				
+				FD_ZERO(&log_fds);
+    				FD_SET(self->fd, &log_fds);
+
+				timeout_tv.tv_sec = 1;
+    				timeout_tv.tv_usec = 0;
+
+				/* ignore return value - the next get line call will handle IO errors */
+				(void)select(1, &log_fds, NULL, NULL, &timeout_tv);
+
+				fsd_mutex_lock( &self->session->mutex );	
+
+				self->run_flag = self->session->wait_thread_run_flag;
+			}
+		}		
+		EXCEPT_DEFAULT
+		 {
+			const fsd_exc_t *e = fsd_exc_get();
+			/* Its better to exit and communicate error rather then let the application to hang */
+			fsd_log_fatal(( "Exception in wait thread %s: <%d:%s>. Exiting !!!", self->name, e->code(e), e->message(e) ));
+			exit(1);
+		 }
+		END_TRY
+
+		if(self->fd != -1)
+			close(self->fd);
+		fsd_log_debug(("%s - Log file closed",self->name));	
+	}
+	FINALLY
+	{
+	 	fsd_log_debug(("%s - Terminated.",self->name));	
+		if(self->job == NULL)
+			fsd_mutex_unlock( &self->session->mutex ); /**/
+	}
+	END_TRY
+	
+	fsd_log_return((""));
+}
+
+void
+pbsdrmaa_select_file_wait_thread ( pbsdrmaa_log_reader_t * self )
+{
+	pbsdrmaa_session_t *pbssession = (pbsdrmaa_session_t*) self->session;
+	
+	if(self->date_changed)
+	{
+		char * log_path = NULL;
+		int num_tries = 0;
+		struct tm tm; 
+		
+		fsd_log_enter((""));
+		
+		if(!self->first_open)
+			time(&self->t);	
+		else
+			self->t = pbssession->log_file_initial_time;
+			
+		localtime_r(&self->t,&tm);
+				
+		#define DRMAA_WAIT_THREAD_MAX_TRIES (12)
+		/* generate new date, close file and open new */
+		if((log_path = fsd_asprintf("%s/server_logs/%04d%02d%02d",
+					pbssession->pbs_home,	 
+					tm.tm_year + 1900,
+					tm.tm_mon + 1,
+					tm.tm_mday)) == NULL) {
+			fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"WT - Memory allocation wasn't possible");
+		}
+
+		if(self->fd != -1)
+			close(self->fd);
+
+		fsd_log_debug(("Log file: %s",log_path));
+				
+	retry:
+		if((self->fd = open(log_path,O_RDONLY) ) == -1 && num_tries > DRMAA_WAIT_THREAD_MAX_TRIES )
+		{
+			fsd_log_error(("Can't open log file. Verify pbs_home. Running standard wait_thread."));
+			fsd_log_error(("Remember that without keep_completed set standard wait_thread won't run correctly"));
+			/*pbssession->super.enable_wait_thread = false;*/ /* run not wait_thread */
+			pbssession->wait_thread_log = false;
+			pbssession->super.wait_thread = pbssession->super_wait_thread;
+			pbssession->super.wait_thread(self->session);
+		} else if ( self->fd == -1 ) {
+			fsd_log_warning(("Can't open log file: %s. Retries count: %d", log_path, num_tries));
+			num_tries++;
+			sleep(5);
+			goto retry;
+		}
+
+		fsd_free(log_path);
+
+		fsd_log_debug(("Log file opened"));
+
+		if(self->first_open) {
+			fsd_log_debug(("Log file lseek"));
+			if(lseek(self->fd,pbssession->log_file_initial_size,SEEK_SET) == (off_t) -1) {
+				char errbuf[256] = "InternalError";
+				(void)strerror_r(errno, errbuf, 256);
+				fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"lseek error: %s",errbuf);
+			}
+			self->first_open = false;
+		}
+
+		self->date_changed = false;
+		
+		fsd_log_return((""));
+	}	
+}
+
+ssize_t
+pbsdrmaa_read_line_wait_thread ( pbsdrmaa_log_reader_t * self, char * line, char * buffer, ssize_t size, int * idx, int * end_idx, int * line_idx )
+{
+	return fsd_getline_buffered(line,buffer,size,self->fd,idx,end_idx,line_idx);
+}
+
+/* reverse date compare*/
+int 
+pbsdrmaa_date_compare(const void *a, const void *b) 
+{
+   const char *ia = *(const char **) a;
+   const char *ib = *(const char **) b;
+   return strcmp(ib, ia);
+}
+
+void
+pbsdrmaa_select_file_job_on_missing( pbsdrmaa_log_reader_t * self )
+{
+	pbsdrmaa_session_t *pbssession = (pbsdrmaa_session_t*) self->session;	
+	
+	char * log_path = NULL;
+	int num_tries = 0;
+	static int file_number = 0;
+	fsd_log_enter((""));
+		
+	if(self->first_open) 
+	{			
+		DIR *dp = NULL;		
+		char * path = NULL;
+		struct dirent *ep = NULL;
+		
+		if((path = fsd_asprintf("%s/server_logs/",pbssession->pbs_home)) == NULL)
+			fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"Job_on_missing - Memory allocation wasn't possible");
+		
+		self->log_files_number = 0;     
+		dp = opendir (path);
+
+		fsd_calloc(self->log_files,2,char*);
+  	
+		if (dp != NULL)
+		{
+			while ((ep = readdir (dp)))
+			{
+				self->log_files_number++;
+				if(self->log_files_number > 2)
+					fsd_realloc(self->log_files,self->log_files_number,char *);
+				
+				self->log_files[self->log_files_number-1] = fsd_strdup(ep->d_name);
+			}
+			(void) closedir (dp);
+		}
+		else
+			fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"Job_on_missing - Couldn't open the directory");
+
+		qsort(self->log_files,self->log_files_number,sizeof(char *),pbsdrmaa_date_compare);
+		
+		if(self->log_files_number <= 2)
+		{
+			self->run_flag = false;
+			fsd_log_error(("Job_on_missing - No log files available"));
+		}
+		
+		self->first_open = false;
+		fsd_free(path);
+	}	
+	else /* check previous day*/
+	{
+		if(++file_number > self->log_files_number - 2)
+			fsd_log_error(("Job_on_missing - All available log files checked"));
+		else
+			fsd_log_debug(("Job_on_missing checking previous day"));
+		
+		self->run_flag = false;
+		pbsdrmaa_job_on_missing_standard( self->job );				
+	}
+	
+	#define DRMAA_WAIT_THREAD_MAX_TRIES (12)
+	if((log_path = fsd_asprintf("%s/server_logs/%s",
+				pbssession->pbs_home,	 
+				self->log_files[file_number])) == NULL) {
+		fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"Job_on_missing - Memory allocation wasn't possible");
+	}
+
+	if(self->fd != -1)
+		close(self->fd);
+
+	fsd_log_debug(("Log file: %s",log_path));
+				
+retry:
+	if((self->fd = open(log_path,O_RDONLY) ) == -1 && num_tries > DRMAA_WAIT_THREAD_MAX_TRIES )
+	{
+		fsd_log_error(("Can't open log file. Verify pbs_home. Running standard job_on_missing"));
+		fsd_log_error(("Remember that without keep_completed set standard job_on_missing won't run correctly"));
+		self->run_flag = false;
+		pbsdrmaa_job_on_missing_standard( self->job );			
+	} else if ( self->fd == -1 ) {
+		fsd_log_warning(("Can't open log file: %s. Retries count: %d", log_path, num_tries));
+		num_tries++;
+		sleep(5);
+		goto retry;
+	}
+	else
+	{
+		struct stat statbuf;
+		if(stat(log_path,&statbuf) == -1) {
+				char errbuf[256] = "InternalError";
+				(void)strerror_r(errno, errbuf, 256);
+				fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"stat error: %s",errbuf);
+		}
+		self->log_file_read_size = 0;
+		self->log_file_initial_size = statbuf.st_size;
+		fsd_log_debug(("Set log_file_initial_size %ld",self->log_file_initial_size));
+	}
+
+	fsd_free(log_path);
+
+	fsd_log_debug(("Log file opened"));
+	
+	fsd_log_return((""));
+}
+
+ssize_t
+pbsdrmaa_read_line_job_on_missing ( pbsdrmaa_log_reader_t * self, char * line, char * buffer, ssize_t size, int * idx, int * end_idx, int * line_idx )
+{
+	int n = fsd_getline_buffered(line,buffer,size,self->fd, idx, end_idx, line_idx);
+	
+	if(n >= 0)
+		self->log_file_read_size += n;
+		
+	if(self->log_file_read_size >= self->log_file_initial_size)
+		return -1; 
+
+	return n; 
+}
+
+int 
+fsd_job_id_cmp(const char *s1, const char *s2) /* maybe move to drmaa_utils? */
+{
+	int job1;
+	int job2;
+	char *rest = NULL;
+	char *token = NULL;
+	char *ptr = fsd_strdup(s1);
+	token = strtok_r(ptr, ".", &rest);
+	job1 = atoi(token);
+	
+	fsd_free(token);
+	
+	ptr = fsd_strdup(s2);
+	token = strtok_r(ptr,".",&rest);
+	job2 = atoi(token);
+	
+	fsd_free(token);
+	return job1 - job2;
+}
+
Index: /branches/2.0/pbs_drmaa/submit.c
===================================================================
--- /branches/2.0/pbs_drmaa/submit.c	(revision 16)
+++ /branches/2.0/pbs_drmaa/submit.c	(revision 16)
@@ -0,0 +1,718 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2009  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <unistd.h>
+#include <string.h>
+
+#include <pbs_ifl.h>
+#include <pbs_error.h>
+
+#include <drmaa_utils/conf.h>
+#include <drmaa_utils/drmaa.h>
+#include <drmaa_utils/drmaa_util.h>
+#include <drmaa_utils/datetime.h>
+#include <drmaa_utils/iter.h>
+#include <drmaa_utils/template.h>
+#include <pbs_drmaa/pbs_attrib.h>
+#include <pbs_drmaa/session.h>
+#include <pbs_drmaa/submit.h>
+#include <pbs_drmaa/util.h>
+
+
+
+#ifndef lint
+static char rcsid[]
+#	ifdef __GNUC__
+		__attribute__ ((unused))
+#	endif
+	= "$Id$";
+#endif
+
+static void
+pbsdrmaa_submit_destroy( pbsdrmaa_submit_t *self );
+
+static char *
+pbsdrmaa_submit_submit( pbsdrmaa_submit_t *self );
+
+static void
+pbsdrmaa_submit_eval( pbsdrmaa_submit_t *self );
+
+
+static void
+pbsdrmaa_submit_set( pbsdrmaa_submit_t *self, const char *pbs_attr,
+		char *value, unsigned placeholders );
+
+static void pbsdrmaa_submit_apply_defaults( pbsdrmaa_submit_t *self );
+static void pbsdrmaa_submit_apply_job_script( pbsdrmaa_submit_t *self );
+static void pbsdrmaa_submit_apply_job_state( pbsdrmaa_submit_t *self );
+static void pbsdrmaa_submit_apply_job_files( pbsdrmaa_submit_t *self );
+static void pbsdrmaa_submit_apply_file_staging( pbsdrmaa_submit_t *self );
+static void pbsdrmaa_submit_apply_job_resources( pbsdrmaa_submit_t *self );
+static void pbsdrmaa_submit_apply_job_environment( pbsdrmaa_submit_t *self );
+static void pbsdrmaa_submit_apply_email_notification( pbsdrmaa_submit_t *self );
+static void pbsdrmaa_submit_apply_job_category( pbsdrmaa_submit_t *self );
+
+
+pbsdrmaa_submit_t *
+pbsdrmaa_submit_new( fsd_drmaa_session_t *session,
+		const fsd_template_t *job_template, int bulk_idx )
+{
+	pbsdrmaa_submit_t *volatile self = NULL;
+	TRY
+	 {
+		fsd_malloc( self, pbsdrmaa_submit_t );
+		self->session = session;
+		self->job_template = job_template;
+		self->script_filename = NULL;
+		self->destination_queue = NULL;
+		self->pbs_job_attributes = NULL;
+		self->expand_ph = NULL;
+		self->destroy = pbsdrmaa_submit_destroy;
+		self->submit = pbsdrmaa_submit_submit;
+		self->eval = pbsdrmaa_submit_eval;
+		self->set = pbsdrmaa_submit_set;
+		self->apply_defaults = pbsdrmaa_submit_apply_defaults;
+		self->apply_job_category = pbsdrmaa_submit_apply_job_category;
+		self->apply_job_script = pbsdrmaa_submit_apply_job_script;
+		self->apply_job_state = pbsdrmaa_submit_apply_job_state;
+		self->apply_job_files = pbsdrmaa_submit_apply_job_files;
+		self->apply_file_staging = pbsdrmaa_submit_apply_file_staging;
+		self->apply_job_resources = pbsdrmaa_submit_apply_job_resources;
+		self->apply_job_environment = pbsdrmaa_submit_apply_job_environment;
+		self->apply_email_notification = pbsdrmaa_submit_apply_email_notification;
+		self->apply_native_specification =
+			pbsdrmaa_submit_apply_native_specification;
+
+		self->pbs_job_attributes = pbsdrmaa_pbs_template_new();
+		self->expand_ph = fsd_expand_drmaa_ph_new( NULL, NULL,
+				(bulk_idx >= 0) ? fsd_asprintf("%d", bulk_idx) : NULL );
+	 }
+	EXCEPT_DEFAULT
+	 {
+		if( self )
+			self->destroy( self );
+	 }
+	END_TRY
+	return self;
+}
+
+
+void
+pbsdrmaa_submit_destroy( pbsdrmaa_submit_t *self )
+{
+	if( self->script_filename )
+	 {
+		unlink( self->script_filename );
+		fsd_free( self->script_filename );
+	 }
+	if( self->pbs_job_attributes )
+		self->pbs_job_attributes->destroy( self->pbs_job_attributes );
+	if( self->expand_ph )
+		self->expand_ph->destroy( self->expand_ph );
+	fsd_free( self->destination_queue );
+	fsd_free( self );
+}
+
+
+char *
+pbsdrmaa_submit_submit( pbsdrmaa_submit_t *self )
+{
+	volatile bool conn_lock = false;
+	struct attrl *volatile pbs_attr = NULL;
+	char *volatile job_id = NULL;
+	TRY
+	 {
+		const fsd_template_t *pbs_tmpl = self->pbs_job_attributes;
+		unsigned i;
+
+		for( i = 0;  i < PBSDRMAA_N_PBS_ATTRIBUTES;  i++ )
+		 {
+			const char *name = pbs_tmpl->by_code( pbs_tmpl, i )->name;
+			if( name  &&  name[0] != '!' && pbs_tmpl->get_attr( pbs_tmpl, name ) )
+			 {
+				struct attrl *p;
+				const char *resource;
+				const char *value;
+				value = pbs_tmpl->get_attr( pbs_tmpl, name );
+				fsd_malloc( p, struct attrl );
+				memset( p, 0, sizeof(struct attrl) );
+				p->next = pbs_attr;
+				pbs_attr = p;
+				resource = strchr( name, '.' );
+				if( resource )
+				 {
+					p->name = fsd_strndup( name, resource-name );
+					p->resource = fsd_strdup( resource+1 );
+				 }
+				else
+					p->name = fsd_strdup( name );
+				fsd_log_debug(("set attr: %s = %s", name, value));
+				p->value = fsd_strdup( value );
+				p->op = SET;
+			 }
+		 }
+
+		conn_lock = fsd_mutex_lock( &self->session->drm_connection_mutex );
+retry:
+		job_id = pbs_submit( ((pbsdrmaa_session_t*)self->session)->pbs_conn,
+				(struct attropl*)pbs_attr, self->script_filename,
+				self->destination_queue, NULL );
+
+		fsd_log_info(("pbs_submit(%s, %s) =%s", self->script_filename, self->destination_queue, job_id));
+
+		if( job_id == NULL )
+		{
+			if (pbs_errno == PBSE_PROTOCOL || pbs_errno == PBSE_EXPIRED)
+			 {
+				pbsdrmaa_session_t *pbsself = (pbsdrmaa_session_t*)self->session;
+				if (pbsself->pbs_conn >= 0 )
+					pbs_disconnect( pbsself->pbs_conn );
+				sleep(1);
+				pbsself->pbs_conn = pbs_connect( pbsself->super.contact );
+				if( pbsself->pbs_conn < 0 )
+					pbsdrmaa_exc_raise_pbs( "pbs_connect" );
+				else
+					goto retry;
+			 }
+			else
+			 {
+				pbsdrmaa_exc_raise_pbs( "pbs_submit" );
+			 }
+		}
+		conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex );
+	 }
+	EXCEPT_DEFAULT
+	 {
+		fsd_free( job_id );
+		fsd_exc_reraise();
+	 }
+	FINALLY
+	 {
+		if( conn_lock )
+			conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex );
+		if( pbs_attr )
+			pbsdrmaa_free_attrl( pbs_attr );
+	 }
+	END_TRY
+	return job_id;
+}
+
+
+void
+pbsdrmaa_submit_eval( pbsdrmaa_submit_t *self )
+{
+	self->apply_defaults( self );
+	self->apply_job_category( self );
+	self->apply_job_script( self );
+	self->apply_job_state( self );
+	self->apply_job_files( self );
+	self->apply_file_staging( self );
+	self->apply_job_resources( self );
+	self->apply_job_environment( self );
+	self->apply_email_notification( self );
+	self->apply_native_specification( self, NULL );
+}
+
+
+void
+pbsdrmaa_submit_set( pbsdrmaa_submit_t *self, const char *name,
+		 char *value, unsigned placeholders )
+{
+	fsd_template_t *pbs_attr = self->pbs_job_attributes;
+	TRY
+	 {
+		if( placeholders )
+			value = self->expand_ph->expand(
+					self->expand_ph, value, placeholders );
+		pbs_attr->set_attr( pbs_attr, name, value );
+	 }
+	FINALLY
+	 {
+		fsd_free( value );
+	 }
+	END_TRY
+}
+
+
+void
+pbsdrmaa_submit_apply_defaults( pbsdrmaa_submit_t *self )
+{
+	fsd_template_t *pbs_attr = self->pbs_job_attributes;
+	pbs_attr->set_attr( pbs_attr, PBSDRMAA_CHECKPOINT, "u" );
+	pbs_attr->set_attr( pbs_attr, PBSDRMAA_KEEP_FILES, "n" );
+	pbs_attr->set_attr( pbs_attr, PBSDRMAA_PRIORITY, "0" );
+}
+
+
+void
+pbsdrmaa_submit_apply_job_script( pbsdrmaa_submit_t *self )
+{
+	const fsd_template_t *jt = self->job_template;
+	/* fsd_template_t *pbs_attr = self->pbs_job_attributes; */
+	fsd_expand_drmaa_ph_t *expand = self->expand_ph;
+	char *script = NULL;
+	size_t script_len;
+	const char *executable;
+	const char *wd;
+	const char *const *argv;
+	const char *input_path;
+	const char *const *i;
+
+	executable   = jt->get_attr( jt, DRMAA_REMOTE_COMMAND );
+	wd           = jt->get_attr( jt, DRMAA_WD );
+	argv         = jt->get_v_attr( jt, DRMAA_V_ARGV );
+	input_path   = jt->get_attr( jt, DRMAA_INPUT_PATH );
+
+	if( wd )
+	 {
+		char *cwd = NULL;
+		cwd = expand->expand( expand, fsd_strdup(wd),
+				FSD_DRMAA_PH_HD | FSD_DRMAA_PH_INCR );
+		expand->set( expand, FSD_DRMAA_PH_WD, cwd );
+	 }
+
+	if( executable == NULL )
+		fsd_exc_raise_code( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE );
+
+	if( input_path != NULL )
+	 {
+		if( input_path[0] == ':' )
+			input_path++;
+	 }
+
+	 { /* compute script length */
+		script_len = 0;
+		if( wd != NULL )
+			script_len += strlen("cd ") + strlen(wd) + strlen("; ");
+		script_len += strlen("exec ") + strlen(executable);
+		if( argv != NULL )
+			for( i = argv;  *i != NULL;  i++ )
+				script_len += 3+strlen(*i);
+		if( input_path != NULL )
+			script_len += strlen(" <") + strlen(input_path);
+	 }
+
+	fsd_calloc( script, script_len+1, char );
+
+	 {
+		char *s;
+		s = script;
+		if( wd != NULL )
+			s += sprintf( s, "cd %s; ", wd );
+		s += sprintf( s, "exec %s", executable );
+		if( argv != NULL )
+			for( i = argv;  *i != NULL;  i++ )
+				s += sprintf( s, " '%s'", *i );
+		if( input_path != NULL )
+			s += sprintf( s, " <%s", input_path );
+		fsd_assert( s == script+script_len );
+	 }
+
+	script = expand->expand( expand, script,
+			FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD | FSD_DRMAA_PH_INCR );
+
+	/* pbs_attr->set_attr( pbs_attr, "!script", script ); */
+
+	self->script_filename = pbsdrmaa_write_tmpfile( script, strlen(script) );
+	fsd_free( script );
+}
+
+
+void
+pbsdrmaa_submit_apply_job_state( pbsdrmaa_submit_t *self )
+{
+	const fsd_template_t *jt = self->job_template;
+	fsd_template_t *pbs_attr = self->pbs_job_attributes;
+	const char *job_name = NULL;
+	const char *submit_state = NULL;
+	const char *drmaa_start_time = NULL;
+
+	job_name = jt->get_attr( jt, DRMAA_JOB_NAME );
+	submit_state = jt->get_attr( jt, DRMAA_JS_STATE );
+	drmaa_start_time = jt->get_attr( jt, DRMAA_START_TIME );
+
+	if( job_name != NULL )
+		pbs_attr->set_attr( pbs_attr, PBSDRMAA_JOB_NAME, job_name );
+
+	if( submit_state != NULL )
+	 {
+		const char *hold_types;
+		if( !strcmp(submit_state, DRMAA_SUBMISSION_STATE_ACTIVE) )
+			hold_types = "n";
+		else if( !strcmp(submit_state, DRMAA_SUBMISSION_STATE_HOLD) )
+			hold_types = "u";
+		else
+			fsd_exc_raise_fmt( FSD_ERRNO_INVALID_VALUE,
+					"invalid value of %s attribute (%s|%s)",
+					DRMAA_JS_STATE, DRMAA_SUBMISSION_STATE_ACTIVE,
+					DRMAA_SUBMISSION_STATE_HOLD );
+		pbs_attr->set_attr( pbs_attr, PBSDRMAA_HOLD_TYPES, hold_types );
+	 }
+
+	if( drmaa_start_time != NULL )
+	 {
+		time_t start_time;
+		char pbs_start_time[20];
+		struct tm start_time_tm;
+		start_time = fsd_datetime_parse( drmaa_start_time );
+		localtime_r( &start_time, &start_time_tm );
+		sprintf( pbs_start_time, "%04d%02d%02d%02d%02d.%02d",
+				start_time_tm.tm_year + 1900,
+				start_time_tm.tm_mon + 1,
+				start_time_tm.tm_mday,
+				start_time_tm.tm_hour,
+				start_time_tm.tm_min,
+				start_time_tm.tm_sec
+				);
+		pbs_attr->set_attr( pbs_attr, PBSDRMAA_EXECUTION_TIME, pbs_start_time );
+	 }
+}
+
+
+void
+pbsdrmaa_submit_apply_job_files( pbsdrmaa_submit_t *self )
+{
+	const fsd_template_t *jt = self->job_template;
+	fsd_template_t *pbs_attr = self->pbs_job_attributes;
+	const char *join_files;
+	bool b_join_files;
+	int i;
+
+	for( i = 0;  i < 2;  i++ )
+	 {
+		const char *drmaa_name;
+		const char *pbs_name;
+		const char *path;
+
+		if( i == 0 )
+		 {
+			drmaa_name = DRMAA_OUTPUT_PATH;
+			pbs_name = PBSDRMAA_OUTPUT_PATH;
+		 }
+		else
+		 {
+			drmaa_name = DRMAA_ERROR_PATH;
+			pbs_name = PBSDRMAA_ERROR_PATH;
+		 }
+
+		path = jt->get_attr( jt, drmaa_name );
+		if( path != NULL )
+		 {
+			if( path[0] == ':' )
+				path++;
+			self->set(self, pbs_name, fsd_strdup(path), FSD_DRMAA_PH_HD | FSD_DRMAA_PH_WD | FSD_DRMAA_PH_INCR);
+		 }
+	 }
+
+	join_files = jt->get_attr( jt, DRMAA_JOIN_FILES );
+	b_join_files = join_files != NULL  &&  !strcmp(join_files,"1");
+	pbs_attr->set_attr( pbs_attr, PBSDRMAA_JOIN_FILES, (b_join_files ? "y" : "n") ); 
+}
+
+
+void
+pbsdrmaa_submit_apply_file_staging( pbsdrmaa_submit_t *self )
+{
+	/* TODO */
+}
+
+
+void
+pbsdrmaa_submit_apply_job_resources( pbsdrmaa_submit_t *self )
+{
+	const fsd_template_t *jt = self->job_template;
+	fsd_template_t *pbs_attr = self->pbs_job_attributes;
+	const char *cpu_time_limit = NULL;
+	const char *walltime_limit = NULL;
+
+	cpu_time_limit = jt->get_attr( jt, DRMAA_DURATION_HLIMIT );
+	walltime_limit = jt->get_attr( jt, DRMAA_WCT_HLIMIT );
+	if( cpu_time_limit )
+	 {
+		pbs_attr->set_attr( pbs_attr, "Resource_List.pcput", cpu_time_limit );
+		pbs_attr->set_attr( pbs_attr, "Resource_List.cput", cpu_time_limit );
+	 }
+	if( walltime_limit )
+		pbs_attr->set_attr( pbs_attr, "Resource_List.walltime", walltime_limit );
+}
+
+void
+pbsdrmaa_submit_apply_job_environment( pbsdrmaa_submit_t *self )
+{
+	const fsd_template_t *jt = self->job_template;
+	const char *const *env_v;
+
+	env_v = jt->get_v_attr( jt, DRMAA_V_ENV);
+
+	if (env_v)
+	{
+		char *env_c = NULL;
+		int ii = 0, len = 0;
+
+		ii = 0;
+		while (env_v[ii]) {
+			len += strlen(env_v[ii]) + 1;
+			ii++;
+		}
+
+		fsd_calloc(env_c, len + 1, char);
+		env_c[0] = '\0';
+
+		ii = 0;
+		while (env_v[ii]) {
+			strcat(env_c, env_v[ii]);
+			strcat(env_c, ",");
+			ii++;
+		}
+
+		env_c[strlen(env_c) -1 ] = '\0'; /*remove the last ',' */
+
+		self->pbs_job_attributes->set_attr(self->pbs_job_attributes, "Variable_List", env_c);
+
+		fsd_free(env_c);
+	}
+}
+
+
+void
+pbsdrmaa_submit_apply_email_notification( pbsdrmaa_submit_t *self )
+{
+	/* TODO */
+}
+
+
+void
+pbsdrmaa_submit_apply_job_category( pbsdrmaa_submit_t *self )
+{
+	const char *job_category = NULL;
+	const char *category_spec = NULL;
+	fsd_conf_option_t *value = NULL;
+
+	job_category = self->job_template->get_attr(
+			self->job_template, DRMAA_JOB_CATEGORY );
+	if( job_category == NULL  ||  job_category[0] == '\0' )
+		job_category = "default";
+	value = fsd_conf_dict_get( self->session->job_categories,
+			job_category );
+	if( value != NULL  &&  value->type == FSD_CONF_STRING )
+		category_spec = value->val.string;
+	if( category_spec != NULL )
+		self->apply_native_specification( self, category_spec );
+}
+
+static void parse_resources(fsd_template_t *pbs_attr,const char *resources)
+{
+	char * volatile name = NULL;
+	char *arg = NULL;
+	char *value = NULL;
+	char *ctxt = NULL;
+	char * volatile resources_copy = fsd_strdup(resources);
+
+	TRY
+	  {
+		for (arg = strtok_r(resources_copy, ",", &ctxt); arg; arg = strtok_r(NULL, ",",&ctxt) )
+		{
+			char *psep = strchr(arg, '=');
+
+			if (psep) 
+			{
+				*psep = '\0';
+				name = fsd_asprintf("Resource_List.%s", arg);
+				value = ++psep;
+				pbs_attr->set_attr( pbs_attr, name , value );
+				fsd_free(name);
+				name = NULL;
+			}
+			else
+			{
+				fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "Invalid native specification: %s (Invalid resource specification: %s)", resources, arg);
+			}
+		}
+	  }
+	FINALLY
+	  {
+		fsd_free(name);
+		fsd_free(resources_copy);
+	  }
+	END_TRY
+}
+
+static void parse_additional_attr(fsd_template_t *pbs_attr,const char *add_attr)
+{
+	char * volatile name = NULL;
+	char *arg = NULL;
+	char *value = NULL;
+	char *ctxt = NULL, *ctxt2 = NULL;
+	char * volatile add_attr_copy = fsd_strdup(add_attr);
+
+	TRY
+	  {
+		for (arg = strtok_r(add_attr_copy, ";", &ctxt); arg; arg = strtok_r(NULL, ";",&ctxt) )
+		{
+			name = fsd_strdup(strtok_r(arg, "=", &ctxt2));
+			value = strtok_r(NULL, "=", &ctxt2);
+			pbs_attr->set_attr( pbs_attr, name , value );
+			fsd_free(name);
+			name = NULL;
+		}
+	  }
+	FINALLY
+	  {
+		fsd_free(name);
+		fsd_free(add_attr_copy);
+	  }
+	END_TRY
+}
+
+
+void
+pbsdrmaa_submit_apply_native_specification( pbsdrmaa_submit_t *self,
+		const char *native_specification )
+{
+        fsd_log_enter(( "({native_specification=%s})", native_specification ));
+
+	if( native_specification == NULL )
+		native_specification = self->job_template->get_attr(
+				self->job_template, DRMAA_NATIVE_SPECIFICATION );
+	if( native_specification == NULL )
+		return;
+
+	{
+		fsd_iter_t * volatile args_list = fsd_iter_new(NULL, 0);
+		fsd_template_t *pbs_attr = self->pbs_job_attributes;
+		char *arg = NULL;
+		volatile char * native_spec_copy = fsd_strdup(native_specification);
+		char * ctxt = NULL;
+		int opt = 0;
+
+		TRY
+		  {
+			for (arg = strtok_r(native_spec_copy, " \t", &ctxt); arg; arg = strtok_r(NULL, " \t",&ctxt) ) {
+				if (!opt)
+				  {
+					if ( (arg[0] != '-') || (strlen(arg) != 2) )
+						fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,
+							"Invalid native specification: -o(ption) expected (arg=%s native=%s).",
+							arg, native_specification);
+
+					opt = arg[1];
+
+					/* handle NO-arg options */
+
+					switch (opt) {
+						case 'h' :
+							pbs_attr->set_attr( pbs_attr, "Hold_Types" , "u" );
+							break;
+						default :
+							continue; /*no NO-ARG option */
+					}
+
+					opt = 0;
+				  }
+				else
+				  {
+					switch (opt) {
+						
+						case 'W' :
+							parse_additional_attr(pbs_attr, arg);
+							break;
+						case 'N' :
+							pbs_attr->set_attr( pbs_attr, "Job_Name" , arg );
+							break;
+						case 'o' :
+							pbs_attr->set_attr( pbs_attr, "Output_Path" , arg );
+							break;
+						case 'e' :
+							pbs_attr->set_attr( pbs_attr, "Error_Path" , arg );
+							break;
+						case 'j' :
+							pbs_attr->set_attr( pbs_attr, "Join_Path" , arg );
+							break;
+						case 'm' :
+							pbs_attr->set_attr( pbs_attr, "Mail_Points" , arg );
+							break;
+						case 'a' :
+							pbs_attr->set_attr( pbs_attr, "Execution_Time" , arg );
+							break;
+						case 'A' :
+							pbs_attr->set_attr( pbs_attr, "Account_Name" , arg );
+							break;
+						case 'c' :
+							pbs_attr->set_attr( pbs_attr, "Checkpoint" , arg );
+							break;
+						case 'k' :
+							pbs_attr->set_attr( pbs_attr, "Keep_Files" , arg );
+							break;
+						case 'p' :
+							pbs_attr->set_attr( pbs_attr, "Priority" , arg );
+							break;
+						case 'q' :
+							self->destination_queue = fsd_strdup( arg );
+							fsd_log_debug(("self->destination_queue = %s", self->destination_queue));
+							break;
+						case 'r' :
+							pbs_attr->set_attr( pbs_attr, "Rerunable" , arg );
+							break;
+						case 'S' :
+							pbs_attr->set_attr( pbs_attr, "Shell_Path_List" , arg );
+							break;
+						case 'u' :
+							pbs_attr->set_attr( pbs_attr, "User_List" , arg );
+							break;
+						case 'v' :
+							pbs_attr->set_attr( pbs_attr, "Variable_List" , arg );
+							break;
+						case 'M' :
+							pbs_attr->set_attr( pbs_attr, "Mail_Users" , arg );
+							break;
+						case 'l' :
+							parse_resources(pbs_attr, arg);
+							break;							
+						default :
+							
+							fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,
+									"Invalid native specification: %s (Unsupported option: -%c)",
+									native_specification, opt);
+					}
+					opt = 0;
+				}
+			}
+
+			if (opt) /* option without optarg */
+				fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,
+						"Invalid native specification: %s",
+						native_specification);
+
+		 }
+		FINALLY
+		 {
+#ifndef PBS_PROFESSIONAL
+			pbs_attr->set_attr( pbs_attr, "submit_args", native_specification);
+#endif
+			args_list->destroy(args_list);
+			fsd_free(native_spec_copy);
+		 }
+		END_TRY
+	}
+}
+
Index: /branches/2.0/pbs_drmaa/CHANGELOG
===================================================================
--- /branches/2.0/pbs_drmaa/CHANGELOG	(revision 12)
+++ /branches/2.0/pbs_drmaa/CHANGELOG	(revision 12)
@@ -0,0 +1,2 @@
+
+* inproper use of fsd_datetime_parse (wait thread)
Index: /branches/2.0/pbs_drmaa/log_reader.h
===================================================================
--- /branches/2.0/pbs_drmaa/log_reader.h	(revision 12)
+++ /branches/2.0/pbs_drmaa/log_reader.h	(revision 12)
@@ -0,0 +1,82 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2009  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+ 
+#ifndef __PBS_DRMAA__LOG_READER_H
+#define __PBS_DRMAA__LOG_READER_H
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <drmaa_utils/job.h>
+#include <drmaa_utils/session.h>
+
+typedef struct pbsdrmaa_log_reader_s pbsdrmaa_log_reader_t;
+
+pbsdrmaa_log_reader_t * 
+pbsdrmaa_log_reader_new ( fsd_drmaa_session_t * session, fsd_job_t * job );
+
+void
+pbsdrmaa_log_reader_destroy ( pbsdrmaa_log_reader_t * self );
+
+struct pbsdrmaa_log_reader_s {
+	fsd_drmaa_session_t *volatile session ;
+	fsd_job_t *volatile job;
+	
+	void (*
+	read_log) ( pbsdrmaa_log_reader_t * self );
+	
+	void (*
+	select_file) ( pbsdrmaa_log_reader_t * self );
+	
+	/* line - read line, buffer - keeps read but not returned lines, idx, end_idx and line_idx values needed to be kept outside the function */
+	ssize_t (*
+	read_line) ( pbsdrmaa_log_reader_t * self, char * line, char * buffer, ssize_t size, int * idx, int * end_idx, int * line_idx );
+	
+	/* specifies if function should run */
+	bool run_flag;
+	
+	/* date of current file */
+	time_t t;	
+	
+	/* for job_on_missing  - available log files */
+	char ** log_files;
+	
+	/* for job_on_missing - number of log files */
+	int log_files_number;
+	
+	/* log file descriptor */
+	int volatile fd;
+	
+	/* for job_on_missing - log file size when function was ran */
+	off_t log_file_initial_size;
+	
+	/* for job_on_missing - read lines size */
+	off_t log_file_read_size;
+	
+	/* for wait_thread - day changed */
+	bool volatile date_changed;
+	
+	/* for wait_thread - log file first open */
+	bool volatile first_open;	
+	
+	char * name;
+};
+
+#endif /* __PBS_DRMAA__LOG_READER_H */
Index: /branches/2.0/pbs_drmaa/submit.h
===================================================================
--- /branches/2.0/pbs_drmaa/submit.h	(revision 12)
+++ /branches/2.0/pbs_drmaa/submit.h	(revision 12)
@@ -0,0 +1,74 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2009  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __PBS_DRMAA__SUBMIT_H
+#define __PBS_DRMAA__SUBMIT_H
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <drmaa_utils/drmaa_util.h>
+
+typedef struct pbsdrmaa_submit_s pbsdrmaa_submit_t;
+
+pbsdrmaa_submit_t *
+pbsdrmaa_submit_new( fsd_drmaa_session_t *session,
+		const fsd_template_t *job_template, int bulk_idx );
+
+struct pbsdrmaa_submit_s {
+	void (*
+	destroy)( pbsdrmaa_submit_t *self );
+
+	char * (*
+	submit)( pbsdrmaa_submit_t *self );
+
+	void (*
+	eval)( pbsdrmaa_submit_t *self );
+
+	void (*apply_defaults)( pbsdrmaa_submit_t *self );
+	void (*apply_job_script)( pbsdrmaa_submit_t *self );
+	void (*apply_job_state)( pbsdrmaa_submit_t *self );
+	void (*apply_job_files)( pbsdrmaa_submit_t *self );
+	void (*apply_file_staging)( pbsdrmaa_submit_t *self );
+	void (*apply_job_resources)( pbsdrmaa_submit_t *self );
+	void (*apply_job_environment)( pbsdrmaa_submit_t *self );
+	void (*apply_email_notification)( pbsdrmaa_submit_t *self );
+	void (*apply_job_category)( pbsdrmaa_submit_t *self );
+	void (*apply_native_specification)(
+			pbsdrmaa_submit_t *self, const char *native_specification );
+
+	void (*set)( pbsdrmaa_submit_t *self, const char *pbs_attr,
+			char *value, unsigned placeholders );
+
+	fsd_drmaa_session_t *session;
+	const fsd_template_t *job_template;
+	char *script_filename;
+	char *destination_queue;
+	fsd_template_t *pbs_job_attributes;
+	fsd_expand_drmaa_ph_t *expand_ph;
+	/* struct attrl *pbs_attribs; */
+	/* uint32_t pbs_attribs_bitset[ PBS_ATTRIBS_BITSET_SIZE ]; */
+};
+
+void pbsdrmaa_submit_apply_native_specification(
+		pbsdrmaa_submit_t *self, const char *native_specification );
+
+#endif /* __PBS_DRMAA__SUBMIT_H */
+
Index: /branches/2.0/pbs_drmaa/job.c
===================================================================
--- /branches/2.0/pbs_drmaa/job.c	(revision 17)
+++ /branches/2.0/pbs_drmaa/job.c	(revision 17)
@@ -0,0 +1,498 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2009  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <drmaa_utils/drmaa.h>
+#include <drmaa_utils/drmaa_util.h>
+#include <pbs_error.h>
+#include <pbs_ifl.h>
+
+#include <pbs_drmaa/job.h>
+#include <pbs_drmaa/log_reader.h>
+#include <pbs_drmaa/pbs_attrib.h>
+#include <pbs_drmaa/session.h>
+#include <pbs_drmaa/util.h>
+
+#ifndef lint
+static char rcsid[]
+#	ifdef __GNUC__
+		__attribute__ ((unused))
+#	endif
+	= "$Id$";
+#endif
+
+
+static void
+pbsdrmaa_job_control( fsd_job_t *self, int action );
+
+static void
+pbsdrmaa_job_update_status( fsd_job_t *self );
+
+static void
+pbsdrmaa_job_on_missing( fsd_job_t *self );
+
+void
+pbsdrmaa_job_on_missing_standard( fsd_job_t *self );
+
+void
+pbsdrmaa_job_on_missing_log_based( fsd_job_t *self );
+
+static void
+pbsdrmaa_job_update( fsd_job_t *self, struct batch_status* );
+
+
+fsd_job_t *
+pbsdrmaa_job_new( char *job_id )
+{
+	pbsdrmaa_job_t *self = (pbsdrmaa_job_t*)fsd_job_new( job_id );
+	fsd_realloc( self, 1, pbsdrmaa_job_t );
+	self->super.control = pbsdrmaa_job_control;
+	self->super.update_status = pbsdrmaa_job_update_status;
+	self->super.on_missing = pbsdrmaa_job_on_missing;
+	self->update = pbsdrmaa_job_update;
+	return (fsd_job_t*)self;
+}
+
+
+static void
+pbsdrmaa_job_control( fsd_job_t *self, int action )
+{
+	volatile bool conn_lock = false;
+	pbsdrmaa_session_t *session = (pbsdrmaa_session_t*)self->session;
+	const char *job_id = self->job_id;
+	const char *apicall = NULL;
+	int rc = PBSE_NONE;
+
+	fsd_log_enter(( "({job_id=%s}, action=%d)",
+			self->job_id, action ));
+
+	TRY
+	 {
+		int try_count;
+		const int max_tries = 3;
+
+		conn_lock = fsd_mutex_lock( &self->session->drm_connection_mutex );
+
+		/*TODO reconnect */
+		for( try_count=0;  try_count < max_tries;  try_count++ )
+		 {
+			switch( action )
+			 {
+				/*
+				 * We cannot know whether we did suspend job
+				 * in other way than remembering this inside DRMAA session.
+				 */
+				case DRMAA_CONTROL_SUSPEND:
+					apicall = "pbs_sigjob";
+					rc = pbs_sigjob( session->pbs_conn, (char*)job_id,
+							"SIGSTOP", NULL );
+					fsd_log_info(("pbs_sigjob(%s, SIGSTOP) =%d", job_id, rc));
+					if( rc == PBSE_NONE )
+						self->flags |= FSD_JOB_SUSPENDED;
+					break;
+				case DRMAA_CONTROL_RESUME:
+					apicall = "pbs_sigjob";
+					rc = pbs_sigjob( session->pbs_conn, (char*)job_id,
+							"SIGCONT", NULL );
+					fsd_log_info(("pbs_sigjob(%s, SIGCONT) =%d", job_id, rc));
+					if( rc == PBSE_NONE )
+						self->flags &= ~FSD_JOB_SUSPENDED;
+					break;
+				case DRMAA_CONTROL_HOLD:
+					apicall = "pbs_holdjob";
+					rc = pbs_holdjob( session->pbs_conn, (char*)job_id,
+							USER_HOLD, NULL );
+					fsd_log_info(("pbs_sigjob(%s, SIGHOLD) =%d", job_id, rc));
+					if( rc == PBSE_NONE )
+						self->flags |= FSD_JOB_HOLD;
+					break;
+				case DRMAA_CONTROL_RELEASE:
+					apicall = "pbs_rlsjob";
+					rc = pbs_rlsjob( session->pbs_conn, (char*)job_id,
+							USER_HOLD, NULL );
+					fsd_log_info(("pbs_rlsjob(%s) =%d", job_id, rc));
+					if( rc == PBSE_NONE )
+						self->flags &= FSD_JOB_HOLD;
+					break;
+				case DRMAA_CONTROL_TERMINATE:
+					apicall = "pbs_deljob";
+					rc = pbs_deljob( session->pbs_conn, (char*)job_id, NULL );
+					fsd_log_info(("pbs_deljob(%s) =%d", job_id, rc));
+					/* Torque:
+					 * deldelay=N -- delay between SIGTERM and SIGKILL (default 0) */
+					if( rc == PBSE_NONE )
+					 {
+						self->flags &= FSD_JOB_TERMINATED_MASK;
+						if( (self->flags & FSD_JOB_TERMINATED) == 0 )
+							self->flags |= FSD_JOB_TERMINATED | FSD_JOB_ABORTED;
+					 }
+					break;
+			 }
+
+			if( rc == PBSE_NONE )
+				break;
+			else if( rc == PBSE_INTERNAL )
+			 {
+				/*
+				 * In PBS Pro pbs_sigjob raises internal server error (PBSE_INTERNAL)
+				 * when job just changed its state to running.
+				 */
+				fsd_log_debug(( "repeating request (%d of %d)",
+							try_count+2, max_tries ));
+				sleep( 1 );
+			 }
+			else
+				pbsdrmaa_exc_raise_pbs( apicall );
+		 } /* end for */
+	 }
+	FINALLY
+	 {
+		if( conn_lock )
+			conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex );
+	 }
+	END_TRY
+
+	fsd_log_return((""));
+}
+
+
+void
+pbsdrmaa_job_update_status( fsd_job_t *self )
+{
+	volatile bool conn_lock = false;
+	struct batch_status *volatile status = NULL;
+	pbsdrmaa_session_t *session = (pbsdrmaa_session_t*)self->session;
+
+	fsd_log_enter(( "({job_id=%s})", self->job_id ));
+	TRY
+	 {
+		conn_lock = fsd_mutex_lock( &self->session->drm_connection_mutex );
+retry:
+
+#ifdef PBS_PROFESSIONAL
+		status = pbs_statjob( session->pbs_conn, self->job_id, NULL, NULL );
+#else
+		status = pbs_statjob( session->pbs_conn, self->job_id, session->status_attrl, NULL );
+#endif
+		fsd_log_info(( "pbs_statjob(fd=%d, job_id=%s, attribs={...}) =%p",
+				 session->pbs_conn, self->job_id, (void*)status ));
+		if( status == NULL )
+		 {
+#ifndef PBS_PROFESSIONAL
+			fsd_log_error(("pbs_statjob error: %d, %s, %s", pbs_errno, pbse_to_txt(pbs_errno), pbs_strerror(pbs_errno)));
+#else
+#  ifndef PBS_PROFESSIONAL_NO_LOG
+			fsd_log_error(("pbs_statjob error: %d, %s", pbs_errno, pbse_to_txt(pbs_errno)));
+#  else
+			fsd_log_error(("pbs_statjob error: %d", pbs_errno));
+#  endif
+#endif
+			switch( pbs_errno )
+			 {
+				case PBSE_UNKJOBID:
+					break;
+				case PBSE_PROTOCOL:
+				case PBSE_EXPIRED:
+					if ( session->pbs_conn >= 0 )
+						pbs_disconnect( session->pbs_conn );
+					sleep(1);
+					session->pbs_conn = pbs_connect( session->super.contact );
+					if( session->pbs_conn < 0 )
+						pbsdrmaa_exc_raise_pbs( "pbs_connect" );
+					else 
+					 {
+						fsd_log_error(("retry:"));
+						goto retry;
+					 }
+				default:
+					pbsdrmaa_exc_raise_pbs( "pbs_statjob" );
+					break;
+				case 0:  /* ? */
+					fsd_exc_raise_code( FSD_ERRNO_INTERNAL_ERROR );
+					break;
+			 }
+		 }
+
+		conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex );
+
+		if( status != NULL )
+		 {
+			((pbsdrmaa_job_t*)self)->update( self, status );
+		 }
+		else if( self->state < DRMAA_PS_DONE )
+			self->on_missing( self );
+	 }
+	FINALLY
+	 {
+		if( conn_lock )
+			conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex );
+		if( status != NULL )
+			pbs_statfree( status );
+	 }
+	END_TRY
+
+	fsd_log_return((""));
+}
+
+
+void
+pbsdrmaa_job_update( fsd_job_t *self, struct batch_status *status )
+{
+	struct attrl *attribs = status->attribs;
+	struct attrl *i = NULL;
+	char pbs_state = 0;
+	int exit_status = -2;
+	const char *cpu_usage = NULL;
+	const char *mem_usage = NULL;
+	const char *vmem_usage = NULL;
+	const char *walltime = NULL;
+	long unsigned int modify_time = 0;
+
+	fsd_log_enter(( "({job_id=%s})", self->job_id ));
+#ifdef DEBUGGING
+	pbsdrmaa_dump_attrl( attribs, NULL );
+#endif
+	fsd_assert( !strcmp( self->job_id, status->name ) );
+
+	for( i = attribs;  i != NULL;  i = i->next )
+	 {
+		int attr;
+		attr = pbsdrmaa_pbs_attrib_by_name( i->name );
+		switch( attr )
+		 {
+			case PBSDRMAA_ATTR_JOB_STATE:
+				pbs_state = i->value[0];				
+				break;
+			case PBSDRMAA_ATTR_EXIT_STATUS:
+				exit_status = atoi( i->value );
+				break;
+			case PBSDRMAA_ATTR_RESOURCES_USED:
+				if( !strcmp( i->resource, "cput" ) )
+					cpu_usage = i->value;
+				else if( !strcmp( i->resource, "mem" ) )
+					mem_usage = i->value;
+				else if( !strcmp( i->resource, "vmem" ) )
+					vmem_usage = i->value;
+				else if( !strcmp( i->resource, "walltime" ) )
+					walltime = i->value;
+				break;
+			case PBSDRMAA_ATTR_QUEUE:
+				if (!self->queue)
+					self->queue = fsd_strdup(i->value);
+				break;
+			case PBSDRMAA_ATTR_ACCOUNT_NAME:
+				if (!self->project)
+					self->project = fsd_strdup(i->value);
+				break;
+			case PBSDRMAA_ATTR_EXECUTION_HOST:
+				if (!self->execution_hosts) {
+					fsd_log_debug(("execution_hosts = %s", i->value));
+					self->execution_hosts = fsd_strdup(i->value);
+				}
+				break;
+			case PBSDRMAA_ATTR_START_TIME:
+				{
+				  long unsigned int start_time;
+				  if (self->start_time == 0 && sscanf(i->value, "%lu", &start_time) == 1)
+					self->start_time = start_time;
+				  break;
+				}
+			case PBSDRMAA_ATTR_MTIME:
+				if (sscanf(i->value, "%lu", &modify_time) != 1)
+					modify_time = 0;
+				break;
+		 }
+	 }
+
+	if( pbs_state )
+		fsd_log_debug(( "pbs_state: %c", pbs_state ));
+
+	if( exit_status != -2 )
+	 {
+		fsd_log_debug(( "exit_status: %d", exit_status ));
+		self->exit_status = exit_status;
+	 }
+	if(pbs_state){
+		switch( pbs_state )
+		 {
+			case 'C': /* Job is completed after having run. */
+				self->flags &= FSD_JOB_TERMINATED_MASK;
+				self->flags |= FSD_JOB_TERMINATED;
+				if (exit_status != -2) { /* has exit code */
+					if( self->exit_status == 0) 
+						self->state = DRMAA_PS_DONE;
+					else 
+						self->state = DRMAA_PS_FAILED;
+				} else {
+					self->state = DRMAA_PS_FAILED;
+					self->exit_status = -1;
+				}
+				self->end_time = modify_time; /* take last modify time as end time */
+				break;
+			case 'E': /* Job is exiting after having run. - MM: ignore exiting state (transient state) - outputs might have not been transfered yet, 
+					MM2: mark job as running if current job status is undetermined - fix "ps after job was ripped" */
+				if (self->state == DRMAA_PS_UNDETERMINED)
+					self->state = DRMAA_PS_RUNNING;
+				break;
+			case 'H': /* Job is held. */
+				self->state = DRMAA_PS_USER_ON_HOLD;
+				self->flags |= FSD_JOB_HOLD;
+				break;
+			case 'Q': /* Job is queued, eligible to run or routed. */
+			case 'W': /* Job is waiting for its execution time to be reached. */
+				self->state = DRMAA_PS_QUEUED_ACTIVE;
+				self->flags &= ~FSD_JOB_HOLD;
+				break;
+			case 'R': /* Job is running. */
+			case 'T': /* Job is being moved to new location (?). */
+			 {
+				if( self->flags & FSD_JOB_SUSPENDED )
+					self->state = DRMAA_PS_USER_SUSPENDED;
+				else
+					self->state = DRMAA_PS_RUNNING;
+				break;
+			 }
+			case 'S': /* (Unicos only) job is suspend. */
+				self->state = DRMAA_PS_SYSTEM_SUSPENDED;
+				break;
+			case 0:  default:
+				self->state = DRMAA_PS_UNDETERMINED;
+				break;
+	 }
+}
+	fsd_log_debug(( "job_ps: %s", drmaa_job_ps_to_str(self->state) ));
+
+	 {
+		int hours, minutes, seconds;
+		long mem;
+		if( cpu_usage && sscanf( cpu_usage, "%d:%d:%d", &hours, &minutes, &seconds ) == 3 )
+		 {
+			self->cpu_usage = 60*( 60*hours + minutes ) + seconds;
+			fsd_log_debug(( "cpu_usage: %s=%lds", cpu_usage, self->cpu_usage ));
+		 }
+		if( mem_usage && sscanf( mem_usage, "%ldkb", &mem ) == 1 )
+		 {
+			self->mem_usage = 1024*mem;
+			fsd_log_debug(( "mem_usage: %s=%ldB", mem_usage, self->mem_usage ));
+		 }
+		if( vmem_usage && sscanf( vmem_usage, "%ldkb", &mem ) == 1 )
+		 {
+			self->vmem_usage = 1024*mem;
+			fsd_log_debug(( "vmem_usage: %s=%ldB", vmem_usage, self->vmem_usage ));
+		 }
+		if( walltime && sscanf( walltime, "%d:%d:%d", &hours, &minutes, &seconds ) == 3 )
+		 {
+			self->walltime = 60*( 60*hours + minutes ) + seconds;
+			fsd_log_debug(( "walltime: %s=%lds", walltime, self->walltime ));
+		 }
+	 }
+}
+
+void
+pbsdrmaa_job_on_missing( fsd_job_t *self )
+{
+	pbsdrmaa_session_t *pbssession = (pbsdrmaa_session_t*)self->session;
+
+	if( pbssession->pbs_home == NULL || pbssession->super.wait_thread_started )
+		pbsdrmaa_job_on_missing_standard( self );	
+	else
+		pbsdrmaa_job_on_missing_log_based( self );	
+}
+
+void
+pbsdrmaa_job_on_missing_standard( fsd_job_t *self )
+{
+	fsd_drmaa_session_t *session = self->session;
+	
+	unsigned missing_mask = 0;
+
+	fsd_log_enter(( "({job_id=%s})", self->job_id ));
+	fsd_log_warning(( "Job %s missing from DRM queue", self->job_id ));
+
+	switch( session->missing_jobs )
+	{
+		case FSD_REVEAL_MISSING_JOBS:         missing_mask = 0;     break;
+		case FSD_IGNORE_MISSING_JOBS:         missing_mask = 0x73;  break;
+		case FSD_IGNORE_QUEUED_MISSING_JOBS:  missing_mask = 0x13;  break;
+	}
+	fsd_log_debug(( "last job_ps: %s (0x%02x); mask: 0x%02x",
+				drmaa_job_ps_to_str(self->state), self->state, missing_mask ));
+
+	if( self->state < DRMAA_PS_DONE
+			&&  (self->state & ~missing_mask) )
+		fsd_exc_raise_fmt(
+				FSD_DRMAA_ERRNO_INVALID_JOB,
+				"self %s missing from queue", self->job_id
+				);
+
+	if( (self->flags & FSD_JOB_TERMINATED_MASK) == 0 )
+	{
+		self->flags &= FSD_JOB_TERMINATED_MASK;
+		self->flags |= FSD_JOB_TERMINATED;
+	}
+
+	if( (self->flags & FSD_JOB_ABORTED) == 0
+			&&  session->missing_jobs == FSD_IGNORE_MISSING_JOBS )
+	{ /* assume everthing was ok */
+		self->state = DRMAA_PS_DONE;
+		self->exit_status = 0;
+	}
+	else
+	{ /* job aborted */
+		self->state = DRMAA_PS_FAILED;
+		self->exit_status = -1;
+	}
+
+	fsd_cond_broadcast( &self->status_cond);
+
+	fsd_log_return(( "; job_ps=%s, exit_status=%d",
+				drmaa_job_ps_to_str(self->state), self->exit_status ));
+}
+
+void
+pbsdrmaa_job_on_missing_log_based( fsd_job_t *self )
+{
+	fsd_drmaa_session_t *session = self->session;
+	pbsdrmaa_log_reader_t *log_reader = NULL;
+	
+	fsd_log_enter(( "({job_id=%s})", self->job_id ));
+	fsd_log_info(( "Job %s missing from DRM queue", self->job_id ));
+	
+	TRY
+	{	
+		log_reader = pbsdrmaa_log_reader_new( session, self);
+		log_reader->read_log( log_reader ); 
+	}
+	FINALLY
+	{
+		pbsdrmaa_log_reader_destroy( log_reader );
+	}
+	END_TRY
+
+	fsd_log_return(( "; job_ps=%s, exit_status=%d",
+				drmaa_job_ps_to_str(self->state), self->exit_status ));	
+}
Index: /branches/2.0/pbs_drmaa/pbs_attrib.gperf
===================================================================
--- /branches/2.0/pbs_drmaa/pbs_attrib.gperf	(revision 12)
+++ /branches/2.0/pbs_drmaa/pbs_attrib.gperf	(revision 12)
@@ -0,0 +1,217 @@
+%{
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2009  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <drmaa_utils/drmaa_attrib.h>
+#include <drmaa_utils/template.h>
+#include <pbs_drmaa/pbs_attrib.h>
+
+#ifndef lint
+static char rcsid[]
+#	ifdef __GNUC__
+		__attribute__ ((unused))
+#	endif
+	= "$Id$";
+#endif
+
+extern const fsd_attribute_t pbsdrmaa_pbs_attributes[];
+#define t(code) \
+	( & pbsdrmaa_pbs_attributes[ code ] )
+%}
+
+%language=ANSI-C
+%includes
+%readonly-tables
+%pic
+%define lookup-function-name pbsdrmaa_pbs_attrib_lookup
+%struct-type
+struct pbs_attrib { int name; const fsd_attribute_t *attr; }
+
+%%
+Execution_Time, t(PBSDRMAA_ATTR_EXECUTION_TIME)
+Checkpoint, t(PBSDRMAA_ATTR_CHECKPOINT)
+Error_Path, t(PBSDRMAA_ATTR_ERROR_PATH)
+group_list, t(PBSDRMAA_ATTR_GROUPS)
+Hold_Types, t(PBSDRMAA_ATTR_HOLD_TYPES)
+Join_Path, t(PBSDRMAA_ATTR_JOIN_FILES)
+Keep_Files, t(PBSDRMAA_ATTR_KEEP_FILES)
+# Resource_List, t(PBSDRMAA_ATTR_RESOURCES)
+Resource_List.cput, t(PBSDRMAA_ATTR_CPU_TIME_LIMIT)
+Resource_List.file, t(PBSDRMAA_ATTR_FILE_SIZE_LIMIT)
+Resource_List.nice, t(PBSDRMAA_ATTR_NICE)
+Resource_List.vmem, t(PBSDRMAA_ATTR_VMEM_LIMIT)
+Resource_List.mem, t(PBSDRMAA_ATTR_MEM_LIMIT)
+Resource_List.pcput, t(PBSDRMAA_ATTR_SINGLE_CPU_TIME_LIMIT)
+Resource_List.pmem, t(PBSDRMAA_ATTR_SINGLE_RSS_LIMIT)
+Resource_List.pvmem, t(PBSDRMAA_ATTR_SINGLE_VMEM_LIMIT)
+Resource_List.walltime, t(PBSDRMAA_ATTR_WALLTIME_LIMIT)
+Resource_List.arch, t(PBSDRMAA_ATTR_ARCHITECTURE)
+Resource_List.host, t(PBSDRMAA_ATTR_HOST)
+Resource_List.nodes, t(PBSDRMAA_ATTR_NODES)
+Resource_List.software, t(PBSDRMAA_ATTR_SOFTWARE)
+Mail_Points, t(PBSDRMAA_ATTR_MAIL_POINTS)
+Output_Path, t(PBSDRMAA_ATTR_OUTPUT_PATH)
+Priority, t(PBSDRMAA_ATTR_PRIORITY)
+destination, t(PBSDRMAA_ATTR_DESITINATION)
+Rerunable, t(PBSDRMAA_ATTR_RERUNABLE)
+job_array_request, t(PBSDRMAA_ATTR_BULK_REQ)
+job_array_id, t(PBSDRMAA_ATTR_BULK_IDX)
+User_List, t(PBSDRMAA_ATTR_USERS)
+Variable_List, t(PBSDRMAA_ATTR_JOB_ENVIRONMENT)
+Account_Name, t(PBSDRMAA_ATTR_ACCOUNT_NAME)
+Mail_Users, t(PBSDRMAA_ATTR_EMAIL)
+Job_Name, t(PBSDRMAA_ATTR_JOB_NAME)
+Shell_Path_List, t(PBSDRMAA_ATTR_SHELL)
+depend, t(PBSDRMAA_ATTR_DEPEND)
+interactive, t(PBSDRMAA_ATTR_INTERACTIVE)
+stagein, t(PBSDRMAA_ATTR_STAGEIN)
+stageout, t(PBSDRMAA_ATTR_STAGEOUT)
+# additional job and general attribute names
+exec_host, t(PBSDRMAA_ATTR_EXECUTION_HOST)
+Job_Owner, t(PBSDRMAA_ATTR_JOB_OWNER)
+resources_used, t(PBSDRMAA_ATTR_RESOURCES_USED)
+job_state, t(PBSDRMAA_ATTR_JOB_STATE)
+queue, t(PBSDRMAA_ATTR_QUEUE)
+server, t(PBSDRMAA_ATTR_SERVER)
+comment, t(PBSDRMAA_ATTR_COMMENT)
+exit_status, t(PBSDRMAA_ATTR_EXIT_STATUS)
+start_time, t(PBSDRMAA_ATTR_START_TIME)
+x, t(PBSDRMAA_ATTR_EXTENSION)
+submit_args, t(PBSDRMAA_ATTR_SUBMIT_ARGS)
+mtime, t(PBSDRMAA_ATTR_MTIME)
+# reservation attributes:
+# reserve_start,       t(PBSDRMAA_ATTR_RESERVATION_START)
+# reserve_end,         t(PBSDRMAA_ATTR_RESERVATION_END)
+# reserve_duration,    t(PBSDRMAA_ATTR_RESERVATION_DURATION)
+# reserve_state,       t(PBSDRMAA_ATTR_RESERVATION_STATE)
+# reserve_substate,    t(PBSDRMAA_ATTR_RESERVATION_SUBSTATE)
+%%
+#undef t
+
+int
+pbsdrmaa_pbs_attrib_by_name( const char *name )
+{
+	const struct pbs_attrib *found;
+	found = pbsdrmaa_pbs_attrib_lookup( name, strlen(name) );
+	if( found )
+		return found->attr->code;
+	else
+		return -1;
+}
+
+static const fsd_attribute_t *
+pbsdrmaa_pbs_template_by_name( const fsd_template_t *self, const char *name )
+{
+	const struct pbs_attrib *found;
+	found = pbsdrmaa_pbs_attrib_lookup( name, strlen(name) );
+	if( found != NULL )
+	 {
+		fsd_assert( found->attr - pbsdrmaa_pbs_attributes == found->attr->code );
+		return found->attr;
+	 }
+	else
+		fsd_exc_raise_fmt(
+				FSD_ERRNO_INVALID_ARGUMENT,
+				"invalid PBS attribute name: %s", name
+				);
+}
+
+
+static const fsd_attribute_t *
+pbsdrmaa_pbs_template_by_code( const fsd_template_t *self, int code )
+{
+	if( 0 <= code  &&  code < PBSDRMAA_N_PBS_ATTRIBUTES )
+	 {
+		fsd_assert( pbsdrmaa_pbs_attributes[code].code == code );
+		return & pbsdrmaa_pbs_attributes[ code ];
+	 }
+	else
+		fsd_exc_raise_fmt(
+				FSD_ERRNO_INVALID_ARGUMENT,
+				"invalid PBS attribute code: %d", code
+				);
+}
+
+
+fsd_template_t *
+pbsdrmaa_pbs_template_new(void)
+{
+	return fsd_template_new(
+			pbsdrmaa_pbs_template_by_name,
+			pbsdrmaa_pbs_template_by_code,
+			PBSDRMAA_N_PBS_ATTRIBUTES
+			);
+}
+
+const fsd_attribute_t pbsdrmaa_pbs_attributes[ PBSDRMAA_N_PBS_ATTRIBUTES ] = {
+	{ "Execution_Time", PBSDRMAA_ATTR_EXECUTION_TIME, false },
+	{ "Checkpoint", PBSDRMAA_ATTR_CHECKPOINT, false },
+	{ "Error_Path", PBSDRMAA_ATTR_ERROR_PATH, false },
+	{ "group_list", PBSDRMAA_ATTR_GROUPS, false },
+	{ "Hold_Types", PBSDRMAA_ATTR_HOLD_TYPES, false },
+	{ "Join_Path", PBSDRMAA_ATTR_JOIN_FILES, false },
+	{ "Keep_Files", PBSDRMAA_ATTR_KEEP_FILES, false },
+	{ "Resource_List.cput", PBSDRMAA_ATTR_CPU_TIME_LIMIT, false },
+	{ "Resource_List.file", PBSDRMAA_ATTR_FILE_SIZE_LIMIT, false },
+	{ "Resource_List.nice", PBSDRMAA_ATTR_NICE, false },
+	{ "Resource_List.vmem", PBSDRMAA_ATTR_VMEM_LIMIT, false },
+	{ "Resource_List.mem", PBSDRMAA_ATTR_MEM_LIMIT, false },
+	{ "Resource_List.pcput", PBSDRMAA_ATTR_SINGLE_CPU_TIME_LIMIT, false },
+	{ "Resource_List.pmem", PBSDRMAA_ATTR_SINGLE_RSS_LIMIT, false },
+	{ "Resource_List.pvmem", PBSDRMAA_ATTR_SINGLE_VMEM_LIMIT, false },
+	{ "Resource_List.walltime", PBSDRMAA_ATTR_WALLTIME_LIMIT, false },
+	{ "Resource_List.arch", PBSDRMAA_ATTR_ARCHITECTURE, false },
+	{ "Resource_List.host", PBSDRMAA_ATTR_HOST, false },
+	{ "Resource_List.nodes", PBSDRMAA_ATTR_NODES, false },
+	{ "Resource_List.software", PBSDRMAA_ATTR_SOFTWARE, false },
+	{ "Mail_Points", PBSDRMAA_ATTR_MAIL_POINTS, false },
+	{ "Output_Path", PBSDRMAA_ATTR_OUTPUT_PATH, false },
+	{ "Priority", PBSDRMAA_ATTR_PRIORITY, false },
+	{ "destination", PBSDRMAA_ATTR_DESITINATION, false },
+	{ "Rerunable", PBSDRMAA_ATTR_RERUNABLE, false },
+	{ "job_array_request", PBSDRMAA_ATTR_BULK_REQ, false },
+	{ "job_array_id", PBSDRMAA_ATTR_BULK_IDX, false },
+	{ "User_List", PBSDRMAA_ATTR_USERS, false },
+	{ "Variable_List", PBSDRMAA_ATTR_JOB_ENVIRONMENT, false },
+	{ "Account_Name", PBSDRMAA_ATTR_ACCOUNT_NAME, false },
+	{ "Mail_Users", PBSDRMAA_ATTR_EMAIL, false },
+	{ "Job_Name", PBSDRMAA_ATTR_JOB_NAME, false },
+	{ "Shell_Path_List", PBSDRMAA_ATTR_SHELL, false },
+	{ "depend", PBSDRMAA_ATTR_DEPEND, false },
+	{ "interactive", PBSDRMAA_ATTR_INTERACTIVE, false },
+	{ "stagein", PBSDRMAA_ATTR_STAGEIN, false },
+	{ "stageout", PBSDRMAA_ATTR_STAGEOUT, false },
+	{ "exec_host", PBSDRMAA_ATTR_EXECUTION_HOST, false },
+	{ "Job_Owner", PBSDRMAA_ATTR_JOB_OWNER, false },
+	{ "resources_used", PBSDRMAA_ATTR_RESOURCES_USED, false },
+	{ "job_state", PBSDRMAA_ATTR_JOB_STATE, false },
+	{ "queue", PBSDRMAA_ATTR_QUEUE, false },
+	{ "server", PBSDRMAA_ATTR_SERVER, false },
+	{ "comment", PBSDRMAA_ATTR_COMMENT, false },
+	{ "exit_status", PBSDRMAA_ATTR_EXIT_STATUS, false },
+	{ "start_time", PBSDRMAA_ATTR_START_TIME, false },
+	{ "x", PBSDRMAA_ATTR_EXTENSION, false },
+	{ "submit_args", PBSDRMAA_ATTR_SUBMIT_ARGS, false },
+	{ "mtime", PBSDRMAA_ATTR_MTIME, false },
+};
+
+/* vim: set ft=c: */
Index: /branches/2.0/pbs_drmaa/util.c
===================================================================
--- /branches/2.0/pbs_drmaa/util.c	(revision 16)
+++ /branches/2.0/pbs_drmaa/util.c	(revision 16)
@@ -0,0 +1,331 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2007  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @file pbs_drmaa/util.c
+ * PBS DRMAA utilities.
+ */
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <drmaa_utils/common.h>
+#include <pbs_drmaa/util.h>
+#include <pbs_error.h>
+#include <pbs_ifl.h>
+
+#ifndef lint
+static char rcsid[]
+#	ifdef __GNUC__
+		__attribute__ ((unused))
+#	endif
+	= "$Id$";
+#endif
+
+
+void
+pbsdrmaa_dump_attrl( const struct attrl *attribute_list, const char *prefix )
+{
+	const struct attrl *i;
+
+	if( prefix == NULL )
+		prefix = "";
+	for( i = attribute_list;  i != NULL;  i = i->next )
+		fsd_log_debug(( "\n %s %s%s%s=%s",
+				prefix, i->name,
+				i->resource ? "." : "",  i->resource ? i->resource : "",
+				i->value
+				));
+}
+
+
+void
+pbsdrmaa_free_attrl( struct attrl *attr )
+{
+	while( attr != NULL )
+	 {
+		struct attrl *p = attr;
+		attr = attr->next;
+		fsd_free( p->name );
+		fsd_free( p->value );
+		fsd_free( p->resource );
+		fsd_free( p );
+	 }
+}
+
+
+void
+pbsdrmaa_exc_raise_pbs( const char *function )
+{
+	int _pbs_errno;
+	int fsd_errno;
+	const char *message = NULL;
+
+	_pbs_errno = pbs_errno;
+
+#ifndef PBS_PROFESSIONAL_NO_LOG
+	message = pbse_to_txt( pbs_errno );
+#else
+	message = "pbs error";
+#endif
+
+	fsd_errno = pbsdrmaa_map_pbs_errno( _pbs_errno );
+	fsd_log_error((
+				"call to %s returned with error %d:%s mapped to %d:%s",
+				function,
+				_pbs_errno, message,
+				fsd_errno, fsd_strerror(fsd_errno)
+				));
+	fsd_exc_raise_fmt( fsd_errno, "%s: %s", function, message );
+}
+
+
+/** Maps PBS error code into DMRAA code. */
+int
+pbsdrmaa_map_pbs_errno( int _pbs_errno )
+{
+	fsd_log_enter(( "(pbs_errno=%d)", _pbs_errno ));
+	switch( _pbs_errno )
+	 {
+		case PBSE_NONE:  /* no error */
+			return FSD_ERRNO_SUCCESS;
+		case PBSE_UNKJOBID:	 /* Unknown Job Identifier */
+			return FSD_DRMAA_ERRNO_INVALID_JOB;
+		case PBSE_NOATTR: /* Undefined Attribute */
+		case PBSE_ATTRRO: /* attempt to set READ ONLY attribute */
+		case PBSE_IVALREQ:  /* Invalid request */
+		case PBSE_UNKREQ:  /* Unknown batch request */
+			return FSD_ERRNO_INTERNAL_ERROR;
+		case PBSE_PERM:  /* No permission */
+		case PBSE_BADHOST:  /* access from host not allowed */
+			return FSD_ERRNO_AUTHZ_FAILURE;
+		case PBSE_JOBEXIST:  /* job already exists */
+		case PBSE_SVRDOWN:  /* req rejected -server shutting down */
+		case PBSE_EXECTHERE:  /* cannot execute there */
+		case PBSE_NOSUP:  /* Feature/function not supported */
+		case PBSE_EXCQRESC:  /* Job exceeds Queue resource limits */
+		case PBSE_QUENODFLT:  /* No Default Queue Defined */
+		case PBSE_NOTSNODE:  /* no time-shared nodes */
+			return FSD_ERRNO_DENIED_BY_DRM;
+		case PBSE_SYSTEM:  /* system error occurred */
+		case PBSE_INTERNAL:  /* internal server error occurred */
+		case PBSE_REGROUTE:  /* parent job of dependent in rte que */
+		case PBSE_UNKSIG:  /* unknown signal name */
+			return FSD_ERRNO_INTERNAL_ERROR;
+		case PBSE_BADATVAL:  /* bad attribute value */
+		case PBSE_BADATLST:  /* Bad attribute list structure */
+		case PBSE_BADUSER:  /* Bad user - no password entry */
+		case PBSE_BADGRP:  /* Bad Group specified */
+		case PBSE_BADACCT:  /* Bad Account attribute value */
+		case PBSE_UNKQUE:  /* Unknown queue name */
+		case PBSE_UNKRESC:  /* Unknown resource */
+		case PBSE_UNKNODEATR:  /* node-attribute not recognized */
+		case PBSE_BADNDATVAL:  /* Bad node-attribute value */
+		case PBSE_BADDEPEND:  /* Invalid dependency */
+		case PBSE_DUPLIST:  /* Duplicate entry in List */
+			return FSD_ERRNO_INVALID_VALUE;
+		case PBSE_MODATRRUN:  /* Cannot modify attrib in run state */
+		case PBSE_BADSTATE:  /* request invalid for job state */
+		case PBSE_BADCRED:  /* Invalid Credential in request */
+		case PBSE_EXPIRED:  /* Expired Credential in request */
+		case PBSE_QUNOENB:  /* Queue not enabled */
+			return FSD_ERRNO_INTERNAL_ERROR;
+		case PBSE_QACESS:  /* No access permission for queue */
+			return FSD_ERRNO_AUTHZ_FAILURE;
+		case PBSE_HOPCOUNT:  /* Max hop count exceeded */
+		case PBSE_QUEEXIST:  /* Queue already exists */
+		case PBSE_ATTRTYPE:  /* incompatable queue attribute type */
+			return FSD_ERRNO_INTERNAL_ERROR;
+#		ifdef PBSE_QUEBUSY
+		case PBSE_QUEBUSY:  /* Queue Busy (not empty) */
+#		endif
+		case PBSE_MAXQUED:  /* Max number of jobs in queue */
+		case PBSE_NOCONNECTS:  /* No free connections */
+		case PBSE_TOOMANY:  /* Too many submit retries */
+		case PBSE_RESCUNAV:  /* Resources temporarily unavailable */
+			return FSD_ERRNO_TRY_LATER;
+		case 111:
+		case PBSE_PROTOCOL:  /* Protocol (ASN.1) error */
+		case PBSE_DISPROTO:  /* Bad DIS based Request Protocol */
+			return FSD_ERRNO_DRM_COMMUNICATION_FAILURE;
+#if 0
+		case PBSE_QUENBIG:  /* Queue name too long */
+		case PBSE_QUENOEN:  /* Cannot enable queue,needs add def */
+		case PBSE_NOSERVER:  /* No server to connect to */
+		case PBSE_NORERUN:  /* Job Not Rerunnable */
+		case PBSE_ROUTEREJ:  /* Route rejected by all destinations */
+		case PBSE_ROUTEEXPD:  /* Time in Route Queue Expired */
+		case PBSE_MOMREJECT:  /* Request to MOM failed */
+		case PBSE_BADSCRIPT:  /* (qsub) cannot access script file */
+		case PBSE_STAGEIN:  /* Stage In of files failed */
+		case PBSE_CKPBSY:  /* Checkpoint Busy, may be retries */
+		case PBSE_EXLIMIT:  /* Limit exceeds allowable */
+		case PBSE_ALRDYEXIT:  /* Job already in exit state */
+		case PBSE_NOCOPYFILE:  /* Job files not copied */
+		case PBSE_CLEANEDOUT:  /* unknown job id after clean init */
+		case PBSE_NOSYNCMSTR:  /* No Master in Sync Set */
+		case PBSE_SISREJECT:  /* sister rejected */
+		case PBSE_SISCOMM:  /* sister could not communicate */
+		case PBSE_CKPSHORT:  /* not all tasks could checkpoint */
+		case PBSE_UNKNODE:  /* Named node is not in the list */
+		case PBSE_NONODES:  /* Server has no node list */
+		case PBSE_NODENBIG:  /* Node name is too big */
+		case PBSE_NODEEXIST:  /* Node name already exists */
+		case PBSE_MUTUALEX:  /* State values are mutually exclusive */
+		case PBSE_GMODERR:  /* Error(s) during global modification of nodes */
+		case PBSE_NORELYMOM:  /* could not contact Mom */
+			return FSD_ERRNO_INTERNAL_ERROR;
+#endif
+		default:
+			return FSD_ERRNO_INTERNAL_ERROR;
+	 }
+}
+
+
+char *
+pbsdrmaa_write_tmpfile( const char *content, size_t len )
+{
+	static const char *tmpfile_template = "/tmp/pbs_drmaa.XXXXXX";
+	char *volatile name = NULL;
+	volatile int fd = -1;
+
+	fsd_log_enter(( "" ));
+
+	TRY
+	 {
+		name = fsd_strdup( tmpfile_template );
+		fd = mkstemp( name );
+		if( fd < 0 )
+			fsd_exc_raise_sys(0);
+		while( len > 0 )
+		 {
+			size_t written = write( fd, content, len );
+			if( written != (size_t)-1 )
+			 {
+				content += written;
+				len -= written;
+			 }
+			else
+				fsd_exc_raise_sys(0);
+		 }
+	 }
+	EXCEPT_DEFAULT
+	 { fsd_free( name ); }
+	FINALLY
+	 {
+		if( fd >= 0 )
+		 {
+			if( close( fd ) )
+				fsd_exc_raise_sys(0);
+		 }
+	 }
+	END_TRY
+
+	fsd_log_return(( "=%s", name ));
+	return name;
+}
+
+ssize_t fsd_getline(char * line,ssize_t size, int fd)
+{
+	char buf;
+	char * ptr = NULL;
+	ssize_t n = 0, rc;
+	ptr = line;
+	for(n = 1; n< size; n++)
+	{		
+		if( (rc = read(fd,&buf,1 )) == 1) {
+			*ptr++ = buf;
+			if(buf == '\n')
+			{
+				break;
+			}
+		}
+		else if (rc == 0) {
+			if (n == 1)
+				return 0;
+			else
+				break;
+		}		
+		else
+			return -1; 
+	}
+
+	return n;
+} 
+
+ssize_t fsd_getline_buffered(char * line,char * buf, ssize_t size, int fd, int * idx, int * end_idx, int * line_idx)
+{
+	int i = -1;
+	int rc = -1;
+
+	memset(line,0,size);
+	
+start:
+	/* idx - start of data to parse (in buffer)
+	   end_idx - end of data read from log (in buffer)
+	   line_idx - place to write data in output line */
+	if(*idx < *end_idx)
+	{
+		/* take line from buffer */
+		for(i = *idx; i<= *end_idx;i++)
+		{		
+			if(buf[i] == '\n')
+			{
+				int tmp = i - *idx;
+				strncpy(line + *line_idx,buf + *idx,tmp);				
+				*idx = i + 1;
+			
+				tmp+= *line_idx;
+				*line_idx = 0;
+				
+				return tmp;
+			}
+		}
+		
+		/* there was no '\n' so next part of log needs to be read. save lines beginning */
+		if(*line_idx + i - *idx > size )
+			fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"Line longer than %d unsupported",size);
+		
+		strncpy(line + *line_idx,buf + *idx,i - *idx);
+		*line_idx += i - *idx;
+		*idx = 0;
+		*end_idx = 0;
+		goto start;
+	}
+	else
+	{		
+		/* read log */
+		if((rc = read(fd,buf,size)) > 0)
+		{		
+			*end_idx = rc - 1;
+			*idx = 0;
+			goto start;
+		}
+		else if (rc == 0) 
+			return 0;
+		else
+			return -1;
+	}
+} 
+
Index: /branches/2.0/pbs_drmaa/job.h
===================================================================
--- /branches/2.0/pbs_drmaa/job.h	(revision 12)
+++ /branches/2.0/pbs_drmaa/job.h	(revision 12)
@@ -0,0 +1,48 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2009  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __PBS_DRMAA__JOB_H
+#define __PBS_DRMAA__JOB_H
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <drmaa_utils/job.h>
+
+typedef struct pbsdrmaa_job_s pbsdrmaa_job_t;
+
+/* Do not depend on <pbs_ifl.h> */
+struct batch_status;
+
+fsd_job_t *
+pbsdrmaa_job_new( char *job_id );
+
+struct pbsdrmaa_job_s {
+	fsd_job_t super;
+
+	void (*
+	update)( fsd_job_t *self, struct batch_status *status );
+};
+
+void
+pbsdrmaa_job_on_missing_standard( fsd_job_t *self );
+
+#endif /* __PBS_DRMAA__JOB_H */
+
Index: /branches/2.0/pbs_drmaa/util.h
===================================================================
--- /branches/2.0/pbs_drmaa/util.h	(revision 12)
+++ /branches/2.0/pbs_drmaa/util.h	(revision 12)
@@ -0,0 +1,52 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2009  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __PBS_DRMAA__UTIL_H
+#define __PBS_DRMAA__UTIL_H
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+void pbsdrmaa_exc_raise_pbs( const char *function );
+int pbsdrmaa_map_pbs_errno( int _pbs_errno );
+
+struct attrl;
+
+void pbsdrmaa_free_attrl( struct attrl *list );
+void pbsdrmaa_dump_attrl(
+		const struct attrl *attribute_list, const char *prefix );
+
+/**
+ * Writes temporary file.
+ * @param content   Buffer with content to write.
+ * @param len       Buffer's length.
+ * @return Path to temporary file.
+ */
+char *
+pbsdrmaa_write_tmpfile( const char *content, size_t len );
+
+ssize_t
+fsd_getline(char * line,ssize_t size, int fd);
+
+ssize_t 
+fsd_getline_buffered(char * line,char * buf, ssize_t size, int fd, int * idx, int * end_idx, int * line_idx);
+
+#endif /* __PBS_DRMAA__UTIL_H */
+
Index: /branches/2.0/pbs_drmaa/session.c
===================================================================
--- /branches/2.0/pbs_drmaa/session.c	(revision 12)
+++ /branches/2.0/pbs_drmaa/session.c	(revision 12)
@@ -0,0 +1,533 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2009  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/select.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include <pbs_ifl.h>
+#include <pbs_error.h>
+
+#include <drmaa_utils/datetime.h>
+#include <drmaa_utils/drmaa.h>
+#include <drmaa_utils/iter.h>
+#include <drmaa_utils/conf.h>
+#include <drmaa_utils/session.h>
+#include <drmaa_utils/datetime.h>
+
+#include <pbs_drmaa/job.h>
+#include <pbs_drmaa/log_reader.h>
+#include <pbs_drmaa/session.h>
+#include <pbs_drmaa/submit.h>
+#include <pbs_drmaa/util.h>
+
+#include <errno.h>
+
+#ifndef lint
+static char rcsid[]
+#	ifdef __GNUC__
+		__attribute__ ((unused))
+#	endif
+	= "$Id$";
+#endif
+
+static void
+pbsdrmaa_session_destroy( fsd_drmaa_session_t *self );
+
+static void 
+pbsdrmaa_session_apply_configuration( fsd_drmaa_session_t *self );
+
+static fsd_job_t *
+pbsdrmaa_session_new_job( fsd_drmaa_session_t *self, const char *job_id );
+
+static bool
+pbsdrmaa_session_do_drm_keeps_completed_jobs( pbsdrmaa_session_t *self );
+
+static void
+pbsdrmaa_session_update_all_jobs_status( fsd_drmaa_session_t *self );
+
+static void 
+*pbsdrmaa_session_wait_thread( fsd_drmaa_session_t *self );
+
+static char *
+pbsdrmaa_session_run_impl(
+		fsd_drmaa_session_t *self,
+		const fsd_template_t *jt,
+		int bulk_idx
+		);
+
+static struct attrl *
+pbsdrmaa_create_status_attrl(void);
+
+
+fsd_drmaa_session_t *
+pbsdrmaa_session_new( const char *contact )
+{
+	pbsdrmaa_session_t *volatile self = NULL;
+
+	if( contact == NULL )
+		contact = "";
+	TRY
+	 {
+		self = (pbsdrmaa_session_t*)fsd_drmaa_session_new(contact);
+		fsd_realloc( self, 1, pbsdrmaa_session_t );
+		self->super_wait_thread = NULL;
+
+		self->log_file_initial_size = 0;
+		self->pbs_conn = -1;
+		self->pbs_home = NULL;
+
+		self->wait_thread_log = false;
+		self->status_attrl = NULL;
+		
+		self->super_destroy = self->super.destroy;
+		self->super.destroy = pbsdrmaa_session_destroy;
+		self->super.new_job = pbsdrmaa_session_new_job;
+		self->super.update_all_jobs_status
+				= pbsdrmaa_session_update_all_jobs_status;
+		self->super.run_impl = pbsdrmaa_session_run_impl;
+
+		self->super_apply_configuration = self->super.apply_configuration;
+		self->super.apply_configuration = pbsdrmaa_session_apply_configuration;
+
+		self->do_drm_keeps_completed_jobs =
+			pbsdrmaa_session_do_drm_keeps_completed_jobs;
+
+		self->status_attrl = pbsdrmaa_create_status_attrl();
+
+		self->pbs_conn = pbs_connect( self->super.contact );
+		fsd_log_info(( "pbs_connect(%s) =%d", self->super.contact,
+					self->pbs_conn ));
+		if( self->pbs_conn < 0 )
+			pbsdrmaa_exc_raise_pbs( "pbs_connect" );
+
+		self->super.load_configuration( &self->super, "pbs_drmaa" );
+
+		self->super.missing_jobs = FSD_IGNORE_MISSING_JOBS;
+		if( self->do_drm_keeps_completed_jobs( self ) )
+			self->super.missing_jobs = FSD_IGNORE_QUEUED_MISSING_JOBS;
+	 }
+	EXCEPT_DEFAULT
+	 {
+		if( self )
+		  {
+			self->super.destroy( &self->super );
+			self = NULL;
+		  }
+	 }
+	END_TRY
+	return (fsd_drmaa_session_t*)self;
+}
+
+
+void
+pbsdrmaa_session_destroy( fsd_drmaa_session_t *self )
+{
+	pbsdrmaa_session_t *pbsself = (pbsdrmaa_session_t*)self;
+	self->stop_wait_thread( self );
+	if( pbsself->pbs_conn >= 0 )
+		pbs_disconnect( pbsself->pbs_conn );
+	fsd_free( pbsself->status_attrl );
+	pbsself->super_destroy( self );	
+}
+
+
+static char *
+pbsdrmaa_session_run_impl(
+		fsd_drmaa_session_t *self,
+		const fsd_template_t *jt,
+		int bulk_idx
+		)
+{
+	char *volatile job_id = NULL;
+	fsd_job_t *volatile job = NULL;
+	pbsdrmaa_submit_t *volatile submit = NULL;
+
+	fsd_log_enter(( "(jt=%p, bulk_idx=%d)", (void*)jt, bulk_idx ));
+	TRY
+	 {
+		submit = pbsdrmaa_submit_new( self, jt, bulk_idx );
+		submit->eval( submit );
+		job_id = submit->submit( submit );
+		job = self->new_job( self, job_id );
+		job->submit_time = time(NULL);
+		job->flags |= FSD_JOB_CURRENT_SESSION;
+		self->jobs->add( self->jobs, job );
+		job->release( job );  job = NULL;
+	 }
+	EXCEPT_DEFAULT
+	 {
+		fsd_free( job_id );
+		fsd_exc_reraise();
+	 }
+	FINALLY
+	 {
+		if( submit )
+			submit->destroy( submit );
+		if( job )
+			job->release( job );
+	 }
+	END_TRY
+	fsd_log_return(( " =%s", job_id ));
+	return job_id;
+}
+
+
+static fsd_job_t *
+pbsdrmaa_session_new_job( fsd_drmaa_session_t *self, const char *job_id )
+{
+	fsd_job_t *job;
+	job = pbsdrmaa_job_new( fsd_strdup(job_id) );
+	job->session = self;
+	return job;
+}
+
+void
+pbsdrmaa_session_apply_configuration( fsd_drmaa_session_t *self )
+{
+	pbsdrmaa_session_t *pbsself = (pbsdrmaa_session_t*)self;
+	fsd_conf_option_t *pbs_home;
+	pbs_home = fsd_conf_dict_get(self->configuration, "pbs_home" );
+
+	if( pbs_home && pbs_home->type == FSD_CONF_STRING )
+	  {
+			struct stat statbuf;
+			char * volatile log_path;
+			struct tm tm;
+			
+			pbsself->pbs_home = pbs_home->val.string;
+			fsd_log_info(("pbs_home: %s",pbsself->pbs_home));
+			pbsself->super_wait_thread = pbsself->super.wait_thread;
+			pbsself->super.wait_thread = pbsdrmaa_session_wait_thread;		
+			pbsself->wait_thread_log = true;
+	
+			time(&pbsself->log_file_initial_time);	
+			localtime_r(&pbsself->log_file_initial_time,&tm);
+
+			log_path = fsd_asprintf("%s/server_logs/%04d%02d%02d",
+					pbsself->pbs_home,
+					tm.tm_year + 1900,
+					tm.tm_mon + 1,
+					tm.tm_mday);
+
+			if(stat(log_path,&statbuf) == -1)
+			  {
+				char errbuf[256] = "InternalError";
+				(void)strerror_r(errno, errbuf, sizeof(errbuf));
+				fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"stat error: %s",errbuf);
+			  }
+	
+			fsd_log_debug(("Log file %s size %d",log_path,(int) statbuf.st_size));
+			pbsself->log_file_initial_size = statbuf.st_size;
+			fsd_free(log_path);
+	  }
+
+	pbsself->super_apply_configuration(self); /* call method from the superclass */
+}
+
+
+void
+pbsdrmaa_session_update_all_jobs_status( fsd_drmaa_session_t *self )
+{
+	volatile bool conn_lock = false;
+	volatile bool jobs_lock = false;
+	pbsdrmaa_session_t *pbsself = (pbsdrmaa_session_t*)self;
+	fsd_job_set_t *jobs = self->jobs;
+	struct batch_status *volatile status = NULL;
+
+	fsd_log_enter((""));
+
+	TRY
+	 {
+		conn_lock = fsd_mutex_lock( &self->drm_connection_mutex );
+retry:
+/* TODO: query only for user's jobs pbs_selstat + ATTR_u */
+#ifdef PBS_PROFESSIONAL
+		status = pbs_statjob( pbsself->pbs_conn, NULL, NULL, NULL );
+#else
+		status = pbs_statjob( pbsself->pbs_conn, NULL, pbsself->status_attrl, NULL );
+#endif
+		fsd_log_info(( "pbs_statjob( fd=%d, job_id=NULL, attribs={...} ) =%p",
+				 pbsself->pbs_conn, (void*)status ));
+		if( status == NULL  &&  pbs_errno != 0 )
+		 {
+			if (pbs_errno == PBSE_PROTOCOL || pbs_errno == PBSE_EXPIRED)
+			 {
+				if ( pbsself->pbs_conn >= 0)
+					pbs_disconnect( pbsself->pbs_conn );
+				sleep(1);
+				pbsself->pbs_conn = pbs_connect( pbsself->super.contact );
+				if( pbsself->pbs_conn < 0 )
+					pbsdrmaa_exc_raise_pbs( "pbs_connect" );
+				else
+					goto retry;
+			 }
+			else
+			 {
+				pbsdrmaa_exc_raise_pbs( "pbs_statjob" );
+			 }
+		 }
+		conn_lock = fsd_mutex_unlock( &self->drm_connection_mutex );
+
+		 {
+			size_t i;
+			fsd_job_t *job;
+			jobs_lock = fsd_mutex_lock( &jobs->mutex );
+			for( i = 0;  i < jobs->tab_size;  i++ )
+				for( job = jobs->tab[i];  job != NULL;  job = job->next )
+				 {
+					fsd_mutex_lock( &job->mutex );
+					job->flags |= FSD_JOB_MISSING;
+					fsd_mutex_unlock( &job->mutex );
+				 }
+			jobs_lock = fsd_mutex_unlock( &jobs->mutex );
+		 }
+
+		 {
+			struct batch_status *volatile i;
+			for( i = status;  i != NULL;  i = i->next )
+			 {
+				fsd_job_t *job = NULL;
+				fsd_log_debug(( "job_id=%s", i->name ));
+				job = self->get_job( self, i->name );
+				if( job != NULL )
+				 {
+					job->flags &= ~FSD_JOB_MISSING;
+					TRY
+					 {
+						((pbsdrmaa_job_t*)job)->update( job, i );
+					 }
+					FINALLY
+					 {
+						job->release( job );
+					 }
+					END_TRY
+				 }
+			 }
+		 }
+
+		 {
+			size_t volatile i;
+			fsd_job_t *volatile job;
+			jobs_lock = fsd_mutex_lock( &jobs->mutex );
+			for( i = 0;  i < jobs->tab_size;  i++ )
+				for( job = jobs->tab[i];  job != NULL;  job = job->next )
+				 {
+					fsd_mutex_lock( &job->mutex );
+					TRY
+					 {
+						if( job->flags & FSD_JOB_MISSING )
+							job->on_missing( job );
+					 }
+					FINALLY{ fsd_mutex_unlock( &job->mutex ); }
+					END_TRY
+				 }
+			jobs_lock = fsd_mutex_unlock( &jobs->mutex );
+		 }
+	 }
+	FINALLY
+	 {
+		if( status != NULL )
+			pbs_statfree( status );
+		if( conn_lock )
+			conn_lock = fsd_mutex_unlock( &self->drm_connection_mutex );
+		if( jobs_lock )
+			jobs_lock = fsd_mutex_unlock( &jobs->mutex );
+	 }
+	END_TRY
+
+	fsd_log_return((""));
+}
+
+
+
+struct attrl *
+pbsdrmaa_create_status_attrl(void)
+{
+	struct attrl *result = NULL;
+	struct attrl *i;
+	const int max_attribs = 16;
+	int n_attribs;
+	int j = 0;
+
+	fsd_log_enter((""));
+	fsd_calloc( result, max_attribs, struct attrl );
+	result[j++].name="job_state";
+	result[j++].name="exit_status";
+	result[j++].name="resources_used";
+	result[j++].name="ctime";
+	result[j++].name="mtime";
+	result[j++].name="qtime";
+	result[j++].name="etime";
+
+	result[j++].name="queue";
+	result[j++].name="Account_Name";
+	result[j++].name="exec_host";
+	result[j++].name="start_time";
+	result[j++].name="mtime";
+#if 0
+	result[j].name="resources_used";  result[j].resource="walltime";  j++;
+	result[j].name="resources_used";  result[j].resource="cput";  j++;
+	result[j].name="resources_used";  result[j].resource="mem";  j++;
+	result[j].name="resources_used";  result[j].resource="vmem";  j++;
+	result[j].name="Resource_List";  result[j].resource="walltime";  j++;
+	result[j].name="Resource_List";  result[j].resource="cput";  j++;
+	result[j].name="Resource_List";  result[j].resource="mem";  j++;
+	result[j].name="Resource_List";  result[j].resource="vmem";  j++;
+#endif
+	n_attribs = j;
+	for( i = result;  true;  i++ )
+		if( i+1 < result + n_attribs )
+			i->next = i+1;
+		else
+		 {
+			i->next = NULL;
+			break;
+		 }
+
+#ifdef DEBUGGING
+	fsd_log_return((":"));
+	pbsdrmaa_dump_attrl( result, NULL );
+#endif
+	return result;
+}
+
+
+bool
+pbsdrmaa_session_do_drm_keeps_completed_jobs( pbsdrmaa_session_t *self )
+{
+
+#ifndef PBS_PROFESSIONAL
+	struct attrl default_queue_query;
+	struct attrl keep_completed_query;
+	struct batch_status *default_queue_result = NULL;
+	struct batch_status *keep_completed_result = NULL;
+	const char *default_queue = NULL;
+	const char *keep_completed = NULL;
+	volatile bool result = false;
+	volatile bool conn_lock = false;
+
+	TRY
+	 {
+		default_queue_query.next = NULL;
+		default_queue_query.name = "default_queue";
+		default_queue_query.resource = NULL;
+		default_queue_query.value = NULL;
+		keep_completed_query.next = NULL;
+		keep_completed_query.name = "keep_completed";
+		keep_completed_query.resource = NULL;
+		keep_completed_query.value = NULL;
+
+		conn_lock = fsd_mutex_lock( &self->super.drm_connection_mutex );
+
+		default_queue_result =
+				pbs_statserver( self->pbs_conn, &default_queue_query, NULL );
+		if( default_queue_result == NULL )
+			pbsdrmaa_exc_raise_pbs( "pbs_statserver" );
+		if( default_queue_result->attribs
+				&&  !strcmp( default_queue_result->attribs->name,
+					"default_queue" ) )
+			default_queue = default_queue_result->attribs->value;
+
+		fsd_log_debug(( "default_queue: %s", default_queue ));
+
+		if( default_queue )
+		 {
+			keep_completed_result = pbs_statque( self->pbs_conn,
+					(char*)default_queue, &keep_completed_query, NULL );
+			if( keep_completed_result == NULL )
+				pbsdrmaa_exc_raise_pbs( "pbs_statque" );
+			if( keep_completed_result->attribs
+					&&  !strcmp( keep_completed_result->attribs->name,
+						"keep_completed" ) )
+				keep_completed = keep_completed_result->attribs->value;
+		 }
+
+		fsd_log_debug(( "keep_completed: %s", keep_completed ));
+	 }
+	EXCEPT_DEFAULT
+	 {
+		const fsd_exc_t *e = fsd_exc_get();
+		fsd_log_warning(( "PBS server seems not to keep completed jobs\n"
+				"detail: %s", e->message(e) ));
+		result = false;
+	 }
+	ELSE
+	 {
+		result = false;
+		if( default_queue == NULL )
+			fsd_log_warning(( "no default queue set on PBS server" ));
+		else if( keep_completed == NULL && self->pbs_home == NULL )
+			fsd_log_warning(( "Torque server is not configured to keep completed jobs\n"
+						"in Torque: set keep_completed parameter of default queue\n"
+						"  $ qmgr -c 'set queue batch keep_completed = 60'\n"
+						" or configure DRMAA to utilize log files"
+						));
+		else
+			result = true;
+	 }
+	FINALLY
+	 {
+		if( default_queue_result )
+			pbs_statfree( default_queue_result );
+		if( keep_completed_result )
+			pbs_statfree( keep_completed_result );
+		if( conn_lock )
+			conn_lock = fsd_mutex_unlock( &self->super.drm_connection_mutex );
+
+	 }
+	END_TRY
+
+	return result;
+#endif
+	fsd_log_warning(( "PBS Professional does not keep information about the completed jobs\n"
+				" You must configure DRMAA to utilize log files in order to always get valid job exit status"
+				));
+	return false;
+}
+
+void *
+pbsdrmaa_session_wait_thread( fsd_drmaa_session_t *self )
+{
+	pbsdrmaa_log_reader_t *log_reader = NULL;
+	
+	fsd_log_enter(( "" ));
+	
+	TRY
+	{	
+		log_reader = pbsdrmaa_log_reader_new( self, NULL);
+		log_reader->read_log( log_reader );
+	}
+	FINALLY
+	{
+		pbsdrmaa_log_reader_destroy( log_reader );
+	}
+	END_TRY
+	
+	fsd_log_return(( " =NULL" ));
+	return NULL;
+}
Index: /branches/2.0/pbs_drmaa/.gitignore
===================================================================
--- /branches/2.0/pbs_drmaa/.gitignore	(revision 12)
+++ /branches/2.0/pbs_drmaa/.gitignore	(revision 12)
@@ -0,0 +1,4 @@
+datetime_tab.c
+datetime_tab.h
+del_all_jobs
+pbs_attrib.c
Index: /branches/2.0/pbs_drmaa/drmaa.c
===================================================================
--- /branches/2.0/pbs_drmaa/drmaa.c	(revision 12)
+++ /branches/2.0/pbs_drmaa/drmaa.c	(revision 12)
@@ -0,0 +1,226 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2007  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <signal.h>
+#include <drmaa_utils/drmaa_base.h>
+#include <drmaa_utils/session.h>
+#include <drmaa_utils/template.h>
+#include <drmaa_utils/drmaa_attrib.h>
+#include <drmaa_utils/iter.h>
+#include <drmaa_utils/logging.h>
+#include <pbs_drmaa/session.h>
+
+
+static fsd_drmaa_session_t *
+pbsdrmaa_new_session( fsd_drmaa_singletone_t *self, const char *contact )
+{
+	return pbsdrmaa_session_new( contact );
+}
+
+static fsd_template_t *
+pbsdrmaa_new_job_template( fsd_drmaa_singletone_t *self )
+{
+	return drmaa_template_new();
+}
+
+static const char *
+pbsdrmaa_get_contact( fsd_drmaa_singletone_t *self )
+{
+	const char *contact = NULL;
+	fsd_mutex_lock( &self->session_mutex );
+	if( self->session )
+		contact = self->session->contact;
+	if( contact == NULL )
+		contact = "localhost";
+	fsd_mutex_unlock( &self->session_mutex );
+	return contact;
+}
+
+static void
+pbsdrmaa_get_version( fsd_drmaa_singletone_t *self,
+		unsigned *major, unsigned *minor )
+{
+	*major = 1;  *minor = 0;
+}
+
+static const char *
+pbsdrmaa_get_DRM_system( fsd_drmaa_singletone_t *self )
+{
+#ifdef PBS_PROFESSIONAL
+	return "PBS Professional";
+#else
+	return "Torque";
+#endif
+}
+
+static const char *
+pbsdrmaa_get_DRMAA_implementation( fsd_drmaa_singletone_t *self )
+{
+	return PACKAGE_NAME" v. "PACKAGE_VERSION
+					" <http://sourceforge.net/projects/pbspro-drmaa/>";
+}
+
+
+fsd_iter_t *
+pbsdrmaa_get_attribute_names( fsd_drmaa_singletone_t *self )
+{
+	static const char *attribute_names[] = {
+		DRMAA_REMOTE_COMMAND,
+		DRMAA_JS_STATE,
+		DRMAA_WD,
+		DRMAA_JOB_CATEGORY,
+		DRMAA_NATIVE_SPECIFICATION,
+		DRMAA_BLOCK_EMAIL,
+		DRMAA_START_TIME,
+		DRMAA_JOB_NAME,
+		DRMAA_INPUT_PATH,
+		DRMAA_OUTPUT_PATH,
+		DRMAA_ERROR_PATH,
+		DRMAA_JOIN_FILES,
+		DRMAA_TRANSFER_FILES,
+		DRMAA_WCT_HLIMIT,
+		DRMAA_DURATION_HLIMIT,
+		NULL
+	};
+	return fsd_iter_new_const( attribute_names, -1 );
+}
+
+fsd_iter_t *
+pbsdrmaa_get_vector_attribute_names( fsd_drmaa_singletone_t *self )
+{
+	static const char *attribute_names[] = {
+		DRMAA_V_ARGV,
+		DRMAA_V_ENV,
+		DRMAA_V_EMAIL,
+		NULL
+	};
+	return fsd_iter_new_const( attribute_names, -1 );
+}
+
+static int
+pbsdrmaa_wifexited(
+		int *exited, int stat,
+		char *error_diagnosis, size_t error_diag_len
+		)
+{
+	*exited = (stat <= 125);
+	return DRMAA_ERRNO_SUCCESS;
+}
+
+static int
+pbsdrmaa_wexitstatus(
+		int *exit_status, int stat,
+		char *error_diagnosis, size_t error_diag_len
+		)
+{
+	*exit_status = stat & 0xff;
+	return DRMAA_ERRNO_SUCCESS;
+}
+
+static int
+pbsdrmaa_wifsignaled(
+		int *signaled, int stat,
+		char *error_diagnosis, size_t error_diag_len
+		)
+{
+	*signaled = (stat > 128 );
+	return DRMAA_ERRNO_SUCCESS;
+}	
+
+static int
+pbsdrmaa_wtermsig(
+		char *signal, size_t signal_len, int stat,
+		char *error_diagnosis, size_t error_diag_len
+		)
+{
+	int sig = stat & 0x7f;
+	strlcpy( signal, fsd_strsignal(sig), signal_len );
+	return DRMAA_ERRNO_SUCCESS;
+}
+
+static int
+pbsdrmaa_wcoredump(
+		int *core_dumped, int stat,
+		char *error_diagnosis, size_t error_diag_len
+		)
+{
+	*core_dumped = 0;
+	return DRMAA_ERRNO_SUCCESS;
+}
+
+static int
+pbsdrmaa_wifaborted(
+		int *aborted, int stat,
+		char *error_diagnosis, size_t error_diag_len
+		)
+{
+	fsd_log_debug(("wifaborted(%d)", stat));
+
+	if ( stat == -1 )
+	 {
+		*aborted = true;
+	 }
+	else if ( stat <= 125 )
+	 {
+		*aborted = false;
+	 }
+	else if ( stat == 126 || stat == 127 )
+         {
+		*aborted = true;
+	 } 
+	else switch( stat & 0x7f )
+	 {
+		case SIGTERM:  case SIGKILL:
+			*aborted = true;
+			break;
+		default:
+			*aborted = false;
+			break;
+	 }
+	return DRMAA_ERRNO_SUCCESS;
+}
+
+
+fsd_drmaa_singletone_t _fsd_drmaa_singletone = {
+	NULL,
+	FSD_MUTEX_INITIALIZER,
+
+	pbsdrmaa_new_session,
+	pbsdrmaa_new_job_template,
+
+	pbsdrmaa_get_contact,
+	pbsdrmaa_get_version,
+	pbsdrmaa_get_DRM_system,
+	pbsdrmaa_get_DRMAA_implementation,
+
+	pbsdrmaa_get_attribute_names,
+	pbsdrmaa_get_vector_attribute_names,
+
+	pbsdrmaa_wifexited,
+	pbsdrmaa_wexitstatus,
+	pbsdrmaa_wifsignaled,
+	pbsdrmaa_wtermsig,
+	pbsdrmaa_wcoredump,
+	pbsdrmaa_wifaborted
+};
+
Index: /branches/2.0/pbs_drmaa/pbs_drmaa.conf.example
===================================================================
--- /branches/2.0/pbs_drmaa/pbs_drmaa.conf.example	(revision 12)
+++ /branches/2.0/pbs_drmaa/pbs_drmaa.conf.example	(revision 12)
@@ -0,0 +1,8 @@
+# $Id$
+# pbs_drmaa.conf - Sample pbs_drmaa configuration file.
+
+#wait_thread: 1,
+#pbs_home: "/var/spool/torque",
+#pool_delay: 5,
+
+
Index: /branches/2.0/pbs_drmaa/session.h
===================================================================
--- /branches/2.0/pbs_drmaa/session.h	(revision 12)
+++ /branches/2.0/pbs_drmaa/session.h	(revision 12)
@@ -0,0 +1,85 @@
+/* $Id$ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2009  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __PBS_DRMAA__SESSION_H
+#define __PBS_DRMAA__SESSION_H
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <drmaa_utils/session.h>
+
+typedef struct pbsdrmaa_session_s pbsdrmaa_session_t;
+
+fsd_drmaa_session_t *
+pbsdrmaa_session_new( const char *contact );
+
+struct pbsdrmaa_session_s {
+	fsd_drmaa_session_t super;
+
+	bool (*
+	do_drm_keeps_completed_jobs)( pbsdrmaa_session_t *self );
+
+	void (*
+	super_destroy)( fsd_drmaa_session_t *self );
+
+	void (*
+	super_apply_configuration)(fsd_drmaa_session_t *self);
+
+	/*
+	 * Pointer to standard wait_thread drmaa_utils function
+	 */
+        void* (*
+        super_wait_thread)( fsd_drmaa_session_t *self );
+
+	/*
+	 * PBS connection (or -1 if not connected).
+	 * A descriptor of socket conencted to PBS server.
+	 */
+	int pbs_conn;
+
+	/*
+	 * PBS folder - used by wait_thread which reads log files
+	 */
+	char * pbs_home;
+
+	/*
+	 * Wait thread reading logs active
+	 */
+	bool wait_thread_log;
+
+	/*
+	 * List of attributes which will be used to query jobs.
+	 */
+	struct attrl *status_attrl;
+
+	/*
+	 * Log file initial size - used by wait_thread which reads log files
+ 	 */
+	off_t log_file_initial_size;
+
+	/*
+	 * Time we checked log file initial size - used by wait_thread which reads log files
+ 	 */
+	time_t log_file_initial_time;
+};
+
+#endif /* __PBS_DRMAA__SESSION_H */
+
Index: /branches/2.0/pbs_drmaa/Makefile.am
===================================================================
--- /branches/2.0/pbs_drmaa/Makefile.am	(revision 12)
+++ /branches/2.0/pbs_drmaa/Makefile.am	(revision 12)
@@ -0,0 +1,46 @@
+# $Id$
+# 
+# FedStage DRMAA for PBS Professional
+# Copyright (C) 2006-2009  FedStage Systems
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+GPERF       = @GPERF@
+GPERFFLAGS  = --readonly-tables
+AM_CPPFLAGS = @PBS_INCLUDES@ -I$(top_srcdir)/drmaa_utils -fPIC
+
+lib_LTLIBRARIES = libdrmaa.la
+
+libdrmaa_la_SOURCES = \
+ drmaa.c \
+ job.c job.h \
+ pbs_attrib.gperf pbs_attrib.h \
+ session.c session.h \
+ submit.c submit.h \
+ util.c util.h \
+ log_reader.c log_reader.h 
+BUILT_SOURCES       = pbs_attrib.c
+EXTRA_DIST          = pbs_attrib.c
+dist_sysconf_DATA   = pbs_drmaa.conf.example
+libdrmaa_la_LIBADD  = ../drmaa_utils/drmaa_utils/libdrmaa_utils.la @PBS_LIBS@
+libdrmaa_la_LDFLAGS = @PBS_LDFLAGS@ -version-info @PBS_DRMAA_VERSION_INFO@
+
+
+.gperf.c:
+	$(GPERF) $(GPERFFLAGS) --output-file=$@ $<
+
+if GCC
+pbs_attrib.lo: CFLAGS += @GCC_W_NO_MISSING_FIELD_INITIALIZERS@
+endif
Index: /branches/2.0/README
===================================================================
--- /branches/2.0/README	(revision 12)
+++ /branches/2.0/README	(revision 12)
@@ -0,0 +1,4 @@
+The manual for the DRMAA for Torque/PBS Pro (since version 1.0.7) is available 
+at the project wiki: 
+
+  http://apps.man.poznan.pl/trac/pbs-drmaa/wiki
Index: /branches/2.0/configure.ac
===================================================================
--- /branches/2.0/configure.ac	(revision 12)
+++ /branches/2.0/configure.ac	(revision 12)
@@ -0,0 +1,178 @@
+AC_INIT([DRMAA for PBS Pro], [1.0.7], [mamonski@man.poznan.pl], [pbs-drmaa])
+AC_PREREQ(2.59)
+AC_REVISION([$Id$])
+AC_COPYRIGHT([
+DRMAA for Torque/PBS Professional
+Copyright (C) 2006-2009  FedStage Systems
+Copyright (C) 2011  Poznan Supercomputing and Networking Center
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+])
+
+PBS_DRMAA_MAJOR=1
+PBS_DRMAA_MINOR=0
+PBS_DRMAA_MICRO=7
+PBS_DRMAA_VERSION_INFO=1:7:0
+AC_SUBST([PBS_DRMAA_MAJOR])
+AC_SUBST([PBS_DRMAA_MINOR])
+AC_SUBST([PBS_DRMAA_MICRO])
+AC_SUBST([PBS_DRMAA_VERSION_INFO])
+
+AC_CONFIG_SRCDIR([pbs_drmaa/drmaa.c])
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_AUX_DIR([scripts])
+
+AM_INIT_AUTOMAKE
+
+# command-line arguments:
+AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug],
+			[produce code suiteable for debugging and print logs at runtime]))
+AC_ARG_ENABLE(development, AC_HELP_STRING([--enable-development],
+			[enable development mode: make additional checks (suiteable for developers)]))
+
+# programs:
+AC_PROG_CC
+AC_PROG_CPP
+AC_PROG_RANLIB
+AC_PROG_INSTALL
+AC_PROG_LIBTOOL
+AC_PROG_MAKE_SET
+AC_PROG_LN_S
+
+# code generation tools:
+AX_GPERF
+
+# check compiler / set basic flags:
+if test x$ac_cv_prog_cc_stdc = xno; then
+	AC_MSG_ERROR([ANSI C compiler is required])
+fi
+
+if test x$GCC = xyes; then
+	CFLAGS="-pedantic -ansi ${CFLAGS}"
+fi
+AM_CONDITIONAL([GCC], [test x$GCC = xyes])
+
+AX_GCC_WARNINGS()
+
+AH_TEMPLATE([DEBUGGING], [Produce debugging code])
+if test x$enable_debug = xyes; then
+	AC_DEFINE(DEBUGGING,[1])
+	CFLAGS="${CFLAGS} -O0"
+else
+	CPPFLAGS="-DNDEBUG ${CPPFLAGS}"
+fi
+
+AH_TEMPLATE([DEVELOPMENT], [Development mode])
+if test x$enable_development = xyes; then
+	AC_DEFINE(DEVELOPMENT, [1])
+fi
+
+AH_BOTTOM([
+#ifndef __GNUC__
+#	define __attribute__ /* nothing */
+#endif
+])
+
+# system:
+CPPFLAGS="-D_REENTRANT -D_THREAD_SAFE ${CPPFLAGS}"
+
+AC_CANONICAL_HOST
+case "$host_os" in
+	*linux*)
+		CPPFLAGS="${CPPFLAGS} -D_GNU_SOURCE"
+		;;
+	*solaris*)
+		CPPFLAGS="${CPPFLAGS} -D_XOPEN_SOURCE=500 -D__EXTENSIONS__"
+		;;
+	*freebsd*)
+		;;
+	*darwin*)
+		CPPFLAGS="${CPPFLAGS} -D_XOPEN_SOURCE=400"
+		;;
+	*)
+		CPPFLAGS="${CPPFLAGS} -D_XOPEN_SOURCE=500"
+		;;
+esac
+
+# project prerequisites:
+
+# libraries:
+ACX_PTHREAD([CFLAGS="$CFLAGS $PTHREAD_CFLAGS" LIBS="$PTHREAD_LIBS $LIBS"],
+		[AC_MSG_ERROR([POSIX threads library is required.])])
+
+AX_PBS([:], [AC_MSG_ERROR([
+PBS libraries/headers not found;
+add --with-pbs to set PBS installation root.]) ])
+CPPFLAGS="${CPPFLAGS} -DCONFDIR=${sysconfdir}"
+
+# headers:
+AC_HEADER_STDC
+AC_HEADER_TIME
+AC_HEADER_STDBOOL
+AC_CHECK_HEADERS([stddef.h stdlib.h string.h strings.h sys/time.h unistd.h])
+
+# types and structures:
+AC_TYPE_SIZE_T
+AC_STRUCT_TM
+
+# compiler characteristic
+AC_C_CONST
+AC_C_INLINE
+AC_C_VOLATILE
+
+# functions:
+AC_FUNC_MALLOC
+AC_FUNC_STRFTIME
+AC_FUNC_VPRINTF
+AC_CHECK_FUNCS([ \
+	asprintf \
+	fstat \
+	getcwd \
+	gettimeofday \
+	localtime_r \
+	memset \
+	mkstemp \
+	setenv \
+	strcasecmp \
+	strchr \
+	strdup \
+	strerror \
+	strlcpy \
+	strndup \
+	strstr \
+	strtol \
+	vasprintf \
+	])
+
+# system services:
+
+# turn on warning after all tests
+if test x$GCC = xyes; then
+	if test x$enable_development = xyes; then
+		CFLAGS="-Werror ${CFLAGS}"
+	fi
+	CFLAGS="-Wall -W -Wno-unused-parameter $GCC_W_NO_FORMAT_ZERO_LENGTH ${CFLAGS}"
+fi
+
+AC_CONFIG_FILES([
+	Makefile
+	pbs_drmaa/Makefile
+])
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_SUBDIRS([drmaa_utils])
+AC_OUTPUT
+
+echo
+echo "Run 'make' now."
+
Index: /branches/2.0/.gitignore
===================================================================
--- /branches/2.0/.gitignore	(revision 12)
+++ /branches/2.0/.gitignore	(revision 12)
@@ -0,0 +1,18 @@
+/aclocal.m4
+/autom4te.cache
+/config.*
+/configure
+/libtool
+/scripts
+/stamp-h1
+
+.deps
+.libs
+Makefile
+Makefile.in
+
+*.la
+*.lo
+*.o
+.*.swp
+*.tar.gz
Index: /branches/2.0/TODO
===================================================================
--- /branches/2.0/TODO	(revision 12)
+++ /branches/2.0/TODO	(revision 12)
@@ -0,0 +1,2 @@
+1. Verify if devel version of PBS
+2. Verify algorithm of merging configuration from different files
Index: /branches/2.0/INSTALL
===================================================================
--- /branches/2.0/INSTALL	(revision 12)
+++ /branches/2.0/INSTALL	(revision 12)
@@ -0,0 +1,236 @@
+Installation Instructions
+*************************
+
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free
+Software Foundation, Inc.
+
+This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
+Basic Installation
+==================
+
+These are generic installation instructions.
+
+   The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation.  It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions.  Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+   It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring.  (Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.)
+
+   If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release.  If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
+
+   The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'.  You only need
+`configure.ac' if you want to change it or regenerate `configure' using
+a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.  If you're
+     using `csh' on an old version of System V, you might need to type
+     `sh ./configure' instead to prevent `csh' from trying to execute
+     `configure' itself.
+
+     Running `configure' takes awhile.  While running, it prints some
+     messages telling which features it is checking for.
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation.
+
+  5. You can remove the program binaries and object files from the
+     source code directory by typing `make clean'.  To also remove the
+     files that `configure' created (so you can compile the package for
+     a different kind of computer), type `make distclean'.  There is
+     also a `make maintainer-clean' target, but that is intended mainly
+     for the package's developers.  If you use it, you may have to get
+     all sorts of other programs in order to regenerate files that came
+     with the distribution.
+
+Compilers and Options
+=====================
+
+Some systems require unusual options for compilation or linking that the
+`configure' script does not know about.  Run `./configure --help' for
+details on some of the pertinent environment variables.
+
+   You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment.  Here
+is an example:
+
+     ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
+
+   *Note Defining Variables::, for more details.
+
+Compiling For Multiple Architectures
+====================================
+
+You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory.  To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'.  `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script.  `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+   If you have to use a `make' that does not support the `VPATH'
+variable, you have to compile the package for one architecture at a
+time in the source code directory.  After you have installed the
+package for one architecture, use `make distclean' before reconfiguring
+for another architecture.
+
+Installation Names
+==================
+
+By default, `make install' will install the package's files in
+`/usr/local/bin', `/usr/local/man', etc.  You can specify an
+installation prefix other than `/usr/local' by giving `configure' the
+option `--prefix=PREFIX'.
+
+   You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files.  If you
+give `configure' the option `--exec-prefix=PREFIX', the package will
+use PREFIX as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+   In addition, if you use an unusual directory layout you can give
+options like `--bindir=DIR' to specify different values for particular
+kinds of files.  Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+   If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System).  The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+   For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+There may be some features `configure' cannot figure out automatically,
+but needs to determine by the type of machine the package will run on.
+Usually, assuming the package is built to be run on the _same_
+architectures, `configure' can figure that out, but if it prints a
+message saying it cannot guess the machine type, give it the
+`--build=TYPE' option.  TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
+     CPU-COMPANY-SYSTEM
+
+where SYSTEM can have one of these forms:
+
+     OS KERNEL-OS
+
+   See the file `config.sub' for the possible values of each field.  If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the machine type.
+
+   If you are _building_ compiler tools for cross-compiling, you should
+use the `--target=TYPE' option to select the type of system they will
+produce code for.
+
+   If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
+
+Sharing Defaults
+================
+
+If you want to set default values for `configure' scripts to share, you
+can create a site shell script called `config.site' that gives default
+values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Defining Variables
+==================
+
+Variables not defined in a site shell script can be set in the
+environment passed to `configure'.  However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost.  In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'.  For example:
+
+     ./configure CC=/usr/local2/bin/gcc
+
+causes the specified `gcc' to be used as the C compiler (unless it is
+overridden in the site shell script).  Here is a another example:
+
+     /bin/bash ./configure CONFIG_SHELL=/bin/bash
+
+Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent
+configuration-related scripts to be executed by `/bin/bash'.
+
+`configure' Invocation
+======================
+
+`configure' recognizes the following options to control how it operates.
+
+`--help'
+`-h'
+     Print a summary of the options to `configure', and exit.
+
+`--version'
+`-V'
+     Print the version of Autoconf used to generate the `configure'
+     script, and exit.
+
+`--cache-file=FILE'
+     Enable the cache: use and save the results of the tests in FILE,
+     traditionally `config.cache'.  FILE defaults to `/dev/null' to
+     disable caching.
+
+`--config-cache'
+`-C'
+     Alias for `--cache-file=config.cache'.
+
+`--quiet'
+`--silent'
+`-q'
+     Do not print messages saying which checks are being made.  To
+     suppress all normal output, redirect it to `/dev/null' (any error
+     messages will still be shown).
+
+`--srcdir=DIR'
+     Look for the package's source code in directory DIR.  Usually
+     `configure' can determine that directory automatically.
+
+`configure' also accepts some other, not widely useful, options.  Run
+`configure --help' for more details.
+
Index: /branches/2.0/COPYING
===================================================================
--- /branches/2.0/COPYING	(revision 12)
+++ /branches/2.0/COPYING	(revision 12)
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
Index: /branches/2.0/Makefile.am
===================================================================
--- /branches/2.0/Makefile.am	(revision 12)
+++ /branches/2.0/Makefile.am	(revision 12)
@@ -0,0 +1,26 @@
+# $Id$
+#
+# FedStage DRMAA for PBS Pro
+# Copyright (C) 2006-2009  FedStage Systems
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+ACLOCAL_AMFLAGS = -I m4
+EXTRA_DIST = \
+ autoclean.sh \
+ autogen.sh \
+ m4/missing-dev-prog.sh
+
+SUBDIRS = drmaa_utils pbs_drmaa
Index: /branches/2.0/autogen.sh
===================================================================
--- /branches/2.0/autogen.sh	(revision 12)
+++ /branches/2.0/autogen.sh	(revision 12)
@@ -0,0 +1,49 @@
+#!/bin/sh
+# $Id$
+
+run() {
+	echo "running $@ ($PWD)"
+	eval "$@"
+}
+
+check()
+{
+	printf "checking for $1... "
+	if ($1 --version < /dev/null > /dev/null 2>&1); then
+		echo "yes"
+	else
+		echo "no"
+		exit 1
+	fi
+}
+
+ACLOCAL=${ACLOCAL:=aclocal}
+AUTOHEADER=${AUTOHEADER:=autoheader}
+AUTOCONF=${AUTOCONF:=autoconf}
+LIBTOOLIZE=${LIBTOOLIZE:=libtoolize}
+AUTOMAKE=${AUTOMAKE:=automake}
+
+check $ACLOCAL
+check $AUTOHEADER
+check $AUTOCONF
+check $LIBTOOLIZE
+check $AUTOMAKE
+
+mkdir -p scripts
+
+run ${ACLOCAL} -I m4 | grep -v ^/usr/share/aclocal || exit 1
+run ${LIBTOOLIZE} --automake --copy --force || exit 1
+run ${AUTOHEADER} --warnings=all || exit 1
+run ${AUTOMAKE} --foreign --add-missing --copy --warnings=all || exit 1
+run ${AUTOCONF} --warnings=all -Wno-obsolete || exit 1
+
+if [ -n "$*" ]; then
+	args="$*"
+elif [ -f config.log ]; then
+	args=`grep '\$ *\./configure ' config.log \
+			 | sed 's:^ *\$ *\./configure ::;s:--no-create::;s:--no-recursion::' \
+			 2>/dev/null`
+fi
+
+(cd drmaa_utils && run sh autogen.sh "$@")
+run ./configure ${args}
Index: /branches/2.0/test/example.c
===================================================================
--- /branches/2.0/test/example.c	(revision 12)
+++ /branches/2.0/test/example.c	(revision 12)
@@ -0,0 +1,287 @@
+/* $Id$ */
+/*
+ *  DRMAA library for Torque/PBS
+ *  Copyright (C) 2006-2007
+ *
+ *  FedStage Systems <http://www.fedstage.com/>,
+ *  Poznan Supercomputing and Networking Center <http://www.man.poznan.pl/>,
+ *  and the OpenDSP project <http://sourceforge.net/projects/opendsp/>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+/**
+ * @file test.c
+ * DRMAA library test / usage example.
+ */
+
+#include <drmaa.h>
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <limits.h>
+#include <errno.h>
+
+#define SEND_MAIL     0
+#define WITH_BULK     0
+#define EXPORT_ENVS   0
+#define DEBUG         1
+#define N_JOBS        1
+
+#define ERR_LEN      DRMAA_ERROR_STRING_BUFFER
+#define JOB_ID_LEN   256
+
+#define errno_error( func ) do{                      \
+	 fprintf( stderr, "%s:%d: %s: %s\n",               \
+			 __FILE__, __LINE__, func, strerror(errno) );  \
+	 exit( 1 );                                        \
+ } while(0)
+
+#define drmaa_error( func ) do{                      \
+		fprintf( stderr, "%s:%d: %s: %s\n> %s\n",        \
+				__FILE__, __LINE__, func,                    \
+				drmaa_strerror(rc), err_msg );               \
+		exit(1);                                         \
+	}while(0)
+
+void
+test_1(void);
+
+drmaa_job_template_t *
+construct_job( char *argv[], char *fds[3], const char *cwd );
+
+void
+time_fmt( time_t t, char *buf, size_t buflen );
+
+
+int
+main( int argc, char *argv[] )
+{
+	test_1();
+	return 0;
+}
+
+void
+test_1(void)
+{
+	char err_msg[ ERR_LEN ] = "";
+	char cwd[ PATH_MAX ];
+	char job_ids[ N_JOBS ][ JOB_ID_LEN ];
+#if WITH_BULK
+	drmaa_job_ids_t *bulk_job_ids = NULL;
+#endif
+	int rc;
+	int i;
+	drmaa_job_template_t *jobs[ N_JOBS ];
+	drmaa_job_template_t *bulk_job = NULL;
+
+	if( getcwd( cwd, PATH_MAX ) == NULL )
+		errno_error("getcwd");
+
+	printf( "connecting\n" );
+	rc = drmaa_init( NULL, err_msg, ERR_LEN );
+	if( rc )  drmaa_error("drmaa_init");
+
+	for( i = 0;  i < N_JOBS;  i++ )
+	 {
+		char arg[ 3 ];
+		char job_path[ PATH_MAX ];
+		char *argv[3];
+		char fds_t[3][64];
+		char *fds[3];
+		int j;
+		printf( "constructing %d\n", i );
+		sprintf( arg, "%d", i );
+		sprintf( job_path, "./test_job" );
+		argv[0] = job_path;
+		argv[1] = arg;
+		argv[2] = NULL;
+		for( j = 0;  j < 3;  j++ )
+			fds[j] = fds_t[j];
+		sprintf( fds[0], "$drmaa_wd_ph$/%d.stdin",  i );
+		sprintf( fds[1], "$drmaa_wd_ph$/%d.stdout", i );
+		sprintf( fds[2], "$drmaa_wd_ph$/%d.stderr", i );
+		jobs[i] = construct_job( argv, fds, cwd );
+
+#if 0
+		char start_time_buf[ 20 ];
+		time_fmt( time(NULL)+15*i, start_time_buf, sizeof(start_time_buf) );
+		printf( "%d: drmaa_start_time=%s\n", i, start_time_buf );
+		rc = drmaa_set_attribute( jobs[i], "drmaa_start_time", start_time_buf,
+				err_msg, ERR_LEN );
+		if( rc )  drmaa_error("drmaa_set_attribute(\"drmaa_set_attribute\")");
+#endif
+	 }
+
+	for( i = 0;  i < N_JOBS;  i++ )
+	 {
+		char job_id[ DRMAA_JOBNAME_BUFFER ];
+		int stat;
+		drmaa_attr_values_t *rusage;
+
+		printf( "running %d\n", i );
+		rc = drmaa_run_job( job_ids[i], JOB_ID_LEN, jobs[ i ], err_msg, ERR_LEN );
+		if( rc )  drmaa_error( "drmaa_run_job" );
+
+		sleep(1);
+		rc = drmaa_wait( job_ids[i], job_id, sizeof(job_id), &stat, DRMAA_TIMEOUT_WAIT_FOREVER, &rusage, err_msg, ERR_LEN );
+		if( rc )
+			drmaa_error( "drmaa_job_wait" );
+		printf( "stat=%d\n", stat );
+	 }
+
+#if WITH_BULK
+	 {
+		char *argv[] = { "./job", "bulk", "$drmaa_incr_ph$", NULL };
+		char *fds[]  = { "b.$drmaa_incr_ph$.stdin", "b.$drmaa_incr_ph$.stdout",
+			"b.$drmaa_incr_ph$.stderr" };
+		bulk_job = construct_job( argv, fds, WD );
+	 }
+	rc = drmaa_run_bulk_jobs( &bulk_job_ids, bulk_job, 1, N_JOBS, 1, err_msg, ERR_LEN );
+	if( rc )  drmaa_error("drmaa_run_bulk_jobs");
+
+	if( bulk_job_ids != NULL )
+		drmaa_release_job_ids( bulk_job_ids );
+#endif
+
+	for( i = 0;  i < N_JOBS;  i++ )
+	 {
+		rc = drmaa_delete_job_template( jobs[i], err_msg, ERR_LEN );
+		if( rc )  drmaa_error("drmaa_delete_job_template");
+	 }
+
+	if( bulk_job != NULL )
+	 {
+		rc = drmaa_delete_job_template( bulk_job, err_msg, ERR_LEN );
+		if( rc )  drmaa_error("drmaa_delete_job_template");
+	 }
+
+	rc = drmaa_exit( err_msg, ERR_LEN );
+	if( rc )  drmaa_error("drmaa_exit");
+}
+
+
+
+drmaa_job_template_t *
+construct_job( char *argv[], char *fds[3], const char *cwd )
+{
+#if 0
+	const char *scalar_attrs[] = {
+		DRMAA_WD            , cwd,
+		DRMAA_REMOTE_COMMAND, argv[0],
+		DRMAA_JOB_NAME      , "jobname",
+		DRMAA_INPUT_PATH    , fds[0],
+		DRMAA_OUTPUT_PATH   , fds[1],
+		DRMAA_ERROR_PATH    , fds[2],
+		/*
+		DRMAA_DURATION_SLIMIT , "00:00:30",
+		DRMAA_DURATION_HLIMIT , "00:01:00",
+		DRMAA_WCT_SLIMIT      , "00:00:02",
+		DRMAA_WCT_HLIMIT      , "00:00:02", */
+		NULL                , NULL
+	};
+#endif
+	const char *scalar_attrs[] = {
+		DRMAA_WD            , NULL,
+		DRMAA_REMOTE_COMMAND, NULL,
+		DRMAA_JOB_NAME      , NULL,
+		DRMAA_INPUT_PATH    , NULL,
+		DRMAA_OUTPUT_PATH   , NULL,
+		DRMAA_ERROR_PATH    , NULL,
+                DRMAA_NATIVE_SPECIFICATION, "-l host=eeyore,nodes=1 -W x=FLAGS:ADVRES:usecase.0",
+		NULL                , NULL
+	};
+#if EXPORT_ENVS
+	const char *exported_envs[] = {
+		"HOME", "PATH", "LD_LIBRARY_PATH",
+		"USER", "USERNAME",
+		"LANG", "LC_ALL", "LC_CTYPE", "LC_MESSAGES", "NLSPATH",
+		"DISPLAY",
+		NULL
+	};
+	char *env[ 32 ];
+#endif
+
+	drmaa_job_template_t *job;
+	char err_msg[ ERR_LEN ] = "";
+	const char *const *i;
+	int rc;
+
+	scalar_attrs[ 1] = cwd;
+	scalar_attrs[ 3] = argv[0];
+	scalar_attrs[ 5] = "jobname";
+	scalar_attrs[ 7] = fds[0];
+	scalar_attrs[ 9] = fds[1];
+	scalar_attrs[11] = fds[2];
+
+	printf( "allocaing template\n" );
+	rc = drmaa_allocate_job_template( &job, err_msg, ERR_LEN );
+	if( rc )  drmaa_error( "drmaa_allocate_job_template" );
+
+	 {
+		for( i = scalar_attrs;  *i;   )
+		 {
+			const char *name  = *i++;
+			const char *value = *i++;
+			printf( "set %s=%s\n", name, value );
+			rc = drmaa_set_attribute( job, name, value, err_msg, ERR_LEN );
+			if( rc )  drmaa_error( "drmaa_set_attribute" );
+		 }
+#		if EXPORT_ENVS
+		for( i=exported_envs, j=env;  *i!=NULL;  i++ )
+		 {
+			const char *value = getenv( *i );
+			if( value != NULL )
+			 {
+				*j = malloc( strlen(*i) + 1 + strlen(value) + 1 );
+				sprintf( *j, "%s=%s", *i, value );
+				printf( "env: %s\n", *j );
+				j++;
+			 }
+		 }
+		*j = NULL;
+#		endif
+	 }
+
+	rc = drmaa_set_vector_attribute( job, DRMAA_V_ARGV, (const char**)argv+1, err_msg, ERR_LEN );
+	if( rc )  drmaa_error("drmaa_set_vector_attribute");
+
+#if SEND_MAIL
+	char *mail_list[] = { "lukasz.ciesnik@gmail.com", NULL };
+	rc = drmaa_set_vector_attribute( job, DRMAA_V_EMAIL, (const char**)mail_list, err_msg, ERR_LEN );
+	if( rc )  drmaa_error( "drmaa_set_vector_attribute(DRMAA_V_EMAIL)" );
+#endif
+
+#if EXPORT_ENVS
+	rc = drmaa_set_vector_attribute( job, DRMAA_V_ENV,  (const char**)env,  err_msg, ERR_LEN );
+	if( rc )  drmaa_error( "drmaa_set_vector_attribute(DRMAA_V_ENV)" );
+#endif
+
+	return job;
+}
+
+
+void
+time_fmt( time_t t, char *buf, size_t buflen )
+{
+	struct tm timem;
+	gmtime_r( &t, &timem );
+	strftime( buf, buflen, "%Y/%m/%d %H:%M:%S", &timem );
+}
+
+
+
Index: /branches/2.0/test/Makefile
===================================================================
--- /branches/2.0/test/Makefile	(revision 12)
+++ /branches/2.0/test/Makefile	(revision 12)
@@ -0,0 +1,3 @@
+example : example.c
+	gcc example.c -o example -ldrmaa -ldrmaa_base
+      
Index: /branches/2.0/m4/ax_gperf.m4
===================================================================
--- /branches/2.0/m4/ax_gperf.m4	(revision 12)
+++ /branches/2.0/m4/ax_gperf.m4	(revision 12)
@@ -0,0 +1,60 @@
+# $Id$
+#
+# SYNOPSIS
+#
+#   AX_GPERF([ACTION-IF-FOUND[, [ACTION-IF-NOT-FOUND]])
+#
+# DESCRIPTION
+#
+#   Test for Gperf perfect hash function generator binary.
+#   When not found GPERF is set with location of fallback
+#   script which prints error message and exits with non-zero
+#   error code.
+#
+#   This macro calls::
+#
+#     AC_SUBST(GPERF)
+#
+# LAST MODIFICATION
+#
+#   2007-12-14
+#
+# LICENSE
+#
+#   Written by Åukasz CieÅnik <lukasz.ciesnik@gmail.com>
+#   and placed under Public Domain
+#
+
+AC_DEFUN([AX_GPERF], [
+	AC_MSG_CHECKING([for gperf])
+	if { echo a; echo b; echo c; } | gperf >/dev/null 2>&1; then
+		ax_prog_gperf_ok=yes
+		GPERF=gperf
+	else
+		if echo $srcdir | grep -q "^/"; then
+			abs_srcdir="$srcdir"
+		else
+			abs_srcdir="`pwd`/$srcdir"
+		fi
+		GPERF="${abs_builddir}/scripts/gperf-fallback.sh"
+		cat >$GPERF <<EOF
+#!/bin/sh
+cat >&2 <<MESSAGE
+ * ERROR: gperf was not found at configuration time while some sources are
+ * build by it.  Either install gperf <http://www.gnu.org/software/gperf/>
+ * or download tarball with generated sources included (than you will
+ * not be able to modify .gperf files).
+MESSAGE
+exit 1
+EOF
+		chmod +x $GPERF
+		ax_prog_gperf_ok=no
+	fi
+	AC_SUBST(GPERF)
+	AC_MSG_RESULT([$ax_prog_gperf_ok])
+	if test x$ax_prog_gperf_ok = xyes; then
+		ifelse([$1], , :, [$1])
+	else
+		ifelse([$2], , :, [$2])
+	fi
+])
Index: /branches/2.0/m4/ax_gcc_warnings.m4
===================================================================
--- /branches/2.0/m4/ax_gcc_warnings.m4	(revision 12)
+++ /branches/2.0/m4/ax_gcc_warnings.m4	(revision 12)
@@ -0,0 +1,50 @@
+# $Id$
+#
+# SYNOPSIS
+#
+#   AX_GCC_FLAGS()
+#
+# DESCRIPTION
+#
+#   Check for supported gcc options.
+#
+#   This macro calls::
+#
+#			AC_SUBST(GCC_W_NO_MISSING_FIELD_INITIALIZERS)
+#			AC_SUBST(GCC_W_NO_FORMAT_ZERO_LENGTH)
+#
+# LAST MODIFICATION
+#
+#   2008-10-13
+#
+# LICENSE
+#
+#   Written by Åukasz CieÅnik <lukasz.ciesnik@gmail.com>
+#   and placed under Public Domain.
+#
+AC_DEFUN([AX_GCC_WARNINGS], [
+if test x$GCC == xyes; then
+	AC_SUBST([GCC_W_NO_MISSING_FIELD_INITIALIZERS])
+	AC_SUBST([GCC_W_NO_FORMAT_ZERO_LENGTH])
+	CFLAGS_save="$CFLAGS"
+
+	AC_MSG_CHECKING([whether gcc accepts -Wno-missing-field-initializers])
+	CFLAGS="$CFLAGS_save -Wall -Wextra -Wno-missing-field-initializers"
+	ax_gcc_warnings_src="int main(){ return 0; }"
+	AC_COMPILE_IFELSE([$ax_gcc_warnings_src],
+		[GCC_W_NO_MISSING_FIELD_INITIALIZERS="-Wno-missing-field-initializers"
+		AC_MSG_RESULT([yes])],
+		[GCC_W_NO_MISSING_FIELD_INITIALIZERS="-Wno-extra"
+		AC_MSG_RESULT([no])])
+
+	AC_MSG_CHECKING([whether gcc accepts -Wno-format-zero-length])
+	CFLAGS="$CFLAGS_save -Wno-format-zero-length"
+	AC_COMPILE_IFELSE([$ax_gcc_warnings_src],
+		[GCC_W_NO_FORMAT_ZERO_LENGTH="-Wno-format-zero-length"
+		AC_MSG_RESULT([yes])],
+		[GCC_W_NO_FORMAT_ZERO_LENGTH="-Wno-format"
+		AC_MSG_RESULT([no])])
+
+	CFLAGS="$CFLAGS_save"
+fi
+])
Index: /branches/2.0/m4/ax_pbs.m4
===================================================================
--- /branches/2.0/m4/ax_pbs.m4	(revision 15)
+++ /branches/2.0/m4/ax_pbs.m4	(revision 15)
@@ -0,0 +1,115 @@
+# $Id$
+#
+# SYNOPSIS
+#
+#   AX_PBS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+#
+# DESCRIPTION
+#
+#   Check for PBS libraries and headers.
+#
+#   This macro calls::
+#
+#     AC_SUBST(PBS_INCLUDES)
+#     AC_SUBST(PBS_LIBS)
+#     AC_SUBST(PBS_LDFLAGS)
+#
+# LAST MODIFICATION
+#
+#   2008-06-13
+#
+# LICENSE
+#
+#   Written by Åukasz CieÅnik <lukasz.ciesnik@gmail.com>
+#   and placed under Public Domain. 
+#   
+#   Further contribution: Mariusz Mamonski <mamonski@man.poznan.pl> 
+#
+
+AC_DEFUN([AX_PBS],[
+AC_ARG_WITH([pbs], [AC_HELP_STRING([--with-pbs=<pbs-prefix>],
+		[Path to existing PBS installation root])])
+AC_ARG_ENABLE([disable-pbs-log], [AC_HELP_STRING([--disable-pbs-log],
+		[Do not use liblog while linking with PBS Professional])])
+		
+AC_SUBST(PBS_INCLUDES)
+AC_SUBST(PBS_LIBS)
+AC_SUBST(PBS_LDFLAGS)
+
+if test x"$with_pbs" != x; then
+	PBS_INCLUDES="-I${with_pbs}/include "
+	PBS_LDFLAGS="-L${with_pbs}/lib "
+else
+	T1=`which pbsnodes`
+	if test x"$T1" != x; then
+		T2=`dirname $T1`
+		PBS_HOME=`dirname $T2`
+		PBS_INCLUDES="-I${PBS_HOME}/include "
+		PBS_LDFLAGS="-L${PBS_HOME}/lib "
+	fi
+fi
+
+LDFLAGS_save="$LDFLAGS"
+CPPFLAGS_save="$CPPFLAGS"
+LDFLAGS="$LDFLAGS $PBS_LDFLAGS"
+CPPFLAGS="$CPPFLAGS $PBS_INCLUDES"
+
+ax_pbs_ok="no"
+
+AH_TEMPLATE([PBS_PROFESSIONAL], [compiling against PBS Professional])
+AH_TEMPLATE([PBS_PROFESSIONAL_NO_LOG], [Do not use liblog while linking with PBS Professional])
+
+if test x"$enable_pbs_log" != "xno"; then
+	ax_pbs_lib_log=" -llog"
+else
+	ax_pbs_lib_log=""
+	AC_DEFINE(PBS_PROFESSIONAL_NO_LOG,[1])
+fi
+
+if test x"$ax_pbs_ok" = xno; then
+	ax_pbs_ok="yes"
+	AC_CHECK_LIB([pbs], [pbs_submit], [:], [ax_pbs_ok="no"])
+	AC_CHECK_LIB([log], [pbse_to_txt], [:], [ax_pbs_ok="no"])
+	if test x"$ax_pbs_ok" = xyes; then
+		ax_pbs_libs="-lpbs $ax_pbs_lib_log"
+	fi
+fi
+
+AS_UNSET([ac_cv_lib_pbs_pbs_submit])
+AS_UNSET([ac_cv_lib_log_pbse_to_txt])
+
+if test x"$ax_pbs_ok" = xno; then
+	ax_pbs_ok="yes"
+	AC_CHECK_LIB([pbs], [pbs_submit], [:], [ax_pbs_ok="no"], [-lssl -lcrypto])
+	AC_CHECK_LIB([log], [pbse_to_txt], [:], [ax_pbs_ok="no"], [-lssl -lcrypto] )
+	if test x"$ax_pbs_ok" = xyes; then
+		ax_pbs_libs="-lpbs $ax_pbs_lib_log -lssl -lcrypto"
+	fi
+fi
+
+
+if test x"$ax_pbs_ok" = xno; then
+ 	ax_pbs_ok="yes"
+ 	AC_CHECK_LIB([torque], [pbs_submit], [:], [ax_pbs_ok="no"])
+ 	AC_CHECK_LIB([torque], [pbse_to_txt], [:], [ax_pbs_ok="no"])
+ 	if test x"$ax_pbs_ok" = xyes; then
+ 		ax_pbs_libs="-ltorque"
+ 	fi
+else
+	AC_DEFINE(PBS_PROFESSIONAL,[1])
+fi
+
+if test x"$ax_pbs_ok" = xyes; then
+	AC_CHECK_HEADERS([pbs_ifl.h pbs_error.h],[:],[ax_pbs_ok="no"])
+fi
+
+LDFLAGS="$LDFLAGS_save"
+CPPFLAGS="$CPPFLAGS_save"
+
+if test x"$ax_pbs_ok" = xyes; then
+	PBS_LIBS="$ax_pbs_libs"
+	ifelse($1, , :, $1) 
+else
+	ifelse($2, , :, $2) 
+fi
+])
Index: /branches/2.0/m4/ac_c_bigendian_cross.m4
===================================================================
--- /branches/2.0/m4/ac_c_bigendian_cross.m4	(revision 12)
+++ /branches/2.0/m4/ac_c_bigendian_cross.m4	(revision 12)
@@ -0,0 +1,86 @@
+dnl @synopsis AC_C_BIGENDIAN_CROSS
+dnl
+dnl Check endianess even when crosscompiling (partially based on the
+dnl original AC_C_BIGENDIAN).
+dnl
+dnl The implementation will create a binary, but instead of running the
+dnl binary it will be grep'ed for some symbols that differ for
+dnl different endianess of the binary.
+dnl
+dnl NOTE: The upcoming autoconf 2.53 does include the idea of this
+dnl macro, what makes it superfluous by then.
+dnl
+dnl @category CrossCompilation
+dnl @author Guido Draheim <guidod@gmx.de>
+dnl @version 2002-03-18
+dnl @license GPLWithACException
+
+AC_DEFUN([AC_C_BIGENDIAN_CROSS],
+[AC_CACHE_CHECK(whether byte ordering is bigendian, ac_cv_c_bigendian,
+[ac_cv_c_bigendian=unknown
+# See if sys/param.h defines the BYTE_ORDER macro.
+AC_TRY_COMPILE([#include <sys/types.h>
+#include <sys/param.h>], [
+#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
+ bogus endian macros
+#endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
+AC_TRY_COMPILE([#include <sys/types.h>
+#include <sys/param.h>], [
+#if BYTE_ORDER != BIG_ENDIAN
+ not big endian
+#endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
+if test $ac_cv_c_bigendian = unknown; then
+AC_TRY_RUN([main () {
+  /* Are we little or big endian?  From Harbison&Steele.  */
+  union
+  {
+    long l;
+    char c[sizeof (long)];
+  } u;
+  u.l = 1;
+  exit (u.c[sizeof (long) - 1] == 1);
+}], ac_cv_c_bigendian=no, ac_cv_c_bigendian=yes,
+[ echo $ac_n "cross-compiling... " 2>&AC_FD_MSG ])
+fi])
+if test $ac_cv_c_bigendian = unknown; then
+AC_MSG_CHECKING(to probe for byte ordering)
+[
+cat >conftest.c <<EOF
+short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
+short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
+void _ascii() { char* s = (char*) ascii_mm; s = (char*) ascii_ii; }
+short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
+short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
+void _ebcdic() { char* s = (char*) ebcdic_mm; s = (char*) ebcdic_ii; }
+int main() { _ascii (); _ebcdic (); return 0; }
+EOF
+] if test -f conftest.c ; then
+     if ${CC-cc} -c conftest.c -o conftest.o && test -f conftest.o ; then
+        if test `grep -l BIGenDianSyS conftest.o` ; then
+           echo $ac_n ' big endian probe OK, ' 1>&AC_FD_MSG
+	   ac_cv_c_bigendian=yes
+        fi
+        if test `grep -l LiTTleEnDian conftest.o` ; then
+           echo $ac_n ' little endian probe OK, ' 1>&AC_FD_MSG
+	   if test $ac_cv_c_bigendian = yes ; then
+	    ac_cv_c_bigendian=unknown;
+           else
+            ac_cv_c_bigendian=no
+           fi
+        fi
+	echo $ac_n 'guessing bigendian ...  ' >&AC_FD_MSG
+     fi
+  fi
+AC_MSG_RESULT($ac_cv_c_bigendian)
+fi
+if test $ac_cv_c_bigendian = yes; then
+  AC_DEFINE(WORDS_BIGENDIAN, 1, [whether byteorder is bigendian])
+  BYTEORDER=4321
+else
+  BYTEORDER=1234
+fi
+AC_DEFINE_UNQUOTED(BYTEORDER, $BYTEORDER, [1234 = LIL_ENDIAN, 4321 = BIGENDIAN])
+if test $ac_cv_c_bigendian = unknown; then
+  AC_MSG_ERROR(unknown endianess - sorry, please pre-set ac_cv_c_bigendian)
+fi
+])
Index: /branches/2.0/m4/ax_docutils.m4
===================================================================
--- /branches/2.0/m4/ax_docutils.m4	(revision 12)
+++ /branches/2.0/m4/ax_docutils.m4	(revision 12)
@@ -0,0 +1,33 @@
+# $Id$
+#
+# SYNOPSIS
+#
+#   AX_DOCUTILS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+#
+# DESCRIPTION
+#
+#   Test for the Docutils -- Python driven reStructuredText processor.
+#   This macro calls (through AC_CHECK_PROGS)::
+#
+#     AC_SUBST(RST2HTML)
+#     AC_SUBST(RST2LATEX)
+#
+# LAST MODIFICATION
+#
+#   2007-12-14
+#
+# LICENSE
+#
+#   Written by Åukasz CieÅnik <lukasz.ciesnik@fedstage.com>
+#   and placed under Public Domain
+#
+
+AC_DEFUN([AX_DOCUTILS], [
+	AC_CHECK_PROGS([RST2HTML], [rst2html rst2html.py])
+	AC_CHECK_PROGS([RST2LATEX], [rst2latex rst2latex.py])
+	if test x$RST2HTML != x -a x$RST2LATEX != x; then
+		ifelse([$1], , :, [$1])
+	else
+		ifelse([$2], , :, [$2])
+	fi
+])
Index: /branches/2.0/m4/acx_pthread.m4
===================================================================
--- /branches/2.0/m4/acx_pthread.m4	(revision 12)
+++ /branches/2.0/m4/acx_pthread.m4	(revision 12)
@@ -0,0 +1,245 @@
+dnl $Id$
+
+dnl
+dnl Check for libs/cppflags needed for POSIX Threads
+dnl
+
+dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+dnl
+dnl Modified from the original version:
+dnl * Removed pthread-specific CC support
+dnl * Added FreeBSD specific -pthread/-lpthread flags
+dnl Notes:
+dnl * -D_THREAD_SAFE may not be necessary on FreeBSD
+dnl   and elsewhere.
+dnl - landonf March 25th, 2005
+dnl
+dnl This macro figures out how to build C programs using POSIX threads.
+dnl It sets the PTHREAD_LIBS output variable to the threads library and
+dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
+dnl C compiler flags that are needed. (The user can also force certain
+dnl compiler flags/libs to be tested by setting these environment
+dnl variables.)
+dnl
+dnl NOTE: You are assumed to not only compile your program with these
+dnl flags, but also link it with them as well. e.g. you should link
+dnl with $CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
+dnl $LIBS
+dnl
+dnl If you are only building threads programs, you may wish to use
+dnl these variables in your default LIBS, and CFLAGS:
+dnl
+dnl        LIBS="$PTHREAD_LIBS $LIBS"
+dnl        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+dnl
+dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
+dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
+dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
+dnl
+dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
+dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
+dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
+dnl default action will define HAVE_PTHREAD.
+dnl
+dnl Please let the authors know if this macro fails on any platform, or
+dnl if you have any other suggestions or comments. This macro was based
+dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
+dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
+dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
+dnl We are also grateful for the helpful feedback of numerous users.
+dnl
+dnl @category InstalledPackages
+dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
+dnl @version 2005-01-14
+dnl @license GPLWithACException
+
+AC_DEFUN([ACX_PTHREAD], [
+AC_REQUIRE([AC_CANONICAL_HOST])
+AC_LANG_SAVE
+AC_LANG_C
+acx_pthread_ok=no
+
+# We used to check for pthread.h first, but this fails if pthread.h
+# requires special compiler flags (e.g. on True64 or Sequent).
+# It gets checked for in the link test anyway.
+
+# First of all, check if the user has set any of the PTHREAD_LIBS,
+# etcetera environment variables, and if threads linking works using
+# them:
+if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
+        save_CFLAGS="$CFLAGS"
+        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+        save_LIBS="$LIBS"
+        LIBS="$PTHREAD_LIBS $LIBS"
+        AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
+        AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
+        AC_MSG_RESULT($acx_pthread_ok)
+        if test x"$acx_pthread_ok" = xno; then
+                PTHREAD_LIBS=""
+                PTHREAD_CFLAGS=""
+        fi
+        LIBS="$save_LIBS"
+        CFLAGS="$save_CFLAGS"
+fi
+
+# We must check for the threads library under a number of different
+# names; the ordering is very important because some systems
+# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
+# libraries is broken (non-POSIX).
+
+# Create a list of thread flags to try.  Items starting with a "-" are
+# C compiler flags, and other items are library names, except for "none"
+# which indicates that we try without any flags at all, and "pthread-config"
+# which is a program returning the flags for the Pth emulation library.
+
+acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
+
+# The ordering *is* (sometimes) important.  Some notes on the
+# individual items follow:
+
+# pthreads: AIX (must check this before -lpthread)
+# none: in case threads are in libc; should be tried before -Kthread and
+#       other compiler flags to prevent continual compiler warnings
+# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
+# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
+# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
+# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
+# -pthreads: Solaris/gcc
+# -mthreads: Mingw32/gcc, Lynx/gcc
+# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
+#      doesn't hurt to check since this sometimes defines pthreads too;
+#      also defines -D_REENTRANT)
+# pthread: Linux, etcetera
+# --thread-safe: KAI C++
+# pthread-config: use pthread-config program (for GNU Pth library)
+
+case "${host_cpu}-${host_os}" in
+        *solaris*)
+
+        # On Solaris (at least, for some versions), libc contains stubbed
+        # (non-functional) versions of the pthreads routines, so link-based
+        # tests will erroneously succeed.  (We need to link with -pthread or
+        # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
+        # a function called by this macro, so we could check for that, but
+        # who knows whether they'll stub that too in a future libc.)  So,
+        # we'll just look for -pthreads and -lpthread first:
+
+        acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
+        ;;
+
+	*freebsd*)
+	# freebsd 4 uses -pthread, freebsd 5 uses -lpthread
+	acx_pthread_flags="pthread -pthread"
+	;;
+esac
+
+if test x"$acx_pthread_ok" = xno; then
+for flag in $acx_pthread_flags; do
+
+        case $flag in
+                none)
+                AC_MSG_CHECKING([whether pthreads work without any flags])
+                ;;
+
+                -*)
+                AC_MSG_CHECKING([whether pthreads work with $flag])
+                PTHREAD_CFLAGS="$flag"
+                PTHREAD_LIBS="$flag"
+                ;;
+
+		pthread-config)
+		AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
+		if test x"$acx_pthread_config" = xno; then continue; fi
+		PTHREAD_CFLAGS="`pthread-config --cflags`"
+		PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
+		;;
+
+                *)
+                AC_MSG_CHECKING([for the pthreads library -l$flag])
+                PTHREAD_LIBS="-l$flag"
+                ;;
+        esac
+
+        save_LIBS="$LIBS"
+        save_CFLAGS="$CFLAGS"
+        LIBS="$PTHREAD_LIBS $LIBS"
+        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+
+        # Check for various functions.  We must include pthread.h,
+        # since some functions may be macros.  (On the Sequent, we
+        # need a special flag -Kthread to make this header compile.)
+        # We check for pthread_join because it is in -lpthread on IRIX
+        # while pthread_create is in libc.  We check for pthread_attr_init
+        # due to DEC craziness with -lpthreads.  We check for
+        # pthread_cleanup_push because it is one of the few pthread
+        # functions on Solaris that doesn't have a non-functional libc stub.
+        # We try pthread_create on general principles.
+        AC_TRY_LINK([#include <pthread.h>],
+                    [pthread_t th; pthread_join(th, 0);
+                     pthread_attr_init(0); pthread_cleanup_push(0, 0);
+                     pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+                    [acx_pthread_ok=yes])
+
+        LIBS="$save_LIBS"
+        CFLAGS="$save_CFLAGS"
+
+        AC_MSG_RESULT($acx_pthread_ok)
+        if test "x$acx_pthread_ok" = xyes; then
+                break;
+        fi
+
+        PTHREAD_LIBS=""
+        PTHREAD_CFLAGS=""
+done
+fi
+
+# Various other checks:
+if test "x$acx_pthread_ok" = xyes; then
+        save_LIBS="$LIBS"
+        LIBS="$PTHREAD_LIBS $LIBS"
+        save_CFLAGS="$CFLAGS"
+        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+
+        # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
+	AC_MSG_CHECKING([for joinable pthread attribute])
+	attr_name=unknown
+	for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
+	    AC_TRY_LINK([#include <pthread.h>], [int attr=$attr;],
+                        [attr_name=$attr; break])
+	done
+        AC_MSG_RESULT($attr_name)
+        if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
+            AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
+                               [Define to necessary symbol if this constant
+                                uses a non-standard name on your system.])
+        fi
+
+        AC_MSG_CHECKING([if more special flags are required for pthreads])
+        flag=no
+        case "${host_cpu}-${host_os}" in
+            *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
+            *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
+        esac
+        AC_MSG_RESULT(${flag})
+        if test "x$flag" != xno; then
+            PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
+        fi
+
+        LIBS="$save_LIBS"
+        CFLAGS="$save_CFLAGS"
+
+fi
+
+AC_SUBST(PTHREAD_LIBS)
+AC_SUBST(PTHREAD_CFLAGS)
+
+# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
+if test x"$acx_pthread_ok" = xyes; then
+        ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
+        :
+else
+        acx_pthread_ok=no
+        $2
+fi
+AC_LANG_RESTORE
+])dnl ACX_PTHREAD
Index: /branches/2.0/m4/bison_ylwrap.sh
===================================================================
--- /branches/2.0/m4/bison_ylwrap.sh	(revision 12)
+++ /branches/2.0/m4/bison_ylwrap.sh	(revision 12)
@@ -0,0 +1,37 @@
+#!/bin/sh
+# ylwrap script specially crafted for Bison
+
+input="$1"; shift
+
+while true; do
+	case "$1" in
+		"")  exit 1;;
+		--)  shift; break;;
+		*)   shift;;
+	esac
+done
+
+prog="$1"; shift; args=($@)
+if [ ${prog} != "bison" ]; then
+	cat >&2 <<EOF
+ * ERROR: Bison was not found at configuration time while some sources are
+ * build by it.  Either install Bison <http://www.gnu.org/software/bison/>
+ * or download tarball with generated sources included (than you will
+ * not be able to modify .y files).
+EOF
+	exit 1
+fi
+
+real_args=()
+for i in ${args[@]}; do
+	case "$i" in
+		-y)  ;;
+		--yacc)  ;;
+		*)  real_args=(${real_args[@]} "$i") ;;
+	esac
+done
+
+echo "${prog} --output=`basename ${input} .y`.c ${real_args[@]} ${input}"
+${prog} --output=`basename ${input} .y`.c ${real_args[@]} ${input}
+
+
Index: /branches/2.0/m4/missing-dev-prog.sh
===================================================================
--- /branches/2.0/m4/missing-dev-prog.sh	(revision 12)
+++ /branches/2.0/m4/missing-dev-prog.sh	(revision 12)
@@ -0,0 +1,7 @@
+#!/bin/sh
+cat >&2 <<MESSAGE
+ * ERROR: $1 was not found at configuration time while some
+ * sources are build by it.  Either install $1 or download
+ * tarball with generated sources included.
+MESSAGE
+exit 1
Index: /branches/2.0/LICENSE
===================================================================
--- /branches/2.0/LICENSE	(revision 12)
+++ /branches/2.0/LICENSE	(revision 12)
@@ -0,0 +1,675 @@
+                      GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. http://fsf.org
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    
+	d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
Index: /branches/2.0/autoclean.sh
===================================================================
--- /branches/2.0/autoclean.sh	(revision 12)
+++ /branches/2.0/autoclean.sh	(revision 12)
@@ -0,0 +1,25 @@
+#!/bin/sh
+# $Id$
+
+echo "Removing all generated files. ($PWD)"
+
+make maintainer-clean
+
+rm -f aclocal.m4 configure configure.scan config.h.in confdefs.h libtool
+
+rm -rf autom4te.cache
+rm -rf scripts
+
+find . -name Makefile.in -exec rm -f {} \;
+find . -name Makefile -exec rm -f {} \;
+find . -name \*~ -exec rm -f {} \;
+find . -name \.#* -exec rm -f {} \;
+find . -name \*.core -exec rm -f {} \;
+find . -name \*.log -exec rm -f {} \;
+find . -name \*.a -exec rm -f {} \;
+find . -name \*.o -exec rm -f {} \;
+find . -name \*.lo* -exec rm -f {} \;
+find . -name \*.la* -exec rm -f {} \;
+
+(cd drmaa_utils && sh autoclean.sh "$@")
+echo "done."
Index: /branches/2.0/AUTHORS
===================================================================
--- /branches/2.0/AUTHORS	(revision 12)
+++ /branches/2.0/AUTHORS	(revision 12)
@@ -0,0 +1,11 @@
+$Id$
+
+Author:
+	Åukasz CieÅnik <lukasz.ciesnik@gmail.com>
+
+Contributors (also current maintainers):
+       MichaÅ MatÅoka <michal.matloka@student.put.poznan.pl>
+       Mariusz MamoÅski <mamonski@man.poznan.pl>
+
+Send bug reports to:
+       Mariusz MamoÅski <mamonski@man.poznan.pl>
