QString DownloadLogsCmd::DownloadLogsTask::getCommand()
{
#ifdef WINDOWS
  return fromString(std::string(File::getBHDir()) + "/Make/" + makeDirectory() + "/downloadLogs.cmd");
#else
  return fromString(std::string(File::getBHDir()) + "/Make/" + makeDirectory() + "/downloadLogs");
#endif
}
Exemplo n.º 2
0
void initDirectories(void) {
  if(PREF_DIR[0] != '~')
    sprintf(preferences_dir, PREF_DIR);
  else
    sprintf(preferences_dir, "%s%s", getHome(), PREF_DIR + 1);

  if(SNAP_DIR[0] != '~')
    sprintf(snapshots_dir, SNAP_DIR);
  else
    sprintf(snapshots_dir, "%s%s", getHome(), SNAP_DIR + 1);

#ifdef LOCAL_DATA
  #ifdef macintosh
  sprintf(data_dir, ":data");
  sprintf(art_dir, ":art");
  sprintf(scripts_dir, ":scripts");
  sprintf(music_dir, ":music");
  sprintf(level_dir, ":levels");
  #else
  sprintf(data_dir, "data");
  sprintf(art_dir, "art");
  sprintf(scripts_dir, "scripts");
  sprintf(music_dir, "music");
  sprintf(level_dir, "levels");
  #endif

#else
  sprintf(data_dir, "%s%c%s", DATA_DIR, SEPARATOR, "data");
  sprintf(art_dir, "%s%c%s", DATA_DIR, SEPARATOR, "art");
  sprintf(scripts_dir, "%s%c%s", DATA_DIR, SEPARATOR, "scripts");
  sprintf(music_dir, "%s%c%s", DATA_DIR, SEPARATOR, "music");
  sprintf(level_dir, "%s%c%s", DATA_DIR, SEPARATOR, "levels");
#endif

	/*
  printf("directories:\n"
	 "\tprefs: %s\n"
	 "\tsnaps: %s\n"
	 "\tdata:  %s\n"
	 "\tart:   %s\n"
	 "\tscripts:   %s\n"
	 "\tmusic: %s\n",
	 preferences_dir, snapshots_dir, 
	 data_dir, art_dir, scripts_dir, 
	 music_dir);
	*/

  makeDirectory(preferences_dir);
  makeDirectory(snapshots_dir);
}
Exemplo n.º 3
0
/*
 * Given a time, opens the appropriate Berkeley DB database--creating it if it
 * doesn't exist, along with any directories in its path--and sets its record
 * number to the appropriate value (1 for new databases, last record number + 1
 * for existing databases).
 */
