예제 #1
0
static SQLRETURN doWork(char op, char *arg, SQLHENV henv, SQLHDBC hdbc, SQLHSTMT shdl, test_req_t *resp) 
{
	SQLRETURN status = SQL_ERROR;
	int empno = (*arg ? atoi(arg) : 8000);
	char buf1[512];
	char buf2[512];
	int rcnt = 0;   // no of matching records

	sprintf(buf2, "%d", empno);
	(resp->data)[0] = 0;

	if (op == '0') {
		(void) strsub((const char*) ISQL, buf1, sizeof (buf1), "?", buf2);
		status = doSql(henv, hdbc, shdl, (SQLCHAR *) buf1);
	} else if (op == '1') {
		(void) strsub((const char*) SSQL, buf1, sizeof (buf1), "?", buf2);
		status = doSelect(henv, hdbc, shdl, (SQLCHAR *) buf1, &rcnt);
		btlogger_snprintf(resp->data, sizeof (resp->data), "%d", rcnt);
	} else if (op == '2') {
		(void) strsub((const char*) USQL, buf1, sizeof (buf1), "?", buf2);
		status = doSql(henv, hdbc, shdl, (SQLCHAR *) buf1);
	} else if (op == '3') {
		(void) strsub((const char*) DSQL, buf1, sizeof (buf1), "?", buf2);
		status = doSql(henv, hdbc, shdl, (SQLCHAR *) buf1);
	}

	return status;
}
예제 #2
0
/*--------------------------------------------------------------------------*/ 
int appendStringToInternalLastErrorMessage(char *strErrorMessage)
{
    if (iLastErrorMessageNbLines >= MAX_ERROR_MESSAGE_NB_LINES)
    {
        return 1;
    }
    else
    {
        if (strLastErrorMessage)
        {
            if (strErrorMessage == NULL)
            {
                strLastErrorMessage[iLastErrorMessageNbLines] = strdup(NO_ERROR_MESSAGE);
            }
            else
            {
                char *withoutCR = strsub(strErrorMessage, CR, EMPTY_STRING);
                strLastErrorMessage[iLastErrorMessageNbLines] = strsub(withoutCR, LF, EMPTY_STRING);
                if (withoutCR)
                {
                    FREE(withoutCR);
                    withoutCR = NULL;
                }
            }
            iLastErrorMessageNbLines++;
        }
        else
        {
            return 1;
        }
    }
    return 0;
}
예제 #3
0
void parse_config(config* cfg, char* str){
	//remove blank lines
	int n = 0;
	int idx_parser;
	int str_len = strlen(str);
	char cfg_name[CFG_BUFF_LEN]="";
	char cfg_val[CFG_BUFF_LEN]="";

	while(str[n] == ' ' || str[n] == '\t') {//if white space at head
		n++;
	}

	if(str[n] == '\n') {//if empty lines
		return;
	}

	str +=n;
	idx_parser = -1;
	for(n = 0; n<str_len; n++) {
		if(str[n] == FILE_CFG_PARSER) {
			idx_parser = n;
			break;
		}
	}
	if(idx_parser == -1 || idx_parser == str_len || idx_parser == 0) {
		return;
	}
	strsub(str, cfg_name, 0, idx_parser-1);
	strsub(str, cfg_val, idx_parser+1, str_len-1);
	strtrim(cfg_name);
	strtrim(cfg_val);

	//identify the configs
	if(!strcmp(cfg_name, CFG_SERIAL_NAME))
		strcpy(cfg->serial_name, cfg_val);
	if(!strcmp(cfg_name, CFG_SERIAL_TYPE))
		sscanf(cfg_val,"%d",&(cfg->serial_type));
	if(!strcmp(cfg_name, CFG_SERIAL_BAUDRATE))
		strcpy(cfg->serial_baudrate, cfg_val);
	if(!strcmp(cfg_name, CFG_SERVER_IP))
		strcpy(cfg->server_ip, cfg_val);
	if(!strcmp(cfg_name, CFG_SERVER_PORT))
		sscanf(cfg_val,"%d",&(cfg->server_port));
	if(!strcmp(cfg_name, CFG_SERVER_PROC))
		sscanf(cfg_val,"%d",&(cfg->server_proc));
	if(!strcmp(cfg_name, CFG_LOCALHOST_PORT))
		sscanf(cfg_val,"%d",&(cfg->localhost_port));
	if(!strcmp(cfg_name, CFG_LOCALHOST_PROC))
		sscanf(cfg_val,"%d",&(cfg->localhost_proc));
	if(!strcmp(cfg_name, CFG_TIME_ZNET_SYNC))
		sscanf(cfg_val,"%d",&(cfg->time_znet_sync));
}
예제 #4
0
char* parntrim(char* expr)
{
	char* newexpr = expr;
	int len = strlen(newexpr);

	if(*newexpr == '(')
		newexpr = strsub(newexpr,1,len-1);

	len = strlen(newexpr);
	if(*(newexpr+len-1) == ')')
		newexpr = strsub(newexpr,0,len-2);

	return newexpr;
}
예제 #5
0
/* ================================================================================== */
char *normalizeFileSeparator(const char *path)
{
#define WINDOWS_FILESEPARATOR "\\"
#define OTHERS_FILESEPARATOR "/"

    char *normalizedPath = NULL;
    if (path)
    {
#ifdef _MSC_VER
        normalizedPath = strsub((char*)path, OTHERS_FILESEPARATOR, DIR_SEPARATOR);
#else
        normalizedPath = strsub((char*)path, WINDOWS_FILESEPARATOR, DIR_SEPARATOR);
#endif
    }
    return normalizedPath;
}
예제 #6
0
static void	bufread_handl(t_data *data, char *str, int cs)
{
	int		i;
	int		len;
	char	*cmd;

	i = 0;
	while (str[i])
	{
		len = 0;
		while (str[i + len] && str[i + len] != '\n')
			len++;
		if (str[i + len])
		{
			if (len)
			{
				cmd = strsub(str, i, len);
				cmd_handl(data, cmd, cs);
				free(cmd);
			}
			i += len + 1;
			len = 0;
		}
		if (!str[i + len])
		{
			strncpy(str, str + i, BUF_SIZE);
			return ;
		}
	}
}
예제 #7
0
파일: utility.c 프로젝트: Tayyib/uludag
//! Returns locale of a process
char *
get_proc_lang(pid_t pid)
{
    pid_t pids[2];
    pids[0] = pid;
    pids[1] = 0;

    proc_t proc;
    PROCTAB *ptp;
    int i = 0;

    char *lang = NULL;

    ptp = openproc(PROC_FILLENV | PROC_PID, pids);
    while(readproc(ptp, &proc)) {
        while (proc.environ[++i]) {
            if (strncmp(proc.environ[i - 1], "LANG", 4) == 0) {
                lang = strsub(proc.environ[i - 1], 5, 7);
                goto out;
            }
        }
    }

out:
    closeproc(ptp);
    return lang;
}
예제 #8
0
void ComplexParametersCategory(char *llog, statistics stats, FILE **fOut, FILE **fcfg)
{
	int i, j;
	char lkk1[LONGSTRINGSIZE], lkk2[LONGSTRINGSIZE];

		fgets2(lkk, LONGSTRINGSIZE, *fcfg);
		while ((lkk[0] != '#') && (lkk[0] != '\0') && (!feof(*fcfg))) {
			i=strpos2(lkk, ":OPT", 1);
			if (lkk[0]=='*') /*if the line is comment out, simply ignore it*/
				i=0;
			if (i) { /* line with OPT */
				j=1;
				ReadSubKey(lkk1, lkk, &j, '#', '#', 5); /* lkk1=symbol */
				lkk2[0]='\0';
				i=0;
				j=1;
				while ( (strcmp (lkk1, lkk2)) && (j<strlen(llog) ) ) {
					i++;
					ReadSubKey(lkk2, llog, &j, ':', ':', 0);
					StripSpaces(lkk2);
				}
				if (j==strlen(llog)) {
					printf("auxfunc_log.c - ComplexParametersCategory -- Wrong config opened.\n");
					exit(EXIT_FAILURE);
				}
				ReadSubKey(lkk2, llog, &j, ':', ':', 0); /*the measured value for the previously text*/
				i++; /*the correct position of the value*/
				j=1;
				ReadSubKey(lkk1, lkk, &j, ':', ':', 0);
				strsub(lkk1, lkk, 1, j);
				sprintf(lkk2, "%s:%E:%E", lkk2, stats.min[i], stats.max[i]);
				strcat(lkk1, lkk2);
				ReadSubKey(lkk2, lkk, &j, ':', ':', 0);
				ReadSubKey(lkk2, lkk, &j, ':', ':', 0);
				ReadSubKey(lkk2, lkk, &j, ':', ':', 0);
				strsub(lkk2, lkk, j, (int)strlen(lkk));
				strcat(lkk1, lkk2);
				fprintf(*fOut, "%s\n", lkk1);

			} else { /* line with --- */
				fprintf(*fOut, "%s\n", lkk);
			}
			fgets2(lkk, LONGSTRINGSIZE, *fcfg);
		}
}
예제 #9
0
파일: task.c 프로젝트: theNerd247/todoc
//helper function for task_parse()
//converts from form "YYYY-MM-DD" to DDMMYYYY as an int 
int parsedate(char* expr){
	int stamp = 0;
	//because this function should only be called when expr is in correct
	//format we don't need to do any checking

	//pull out the characters in form DDMMYYYY form
	char tmpform[9];
	strsub(expr,8,9,tmpform);
	strsub(expr,5,6,tmpform+2);
	strsub(expr,0,3,tmpform+4);
	tmpform[8] = '\0';

	size_t i;
	//the "-48" is to convert from ascii to int
	for (i = 0; i < 8; i++)
		stamp += (tmpform[7-i]-48)*pow(10,i);

	return stamp;
}
예제 #10
0
파일: csvRead.c 프로젝트: scitao/scilab
// =============================================================================
static char *stripCharacters(const char *line)
{
    char *returnedLine = NULL;
    if (line)
    {
        char *tmpLineWithoutTab = strsub((char*)line, "\t", "");
        if (tmpLineWithoutTab)
        {
            char *tmpLineWithoutLF = strsub(tmpLineWithoutTab, "\r", "");
            if (tmpLineWithoutLF)
            {
                char *tmpLineWithoutCR = strsub(tmpLineWithoutTab, "\n", "");
                if (tmpLineWithoutCR)
                {
                    returnedLine = strsub(tmpLineWithoutCR, " ", "");
                    FREE(tmpLineWithoutCR);
                }
                else
                {
                    returnedLine = os_strdup(line);
                }
                FREE(tmpLineWithoutLF);
                tmpLineWithoutLF = NULL;
            }
            else
            {
                returnedLine = os_strdup(line);
            }
            FREE(tmpLineWithoutTab);
            tmpLineWithoutTab = NULL;
        }
        else
        {
            returnedLine = os_strdup(line);
        }
    }

    return returnedLine;
}
예제 #11
0
static void 
safe_strsub( char *source, char *pattern, char *replacement, char *dest )
{
	char 	*copy;

	allot( char *, copy, strlen( source ) + STRSZ );

	strsub( source, pattern, replacement, copy );
	
	strcpy( dest, copy );

	free( copy );
}
예제 #12
0
파일: csl.c 프로젝트: Tayyib/uludag
//! CSL method: script()
static PyObject *
c_script(PyObject *self, PyObject *args)
{
    /*!
     * This method can be used in CSL scripts to get script's owner.
     *
     * @return Owner of the running CSL script.
     */

    const char *path = dbus_message_get_path(my_proc.bus_msg);
    const char *app = strsub(path, strlen("/package/"), 0);
    return PyString_FromString(app);
}
예제 #13
0
파일: loop.c 프로젝트: Pardus-Linux/COMAR
//! Handles a DBus message and executes related script
void
handle_message(DBusMessage *msg)
{
    Py_Initialize();

    const char *method = dbus_message_get_member(msg);
    const char *iface = dbus_message_get_interface(msg);
    const char *path = dbus_message_get_path(msg);

    log_debug("Forked new process for '%s.%s' - '%s'\n", iface, method, path);

    if (method == NULL || path == NULL || method == NULL) {
        bus_reply_unknown_method(msg);
    }
    else if (strcmp("org.freedesktop.DBus.Introspectable", iface) == 0 && strcmp("Introspect", method) == 0) {
        // Introspection method
        message_execute(msg, NULL, "Core", "introspect");
    }
    else if (strcmp(config_interface, iface) == 0) {
        // Core methods
        message_execute(msg, NULL, "Core", method);
    }
    else if (strncmp(config_interface, iface, strlen(config_interface)) == 0 && iface[strlen(config_interface)] == '.') {
        // Model.method
        char *model = strsub(iface, strlen(config_interface) + 1, strlen(iface));
        char *app = strsub(path, strlen("/package/"), strlen(path));

        message_execute(msg, app, model, method);

        free(model);
        free(app);
    }
    else {
        bus_reply_unknown_method(msg);
    }

    Py_Finalize();
}
예제 #14
0
파일: script.c 프로젝트: Pardus-Linux/COMAR
//! Returns package name, used in scripts
static PyObject *
c_package(PyObject *self, PyObject *args)
{
    const char *path = dbus_message_get_path(my_proc.bus_msg);

    if (strncmp(path, "/package/", strlen("/package/")) == 0) {
        const char *app = strsub(path, strlen("/package/"), strlen(path));
        if (strlen(app) > 0) {
            return PyString_FromString(app);
        }
    }

    Py_INCREF(Py_None);
    return Py_None;
}
예제 #15
0
파일: script.c 프로젝트: Pardus-Linux/COMAR
//! Returns model name, used in scripts
static PyObject *
c_model(PyObject *self, PyObject *args)
{
    const char *iface = dbus_message_get_interface(my_proc.bus_msg);

    if (strncmp(iface, config_interface, strlen(config_interface)) == 0) {
        const char *model = strsub(iface, strlen(config_interface) + 1, strlen(iface));
        if (strlen(model) > 0) {
            return PyString_FromString(model);
        }
    }

    Py_INCREF(Py_None);
    return Py_None;
}
예제 #16
0
파일: initialize.c 프로젝트: alone888/wwmxd
/*
 * receives a string from the extract/ directory with #SYMBOL# and/or #NODE# text
 * requiring a measurement extraction and replaces it with the appropriate value
 */
