sbsv2/raptor/util/talon/talon.c
author raptorbot <raptorbot@systemstesthead.symbian.intra>
Mon, 22 Feb 2010 22:24:20 +0000
branchfix
changeset 251 64208ed747d4
parent 237 dd11681bd6f3
child 252 6846d05399b6
permissions -rw-r--r--
SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     1
/*
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     3
* All rights reserved.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     4
* This component and the accompanying materials are made available
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     6
* which accompanies this distribution, and is available
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     8
*
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     9
* Initial Contributors:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    10
* Nokia Corporation - initial contribution.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    11
*
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    12
* Contributors:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    13
*
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    14
* Description: 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    15
*
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    16
*/
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    17
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    18
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    19
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    20
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    21
#include <stdlib.h>
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    22
#include <unistd.h>
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    23
#include <string.h>
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    24
#include <stdio.h>
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    25
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    26
#include <sys/types.h>
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    27
#include <sys/stat.h>
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    28
#include <fcntl.h>
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    29
#include <stdarg.h>
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    30
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    31
#include "talon_process.h"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    32
#include "sema.h"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    33
#include "buffer.h"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    34
#include "../config.h"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    35
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    36
/* The output semaphore. */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    37
sbs_semaphore talon_sem;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    38
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    39
#define TALON_ATTEMPT_STRMAX 32
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    40
#define RECIPETAG_STRMAX 2048
237
dd11681bd6f3 SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents: 3
diff changeset
    41
#define STATUS_STRMAX 120
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    42
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    43
#define TALONDELIMITER '|'
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    44
#define VARNAMEMAX 100
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    45
#define VARVALMAX 1024
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    46
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    47
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    48
#include "log.h"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    49
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    50
#ifdef HAS_MSVCRT
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    51
/* Make all output handling binary */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    52
unsigned int _CRT_fmode = _O_BINARY;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    53
#endif
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    54
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    55
double getseconds(void)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    56
{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    57
	struct timeval tp;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    58
	gettimeofday(&tp, NULL);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    59
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    60
	return (double)tp.tv_sec + ((double)tp.tv_usec)/1000000.0L;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    61
}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    62
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    63
void talon_setenv(char name[], char val[])
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    64
{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    65
#if defined(HAS_GETENVIRONMENTVARIABLE)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    66
	SetEnvironmentVariableA(name,val); 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    67
#elif defined(HAS_GETENV)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    68
	setenv(name,val, 1);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    69
#else
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    70
#	error "Need a function for setting environment variables"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    71
#endif
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    72
}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    73
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    74
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    75
#define TALON_MAXENV 4096
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    76
char * talon_getenv(char name[])
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    77
{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    78
#if defined(HAS_SETENV)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    79
	char *val = getenv(name);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    80
	char *dest = NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    81
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    82
	if (val)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    83
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    84
		dest = malloc(strlen(val) + 1);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    85
		if (dest)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    86
		{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    87
			strcpy(dest,val);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    88
		}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    89
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    90
	return dest;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    91
#elif defined(HAS_SETENVIRONMENTVARIABLE)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    92
	char *val = malloc(TALON_MAXENV);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    93
	if (0 != GetEnvironmentVariableA(name,val,TALON_MAXENV-1))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    94
		return val;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    95
	else
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    96
		return NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    97
#else
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    98
#	error "Need a function for setting environment variables"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    99
#endif
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   100
}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   101
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   102
void prependattributes(buffer *b, char *attributes)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   103
{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   104
	char recipetag[RECIPETAG_STRMAX];
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   105
	char *rt;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   106
	char envvarname[VARNAMEMAX];
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   107
	char *att;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   108
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   109
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   110
        strcpy(recipetag, "<recipe ");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   111
	rt = recipetag + 8;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   112
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   113
	att = attributes;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   114
	while (*att != '\0' && rt < &recipetag[RECIPETAG_STRMAX-1])
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   115
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   116
		if ( *att == '$' )
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   117
		{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   118
			int e;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   119
			char *v;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   120
			/* insert the value of an environent variable */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   121
			att++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   122
			e = 0;	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   123
			do {
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   124
				envvarname[e++] = *att;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   125
				att++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   126
			} while ( e < (VARNAMEMAX-1) && (isalnum(*att) || *att == '_'));
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   127
			envvarname[e] = '\0';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   128
/* DEBUG(("envvarname: %s\n", envvarname)); */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   129
			v = talon_getenv(envvarname);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   130
			if (v)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   131
			{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   132
				/* DEBUG(("     value: %s\n", v)); */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   133
				char *oldv=v;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   134
				while (*v != '\0' && rt < &recipetag[RECIPETAG_STRMAX-1])
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   135
				{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   136
					*rt = *v;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   137
					rt++; v++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   138
				}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   139
				free(oldv);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   140
			}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   141
		} else {
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   142
			*rt = *att;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   143
			rt++; att++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   144
		}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   145
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   146
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   147
	char *finish = ">\n<![CDATA[\n";
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   148
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   149
	while (*finish != '\0' && rt < &recipetag[RECIPETAG_STRMAX-1])
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   150
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   151
		*rt = *finish;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   152
		*rt++; finish++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   153
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   154
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   155
	*rt = '\0';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   156
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   157
        buffer_prepend(b, recipetag, strlen(recipetag));
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   158
}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   159
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   160
/* read a recipe string from a temporary file.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   161
 *
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   162
 * We only expect to do this for very long command lines on
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   163
 * Windows. So allocate the maximum size for CreateProcess on
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   164
 * Win32 (32768 bytes) and error if the file is longer than that. 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   165
 *
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   166
 */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   167
