Example #1
0
int f_ext_name(ARG0) {
    int itmp;
    if (mode >= 0) {
        itmp = use_ext_name;
        use_ext_name = 1;
        getExtName(sec, mode, NULL, inv_out, NULL, NULL,".","_");
        use_ext_name = itmp;
    }
    return 0;
}
Example #2
0
int f_full_name(ARG0) {
    int i;
    if (mode >= 0) {
        getExtName(sec, mode, NULL, inv_out, NULL, NULL,".","_");
	inv_out += strlen(inv_out);
	*inv_out++ = '.';
	*inv_out = 0;
	f_lev(call_ARG0(inv_out,NULL));
	for (i = 0; inv_out[i]; i++) {
	    if (inv_out[i] == ' ') inv_out[i] = '_';
	}
    }
    return 0;
}
Example #3
0
DWORD CM3u::Load(LPCTSTR szFileName)
{
	DWORD	dwWin32errorCode = ERROR_SUCCESS;
	Release();

	if (lstrcmpi(getExtName(szFileName), _T(".m3u8")) == 0) {
		if ((m_encoding != ENC_UTF8N) && (m_encoding != ENC_UTF8B)) {
			m_encoding = ENC_UTF8N;
		}
	}

	FILE *fp = _tfopen(szFileName, _T("r"));
	if (fp == NULL) {
		return ERROR_INVALID_FUNCTION;	// QQQ 何かエラーを返しておく
	}
	int input_code = DTC_CODE_ANSI;
	BOOL firstline = TRUE;
	char buf[1024*64];
	char *ptr, *eptr;
	while (fgets(buf, sizeof(buf), fp)) {
		ptr = buf;
		if (firstline) {
			if (memcmp(buf, "\xEF\xBB\xBF", 3) == 0) {	// UTF-8 BOM
				m_encoding = ENC_UTF8B;
				ptr += 3;
			}
			if ((m_encoding == ENC_UTF8N) || (m_encoding == ENC_UTF8B)) {
				input_code = DTC_CODE_UTF8;
			}
			firstline = FALSE;
		}
		eptr = ptr + strlen(ptr);
		if ((eptr > ptr) && (eptr[-1] == '\n')) {
			--eptr;
		}
		m_strLines.Add(DataToCString(ptr, eptr - ptr, input_code));	//1行追加
	}
	fclose(fp);

	return dwWin32errorCode;
}
Example #4
0
DWORD CM3u::Save(LPCTSTR szFileName)
{
	DWORD	dwWin32errorCode = ERROR_SUCCESS;

	if (lstrcmpi(getExtName(szFileName), _T(".m3u8")) == 0) {
		if ((m_encoding != ENC_UTF8N) && (m_encoding != ENC_UTF8B)) {
			m_encoding = ENC_UTF8N;
		}
	}
	int output_code = DTC_CODE_ANSI;
	if ((m_encoding == ENC_UTF8N) || (m_encoding == ENC_UTF8B)) {
		output_code = DTC_CODE_UTF8;
	}

	//ファイルをオープン
	HANDLE hFile = CreateFile(
							szFileName,
							GENERIC_READ|GENERIC_WRITE,
							FILE_SHARE_READ,
							NULL,
							CREATE_ALWAYS,	//新しいファイルを作成します。指定したファイルが既に存在している場合、そのファイルを上書きし、既存の属性を消去します。
							FILE_ATTRIBUTE_NORMAL,
							NULL);
	if(hFile == INVALID_HANDLE_VALUE)
	{
		dwWin32errorCode = GetLastError();
		return dwWin32errorCode;
	}

	DWORD dwWritten;
	if (m_encoding == ENC_UTF8B) {
		WriteFile(hFile, "\xEF\xBB\xBF", 3, &dwWritten, NULL);
	}

	//リストが空の時は0バイトのファイルを作る
	if(m_strLines.GetUpperBound() == -1)
	{
		CloseHandle(hFile);
		return dwWin32errorCode;
	}

	CString str;
	for(int i=0; i<=m_strLines.GetUpperBound(); i++)
	{
		str = m_strLines.GetAt(i);
		str += _T("\r\n");
		int size;
		char *buf = TstrToDataAlloc(str, str.GetLength(), &size, output_code);
		if (buf != NULL) {
			int ret = WriteFile(hFile,buf,size,&dwWritten,NULL);
			free(buf);
			if (!ret) {
				dwWin32errorCode = GetLastError();
				break;
			}
		}
	}
	CloseHandle(hFile);
	
	return dwWin32errorCode;
}
Example #5
0
int f_csv(ARG1) {

    char new_inv_out[STRING_SIZE];
    char name[100], desc[100], unit[100];
    FILE *out;

    unsigned int j;
    char vt[20],rt[20];
    int year, month, day, hour, minute, second;
	
    /* initialization phase */

    if (mode == -1) {
        WxText = decode = latlon = 1;
        if ((*local = (void *) ffopen(arg1,file_append ? "a" : "w")) == NULL)
		fatal_error("csv could not open file %s", arg1);  
	return 0;
    }

    /* cleanup phase */

    if (mode == -2) return 0;

    /* processing phase */

    if (lat == NULL || lon == NULL) {
	fprintf(stderr,"csv: latitude/longitude not defined, record skipped\n");
	return 0;
    }

    out = (FILE *) *local;

    /*Collect runtime and validtime into vt and rt*/

    reftime(sec, &year, &month, &day, &hour, &minute, &second);
    sprintf(rt, "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d", year,month,day,hour,minute,second);

    vt[0] = 0;
    if (verftime(sec, &year, &month, &day, &hour, &minute, &second) == 0) {
        sprintf(vt,"%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d", year,month,day,hour,minute,second);
    }

    /*Get levels, parameter name, description and unit*/

    *new_inv_out = 0;
    f_lev(call_ARG0(new_inv_out,NULL));

    if (strcmp(new_inv_out, "reserved")==0) return 0;
//    getName(sec, mode, NULL, name, desc, unit);
    getExtName(sec, mode, NULL, name, desc, unit,".","_");
//	fprintf(stderr,"Start processing of %s at %s\n", name, new_inv_out);
//	fprintf(stderr,"Gridpoints in data: %d\n", ndata);
//	fprintf(stderr,"Description: %s, Unit %s\n", desc,unit);

     /* Lage if-setning rundt hele som sjekker om alt eller deler skal ut*/

    if (WxNum > 0) {
        for (j = 0; j < ndata; j++) {
            if (!UNDEFINED_VAL(data[j])) {
	        fprintf(out,"\"%s\",\"%s\",\"%s\",\"%s\",%g,%g,\"%s\"\n",rt,vt,name,
		    new_inv_out,lon[j] > 180.0 ?  lon[j]-360.0 : lon[j],lat[j],WxLabel(data[j]));
	    }
	}
    }
    else {
        for (j = 0; j < ndata; j++) {
            if (!UNDEFINED_VAL(data[j])) {
	        fprintf(out,"\"%s\",\"%s\",\"%s\",\"%s\",%g,%g,%lg\n",rt,vt,name,
		    new_inv_out,lon[j] > 180.0 ?  lon[j]-360.0 : lon[j],lat[j],data[j]);
	    }
	}
    }
    if (flush_mode) fflush(out);
    return 0;
}
Example #6
0
CShellExt::EN_FILETYPE CShellExt::GetFileType(LPCTSTR szFileName)
{
	LPCTSTR szExt = getExtName(szFileName);
	if((lstrcmpi(szExt,_T(".mp3")) == 0) ||
		(lstrcmpi(szExt,_T(".mp2")) == 0) ||
		(lstrcmpi(szExt,_T(".mp1")) == 0) ||
		(lstrcmpi(szExt,_T(".rmp")) == 0) )
	{
		DWORD dwRet;
		HANDLE hFile = CreateFile(
					szFileName,
					GENERIC_READ,
					FILE_SHARE_READ,
					NULL,
					OPEN_EXISTING,			//指定したファイルが存在していない場合、この関数は失敗します。 
					FILE_ATTRIBUTE_NORMAL,
					NULL);
		if(hFile != INVALID_HANDLE_VALUE)
		{
			//RIFF/WAVEヘッダがある場合はWAVEとみなす
			char buf[16];
			if(ReadFile(hFile,&buf,16,&dwRet,NULL) && (dwRet == 16))
			{
				buf[4] = '_';
				buf[5] = '_';
				buf[6] = '_';
				buf[7] = '_';
				if((dwRet == 16) && (memcmp(buf,"RIFF____WAVEfmt ",16) == 0))
				{
					CloseHandle(hFile);
					return WAVE;
				}
			}
			CloseHandle(hFile);
		}
		return MP3;
	}
	/*else*/ if(lstrcmpi(szExt,_T(".wav")) == 0)
	{
		return WAVE;
	}
	/*else*/ if(lstrcmpi(szExt,_T(".avi")) == 0)
	{
		return AVI;
	}
	/*else*/ if(lstrcmpi(szExt,_T(".vqf")) == 0)
	{
		return VQF;
	}
	/*else*/ if((lstrcmpi(szExt,_T(".wma")) == 0) ||
			(lstrcmpi(szExt,_T(".wmv")) == 0) ||
			(lstrcmpi(szExt,_T(".asf")) == 0) )
	{
		return WMA;
	}
	/*else*/ if((lstrcmpi(szExt,_T(".m3u")) == 0) ||
			(lstrcmpi(szExt,_T(".m3u8")) == 0) )
	{
		return M3U;
	}
	/*else*/ if(lstrcmpi(szExt,_T(".ogg")) == 0)
	{
		return OGG;
	}
	/*else*/ if(lstrcmpi(szExt,_T(".ape")) == 0)
	{
		return APE;
	}
	/*else*/ if((lstrcmpi(szExt,_T(".mp4")) == 0) ||
			(lstrcmpi(szExt,_T(".m4v")) == 0) ||
			(lstrcmpi(szExt,_T(".m4a")) == 0) ||
			(lstrcmpi(szExt,_T(".3gp")) == 0) ||
			(lstrcmpi(szExt,_T(".3g2")) == 0) )
	{
		return MP4;
	}

	DWORD dwUseExtra=0;
	regGetDword(HKEY_CURRENT_USER,MP3INFP_REG_ENTRY,_T("UseExperimentalSupport"),&dwUseExtra,FALSE);
	if(dwUseExtra){
		if(lstrcmpi(szExt,_T(".tta")) == 0)return MP3;
		if(lstrcmpi(szExt,_T(".tak")) == 0)return APE;
	}

	return UNKNOWN;
}
/**
 * FUNCTION: xmlGenerateTag
 *
 * Generates a XML tag
 *
 * PRE-Condition:   valid parameters
 *
 * POST-Condition:  the XML tag is written to the XML buffer
 *
 * IN:              tagId, the ID for the tag to generate (TN_ADD, ...)
 *                  tagType, the tag type (e.g. Begin Tag -> TT_BEG, ...)
 *                  attFlag, indicates if the encoded tag contain Attributes in namespace extensions
 *
 * IN/OUT:          pBufMgr, pointer to a structure containing buffer management elements
 *
 * RETURN:          shows error codes of function,
 *                  0, if OK
 */
