imgtools/imglib/host/h_utl.cpp
author Mike Kinghan <mikek@symbian.org>
Tue, 13 Jul 2010 15:22:53 +0100
changeset 25 223dcf462b73
permissions -rwxr-xr-x
Re-adding erroneously forgotten files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     1
/*
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     2
* Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     3
* All rights reserved.
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     8
*
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     9
* Initial Contributors:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    11
*
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    12
* Contributors:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    13
*
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    14
* Description: 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    15
*
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    16
*/
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    17
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    18
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    19
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    20
#define __INCLUDE_CAPABILITY_NAMES__
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    21
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    22
#if defined(_MSVCDOTNET__) || defined(__TOOLS2__)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    23
#include <string>
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    24
#else //!__MSVCDOTNET__
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    25
#include <string.h>
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    26
#endif //__MSVCDOTNET__
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    27
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    28
#include <stdarg.h>
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    29
#include <stdlib.h>
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    30
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    31
#include <e32std.h>
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    32
#include <e32std_private.h>
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    33
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    34
#include "h_utl.h"
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    35
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    36
#ifdef __LINUX__
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    37
 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    38
 // Convert the supplied string to uppercase, in-place 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    39
 char* strupr(char *a)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    40
    {
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    41
     char *ret = a;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    42
 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    43
    while (*a)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    44
        {
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    45
        *a = toupper(*a);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    46
        a++;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    47
         }
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    48
 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    49
     return ret;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    50
     }
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    51
 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    52
 off_t filelength(int filedes)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    53
     {
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    54
     struct stat buf;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    55
     if(!fstat(filedes, &buf))
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    56
         {
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    57
        return buf.st_size;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    58
         }
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    59
    perror("fstat failed");
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    60
   return 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    61
    }
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    62
 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    63
#endif
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    64
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    65
TBool PVerbose=ETrue;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    66
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    67
HPrint H;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    68
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    69
HPrint::~HPrint()
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    70
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    71
	iLogFile.close();
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    72
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    73
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    74
void HPrint::SetLogFile(TText *aFileName)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    75
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    76
	iLogFile.open((const char *)aFileName);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    77
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    78
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    79
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    80
/**
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    81
Closing the logfile.(since 'n' number of drive images can be created)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    82
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    83
@internalComponent
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    84
@released
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    85
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    86
*/
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    87
void HPrint::CloseLogFile()
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    88
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    89
	if(iLogFile.is_open())
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    90
		iLogFile.close();
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    91
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    92
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    93
TInt HPrint::PrintString(TPrintType aType,const char *aFmt,...)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    94
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    95
// Print text, noting where to send it.
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    96
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    97
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    98
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    99
	TInt r=KErrNone;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   100
	va_list list;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   101
	va_start(list,aFmt);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   102
	_vsnprintf((char *)iText,KMaxStringLength,aFmt,list);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   103
	va_end(list);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   104
	switch (aType)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   105
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   106
	case EAlways:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   107
		cout << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   108
		iLogFile << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   109
		break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   110
	case EScreen:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   111
		cout << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   112
		break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   113
	case ELog:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   114
		if (iVerbose)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   115
			cout << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   116
		iLogFile << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   117
		break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   118
	case EWarning:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   119
		cerr << "WARNING: " << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   120
		iLogFile << "WARNING: "<<iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   121
		break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   122
	case EError:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   123
		cerr << "ERROR: " << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   124
		iLogFile << "ERROR: " << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   125
		r=KErrGeneral;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   126
		break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   127
	case EPeError:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   128
		if (PVerbose)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   129
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   130
			cerr << "ERROR: " << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   131
			iLogFile << "ERROR: " << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   132
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   133
		r=KErrGeneral;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   134
		break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   135
	case ESevereError:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   136
		cerr << "ERROR: " << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   137
		iLogFile << "ERROR: " << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   138
		r=KErrGeneral;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   139
		break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   140
	case EDiagnostic:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   141
		cerr << "DIAGNOSTIC MESSAGE: " << iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   142
		iLogFile << "DIAGNOSTIC MESSAGE: "<<iText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   143
		break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   144
	default:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   145
		cerr << "ERROR: Invalid print type" << endl;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   146
		r=KErrGeneral;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   147
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   148
	cout.flush();
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   149
	iLogFile.flush();
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   150
	return r;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   151
    }
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   152
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   153
TVersion::TVersion()
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   154
	{}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   155