char *read_recipe_from_file(const char *filename)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   168
{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   169
	FILE *fp = fopen(filename, "r");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   170
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   171
	if (!fp)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   172
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   173
		error("talon: error: could not read '%s'\n", filename);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   174
		return NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   175
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   176
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   177
	int max_length = 32768;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   178
	char *recipe = (char*)malloc(max_length);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   179
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   180
	if (!recipe)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   181
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   182
		error("talon: error: could not allocate memory to read '%s'\n", filename);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   183
		return NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   184
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   185
	int position = 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   186
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   187
	/* read the file one character at a time */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   188
	int c;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   189
	while ((c = getc(fp)) != EOF)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   190
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   191
		switch (c)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   192
		{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   193
			case '\r':
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   194
			case '\n':
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   195
				/* ignore newlines */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   196
				break;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   197
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   198
			case '"':
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   199
				/* double quotes have to be escaped so they aren't lost later */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   200
				if (position < max_length)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   201
					recipe[position++] = '\\';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   202
				if (position < max_length)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   203
					recipe[position++] = c;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   204
				break;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   205
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   206
			default:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   207
				if (position < max_length)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   208
					recipe[position++] = c;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   209
				break;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   210
		}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   211
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   212
	fclose(fp);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   213
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   214
	/* add a terminating \0 */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   215
	if (position < max_length)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   216
		recipe[position] = '\0';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   217
	else
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   218
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   219
		error("talon: error: command longer than 32768 in '%s'\n", filename);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   220
		return NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   221
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   222
	return recipe;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   223
}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   224
251
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   225
#ifdef HAS_GETCOMMANDLINE
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   226
/*
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   227
   Get rid of the path to talon from a commandline string on windows find the 
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   228
   -c (if it's there) and step past it to after the quote on the first command:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   229
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   230
   "g:\program files\talon\talon.exe" -c "gcc -c . . ."
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   231
                                          ^------ Returns a pointer to here
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   232
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   233
   Take care of the possibilty that there might be spaces in the command
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   234
   if it is quoted.
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   235
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   236
   A state-machine is flexible but not all that easy to write.  Should investigate
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   237
   the possiblity of using the Ragel state machine generator perhaps.
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   238
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   239
*/
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   240
#define CH_START 0
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   241
#define CH_PRE 1
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   242
#define CH_EXQUOTE 2
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   243
#define CH_INQUOTE 3
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   244
#define CH_POST 4
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   245
#define CH_MINUS 5
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   246
#define CH_C 6
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   247
#define CH_PRECOMMAND 7
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   248
#define CH_COMMAND 8
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   249
#define CH_ERR 9
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   250
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   251
char * chompCommand(char command[])
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   252
{
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   253
	char *result = command;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   254
	int state = CH_START;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   255
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   256
	while (state != CH_COMMAND && state != CH_ERR)
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   257
	{
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   258
		DEBUG(("startstate: %d, char %c ",state, *result));
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   259
		switch (*result)
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   260
		{
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   261
			case ' ':
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   262
				switch (state)
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   263
				{
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   264
					case CH_START:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   265
					case CH_PRE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   266
						state = CH_PRE;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   267
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   268
					case CH_EXQUOTE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   269
						state = CH_POST;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   270
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   271
					case CH_INQUOTE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   272
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   273
					case CH_POST:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   274
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   275
					case CH_MINUS:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   276
						state = CH_C;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   277
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   278
					case CH_C:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   279
						state = CH_PRECOMMAND;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   280
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   281
					case CH_PRECOMMAND:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   282
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   283
					default:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   284
						state = CH_ERR;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   285
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   286
				}
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   287
			break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   288
			case 'c':
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   289
				switch (state)
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   290
				{
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   291
					case CH_START:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   292
					case CH_PRE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   293
						state = CH_EXQUOTE;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   294
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   295
					case CH_EXQUOTE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   296
					case CH_INQUOTE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   297
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   298
					case CH_POST:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   299
						state = CH_ERR;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   300
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   301
					case CH_MINUS:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   302
						state = CH_C;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   303
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   304
					case CH_C:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   305
					case CH_PRECOMMAND:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   306
					default:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   307
						state = CH_ERR;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   308
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   309
				}
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   310
			break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   311
			case '-':
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   312
				switch (state)
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   313
				{
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   314
					case CH_START:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   315
					case CH_PRE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   316
						state = CH_EXQUOTE;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   317
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   318
					case CH_EXQUOTE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   319
					case CH_INQUOTE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   320
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   321
					case CH_POST:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   322
						state = CH_MINUS;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   323
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   324
					case CH_MINUS:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   325
					case CH_C:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   326
					case CH_PRECOMMAND:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   327
					default:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   328
						state = CH_ERR;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   329
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   330
				}
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   331
			break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   332
			case '"':
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   333
				switch (state)
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   334
				{
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   335
					case CH_START:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   336
					case CH_PRE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   337
					case CH_EXQUOTE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   338
						state = CH_INQUOTE;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   339
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   340
					case CH_INQUOTE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   341
						state = CH_EXQUOTE;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   342
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   343
					case CH_POST:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   344
					case CH_MINUS:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   345
					case CH_C:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   346
						state = CH_ERR;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   347
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   348
					case CH_PRECOMMAND:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   349
						state = CH_COMMAND;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   350
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   351
					default:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   352
						state = CH_ERR;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   353
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   354
				}
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   355
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   356
			break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   357
			default:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   358
				switch (state)
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   359
				{
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   360
					case CH_START:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   361
					case CH_PRE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   362
						state = CH_EXQUOTE;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   363
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   364
					case CH_INQUOTE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   365
					case CH_EXQUOTE:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   366
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   367
					default:
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   368
						state = CH_ERR;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   369
						break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   370
				}
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   371
			break;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   372
		}
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   373
		DEBUG((stderr,"endstate: %d\n",state));
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   374
		result ++;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   375
		
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   376
	}
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   377
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   378
	if (state == CH_ERR)
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   379
		return NULL;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   380
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   381
	return result;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   382
}
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   383
#endif
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   384
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   385
int main(int argc, char *argv[])
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   386
{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   387
	/* find the argument to -c then strip the talon related front section */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   388
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   389
	char *recipe = NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   390
	int talon_returncode = 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   391
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   392
#ifdef HAS_GETCOMMANDLINE
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   393
	char *commandline= GetCommandLine();
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   394
	/*
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   395
	 * The command line should be either,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   396
	 * talon -c "some shell commands"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   397
	 * or
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   398
	 * talon shell_script_file
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   399
	 *
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   400
	 * talon could be an absolute path and may have a .exe extension.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   401
	 */
251
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   402
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   403
	
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   404
	recipe = chompCommand(commandline);
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   405
	if (recipe == NULL)
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   406
	{
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   407
		error("talon: error: unable to locate argument start in '%s'\n", commandline);
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   408
		return 1;
64208ed747d4 SF Bug 2000 - Talon fails when installed in a path containing the string '-c' (windows only)
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents: 237
diff changeset
   409
	}
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   410
	if (recipe)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   411
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   412
		/* there was a -c so extract the quoted commands */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   413
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   414
		int recipelen = strlen(recipe);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   415
		if (recipelen > 0 && recipe[recipelen - 1] == '"')
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   416
			recipe[recipelen - 1] = '\0'; /* remove trailing quote */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   417
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   418
	else
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   419
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   420
		/* there was no -c so extract the argument as a filename */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   421
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   422
		recipe = strstr(commandline, "talon");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   423
		if (recipe)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   424
		{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   425
			/* find the first space */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   426
			while (!isspace(*recipe) && *recipe != '\0')
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   427
				recipe++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   428
			/* skip past the spaces */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   429
			while (isspace(*recipe))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   430
				recipe++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   431
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   432
			recipe = read_recipe_from_file(recipe);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   433
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   434
			if (!recipe)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   435
			{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   436
			    error("talon: error: bad script file in shell call '%s'\n", commandline);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   437
				return 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   438
			}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   439
		}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   440
		else
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   441
		{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   442
			error("talon: error: no 'talon' in shell call '%s'\n", commandline);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   443
			return 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   444
		}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   445
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   446
#else
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   447
	/*
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   448
	 * The command line should be either,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   449
	 * talon -c "some shell commands"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   450
	 * or
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   451
	 * talon shell_script_file
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   452
	 *
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   453
	 * talon could be an absolute path and may have a .exe extension.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   454
	 */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   455
	switch (argc)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   456
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   457
		case 2:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   458
			recipe = read_recipe_from_file(argv[1]);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   459
			break;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   460
		case 3:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   461
			if (strcmp("-c", argv[1]) != 0)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   462
			{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   463
				error("talon: error: %s\n", "usage is 'talon -c command' or 'talon script_filename'");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   464
				return 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   465
			}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   466
			recipe = argv[2];
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   467
			break;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   468
		default:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   469
			error("talon: error: %s\n", "usage is 'talon -c command' or 'talon script_filename'");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   470
			return 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   471
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   472
#endif
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   473
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   474
	/* did we get a recipe at all? */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   475
	if (!recipe)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   476
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   477
		error("talon: error: %s", "no recipe supplied to the shell.\n");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   478
		return 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   479
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   480
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   481
	/* remove any leading white space on the recipe */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   482
	while (isspace(*recipe))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   483
		recipe++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   484
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   485
	/* turn debugging on? */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   486
	char *debugstr=talon_getenv("TALON_DEBUG");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   487
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   488
	if (debugstr)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   489
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   490
		loglevel=LOGDEBUG;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   491
		free(debugstr); debugstr=NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   492
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   493
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   494
	DEBUG(("talon: recipe: %s\n", recipe));
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   495
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   496
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   497
	char varname[VARNAMEMAX];
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   498
	char varval[VARVALMAX];
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   499
	int dotagging = 0; 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   500
	int force_descramble_off = 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   501
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   502
	char  *rp = recipe;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   503
	if (*rp == TALONDELIMITER) {
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   504
		dotagging = 1; 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   505
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   506
		/* there are some talon-specific settings 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   507
		 * in the command which must be stripped */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   508
		rp++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   509
		char *out = varname;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   510
		char *stopout = varname + VARNAMEMAX - 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   511
		DEBUG(("talon: parameters found\n"));
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   512
		while (*rp != '\0')
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   513
		{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   514
			
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   515
			switch (*rp) {
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   516
				case  '=':
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   517
					*out = '\0';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   518
					DEBUG(("talon: varname: %s\n",varname));
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   519
					out = varval;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   520
					stopout = varval + VARVALMAX - 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   521
					break;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   522
				case ';':
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   523
					*out = '\0';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   524
					DEBUG(("talon: varval: %s\n",varval));
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   525
					talon_setenv(varname, varval);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   526
					out = varname;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   527
					stopout = varname + VARNAMEMAX - 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   528
					break;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   529
				default:	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   530
					*out = *rp;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   531
					if (out < stopout)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   532
						out++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   533
					break;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   534
			}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   535
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   536
			if (*rp == TALONDELIMITER)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   537
			{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   538
				rp++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   539
				break;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   540
			}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   541
			
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   542
			rp++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   543
		}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   544
	} else {
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   545
		/* This is probably a $(shell) statement 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   546
 		 * in make so no descrambling needed and 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   547
 		 * tags are definitely not wanted as they 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   548
 		 * would corrupt the expected output*/
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   549
		force_descramble_off = 1; 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   550
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   551
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   552
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   553
	/* Now take settings from the environment (having potentially modified it) */	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   554
	if (talon_getenv("TALON_DEBUG"))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   555
		loglevel=LOGDEBUG;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   556
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   557
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   558
	int enverrors = 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   559
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   560
	char *shell = talon_getenv("TALON_SHELL");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   561
	if (!shell)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   562
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   563
		error("error: %s", "TALON_SHELL not set in environment\n");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   564
		enverrors++;	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   565
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   566
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   567
	int timeout = -1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   568
	char *timeout_str = talon_getenv("TALON_TIMEOUT");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   569
	if (timeout_str)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   570
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   571
		timeout = atoi(timeout_str);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   572
		free(timeout_str); timeout_str = NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   573
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   574
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   575
	char *buildid = talon_getenv("TALON_BUILDID");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   576
	if (!buildid)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   577
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   578
		error("error: %s", "TALON_BUILDID not set in environment\n");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   579
		enverrors++;	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   580
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   581
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   582
	char *attributes = talon_getenv("TALON_RECIPEATTRIBUTES");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   583
	if (!attributes)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   584
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   585
		error("error: %s", "TALON_RECIPEATTRIBUTES not set in environment\n");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   586
		enverrors++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   587
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   588
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   589
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   590
	int max_retries = 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   591
	char *retries_str = talon_getenv("TALON_RETRIES");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   592
	if (retries_str)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   593
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   594
		max_retries = atoi(retries_str);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   595
		free(retries_str); retries_str = NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   596
	}	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   597
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   598
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   599
	int descramble = 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   600
	if (! force_descramble_off )
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   601
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   602
		char *descramblestr = talon_getenv("TALON_DESCRAMBLE");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   603
		if (descramblestr)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   604
		{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   605
			if (*descramblestr == '0')
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   606
				descramble = 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   607
			else
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   608
				descramble = 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   609
		
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   610
			free(descramblestr); descramblestr = NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   611
		}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   612
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   613
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   614
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   615
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   616
	/* Talon can look in a flags variable to alter it's behaviour */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   617
	int force_success = 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   618
	char *flags_str = talon_getenv("TALON_FLAGS");
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   619
	if (flags_str)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   620
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   621
		int c;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   622
		for (c=0; flags_str[c] !=0; c++)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   623
			flags_str[c] = tolower(flags_str[c]);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   624
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   625
		if (strstr(flags_str, "forcesuccess"))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   626
			force_success = 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   627
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   628
		/* don't put <recipe> or <CDATA<[[ tags around the output. e.g. if it's XML already*/
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   629
		if (strstr(flags_str, "rawoutput"))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   630
		{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   631
			dotagging = 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   632
		}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   633
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   634
		free(flags_str); flags_str = NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   635
	}	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   636
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   637
	/* Talon subprocesses need to have the "correct" shell variable set. */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   638
	talon_setenv("SHELL", shell); 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   639
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   640
	/* we have allowed some errors to build up so that the user
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   641
	 * can see all of them before we stop and force the user 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   642
	 * to fix them
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   643
	 */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   644
	if (enverrors)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   645
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   646
		return 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   647
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   648
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   649
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   650
	/* Run the recipe repeatedly until the retry count expires or
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   651
	 * it succeeds.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   652
	 */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   653
	int attempt = 0, retries = max_retries;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   654
	proc *p = NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   655
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   656
	char *args[5];
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   657
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   658
	char *qrp=rp;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   659
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   660
#ifdef HAS_GETCOMMANDLINE
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   661
	/* re-quote the argument to -c since this helps windows deal with it */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   662
	int qrpsize = strlen(rp) + 3;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   663
	qrp = malloc(qrpsize);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   664
	qrp[0] = '"';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   665
	strcpy(&qrp[1], rp);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   666
	qrp[qrpsize-2] = '"';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   667
	qrp[qrpsize-1] = '\0';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   668
