コード例 #1
0
//This function may be recruse called
void plainconf::loadConfFile(const char *path)
{
    logToMem(LOG_LEVEL_INFO, "start parsing file %s", path);

    int type = checkFiletype(path);

    if (type == 0)
        return;

    else if (type == 2)
        loadDirectory(path, NULL);

    else if (type == 3)
    {
        AutoStr2 prefixPath = path;
        const char *p = strrchr(path, '/');

        if (p)
            prefixPath.setStr(path, p - path);

        struct stat sb;

        //removed the wildchar filename, should be a directory if exist
        if (stat(prefixPath.c_str(), &sb) == -1)
        {
            logToMem(LOG_LEVEL_ERR, "LoadConfFile error 1, path:%s directory:%s",
                     path, prefixPath.c_str());
            return ;
        }

        if ((sb.st_mode & S_IFMT) != S_IFDIR)
        {
            logToMem(LOG_LEVEL_ERR, "LoadConfFile error 2, path:%s directory:%s",
                     path, prefixPath.c_str());
            return ;
        }

        loadDirectory(prefixPath.c_str(), p + 1);
    }

    else //existed file
    {
        //gModuleList.push_back();
        //XmlNode *xmlNode = new XmlNode;
        FILE *fp = fopen(path, "r");

        if (fp == NULL)
        {
            logToMem(LOG_LEVEL_ERR, "Cannot open configuration file: %s", path);
            return;
        }


        const int MAX_LINE_LENGTH = 8192;
        char sLine[MAX_LINE_LENGTH];
        char *p;
        char sLines[MAX_LINE_LENGTH] = {0};
        int lineNumber = 0;
        const int MAX_MULLINE_SIGN_LENGTH = 128;
        char sMultiLineModeSign[MAX_MULLINE_SIGN_LENGTH] = {0};
        size_t  nMultiLineModeSignLen = 0;  //>0 is mulline mode

        while (fgets(sLine, MAX_LINE_LENGTH, fp), !feof(fp))
        {
            ++lineNumber;
            p = sLine;

            if (nMultiLineModeSignLen)
            {
                //Check if reach the END of the milline mode
                size_t len = 0;
                const char *pLineStart = getStrNoSpace(p, len);

                if (len == nMultiLineModeSignLen &&
                    strncasecmp(pLineStart, sMultiLineModeSign, nMultiLineModeSignLen) == 0)
                {
                    nMultiLineModeSignLen = 0;
                    removeSpace(sLines,
                                1);   //Remove the last \r\n so that if it is one line, it will still be one line
                    parseLine(path, lineNumber, sLines);
                    sLines[0] = 0x00;
                }
                else
                    strcat(sLines, p);

                continue;
            }

            removeSpace(p, 0);
            removeSpace(p, 1);

            if (!isValidline(p))
                continue;

            AutoStr2 pathInclude;

            if (isInclude(p, pathInclude))
            {
                char achBuf[512] = {0};
                getIncludeFile(pathInclude.c_str(), achBuf);
                loadConfFile(achBuf);
            }
            else
            {
                nMultiLineModeSignLen = checkMultiLineMode(p, sMultiLineModeSign,
                                        MAX_MULLINE_SIGN_LENGTH);

                if (nMultiLineModeSignLen > 0)
                    strncat(sLines, p, strlen(p) - (3 + nMultiLineModeSignLen));
                //need to continue
                else if (isChunkedLine(p))
                {
                    strncat(sLines, p, strlen(p) - 1);
                    //strcatchr(sLines, ' ', MAX_LINE_LENGTH); //add a space at the end of the line which has a '\\'
                }

                else
                {
                    strcat(sLines, p);
                    parseLine(path, lineNumber, sLines);
                    sLines[0] = 0x00;
                }
            }
        }

        fclose(fp);

        //Parsed, check in it
        checkInFile(path);
    }
}
コード例 #2
0
ファイル: rcDataObjGet.cpp プロジェクト: StephanU/irods
int
rcDataObjGet( rcComm_t *conn, dataObjInp_t *dataObjInp, char *locFilePath ) {
    int status;
    portalOprOut_t *portalOprOut = NULL;
    bytesBuf_t dataObjOutBBuf;
#ifndef windows_platform
    struct stat statbuf;
#else
    struct irodsntstat statbuf;
#endif

    if ( strcmp( locFilePath, STDOUT_FILE_NAME ) == 0 ) {
        /* no parallel I/O if pipe to stdout */
        dataObjInp->numThreads = NO_THREADING;
    }
#ifndef windows_platform
    else if ( stat( locFilePath, &statbuf ) >= 0 )
#else
    else if ( iRODSNt_stat( locFilePath, &statbuf ) >= 0 )
#endif
    {
        /* local file exists */
        if ( getValByKey( &dataObjInp->condInput, FORCE_FLAG_KW ) == NULL ) {
            return ( OVERWRITE_WITHOUT_FORCE_FLAG );
        }
    }

    status = _rcDataObjGet( conn, dataObjInp, &portalOprOut, &dataObjOutBBuf );

    if ( status < 0 ) {
        if ( portalOprOut != NULL ) {
            free( portalOprOut );
        }
        return ( status );
    }

    if ( status == 0 || dataObjOutBBuf.len > 0 ) {
        /* data included */
        /**** Removed by Raja as this can cause problems when the data sizes are different - say when post processing is done....Dec 2 2010
              if (dataObjInp->dataSize > 0 &&
              dataObjInp->dataSize != dataObjOutBBuf.len) {
              rodsLog (LOG_NOTICE,
              "putFile: totalWritten %lld dataSize %lld mismatch",
              dataObjOutBBuf.len, dataObjInp->dataSize);
              return (SYS_COPY_LEN_ERR);
              }
        ****/
        status = getIncludeFile( conn, &dataObjOutBBuf, locFilePath );
        free( dataObjOutBBuf.buf );
    }
    else if ( getUdpPortFromPortList( &portalOprOut->portList ) != 0 ) {
        int veryVerbose;
        /* rbudp transfer */
        /* some sanity check */
        if ( portalOprOut->numThreads != 1 ) {
            rcOprComplete( conn, SYS_INVALID_PORTAL_OPR );
            free( portalOprOut );
            return ( SYS_INVALID_PORTAL_OPR );
        }
        conn->transStat.numThreads = portalOprOut->numThreads;
        if ( getValByKey( &dataObjInp->condInput, VERY_VERBOSE_KW ) != NULL ) {
            printf( "From server: NumThreads=%d, addr:%s, port:%d, cookie=%d\n",
                    portalOprOut->numThreads, portalOprOut->portList.hostAddr,
                    portalOprOut->portList.portNum, portalOprOut->portList.cookie );
            veryVerbose = 2;
        }
        else {
            veryVerbose = 0;
        }

        // =-=-=-=-=-=-=-
        // if a secret has been negotiated then we must be using
        // encryption.  given that RBUDP is not supported in an
        // encrypted capacity this is considered an error
        if ( irods::CS_NEG_USE_SSL == conn->negotiation_results ) {
            rodsLog(
                LOG_ERROR,
                "getFileToPortal: Encryption is not supported with RBUDP" );
            return SYS_INVALID_PORTAL_OPR;

        }

        status = getFileToPortalRbudp(
                     portalOprOut,
                     locFilePath, 0,
                     dataObjInp->dataSize,
                     veryVerbose, 0 );

        /* just send a complete msg */
        if ( status < 0 ) {
            rcOprComplete( conn, status );

        }
        else {
            status = rcOprComplete( conn, portalOprOut->l1descInx );
        }
    }
    else {

        if ( portalOprOut->numThreads <= 0 ) {
            status = getFile( conn, portalOprOut->l1descInx,
                              locFilePath, dataObjInp->objPath, dataObjInp->dataSize );
        }
        else {
            if ( getValByKey( &dataObjInp->condInput, VERY_VERBOSE_KW ) != NULL ) {
                printf( "From server: NumThreads=%d, addr:%s, port:%d, cookie=%d\n",
                        portalOprOut->numThreads, portalOprOut->portList.hostAddr,
                        portalOprOut->portList.portNum, portalOprOut->portList.cookie );
            }
            /* some sanity check */
            if ( portalOprOut->numThreads >= 20 * DEF_NUM_TRAN_THR ) {
                rcOprComplete( conn, SYS_INVALID_PORTAL_OPR );
                free( portalOprOut );
                return ( SYS_INVALID_PORTAL_OPR );
            }

            conn->transStat.numThreads = portalOprOut->numThreads;
            status = getFileFromPortal( conn, portalOprOut, locFilePath,
                                        dataObjInp->objPath, dataObjInp->dataSize );
        }
        /* just send a complete msg */
        if ( status < 0 ) {
            rcOprComplete( conn, status );
        }
        else {
            status = rcOprComplete( conn, portalOprOut->l1descInx );
        }
    }

    if ( status >= 0 && conn->fileRestart.info.numSeg > 0 ) { /* file restart */
        clearLfRestartFile( &conn->fileRestart );
    }

    if ( getValByKey( &dataObjInp->condInput, VERIFY_CHKSUM_KW ) != NULL ) {
        if ( portalOprOut == NULL || strlen( portalOprOut->chksum ) == 0 ) {
            rodsLog( LOG_ERROR,
                     "rcDataObjGet: VERIFY_CHKSUM_KW set but no chksum from server" );
        }
        else {

            status = verifyChksumLocFile( locFilePath, portalOprOut->chksum, NULL );
            if ( status == USER_CHKSUM_MISMATCH ) {
                rodsLogError( LOG_ERROR, status,
                              "rcDataObjGet: chksum mismatch error for %s, status = %d",
                              locFilePath, status );
                if ( portalOprOut != NULL ) {
                    free( portalOprOut );
                }
                return ( status );
            }
            else if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "rcDataObjGet: chksumLocFile error for %s, status = %d",
                              locFilePath, status );
                if ( portalOprOut != NULL ) {
                    free( portalOprOut );
                }
                return ( status );
            }

        }
    }
    if ( portalOprOut != NULL ) {
        free( portalOprOut );
    }

    return ( status );
}
コード例 #3
0
ファイル: main.c プロジェクト: Ebatsin/examples-learning
int main(int argc, char **argv) {
	int flag;
	const char* filename = NULL;

	// retrieve the options
	while(1) {
		static struct option long_options[] = {
			{"help", no_argument, &flagHelp, 1},
			{"no-counter-examples", no_argument, &flagNoCounterExample, 1},
			{"no-generalization", no_argument, &flagNoGeneralization, 1},
			{"expand-relations", no_argument, &flagExpandRelation, 1},
			{"no-color", no_argument, &flagNoColor, 1},
			{0, 0, 0, 0}
		};
		/* getopt_long stores the option index here. */
		int option_index = 0;

		flag = getopt_long (argc, argv, "vh", long_options, &option_index);

		/* Detect the end of the options. */
		if (flag == -1) {
			break;
		}

		switch(flag) {
			case 0:
				// all long option set flags, they will be checked after
				break;
			case 'v':
				// each occurence of a v add a verbosity level
				++flagVerbose;
				break;
			case 'h':
				flagHelp = 1;
				break;
			case '?':
				/* getopt_long already printed an error message. */
				break;
			default:
				abort ();
		}
	}

	if (optind < argc) {
		filename = argv[optind];
	}
	else if(!flagHelp) {
		output(LERROR, "An example file must be passed as an argument. Re run with --help for more informations.\n");
		return 1;
	}
	else {
		output(L0, PROG_NAME " is a programs that aims to find similarities in objects of same type.\n");
		output(L0, "Usage: " PROG_NAME " --help\n");
		output(L0, "       " PROG_NAME " <example-file-path>\n\n");
		output(L0, "--help                  Print the options that can be given to the program\n");
		output(L0, "--expand-relations      On solution objects that contains relations, print the object linked instead of writing its name\n");
		output(L0, "--no-generalization     Skip the generalization step of the solutions generation.\n");
		output(L0, "--no-counter-examples   Prevent the use of counter-exemples to reduce the solutions.\n");
		output(L0, "--no-color              Disable the colored output.\n");
		output(L0, "-v                      Set the verbosity level. 4 levels are available (up to -vvvv)\n");

		return 0;
	}

	setOutputImportance(flagVerbose);

	// if the user ask for no color or the output streams (whether stdout or stderr) aren't terminals, remove colors
	if(flagNoColor || !isatty(fileno(stdout)) || !isatty(fileno(stderr))) {
		enableColors(0);
	}

	size_t includePosition;
	char* c = getIncludeFile(filename, &includePosition);

	if(c == NULL) {
		output(LERROR, "The loading of the configuration file failed. The configuration must be linked in the example file (example file loaded: %s).\n", filename);
	}
	else {
		output(L1, "%sLoading configuration file: %s%s\n", SBDEFAULT, c, SDEFAULT);
		Model* m = loadConfigFile(c);

		if(m == NULL) {
			output(LERROR, "Configuration file parsing: failed\n");
			free(c);
			return 1;
		}

		output(L1, "%sLoading examples file: %s%s\n", SBDEFAULT, filename, SDEFAULT);

		Examples* e = loadExampleFile(filename, m, includePosition);

		if(e == NULL) {
			output(LERROR, "Example file parsing: failed\n");
			free(c);
			freeModel(m);
			return 1;
		}

		output(L1, "%sGenerating all combinations...%s\n", SBDEFAULT, SDEFAULT);

		Solution* s = genAllCombi(m, e);

		output(L1, "%sAdding relations...%s\n", SBDEFAULT, SDEFAULT);

		genAllRelations(s, e, m);

		if(!flagNoGeneralization) {
			output(L1, "%sGeneralization...%s\n", SBDEFAULT, SDEFAULT);
			genGeneralization(m, s);
		}

		if(!flagNoCounterExample) {
			output(L1, "%sChecking counter-examples...%s\n", SBDEFAULT, SDEFAULT);
			genCounterExamples(m, e, s);
		}

		output(L1, "%sSolutions:%s\n", SBDEFAULT, SDEFAULT);
		
		genOutput(s, m, flagExpandRelation);

		free(c);
		freeModel(m);
		freeExamples(e);
		freeSolution(s);
	}

	return 0;
}