void DecodeSymbolNode(char *ret, int i)
{
	int ii;
	char laux[LONGSTRINGSIZE];

	ii=1;
	ReadSubKey(laux, ret, &ii, '#', '#', 0);
	while (ii<=(int)strlen(ret)) {
		Str2Lower(laux);
		if (!strcmp(laux, "symbol"))
			ii=ii+1000;                 /*it is a "symbol" and encode this information by adding '1000'*/
		else {
			if (strcmp(laux, "node")) { /*if it is not "node" then exit*/
				printf("initialize.c - DecodeSymbolNode -- Unrecognized option: %s\n", laux);
				exit(EXIT_FAILURE);
			}
		}

		if (ii>1000)
			strsub(laux, ret, ii-1000+1, (int)strlen(ret)-(ii-1000)); /*copies the last part of the string to laux*/
		else
			strsub(laux, ret, ii+1, (int)strlen(ret)-ii);             /*copies the last part of the string to laux*/
		ret[strpos2(ret, "#", 1)-1]='\0';                                 /*properly finishes string                  */
		if (ii>1000) {
			ii=ii-1000;
			strcat(ret, UNIQUECHAR);                  /* unique sequence added to the symbol*/
			strcat(ret, measurements[i].meas_symbol); /* adds the symbol or... */
			/* strcat(ret, " "); not necessary anymore (*) */
		} else
			strcat(ret, measurements[i].node);        /* ...adds the node       */

		strcat(ret, laux);
		ii=1;
		ReadSubKey(laux, ret, &ii, '#', '#', 0);
	}
}
예제 #17
0
파일: initialize.c 프로젝트: alone888/wwmxd
/*
 * receives a SPICE string from the <inputfile>.* with #<text># and replaces
 * it with the correct parameters. Depending on the optimize variable value:
 *      optimize=0 : we are initializing, just replace fixed variables
 *      optimize=1 : "   "  optimizing, replace remaining optimizing variables
 */