#endif
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   669
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   670
	int index = 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   671
	args[index++] = shell;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   672
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   673
	if (dotagging)  /* don't do bash -x for non-tagged commands e.g. $(shell output) */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   674
		args[index++] = "-x";
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   675
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   676
	args[index++] = "-c";
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   677
	args[index++] = qrp;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   678
	args[index++] = NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   679
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   680
	/* get the semaphore ready */
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   681
	talon_sem.name = buildid;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   682
	talon_sem.timeout = timeout;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   683
	do
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   684
	{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   685
		char talon_attempt[TALON_ATTEMPT_STRMAX];
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   686
		double start_time = getseconds();
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   687
		
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   688
		attempt++;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   689
		
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   690
		snprintf(talon_attempt, TALON_ATTEMPT_STRMAX-1, "%d", attempt);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   691
		talon_attempt[TALON_ATTEMPT_STRMAX - 1] = '\0';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   692
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   693
		talon_setenv("TALON_ATTEMPT", talon_attempt);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   694
		
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   695
		p = process_run(shell, args, timeout);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   696
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   697
		double end_time = getseconds();
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   698
		
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   699
		if (p) 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   700
		{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   701
			char status[STATUS_STRMAX];
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   702
			char timestat[STATUS_STRMAX];
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   703
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   704
			talon_returncode = p->returncode;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   705
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   706
			if (dotagging) 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   707
			{
237
dd11681bd6f3 SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents: 3
diff changeset
   708
				char *flagsstr = force_success == 0 ? "" : " flags='FORCESUCCESS'";
dd11681bd6f3 SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents: 3
diff changeset
   709
				char *reasonstr = "" ;
dd11681bd6f3 SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents: 3
diff changeset
   710
dd11681bd6f3 SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents: 3
diff changeset
   711
				if (p->causeofdeath == PROC_TIMEOUTDEATH)
dd11681bd6f3 SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents: 3
diff changeset
   712
					reasonstr = " reason='timeout'";
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   713
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   714
				if (p->returncode != 0)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   715
				{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   716
					char *exitstr = retries > 0 ? "retry" : "failed";
237
dd11681bd6f3 SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents: 3
diff changeset
   717
					snprintf(status, STATUS_STRMAX - 1, "\n<status exit='%s' code='%d' attempt='%d'%s%s />", exitstr, p->returncode, attempt, flagsstr, reasonstr );
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   718
				} else {
237
dd11681bd6f3 SF bug 1861 : display informative messages when timeouts occur in build tasks.
timothy.murphy@nokia.com
parents: 3
diff changeset
   719
					snprintf(status, STATUS_STRMAX - 1, "\n<status exit='ok' attempt='%d'%s%s />", attempt, flagsstr, reasonstr );
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   720
				}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   721
				status[STATUS_STRMAX-1] = '\0';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   722
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   723
				snprintf(timestat, STATUS_STRMAX - 1, "<time start='%.5f' elapsed='%.3f' />",start_time, end_time-start_time );
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   724
				timestat[STATUS_STRMAX-1] = '\0';
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   725
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   726
				prependattributes(p->output, attributes);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   727
			
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   728
			if (dotagging) {
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   729
			}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   730
				buffer_append(p->output, "\n]]>", 4);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   731
				buffer_append(p->output, timestat, strlen(timestat));
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   732
				buffer_append(p->output, status, strlen(status));
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   733
				buffer_append(p->output, "\n</recipe>\n", 11);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   734
			}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   735
		
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   736
			unsigned int iterator = 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   737
			byteblock *bb;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   738
		
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   739
			if (descramble)	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   740
				sema_wait(&talon_sem);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   741
			while ((bb = buffer_getbytes(p->output, &iterator)))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   742
			{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   743
				write(STDOUT_FILENO, &bb->byte0, bb->fill);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   744
			}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   745
			if (descramble)	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   746
				sema_release(&talon_sem);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   747
		
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   748
		
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   749
			if (p->returncode == 0 || force_success)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   750
			{
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   751
				process_free(&p);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   752
				break;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   753
			}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   754
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   755
			process_free(&p);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   756
		} else {
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   757
			error("error: failed to run shell: %s: check the SHELL environment variable.\n", args[0]);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   758
			return 1;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   759
		}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   760
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   761
		retries--;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   762
	}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   763
	while (retries >= 0);
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   764
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   765
	if (buildid) free(buildid); buildid = NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   766
	if (attributes) free(attributes); attributes = NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   767
	if (shell) free(shell); shell = NULL;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   768
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   769
	if (force_success)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   770
		return 0;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   771
	else 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   772
		return talon_returncode;
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   773
}