char *LogoManager_ChannelNameToLogoName(char *ChannelName, char *LogoName, int LogoNameSize)
{
  TRACEENTER();

  char                 *pLogoName;
  char                  AllowedChars[] = "abcdefghijklmnoprqstuvwxyz0123456789הצ�+";

  if(LogoName && LogoNameSize)
  {
    memset(LogoName, 0, LogoNameSize);
    strncpy(LogoName, SkipCharTableBytes(ChannelName), LogoNameSize - 1);
    StrMkISO(LogoName);
    MakeValidFileName(LogoName, ControlChars | LFChars);
    LowerCase(LogoName);

    pLogoName = LogoName;
    while(*pLogoName)
    {
      if(index(AllowedChars, *pLogoName) == NULL)
        DeleteAt(pLogoName, 0, 1);
      else
        pLogoName++;
    }
    StrReplace(LogoName, "ה", "ae");
    StrReplace(LogoName, "צ", "oe");
    StrReplace(LogoName, "�", "ue");
  }

  TRACEEXIT();
  return LogoName;
}
Esempio n. 2
0
void Disasm(uint8_t* ram, uint32_t start)
{
	LogV("starting disassembly at: 0x%08x", start);
	uint32_t pc = start;
	
	int end = 1024 * 1024 * 16;
	while(ram[--end] == 0);
	
	while(pc <= end){
		int hasRead = 0;
		uint8_t read8(){ hasRead++; return ram[pc++]; }

		uint32_t read16(){
			uint16_t ret = read8();
			ret |= read8() << 8;
			return ret;
		}

		uint32_t read32(){
			uint32_t ret = read8();
			ret |= read8() << 8;
			ret |= read8() << 16;
			ret |= read8() << 24;
			return ret;
		}

		DIns ins = read8();
		LAssert(ins < DINS_NUM, "illegal instruction: 0x%02x", ins);

		int n = printf("\t%s ", dinsNames[ins]);

		for(int i = 0; i < InsNumOps(ins); i++){
			DVals op = read8();
			LAssert(op < DVALS_NUM, "illegal operand value: 0x%02x", op);
			char numStr[64] = {0};

			if(OpHasNextWord(op))
				sprintf(numStr, "0x%02x", read32());
			
			LogD("op: %d", op);
			char str[64];
			n += printf("%s", StrReplace(str, valNames[op], "nw", numStr));

			if(i < InsNumOps(ins) - 1)
				n += printf(", ");
		}

		printf("%*s", 40 - n, "; ");
		printf("0x%08x | ", pc - hasRead);
		for(int i = 0; i < hasRead; i++) printf("%02x ", ram[pc - hasRead + i]);

		printf("\n");
	}
}
Esempio n. 3
0
/* Expand "{Hugs}" to real path */
static String expandHugsPath(String toExpand)
{
  #define MAX_RESULTS 5

  static CHAR expanded[MAX_RESULTS][2*_MAX_PATH]; 
  static i = 0;

  /* get next slot */
  i++; if(i>=MAX_RESULTS) i = 0;

  StrReplace("{Hugs}", hugsHome, toExpand, expanded[i]);
  return expanded[i];
}
Esempio n. 4
0
SimJson::SimJson(const std::string& key, const std::string& value, bool is_transed)
{
    string v = value;
    if (!is_transed) v=StrReplace(value, "\"", "\\\"");
    if (!key.empty())
    {
        m_type = SIMJSON_EMPTY;
        m_str = "\"" + key + "\":\"" + v + "\"";
    }
    else
    {
        m_type = SIMJSON_NODE;
        m_str = "\"" + v + "\"";
    }
}
int main(int argc, char *argv[])
{
      char buf[200];
      char *Start;

      if(argc != 3)
            exit(1);

      /* Repeat until all occurences replaced */

      while(NULL != (Start = gets(buf)))
      {
            while(NULL != (Start = StrReplace(Start, argv[1], argv[2])))
                  ;
            printf("%s\n", buf);
      }
      return 0;
}
/**
desc:		将源字符串中的字符串替换成新字符串

strSrc:		源字符串
strFrom:	要替换的字符串
strTo:		用来替换的新字符串

return:		返回替换后的新字符串
*/
CString CommonStrMethod::StrReplace(CString strSrc, 
									CString strFrom, 
									CString strTo)
{
	int nLength = strFrom.GetLength();
	CString strSrcTemp = strSrc;
	int nAbsStart = 0;
	BOOL bFound = FALSE;
	int nStart = -1;
	for(; (nStart = strSrcTemp.Find(strFrom.GetAt(0))) != -1;)
	{
		int i = 0, j = nStart;
		for(; i < nLength-1;)
		{
			if(strSrcTemp.GetAt(++j) != strFrom.GetAt(++i))
			{
				strSrcTemp = strSrcTemp.Mid(nStart+1);
				nAbsStart += nStart+1;
				nStart = -1;
				break;
			}
		}
		if(i == nLength-1)
		{
			bFound = TRUE;
			nAbsStart += nStart;
			break;
		}
	}
	if(bFound == FALSE)
	{
		return strSrc;
	}
	CString strDest = strSrc.Left(nAbsStart);
	strDest += strTo;
	strDest += strSrc.Mid(nAbsStart + nLength);

	return StrReplace(strDest, strFrom, strTo);
}
Esempio n. 7
0
/*******************************+++*******************************/
int CrossValidate(void)
/*****************************************************************/
/*   Purpose:  Compute cross validations and put them in the CV  */
/*             matrix.                                           */
/*                                                               */
/*   1996.04.12: Completed removed.                              */
/*   1996.04.04: X and y include NA's.                           */
/*   1996.04.14: KrigModAlloc/KrigModData; DbIndexXY.            */
/*   2009.05.07: Multiple correlation families                   */
/*****************************************************************/
{
    int            ErrNum, ErrReturn;
    KrigingModel   KrigMod;
    real           *CVMaxErr, *CVRootMSE, *ErrVar, *PredCol;
    real           *SE, *SECol, *SPVar, *YHatCV;
    size_t         IndexMaxErr, j;
    string         ColName;
    string         *CaseMaxErr;

    if (MatNumCols(&T) > 0)
    {
        Error("Transformations not allowed.\n");
        return INPUT_ERR;
    }

    ErrVar = MatColFind(&YDescrip, ERR_VAR, NO);
    SPVar  = MatColFind(&YDescrip, SP_VAR, YES);

    /* Add columns to the YDescrip matrix. */
    CVRootMSE  = MatColAdd(CV_ROOT_MSE,        &YDescrip);
    CVMaxErr   = MatColAdd(CV_MAX_ERR,         &YDescrip);
    CaseMaxErr = MatStrColAdd(CASE_CV_MAX_ERR, &YDescrip);

    /* Compute cross-validation predictions for each response. */
    ErrReturn = OK;
    ErrorSave = YES;
    for (j = 0; j < MatNumRows(&YDescrip); j++)
    {
        if (DbIndexXY(j) == 0)
            continue;

        ErrorVar = yName;

        /* Allocations. */
        YHatCV = AllocReal(nCasesXY, NULL);
        SE     = AllocReal(nCasesXY, NULL);

        /* Set up kriging model. */
        KrigModAlloc(nCasesXY, MatNumCols(&X), yName, &T, &RegMod,
                     &SPMod, CorFamNum, RanErr, &KrigMod);
        KrigModData(nCasesXY, IndexXY, &X, y, &KrigMod);

        /* SPModMat contains the correlation parameters. */
        ErrNum = KrigModSetUp(&SPModMat, yName, SPVar[j],
                              (ErrVar != NULL) ? ErrVar[j] : 0.0, &KrigMod);

        if (ErrNum == OK)
            ErrNum = CalcCV(&KrigMod, YHatCV, SE);

        if (ErrNum == OK)
        {
            /* Put cross validations and standard errors */
            /* in CV.                                    */

            ColName = StrPaste(3, PRED, ".", yName);
            PredCol = MatColAdd(ColName, &CV);
            AllocFree(ColName);
            VecCopyIndex(nCasesXY, NULL, YHatCV, IndexXY,
                         PredCol);

            ColName = StrPaste(3, STD_ERR, ".", yName);
            SECol = MatColAdd(ColName, &CV);
            AllocFree(ColName);
            VecCopyIndex(nCasesXY, NULL, SE, IndexXY, SECol);

            /* Compute summary statistics. */
            CVRootMSE[j] = RootMSE(MatNumRows(&CV), PredCol, y,
                                   &CVMaxErr[j], &IndexMaxErr);
            if (IndexMaxErr != INDEX_ERR)
                CaseMaxErr[j] = StrReplace(
                                    MatRowName(&X, IndexMaxErr),
                                    CaseMaxErr[j]);

        }

        KrigModFree(&KrigMod);

        if (ErrNum != OK)
            ErrReturn = ErrNum;

        AllocFree(YHatCV);
        AllocFree(SE);
    }

    OutputSummary(&YDescrip, NumStr(SummaryStats), SummaryStats);

    return ErrReturn;
}
Esempio n. 8
0
int Service::Initialise(dictionary* ini)
{
	g_ini = ini;

	g_serviceId = iniparser_getstr(ini, SERVICE_ID);
	if (g_serviceId == NULL) {
		Log::Error("Service ID not specified");
		return 1;
	}

	// Parse controls accepted
	char* controls = iniparser_getstr(ini, SERVICE_CONTROLS);
	if (controls) {
		int len = strlen(controls);
		int nb = 0;
		for (int i = 0; i < len; i++) {
			if (controls[i] == '|') {
				controls[i] = 0;
				nb++;
			}
		}
		char* p = controls;
		char* e = controls + len;
		for (int i = 0; i <= nb; i++) {
			int plen = strlen(p);
			StrTrim(p, " ");
			if (strcmp("stop", p) == 0) {
				g_controlsAccepted |= SERVICE_ACCEPT_STOP;
			}
			else if (strcmp("shutdown", p) == 0) {
				g_controlsAccepted |= SERVICE_ACCEPT_SHUTDOWN;
			}
			else if (strcmp("pause", p) == 0) {
				g_controlsAccepted |= SERVICE_ACCEPT_PAUSE_CONTINUE;
			}
			else if (strcmp("param", p) == 0) {
				g_controlsAccepted |= SERVICE_ACCEPT_PARAMCHANGE;
			}
			else if (strcmp("netbind", p) == 0) {
				g_controlsAccepted |= SERVICE_ACCEPT_NETBINDCHANGE;
			}
			else if (strcmp("hardware", p) == 0) {
				g_controlsAccepted |= SERVICE_ACCEPT_HARDWAREPROFILECHANGE;
			}
			else if (strcmp("power", p) == 0) {
				g_controlsAccepted |= SERVICE_ACCEPT_POWEREVENT;
			}
			else if (strcmp("session", p) == 0) {
				g_controlsAccepted |= SERVICE_ACCEPT_SESSIONCHANGE;
			}

			p += plen + 1;
			if (p >= e) break;
		}
	}
	else {
		g_controlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
	}

	// Initialise JNI members
	JNIEnv* env = VM::GetJNIEnv();
	if (env == NULL) {
		Log::Error("JNIEnv is null");
		return 1;
	}

	char* svcClass = iniparser_getstr(ini, SERVICE_CLASS);
	StrReplace(svcClass, '.', '/');
	g_serviceClass = JNI::FindClass(env, svcClass);
	if (g_serviceClass == NULL) {
		Log::Error("Could not find service class");
		return 1;
	}

	jmethodID scon = env->GetMethodID(g_serviceClass, "<init>", "()V");
	if (scon == NULL) {
		Log::Error("Could not find service class default constructor");
		return 1;
	}

	g_serviceInstance = env->NewObject(g_serviceClass, scon);
	if (g_serviceInstance == NULL) {
		Log::Error("Could not create service class");
		return 1;
	}
	// Need a global reference here to as we transfer across threads
	g_serviceInstance = env->NewGlobalRef(g_serviceInstance);

	g_controlMethod = env->GetMethodID(g_serviceClass, "serviceRequest", "(I)I");
	if (g_controlMethod == NULL) {
		Log::Error("Could not find control method class");
		return 1;
	}

	g_mainMethod = env->GetMethodID(g_serviceClass, "serviceMain", "([Ljava/lang/String;)I");
	if (g_mainMethod == NULL) {
		Log::Error("Could not find control main class");
		return 1;
	}

	return 0;
}
void HDD_DecodeRECHeader_ST_TF7k7HDPVR(byte *Buffer, tRECHeaderInfo *RECHeaderInfo)
{
  TRACEENTER();

  dword                 p;
  word                  TPFlags1;
  byte                  EventTextLength;
  int                   i;

  //Header
  p = 0x4d0;
  memcpy(RECHeaderInfo->HeaderUnknown2, &Buffer[p + 0x0006], 2);
  RECHeaderInfo->HeaderDuration  = getWord(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->HeaderSvcNumber = getWord(&Buffer[p + 0x000a], WrongEndian);
  RECHeaderInfo->HeaderSvcType   = getWord(&Buffer[p + 0x000c], WrongEndian);

  //Service Info
  p = 0x04de;
  RECHeaderInfo->SISatIndex  =  Buffer[p + 0x0000];
  RECHeaderInfo->SIServiceType = Buffer[p + 0x0001];

  TPFlags1 = getWord(&Buffer[p + 0x0002], WrongEndian);
  RECHeaderInfo->SITPIdx     =  TPFlags1 & 0x3ff;
  RECHeaderInfo->SITunerNum  = (TPFlags1 >> 10) & 3;
  RECHeaderInfo->SISkipFlag  = (TPFlags1 >> 12) & 1;
  RECHeaderInfo->SILockFlag  = (TPFlags1 >> 13) & 1;
  RECHeaderInfo->SICASFlag   = (TPFlags1 >> 14) & 1;
  RECHeaderInfo->SIDelFlag   = (TPFlags1 >> 15) & 1;

  RECHeaderInfo->SIServiceID = getWord(&Buffer[p + 0x0004], WrongEndian);
  RECHeaderInfo->SIPMTPID    = getWord(&Buffer[p + 0x0006], WrongEndian);
  RECHeaderInfo->SIPCRPID    = getWord(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->SIVideoPID  = getWord(&Buffer[p + 0x000a], WrongEndian);
  RECHeaderInfo->SIAudioPID  = getWord(&Buffer[p + 0x000c], WrongEndian);
  strncpy(RECHeaderInfo->SISvcName, &Buffer[p + 0x000e], 28);

  //Transponder Info
  p = 0x0508;
  RECHeaderInfo->TPSatIndex           = Buffer[p + 0x0000];

  RECHeaderInfo->TPFlags2             = Buffer[p + 0x0001];
  RECHeaderInfo->TPPolarization       =  RECHeaderInfo->TPFlags2 & 1;
  RECHeaderInfo->TPMode               = (RECHeaderInfo->TPFlags2 >> 1) & 7;
  RECHeaderInfo->TPFlags2             = RECHeaderInfo->TPFlags2 & 0x00f0;

  memcpy(RECHeaderInfo->TPUnknown3, &Buffer[p + 0x0002], 2);
  RECHeaderInfo->TPFrequency          = getDword(&Buffer[p + 0x0004], WrongEndian);
  RECHeaderInfo->TPSymbolRate         = getWord(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->TPTSID               = getWord(&Buffer[p + 0x000a], WrongEndian);
  memcpy(RECHeaderInfo->TPUnknown5, &Buffer[p + 0x000c], 2);
  RECHeaderInfo->TPOriginalNetworkID  = getWord(&Buffer[p + 0x000e], WrongEndian);

  //Event Info
  p = 0x0518;
  memcpy(RECHeaderInfo->EventUnknown1, &Buffer[p], 2);
  RECHeaderInfo->EventDuration       = 60 * Buffer[p + 0x0003] + Buffer[p + 0x0002];
  RECHeaderInfo->EventEventID        = getDword(&Buffer[p + 0x0004], WrongEndian);
  RECHeaderInfo->EventStartTime      = getDword(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->EventEndTime        = getDword(&Buffer[p + 0x000c], WrongEndian);
  RECHeaderInfo->EventRunningStatus  = Buffer[p + 0x0010];
  EventTextLength                    = Buffer[p + 0x0011];
  RECHeaderInfo->EventParentalRate   = Buffer[p + 0x0012];
  strncpy(RECHeaderInfo->EventEventName, &Buffer[p + 0x0013], EventTextLength);
  strncpy(RECHeaderInfo->EventEventDescription, &Buffer[p + 0x0013 + EventTextLength], 257 - EventTextLength);
  RECHeaderInfo->EventServiceID      =  getWord(&Buffer[p + 0x0114], WrongEndian);
  memcpy(RECHeaderInfo->EventUnknown2, &Buffer[p + 0x0116], 14);

  //Extended Event Info
  p = 0x063c;
  RECHeaderInfo->ExtEventServiceID   = getWord(&Buffer[p + 0x0000], WrongEndian);
  RECHeaderInfo->ExtEventTextLength  = getWord(&Buffer[p + 0x0002], WrongEndian);
  RECHeaderInfo->ExtEventEventID     = getDword(&Buffer[p + 0x0004], WrongEndian);
  memcpy(RECHeaderInfo->ExtEventText, &Buffer[p + 0x0008], RECHeaderInfo->ExtEventTextLength);
  for(i = 0; i < RECHeaderInfo->ExtEventTextLength - 1; i++)
    if(RECHeaderInfo->ExtEventText[i] == '\0') RECHeaderInfo->ExtEventText[i] = ' ';
  StrReplace(RECHeaderInfo->ExtEventText, "\\n", "\x8a");

  //Crypt Info
  p = 0x0a44;
  memcpy(RECHeaderInfo->CryptUnknown1, &Buffer[p], 4);
  RECHeaderInfo->CryptFlag = Buffer[p + 0x0004];
  memcpy(RECHeaderInfo->CryptUnknown2, &Buffer[p + 0x0005], 3);

  //Bookmarks
  p = 0x0a4c;
  memcpy(RECHeaderInfo->Bookmark, &Buffer[p + 0x0000], 64 * sizeof(dword));
  RECHeaderInfo->Resume = getDword(&Buffer[p + 0x0100], WrongEndian);

  TRACEEXIT();
}
void HDD_DecodeRECHeader_ST_TMSC(byte *Buffer, tRECHeaderInfo *RECHeaderInfo)
{
  TRACEENTER();

  dword                 p;
  word                  Flags;
  byte                  EventTextLength;
  int                   i;

  //Header
  p = 0;
  memcpy(RECHeaderInfo->HeaderUnknown2, &Buffer[p + 6], 2);
  RECHeaderInfo->HeaderStartTime = getDword(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->HeaderDuration  = getWord(&Buffer[p + 0x000c], WrongEndian);
  RECHeaderInfo->HeaderDurationSec  = getWord(&Buffer[p + 0x000e], WrongEndian);

  RECHeaderInfo->CryptFlag   = Buffer[p + 0x0010] & 0x03;
  RECHeaderInfo->HeaderFlags = Buffer[p + 0x0010] & 0xfc;

  RECHeaderInfo->HeaderCopyFlag = Buffer[p + 0x0011] & 0x80;
  RECHeaderInfo->HeaderTSFlag = Buffer[p + 0x0011] & 0x40;
  RECHeaderInfo->HeaderFlags2 = Buffer[p + 0x0011] & 0x3f;

  memcpy(RECHeaderInfo->HeaderUnknown4, &Buffer[p + 0x0012], 10);

  //Service Info
  p = 0x001c;
  RECHeaderInfo->SISatIndex    =  Buffer[p + 0x0000];
  RECHeaderInfo->SIServiceType =  Buffer[p + 0x0001];

  Flags = getWord(&Buffer[p +0x0002], WrongEndian);
  RECHeaderInfo->SITPIdx     =  Flags & 0x3ff;
  RECHeaderInfo->SITunerNum  = (Flags >> 10) & 3;
  RECHeaderInfo->SIDelFlag   = (Flags >> 12) & 1;
  RECHeaderInfo->SICASFlag   = (Flags >> 13) & 1;
  RECHeaderInfo->SILockFlag  = (Flags >> 14) & 1;
  RECHeaderInfo->SISkipFlag  =  Flags >> 15;

  RECHeaderInfo->SIServiceID = getWord(&Buffer[p + 0x0004], WrongEndian);
  RECHeaderInfo->SIPMTPID    = getWord(&Buffer[p + 0x0006], WrongEndian);
  RECHeaderInfo->SIPCRPID    = getWord(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->SIVideoPID  = getWord(&Buffer[p + 0x000a], WrongEndian);
  RECHeaderInfo->SIAudioPID  = getWord(&Buffer[p + 0x000c], WrongEndian);

  strncpy(RECHeaderInfo->SISvcName, &Buffer[p + 0x000e], 24);

  RECHeaderInfo->SIVideoStreamType = Buffer[p + 0x0026];
  RECHeaderInfo->SIAudioStreamType = Buffer[p + 0x0027];

  //Event Info
  p = 0x0044;
  memcpy(RECHeaderInfo->EventUnknown1, &Buffer[p], 2);
  RECHeaderInfo->EventDuration       = 60 * Buffer[p +  3] + Buffer[p +  2];
  RECHeaderInfo->EventEventID        = getDword(&Buffer[p + 0x0004], WrongEndian);
  RECHeaderInfo->EventStartTime      = getDword(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->EventEndTime        = getDword(&Buffer[p + 0x000c], WrongEndian);
  RECHeaderInfo->EventRunningStatus  = Buffer[p + 0x0010];
  EventTextLength                    = Buffer[p + 0x0011];
  RECHeaderInfo->EventParentalRate   = Buffer[p + 0x0012];
  strncpy(RECHeaderInfo->EventEventName, &Buffer[p + 0x0013], EventTextLength);
  strncpy(RECHeaderInfo->EventEventDescription, &Buffer[p + 0x0013 + EventTextLength], 273 - EventTextLength);

  //Extended Event Info
  p = 0x0168;
  RECHeaderInfo->ExtEventServiceID   = getWord(&Buffer[p + 0x0000], WrongEndian);
  RECHeaderInfo->ExtEventTextLength  = getWord(&Buffer[p + 0x0002], WrongEndian);
  RECHeaderInfo->ExtEventEventID     = getDword(&Buffer[p + 0x0004], WrongEndian);
  memcpy(RECHeaderInfo->ExtEventText, &Buffer[p + 0x0008], RECHeaderInfo->ExtEventTextLength);
  for(i = 0; i < RECHeaderInfo->ExtEventTextLength - 1; i++)
    if(RECHeaderInfo->ExtEventText[i] == '\0') RECHeaderInfo->ExtEventText[i] = ' ';
  StrReplace(RECHeaderInfo->ExtEventText, "\\n", "\x8a");

  //Transponder info
  p = 0x0570;
  memcpy(RECHeaderInfo->TPUnknown1, &Buffer[p + 0x0000], 4);
  RECHeaderInfo->TPFrequency          = getDword(&Buffer[p + 0x0004], WrongEndian) >> 8;
  RECHeaderInfo->TPSymbolRate         = getWord(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->TPTSID               = getWord(&Buffer[p + 0x000a], WrongEndian);
  RECHeaderInfo->TPOriginalNetworkID  = getWord(&Buffer[p + 0x000c], WrongEndian);
  RECHeaderInfo->TPModulation         = Buffer[p + 0x000e];
  RECHeaderInfo->TPUnknown6           = Buffer[p + 0x000f];

  //Crypt Info: see header flags

  //Bookmarks
  p = 0x0580;
  RECHeaderInfo->NrBookmarks = getDword(&Buffer[p + 0x0000], WrongEndian);
  memcpy(RECHeaderInfo->Bookmark, &Buffer[p + 0x0004], 177 * sizeof(dword));
  RECHeaderInfo->Resume = getDword(&Buffer[p + 0x02c8], WrongEndian);

  TRACEEXIT();
}
void HDD_DecodeRECHeader_ST_T5800(byte *Buffer, tRECHeaderInfo *RECHeaderInfo)
{
  TRACEENTER();

  dword                 p;
  byte                  EventTextLength;
  int                   i;

  //Header
  p = 0;
  memcpy(RECHeaderInfo->HeaderUnknown2, &Buffer[p + 6], 2);
  RECHeaderInfo->HeaderDuration  = getWord(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->HeaderSvcNumber = getWord(&Buffer[p + 0x000a], WrongEndian);
  RECHeaderInfo->HeaderSvcType   = getWord(&Buffer[p + 0x000c], WrongEndian);

  //Service Info
  p = 0x000e;
  RECHeaderInfo->SISatIndex  = Buffer[p + 0x0000];
  RECHeaderInfo->SIServiceType = Buffer[p + 0x0001];
  RECHeaderInfo->SITPIdx     =  getWord(&Buffer[p + 0x0002], WrongEndian) >> 6;
  RECHeaderInfo->SITunerNum  = (getWord(&Buffer[p + 0x0002], WrongEndian) >> 4) & 3;
  RECHeaderInfo->SIDelFlag   = (getWord(&Buffer[p + 0x0002], WrongEndian) >> 3) & 1;
  RECHeaderInfo->SICASFlag   = (getWord(&Buffer[p + 0x0002], WrongEndian) >> 2) & 1;
  RECHeaderInfo->SILockFlag  = (getWord(&Buffer[p + 0x0002], WrongEndian) >> 1) & 1;
  RECHeaderInfo->SISkipFlag  = (getWord(&Buffer[p + 0x0002], WrongEndian)     ) & 1;

  RECHeaderInfo->SIServiceID = getWord(&Buffer[p + 0x0004], WrongEndian);
  RECHeaderInfo->SIPMTPID    = getWord(&Buffer[p + 0x0006], WrongEndian);
  RECHeaderInfo->SIPCRPID    = getWord(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->SIVideoPID  = getWord(&Buffer[p + 0x000a], WrongEndian);
  RECHeaderInfo->SIAudioPID  = getWord(&Buffer[p + 0x000c], WrongEndian);
  strncpy(RECHeaderInfo->SISvcName, &Buffer[p + 0x000e], 28);

  //Transponder Info
  p = 0x0038;
  RECHeaderInfo->TPChannelNumber      = getWord(&Buffer[p + 0x0000], WrongEndian);
  RECHeaderInfo->TPBandwidth          = Buffer[p + 0x0002];
  RECHeaderInfo->TPUnknown2           = Buffer[p + 0x0003];
  RECHeaderInfo->TPFrequency          = getDword(&Buffer[p + 0x0004], WrongEndian);
  RECHeaderInfo->TPTSID               = getWord(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->TPLPHPStream         = Buffer[p + 0x000a];
  RECHeaderInfo->TPUnknown4           = Buffer[p + 0x000b];
  RECHeaderInfo->TPOriginalNetworkID  = getWord(&Buffer[p + 0x000c], WrongEndian);
  RECHeaderInfo->TPNetworkID          = getWord(&Buffer[p + 0x000e], WrongEndian);

  //Event Info
  p = 0x0048;
  memcpy(RECHeaderInfo->EventUnknown1, &Buffer[p], 2);
  RECHeaderInfo->EventDuration       = 60 * Buffer[p + 0x0002] + Buffer[p +  3];
  RECHeaderInfo->EventEventID        =  getDword(&Buffer[p + 0x0004], WrongEndian);
  RECHeaderInfo->EventStartTime      =  getDword(&Buffer[p + 0x0008], WrongEndian);
  RECHeaderInfo->EventEndTime        =  getDword(&Buffer[p + 0x000c], WrongEndian);
  RECHeaderInfo->EventRunningStatus  = Buffer[p + 0x0010];
  EventTextLength                    = Buffer[p + 0x0011];
  RECHeaderInfo->EventParentalRate   = Buffer[p + 0x0012];
  strncpy(RECHeaderInfo->EventEventName, &Buffer[p + 0x0013], EventTextLength);
  strncpy(RECHeaderInfo->EventEventDescription, &Buffer[p + 0x0013 + EventTextLength], 257 - EventTextLength);
  RECHeaderInfo->EventServiceID      =  getWord(&Buffer[p + 0x0114], WrongEndian);
  memcpy(RECHeaderInfo->EventUnknown2, &Buffer[p + 0x0116], 10);

  //Extended Event Info
  p = 0x016c;
  RECHeaderInfo->ExtEventServiceID   = getWord(&Buffer[p + 0x0000], WrongEndian);
  RECHeaderInfo->ExtEventTextLength  = getWord(&Buffer[p + 0x0002], WrongEndian);
  RECHeaderInfo->ExtEventEventID     = getDword(&Buffer[p + 0x0004], WrongEndian);
  memcpy(RECHeaderInfo->ExtEventText, &Buffer[p + 0x0008], RECHeaderInfo->ExtEventTextLength);
  for(i = 0; i < RECHeaderInfo->ExtEventTextLength - 1; i++)
    if(RECHeaderInfo->ExtEventText[i] == '\0') RECHeaderInfo->ExtEventText[i] = ' ';
  StrReplace(RECHeaderInfo->ExtEventText, "\\n", "\x8a");

  //Crypt Info
  p = 0x0574;
  memcpy(RECHeaderInfo->CryptUnknown1, &Buffer[p], 4);
  RECHeaderInfo->CryptFlag = Buffer[p + 0x0004];
  memcpy(RECHeaderInfo->CryptUnknown2, &Buffer[p + 0x0005], 3);

  //Bookmarks
  p = 0x057c;
  memcpy(RECHeaderInfo->Bookmark, &Buffer[p + 0x0000], 64 * sizeof(dword));
  RECHeaderInfo->Resume = getDword(&Buffer[p + 0x0100], WrongEndian);

  TRACEEXIT();
}
Esempio n. 12
0
void exportModule(HANDLE hContact, char* module, FILE* file)
{
	char tmp[32];
	ModuleSettingLL settinglist;
	struct ModSetLinkLinkItem *setting;

	EnumSettings(hContact,module,&settinglist);

	// print the module header..
	fprintf(file, "\n[%s]", module);
	setting = settinglist.first;
	while(setting)
	{
		DBVARIANT dbv;
		if (!GetSetting(hContact, module, setting->name, &dbv))
		{
			switch (dbv.type)
			{
				case DBVT_BYTE:
					fprintf(file, "\n%s=b%s", setting->name, itoa(dbv.bVal,tmp,10));
					DBFreeVariant(&dbv);
					break;
				case DBVT_WORD:
					fprintf(file, "\n%s=w%s", setting->name, itoa(dbv.wVal,tmp,10));
					DBFreeVariant(&dbv);
					break;
				case DBVT_DWORD:
					fprintf(file, "\n%s=d%s", setting->name, itoa(dbv.dVal,tmp,10));
					DBFreeVariant(&dbv);
					break;
				case DBVT_ASCIIZ:
				case DBVT_UTF8:
						if (strchr(dbv.pszVal, '\r'))
						{
							char *end = StrReplace("\\", "\\\\", dbv.pszVal);
							end = StrReplace("\r", "\\r", end);
							end = StrReplace("\n", "\\n", end);
							fprintf(file, "\n%s=g%s", setting->name, end);
							break;
						}
						if (dbv.type == DBVT_UTF8)
							fprintf(file, "\n%s=u%s", setting->name, dbv.pszVal);
						else
							fprintf(file, "\n%s=s%s", setting->name, dbv.pszVal);
						DBFreeVariant(&dbv);
						break;
				case DBVT_BLOB:
				{
					int j;
					char *data = NULL;
					if (!(data = (char*)mir_alloc( 3*(dbv.cpbVal+1)*sizeof(char)) ))
						break;
					data[0] = '\0';
					for (j=0; j<dbv.cpbVal; j++)
					{
						char tmp[16];
						mir_snprintf(tmp, SIZEOF(tmp), "%02X ", (BYTE)dbv.pbVal[j]);
						strcat(data, tmp);
					}
					fprintf(file,"\n%s=n%s",setting->name , data);
					mir_free(data);
				}
				DBFreeVariant(&dbv);
				break;
			}
		}
		setting = (struct ModSetLinkLinkItem *)setting->next;
	}
	FreeModuleSettingLL(&settinglist);
}
Esempio n. 13
0
//-----------------------------------------------------------------------------
// Initialize filenames of various path/files (configuration files, etc).
// FIXME-BUFFER: Potential buffer overflows here.
//-----------------------------------------------------------------------------
void    Filenames_Init()
{
    // Get and save current directory
    getcwd(g_env.Paths.StartingDirectory, countof(g_env.Paths.StartingDirectory));

    // Find emulator directory --------------------------------------------------

#if defined(ARCH_MACOSX)
    GetResourcePath( g_env.Paths.EmulatorDirectory, sizeof(g_env.Paths.EmulatorDirectory) );
    ConsolePrintf ("Resource path = %s\n", g_env.Paths.EmulatorDirectory);
#else
    strcpy(g_env.Paths.EmulatorDirectory, g_env.argv[0]);
    #ifdef ARCH_WIN32
        StrReplace(g_env.Paths.EmulatorDirectory, '\\', '/');
    #endif
    char* p = strrchr(g_env.Paths.EmulatorDirectory, '/');
    if (p)
        *p = EOSTR;
    else
        strcpy(g_env.Paths.EmulatorDirectory, g_env.Paths.StartingDirectory);
#endif

#if defined(ARCH_UNIX) || defined(ARCH_MACOSX)
    char* rp = realpath(g_env.Paths.EmulatorDirectory, NULL);
    if (rp != NULL)
    {
        strcpy(g_env.Paths.EmulatorDirectory, rp);
        //strcat(g_env.Paths.EmulatorDirectory, "/");
        free(rp);
    }
#endif

    char data_dir[FILENAME_LEN];
    char internal_resources_dir[FILENAME_LEN];
    char external_resources_dir[FILENAME_LEN];
    strcpy(data_dir, g_env.Paths.EmulatorDirectory);
#ifdef ARCH_MACOSX
    GetWritableInternalResourcePath( internal_resources_dir, sizeof(internal_resources_dir) );
    GetWritableExternalResourcePath( external_resources_dir, sizeof(external_resources_dir) );
    const char* files_to_copy_internal_resources[2] = 
    {
        "meka.inp",
        NULL
    };
    PopulateWritableInternalResourcesPath(internal_resources_dir, files_to_copy_internal_resources);
#else
    strcpy(internal_resources_dir, g_env.Paths.EmulatorDirectory);
    strcpy(external_resources_dir, g_env.Paths.EmulatorDirectory);
#endif

    //ConsolePrintf("Data Directory = %s\n", data_dir);
    //ConsolePrintf("Internal Writable Resources Directory = %s\n", internal_resources_dir);
    //ConsolePrintf("External Writable Resources Directory = %s\n", external_resources_dir);

    // Datafiles
    sprintf(g_env.Paths.DataFile,       "%s/meka.dat",    data_dir);
    sprintf(g_env.Paths.DataBaseFile,   "%s/meka.nam",    data_dir);
    sprintf(g_env.Paths.SkinFile,       "%s/meka.thm",    data_dir);

    sprintf(Patches.filename,           "%s/meka.pat",    data_dir);
    sprintf(Blitters.filename,          "%s/meka.blt",    data_dir);
    sprintf(Messages.FileName,          "%s/meka.msg",    data_dir);

    // files that are written to
    sprintf(Desktop.filename,           "%s/meka.dsk",    internal_resources_dir);
    sprintf(VLFN_DataBase.filename,     "%s/meka.fdb",    internal_resources_dir);
    sprintf(Inputs.FileName,            "%s/meka.inp",    internal_resources_dir);

    // Documentations
    sprintf(g_env.Paths.DocumentationMain,       "%s/meka.txt",      data_dir);
    sprintf(g_env.Paths.DocumentationCompat,     "%s/compat.txt",    data_dir);
    sprintf(g_env.Paths.DocumentationMulti,      "%s/multi.txt",     data_dir);
    sprintf(g_env.Paths.DocumentationChanges,    "%s/changes.txt",   data_dir);
    sprintf(g_env.Paths.DocumentationDebugger,   "%s/debugger.txt",  data_dir);

    // Configuration file
#ifdef ARCH_WIN32
    sprintf(g_env.Paths.ConfigurationFile,       "%s/mekaw.cfg",     g_env.Paths.EmulatorDirectory);
#else /* unix */
    sprintf(g_env.Paths.ConfigurationFile,       "%s/meka.cfg",      internal_resources_dir);
#endif

    // Directories
    sprintf(g_env.Paths.ScreenshotDirectory,     "%s/Screenshots",   external_resources_dir);
    sprintf(g_env.Paths.SavegameDirectory,       "%s/Saves",         external_resources_dir);
    sprintf(g_env.Paths.MusicDirectory,          "%s/Music",         external_resources_dir);
    sprintf(g_env.Paths.DebugDirectory,          "%s/Debug",         external_resources_dir);

    // ROM
    strcpy(g_env.Paths.MediaImageFile,  "");
    strcpy(g_env.Paths.BatteryBackedMemoryFile, "");
}