TVersion::TVersion(TInt aMajor, TInt aMinor, TInt aBuild)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   156
	: iMajor((TInt8)aMajor), iMinor((TInt8)aMinor), iBuild((TInt16)aBuild)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   157
	{}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   158
#ifdef __TOOLS2__
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   159
istringstream &operator>>(istringstream &is, TVersion &aVersion)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   160
#else
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   161
istrstream &operator>>(istrstream &is, TVersion &aVersion)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   162
#endif
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   163
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   164
// Input a TVersion with syntax: major[.minor][(build)]
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   165
//	
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   166
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   167
#ifdef __TOOLS2__
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   168
string tmp = is.str();
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   169
const char *str=tmp.c_str();
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   170
#else
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   171
#ifdef __LINUX__
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   172
    char *str = is.rdbuf()->str();
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   173
#else
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   174
    char *str=is.str();
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   175
#endif
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   176
#endif
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   177
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   178
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   179
	TInt build=0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   180
	memset(&aVersion, 0, sizeof(TVersion));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   181
	TInt i;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   182
	TInt len=strlen(str);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   183
	for (i=0; i<len; i++)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   184
		if (str[i]=='(')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   185
			break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   186
	if (i<len)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   187
		build=atoi(str+i+1);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   188
	aVersion.iMajor = (TInt8)Min(KMaxTInt8, atoi(str));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   189
	int majorV = atoi(str);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   190
	// iMajor is defined as TInt8 so it should not be bigger than 127
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   191
	if (majorV > 127)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   192
		{ 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   193
		cout << "\n Warning: major version must be in range 0 - 127 \n";
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   194
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   195
	char const * pMinor = strchr(str, '.');
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   196
	if (pMinor)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   197
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   198
		pMinor++; 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   199
		aVersion.iMinor = (TInt8)Min(KMaxTInt8, atoi(pMinor));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   200
		int minorV = atoi(pMinor);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   201
		// iMinor is defined as TInt8 so it should not be bigger than 127
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   202
		if (minorV > 127)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   203
			{ 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   204
			cout << "\n Warning: minor version must be in range 0 - 127 \n";
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   205
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   206
		}	
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   207
	aVersion.iBuild=(TInt16)build;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   208
	return is;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   209
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   210
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   211
TInt Locate(const char *aString, char aChar)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   212
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   213
// Locate aChar in aString
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   214
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   215
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   216
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   217
	if (aString==NULL)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   218
		return KErrNotFound;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   219
	TInt i=0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   220
	while (*aString!=0)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   221
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   222
		if (*aString==aChar)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   223
			return i;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   224
		aString++;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   225
		i++;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   226
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   227
	return KErrNotFound;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   228
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   229
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   230
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   231
#define KHoursToMicroSeconds	Int64(3600000000UL) 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   232
#define KDaysToMicroSeconds		(Int64(24)*KHoursToMicroSeconds)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   233
const TInt KMinutesToMicroSeconds = 60000000;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   234
const TInt KSecondsToMicroSeconds =  1000000;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   235
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   236
const TInt8 mTab[2][12]=
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   237
    {
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   238
    {31,28,31,30,31,30,31,31,30,31,30,31}, // 28 days in Feb
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   239
    {31,29,31,30,31,30,31,31,30,31,30,31}  // 29 days in Feb
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   240
    };
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   241
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   242
TInt Time::LeapYearsUpTo(TInt aYear)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   243
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   244
// from 0AD to present year according to the rule above
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   245
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   246
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   247
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   248
	if (aYear<=0)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   249
		return(aYear/4);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   250
	if (aYear<=1600)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   251
		return(1+((aYear-1)/4));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   252
	TInt num=401; // 1600/4+1
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   253
	aYear-=1601;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   254
	num+=(aYear/4-aYear/100+aYear/400);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   255
	return(num);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   256
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   257
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   258
TBool Time::IsLeapYear(TInt aYear)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   259
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   260
// up to and including 1600 leap years were every 4 years,since then leap years are every 4 years unless
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   261
// the year falls on a century which is not divisible by 4 (ie 1900 wasnt,2000 will be)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   262
// for simplicity define year 0 as a leap year
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   263
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   264
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   265
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   266
	if (aYear>1600)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   267
    	return(!(aYear%4) && (aYear%100 || !(aYear%400)));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   268
	return(!(aYear%4));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   269
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   270
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   271
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   272
Int64 ConvertTime(TInt aDay, TInt aMonth, TInt aYear, TInt aHour, TInt aMinute, TInt aSecond, TInt aMilliSeconds)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   273
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   274
// converts TDateTime into a TTime, doesnt check for overflows
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   275
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   276
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   277
	
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   278
	TInt days=365*aYear+Time::LeapYearsUpTo(aYear);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   279
	TBool isleap=Time::IsLeapYear(aYear);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   280
	for (TInt ii=0; ii<aMonth; ii++)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   281
	    days+=(mTab[isleap][ii]);	
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   282
	days+=aDay;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   283
	TInt sum=aMilliSeconds+aSecond*KSecondsToMicroSeconds;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   284
	return((Int64(days)*KDaysToMicroSeconds+Int64(aHour)*KHoursToMicroSeconds) 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   285
			+(Int64(KMinutesToMicroSeconds)*Int64(aMinute)+Int64(sum))); 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   286
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   287
	
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   288
TInt StringToTime(Int64 &aTime, char *aString)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   289
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   290
// Convert string to time. String is in the format:
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   291
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   292
// dd/mm/yyyy hh:mm:ss.mmmmmmm
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   293
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   294
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   295
	TInt day=1;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   296
	TInt month=1;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   297
	TInt year=1997;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   298
	TInt hour=10;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   299
	TInt minute=10;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   300
	TInt sec=0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   301
	TInt mill=0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   302
	char ch;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   303
	#ifdef __TOOLS2__
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   304
	istringstream val(aString);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   305
	#else
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   306
	istrstream val(aString,strlen(aString));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   307
	#endif
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   308
	val >> dec >> day; // locks istrstream in decimal mode for further extractions
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   309
	val >> ch;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   310
	if (ch!='/')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   311
		return KErrGeneral;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   312
	val >> month;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   313
	val >> ch;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   314
	if (ch!='/')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   315
		return KErrGeneral;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   316
	val >> year;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   317
	val >> ch;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   318
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   319
	if (ch=='_')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   320
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   321
		// time too.
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   322
		val >> hour;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   323
		val >> ch;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   324
		if (ch!=':')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   325
			return KErrGeneral;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   326
		val >> minute;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   327
		val >> ch;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   328
		if (ch!=':')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   329
			return KErrGeneral;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   330
		val >> sec;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   331
		val >> ch;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   332
		if (ch=='.')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   333
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   334
			val >> mill;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   335
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   336
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   337
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   338
	if (day<1 || day>31)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   339
		return KErrArgument;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   340
	if (month<1 || month>12)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   341
		return KErrArgument;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   342
	if (year<1970 || year>2060)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   343
		return KErrArgument;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   344
	if (hour<0 || hour>23)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   345
		return KErrArgument;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   346
	if (minute<0 || minute>59)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   347
		return KErrArgument;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   348
	if (sec<0 || sec>59)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   349
		return KErrArgument;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   350
	if (mill<0 || mill>999999)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   351
		return KErrArgument;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   352
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   353
	aTime=ConvertTime(day-1, month-1, year, hour, minute, sec, mill);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   354
	return KErrNone;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   355
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   356
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   357
void ByteSwap(TUint &aVal)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   358
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   359
	TUint t0=aVal & 0xff;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   360
	TUint t1=(aVal>>8)  & 0xff;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   361
	TUint t2=(aVal>>16) & 0xff;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   362
	TUint t3=aVal>>24;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   363
	aVal=(t0 << 24) | (t1 << 16) | (t2 << 8) | (t3);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   364
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   365
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   366
void ByteSwap(TUint16 &aVal)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   367
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   368
	TUint16 t0=(TUint16)((aVal >> 8) & 0xff);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   369
	TUint16 t1=(TUint16)(aVal & 0xff);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   370
	aVal=(TUint16)((t1 << 8) | t0);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   371
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   372
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   373
void ByteSwap(TUint *aPtr, TInt aSize)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   374
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   375
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   376
	while ((aSize-=4)>=0)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   377
		ByteSwap(*aPtr++);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   378
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   379
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   380
TBool IsBracketedHex(const char* s, const char* brackets, TInt digits, TUint32& aValue)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   381
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   382
	if (s[0]!=brackets[0] || s[1+digits]!=brackets[1])
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   383
		return EFalse;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   384
	TInt i;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   385
	TUint32 x = 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   386
	for (i=1; i<=digits; ++i)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   387
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   388
		TInt c = s[i];
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   389
		if (c>='a' && c<='z') c-=32;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   390
		if (c<'0' || (c>'9' && c<'A') || c>'F')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   391
			return EFalse;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   392
		c-='0';
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   393
		if (c>9) c-=7;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   394
		x = (x<<4) | (TUint32)c;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   395
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   396
	aValue = x;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   397
	return ETrue;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   398
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   399
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   400
TInt CheckForDecimalVersion(const char* begin, const char* s, TUint32& aValue)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   401
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   402
	aValue = 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   403
	if (s <= begin || *s != '}')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   404
		return 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   405
	TUint32 v[2] = {0,0};
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   406
	TUint32 m = 1;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   407
	TInt pos = 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   408
	const char* s0 = s + 1;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   409
	for (--s; s >= begin; --s)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   410
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   411
		int c = *s;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   412
		if (c >= '0' && c <= '9')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   413
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   414
			v[pos] += m * (c - '0');
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   415
			if (v[pos] >= 65536u)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   416
				return 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   417
			m *= 10;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   418
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   419
		else if (c == '.')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   420
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   421
			m = 1;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   422
			if (++pos >= 2)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   423
				return 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   424
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   425
		else if (c == '{')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   426
			break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   427
		else
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   428
			return 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   429
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   430
	if (s < begin)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   431
		return 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   432
	aValue = (v[1] << 16) | v[0];
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   433
	return s0 - s;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   434
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   435
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   436
// Decompose a name of the form NAME{MMMMmmmm}[UUUUUUUU].EXT where the bracketed
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   437
// sections and extension are both optional.
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   438
// Return a newly malloc-ed string containing NAME.EXT
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   439
// Set aUid = 0xUUUUUUUU if present, 0 if not
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   440
// Set aModuleVersion = 0xMMMMmmmm if present, 0 if not
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   441
// Set aFlags according to which of these are present
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   442
char* SplitFileName(const char* aName, TUint32& aUid, TUint32& aModuleVersion, TUint32& aFlags)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   443
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   444
	TFileNameInfo f(aName, ETrue);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   445
	aUid = f.iUid3;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   446
	aModuleVersion = f.iModuleVersion;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   447
	aFlags = f.iFlags;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   448
	TInt nl = f.iBaseLength;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   449
	TInt el = f.iTotalLength - f.iExtPos;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   450
	TInt tl = nl + el;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   451
	char* t = (char*)malloc(tl + 1);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   452
	if (t)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   453
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   454
		memcpy(t, aName, nl);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   455
		if (el)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   456
			memcpy(t + nl, aName + f.iExtPos, el);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   457
		t[tl] = 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   458
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   459
	return t;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   460
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   461
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   462
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   463
// Decompose a name of the form NAME{MMMMmmmm}.EXT where the bracketed
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   464
// sections and extension are both optional.
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   465
// Return a newly malloc-ed string containing NAME.EXT
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   466
// Set aModuleVersion = 0xMMMMmmmm if present, 0 if not
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   467
// Set aFlags according to whether version present
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   468
char* SplitFileName(const char* aName, TUint32& aModuleVersion, TUint32& aFlags)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   469
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   470
	TFileNameInfo f(aName, EFalse);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   471
	aModuleVersion = f.iModuleVersion;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   472
	aFlags = f.iFlags;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   473
	TInt nl = f.iBaseLength;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   474
	TInt el = f.iTotalLength - f.iExtPos;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   475
	TInt tl = nl + el;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   476
	char* t = (char*)malloc(tl + 1);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   477
	if (t)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   478
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   479
		memcpy(t, aName, nl);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   480
		if (el)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   481
			memcpy(t + nl, aName + f.iExtPos, el);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   482
		t[tl] = 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   483
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   484
	return t;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   485
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   486
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   487
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   488
// Parse a filename and convert decimal version number to hex
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   489
// If aConvertPathPunct is true (default) then path punctuators
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   490
// will be converted to the host system kind (Windows = '\\', Linux = '/')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   491
char* NormaliseFileName(const char* aName, bool aConvertPathPunct)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   492
{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   493
	//convert forward slashes into back slashes.
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   494
	char* filename = strdup(aName);  //prevent violated access from stack.
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   495
	if (aConvertPathPunct)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   496
		{ 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   497
		char* fwdslashfinder = filename;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   498
#ifndef __LINUX__
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   499
		fwdslashfinder=strstr(fwdslashfinder, "/");
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   500
		while(fwdslashfinder)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   501
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   502
			*fwdslashfinder++ = '\\';
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   503
			fwdslashfinder=strstr(fwdslashfinder, "/");
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   504
	  	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   505
#else
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   506
		fwdslashfinder=strstr(fwdslashfinder, "\\");
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   507
		while(fwdslashfinder)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   508
		  	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   509
			*fwdslashfinder++ = '/';
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   510
			fwdslashfinder=strstr(fwdslashfinder, "\\");
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   511
		  	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   512
#endif
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   513
		}	
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   514
	//normalize filename.
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   515
	TFileNameInfo f(filename, EFalse);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   516
	TInt nl = f.iBaseLength;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   517
	TInt el = f.iTotalLength - f.iExtPos;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   518
	TInt tl = nl + el;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   519
	if (f.iFlags & EVerPresent)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   520
		tl += 10;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   521
	char* t = (char*)malloc(tl + 1);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   522
	if (t)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   523
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   524
		memcpy(t, filename, nl);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   525
		if (f.iFlags & EVerPresent)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   526
			sprintf(t + nl, "{%08lx}%s", f.iModuleVersion, filename + f.iExtPos);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   527
		else if (el)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   528
			memcpy(t + nl, filename + f.iExtPos, el);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   529
		t[tl] = 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   530
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   531
	free(filename);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   532
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   533
	return t;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   534
}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   535
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   536
TFileNameInfo::TFileNameInfo(const char* aFileName, TBool aLookForUid)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   537
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   538
	iFileName = aFileName;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   539
	TInt l = strlen(aFileName);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   540
	iTotalLength = l;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   541
	TInt remain = l;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   542
	iFlags = 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   543
	iUid3 = 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   544
	iModuleVersion = 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   545
	iBaseLength = l;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   546
	iExtPos = l;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   547
	const char* s = iFileName + l;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   548
	for (; s>=iFileName && *s!='.' && *s!='}' && (!aLookForUid || *s!=']'); --s) {}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   549
	if (s<iFileName)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   550
		return;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   551
	if (*s == '.')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   552
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   553
		iExtPos = s - iFileName;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   554
		if (iExtPos == 0)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   555
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   556
			iBaseLength = 0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   557
			return;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   558
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   559
		remain = iExtPos;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   560
		--s;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   561
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   562
	else if (s != iFileName + l)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   563
		return;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   564
	if (aLookForUid && remain>=10 && IsBracketedHex(s-9, "[]", 8, iUid3))
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   565
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   566
		iFlags |= EUidPresent;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   567
		remain -= 10;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   568
		s -= 10;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   569
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   570
	if (remain>=10 && IsBracketedHex(s-9, "{}", 8, iModuleVersion))
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   571
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   572
		iFlags |= EVerPresent;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   573
		remain -= 10;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   574
		s -= 10;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   575
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   576
	else
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   577
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   578
		TInt n = CheckForDecimalVersion(iFileName, s, iModuleVersion);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   579
		if (n>0)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   580
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   581
			iFlags |= EVerPresent;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   582
			remain -= n;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   583
			s -= n;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   584
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   585
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   586
	iBaseLength = remain;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   587
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   588
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   589
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   590
#define PARSE_CAPABILITIES_ERROR(aMessage) Print(EError, "%s\n",aMessage)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   591
#define PARSE_CAPABILITIES_ERROR2(aMessage1,aMessage2) Print(EError, "%s%s\n",aMessage1,aMessage2)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   592
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   593
TInt ParseCapabilitiesArg(SCapabilitySet& aCapabilities, const char *aText)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   594
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   595
// This is a cun'n'paste copy of the function in BASE\WINS\SPECIFIC\PROPERTY.CPP
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   596
// Keep both of these versions up to date with each other
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   597
//
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   598
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   599
	memset(&aCapabilities,0,sizeof(aCapabilities));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   600
	char c;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   601
	while((c=*aText)!=0)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   602
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   603
		if(c<=' ')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   604
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   605
			++aText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   606
			continue;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   607
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   608
		int invert=0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   609
		if(c=='+')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   610
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   611
			++aText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   612
			c=*aText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   613
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   614
		if(c=='-')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   615
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   616
			invert=1;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   617
			++aText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   618
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   619
		const char* name = aText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   620
		while((c=*aText)>' ')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   621
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   622
			if(c=='-' || c=='+')
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   623
				break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   624
			++aText;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   625
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   626
		TUint n = aText-name; 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   627
		TInt i; 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   628
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   629
		if(n==3 && strnicmp("all",name,n)==0)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   630
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   631
			if(invert)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   632
				{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   633
				PARSE_CAPABILITIES_ERROR("Capability '-ALL' not allowed");
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   634
				return KErrArgument;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   635
				}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   636
			for(i=0; i<ECapability_Limit; i++)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   637
				{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   638
				if(CapabilityNames[i])
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   639
					aCapabilities[i>>5] |= (1<<(i&31));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   640
				}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   641
			continue;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   642
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   643
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   644
		if(n==4 && strnicmp("none",name,n)==0)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   645
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   646
			if(invert)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   647
				{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   648
				PARSE_CAPABILITIES_ERROR("Capability '-NONE' not allowed");
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   649
				return KErrArgument;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   650
				}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   651
			memset(&aCapabilities,0,sizeof(aCapabilities));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   652
			continue;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   653
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   654
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   655
		for(i=0; i<ECapability_Limit; i++)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   656
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   657
			const char* cap = CapabilityNames[i];
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   658
			if(!cap)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   659
				continue;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   660
			if((TUint)strlen(cap)!=n) 
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   661
				continue;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   662
			if(strnicmp(cap,name,n)!=0)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   663
				continue;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   664
			break;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   665
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   666
		if(i>=ECapability_Limit)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   667
			{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   668
			char badName[32];
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   669
			if(n>=sizeof(badName)) n=sizeof(badName)-1;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   670
			memcpy(badName,name,n);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   671
			badName[n]=0;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   672
			PARSE_CAPABILITIES_ERROR2("Unrecognised capability name: ",badName);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   673
			return KErrArgument;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   674
			}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   675
		if(invert)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   676
			aCapabilities[i>>5] &= ~(1<<(i&31));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   677
		else
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   678
			aCapabilities[i>>5] |= (1<<(i&31));
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   679
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   680
	return KErrNone;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   681
	}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   682
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   683
TInt ParseBoolArg(TBool& aValue, const char *aText)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   684
	{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   685
	if (_stricmp(aText, "on")==0 || _stricmp(aText, "yes")==0 || _stricmp(aText, "1")==0 || strlen(aText)==0)
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   686
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   687
		aValue = ETrue;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   688
		return KErrNone;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   689
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   690
	if (_stricmp(aText, "off")==0 || _stricmp(aText, "no")==0 || _stricmp(aText, "0")==0 )
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   691
		{
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   692
		aValue = EFalse;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   693
		return KErrNone;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   694
		}
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   695
	Print(EError, "Expected a boolean on/off value but found %s\n",aText);
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   696
	return KErrArgument;
223dcf462b73 Re-adding erroneously forgotten files
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   697
	}