1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
/*
FALCON - The Falcon Programming Language.
FILE: process_mod.cpp
Process module common functions and utilities.
-------------------------------------------------------------------
Author: Giancarlo Niccolai
Begin: sab mar 11 2006
-------------------------------------------------------------------
(C) Copyright 2004: the FALCON developers (see list in AUTHORS file)
See LICENSE file for licensing details.
*/
/** \file
Process module common functions and utilities.
*/
#include <ctype.h>
#include <falcon/memory.h>
#include <falcon/string.h>
#include <string.h>
#include "../sys/process.h"
#include "process.h"
namespace Falcon { namespace Mod {
/*
Mod::Process
*/
Process::Process(CoreClass const* cls) :
CacheObject(cls),
m_process( Sys::Process::factory() )
{ }
Process::~Process()
{
if ( m_process )
delete m_process;
}
Sys::Process* Process::handle()
{
return m_process;
}
/*
Mod::ProcessEnum
*/
ProcessEnum::ProcessEnum(CoreClass const* cls) :
CacheObject(cls),
m_processEnum( new Sys::ProcessEnum )
{ }
ProcessEnum::~ProcessEnum()
{
if ( m_processEnum )
delete m_processEnum;
}
Sys::ProcessEnum* ProcessEnum::handle()
{
return m_processEnum;
}
void argvize(GenericVector& argv, const String ¶ms)
{
typedef enum {
s_none,
s_quote1,
s_quote2,
s_escape1,
s_escape2,
s_token
} t_state;
t_state state = s_none;
// string lenght
uint32 len = params.length();
uint32 pos = 0;
uint32 posInit = 0;
if( len > 0 )
{
while( pos < len )
{
uint32 chr = params.getCharAt( pos );
switch( state )
{
case s_none:
switch( chr )
{
case ' ': case '\t':
break;
case '\"':
state = s_quote1;
posInit = pos;
break;
case '\'':
state = s_quote2;
posInit = pos;
break;
default:
state = s_token;
posInit = pos;
}
break;
case s_token:
switch( chr )
{
case ' ': case '\t':
argv.push(new String( params, posInit, pos ));
state = s_none;
break;
// In case of " change state but don't change start position
case '\"':
argv.push(new String( params, posInit, pos ));
posInit = pos + 1;
state = s_quote1;
break;
case '\'':
argv.push(new String( params, posInit, pos ));
posInit = pos + 1;
state = s_quote2;
break;
}
break;
case s_quote1:
if ( chr == '\\' )
state = s_escape1;
else if ( chr == '\"' )
{
argv.push(new String( params, posInit, pos ));
state = s_none;
}
break;
case s_escape1:
state = s_quote1;
break;
case s_quote2:
if ( chr == '\\' )
state = s_escape2;
else if ( chr == '\'' )
{
argv.push(new String( params, posInit, pos ));
state = s_none;
}
break;
case s_escape2:
state = s_quote2;
break;
}
pos ++;
}
}
// last
if( state != s_none && posInit < pos )
argv.push(new String( params, posInit, pos ));
}
}} // ns Falcon::Mod
/* end of process_mod.cpp */
|