Ret_t xmlGenerateTag(XltTagID_t tagId, XltTagType_t tagType, BufferMgmtPtr_t pBufMgr, SmlPcdataExtension_t attFlag)
{
    Ret_t _err;

    MemByte_t _begpar = XML_BEGPAR;
    MemByte_t _tagdel = XML_TAGDEL;
    MemByte_t _endpar = XML_ENDPAR;
    MemByte_t _nstagstart[] = XML_NSSTART;
    MemByte_t _nstagend[]   = XML_NSEND;


    String_t _tagstr;
    String_t _tagnsattr = NULL;

    if ((_tagstr = (String_t)smlLibMalloc(XML_MAX_TAGLEN)) == NULL) return SML_ERR_NOT_ENOUGH_SPACE;

    if ((_err = getTagString(tagId, _tagstr, attFlag)) != SML_ERR_OK)  {
        smlLibFree(_tagstr);
        return _err;
    }

    if (!_tagstr)  {  // check again as _tagstr might be alterd in getTagString
        smlLibFree(_tagstr);
        return SML_ERR_XLT_INVAL_TAG_TYPE;
    }

    /* the <SyncML> tag _must_ have an xmlns attribute */
    if (attFlag != pBufMgr->smlActiveExt || tagId == TN_SYNCML) {
        // %%% luz:2003-07-31: now uses namespace from table according to version
        if (getExtName(attFlag, &_tagnsattr, pBufMgr->vers) != SML_ERR_OK) {
            smlLibFree(_tagstr);
            return  SML_ERR_XLT_INVAL_TAG_TYPE;
        }
    }
    pBufMgr->smlActiveExt = attFlag;
    //check if content byte has to be added to the tag
    switch (tagType)
    {
    // set the end tag
    case TT_END:
    {
        if ((_err = xltAddToBuffer((MemPtr_t)(&_begpar), 1, pBufMgr)) != SML_ERR_OK) break;
        if ((_err = xltAddToBuffer((MemPtr_t)(&_tagdel), 1, pBufMgr)) != SML_ERR_OK) break;
        if ((_err = xltAddToBuffer((MemPtr_t)_tagstr, smlLibStrlen(_tagstr), pBufMgr)) != SML_ERR_OK) break;
        if ((_err = xltAddToBuffer((MemPtr_t)(&_endpar), 1, pBufMgr)) != SML_ERR_OK) break;
        if (tagId == pBufMgr->switchExtTag) {
            pBufMgr->smlActiveExt = pBufMgr->smlLastExt;
            pBufMgr->smlCurExt    = pBufMgr->smlLastExt;
            pBufMgr->smlLastExt   = attFlag;
        }
        // just forget the stored number ob bytes for this end-tag since written now
        pBufMgr->endTagSize -= (3 + smlLibStrlen(_tagstr));
        break;
    }
    //Empty tag
    case TT_ALL:
    {
        if ((_err = xltAddToBuffer((MemPtr_t)(&_begpar), 1, pBufMgr)) != SML_ERR_OK) break;
        if ((_err = xltAddToBuffer((MemPtr_t)_tagstr, smlLibStrlen(_tagstr), pBufMgr)) != SML_ERR_OK) break;
        if (_tagnsattr) {
            if ((_err = xltAddToBuffer((MemPtr_t)(&_nstagstart), 8, pBufMgr)) != SML_ERR_OK) break;
            if ((_err = xltAddToBuffer((MemPtr_t)_tagnsattr, smlLibStrlen(_tagnsattr), pBufMgr)) != SML_ERR_OK) break;
            if ((_err = xltAddToBuffer((MemPtr_t)&_nstagend, 1, pBufMgr)) != SML_ERR_OK) break;
        }
        if ((_err = xltAddToBuffer((MemPtr_t)(&_tagdel), 1, pBufMgr)) != SML_ERR_OK) break;
        if ((_err = xltAddToBuffer((MemPtr_t)(&_endpar), 1, pBufMgr)) != SML_ERR_OK) break;

        break;
    }
    //Only Begin Tag -> content follows -> content byte has to be added
    case TT_BEG:
    {
        if ((_err = xltAddToBuffer((MemPtr_t)(&_begpar), 1, pBufMgr)) != SML_ERR_OK) break;
        if ((_err = xltAddToBuffer((MemPtr_t)_tagstr, smlLibStrlen(_tagstr), pBufMgr)) != SML_ERR_OK) break;
        if (_tagnsattr) {
            if ((_err = xltAddToBuffer((MemPtr_t)&_nstagstart, 8, pBufMgr)) != SML_ERR_OK) break;
            if ((_err = xltAddToBuffer((MemPtr_t)_tagnsattr, smlLibStrlen(_tagnsattr), pBufMgr)) != SML_ERR_OK) break;
            if ((_err = xltAddToBuffer((MemPtr_t)&_nstagend, 1, pBufMgr)) != SML_ERR_OK) break;
        }
        if ((_err = xltAddToBuffer((MemPtr_t)(&_endpar), 1, pBufMgr)) != SML_ERR_OK) break;

        // remember the number of byte that must follow for the according  end-tag
        pBufMgr->endTagSize += (3 + smlLibStrlen(_tagstr));
        break;
    }
    default:
    {
        smlLibFree(_tagstr);
        smlLibFree(_tagnsattr);
        return SML_ERR_XLT_INVAL_TAG_TYPE;
    }
    }
    smlLibFree(_tagstr);
    smlLibFree(_tagnsattr);
    return _err;
}