void ReplaceSymbol(char *ret, int optimize)
{
	int i, k, ii;
	char laux[LONGSTRINGSIZE], inlinecomment[LONGSTRINGSIZE] /*, lxp[LONGSTRINGSIZE]*/;

	k=inlinestrpos(ret);
	inlinecomment[0]='\0';
	if (k) {
		strsub(inlinecomment, ret, k, (int)strlen(ret)); /*copies the in-line comment*/
		ret[k-1]='\0';
	}

	ii=1;
	ReadSubKey(laux, ret, &ii, '#', '#', 5);
	while (ii<=(int)strlen(ret)) {
		/*Str2Lower(laux);*/
		i=0;
		while (strcmp(parameters[i].symbol, laux)) {
			if (parameters[i].symbol[0] == '\0') { /*if symbol is not found*/
				printf("initialize.c - ReplaceSymbol -- Symbol in <inputfile>.* not found in <inputfile>.cfg: %s\n", laux);
				exit(EXIT_FAILURE);
			}
			i++;
		}

//		strsub(laux, ret, ii+1, (int)strlen(ret)-ii);    /*copies the last part of the string to laux*/
//		/*ret[strpos2(ret, "#", 1)-1]='\0';*/             /*properly finishes the string*/
//		ret[ii-(int)strlen(parameters[i].symbol)-2]='\0'; /*properly finishes the string*/

		if (optimize==0) { /*optimize=0 : we are initializing*/
			if (parameters[i].optimize==0)
				sprintf(laux, "%E", parameters[i].value);   /*writes the value*/
			else
				sprintf(laux, "#%s#",parameters[i].symbol); /*writes the #<symbol>#  back again*/
		} else {           /*optimize=1 : we are optimizing*/
			sprintf(laux, "%E", parameters[i].value);           /*writes the value*/
		}

InsertString(ret, laux, (ii-(int)strlen(parameters[i].symbol)-1), ii+1);

//		strcat(ret, lxp);
//		strcat(ret, laux);
		ii++; /*because 'ReadSubKey' starts at [ii-1] instead of [ii]*/
		ReadSubKey(laux, ret, &ii, '#', '#', 0);
	}

	strcat(ret, inlinecomment); /*concatenates the in-line comment*/
}
예제 #18
0
/*--------------------------------------------------------------------------*/
int C2F(msgstore)(char *str, int *n)
{
    int iRes = 0;

    char **multilines = NULL;
    int nbLines = 0;
    int i = 0;
    char *msg = NULL;
    char *msgTmp = NULL;

    if (str == NULL) return 1;
    msg = strdup(str);
    if (msg)
    {
        msg[*n] = 0;
    }

    // remove duplicate percent bug 9571
    msgTmp = strsub(msg, "%%", "%");
    if (msgTmp)
    {
        FREE(msg);
        msg = msgTmp;
    }
    multilines = splitErrorMessage(msg, &nbLines);
    if (multilines)
    {
        for (i = 0; i < nbLines; i++)
        {
            iRes = appendStringToInternalLastErrorMessage(multilines[i]);
            if (iRes) break;
        }
        freeArrayOfString(multilines, nbLines);
        multilines = NULL;
    }
    else
    {
        iRes = appendStringToInternalLastErrorMessage(msg);
    }

    if (msg)
    {
        FREE(msg);
        msg = NULL;
    }

    return iRes;
}
/*--------------------------------------------------------------------------*/
static BOOL AddScilabBinDirectoryToPATHEnvironnementVariable(char *DefaultPath)
{
#define SCILAB_BIN_PATH "%s/bin"
#define NEW_PATH "PATH=%s;%s"

    BOOL bOK = FALSE;
    char *PATH = NULL;
    char *env = NULL;
    char scilabBinPath[MAX_PATH];
    char *scilabBinPathConverted;

    PATH = getenv("PATH");

    env = (char*) MALLOC(sizeof(char) * (strlen(NEW_PATH) + strlen(PATH) +
                                         strlen(DefaultPath) + 1));
    if (env)
    {
        sprintf(scilabBinPath, SCILAB_BIN_PATH, DefaultPath);

        scilabBinPathConverted = (char*) MALLOC(MAX_PATH * sizeof(char));
#ifdef _MSC_VER
        scilabBinPathConverted = strsub(scilabBinPath, "/", "\\");
#else
        scilabBinPathConverted = strdup(scilabBinPath);
#endif
        if (stristr(PATH, scilabBinPathConverted) == 0)
        {
            sprintf(env, NEW_PATH, scilabBinPathConverted, PATH);
            if (_putenv (env))
            {
                bOK = FALSE;
            }
            else
            {
                bOK = TRUE;
            }
            FREE(env);
            env = NULL;
        }

        FREE(scilabBinPathConverted);
    }
    return bOK;
}
예제 #20
0
파일: qalib.c 프로젝트: juddy/edcde
/* Used to grab string that will be place in global var: __Command_Line.
   This is associated with option: -C. 
*/
Local void
GET_COMMAND_LINE(short *I, Char *Current_, struct LOC_GET_PARAMS *LINK)
{
    Char Current[256];
    Char STR1[256];
    short FORLIM;

    strcpy(Current, Current_);
    strcpy(Current, strsub(STR1, Current, strpos2(Current, "\"", 1) + 1,
                           (int) strlen(Current)));
    sprintf(STR1, "%.*s", strpos2(Current, "\"", 1) - 1, Current);
    strcpy(Current, STR1);
    if (Current[0] == ' ')
        (*I)++;
    FORLIM = (int) strlen(Current);
    for (LINK->LINK->J = 2; LINK->LINK->J <= FORLIM; LINK->LINK->J++) {
        if (Current[LINK->LINK->J - 1] == ' ' && Current[LINK->LINK->J - 2] != ' ')
            (*I)++;
    }
    strcpy(__Command_Line, Current);
}
예제 #21
0
파일: utl_test.c 프로젝트: ttxie/comm
int main()
{
        uint32_t ip;
        char ipc[25];
        char *line = (char*)calloc(1,64), *p=NULL;
//        char line[64];
        FILE *fl = fopen("tt.ini", "r");

assert(p);
        ip = inet_addr("210.211.212.213");
        printf("now:%u\n", (unsigned)time(NULL));
        printf("ip:%s,ts:%lld\n", sk_ntoa(ip), tm64());
        
	strcpy(ipc, "127.0.0.1:1024 ");
	p = strsub(ipc, 10, 4);
	hexdump(p, 16);
	printf("ip:%s, strlen(p):%d\n", p, (int)(strlen(p)));
	free(p);



        fgets(line, 96, fl);

        //strcliney(line, " \n\tabcd \n\n\r");
        //hexdump((u_char*)line, 16);

        printf("line:%s\n", trim(line));
        printf("line:%p\n", line);
        //strcliney(line, trim(line));
        //hexdump((u_char*)line, 16);

        strupper(line);
        printf("len:%u,trim(line):%s\n",(unsigned)strlen(line), line);
        strlower(line);
        printf("len:%u,trim(line):%s\n",(unsigned)strlen(line), line);
        
        free(line);
        return 0;

}
예제 #22
0
/***********************************************************
display the chatbox on screen
***********************************************************/
void LetterViewerBox::Show(long LetterId, const std::string & date, const std::string & from, 
							const std::string & subject, const std::string & message)
{
	_LetterId = LetterId;

	try
	{
		CEGUI::String str = "";
		if(date != "")
		{
			try
			{
				boost::posix_time::ptime pt = boost::posix_time::time_from_string(date);
				typedef boost::date_time::c_local_adjustor<boost::posix_time::ptime> local_adj;
				boost::posix_time::ptime converted = local_adj::utc_to_local(pt);
				str += CEGUI::String((const unsigned char *)boost::posix_time::to_simple_string(converted).c_str());
				str += " - ";
			}
			catch(...){}
		}
		str += "Letter from ";
		str += CEGUI::String((const unsigned char *)from.c_str());
		CEGUI::WindowManager::getSingleton().getWindow("LetterViewerWIndowFrame")->setText(str);

		CEGUI::String strsub((const unsigned char *)subject.c_str());
		CEGUI::WindowManager::getSingleton().getWindow("LetterViewerSubjectEdit")->setText(strsub);

		CEGUI::String strmess((const unsigned char *)message.c_str());
		CEGUI::WindowManager::getSingleton().getWindow("LetterViewerMessage")->setText(strmess);


		if(!_myBox->isVisible())
			_myBox->show();
	}
	catch(CEGUI::Exception &ex)
	{
		LogHandler::getInstance()->LogToFile(std::string("Exception LetterViewerBox Show: ") + ex.getMessage().c_str());
	}
}
예제 #23
0
char* expndcoef(char* expr)
{
	if (expr == NULL || *expr == '\0')
		return expr;

	//find indep var	
	char* tok1;
	char* indeppos = (char*)memchr(expr, indep_var, strlen(expr));

	if(indeppos == NULL)
		return expr;

	//check for coef where indep var is found and then add the rest. 
	tok1 = strsub(expr,0,indeppos-expr);
	if(strpbrk(tok1+strlen(tok1)-2,"0123456789") != NULL)
		tok1 = strins(tok1, "*", indeppos-expr);

	char* tok2 = expndcoef(indeppos+1);
	strcat(tok1,tok2);

	return tok1;
}
예제 #24
0
static char *
generate_sqltable_create( Dbptr db, long flags )
{
	char	*table;
	char	part[STRSZ];
	void	*stk = 0;
	Tbl	*primary;
	Tbl	*fields;
	long	ifield;
	char	*field;
	char	field_a[STRSZ];
	char	field_b[STRSZ];
	char	*fnull;
	long	fsize;
	long	ftype;
	char	*fformat;
	int	precision;
	int	scale;
	long	longest = 0;

	if( db.table < 0 ) {

		return NULL;
	}

	dbquery( db, dbTABLE_NAME, &table );

	pushstr( &stk, "CREATE TABLE `" );
	pushstr( &stk, table );
	pushstr( &stk, "`\n  (\n" );

	dbquery( db, dbTABLE_FIELDS, &fields );

	applytbl( fields, find_longest, (void *) &longest );

	if( ! ( flags & DB2SQL_OMIT_SYNC ) && longest < strlen( Db2sql_syncfield_name ) ) {

		longest = strlen( Db2sql_syncfield_name );
	}

	for( ifield = 0; ifield < maxtbl( fields ); ifield++ ) {

		if( ifield > 0 ) {

			pushstr( &stk, ",\n" );
		}

		field = gettbl( fields, ifield );

		db = dblookup( db, "", table, field, "" );

		pushstr( &stk, "  `" );
		pushstr( &stk, field );
		pushstr( &stk, "`" );
		pushstr( &stk, spaces( longest - strlen(field) + 2 ) );

		dbquery( db, dbFIELD_SIZE, &fsize );
		dbquery( db, dbFIELD_TYPE, &ftype );
		dbquery( db, dbFIELD_FORMAT, &fformat );
		dbquery( db, dbNULL, &fnull );

		memset( part, '\0', STRSZ );

		switch( ftype ) {

		case dbSTRING:
			if( fsize < 256 ) {
				sprintf( part, "CHAR(%ld)", fsize );
			} else {
				sprintf( part, "TEXT(%ld)", fsize );
			}
			pushstr( &stk, part );
			break;

		case dbREAL:
		case dbTIME:
			if( fnull != (char *) NULL && strcontains( fnull, "[eE]", 0, 0, 0 ) ) {
				sprintf( part, "DOUBLE" );
			} else {
				sscanf( fformat, "%%%d.%d", &precision, &scale );
				sprintf( part, "DECIMAL(%d,%d)", precision, scale );
			}
			pushstr( &stk, part );
			break;

		case dbINTEGER:
		case dbYEARDAY:
			sprintf( part, "INTEGER(%ld)", fsize );
			pushstr( &stk, part );
			break;

		case dbDBPTR:
			pushstr( &stk, "CHAR(32)" );
			break;
		}

		/* Disallow defaults for SQL TEXT fields */

		if( fnull != (char *) NULL && strncmp( part, "TEXT", 4 ) ) {

			pushstr( &stk, " DEFAULT " );

			if( ftype == dbSTRING ) {
		
				pushstr( &stk, "'" );
				pushstr( &stk, fnull );
				pushstr( &stk, "'" );

			} else {

				pushstr( &stk, fnull );
			}
		}
	}

	if( ! ( flags & DB2SQL_OMIT_SYNC ) ) {

		pushstr( &stk, ",\n" );

		pushstr( &stk, "  `" );
		pushstr( &stk, Db2sql_syncfield_name );
		pushstr( &stk, "`" );
		pushstr( &stk, spaces( longest - strlen(Db2sql_syncfield_name) + 2 ) );

		pushstr( &stk, DB2SQL_SYNCFIELD_SPEC );
	}

	dbquery( db, dbPRIMARY_KEY, &primary );

	if( maxtbl( primary ) > 0 ) {

		pushstr( &stk, ",\n  PRIMARY KEY (" );

		for( ifield = 0; ifield < maxtbl( primary ); ifield++ ) {

			if( ifield > 0 ) {

				pushstr( &stk, ", " );
			}
	
			field = gettbl( primary, ifield );

			if( strcontains( field, "::", 0, 0, 0 ) ) {

				strsub( field, "::", "  ", field );

				sscanf( field, "%s %s", field_a, field_b );

				pushstr( &stk, "`" );
				pushstr( &stk, field_a );
				pushstr( &stk, "`" );

				/* end-of-range keys can be NULL in Datascope,
				   so don't use it as primary in SQL: 

				pushstr( &stk, ", `" );
				pushstr( &stk, field_b );
				pushstr( &stk, "`" );
				*/

			} else {

				pushstr( &stk, "`" );
				pushstr( &stk, field );
				pushstr( &stk, "`" );
			}
		}

		pushstr( &stk, ")" );
	}

	pushstr( &stk, "\n  );\n" );

	return popstr( &stk, 1 );
}
예제 #25
0
/*--------------------------------------------------------------------------*/
JavaVMOption * getJvmOptions(char *SCI_PATH, char *filename_xml_conf, int *size_JavaVMOption)
{
    if ( FileExist(filename_xml_conf) )
    {
        JavaVMOption *jvm_options = NULL;
        char *encoding = GetXmlFileEncoding(filename_xml_conf);

        /* Don't care about line return / empty line */
        xmlKeepBlanksDefault(0);
        /* check if the XML file has been encoded with utf8 (unicode) or not */
        if (stricmp("utf-8", encoding) == 0)
        {
            xmlDocPtr doc = NULL;
            xmlXPathContextPtr xpathCtxt = NULL;
            xmlXPathObjectPtr xpathObj = NULL;
            char *jvm_option_string = NULL;
            char *xpath_query = NULL;

            int indice = 0;
            {
                BOOL bConvert = FALSE;
                char *shortfilename_xml_conf = getshortpathname(filename_xml_conf, &bConvert);
                if (shortfilename_xml_conf)
                {
                    doc = xmlParseFile (shortfilename_xml_conf);
                    FREE(shortfilename_xml_conf);
                    shortfilename_xml_conf = NULL;
                }
            }

            if (doc == NULL)
            {
                fprintf(stderr, _("Error: Could not parse file %s.\n"), filename_xml_conf);
                FREE(encoding);
                encoding = NULL;
                *size_JavaVMOption = 0;
                return NULL;
            }

            xpathCtxt = xmlXPathNewContext(doc);
            /* Retrieve all nodes without the os tag + only the one from our operating system */
#define XPATH_QUERY "//jvm_options/option[not(@os)] | //jvm_options/option[@os='%s']"

            xpath_query = (char *)MALLOC(sizeof(char) * ((int)strlen(XPATH_QUERY) + (int)strlen(OSNAME) + 1));
            sprintf(xpath_query, XPATH_QUERY, OSNAME);

            xpathObj = xmlXPathEval((const xmlChar*)xpath_query, xpathCtxt);
            FREE(xpath_query);
            if (xpathObj && xpathObj->nodesetval->nodeMax)
            {
                /* the Xpath has been understood and there are node */
                int i;
                char *heapSize = getJavaHeapSize();

                for (i = 0; i < xpathObj->nodesetval->nodeNr; i++)
                {

                    xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[i]->properties;
                    /* Get the properties of <option>  */
                    while (attrib != NULL)
                    {
                        /* loop until when have read all the attributes */
                        if (xmlStrEqual (attrib->name, (const xmlChar*) "value"))
                        {
                            /* we found the tag name */
                            const char *str = (const char*)attrib->children->content;
                            if (strstr(str, "-Xmx") == str && heapSize)
                            {
                                jvm_option_string = os_strdup(heapSize);
                            }
                            else
                            {
                                jvm_option_string = os_strdup(str);
                            }
                        }
                        attrib = attrib->next;
                    }

                    if ( (jvm_option_string) && (strlen(jvm_option_string) > 0) )
                    {
                        char *option_string_path_separator = NULL;
                        char *option_string_sci_path = NULL;

                        option_string_path_separator = strsub(jvm_option_string, "$PATH_SEPARATOR", PATH_SEPARATOR);
                        option_string_sci_path = strsub(option_string_path_separator, "$SCILAB", SCI_PATH);
                        if (option_string_path_separator)
                        {
                            FREE(option_string_path_separator);
                        }

                        jvm_options = (JavaVMOption *)REALLOC(jvm_options, sizeof(JavaVMOption) * (indice + 1));
                        jvm_options[indice].optionString = option_string_sci_path;
                        indice++;
                    }
                    if (jvm_option_string)
                    {
                        FREE(jvm_option_string);
                        jvm_option_string = NULL;
                    }
                }

                FREE(heapSize);
            }

            if (xpathObj)
            {
                xmlXPathFreeObject(xpathObj);
            }
            if (xpathCtxt)
            {
                xmlXPathFreeContext(xpathCtxt);
            }
            xmlFreeDoc (doc);

            /* xmlCleanupParser is called in
             * modules/core/src/c/TerminateCore.c
             * since it needs to be done only once.
             */

            if (getenv("SCI_JAVA_ENABLE_HEADLESS") != NULL)
            {
                /* When Scilab is built from a virtual machine, it needs
                 * an X11 server / input
                 * This is only called by "make doc" by the SCI/Makefile.am
                 */
#define HEADLESS "-Djava.awt.headless=true"
                jvm_options = (JavaVMOption *)REALLOC(jvm_options, sizeof(JavaVMOption) * (indice + 1));
                jvm_options[indice].optionString = MALLOC((strlen(HEADLESS) + 1) * sizeof(char));
                strcpy(jvm_options[indice].optionString, HEADLESS);
                indice++;
#undef HEADLESS
            }

            FREE(encoding);
            encoding = NULL;

            *size_JavaVMOption = indice;
            return jvm_options;
        }
        else
        {
            fprintf(stderr, _("Error: Not a valid configuration file %s (encoding not '%s') Encoding '%s' found.\n"), filename_xml_conf, "utf-8", encoding);
        }
        FREE(encoding);
        encoding = NULL;
    }
    return NULL;
}
예제 #26
0
pcre_error_code pcre_private(char *INPUT_LINE, char *INPUT_PAT, int *Output_Start, int *Output_End, char*** _pstCapturedString, int* _piCapturedStringCount)
{
    /* ALL strings are managed as UTF-8 by default */
    int options = PCRE_UTF8;
    int size_offsets = 45;
    int size_offsets_max;
    int *offsets = NULL;
    int all_use_dfa = 0;
    BOOL LOOP_PCRE_TST = FALSE;

    /* These vectors store, end-to-end, a list of captured substring names. Assume
    that 1024 is plenty long enough for the few names we'll be testing. */

    char copynames[1024];
    char getnames[1024];

    char *copynamesptr = NULL;
    char *getnamesptr = NULL;

    int rc = 0;
    (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
    if (rc != 1)
    {
        return UTF8_NOT_SUPPORTED;
    }

    /* bug 3891 */
    /* backslash characters are not interpreted for input */
    buffer = strsub(INPUT_LINE, "\\", "\\\\");

    size_offsets_max = size_offsets;
    offsets = (int *)MALLOC(size_offsets_max * sizeof(int));
    if (offsets == NULL)
    {
        if (buffer)
        {
            FREE(buffer);
            buffer = NULL;
        }
        return NOT_ENOUGH_MEMORY_FOR_VECTOR;
    }
    /* Main loop */
    LOOP_PCRE_TST = FALSE;
    while (!LOOP_PCRE_TST)
    {
        pcre *re = NULL;
        pcre_extra *extra = NULL;
        const char *error = NULL;
        char *back_p = NULL;
        char *p = NULL;
        char *pp = NULL;
        char *ppp = NULL;
        const unsigned char *tables = NULL;
        int do_G = 0;
        int do_g = 0;
        int erroroffset = 0, len = 0, delimiter;

        LOOP_PCRE_TST = TRUE;
        p = strdup(INPUT_PAT);
        back_p = p;
        while (isspace(*p))
        {
            p++;
        }
        if (*p == 0)
        {
            continue;
        }
        /* In-line pattern (the usual case). Get the delimiter and seek the end of
        the pattern; if is isn't complete, read more. */

        delimiter = *p++;

        if (isalnum(delimiter) || delimiter == '\\')
        {
            if (buffer)
            {
                FREE(buffer);
                buffer = NULL;
            }
            if (offsets)
            {
                FREE(offsets);
                offsets = NULL;
            }
            if (back_p)
            {
                FREE(back_p);
                back_p = NULL;
            }
            return DELIMITER_NOT_ALPHANUMERIC;
        }

        pp = p;

        while (*pp != 0)
        {
            if (*pp == '\\' && pp[1] != 0)
            {
                pp++;
            }
            else if (*pp == delimiter)
            {
                break;
            }
            pp++;
        }

        /* If the delimiter can't be found, it's a syntax error */
        if (*pp == 0)
        {
            if (buffer)
            {
                FREE(buffer);
                buffer = NULL;
            }
            if (offsets)
            {
                FREE(offsets);
                offsets = NULL;
            }
            if (back_p)
            {
                FREE(back_p);
                back_p = NULL;
            }
            if (offsets)
            {
                FREE(offsets);
            }
            return CAN_NOT_COMPILE_PATTERN;
        }

        /* If the first character after the delimiter is backslash, make
        the pattern end with backslash. This is purely to provide a way
        of testing for the error message when a pattern ends with backslash. */

        if (pp[1] == '\\')
        {
            *pp++ = '\\';
        }

        /* Terminate the pattern at the delimiter, and save a copy of the pattern
        for callouts. */

        *pp++ = 0;

        /* Look for options after final delimiter */

        //options = 8192;

        while (*pp != 0)
        {
            switch (*pp++)
            {
                case 'f':
                    options |= PCRE_FIRSTLINE;
                    break;
                case 'g':
                    do_g = 1;
                    break;
                case 'i':
                    options |= PCRE_CASELESS;
                    break;
                case 'm':
                    options |= PCRE_MULTILINE;
                    break;
                case 's':
                    options |= PCRE_DOTALL;
                    break;
                case 'x':
                    options |= PCRE_EXTENDED;
                    break;
                case '+':
                    break;
                case 'A':
                    options |= PCRE_ANCHORED;
                    break;
                case 'B':
                    break;
                case 'C':
                    options |= PCRE_AUTO_CALLOUT;
                    break;
                case 'D':
                    break;
                case 'E':
                    options |= PCRE_DOLLAR_ENDONLY;
                    break;
                case 'F':
                    break;
                case 'G':
                    do_G = 1;
                    break;
                case 'I':
                    break;
                case 'J':
                    options |= PCRE_DUPNAMES;
                    break;
                case 'M':
                    break;
                case 'N':
                    options |= PCRE_NO_AUTO_CAPTURE;
                    break;
                case 'S':
                    break;
                case 'U':
                    options |= PCRE_UNGREEDY;
                    break;
                case 'X':
                    options |= PCRE_EXTRA;
                    break;
                case 'Z':
                    break;
                case '8':
                {
                    int rc = 0;
                    (void)pcre_config(PCRE_CONFIG_UTF8, &rc);
                    if (rc != 1)
                    {
                        if (buffer)
                        {
                            FREE(buffer);
                            buffer = NULL;
                        }
                        if (offsets)
                        {
                            FREE(offsets);
                        }
                        return UTF8_NOT_SUPPORTED;
                    }
                    options |= PCRE_UTF8;
                }
                break;
                case '?':
                    options |= PCRE_NO_UTF8_CHECK;
                    break;
                case 'L':
                    ppp = pp;
                    /* The '\r' test here is so that it works on Windows. */
                    /* The '0' test is just in case this is an unterminated line. */
                    while (*ppp != 0 && *ppp != '\n' && *ppp != '\r' && *ppp != ' ')
                    {
                        ppp++;
                    }
                    *ppp = 0;
                    if (setlocale(LC_CTYPE, (const char *)pp) == NULL)
                    {
                        goto SKIP_DATA;
                    }

                    tables = pcre_maketables();
                    pp = ppp;
                    break;
                case '>':
                    while (*pp != 0)
                    {
                        pp++;
                    }
                    while (isspace(pp[-1]))
                    {
                        pp--;
                    }
                    *pp = 0;
                    break;
                case '<':
                {
                    while (*pp++ != '>')
                    {
                        ;
                    }
                }
                break;
                case '\r':                      /* So that it works in Windows */
                case '\n':
                case ' ':
                    break;

                default:
                    goto SKIP_DATA;
            }
        }

        /* Handle compiling via the POSIX interface, which doesn't support the
        timing, showing, or debugging options, nor the ability to pass over
        local character tables. */


        {
            re = pcre_compile((char *)p, options, &error, &erroroffset, tables);
            /* Compilation failed; go back for another re, skipping to blank line
            if non-interactive. */
            if (re == NULL)
            {
SKIP_DATA:
                if (buffer)
                {
                    FREE(buffer);
                    buffer = NULL;
                }
                if (offsets)
                {
                    FREE(offsets);
                    offsets = NULL;
                }
                if (tables)
                {
                    (*pcre_free)((void*)tables);
                    tables = NULL;
                }
                if (extra)
                {
                    FREE(extra);
                    extra = NULL;
                }
                if (back_p)
                {
                    FREE(back_p);
                    back_p = NULL;
                }
                return CAN_NOT_COMPILE_PATTERN;
            }

        }        /* End of non-POSIX compile */

        /* Read data lines and test them */
        {
            char *q = NULL;
            char *bptr = NULL;
            int *use_offsets = offsets;
            int use_size_offsets = size_offsets;
            int callout_data = 0;
            int callout_data_set = 0;
            int count = 0;
            int c = 0;
            int copystrings = 0;
            int find_match_limit = 0;
            int getstrings = 0;
            int gmatched = 0;
            int start_offset = 0;
            int g_notempty = 0;
            int use_dfa = 0;

            options = 0;
            *copynames = 0;
            *getnames = 0;

            copynamesptr = copynames;
            getnamesptr = getnames;

            callout_count = 0;
            callout_fail_count = 999999;
            callout_fail_id = -1;

            if (extra != NULL)
            {
                extra->flags &= ~(PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION);
            }
            p = buffer;
            bptr = q = buffer;
            while ((c = *p++) != 0)
            {
                int i = 0;
                int n = 0;

                if (c == '\\') switch ((c = *p++))
                    {
                        case 'a':
                            c =    7;
                            break;
                        case 'b':
                            c = '\b';
                            break;
                        case 'e':
                            c =   27;
                            break;
                        case 'f':
                            c = '\f';
                            break;
                        case 'n':
                            c = '\n';
                            break;
                        case 'r':
                            c = '\r';
                            break;
                        case 't':
                            c = '\t';
                            break;
                        case 'v':
                            c = '\v';
                            break;
                        case '0':
                        case '1':
                        case '2':
                        case '3':
                        case '4':
                        case '5':
                        case '6':
                        case '7':
                            c -= '0';
                            while (i++ < 2 && isdigit(*p) && *p != '8' && *p != '9')
                            {
                                c = c * 8 + *p++ - '0';
                            }
                            break;
                        case 'x':
                            /* Ordinary \x */
                            c = 0;
                            while (i++ < 2 && isxdigit(*p))
                            {
                                c = c * 16 + tolower(*p) - ((isdigit(*p)) ? '0' : 'W');
                                p++;
                            }
                            break;
                        case 0:   /* \ followed by EOF allows for an empty line */
                            p--;
                            continue;
                        case '>':
                            while (isdigit(*p))
                            {
                                start_offset = start_offset * 10 + *p++ - '0';
                            }
                            continue;
                        case 'A':  /* Option setting */
                            options |= PCRE_ANCHORED;
                            continue;
                        case 'B':
                            options |= PCRE_NOTBOL;
                            continue;
                        case 'C':
                            if (isdigit(*p))    /* Set copy string */
                            {
                                while (isdigit(*p))
                                {
                                    n = n * 10 + *p++ - '0';
                                }
                                copystrings |= 1 << n;
                            }
                            else if (isalnum(*p))
                            {
                                char *npp = copynamesptr;
                                while (isalnum(*p))
                                {
                                    *npp++ = *p++;
                                }
                                *npp++ = 0;
                                *npp = 0;
                                pcre_get_stringnumber(re, (char *)copynamesptr);
                                copynamesptr = npp;
                            }
                            else if (*p == '+')
                            {
                                p++;
                            }
                            else if (*p == '-')
                            {
                                p++;
                            }
                            else if (*p == '!')
                            {
                                callout_fail_id = 0;
                                p++;
                                while (isdigit(*p))
                                {
                                    callout_fail_id = callout_fail_id * 10 + *p++ - '0';
                                }
                                callout_fail_count = 0;
                                if (*p == '!')
                                {
                                    p++;
                                    while (isdigit(*p))
                                    {
                                        callout_fail_count = callout_fail_count * 10 + *p++ - '0';
                                    }
                                }
                            }
                            else if (*p == '*')
                            {
                                int sign = 1;
                                callout_data = 0;
                                if (*(++p) == '-')
                                {
                                    sign = -1;
                                    p++;
                                }
                                while (isdigit(*p))
                                {
                                    callout_data = callout_data * 10 + *p++ - '0';
                                }
                                callout_data *= sign;
                                callout_data_set = 1;
                            }
                            continue;
                        case 'G':
                            if (isdigit(*p))
                            {
                                while (isdigit(*p))
                                {
                                    n = n * 10 + *p++ - '0';
                                }
                                getstrings |= 1 << n;
                            }
                            else if (isalnum(*p))
                            {
                                char *npp = getnamesptr;
                                while (isalnum(*p))
                                {
                                    *npp++ = *p++;
                                }
                                *npp++ = 0;
                                *npp = 0;
                                pcre_get_stringnumber(re, (char *)getnamesptr);
                                getnamesptr = npp;
                            }
                            continue;
                        case 'L':
                            continue;
                        case 'M':
                            find_match_limit = 1;
                            continue;
                        case 'N':
                            options |= PCRE_NOTEMPTY;
                            continue;
                        case 'O':
                            while (isdigit(*p))
                            {
                                n = n * 10 + *p++ - '0';
                            }
                            if (n > size_offsets_max)
                            {
                                size_offsets_max = n;
                                if (offsets)
                                {
                                    FREE(offsets);
                                }
                                use_offsets = offsets = (int *)MALLOC(size_offsets_max * sizeof(int));
                            }
                            use_size_offsets = n;
                            if (n == 0)
                            {
                                use_offsets = NULL;    /* Ensures it can't write to it */
                            }
                            continue;
                        case 'P':
                            options |= PCRE_PARTIAL;
                            continue;
                        case 'Q':
                            while (isdigit(*p))
                            {
                                n = n * 10 + *p++ - '0';
                            }
                            if (extra == NULL)
                            {
                                extra = (pcre_extra *)MALLOC(sizeof(pcre_extra));
                                extra->flags = 0;
                            }
                            extra->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
                            extra->match_limit_recursion = n;
                            continue;
                        case 'q':
                            while (isdigit(*p))
                            {
                                n = n * 10 + *p++ - '0';
                            }
                            if (extra == NULL)
                            {
                                extra = (pcre_extra *)MALLOC(sizeof(pcre_extra));
                                extra->flags = 0;
                            }
                            extra->flags |= PCRE_EXTRA_MATCH_LIMIT;
                            extra->match_limit = n;
                            continue;
#if !defined NODFA
                        case 'R':
                            options |= PCRE_DFA_RESTART;
                            continue;
#endif
                        case 'S':

                            continue;
                        case 'Z':
                            options |= PCRE_NOTEOL;
                            continue;
                        case '?':
                            options |= PCRE_NO_UTF8_CHECK;
                            continue;
                        case '<':
                        {
                            while (*p++ != '>')
                            {
                                ;
                            }
                        }
                        continue;
                    }
                *q++ = (char)c;
            }
            *q = 0;
            len = (int)(q - buffer);
            if ((all_use_dfa || use_dfa) && find_match_limit)
            {
                if (buffer)
                {
                    FREE(buffer);
                    buffer = NULL;
                }
                if (offsets)
                {
                    FREE(offsets);
                    offsets = NULL;
                }
                if (p)
                {
                    FREE(p);
                    p = NULL;
                }
                if (re)
                {
                    (*pcre_free)(re);
                    re = NULL;
                }
                if (tables)
                {
                    (*pcre_free)((void*)tables);
                    tables = NULL;
                }
                if (extra)
                {
                    FREE(extra);
                    extra = NULL;
                }
                return LIMIT_NOT_RELEVANT_FOR_DFA_MATCHING;
            }
            /* Handle matching via the POSIX interface, which does not
            support timing or playing with the match limit or callout data. */
            for (;; gmatched++)    /* Loop for /g or /G */
            {

                /* If find_match_limit is set, we want to do repeated matches with
                varying limits in order to find the minimum value for the match limit and
                for the recursion limit. */

                if (find_match_limit)
                {
                    if (extra == NULL)
                    {
                        extra = (pcre_extra *)MALLOC(sizeof(pcre_extra));
                        extra->flags = 0;
                    }

                    (void)check_match_limit(re, extra, bptr, len, start_offset,
                                            options | g_notempty, use_offsets, use_size_offsets,
                                            PCRE_EXTRA_MATCH_LIMIT, &(extra->match_limit),
                                            PCRE_ERROR_MATCHLIMIT);

                    count = check_match_limit(re, extra, bptr, len, start_offset,
                                              options | g_notempty, use_offsets, use_size_offsets,
                                              PCRE_EXTRA_MATCH_LIMIT_RECURSION, &(extra->match_limit_recursion),
                                              PCRE_ERROR_RECURSIONLIMIT);
                }
                /* If callout_data is set, use the interface with additional data */
                else if (callout_data_set)
                {
                    if (extra == NULL)
                    {
                        extra = (pcre_extra *)MALLOC(sizeof(pcre_extra));
                        extra->flags = 0;
                    }
                    extra->flags |= PCRE_EXTRA_CALLOUT_DATA;
                    extra->callout_data = &callout_data;
                    count = pcre_exec(re, extra, (char *)bptr, len, start_offset,
                                      options | g_notempty, use_offsets, use_size_offsets);

                    extra->flags &= ~PCRE_EXTRA_CALLOUT_DATA;
                }
                /* The normal case is just to do the match once, with the default
                value of match_limit. */
                else
                {
                    count = pcre_exec(re, extra, (char *)bptr, len,
                                      start_offset, options | g_notempty, use_offsets, use_size_offsets);
                    if (count == 0)
                    {
                        count = use_size_offsets / 3;
                    }

                    //to retrieve backref count and values
                    if (count > 0 && _pstCapturedString != NULL && _piCapturedStringCount != NULL)
                    {
                        int i = 0;
                        int iErr = 0;

                        iErr = pcre_fullinfo(re, extra, PCRE_INFO_CAPTURECOUNT, _piCapturedStringCount);
                        //sciprint("PCRE_INFO_CAPTURECOUNT %d\n", *_piCapturedStringCount);

                        if (*_piCapturedStringCount > 0)
                        {
                            *_pstCapturedString = (char**)MALLOC(sizeof(char*) * *_piCapturedStringCount);
                            for (i = 0 ; i < *_piCapturedStringCount ; i++)
                            {
                                char* pstSubstring = NULL;
                                pcre_get_substring(bptr, use_offsets, count, i + 1, &pstSubstring);
                                if (pstSubstring != NULL)
                                {
                                    (*_pstCapturedString)[i] = strdup(pstSubstring);
                                }
                                pcre_free_substring(pstSubstring);
                            }
                        }
                    }
                }
                /* Matched */
                if (count >= 0)
                {
                    int i, maxcount;
                    maxcount = use_size_offsets / 3;
                    /* This is a check against a lunatic return value. */
                    if (count > maxcount)
                    {
                        if (buffer)
                        {
                            FREE(buffer);
                            buffer = NULL;
                        }
                        if (offsets)
                        {
                            FREE(offsets);
                            offsets = NULL;
                        }
                        if (re)
                        {
                            (*pcre_free)(re);
                            re = NULL;
                        }
                        if (tables)
                        {
                            (*pcre_free)((void*)tables);
                            tables = NULL;
                        }
                        if (extra)
                        {
                            FREE(extra);
                            extra = NULL;
                        }
                        if (back_p)
                        {
                            FREE(back_p);
                            back_p = NULL;
                        }
                        return TOO_BIG_FOR_OFFSET_SIZE;
                    }

                    for (i = 0; i < count * 2; i += 2)
                    {
                        if (use_offsets[i] >= 0)
                        {
                            *Output_Start = use_offsets[i];
                            *Output_End = use_offsets[i + 1];
                            if (buffer)
                            {
                                FREE(buffer);
                            }

                            /* use_offsets = offsets no need to free use_offsets if we free offsets */
                            if (offsets)
                            {
                                FREE(offsets);
                            }

                            /* "re" allocated by pcre_compile (better to use free function associated)*/
                            if (re)
                            {
                                (*pcre_free)(re);
                            }

                            if (extra)
                            {
                                FREE(extra);
                            }
                            if (tables)
                            {
                                /* "tables" allocated by pcre_maketables (better to use free function associated to pcre)*/
                                (*pcre_free)((void *)tables);
                                tables = NULL;
                                setlocale(LC_CTYPE, "C");
                            }

                            if (back_p)
                            {
                                FREE(back_p);
                                back_p = NULL;
                            }
                            return PCRE_FINISHED_OK;
                        }
                    }

                    for (copynamesptr = copynames; *copynamesptr != 0; copynamesptr += (int)strlen((char*)copynamesptr) + 1)
                    {
                        char copybuffer[256];
                        pcre_copy_named_substring(re, (char *)bptr, use_offsets, count, (char *)copynamesptr, copybuffer, sizeof(copybuffer));
                    }

                    for (i = 0; i < 32; i++)
                    {
                        if ((getstrings & (1 << i)) != 0)
                        {
                            const char *substring;
                            pcre_get_substring((char *)bptr, use_offsets, count, i, &substring);
                        }
                    }

                    for (getnamesptr = getnames; *getnamesptr != 0; getnamesptr += (int)strlen((char*)getnamesptr) + 1)
                    {
                        const char *substring;
                        pcre_get_named_substring(re, (char *)bptr, use_offsets, count, (char *)getnamesptr, &substring);
                    }

                }
                /* Failed to match. If this is a /g or /G loop and we previously set
                g_notempty after a null match, this is not necessarily the end. We want
                to advance the start offset, and continue. We won't be at the end of the
                string - that was checked before setting g_notempty.
                Complication arises in the case when the newline option is "any" or
                "anycrlf". If the previous match was at the end of a line terminated by
                CRLF, an advance of one character just passes the \r, whereas we should
                prefer the longer newline sequence, as does the code in pcre_exec().
                Fudge the offset value to achieve this.

                Otherwise, in the case of UTF-8 matching, the advance must be one
                character, not one byte. */
                else
                {
                    if (count == PCRE_ERROR_NOMATCH)
                    {
                        if (gmatched == 0)
                        {
                            if (tables)
                            {
                                (*pcre_free)((void *)tables);
                                tables = NULL;
                            }
                            if (re)
                            {
                                (*pcre_free)((void *)re);
                                re = NULL;
                            }
                            if (buffer)
                            {
                                FREE(buffer);
                                buffer = NULL;
                            }
                            if (offsets)
                            {
                                FREE(offsets);
                            }
                            if (p)
                            {
                                FREE(back_p);
                                back_p = NULL;
                            }
                            return NO_MATCH;
                        }
                    }

                    if (count == PCRE_ERROR_MATCHLIMIT )
                    {
                        if (tables)
                        {
                            (*pcre_free)((void *)tables);
                            tables = NULL;
                        }
                        if (re)
                        {
                            (*pcre_free)((void *)re);
                            re = NULL;
                        }
                        if (buffer)
                        {
                            FREE(buffer);
                            buffer = NULL;
                        }
                        if (offsets)
                        {
                            FREE(offsets);
                            offsets = NULL;
                        }
                        if (back_p)
                        {
                            FREE(back_p);
                            back_p = NULL;
                        }
                        return MATCH_LIMIT;
                    }
                    break;  /* Out of loop */
                }

                /* If not /g or /G we are done */
                if (!do_g && !do_G)
                {
                    break;
                }

                /* If we have matched an empty string, first check to see if we are at
                the end of the subject. If so, the /g loop is over. Otherwise, mimic
                what Perl's /g options does. This turns out to be rather cunning. First
                we set PCRE_NOTEMPTY and PCRE_ANCHORED and try the match again at the
                same point. If this fails (picked up above) we advance to the next
                character. */

                g_notempty = 0;

                if (use_offsets[0] == use_offsets[1])
                {
                    if (use_offsets[0] == len)
                    {
                        break;
                    }
                    g_notempty = PCRE_NOTEMPTY | PCRE_ANCHORED;
                }

                /* For /g, update the start offset, leaving the rest alone */

                if (do_g)
                {
                    start_offset = use_offsets[1];
                }
                /* For /G, update the pointer and length */
                else
                {
                    bptr += use_offsets[1];
                    len -= use_offsets[1];
                }
            }  /* End of loop for /g and /G */

            if (re)
            {
                (*pcre_free)(re);
                re = NULL;
            }
            if (extra)
            {
                FREE(extra);
                extra = NULL;
            }
            if (tables)
            {
                (*pcre_free)((void *)tables);
                tables = NULL;
            }

            FREE(back_p);
            back_p = NULL;
            continue;
        }    /* End of loop for data lines */
    }

    if (buffer)
    {
        FREE(buffer);
        buffer = NULL;
    }
    if (offsets)
    {
        FREE(offsets);
        offsets = NULL;
    }

    return PCRE_EXIT;
}
예제 #27
0
static char *
generate_sqlrow_insert( Dbptr db, char *(*createsync)(Dbptr db), long flags )
{
	void	*stk = 0;
	char	*table;
	Tbl	*fields;
	Dbvalue	dbvalue;
	char	*field;
	long	ifield;
	long	ftype;
	char	*fformat;
	char	part[STRSZ];
	char	*sync;
	char	*copy;

	if( db.record < 0 && 
	    db.record != dbSCRATCH && 
	    db.record != dbNULL ) {

		return NULL;
	}

	dbquery( db, dbTABLE_NAME, &table );
	dbquery( db, dbTABLE_FIELDS, &fields );

	pushstr( &stk, "INSERT INTO `" );
	pushstr( &stk, table );

	pushstr( &stk, "` VALUES(" );

	for( ifield = 0; ifield < maxtbl( fields ); ifield++ ) {
		
		field = gettbl( fields, ifield );

		db = dblookup( db, "", "", field, "" );

		dbquery( db, dbFIELD_TYPE, &ftype );
		dbquery( db, dbFIELD_FORMAT, &fformat );

		dbgetv( db, 0, field, &dbvalue, NULL );

		if( ifield > 0 ) {

			pushstr( &stk, ", " );
		}

		if( ! ( flags & DB2SQL_USE_DATASCOPE_NULLS ) && dbfield_isnull( db ) ) {

			pushstr( &stk, "NULL" );

			continue;
		}

		memset( part, '\0', STRSZ );

		switch( ftype ) {

		case dbSTRING:
			pushstr( &stk, "'" );
			if( strchr( dbvalue.s, '\'' ) == (char *) NULL ) {
				pushstr( &stk, dbvalue.s );
			} else {
				allot( char *, copy, 2 * strlen( dbvalue.s ) );
				strsub( dbvalue.s, "'", "\\'", copy );
				pushstr( &stk, copy );
				free( copy );
			}
			pushstr( &stk, "'" );
			break;

		case dbREAL:
		case dbTIME:
			sprintf( part, fformat, dbvalue.d );
			pushstr( &stk, part );
			break;

		case dbINTEGER:
		case dbYEARDAY:
			sprintf( part, fformat, dbvalue.i );
			pushstr( &stk, part );
			break;

		case dbDBPTR:
			sprintf( part, "%ld %ld %ld %ld", 
					dbvalue.db.database, 
					dbvalue.db.table, 
					dbvalue.db.field, 
					dbvalue.db.record );
			pushstr( &stk, part );
			break;
		}
	}

	if( ! ( flags & DB2SQL_OMIT_SYNC ) ) {

		if( createsync != (char *(*)(Dbptr db)) NULL ) {

			sync = (*createsync)( db );

		} else {

			sync = (char *) NULL;
		}

		pushstr( &stk, ", '" );

		if( sync != (char *) NULL ) {

			pushstr( &stk, sync );

		} else {

			pushstr( &stk, DB2SQL_SYNCFIELD_NULL );
		}

		pushstr( &stk, "'" );

		if( sync != (char *) NULL ) {

			free( sync );
		}
	}

	pushstr( &stk, ");\n" );

	return popstr( &stk, 1 );
}
예제 #28
0
파일: main.c 프로젝트: pdeans/cprogramming
void getEmployees(Employee workers[])
{
    char buffer[100];
    int i = 0;
    char ageTemp[3];
    char tenureTemp[2];
    char salaryTemp[7];

    while (!feof(fp)) {
        fgets(buffer, 100, fp);
        strsub(buffer, workers[i].first, 0, 6);
        strsub(buffer, workers[i].initial, 8, 8);
        strsub(buffer, workers[i].last, 10, 18);
        strsub(buffer, workers[i].street, 20, 35);
        strsub(buffer, workers[i].city, 37, 47);
        strsub(buffer, workers[i].state, 49, 50);
        strsub(buffer, workers[i].zip, 52, 56);
        strsub(buffer, ageTemp, 58, 59);
        strsub(buffer, workers[i].sex, 61, 61);
        strsub(buffer, tenureTemp, 63, 63);
        strsub(buffer, salaryTemp, 65, 70);
        workers[i].age = atoi(ageTemp);
        workers[i].tenure = atoi(tenureTemp);
        workers[i].salary = atof(salaryTemp);
        i++;
    }
}
예제 #29
0
/*
 * create the file 'alter.inc' to be included in <inputfile>.* file. Depending
 * the value of the 'append' variable, the data is append or a new file is
 * created.
 */
void CreateALTERinc(char *ConfigFile, char *OutputFile, int append)
{
	int i, j, k, kk, add, jj, l;
	char data[LONGSTRINGSIZE];
	FILE *fsweepINI, *falterINC;
	alter_line alter[ALTERLINES]; /*ALTERLINES in 'sweep.ini' file*/
	int sweep[SWEEPLINES];        /*SWEEPLINES variables: [2123] */
	int order[SWEEPLINES];        /*SWEEPLINES variables: [1111] [1112] [1113] [1121] ...*/
	int ptr, num_lines, index, alter_times;


	/**/
	/*Step0: zero variables*/
	for (i = 0; i <= ALTERLINES-1; i++) {
		*alter[i].text = '\0';
		for (j = 0; j <= SWEEPVARS-1; j++)
			*alter[i].data[j] = '\0';
	}

	for (i = 0; i <= SWEEPLINES-1; i++) {
		sweep[i] = 0;
		order[i] = 0;
	}


	/**/
	/*Step1: open input and output files*/
	if ((fsweepINI=fopen(ConfigFile,"rt")) == 0) {
		printf("auxfunc_alter.c -  CreateALTERinc -- Cannot open config file: %s\n", ConfigFile);
		exit(EXIT_FAILURE);
	}
	if (append) {
		if ((falterINC=fopen(OutputFile,"r+t")) == 0) { /*append to a file*/
			printf("auxfunc_alter.c -  CreateALTERinc -- Cannot write to output file: %s\n", OutputFile);
			exit(EXIT_FAILURE);
		}
	} else {
		if ((falterINC=fopen(OutputFile,"wt")) == 0) { /*create an empty file for writing*/
			printf("auxfunc_alter.c -  CreateALTERinc -- Cannot write to output file: %s\n", OutputFile);
			exit(EXIT_FAILURE);
		}
	}


	/**/
	/**/
	ReadKey(lkk, "# ALTER #", fsweepINI);
	if (!lkk[0]) {
		printf("auxfunc_alter.c -  CreateALTERinc -- # ALTER # key not found\n");
		exit(EXIT_FAILURE);
	} else {
		/**/
		/*Step2: read the options in the configuration file*/
		fgets2(lkk, LONGSTRINGSIZE, fsweepINI);
		switch(spice) { /*Spectre special case*/
			case 1: /*Eldo*/
			case 2: /*HSPICE*/
				break;
			case 3: /*LTspice*/
				printf("auxfunc_alter.c - CreateALTERinc -- LTspice not supported\n");
				exit(EXIT_FAILURE);
			case 4: /*Spectre*/
				if (!strpos2(lkk, " altergroup", 1)) {
					printf("auxfunc_alter.c - CreateALTERinc -- 'altergroup' must exist in Spectre mode\n");
					exit(EXIT_FAILURE);
				}
				break;
			case 50: /*Qucs*/
				printf("auxfunc_alter.c - CreateALTERinc -- Qucs not supported\n");
				exit(EXIT_FAILURE);
			case 100: /*general*/
				printf("auxfunc_alter.c - CreateALTERinc -- GENERAL not supported\n");
				exit(EXIT_FAILURE);
			default:
				printf("auxfunc_alter.c - CreateALTERinc -- Something unexpected has happened!\n");
				exit(EXIT_FAILURE);
		}
		i = 1;
		ptr = 0;
		while (lkk[0] != '#') {
			if (lkk[0] != '*') {
				if (i > (ALTERLINES)) {
					printf("auxfunc_alter.c -  CreateALTERinc -- Maximum number of %d lines reached. Increase ALTERLINES in auxfunc_alter.h\n", ALTERLINES);
					exit(EXIT_FAILURE);
				}

				j = strpos2(lkk, "$", 1); /*This will skip the characters after '$', the inline comment used by the sweep tools*/
				if (j != 0)
					lkk[j-1]='\0'; /* sprintf(lkk, "%.*s", (int)(j - 1), strcpy(data, lkk)); */
				StripSpaces(lkk);


				/*****/
				/*The next block reads the data to sweep*/
				j = strpos2(lkk, "[", 1);
				if (j == 0 || lkk[0] == '*') {
					sprintf(alter[i - 1].text, "%.*s", (int)strlen(lkk), lkk);
					i++;
				}
				else {
					if (strpos2(lkk, "  ", j)) {
						printf("auxfunc_alter.c -  CreateALTERinc -- More than one space exist in: %s\n", strsub(data, lkk, j, LONGSTRINGSIZE));
						exit(EXIT_FAILURE);
					}
					if (strpos2(lkk, "[ ", j)) {
						printf("auxfunc_alter.c -  CreateALTERinc -- Space exist after '[' in: %s\n", strsub(data, lkk, j, LONGSTRINGSIZE));
						exit(EXIT_FAILURE);
					}
					if (strpos2(lkk, " ]", j)) {
						printf("auxfunc_alter.c -  CreateALTERinc -- Space exist before ']' in: %s\n", strsub(data, lkk, j, LONGSTRINGSIZE));
						exit(EXIT_FAILURE);
					}
					sprintf(alter[i - 1].text, "%.*s", (int)(j - 1), lkk);
					/*begin*/
					k = 0;
					ReadSubKey(data, lkk, &j, '[', ' ', 4);
					if (*data != '\0') {
						k++;
						read_sweep_vars(alter[i - 1].data[0], data);
					}

					l=1;
					while (l<SWEEPVARS) {
						ReadSubKey(data, lkk, &j, ' ', ' ', 0);
						if (*data != '\0') {
							k++;
							read_sweep_vars(alter[i - 1].data[l], data);
						} else
							break;
						l++;
					}

					sweep[ptr] = k;
					order[ptr] = 1;
					ptr++;
					/*end;*/
					i++;
				}
				/*****/
			}
			fgets2(lkk, LONGSTRINGSIZE, fsweepINI);
		}
		num_lines = i - 1;


		/**/
		/*Step3: */
		alter_times = 1;   /*alter_times: how many simulations?*/
		kk = 0;
		for (i = 0; i < num_lines; i++) {
			if (*alter[i].data[0] != '\0') {
				kk++;
				alter_times *= sweep[kk - 1];
			}
		}

		if (alter_times > 65536L || kk > SWEEPLINES) {
			if (kk > SWEEPLINES) {
				printf("auxfunc_alter.c -  CreateALTERinc -- Maximum number of %d variables to sweep reached. Increase SWEEPLINES in auxfunc_alter.h\n", SWEEPLINES);
				exit(EXIT_FAILURE);
			} else {
				printf("auxfunc_alter.c -  CreateALTERinc -- More than 65536 simulations reached\n");
				exit(EXIT_FAILURE);
			}
		} else {
			if (append) { /*Assumes that is comming from errfunc.c*/
				switch(spice) {
					case 1: /*Eldo*/
					case 2: /*HSPICE*/
						fseek(falterINC, -5, SEEK_END);               /*properly position the pointer*/
						break;
					case 3: /*LTspice*/
						printf("auxfunc_alter.c - CreateALTERinc -- LTspice not supported\n");
						exit(EXIT_FAILURE);
					case 4: /*Spectre*/
						break;
					case 50: /*Qucs*/
						printf("auxfunc_alter.c - CreateALTERinc -- Qucs not supported\n");
						exit(EXIT_FAILURE);
					case 100: /*general*/
						printf("auxfunc_alter.c - CreateALTERinc -- GENERAL not supported\n");
						exit(EXIT_FAILURE);
					default:
						printf("auxfunc_alter.c - CreateALTERinc -- Something unexpected has happened!\n");
						exit(EXIT_FAILURE);
				}
				#ifdef __MINGW32__
				fseek(falterINC, -1, SEEK_CUR);               /*properly position the pointer*/
				#endif
			}

			switch(spice) { /*Spectre special case*/
				case 1: /*Eldo*/
				case 2: /*HSPICE*/
					break;
				case 3: /*LTspice*/
					break;
					printf("auxfunc_alter.c - CreateALTERinc -- LTspice not supported\n");
				case 4: /*Spectre*/
					fprintf(falterINC, "simulator lang=spectre\n\n");
					break;
				case 50: /*Qucs*/
					printf("auxfunc_alter.c - CreateALTERinc -- Qucs not supported\n");
					break;
				case 100: /*general*/
					printf("auxfunc_alter.c - CreateALTERinc -- GENERAL not supported\n");
					break;
				default:
					printf("auxfunc_alter.c - CreateALTERinc -- Something unexpected has happened!\n");
					exit(EXIT_FAILURE);
			}


			/**/
			/*Step4*/
			for (index = 1; index <= alter_times; index++) {
				add = 1;   /*build ( [1111] [1112] [1113] [1121] ...*/
				for (jj = kk - 1; jj >= 0; jj--) {
					if (sweep[jj] != 0) {
						if (order[jj] != sweep[jj]) {
							if (index != 1)
								order[jj] += add;
							add = 0;
						} else {
							if (add == 1)
								order[jj] = 1;
						}
					}
				}


				/**/
				/*Step5: print the header with the information about the sweeped vars*/
				j = 1;
				switch(spice) {
					case 1: /*Eldo*/
					case 2: /*HSPICE*/
						fprintf(falterINC, ".ALTER @%d ->", index);
						break;
					case 3: /*LTspice*/
						printf("auxfunc_alter.c - CreateALTERinc -- LTspice not supported\n");
						exit(EXIT_FAILURE);
					case 4: /*Spectre*/
						fprintf(falterINC, "//.ALTER @%d ->", index);
						break;
					case 50: /*Qucs*/
						printf("auxfunc_alter.c - CreateALTERinc -- Qucs not supported\n");
						exit(EXIT_FAILURE);
					case 100: /*general*/
						printf("auxfunc_alter.c - CreateALTERinc -- GENERAL not supported\n");
						exit(EXIT_FAILURE);
					default:
						printf("auxfunc_alter.c - CreateALTERinc -- Something unexpected has happened!\n");
						exit(EXIT_FAILURE);
				}
				for (k = 0; k < num_lines; k++) {
					if (*alter[k].data[0] != '\0') {
						strcpy(data, alter[k].text + 0);   /*previously it had '1', but with '0' nothing is removed*/
						sprintf(data, " %s", alter[k].text + 0);
						fputs(data, falterINC);
						l = order[j - 1];
						j++;
						fprintf(falterINC, "%s;", alter[k].data[l - 1]);
					}
				}
				putc('\n', falterINC);


				/**/
				/*Step6: print each one of the alter lines*/	
				i = 0; /*For Spectre only: in the following block, 'i' is for the indication of EndOfAlterGroup*/
				j = 1;
				for (k = 0; k < num_lines; k++) {
					if (*alter[k].data[0] != '\0') {
						fputs(alter[k].text, falterINC);
						l = order[j - 1];
						j++;
						fprintf(falterINC, "%s\n", alter[k].data[l - 1]);
					} else {
						if (*alter[k].text != '\0') {
							switch(spice) { /*Spectre altergroup handling*/
								case 1: /*Eldo*/
								case 2: /*HSPICE*/
									fprintf(falterINC, "%s\n", alter[k].text);
									break;
								case 3: /*LTspice*/
									printf("auxfunc_alter.c - CreateALTERinc -- LTspice not supported\n");
									exit(EXIT_FAILURE);
								case 4: /*Spectre*/
									if ( (k==0) || (i==1) ){ /*add index to altergroup line*/
										strcpy(lkk, alter[k].text);
										l = strpos2(lkk, " ", 1);
										sprintf(data, "%d", index);
										InsertString(lkk, data, l, l);
										fprintf(falterINC, "%s\n", lkk);
									} else
										fprintf(falterINC, "%s\n", alter[k].text);
									if (!strcmp(alter[k].text, "}")) /*Detects the end of altergroup as soon as it finds '}'*/
										i=1;                     /* and stores this information in variable 'i'         */
									l = strpos2(alter[k].text, "}", 1); /*Verification that detection went well*/
									if (l && (i==0) ) {
										printf("auxfunc_alter.c - CreateALTERinc -- Failed the detection of the end of altergroup\n");
										exit(EXIT_FAILURE);
									}
									break;
								case 50: /*Qucs*/
									printf("auxfunc_alter.c - CreateALTERinc -- Qucs not supported\n");
									exit(EXIT_FAILURE);
								case 100: /*general*/
									printf("auxfunc_alter.c - CreateALTERinc -- GENERAL not supported\n");
									exit(EXIT_FAILURE);
								default:
									printf("auxfunc_alter.c - CreateALTERinc -- Something unexpected has happened!\n");
									exit(EXIT_FAILURE);
							}
						}
					}
				}
				putc('\n', falterINC);
			}
		}
	}


	if (fsweepINI != NULL)
		fclose(fsweepINI);
	if (falterINC != NULL)
		fclose(falterINC);

} /*CreateALTERinc*/
main()
{
	char string1[100],string2[100],string3[100],string4[100],string5[100], character;      //Declaring variables
	int iterator = 0,length,start;
	printf("Enter the first string to concat \n");
	do                                                         //Reading the first string for concatination
	{
		character = getchar();
		string1[iterator] = character;
		iterator++;
	} while (character != '\n');
	string1[iterator-1] = '\0';
	iterator = 0;
	printf("Enter the second string to concat \n");
	do                                                          //Reading the second string for concatination
	{
		character = getchar();
		string2[iterator] = character;
		iterator++;
	} while (character != '\n');
	string2[iterator-1] = '\0';
	length = strlen(string1);                                  //Function call for strlen() function
	printf("Length of string %s is %d \n", string1,length);    //Printing the length of first string
	length = strlen(string2);
	printf("Length of string %s is %d \n", string2, length);  //Function call for strlen() function
	strcat(string1, string2);                                 //Printing the length of second string
	iterator = 0;
	printf("Enter the first string to compare \n");
	do                                                        //Reading the first string for comparing
	{                                              
		character = getchar();
		string3[iterator] = character;
		iterator++;
	} while (character != '\n');
	string3[iterator - 1] = '\0';
	iterator = 0;
	printf("Enter the second string to compare \n");
	do                                                        //Reading the second string for concatination
	{
		character = getchar();
		string4[iterator] = character;
		iterator++;
	} while (character != '\n');
	string4[iterator - 1] = '\0';
	length=strcmp(string3, string4);                         //Function call for strcmp() function
	printf("the comparision of the strings is %d \n", length); //Printing the result of the comparision
	iterator = 0;
	printf("Enter the string to print its substring \n");
	do                                                         //Reading the main string
	{
		character = getchar();
		string4[iterator] = character;
		iterator++;
	} while (character != '\n');
	string4[iterator - 1] = '\0';
	printf("Enter the start position and length of substring \n");  
	scanf_s("%d%d", &start, &length);                           //Reading the start position and length for the subsrting
	strsub(string4, start, length);                             //Function call for strsub() function
	iterator = 0;
	printf("Enter the string to be trimmed \n");
	getchar();
	do                                                        //Reading the text to be trimmed
	{
		character = getchar();
		string5[iterator] = character;
		iterator++;
	} while (character != '\n');
	string5[iterator - 1] = '\0';
	trim(string5);                                           //Function call for trim() function
}