std::tr1::unordered_map <uint32_t, _BerkeleyDB*>::iterator BerkeleyDB::createDatabase(const uint32_t &hourStartTime) {
  std::string dataFileName = getDataDirectory(hourStartTime);
  std::tr1::unordered_map <uint32_t, _BerkeleyDB*>::iterator databaseItr;
  if (!makeDirectory(dataFileName, 0755)) {
    return databases.end();
  }
  databaseItr = databases.insert(std::make_pair(hourStartTime,
                                                new _BerkeleyDB)).first;
  dataFileName += _baseFileName + '_' + getHour(hourStartTime);
  if (db_create(&(databaseItr -> second -> database), NULL, 0) != 0) {
    return databases.end();
  }
  if (databaseItr -> second -> database -> open(databaseItr -> second -> database,
                                                NULL, dataFileName.c_str(),
                                                NULL, DB_RECNO, DB_CREATE,
                                                S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) != 0) {
    return databases.end();
  }
  if (databaseItr -> second -> database -> cursor(databaseItr -> second -> database,
                                                  NULL, &(databaseItr -> second -> cursor),
                                                  0) != 0) {
    return databases.end();
  }
  if (databaseItr -> second -> cursor -> c_get(databaseItr -> second -> cursor,
                                               &(databaseItr -> second -> key),
                                               &(databaseItr -> second -> data),
                                               DB_LAST) == DB_NOTFOUND) {
    databaseItr -> second -> recordNumber = 1;
  }
  else {
    databaseItr -> second -> recordNumber = *(uint32_t*)databaseItr -> second -> key.data + 1;
  }
  databaseItr -> second -> cursor -> c_close(databaseItr -> second -> cursor);
  return databaseItr;
}
Exemplo n.º 4
0
void makeDirectory(const std::string& path)
{
    if(path.empty())
    {
        return;
    }

    if(isDirectory(path))
    {
        return;
    }

    if(!isDirectory(getDirectory(path)))
    {
        makeDirectory(getDirectory(path));
    }

    #ifndef _WIN32
    int status = mkdir(path.c_str(), 0755);

    if(status != 0)
    {
        throw std::runtime_error("Failed to make directory '" + path + "'.");
    }
    #else
    assertM(false, "Not implemented for this platform.");
    #endif
}
Exemplo n.º 5
0
Path& Path::append(const Path& path)
{
    makeDirectory();
    m_vDirs.insert(m_vDirs.end(), path.m_vDirs.begin(), path.m_vDirs.end());
    m_sName = path.m_sName;
    return *this;
}
Exemplo n.º 6
0
Path& Path::append(const Path& path)
{
	makeDirectory();
	_dirs.insert(_dirs.end(), path._dirs.begin(), path._dirs.end());
	_name = path._name;
	_version = path._version;
	return *this;
}
Exemplo n.º 7
0
Path::Path(const Path& parent, const std::string& fileName)
    : m_sNode(parent.m_sNode)
    , m_sDevice(parent.m_sDevice)
    , m_sName(parent.m_sName)
    , m_vDirs(parent.m_vDirs)
    , m_bAbsolute(parent.m_bAbsolute)
{	
    makeDirectory();
    m_sName = fileName;
}
Exemplo n.º 8
0
Path::Path(const Path& parent, const char* fileName):
	_node(parent._node), 
	_device(parent._device),
	_name(parent._name),
	_version(parent._version),
	_dirs(parent._dirs),
	_absolute(parent._absolute)
{	
	makeDirectory();
	_name = fileName;
}
Exemplo n.º 9
0
 FileSaver::FileSaver(const std::string& directoryPath) :
     mDirectoryPath{formatAsDirectory(directoryPath)}
 {
     try
     {
         makeDirectory(mDirectoryPath);
     }
     catch (const std::exception& e)
     {
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 10
0
static int archiveLog (LOGGER *p_logger, char *archiveDate) {

	int		retval	= SUCCESS;
	char		archivePath[LOG_MAX_PATH_LEN+1];
	char		*fname;
	char		*ext;
	char		timeStr[64];	/* .HH.MM.SS */
	char		newName[LOG_MAX_FILENAME_LEN+1];
	struct tm	*lt;

	if (p_logger == NULL) {
		fprintf (stderr, "ERROR: %s - NULL logger provided\n", __FUNCTION__);
		return ERROR;
	}

	if (!(p_logger->optionMask & NODE_IN_USE)) {
		fprintf (stderr, "ERROR: %s - Logger not in use\n", __FUNCTION__);
		return ERROR;
	}

	sprintf (archivePath, "%s/%s", p_logger->archivePath, archiveDate);
	if (!fileExists (archivePath)) {
		if (makeDirectory (archivePath, YES, DIRECTORY_CREATE_PERMS)) {
			fprintf (stderr, "ERROR: %s - could not create directory %s\n", __FUNCTION__, archivePath);
			retval = ERROR;
		}
	}

	fname = strdup (p_logger->logName);
	splitFilenameExt (fname, &ext);		/* Remove the extension, if there is one */

	lt = localtime (&p_logger->lastLogTime);
	sprintf (timeStr, "%02d.%02d.%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);

	sprintf (newName, "%s/%s.%s", archivePath, fname, timeStr);
	free (fname);

	if (p_logger->optionMask & O_LOG_INIT) {
		p_logger->amArchiving = TRUE;
		logMsg (p_logger, V_ALWAYS, S_STATUS, "%s ARCHIVED TO %s", p_logger->name, newName);
		p_logger->amArchiving = FALSE;
	}

	logClose (p_logger);

	if (moveFile (p_logger->fullLogName, newName, NO)) {
		fprintf (stderr, "ERROR: %s - could not move %s to %s\n", __FUNCTION__, p_logger->fullLogName, archivePath);
		retval = ERROR;
	}

	return retval;
}
Exemplo n.º 11
0
void doJob(const std::string& inputMaf, const std::string& outDir, 
		   std::vector<ParamPair> simplParams, std::vector<int> minBlockSizes)
{

	const int MIN_ALIGNMENT = 1;
	const int MAX_ALIGNMENT_GAP = 0;
	const auto EMPTY_GROUP = BlockGroups();

	BlockGroups blockGroups = EMPTY_GROUP;
	PermVec currentBlocks;
	//sort blocks in reverse order (will use it as stack)
	std::sort(minBlockSizes.begin(), minBlockSizes.end(), std::greater<int>());
	makeDirectory(outDir);

	//read maf alignment and join adjacent columns
	std::cerr << "\tParsing MAF file\n";
	PermVec mafBlocks = mafToPermutations(inputMaf, MIN_ALIGNMENT);
	compressPaths(mafBlocks, MAX_ALIGNMENT_GAP, currentBlocks, blockGroups);

	//iterative simplification
	for (const ParamPair& ppair : simplParams)
	{
		if (minBlockSizes.empty()) break;
		//output blocks of certain size
		while (!minBlockSizes.empty() && minBlockSizes.back() < ppair.minBlock)
		{
			std::string blockDir = outDir + "/" + 
								   std::to_string(minBlockSizes.back());
			outputBlocks(blockDir, currentBlocks, blockGroups,
						 minBlockSizes.back());
			minBlockSizes.pop_back();
		}

		std::cerr << "\tSimplification with " << ppair.minBlock << " "
				  << ppair.maxGap << std::endl;
		PermVec inputBlocks = filterBySize(currentBlocks, EMPTY_GROUP,
										   ppair.minBlock, true);
		PermVec outBlocks;
		blockGroups.clear();
		processGraph(inputBlocks, ppair.maxGap, outBlocks, blockGroups);
		currentBlocks = outBlocks;
	}

	//if any left
	for (int minBlock : minBlockSizes)
	{
		std::string blockDir = outDir + "/" + std::to_string(minBlock);
		outputBlocks(blockDir, currentBlocks, blockGroups, minBlock);
	}
}
Exemplo n.º 12
0
void outputBlocks(const std::string& outDir, PermVec& blocks,
				  BlockGroups& groups, int blockSize)
{
	makeDirectory(outDir);
	std::string permsFile = outDir + "/genomes_permutations.txt";
	std::string coordsFile = outDir + "/blocks_coords.txt";
	std::string statsFile = outDir + "/coverage_report.txt";

	PermVec outPerms = filterBySize(blocks, groups, blockSize, true);
	renumerate(outPerms);
	outputPermutation(outPerms, permsFile);
	outputCoords(outPerms, coordsFile);
	outputStatistics(outPerms, statsFile);
}
Exemplo n.º 13
0
void Path::parseWindows(const std::string& sPath)
{
    clear();

    std::string::const_iterator it  = sPath.begin();
    std::string::const_iterator end = sPath.end();

    if (it != end)
    {
        if (*it == '\\' || *it == '/') { m_bAbsolute = true; ++it; }
        if (m_bAbsolute && it != end && (*it == '\\' || *it == '/')) // UNC
        {
            ++it;
            while (it != end && *it != '\\' && *it != '/') m_sNode += *it++;
            if (it != end) ++it;
        }
        else if (it != end)
        {
            char d = *it++;
            if (it != end && *it == ':') // drive letter
            {
                if (m_bAbsolute || !((d >= 'a' && d <= 'z') || (d >= 'A' && d <= 'Z')))
                {
                    FIRTEX_THROW(BadParameterException, "Bad parameter: [%s]", sPath.c_str());
                }
                m_bAbsolute = true;
                m_sDevice += d;
                ++it;
                if (it == end || (*it != '\\' && *it != '/'))
                {
                    FIRTEX_THROW(BadParameterException, "Bad parameter: [%s]", sPath.c_str());
                }
                ++it;
            }
            else --it;
        }
        while (it != end)
        {
            std::string name;
            while (it != end && *it != '\\' && *it != '/') name += *it++;
            if (it != end)
                pushDirectory(name);
            else
                m_sName = name;
            if (it != end) ++it;
        }
    }
    if (!m_sNode.empty() && m_vDirs.empty() && !m_sName.empty())
        makeDirectory();
}
Exemplo n.º 14
0
devcall lfsControl(struct dentry *devptr, int32 func, int32 arg1, int32 arg2)
{
	int retval;
	switch(func)
	{
		case LF_CTL_MKDIR:
			{
				retval = makeDirectory((char *)arg1);
				return retval;
			}
		default:
			return SYSERR;
	}
	
	return OK;
}
Exemplo n.º 15
0
static void dumpGameData(const char *name, FILE *in, uint32_t offset, uint32_t size) {
	fprintf(stdout, "%s at 0x%x size %d bytes\n", name, offset, size);
	makeDirectory(GAMEDATA_DIRECTORY);
	char path[MAXPATHLEN];
	snprintf(path, sizeof(path), "%s/%s", GAMEDATA_DIRECTORY, name);
	FILE *out = fopen(path, "wb");
	if (out) {
		uint8_t buf[4096];
		int count;
		fseek(in, offset, SEEK_SET);
		while ((count = fread(buf, 1, size < sizeof(buf) ? size : sizeof(buf), in)) > 0) {
			fwrite(buf, 1, count, out);
			size -= count;
		}
		fclose(out);
	}
}
Exemplo n.º 16
0
void Path::parseWindows(const std::string& path)
{
	clear();

	std::string::const_iterator it  = path.begin();
	std::string::const_iterator end = path.end();

	if (it != end)
	{
		if (*it == '\\' || *it == '/') { _absolute = true; ++it; }
		if (_absolute && it != end && (*it == '\\' || *it == '/')) // UNC
		{
			++it;
			while (it != end && *it != '\\' && *it != '/') _node += *it++;
			if (it != end) ++it;
		}
		else if (it != end)
		{
			char d = *it++;
			if (it != end && *it == ':') // drive letter
			{
				if (_absolute || !((d >= 'a' && d <= 'z') || (d >= 'A' && d <= 'Z'))) throw std::exception();
				_absolute = true;
				_device += d;
				++it;
				if (it == end || (*it != '\\' && *it != '/')) throw std::exception();
				++it;
			}
			else --it;
		}
		while (it != end)
		{
			std::string name;
			while (it != end && *it != '\\' && *it != '/') name += *it++;
			if (it != end)
				pushDirectory(name);
			else
				_name = name;
			if (it != end) ++it;
		}
	}
	if (!_node.empty() && _dirs.empty() && !_name.empty())
		makeDirectory();
}
Exemplo n.º 17
0
void errorReporterInitialize(ErrorReporter self) {
  CharString infoText = newCharStringWithCString(kErrorReportInfoText);
  CharString wrappedInfoText;
  time_t now;
  size_t length;
  size_t i;

  printf("=== Starting error report ===\n");
  wrappedInfoText = charStringWrap(infoText, 0);
  // The second newline here is intentional
  printf("%s\n", wrappedInfoText->data);

  time(&now);
  self->started = true;

  snprintf(self->reportName->data, self->reportName->capacity,
    "MrsWatson Report %s", ctime(&now));
  // Trim the final newline character from this string if it exists
  length = strlen(self->reportName->data);
  if(self->reportName->data[length - 1] == '\n') {
    self->reportName->data[length - 1] = '\0';
    length--;
  }
  for(i = 0; i < length; i++) {
    if(!charStringIsLetter(self->reportName, i) ||
        charStringIsNumber(self->reportName, i)) {
      self->reportName->data[i] = '-';
    }
  }

 #if UNIX
  snprintf(self->desktopPath->data, self->desktopPath->capacity,
    "%s/Desktop", getenv("HOME"));
#elif WINDOWS
  SHGetFolderPathA(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0, self->desktopPath->data);
#endif
  snprintf(self->reportDirPath->data, self->reportDirPath->capacity,
    "%s%c%s", self->desktopPath->data, PATH_DELIMITER, self->reportName->data);
  makeDirectory(self->reportDirPath);

  freeCharString(wrappedInfoText);
  freeCharString(infoText);
}
Exemplo n.º 18
0
void NoiseMatrixLayerGraphs(TString myFileName, int nDDU, int nCham, int nLayer){
  //gSystem->cd("images/NoiseMatrix");
  //gSystem->cd(myFileName);

int nElements = 12;
TH2F *noiseGraph;
TCanvas *noiseCanv;
 for (int i=0; i< nDDU; ++i){
   int idArray[9];
   GetChamberIDs(idArray);
   //   Float_t BoundsMinArray[108];
   //   Float_t BoundsMaxArray[108];
   Float_t BoundsChamMin[9];
   Float_t BoundsChamMax[9];
   //GetNoiseBounds(BoundsMinArray, BoundsMaxArray, BoundsChamMin, BoundsChamMax);
   GetNoiseBounds(BoundsChamMin, BoundsChamMax, nCham);
   for (int j=0; j<nCham; ++j){
     TString ChamDirecName = Form("Chamber_%d_Layer_Graphs", idArray[j]);
     makeDirectory(ChamDirecName); 
     gSystem->cd(ChamDirecName); 
     for (int l=0; l<nLayer; ++l){ 
       TString NoiseCanvName = Form ("Noise_Matrix_Elements_Chamber_%d_Layer_%d",idArray[j],l); 
       noiseCanv = new TCanvas(NoiseCanvName, NoiseCanvName,200,10,1200,800); 
       noiseCanv->Divide(4,3); 
       noiseCanv->Draw(); 
       for (int k=0; k<nElements; ++k){  
	 TString ElementGraphName = Form("Element_%d",k); 
	 noiseGraph = new TH2F(ElementGraphName,ElementGraphName,80,0,80,20,BoundsChamMin[j],BoundsChamMax[j]);  
	 noiseCanv->cd(k+1); 
	 noiseGraph->Draw(); 
	 TString GraphForm = Form("elem[%d]:strip", k); 
	 TString GraphCut = Form("cham==%d&&layer==%d", j, l); 
	 Calibration->Project(ElementGraphName, GraphForm, GraphCut); 
       }//nElements 
       noiseCanv->Update();    
       PrintAsGif(noiseCanv, NoiseCanvName); 
     }//nLayer
     gSystem->cd("../");
   }//nCham 
 }//nDDU 
gSystem->cd("../../../"); 
directoryCheck(); 
}//NoiseMatrixGraphs 
Exemplo n.º 19
0
static CharString _fileUtilitiesMakeTempDir(void) {
  CharString tempDirName = newCharString();
#if UNIX
  snprintf(tempDirName->data, tempDirName->capacity, "/tmp/mrswatsontest-XXXXXX");
  mktemp(tempDirName->data);
#elif WINDOWS
  CharString systemTempDir = newCharString();
  CharString randomDirName = newCharString();
  snprintf(randomDirName->data, randomDirName->capacity, "mrswatsontest-%d", rand());
  GetTempPathA(systemTempDir->capacity, systemTempDir->data);
  buildAbsolutePath(systemTempDir, randomDirName, NULL, tempDirName);
  freeCharString(systemTempDir);
  freeCharString(randomDirName);
#endif
  if(!makeDirectory(tempDirName)) {
    fprintf(stderr, "WARNING: Could not make temporary directory\n");
    return NULL;
  }
  return tempDirName;
}
QLogSystem::QLogSystem() : m_nExpire(15)
{
    m_Time = QDateTime::currentDateTime();
    QString strDocuments = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);

    strDocuments = rstrip( strDocuments, "/\\" );

    m_strRootPath = strDocuments;
    m_strRootPath += "/T3kCfgFE/Logs";

    makeDirectory(m_strRootPath);

    QString strLogPathName;
    getLogPathName( m_Time, strLogPathName );
    openLogFile( strLogPathName );

    deleteExpiredLogFiles();

    write( "INFO", ("==== T3kCfgFE Start! ====") );
    write( "INFO", "Exec Path: %s", (const char*)qApp->applicationFilePath().toUtf8() );
}
Exemplo n.º 21
0
bool HelloWorld::convert(string filePath)
{
    if (filePath =="")
        return false;
    
    size_t pos = filePath.find("file://");
    if (pos != string::npos){
        filePath = filePath.substr (pos+7);
    }
    
    Magick::Image masterImage(filePath);
    
    if (!masterImage.isValid()){
        return false;
    }
    
    showPreview(masterImage);
    
    
    string saveFolder = getFolder(filePath) + "/IconResized/" ;
    makeDirectory(saveFolder);
    
    string openDir;
    
    typedef map<string, string>::iterator it_type;
    for(it_type iterator = sizes.begin(); iterator != sizes.end(); iterator++) {
        // iterator->first = key
        // iterator->second = value
        // Repeat if you also want to iterate through the second map.
        string savePath = saveFolder + iterator->second;
        
        openDir = savePath;
        resizeAndWriteImage(masterImage, savePath, iterator->first);
    }
    
    openSavedFolder(openDir);
    
    return true;
}
Exemplo n.º 22
0
Path& Path::parseDirectory(const std::string& path, Style style)
{
	assign(path, style);
	return makeDirectory();
}
Exemplo n.º 23
0
Path& Path::parseDirectory(const std::string& path)
{
	assign(path);
	return makeDirectory();
}
Exemplo n.º 24
0
int stmd_RuleEntSelect(int time_type, int duration, char *table_type)
{
    char        condBuf[4096], tmpBuf[1024];
    int         sts_code;
    char        str_time[10];

    char        query[4096], query_head[4096]; 
    MYSQL_RES   *result;
    MYSQL_ROW   row;

    time_t      now;
    char        tm[DIR_NUM][8];
    char        path[60];
    char        fileName[60];
    FILE        *fp;

    int         i;
	char title[4][16] = {"SYSTEM", "ITEM", "Session", "Block"};
	char title1[5][16] = {"", "", "UpStream(Mbps)", "DnStream(Mbps)", "Total(Mbps)"};
	char title2[5][16] = {"", "", "UpByte(MBytes)", "DnByte(MBytes)", "Total(MBytes)"};

    int row_index;
    char SysName[2][8];
    int realSysCnt =0;
    int realItemCnt =0, row_cnt=0 ;

	int     snd_cnt = 1;


    now = time(0);
    if(time_type != STMD_WEEK)
        now = now - (printTIME[time_type]*60) - STAT_OFFSET_UNIT;
    else
        now = now - (printTIME[time_type]*60);

    getFilePath (path, tm, &now); // ~/LOG/STAT 까지 만든다.
    makeDirectory (time_type,path,tm);

    sprintf(fileName, "%s", path );
    makeFileName ( fileName, STMD_RULE_ENT, time_type, tm );

    if ( ( fp = fopen(fileName, APPEND ) ) == NULL )
	{
        sprintf(trcBuf, "%s Open Fail\n", fileName);
        trclib_writeLog(FL, trcBuf);
        return -1;
    }

	//char title[4][16] = {"SYSTEM", "ITEM", "Session", "Block"};
	//char title1[5][16] = {"", "", "UpStream(Mbps)", "DnStream(Mbps)", "Total(Mbps)"};
	//char title2[5][16] = {"", "", "UpByte(MBytes)", "DnByte(MBytes)", "Total(MBytes)"};
    switch (time_type) {
        case    STMD_HOUR :
            sts_code = STSCODE_STM_PERIODIC_RULEENT_HOUR;
            sprintf(str_time, "%s", STMD_STR_HOUR);
			sprintf(query_head, "SELECT record_source, rule_ent_id, rule_ent_name, "
					" IFNULL(SUM(session),0), IFNULL(SUM(block_cnt),0), "
					" ROUND(IFNULL(SUM(upstream_volume)*8/1024/1024/3600,0),3), "
					" ROUND(IFNULL(SUM(downstream_volume)*8/1024/1024/3600,0),3), "
					" ROUND((IFNULL(SUM(upstream_volume),0) + IFNULL(SUM(downstream_volume),0))*8/1024/1024/3600,3), "
					" ROUND(IFNULL(SUM(upstream_volume)/1024/1024 ,0),3), "
					" ROUND(IFNULL(SUM(downstream_volume)/1024/1024 ,0),3), "
					" ROUND((IFNULL(SUM(upstream_volume),0) + IFNULL(SUM(downstream_volume),0))/1024/1024,3) "
                	" from %s ", table_type);
            break;
        case    STMD_DAY :
            sts_code = STSCODE_STM_PERIODIC_RULEENT_DAY;
            sprintf(str_time, "%s", STMD_STR_DAY);
			sprintf(query_head, "SELECT record_source, rule_ent_id, rule_ent_name, "
					" IFNULL(SUM(session),0), IFNULL(SUM(block_cnt),0), "
					" ROUND(IFNULL(SUM(upstream_volume)*8/1024/1024/86400,0),3), "
					" ROUND(IFNULL(SUM(downstream_volume)*8/1024/1024/86400,0),3), "
					" ROUND((IFNULL(SUM(upstream_volume),0) + IFNULL(SUM(downstream_volume),0))*8/1024/1024/86400,3), "
					" ROUND(IFNULL(SUM(upstream_volume)/1024/1024 ,0),3), "
					" ROUND(IFNULL(SUM(downstream_volume)/1024/1024 ,0),3), "
					" ROUND((IFNULL(SUM(upstream_volume),0) + IFNULL(SUM(downstream_volume),0))/1024/1024,3) "
                	" from %s ", table_type);
            break;
        case    STMD_WEEK :
            sts_code = STSCODE_STM_PERIODIC_RULEENT_WEEK;
            sprintf(str_time, "%s", STMD_STR_WEEK);
			sprintf(query_head, "SELECT record_source, rule_ent_id, rule_ent_name, "
					" IFNULL(SUM(session),0), IFNULL(SUM(block_cnt),0), "
					" ROUND(IFNULL(SUM(upstream_volume)*8/1024/1024/86400*7,0),3), "
					" ROUND(IFNULL(SUM(downstream_volume)*8/1024/1024/86400*7,0),3), "
					" ROUND((IFNULL(SUM(upstream_volume),0) + IFNULL(SUM(downstream_volume),0))*8/1024/1024/86400*7,3), "
					" ROUND(IFNULL(SUM(upstream_volume)/1024/1024 ,0),3), "
					" ROUND(IFNULL(SUM(downstream_volume)/1024/1024 ,0),3), "
					" ROUND((IFNULL(SUM(upstream_volume),0) + IFNULL(SUM(downstream_volume),0))/1024/1024,3) "
                	" from %s ", table_type);
            break;
        case    STMD_MONTH :
            sts_code = STSCODE_STM_PERIODIC_RULEENT_MONTH;
            sprintf(str_time, "%s", STMD_STR_MONTH);
			sprintf(query_head, "SELECT record_source, rule_ent_id, rule_ent_name, "
					" IFNULL(SUM(session),0), IFNULL(SUM(block_cnt),0), "
					" ROUND(IFNULL(SUM(upstream_volume)*8/1024/1024/86400*30,0),3), "
					" ROUND(IFNULL(SUM(downstream_volume)*8/1024/1024/86400*30,0),3), "
					" ROUND((IFNULL(SUM(upstream_volume),0) + IFNULL(SUM(downstream_volume),0))*8/1024/1024/86400*30,3), "
					" ROUND(IFNULL(SUM(upstream_volume)/1024/1024 ,0),3), "
					" ROUND(IFNULL(SUM(downstream_volume)/1024/1024 ,0),3), "
					" ROUND((IFNULL(SUM(upstream_volume),0) + IFNULL(SUM(downstream_volume),0))/1024/1024,3) "
                	" from %s ", table_type);
            break;
    }

    sprintf(condBuf,"    %s %s\n    S%04d RULE ENTRY PERIODIC STATISTICS MESSAGE\n",
        "SCE", // 현재는 OMP로 고정하지만 실질적인 시스템 이름으로 변경 필요 hslim_oper
        commlib_printTStamp(), // 현재시각 time stamp (년,월,일,시,분,초,요일)
        sts_code);

    sprintf(tmpBuf, "    PERIOD = %s\n    MEASURETIME = %s  -  %s\n\n",
        str_time,
        get_period_start_time(time_type), get_period_end_time(time_type));
    strcat(condBuf,tmpBuf);

	sprintf(tmpBuf, "    =======================================================================================\n");
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %6s %-38s %-15s %-15s \n","",title[0],title[1],title[2],title[3]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %6s %-38s %-15s %-15s %-15s\n","","","",title1[2],title1[3],title1[4]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %6s %-38s %-15s %-15s %-15s\n","","","",title2[2],title2[3],title2[4]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "    =======================================================================================\n");
	strcat(condBuf, tmpBuf);

    for(i=0; i<SCE_CNT; i++ )
	{
        sprintf(SysName[i], "%s", g_stSCE[i].sce_name);
        realSysCnt++;
    }

    for(i = 0; i < realSysCnt; i++)
	{
		realItemCnt = g_stSCEEntry[i].ruleEntryCnt;

        sprintf(query, "%s  "
                " where record_source = '%s' AND (stat_date = '%s') "
				" group by record_source, rule_ent_id, rule_ent_name "
				" order by record_source, rule_ent_id, rule_ent_name ", query_head,
            	SysName[i], get_period_select_time(time_type));

		logPrint(trcLogId, FL, "periodic query: %s \n",query);

        if ( trcLogFlag == TRCLEVEL_SQL ) 
		{
            sprintf(trcBuf, "query = %s\n", query);
            trclib_writeLog(FL, trcBuf);
        }

		if (stmd_mysql_query (query) < 0) {
            sprintf(trcBuf,">>> mysql_query fail; query:%s, err=%s\n", query,mysql_error(conn));
            trclib_writeLogErr (FL,trcBuf);
            if(fp != NULL) fclose(fp);
            return -1;
        }

        row_cnt = 0;                                                                                              
        result = mysql_store_result(conn);
        while( (row = mysql_fetch_row(result)) != NULL)
		{
			row_index = 3;

			if(strlen(condBuf) > 3000) {
	            strcat(condBuf, "\nCONTINUE\n");
				stmd_txMsg2Cond (condBuf, (sts_code - STSCODE_TO_MSGID_STATISTICS), 1, snd_cnt++);
        		fprintf (fp, "%s",condBuf);
				memset(condBuf, 0x00, sizeof(condBuf));
			}

			if( row_cnt == 0 )
			{
				sprintf(tmpBuf, "%3s %6s %-38s %-15s %-15s \n",
						"", row[0], row[2], row[row_index],row[row_index+1]);
				strcat(condBuf, tmpBuf);
			}
			else
			{
				sprintf(tmpBuf, "%3s %6s %-38s %-15s %-15s\n",
						"","", row[2], row[row_index],row[row_index+1]);
				strcat(condBuf, tmpBuf);
			}
			if(strlen(condBuf) > 3000) {
	            strcat(condBuf, "\nCONTINUE\n");
				stmd_txMsg2Cond (condBuf, (sts_code - STSCODE_TO_MSGID_STATISTICS), 1, snd_cnt++);
        		fprintf (fp, "%s",condBuf);
				memset(condBuf, 0x00, sizeof(condBuf));
			}

            sprintf(tmpBuf, "%3s %6s %-28s %15s %15s %15s\n",
                    "", "", "", row[row_index+2], row[row_index+3], row[row_index+4] );
            strcat(condBuf, tmpBuf);                                             

			if(strlen(condBuf) > 3000) {
	            strcat(condBuf, "\nCONTINUE\n");
				stmd_txMsg2Cond (condBuf, (sts_code - STSCODE_TO_MSGID_STATISTICS), 1, snd_cnt++);
        		fprintf (fp, "%s",condBuf);
				memset(condBuf, 0x00, sizeof(condBuf));
			}

            sprintf(tmpBuf, "%3s %6s %-28s %15s %15s %15s\n",
                    "", "", "", row[row_index+5], row[row_index+6], row[row_index+7] );
            strcat(condBuf, tmpBuf);                                             

		
			if(strlen(condBuf) > 3000) {
	            strcat(condBuf, "\nCONTINUE\n");
				stmd_txMsg2Cond (condBuf, (sts_code - STSCODE_TO_MSGID_STATISTICS), 1, snd_cnt++);
        		fprintf (fp, "%s",condBuf);
				memset(condBuf, 0x00, sizeof(condBuf));
			}
			row_cnt++;
        }
        mysql_free_result(result);

		// ?????
		// 여기는 수행되면 안됨. 5분 통계에서 이미 다 들어 가있음. 
#if 0
        if( row_cnt == 0 ) // no query result set
        {
            for( j = 0; j < realItemCnt; j++ )
            {
				if( g_stSCEEntry[i].stEntry[j].real == 1 && g_stSCEEntry[i].stEntry[j].eName != NULL )
				{
					if( j == 0 )
					{
						sprintf(tmpBuf, "%3s %6s %-38s %-15s %-15s\n",
								"", SysName[i], g_stSCEEntry[i].stEntry[j].eName, "0","0","0");
						strcat(condBuf, tmpBuf);
						sprintf(tmpBuf, "%3s %6s %-38s %-15s %-15s %-15s\n",
								"", "", "", "0.000","0.000","0.000");
						strcat(condBuf, tmpBuf);                                                             
						sprintf(tmpBuf, "%3s %6s %-38s %-15s %-15s %-15s\n",
								"", "", "", "0","0","0");
						strcat(condBuf, tmpBuf);
						sprintf(tmpBuf, "    --------------------------------------------------------------------------------------\n");
						strcat(condBuf, tmpBuf);
					}
					else
					{
						sprintf(tmpBuf, "%3s %6s %-38s %-15s %-15s\n",
								"", "", g_stSCEEntry[i].stEntry[j].eName, "0","0","0");
						strcat(condBuf, tmpBuf);
						sprintf(tmpBuf, "%3s %6s %-38s %-15s %-15s %-15s\n",
								"", "", "", "0.000","0.000","0.000");
						strcat(condBuf, tmpBuf);                                                             
						sprintf(tmpBuf, "%3s %6s %-38s %-15s %-15s %-15s\n",
								"", "", "", "0","0","0");
						strcat(condBuf, tmpBuf);
						sprintf(tmpBuf, "    ---------------------------------------------------------------------------------------\n");
					}
				}
				if(strlen(condBuf) > 3000) {
					stmd_cron_txMsg2Cond (condBuf, (sts_code - STSCODE_TO_MSGID_STATISTICS), 1, snd_cnt);
        			fprintf (fp, "%s",condBuf);
					sprintf(condBuf, "");
				}
            }
        }
#endif

		sprintf(tmpBuf, "    =======================================================================================\n");
		strcat(condBuf, tmpBuf);

    }

    sprintf(tmpBuf, "    COMPLETED\n\n\n");
    strcat(condBuf, tmpBuf);

    if(fp != NULL) 
	{
        fprintf (fp, "%s",condBuf);
        fclose(fp);
    }
    
    stmd_txMsg2Cond(condBuf, (sts_code - STSCODE_TO_MSGID_STATISTICS), 0, snd_cnt);
    
    return 1;
}
Exemplo n.º 25
0
void  readKeyboard(void)
{
	struct dir_node *currentNode;
	unsigned char key;
	bool decision = false;

	key = toupper(cgetc());

	switch((int)key)
	{
	case HK_FORMATTER:
		if(loadOverlay(7))
		{
			formatDisk(selectedPanel);

			clrscr();
			writeMenuBar();
			reloadPanels();
		}
		break;
	case HK_BASIC_VIEWER:
		if(loadOverlay(6))
		{
			viewFileAsBASIC(selectedPanel);

			clrscr();
			writeMenuBar();
			reloadPanels();
		}
		break;
	case HK_HEX_EDIT:
		if(loadOverlay(5))
		{
			hexEditCurrentFile(selectedPanel);

			clrscr();
			writeMenuBar();
			reloadPanels();
		}
		break;

	case CH_ENTER:
		currentNode = getSelectedNode(selectedPanel);
		if(isDirectory(selectedPanel))
		{
			enterDirectory(selectedPanel);
		}
		else if(currentNode != NULL)
		{
			sprintf(filePath, "%s/%s", selectedPanel->path, currentNode->name);
			if(currentNode->type == 0x06
				|| currentNode->type == 0xFF)
			{
				saveScreen();
				decision = writeYesNo("Confirm", quit_message, 1);
				retrieveScreen();

				if(decision == true)
				{
					exec(filePath, NULL);
				}
			}
			else if(currentNode->type == 0xFC)
			{
				if(loadOverlay(6))
				{
					viewFileAsBASIC(selectedPanel);

					clrscr();
					writeMenuBar();
					reloadPanels();
				}
			}
			else
			{
				if(loadOverlay(1))
					viewFile(filePath);
			}
		}
		break;
	case KEY_F4:
		rereadSelectedPanel();
		break;
	case KEY_F3:
		selectDrive(selectedPanel);
		rereadSelectedPanel();
		break;
	case HK_SELECT:
		selectCurrentFile();
		break;
#ifdef __APPLE2ENH__
		case CH_CURS_UP:
#else
		case CH_CURS_LEFT:
#endif
		moveSelectorUp(selectedPanel);
		break;
#ifdef __APPLE2ENH__
		case CH_CURS_DOWN:
#else
		case CH_CURS_RIGHT:
#endif
		moveSelectorDown(selectedPanel);
		break;
#ifdef __APPLE2ENH__
	case CH_CURS_LEFT:
		if(selectedPanel == &rightPanelDrive
			&& strlen(leftPanelDrive.path) > 0)
		{
			selectedPanel = &leftPanelDrive;
			writeSelectorPosition(&leftPanelDrive, '>');
			writeSelectorPosition(&rightPanelDrive, ' ');
			writeCurrentFilename(selectedPanel);
		}
		break;
	case CH_CURS_RIGHT:
		if(selectedPanel == &leftPanelDrive
			&& strlen(rightPanelDrive.path) > 0)
		{
			selectedPanel = &rightPanelDrive;
			writeSelectorPosition(&leftPanelDrive, ' ');
			writeSelectorPosition(&rightPanelDrive, '>');
			writeCurrentFilename(selectedPanel);
		}
		break;
#endif
	case HK_SWITCH_PANEL:
		if(selectedPanel == &leftPanelDrive
			&& strlen(rightPanelDrive.path) > 0)
		{
			selectedPanel = &rightPanelDrive;
			writeSelectorPosition(&leftPanelDrive, ' ');
			writeSelectorPosition(&rightPanelDrive, '>');
			writeCurrentFilename(selectedPanel);
		}
		else if(selectedPanel == &rightPanelDrive
			&& strlen(leftPanelDrive.path) > 0)
		{
			selectedPanel = &leftPanelDrive;
			writeSelectorPosition(&leftPanelDrive, '>');
			writeSelectorPosition(&rightPanelDrive, ' ');
			writeCurrentFilename(selectedPanel);
		}
		break;

	case KEY_SH_PLUS:
		enterDirectory(selectedPanel);
		break;
	case KEY_SH_MINUS:
	case CH_ESC:
		leaveDirectory(selectedPanel);
		break;
	//case 188: // C= C - Command Menu
	//	writeMenu(command);
	//	break;
	//case 182: // C= L - Left Menu
	//	writeMenu(left);
	//	break;
	//case 178: // C= R - Right Menu
	//	writeMenu(right);
	//	break;
	//case 187: // C= F - File Menu
	//	writeMenu(file);
	//	break;
	//case 185: // C= O - Options Menu
	//	writeMenu(options);
	//	break;
	case HK_REREAD_LEFT:
		rereadDrivePanel(left);
		break;
	case HK_REREAD_RIGHT:
		rereadDrivePanel(right);
		break;
	case HK_DRIVE_LEFT:
		writeDriveSelectionPanel(left);
		break;
	case HK_DRIVE_RIGHT:
		writeDriveSelectionPanel(right);
		break;
	case HK_SELECT_ALL:
		selectAllFiles(selectedPanel, true);
		break;
	case HK_DESELECT_ALL:
		selectAllFiles(selectedPanel, false);
		break;
	case KEY_F1:
		if(loadOverlay(1))
			writeHelpPanel();
		break;
	case KEY_F2:
		quit();
		break;
	case KEY_F5:
		if(loadOverlay(4))
			copyFiles();
		break;
	case HK_RENAME:
	case KEY_F6:
		if(loadOverlay(4))
			renameFile();
		break;
	case HK_DELETE:
	case KEY_F8:
		if(loadOverlay(4))
			deleteFiles();
		break;
	//case KEY_AT:
	//	inputCommand();
	//	break;
	case KEY_F7:
		if(loadOverlay(4))
			makeDirectory();
		break;
	case HK_TO_TOP:
		moveTop(selectedPanel);
		break;
	case HK_TO_BOTTOM:
		moveBottom(selectedPanel);
		break;
	case HK_PAGE_UP:
		movePageUp(selectedPanel);
		break;
	case HK_PAGE_DOWN:
		movePageDown(selectedPanel);
		break;
	case HK_WRITE_DISK_IMAGE:
		if(loadOverlay(3))
			writeDiskImage();
		break;
	case HK_CREATE_DISK_IMAGE:
		if(loadOverlay(3))
			createDiskImage();
		break;
	case HK_COPY_DISK:
		if(loadOverlay(2))
			copyDisk();
		break;
	default:
		//writeStatusBarf("%c", key);
		break;
	}
}
Exemplo n.º 26
0
int stmd_LoadSelect(int time_type, char *table_type)
{
    char        condBuf[4096], tmpBuf[1024];
    int         sts_code;
    char        str_time[10];
    int         select_cnt = 0;

    char        query[4096];
    MYSQL_RES   *result;
    MYSQL_ROW   row;

    time_t      now;
    char        tm[DIR_NUM][8];
    char        path[60];
    char        fileName[60];
    FILE        *fp;

    char        itemRes[8][10];
    int         i,j;
//    char *title[]={"CPU","MEM","DISK","QUEUE","SESS"};
    char *title[]={"CPU","MEM","HW","QUEUE"};
    int row_index;
    char SysName[5][8];
    int realSysCnt =0;
    int realItemCnt =0;

    for(i=0; i<sysCnt; i++ ){
        sprintf(SysName[i], "%s", StatisticSystemInfo[i].sysName);
        realSysCnt++;
    }
/* 10.13 TAP REMOVE
    sprintf(SysName[realSysCnt], "TAPA");realSysCnt++;
    sprintf(SysName[realSysCnt], "TAPB");realSysCnt++;
*/
    sprintf(SysName[realSysCnt], "SCEA");realSysCnt++;
    sprintf(SysName[realSysCnt], "SCEB");realSysCnt++;


    now = time(0);
    if(time_type != STMD_WEEK)
        now = now - (printTIME[time_type]*60) - STAT_OFFSET_UNIT;
    else
        now = now - (printTIME[time_type]*60);

    getFilePath (path, tm, &now); // ~/LOG/STAT 까지 만든다.
    makeDirectory (time_type,path,tm);

    sprintf(fileName, "%s", path );
    makeFileName ( fileName, STMD_LOAD, time_type, tm );

    if ( ( fp = fopen(fileName, APPEND ) ) == NULL ){
        sprintf(trcBuf, "%s Open Fail\n", fileName);
        trclib_writeLog(FL, trcBuf);
        return -1;
    }


    switch (time_type) {
        case    STMD_HOUR :
            sts_code = STSCODE_STM_PERIODIC_LOAD_HOUR;
            sprintf(str_time, "%s", STMD_STR_HOUR);
            break;
        case    STMD_DAY :
            sts_code = STSCODE_STM_PERIODIC_LOAD_DAY;
            sprintf(str_time, "%s", STMD_STR_DAY);
            break;
        case    STMD_WEEK :
            sts_code = STSCODE_STM_PERIODIC_LOAD_WEEK;
            sprintf(str_time, "%s", STMD_STR_WEEK);
            break;
        case    STMD_MONTH :
            sts_code = STSCODE_STM_PERIODIC_LOAD_MONTH;
            sprintf(str_time, "%s", STMD_STR_MONTH);
            break;
    }

    sprintf(condBuf,"    %s %s\n    S%04d LOAD PERIODIC STATISTICS MESSAGE\n",
        //"BSDM", // 현재는 OMP로 고정하지만 실질적인 시스템 이름으로 변경 필요 hslim_oper
        "DSCM", // 현재는 OMP로 고정하지만 실질적인 시스템 이름으로 변경 필요 hslim_oper
        commlib_printTStamp(), // 현재시각 time stamp (년,월,일,시,분,초,요일)
        sts_code);

    sprintf(tmpBuf, "    PERIOD = %s\n    MEASURETIME = %s  -  %s\n\n",
        str_time,
        get_period_start_time(time_type), get_period_end_time(time_type));
    strcat(condBuf,tmpBuf);

    sprintf(tmpBuf, "    ==================================\n");
    strcat(condBuf, tmpBuf);
    sprintf(tmpBuf, "    SYSTEM    ITEM    AVG(%%)    MAX(%%)\n");
    strcat(condBuf, tmpBuf);
    sprintf(tmpBuf, "    ==================================\n");
    strcat(condBuf, tmpBuf);

    for(i = 0; i < realSysCnt; i++){

        //if(!strcasecmp(SysName[i], "BSDM"))
        if(!strcasecmp(SysName[i], "DSCM"))
            realItemCnt=4;
/* 10.13 TAP REMOVE
        else if(!strcasecmp(SysName[i], "TAPA") || !strcasecmp(SysName[i], "TAPB"))
            realItemCnt=3;
*/
		else if(!strcasecmp(SysName[i], "SCEA") || !strcasecmp(SysName[i], "SCEB"))
            realItemCnt=3;
        else
            realItemCnt=4;
//            realItemCnt=5;

        sprintf(query, "SELECT "
                " IFNULL(AVG(avr_cpu0), 0), IFNULL(MAX(max_cpu0), 0)," 
                " IFNULL(AVG(avr_memory), 0), IFNULL(MAX(max_memory), 0)," 
                " IFNULL(AVG(avr_disk), 0), IFNULL(MAX(max_disk), 0)," 
                " IFNULL(AVG(avr_msgQ), 0), IFNULL(MAX(max_msgQ), 0) " 
           //     " IFNULL(AVG(avr_sess), 0), IFNULL(MAX(max_sess), 0)" 
                " from %s "
                " where system_name = '%s' AND (stat_date = '%s')",
            table_type, SysName[i], get_period_select_time(time_type));

        if ( trcLogFlag == TRCLEVEL_SQL ) {
            sprintf(trcBuf, "query = %s\n", query);
            trclib_writeLog(FL, trcBuf);
        }
		if (stmd_mysql_query (query) < 0) {
            sprintf(trcBuf,">>> mysql_query fail; err=%s\n", mysql_error(conn));
            trclib_writeLogErr (FL,trcBuf);
            if(fp != NULL) fclose(fp);
            return -1;
        }

        result = mysql_store_result(conn);
        while((row = mysql_fetch_row(result)) != NULL) 
		{
//            for(j=0; j < 10; j++)
            for(j=0; j < 8; j++)
			{ // SESS는 그댜로 출력 하자. add by helca 080930
                strcpy(itemRes[j], row[j]);
				sprintf(itemRes[j], "%d.%d", atoi(itemRes[j])/10, atoi(itemRes[j])%10); 
				/** session delete 0608
				if(j<8)
					sprintf(itemRes[j], "%d.%d", atoi(itemRes[j])/10, atoi(itemRes[j])%10); 
				else
					sprintf(itemRes[j], "%d", atoi(itemRes[j]));
				*/
            }

            row_index = 0;
            for(j=0; j < realItemCnt; j++)
			{
                if (j==0)
				{
                    sprintf(tmpBuf, "%3s %-9s %-5s %8s %9s\n", 
                        "", SysName[i], title[j], itemRes[row_index],itemRes[row_index+1]);
                    strcat(condBuf, tmpBuf);
                } 
				else 
				{
                    sprintf(tmpBuf, "%3s %-9s %-5s %8s %9s\n", 
                        "", "", title[j], itemRes[row_index],itemRes[row_index+1]);
                    strcat(condBuf, tmpBuf);
                }

                row_index += 2;
            }
            sprintf(tmpBuf, "    ==================================\n");
            strcat(condBuf, tmpBuf);

            select_cnt++;
        }
        mysql_free_result(result);

        if (select_cnt == 0) 
		{
            for(j=0; j < realItemCnt; j++)
			{
                if (j==0)
				{
                    sprintf(tmpBuf, "%3s %-9s %-5s %8s %9s\n", 
                        "", SysName[i], title[j], "0.0", "0.0");
                    strcat(condBuf, tmpBuf);
                }
				else 
				{
                    sprintf(tmpBuf, "%3s %-9s %-5s %8s %9s\n", 
                        "", "", title[j], "0.0", "0.0");
                    strcat(condBuf, tmpBuf);
                }
            }
            sprintf(tmpBuf, "    ==================================\n");
            strcat(condBuf, tmpBuf);
        } 
    }

    sprintf(tmpBuf, "    COMPLETED\n\n\n");
    strcat(condBuf, tmpBuf);

    if(fp != NULL) 
	{
        fprintf (fp, "%s",condBuf);
        fclose(fp);
    }
    
    stmd_txMsg2Cond(condBuf, (sts_code - STSCODE_TO_MSGID_STATISTICS), 0, 1);
    
    return 1;
}
Exemplo n.º 27
0
void loop_SHELL()
{
	FILE* _io_=fopen("commands.txt","a+");
	
	realpath("commands.txt", history_file_path);
	
   	while(1)
	{
		char cwd[MAX_SIZE];
		char buf[MAX_SIZE];

		FILE* _out_;

		if(getcwd(cwd, MAX_SIZE) != NULL)
		printf(" %s > ",cwd);
		
		else{
			printf("Command Prompt error ! Terminating...\n ");
			exit(1);
		}

		if(fgets(buf, MAX_SIZE, stdin)==NULL)
			continue;

		if(strlen(buf)<=1)
			continue;

		if(updateHistory(buf)==-1)
			printf("Trouble updating History !\n");

		char **args = (char**)malloc(MAX_SIZE*sizeof(char*));

		char** p =args;

		*p=strtok(buf, " \t\n");

		while(*p!=NULL)
		{
			p++;
			*p=strtok(NULL, " \t\n");
		}

		if(args==NULL)
			continue;

		if(strcmp(args[0],"clear")==0 && args[1]==NULL)
			clrscreen();

		else if(strcmp(args[0],"ls")==0)
			listContents(args[1]);

		else if(strcmp(args[0],"env")==0 && args[1]==NULL)
			showEnvironmentVariables();

		else if(strcmp(args[0],"exit")==0 && args[1]==NULL)
			exit(0);

		else if(strcmp(args[0],"pwd")==0 && args[1]==NULL)
		{
			if (showWorkingDirectory() == -1)
				printf("Error showing current directory !\n");
		}

		else if(strcmp(args[0],"cd")==0)
		{
			if(changeDirectory(args[1])==-1)
				printf("ERROR : No such directory exists!\n");
		}
		
		else if(strcmp(args[0],"mkdir")==0)
		{
			if(args[1]==NULL)
				printf("Invalid Command ! Please enter : \n mkdir <dir_name>\n");
			else if(makeDirectory(args[1])==-1)
				printf("ERROR in creating directory !\n");
		}

		else if(strcmp(args[0],"rmdir")==0)
		{
			if(args[1]==NULL)
				printf("Invalid Command ! Please enter : \n rmdir <dir_name>\n");
			else if(removeDirectory(args[1])==-1)
				printf("ERROR in deleting directory !\n");
		}

		else if(strcmp(args[0],"history")==0)
		{
			if(showHistory(args[1])==-1)
				printf("ERROR ! Trouble showing history !\n");
		}
		
		else executeCommand(args);
	}

}
Exemplo n.º 28
0
LOGGER *logInitLogger (char *name, int facility, int options, int verbosity, char *logPath,
			char *logName, long rollOverSize, long bufferSize) {

	LOGGER 		*pl;
	int		i;
	struct stat	sb;

	if ((logPath == NULL) || (logPath[0] == '\0')) {
		fprintf (stderr, "ERROR: %s - Invalid logPath passed\n", __FUNCTION__);
		return NULL;
	}

	if ((logName == NULL) || (logName[0] == '\0')) {
		fprintf (stderr, "ERROR: %s - Invalid logName passed\n", __FUNCTION__);
		return NULL;
	}

	if ((facility < F_MIN) || (facility > F_MAX)) {
		fprintf (stderr, "ERROR: %s - Unknown facility %d\n", __FUNCTION__, facility);
		return NULL;
	}

	if (facility != F_FILE) {
		fprintf (stderr, "ERROR: %s - The only facility current supported is F_FILE (%d)\n",
			__FUNCTION__, F_FILE);
		return NULL;
	}

	if ((options & O_FLUSH_AFTER_EACH) && (options & O_TIMED_FLUSH)) {
		fprintf (stderr, "ERROR: %s - O_FLUSH_AFTER_EACH and O_TIMED_FLUSH cannot both be set\n",
			__FUNCTION__);
		return NULL;
	}

	verbosity = (verbosity < V_MIN) ? V_MIN : verbosity;
	verbosity = (verbosity > V_MAX) ? V_MAX : verbosity;

	if (loggerStore.count == 0) {
		i = 0;
		if ((loggerStore.loggers = (LOGGER **) malloc (sizeof (LOGGER *))) == NULL) {
			fprintf (stderr, "ERROR: %s - Could not malloc space for loggerStore array\n", __FUNCTION__);
			return NULL;
		}

		if ((loggerStore.loggers[0] = (LOGGER *) malloc (sizeof (LOGGER))) == NULL) {
			fprintf (stderr, "ERROR: %s - Could not malloc space for logger node\n", __FUNCTION__);
			return NULL;
		}
	} else {	/* Try to find an allocated logger that's not being used */
		for (i = 0; i < loggerStore.count; i++) {
			if (!(loggerStore.loggers[i]->optionMask & NODE_IN_USE)) {
				break;
			}
		}

		if (i >= loggerStore.count) {
			if ((loggerStore.loggers = (LOGGER **) realloc (loggerStore.loggers, sizeof (LOGGER *) * (loggerStore.count+1))) == NULL) {
				fprintf (stderr, "ERROR: %s - Could not realloc loggerStore\n", __FUNCTION__);
				return NULL;
			}

			if ((loggerStore.loggers[i] = (LOGGER *) malloc (sizeof (LOGGER))) == NULL) {
				fprintf (stderr, "ERROR: %s - Could not malloc space for logger node\n", __FUNCTION__);
				return NULL;
			}
		}

	}

	pl = loggerStore.loggers[i];
	pl->index = i;

	loggerStore.count++;
	pl->name = strdup (name);
	options |= NODE_IN_USE;
	pl->optionMask		= options;		/* Set the LOG_IN_USE bit and the flags passed in */
	pl->verbosity		= verbosity;
	pl->facility		= facility;		/* Only supports LOG_FILE now...how to implement others? */
	pl->bufferSize		= bufferSize;
	pl->logFd		= NULL;
	pl->needFlush		= FALSE;
	pl->flushInterval	= LOG_DEFAULT_FLUSH_INTERVAL;
	pl->timerSignal		= SIGRTMIN;
	pl->flushBufSize	= 0;
	pl->amArchiving		= FALSE;

//	switch (p_logger->facility) {
//		case F_FILE:
//			retval = logInitFile (p_logger);
//			break;
//
//		case F_DB:
//			retval = logInitDB (p_logger);
//			break;
//
//		case F_SOCKET:
//			retval = logInitSocket (p_logger);
//			break;
//
//		case F_PIPE:
//			retval = logInitPipe (p_logger);
//			break;
//
//		case F_CONSOLE:
//			retval = logInitConsole (p_logger);
//			break;
//
//		case F_PRINTER:
//			retval = logInitPipe (p_logger);
//			break;
//
//		default:	/* Shouldn't ever get here... */
//			fprintf ("ERROR: %s - hit default case\n", __FUNCTION__);
//			break;
//	}

	/* Force rollover size to LOG_MAX_FILE_SIZE if user leaves it set to 0 */
	pl->rollOverSize = rollOverSize ? rollOverSize : LOG_MAX_FILE_SIZE;

	if ((pl->logPath = strdup (logPath)) == NULL) {
		fprintf (stderr, "ERROR: %s - Could not strdup logPath\n", __FUNCTION__);
		return NULL;
	}

	if ((pl->logName = strdup (logName)) == NULL) {
		fprintf (stderr, "ERROR: %s - Could not strdup logName\n", __FUNCTION__);
		return NULL;
	}

	if ((pl->fullLogName = malloc (strlen (logPath) + strlen (logName) + 2)) == NULL) {
		fprintf (stderr, "ERROR: %s - Could not malloc fullLogName\n", __FUNCTION__);
		return NULL;
	}

	sprintf (pl->fullLogName, "%s/%s", logPath, logName);

	/* This is kludged for now, allow it to be specified later */
	if ((pl->archivePath = malloc (strlen (logPath) + strlen ("/ARCHIVE/MmmDd") + 1)) == NULL) {
		fprintf (stderr, "ERROR: %s - Could not malloc archivePath\n", __FUNCTION__);
		return NULL;
	}

	sprintf (pl->archivePath, "%s/ARCHIVE", logPath);

	if ((pl->timeFormat = strdup (LOG_DEFAULT_DATE_FORMAT)) == NULL) {	/* Hand jam this for now. In future make it configurable */
		fprintf (stderr, "ERROR: %s - Could not strdup date format string\n", __FUNCTION__);
		return NULL;
	}

	if ((pl->buffer = malloc (bufferSize)) == NULL) {
		fprintf (stderr, "ERROR: %s - Could not malloc buffer\n", __FUNCTION__);
		return NULL;
	}

	if ((pl->formatBuf = malloc (LOG_FORMAT_BUF_SIZE)) == NULL) {
		fprintf (stderr, "ERROR: %s - Could not malloc format buffer\n", __FUNCTION__);
		return NULL;
	}

	pl->lastLogDay = pl->lastLogTime = 0;

	if (!fileExists (pl->logPath)) {
		if (makeDirectory (pl->logPath, YES, DIRECTORY_CREATE_PERMS) < 0) {
			fprintf (stderr, "ERROR: %s - Could not make directory for logPath\n", __FUNCTION__);
			return NULL;
		}
	}

	/* Cheat to get the device block size by checking on the block size of the logPath directory file */
	pl->flushBufSize = (stat (pl->logPath, &sb) == 0) ? sb.st_blksize : DEFAULT_DISK_BLOCK_SIZE;

	if (fileExists (pl->fullLogName)) {
		pl->lastLogTime = getFileLastMod (pl->fullLogName);
		pl->lastLogDay = pl->lastLogTime / SECONDS_PER_DAY;
		pl->logSize = getFileSize (pl->fullLogName);
		checkLogRollover (pl);		/* Rollover the log if necessary */
	} else {
		pl->lastLogDay = pl->lastLogTime = 0;
		pl->logSize = 0;
	}

	if (options & O_LOG_INIT) {
		logMsg (pl, V_INFO, S_STATUS, "%s INITIALIZED", pl->name);
		if (!(options & O_KEEP_OPEN)) {
			logClose (pl);
		}
	}

	if (options & O_KEEP_OPEN) {
		logOpen (pl);
	}

	return pl;
}
Exemplo n.º 29
0
bool Mineserver::configDirectoryPrepare(const std::string& path)
{
  const std::string distsrc = pathOfExecutable() + PATH_SEPARATOR + CONFIG_DIR_DISTSOURCE;

  std::cout << std::endl
            << "configDirectoryPrepare(): target directory = \"" << path
            << "\", distribution source is \"" << distsrc << "\"." << std::endl
            << "WARNING: This function is not implemented fully at present." << std::endl
            << "You must check that all the necessary files are in the target directory" << std::endl
            << "(including recipes and plugins) and that the config file is correct." << std::endl
            << std::endl;

  /*
     WARNING:
     ========
     kiki64's commit sort've messed things up. Someone needs to re-enable config.cfg's values for
     target paths (home, plugins, and files paths). I have fixed the issue with windows vs. *nix.
  */

  struct stat st;
  //Create Mineserver directory
  if (stat(path.c_str(), &st) != 0)
  {
    LOG2(INFO, "Creating: " + path);
    if (!makeDirectory(path))
    {
      LOG2(ERROR, path + ": " + strerror(errno));
      return false;
    }
  }

  //Create recipe/plugin directories
  // TODO: Fill in respective values with config()->sData("system.path.data")) and "system.path.plugins"
  const std::string directories [] = 
  {
    "plugins",
    "files",
    "files/recipes",
    "files/recipes/armour",
    "files/recipes/block",
    "files/recipes/cloth",
    "files/recipes/dyes",
    "files/recipes/food",
    "files/recipes/materials",
    "files/recipes/mechanism",
    "files/recipes/misc",
    "files/recipes/tools",
    "files/recipes/transport",
    "files/recipes/weapons",
  };
  for (size_t i = 0; i < sizeof(directories) / sizeof(directories[0]); i++)
  {
    std::string recipePath = path + PATH_SEPARATOR + directories[i];
    if (stat(recipePath.c_str(), &st) != 0)
    {
      //LOG2(INFO, "Creating: " + recipePath);
      if (!makeDirectory(recipePath))
      {
        LOG2(ERROR, recipePath + ": " + strerror(errno));
        return false;
      }
    }
  }

  // copy example configs
  const std::string files[] =
  {
    "banned.txt",
    "commands.cfg",
    "config.cfg",
    "item_alias.cfg",
    "ENABLED_RECIPES.cfg",
    "motd.txt",
    "permissions.txt",
    "roles.txt",
    "rules.txt",
    "whitelist.txt",
#ifdef WIN32
    "commands.dll",
#else
    "commands.so",
#endif
  };

  //Get list of recipe files
  std::vector<std::string> temp;
  Mineserver::m_inventory->getEnabledRecipes(temp, pathOfExecutable() + PATH_SEPARATOR + "files" + PATH_SEPARATOR + "ENABLED_RECIPES.cfg");

  //Add non-recipes to list
  for (unsigned int i = 0; i < sizeof(files) / sizeof(files[0]); i++)
  {
    temp.push_back(files[i]);
  }

  for (unsigned int i = 0; i < temp.size(); i++)
  {
    std::string namein, nameout;

    if(temp[i].substr(temp[i].size() - 7).compare(".recipe") == 0)//If a recipe file
    {
      namein  = pathOfExecutable() + PATH_SEPARATOR + "files" + PATH_SEPARATOR + "recipes" + PATH_SEPARATOR + temp[i];
      nameout = path + PATH_SEPARATOR + "files" + PATH_SEPARATOR + "recipes" + PATH_SEPARATOR + temp[i];
    }
    else if ((temp[i].substr(temp[i].size() - 4).compare(".dll") == 0) ||
             (temp[i].substr(temp[i].size() - 3).compare(".so") == 0))
    {
      namein  = pathOfExecutable() + PATH_SEPARATOR + "files" + PATH_SEPARATOR + "plugins" + PATH_SEPARATOR + temp[i];
      nameout = path + PATH_SEPARATOR + "plugins" + PATH_SEPARATOR + temp[i];
    }
    else
    {
      namein  = pathOfExecutable() + PATH_SEPARATOR + "files" + PATH_SEPARATOR + temp[i];
      nameout = path + PATH_SEPARATOR + temp[i];
    }

    // don't overwrite existing files
    if ((stat(nameout.c_str(), &st) == 0)) // && S_ISREG(st.st_mode) )
    {
      continue;
    }

    std::ifstream fin(namein.c_str(), std::ios_base::binary | std::ios_base::in);
    if (fin.fail())
    {
      LOG2(ERROR, "Failed to open: " + namein);
      continue;
    }

    //LOG2(INFO, "Copying: " + nameout);
    std::ofstream fout(nameout.c_str(), std::ios_base::binary);
    if (fout.fail())
    {
      LOG2(ERROR, "Failed to write to: " + nameout);
      continue;
    }

    fout << fin.rdbuf();
  }

  return true;
}
Exemplo n.º 30
0
int stmd_LogonSelect(int time_type, char *table_type)
{
    char        condBuf[4096], tmpBuf[1024];
    int         sts_code;
    char        str_time[10];
    int         select_cnt = 0, snd_cnt = 0;

    char        query[4096];
    MYSQL_RES   *result;
    MYSQL_ROW   row;

    time_t      now;
    char        tm[DIR_NUM][8];
    char        path[60];
    char        fileName[60];
    FILE        *fp;

    int         i, j, row_index, realSysCnt = 2, realItemCnt = 0;
    char title[7][16]={"SYSTEM", "SM_CH_ID", "LOG_MOD", "LOG_REQ", "LOG_SUCC","LOG_FAIL","SUCC_RATE"}; //uamyd 20110515 succrate_added
	char title1[5][16]={"", "HBIT_0","HBIT_1","HBIT_2", "HBIT_3"}; 
	char title2[5][16]={"", "HBIT_4","HBIT_5","HBIT_6", "HBIT_7"};
	char title3[5][16]={"", "HBIT_8","HBIT_9","HBIT_10", "HBIT_11"};
	char title4[5][16]={"", "HBIT_12","HBIT_13","HBIT_14", "HBIT_15"};
	char title5[5][16]={"", "HBIT_16","HBIT_17","HBIT_18", "HBIT_19"};
	char title6[5][16]={"", "HBIT_20","HBIT_21","HBIT_22", "HBIT_23"};
	char title7[5][16]={"", "HBIT_24","HBIT_25","HBIT_26", "HBIT_27"};
	char title8[5][16]={"", "HBIT_28","HBIT_29","HBIT_30", "HBIT_31"};
	char title10[5][16]={"", "SM_INT_ERR","OP_ERR","OP_TIMEOUT", "ETC_FAIL"};
	char title11[3][16]={"", "API_REQ_ERR","API_TIMEOUT"};
    char SysName[2][8] = {"SCMA","SCMB"};

    now = time(0);
    if(time_type != STMD_WEEK)
        now = now - (printTIME[time_type]*60) - STAT_OFFSET_UNIT;
    else
        now = now - (printTIME[time_type]*60);

    getFilePath (path, tm, &now); // ~/LOG/STAT 까지 만든다.
    makeDirectory (time_type,path,tm);

    sprintf(fileName, "%s", path );
    makeFileName ( fileName, STMD_LOGON, time_type, tm );

    if ( ( fp = fopen(fileName, APPEND ) ) == NULL ){
        sprintf(trcBuf, "%s Open Fail\n", fileName);
        trclib_writeLog(FL, trcBuf);
        return -1;
    }


    switch (time_type) {
        case    STMD_HOUR :
            sts_code = STSCODE_STM_PERIODIC_LOGON_HOUR;
            sprintf (str_time, "%s", STMD_STR_HOUR);
            break;
        case    STMD_DAY :
            sts_code = STSCODE_STM_PERIODIC_LOGON_DAY;
            sprintf (str_time, "%s", STMD_STR_DAY);
            break;
        case    STMD_WEEK :
            sts_code = STSCODE_STM_PERIODIC_LOGON_WEEK;
            sprintf (str_time, "%s", STMD_STR_WEEK);
            break;
        case    STMD_MONTH :
            sts_code = STSCODE_STM_PERIODIC_LOGON_MONTH;
            sprintf (str_time, "%s", STMD_STR_MONTH);
            break;
    }

    sprintf(condBuf,"    %s %s\n    S%04d LOGON PERIODIC STATISTICS MESSAGE\n",
        "SCM", // 현재는 OMP로 고정하지만 실질적인 시스템 이름으로 변경 필요 hslim_oper
        commlib_printTStamp(), // 현재시각 time stamp (년,월,일,시,분,초,요일)
        sts_code);

    sprintf(tmpBuf, "    PERIOD = %s\n    MEASURETIME = %s  -  %s\n\n",
        str_time,
        get_period_start_time(time_type), get_period_end_time(time_type));
    strcat(condBuf,tmpBuf);

    sprintf(tmpBuf, "    ====================================================================\n");
    strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s\n","",title[0],title[1],title[2] );
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n","","",title[3],title[4],title[5],title[6] ); //uamyd 20110515 succrate_added
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", "","", title1[1], title1[2],title1[3],title1[4]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", "","", title2[1], title2[2],title2[3],title2[4]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", "","", title3[1], title3[2],title3[3],title3[4]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", "","", title4[1], title4[2],title4[3],title4[4]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", "","", title5[1], title5[2],title5[3],title5[4]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", "","", title6[1], title6[2],title6[3],title6[4]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", "","", title7[1], title7[2],title7[3],title7[4]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", "","", title8[1], title8[2],title8[3],title8[4]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", "","", title10[1], title10[2],title10[3],title10[4]);
	strcat(condBuf, tmpBuf);
	sprintf(tmpBuf, "%3s %8s %12s %12s\n", "","", title11[1], title11[2]);
	strcat(condBuf, tmpBuf);
    sprintf(tmpBuf, "    ====================================================================\n");
    strcat(condBuf, tmpBuf);

    for(i = 0; i < realSysCnt; i++)
	{
		realItemCnt = 1;

	   	sprintf(query, "SELECT system_name, sm_ch_id, log_mod, "
				" ifnull(sum(log_req), 0), ifnull(sum(log_succ), 0), ifnull(sum(log_fail), 0), "
				" ifnull(sum(HBIT_0), 0), ifnull(sum(HBIT_1), 0), ifnull(sum(HBIT_2), 0), "
				" ifnull(sum(HBIT_3), 0),  "
				" ifnull(sum(HBIT_4), 0), ifnull(sum(HBIT_5), 0), ifnull(sum(HBIT_6), 0), "
				" ifnull(sum(HBIT_7), 0),  "
				" ifnull(sum(HBIT_8), 0), ifnull(sum(HBIT_9), 0), ifnull(sum(HBIT_10), 0), "
				" ifnull(sum(HBIT_11), 0),  "
				" ifnull(sum(HBIT_12), 0), ifnull(sum(HBIT_13), 0), ifnull(sum(HBIT_14), 0), "
				" ifnull(sum(HBIT_15), 0),  "
				" ifnull(sum(HBIT_16), 0), ifnull(sum(HBIT_17), 0), ifnull(sum(HBIT_18), 0), "
				" ifnull(sum(HBIT_19), 0),  "
				" ifnull(sum(HBIT_20), 0), ifnull(sum(HBIT_21), 0), ifnull(sum(HBIT_22), 0), "
				" ifnull(sum(HBIT_23), 0),  "
				" ifnull(sum(HBIT_24), 0), ifnull(sum(HBIT_25), 0), ifnull(sum(HBIT_26), 0), "
				" ifnull(sum(HBIT_27), 0),  "
				" ifnull(sum(HBIT_28), 0), ifnull(sum(HBIT_29), 0), ifnull(sum(HBIT_30), 0), "
				" ifnull(sum(HBIT_31), 0),  "
				" ifnull(sum(sm_int_err),0), ifnull(sum(op_err),0), ifnull(sum(op_timeout),0), "
				" ifnull(sum(etc_fail),0), "
				" ifnull(sum(api_req_err),0), ifnull(sum(api_timeout),0) "
			   " from %s "
			   " where system_name = '%s' AND (stat_date = '%s') "
			   " group by system_name, sm_ch_id, log_mod ",
			   table_type, SysName[i], get_period_select_time(time_type));

        if ( trcLogFlag == TRCLEVEL_SQL ) {
            sprintf(trcBuf, "query = %s\n", query);
            trclib_writeLog(FL, trcBuf);
        }
		if (stmd_mysql_query (query) < 0) {
            sprintf(trcBuf,">>> mysql_query fail; err=%s\n", mysql_error(conn));
            trclib_writeLogErr (FL,trcBuf);
            if(fp != NULL) fclose(fp);
            return -1;
        }

        select_cnt = 0;
        result = mysql_store_result(conn);

		if(strlen(condBuf)) {
			stmd_txMsg2Cond(condBuf, (sts_code - STSCODE_TO_MSGID_STATISTICS), 1, snd_cnt++);
			fprintf (fp, "%s",condBuf);
			memset(condBuf, 0x00, sizeof(condBuf));
		}

        while((row = mysql_fetch_row(result)) != NULL) 
		{
			row_index = 1;
			if (select_cnt == 0)
			{
				sprintf(tmpBuf, "%3s %8s SM_CH%7s %12s\n",
						"",SysName[i],row[row_index],!atoi(row[row_index+1])?"LOG_ON":"LOG_OUT");
				strcat(condBuf, tmpBuf);
			} 
			else 
			{
				sprintf(tmpBuf, "%3s %8s SM_CH%7s %12s\n",
						"","",row[row_index],!atoi(row[row_index+1])?"LOG_ON":"LOG_OUT");
				strcat(condBuf, tmpBuf);
			}

			sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12.1f\n", //uamyd 20110515 succrate_added
					"", "", row[row_index+2],row[row_index+3],row[row_index+4],
					atoi(row[row_index+2])==0?0.0:(((float)atoi(row[row_index+3])/(float)atoi(row[row_index+2]))*100)); //uamyd 20110515 succrate_added
			strcat(condBuf, tmpBuf );

			for( j=5; j<34; j+=4 ){
				//j = 5,9,13,17,21,25,29,33
				sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", 
						"", "", row[row_index+j],row[row_index+j+1],row[row_index+j+2],row[row_index+j+3]);
				strcat(condBuf, tmpBuf );
			}
			sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", 
					"", "", row[row_index+37],row[row_index+38],row[row_index+39],row[row_index+40]);
			strcat(condBuf, tmpBuf);
			sprintf(tmpBuf, "%3s %8s %12s %12s\n",
					"", "", row[row_index+41],row[row_index+42]);
			strcat(condBuf, tmpBuf);

    		sprintf(tmpBuf, "    ====================================================================\n");
			strcat(condBuf, tmpBuf);
			select_cnt++;

			if(strlen(condBuf)) {
				stmd_txMsg2Cond(condBuf, (sts_code - STSCODE_TO_MSGID_STATISTICS), 1, snd_cnt++);
                fprintf (fp, "%s",condBuf);
                memset(condBuf, 0x00, sizeof(condBuf));
            }
        }
        mysql_free_result(result);

        if (select_cnt == 0) 
		{
			sprintf(tmpBuf, "%3s %8s %12s %12s\n", "",SysName[i], "-","-");
			strcat(condBuf, tmpBuf);
			sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", "", "", "0","0","0","0"); //uamyd 20110515 succrate_added
			strcat(condBuf, tmpBuf);
			for(j=0;j<9;j++){
				sprintf(tmpBuf, "%3s %8s %12s %12s %12s %12s\n", "", "", "0","0","0","0");
				strcat(condBuf, tmpBuf );
			}
			sprintf(tmpBuf, "%3s %8s %12s %12s\n", 
					"", "", "0","0");
			strcat(condBuf, tmpBuf);
    		sprintf(tmpBuf, "    ====================================================================\n");
            strcat(condBuf, tmpBuf);
        } 
    }

    sprintf(tmpBuf, "    COMPLETED\n\n\n");
    strcat(condBuf, tmpBuf);

    if(fp != NULL) 
	{
        fprintf (fp, "%s",condBuf);
        fclose(fp);
    }
    
    stmd_txMsg2Cond(condBuf, (sts_code - STSCODE_TO_MSGID_STATISTICS), 0, snd_cnt);
    
    return 1;
}