// 读取文件数据 bool FileGetData(LPTSTR fileName, char* fileBuffer, int fileSize) { // 获取文件名 FileGetName(fileName); // 文件句柄 HANDLE hFile = CreateFile(TheFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); // 读取字节数 DWORD dSize = 0; // 无法打开文件 if(hFile==INVALID_HANDLE_VALUE){ return false; } // 读取文件 if(!ReadFile(hFile,fileBuffer,fileSize,&dSize,NULL)){ return false; } // 关闭文件句柄 CloseHandle(hFile); return true; }
void PhoneGapFile::actionResolveLocalFileSystemURI(JSONMessage& message) { String callbackID = message.getParam("PhoneGapCallBackId"); String uri = message.getArgsField("uri"); // Get path. const char* pURL = uri.c_str(); const char* pPath = strstr(pURL, "file://"); if (NULL == pPath) { callFileError(callbackID, "1000"); return; } if (pURL != pPath) { callFileError(callbackID, FILEERROR_SYNTAX_ERR); return; } // Move to after "file://" pPath += 7; // Check that this is an existing directory. if (!FileIsDirectory(pPath)) { callFileError(callbackID, FILEERROR_NOT_FOUND_ERR); return; } String entry = emitDirectoryEntry( FileGetName(pPath), pPath); callSuccess( callbackID, entry, "window.localFileSystem._castEntry"); }
/** * Return a File object. */ void PhoneGapFile::actionGetFileMetadata(JSONMessage& message) { String callbackID = message.getParam("PhoneGapCallBackId"); String fullPath = message.getArgsField("fullPath"); char sizeBuf[64]; sprintf(sizeBuf, "%i", FileGetSize(fullPath)); String file = emitFile( FileGetName(fullPath), fullPath, FileGetMimeType(fullPath), FileGetDate(fullPath), sizeBuf); // Note that _castDate also casts a File object. callSuccess( callbackID, file, "window.localFileSystem._castDate"); }
BOOL SaveChart (HWND hWndGraph, HANDLE hInputFile, BOOL bGetFileName) { PGRAPHSTRUCT pGraph ; PLINE pLine ; HANDLE hFile ; DISKCHART DiskChart ; PERFFILEHEADER FileHeader ; TCHAR szFileName [256] ; BOOL newFileName = FALSE ; if (hInputFile) { // use the input file handle if it is available // this is the case for saving workspace data hFile = hInputFile ; } else { if (pChartFullFileName) { lstrcpy (szFileName, pChartFullFileName) ; } if (bGetFileName || pChartFullFileName == NULL) { // if (!pChartFullFileName) // { // StringLoad (IDS_GRAPH_FNAME, szFileName) ; // } if (!FileGetName (hWndGraph, IDS_CHARTFILE, szFileName)) { return (FALSE) ; } newFileName = TRUE ; } hFile = FileHandleCreate (szFileName) ; if (hFile && newFileName) { ChangeSaveFileName (szFileName, IDM_VIEWCHART) ; } else if (!hFile) { DlgErrorBox (hWndGraph, ERR_CANT_OPEN, szFileName) ; } } if (!hFile) return (FALSE) ; pGraph = pGraphs ; if (!pGraph) { if (!hInputFile) { CloseHandle (hFile) ; } return (FALSE) ; } if (!hInputFile) { // only need to write file header if not workspace memset (&FileHeader, 0, sizeof (FileHeader)) ; lstrcpy (FileHeader.szSignature, szPerfChartSignature) ; FileHeader.dwMajorVersion = ChartMajorVersion ; FileHeader.dwMinorVersion = ChartMinorVersion ; if (!FileWrite (hFile, &FileHeader, sizeof (PERFFILEHEADER))) { goto Exit0 ; } } DiskChart.Visual = pGraph->Visual ; DiskChart.gOptions = pGraph->gOptions ; DiskChart.gMaxValues = pGraph->gMaxValues ; DiskChart.dwNumLines = NumLines (pGraph->pLineFirst) ; DiskChart.bManualRefresh = pGraph->bManualRefresh ; DiskChart.perfmonOptions = Options ; if (!FileWrite (hFile, &DiskChart, sizeof (DISKCHART))) { goto Exit0 ; } for (pLine = pGraph->pLineFirst ; pLine ; pLine = pLine->pLineNext) { // for if (!WriteLine (pLine, hFile)) { goto Exit0 ; } } // for if (!hInputFile) { CloseHandle (hFile) ; } return (TRUE) ; Exit0: if (!hInputFile) { CloseHandle (hFile) ; // only need to report error if not workspace DlgErrorBox (hWndGraph, ERR_SETTING_FILE, szFileName) ; } return (FALSE) ; } // SaveChart
// This routine opens the export file and put in the header info. // It is used by ExportChart, ExportAlert, & ExportReport. INT ExportFileOpen (HWND hWnd, HANDLE *phFile, int IntervalMSecs, LPTSTR *ppFileName) { CHAR TempBuff [LongTextLen] ; TCHAR UnicodeBuff [LongTextLen] ; TCHAR UnicodeBuff1 [MiscTextLen] ; SYSTEMTIME SystemTime ; int StringLen ; INT ErrCode = 0 ; FLOAT eIntervalSecs ; // defined and setup in status.c extern TCHAR szCurrentActivity [] ; extern TCHAR szStatusFormat [] ; *phFile = 0 ; if (!FileGetName (hWnd, IDS_EXPORTFILE, UnicodeBuff)) { // user cancel goto Exit0 ; } *ppFileName = StringAllocate (UnicodeBuff) ; // open the file.. if (!(*phFile = FileHandleCreate (UnicodeBuff))) { // can't open the file ErrCode = ERR_CANT_OPEN ; goto Exit0 ; } // export header StringLoad (IDS_REPORT_HEADER, UnicodeBuff) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; StringLen = strlen (TempBuff) ; ConvertUnicodeStr (&TempBuff[StringLen], LocalComputerName) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } // export today's date time GetLocalTime (&SystemTime) ; StringLoad (IDS_EXPORT_DATE, UnicodeBuff) ; StringLen = lstrlen (UnicodeBuff) ; UnicodeBuff[StringLen] = TEXT(':') ; UnicodeBuff[StringLen+1] = TEXT(' ') ; SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen+2]) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } StringLoad (IDS_EXPORT_TIME, UnicodeBuff) ; StringLen = lstrlen (UnicodeBuff) ; UnicodeBuff[StringLen] = TEXT(':') ; UnicodeBuff[StringLen+1] = TEXT(' ') ; SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen+2], FALSE) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } // export data source TSPRINTF (UnicodeBuff, szStatusFormat, PlayingBackLog () ? PlaybackLog.szFileTitle : szCurrentActivity) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } if (!PlayingBackLog()) { eIntervalSecs = (FLOAT)IntervalMSecs / (FLOAT) 1000.0 ; StringLoad (IDS_CHARTINT_FORMAT, UnicodeBuff1) ; TSPRINTF (UnicodeBuff, UnicodeBuff1, eIntervalSecs) ; ConvertDecimalPoint (UnicodeBuff) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } } else { // export the log start and stop date/time StringLoad (IDS_START_TEXT, UnicodeBuff) ; StringLen = lstrlen (UnicodeBuff) ; LogPositionSystemTime (&(PlaybackLog.StartIndexPos), &SystemTime) ; SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen]) ; StringLen = lstrlen (UnicodeBuff) ; UnicodeBuff[StringLen] = TEXT(' ') ; StringLen++ ; SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen], FALSE) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } StringLoad (IDS_STOP_TEXT, UnicodeBuff) ; StringLen = lstrlen (UnicodeBuff) ; LogPositionSystemTime (&(PlaybackLog.StopIndexPos), &SystemTime) ; SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen]) ; StringLen = lstrlen (UnicodeBuff) ; UnicodeBuff[StringLen] = TEXT(' ') ; StringLen++ ; SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen], FALSE) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } if (hWnd == hWndAlert) { eIntervalSecs = (FLOAT)IntervalMSecs / (FLOAT) 1000.0 ; StringLoad (IDS_CHARTINT_FORMAT, UnicodeBuff1) ; TSPRINTF (UnicodeBuff, UnicodeBuff1, eIntervalSecs) ; ConvertDecimalPoint (UnicodeBuff) ; ConvertUnicodeStr (TempBuff, UnicodeBuff) ; strcat (TempBuff, LineEndStr) ; if (!FileWrite (*phFile, TempBuff, strlen(TempBuff))) { ErrCode = ERR_EXPORT_FILE ; goto Exit0 ; } } } return (0) ; Exit0: return (ErrCode) ; } // ExportFileOpen
// mosync://PhoneGap?service=File&action=readEntries&args={"fullPath":"/mnt/sdcard/fob1"}& // PhoneGapCallBackId=File21 void PhoneGapFile::actionReadEntries(JSONMessage& message) { String callbackID = message.getParam("PhoneGapCallBackId"); String path = message.getArgsField("fullPath"); // Open entry array. String entries = "["; char nameBuf[2048]; // Make sure path end with a slash. FileMakeDirectoryPath(path); // Open directory listing. MAHandle list = maFileListStart( path.c_str(), "", MA_FL_SORT_NAME | MA_FL_ORDER_ASCENDING); if (list < 0) { callFileError(callbackID, FILEERROR_NOT_FOUND_ERR); return; } // List all files in this directory. while (true) { // Move to next file. int result = maFileListNext(list, nameBuf, 2048); if (0 == result) { // No more files. break; } if (0 > result) { maFileListClose(list); callFileError(callbackID, FILEERROR_NOT_FOUND_ERR); return; } // Add separating comma if needed. if (entries.size() > 1) { entries += ","; } // Full path to entry. String fullPath = path + nameBuf; // Is this a directory? if ('/' == nameBuf[result - 1]) { // We remove the trailing slash of the directory. String pathWithNoSlash = fullPath.substr(0, fullPath.size() - 1); String entry = emitDirectoryEntry( FileGetName(pathWithNoSlash), pathWithNoSlash); entries += entry; } else { String entry = emitFileEntry( FileGetName(fullPath), fullPath); entries += entry; } } // Close the directory listing. maFileListClose(list); // Close entry array. entries += "]"; // Return result to PhoneGap. callSuccess( callbackID, entries, "window.localFileSystem._castEntries"); }
int main(int argc, char *argv[]) { char name[100]; lst = stderr; if (argc == 1) { Help(); exit(EXIT_FAILURE); } InitFrameVars(); source_name[0] = '\0'; param_options(argc, argv); /* check on correct parameter usage */ if (source_name[0] == 0) { fprintf(stderr, "No input file specified"); exit(EXIT_FAILURE); } /* open the Source file (Scanner.S_src) */ if ((S_src = open(source_name, O_RDONLY|O_BINARY)) == -1) { fprintf(stderr, "Unable to open input file %s\n", source_name); exit(EXIT_FAILURE); } /* open the listing file */ if (L_option) { FileGetName(name, source_name); strcat(name, ".lst"); lstfile = OpenFile(name, "w", 1); } else if (!Q_option) lstfile = stderr; else lstfile = stdout; /* install error reporting procedure */ Custom_Error = (Error_Func) StoreError; InitTab(); InitScannerTab(); Parse(); close(S_src); lst = lstfile; if (Errors && !L_option) SummarizeErrors(); else if (Errors || L_option) PrintListing(); if (Errors) { /* Check for Syntax Errors */ fclose(lstfile); exit(EXIT_FAILURE); } MakeScanner(); MakeParser(); if (Errors) { /* Check for LL(1) Errors, Undeclared Symbols, etc */ fclose(lstfile); exit(EXIT_FAILURE); } SetupFrameVars(); if (!T_option) { if (!P_option) GenScanner(); GenParser(); GenHeaders(); if (C_option) GenCompiler(); } if (L_option) { if (S_option) { ShowClassTab(); ShowTermTab(); ShowCommentTab(); ShowSymSetTab(); ShowNTermTab(); } if (A_option) ShowDFA(); fclose(lstfile); } DoneTab(); DoneScannerTab(); return (EXIT_SUCCESS); }