int ScanTimeFrame (char *tstring, time_t * t_start, time_t * t_end) { char *p; if (!tstring) { fprintf (stderr, "Time Window format error '%s'\n", tstring); return 0; } // check for delta time window if (tstring[0] == '-' || tstring[0] == '+') { if (!twin_first || !twin_last) { fprintf (stderr, "Time Window error: No time slot information available\n"); return 0; } if (tstring[0] == '-') { *t_start = twin_last + atoi (tstring); *t_end = twin_last; return 1; } if (tstring[0] == '+') { *t_start = twin_first; *t_end = twin_first + atoi (tstring); return 1; } } if (strlen (tstring) < 4) { fprintf (stderr, "Time Window format error '%s'\n", tstring); return 0; } if ((p = strchr (tstring, '-')) == NULL) { ParseTime (tstring, t_start); *t_end = 0xFFFFFFFF; } else { *p++ = 0; ParseTime (tstring, t_start); ParseTime (p, t_end); } return *t_start == 0 || *t_end == 0 ? 0 : 1; } // End of ScanTimeFrame
PR_IMPLEMENT(nsresult) NS_TimelineMarkTimer(const char *timerName, const char *str) { PR_CallOnce(&initonce, TimelineInit); if (gTimelineDisabled) return NS_ERROR_NOT_AVAILABLE; TimelineThreadData *thread = GetThisThreadData(); if (thread->timers == NULL) return NS_ERROR_FAILURE; if (thread->disabled) return NS_ERROR_NOT_AVAILABLE; nsTimelineServiceTimer *timer = (nsTimelineServiceTimer *)PL_HashTableLookup(thread->timers, timerName); if (timer == NULL) { return NS_ERROR_FAILURE; } PRTime accum = timer->getAccum(); char buf[500]; PRInt32 sec, msec; ParseTime(accum, sec, msec); if (!str) PR_snprintf(buf, sizeof buf, "%s total: %d.%03d", timerName, sec, msec); else PR_snprintf(buf, sizeof buf, "%s total: %d.%03d (%s)", timerName, sec, msec, str); NS_TimelineMark(buf); return NS_OK; }
void FTextureManager::ParseRangeAnim (FScanner &sc, FTextureID picnum, int usetype, bool missing) { int type; FTextureID framenum; DWORD min, max; type = FAnimDef::ANIM_Forward; framenum = ParseFramenum (sc, picnum, usetype, missing); ParseTime (sc, min, max); if (framenum == picnum || !picnum.Exists()) { return; // Animation is only one frame or does not exist } if (framenum < picnum) { type = FAnimDef::ANIM_Backward; Texture(framenum)->bNoDecals = Texture(picnum)->bNoDecals; swapvalues (framenum, picnum); } if (sc.GetString()) { if (sc.Compare ("Oscillate")) { type = type == FAnimDef::ANIM_Forward ? FAnimDef::ANIM_OscillateUp : FAnimDef::ANIM_OscillateDown; } else { sc.UnGet (); } } AddSimpleAnim (picnum, framenum - picnum + 1, type, min, max - min); }
FAnimDef *FTextureManager::ParseRangeAnim (FScanner &sc, FTextureID picnum, int usetype, bool missing) { int type; FTextureID framenum; DWORD min, max; type = FAnimDef::ANIM_Forward; framenum = ParseFramenum (sc, picnum, usetype, missing); ParseTime (sc, min, max); if (framenum == picnum || !picnum.Exists() || !framenum.Exists()) { return NULL; // Animation is only one frame or does not exist } if (Texture(framenum)->Name.IsEmpty()) { // long texture name: We cannot do ranged anims on these because they have no defined order sc.ScriptError ("You cannot use \"range\" for long texture names."); } if (framenum < picnum) { type = FAnimDef::ANIM_Backward; Texture(framenum)->bNoDecals = Texture(picnum)->bNoDecals; swapvalues (framenum, picnum); } FAnimDef *ani = AddSimpleAnim (picnum, framenum - picnum + 1, min, max - min); if (ani != NULL) ani->AnimType = type; return ani; }
//------------------------------------------------------------------------------ bool TcopsVHFAscii::ParseDataBlock() { bool retval = false; for (UnsignedInt i = 0; i < supportedFields.size(); ++i) { std::string theField = supportedFields[i]; if (readAllSupportedFields || (find(selectedFields.begin(), selectedFields.end(), theField) != selectedFields.end())) { // Read the data block looking for a file string match for (UnsignedInt i = 0; i < dataBuffer.size(); ++i) { if (dataBuffer[i].find(fileStringMap[theField])!=std::string::npos) { switch (dataType[theField]) { case READER_REAL: if (ParseRealValue(i, theField)) retval = true;; break; case READER_RVECTOR6: { // Set up for the Cartesian State scan StringArray theIds; theIds.push_back("X "); // ' ' to distinguish from XDOT, theIds.push_back("Y "); // YDOT, and ZDOT theIds.push_back("Z "); theIds.push_back("XDOT"); theIds.push_back("YDOT"); theIds.push_back("ZDOT"); // And find it if (ParseRvector6Value(i, theField, theIds)) retval = true; } break; case READER_STRING: case READER_TIMESTRING: if (ParseStringValue(i, theField)) { if (dataType[theField] == READER_TIMESTRING) ParseTime(theField); retval = true; } break; default: // Skip the other types (basically the subtypes) break; } } } } } return retval; }
static bool Copy(RecordedFlightInfo &dest, const LX::FlightInfo &src) { if (!ParseDate(dest.date, src.date) || !ParseTime(dest.start_time, src.start_time) || !ParseTime(dest.end_time, src.stop_time)) return false; dest.internal.lx.start_address[0] = src.start_address.address0; dest.internal.lx.start_address[1] = src.start_address.address1; dest.internal.lx.start_address[2] = src.start_address.address2; dest.internal.lx.end_address[0] = src.end_address.address0; dest.internal.lx.end_address[1] = src.end_address.address1; dest.internal.lx.end_address[2] = src.end_address.address2; return true; }
// // Updates the time displayed on the 7-segment display. Will turn on one digit, and // turn off all others. The time is input in 24-hour mode, and then parsed before being // displayed. // void UpdateTime(int digit, int hours, int minutes) { ParseTime(hours, minutes); if( digit == 1 && digitNumber[0] == 0 ) return; if( digit == 5 ) DisplayTime(digit, 10); else DisplayTime(digit, digitNumber[digit - 1]); }
bool ObjIeeeAscii::ModuleDate(const char *buffer, eParseType ParseType) { if (!file) ThrowSyntax(buffer, ParseType); std::tm time; int pos = 2; ParseTime(buffer, time, &pos); CheckTerm(buffer + pos); file->SetFileTime(time); return false; }
bool CCommandLineParser::GetOption(LPCWSTR pszKey,FILETIME *pTime) const { if (IsStringEmpty(pszKey) || pTime==nullptr) return false; auto i=m_OptionMap.find(pszKey); if (i==m_OptionMap.end() || i->second+1>=m_ArgCount) return false; if (!ParseTime(m_ppszArgList[i->second+1],pTime)) return false; return true; }
static void PrintTime(PRTime tm, const char *text, va_list args) { PRInt32 secs, msecs; char pbuf[550], *pc, tbuf[550]; ParseTime(tm, secs, msecs); // snprintf/write rather than fprintf because we don't want // messages from multiple threads to garble one another. pc = Indent(pbuf); PR_vsnprintf(pc, sizeof pbuf - (pc - pbuf), text, args); PR_snprintf(tbuf, sizeof tbuf, "%05d.%03d (%08p): %s\n", secs, msecs, PR_GetCurrentThread(), pbuf); PR_Write(timelineFD, tbuf, strlen(tbuf)); }
void FTextureManager::ParsePicAnim (FScanner &sc, FTextureID picnum, int usetype, bool missing, TArray<FAnimDef::FAnimFrame> &frames) { FTextureID framenum; DWORD min = 1, max = 1; framenum = ParseFramenum (sc, picnum, usetype, missing); ParseTime (sc, min, max); if (picnum.isValid()) { FAnimDef::FAnimFrame frame; frame.SpeedMin = min; frame.SpeedRange = max - min; frame.FramePic = framenum; frames.Push (frame); } }
void CPlayerSubresyncBar::OnNMDblclkList(NMHDR* pNMHDR, LRESULT* pResult) { LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)pNMHDR; if (lpnmlv->iItem >= 0 && lpnmlv->iSubItem >= 0 && (m_mode == VOBSUB || m_mode == TEXTSUB)) { if (CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd()) { int t = 0; if (lpnmlv->iSubItem > COL_PREVEND || !ParseTime(m_list.GetItemText(lpnmlv->iItem, lpnmlv->iSubItem), t, false)) { t = m_sts[lpnmlv->iItem].start; } REFERENCE_TIME rt = (REFERENCE_TIME)t * 10000; pFrame->SeekTo(rt); } } *pResult = 0; }
//---------------------------------------------------- bool wxBratTools::ParseTime(const wxString& value, wxTimeSpan& ts, wxString& error) { wxDateTime dt; bool bOk = ParseTime(value, dt, error); if (!bOk) { return bOk; } wxTimeSpan tsTemp(dt.GetHour(), dt.GetMinute()); ts = tsTemp; //ts = wxTimeSpan::Hours(dt.GetHour()); //ts += wxTimeSpan::Hours(dt.GetMinute()); return bOk; }
bool Parser::ParseForTrainer(char *msg) { char *end; int n; static char buffer[MAX_MESSAGE]; if (msg[6] == 'r') // 跳过括号和hear,referee { ParseTime(msg, &msg, true); parser::get_word(&msg); end = msg; while (*end != ')') end++; n = end - msg; strncpy(buffer, msg, n * sizeof(char)); buffer[n] = '\0'; ParseRefereeMsg(buffer); return true; } else return false; }
bool FlytecDevice::ReadFlightList(RecordedFlightList &flight_list, OperationEnvironment &env) { port.StopRxThread(); char buffer[256]; strcpy(buffer, "$PBRTL,"); AppendNMEAChecksum(buffer); strcat(buffer, "\r\n"); port.Write(buffer); if (!ExpectXOff(port, env, 1000)) return false; unsigned tracks = 0; while (true) { // Check if the user cancelled the operation if (env.IsCancelled()) return false; // Receive the next line if (!ReceiveLine(port, buffer, ARRAY_SIZE(buffer), 1000)) return false; // XON was received, last record was read already if (StringIsEmpty(buffer)) break; // $PBRTL Identifier // AA total number of stored tracks // BB actual number of track (0 indicates the most actual track) // DD.MM.YY date of recorded track (UTC)(e.g. 24.03.04) // hh:mm:ss starttime (UTC)(e.g. 08:23:15) // HH:MM:SS duration (e.g. 03:23:15) // *ZZ Checksum as defined by NMEA RecordedFlightInfo flight; NMEAInputLine line(buffer); // Skip $PBRTL line.Skip(); if (tracks == 0) { // If number of tracks not read yet // .. read and save it if (!line.ReadChecked(tracks)) continue; env.SetProgressRange(tracks); } else line.Skip(); if (!line.ReadChecked(flight.internal.flytec)) continue; if (tracks != 0 && flight.internal.flytec < tracks) env.SetProgressPosition(flight.internal.flytec); char field_buffer[16]; line.Read(field_buffer, ARRAY_SIZE(field_buffer)); if (!ParseDate(field_buffer, flight.date)) continue; line.Read(field_buffer, ARRAY_SIZE(field_buffer)); if (!ParseTime(field_buffer, flight.start_time)) continue; BrokenTime duration; line.Read(field_buffer, ARRAY_SIZE(field_buffer)); if (!ParseTime(field_buffer, duration)) continue; flight.end_time = flight.start_time + duration; flight_list.append(flight); } return true; }
/** * Main demux callback function * @param p_demux: this demux object */ static int Demux( demux_t *p_demux ) { char *psz_line; char *psz_artist = NULL, *psz_album = NULL, *psz_genre = NULL, *psz_year = NULL; char *psz_author = NULL, *psz_title = NULL, *psz_copyright = NULL, *psz_cdnum = NULL, *psz_comments = NULL; mtime_t i_duration = -1; const char **ppsz_options = NULL; int i_options = 0, i_start = 0, i_stop = 0; bool b_cleanup = false; input_item_t *p_input; input_item_t *p_current_input = GetCurrentItem(p_demux); input_item_node_t *p_subitems = input_item_node_Create( p_current_input ); psz_line = vlc_stream_ReadLine( p_demux->s ); while( psz_line ) { char *psz_parse = psz_line; /* Skip leading tabs and spaces */ while( *psz_parse == ' ' || *psz_parse == '\t' || *psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++; if( *psz_parse == '#' ) { /* Ignore comments */ } else if( *psz_parse ) { char *psz_mrl, *psz_option_next, *psz_option; char *psz_param, *psz_value; /* Get the MRL from the file. Note that this might contain parameters of form ?param1=value1¶m2=value2 in a RAM file */ psz_mrl = ProcessMRL( psz_parse, p_demux->p_sys->psz_prefix ); b_cleanup = true; if ( !psz_mrl ) goto error; /* We have the MRL, now we have to check for options and parse them from MRL */ psz_option = strchr( psz_mrl, '?' ); /* Look for start of options */ if( psz_option ) { /* Remove options from MRL because VLC can't get the file otherwise */ *psz_option = '\0'; psz_option++; psz_option_next = psz_option; while( 1 ) /* Process each option */ { /* Look for end of first option which maybe a & or \0 */ psz_option = psz_option_next; psz_option_next = strchr( psz_option, '&' ); if( psz_option_next ) { *psz_option_next = '\0'; psz_option_next++; } else psz_option_next = strchr( psz_option, '\0' ); /* Quit if options are over */ if( psz_option_next == psz_option ) break; /* Parse out param and value */ psz_param = psz_option; psz_value = strchr( psz_option, '=' ); if( psz_value == NULL ) break; *psz_value = '\0'; psz_value++; /* Take action based on parameter value in the below if else structure */ /* TODO: Remove any quotes surrounding values if required */ if( !strcmp( psz_param, "clipinfo" ) ) { ParseClipInfo( psz_value, &psz_artist, &psz_title, &psz_album, &psz_genre, &psz_year, &psz_cdnum, &psz_comments ); /* clipinfo has various sub parameters, which is parsed by this function */ } else if( !strcmp( psz_param, "author" ) ) { psz_author = vlc_uri_decode_duplicate(psz_value); EnsureUTF8( psz_author ); } else if( !strcmp( psz_param, "start" ) && strncmp( psz_mrl, "rtsp", 4 ) /* Our rtsp-real or our real demuxer is wrong */ ) { i_start = ParseTime( psz_value, strlen( psz_value ) ); char *temp; if( i_start ) { if( asprintf( &temp, ":start-time=%d", i_start ) != -1 ) INSERT_ELEM( ppsz_options, i_options, i_options, temp ); } } else if( !strcmp( psz_param, "end" ) ) { i_stop = ParseTime( psz_value, strlen( psz_value ) ); char *temp; if( i_stop ) { if( asprintf( &temp, ":stop-time=%d", i_stop ) != -1 ) INSERT_ELEM( ppsz_options, i_options, i_options, temp ); } } else if( !strcmp( psz_param, "title" ) ) { free( psz_title ); psz_title = vlc_uri_decode_duplicate(psz_value); EnsureUTF8( psz_title ); } else if( !strcmp( psz_param, "copyright" ) ) { psz_copyright = vlc_uri_decode_duplicate(psz_value); EnsureUTF8( psz_copyright ); } else { /* TODO: insert option anyway? Currently ignores*/ /* INSERT_ELEM( ppsz_options, i_options, i_options, psz_option ); */ } } } /* Create the input item and pump in all the options into playlist item */ p_input = input_item_NewExt( psz_mrl, psz_title, i_duration, ITEM_TYPE_UNKNOWN, ITEM_NET_UNKNOWN ); if( !p_input ) { free( psz_mrl ); goto error; } input_item_AddOptions( p_input, i_options, ppsz_options, 0 ); if( !EMPTY_STR( psz_artist ) ) input_item_SetArtist( p_input, psz_artist ); if( !EMPTY_STR( psz_author ) ) input_item_SetPublisher( p_input, psz_author ); if( !EMPTY_STR( psz_title ) ) input_item_SetTitle( p_input, psz_title ); if( !EMPTY_STR( psz_copyright ) ) input_item_SetCopyright( p_input, psz_copyright ); if( !EMPTY_STR( psz_album ) ) input_item_SetAlbum( p_input, psz_album ); if( !EMPTY_STR( psz_genre ) ) input_item_SetGenre( p_input, psz_genre ); if( !EMPTY_STR( psz_year ) ) input_item_SetDate( p_input, psz_year ); if( !EMPTY_STR( psz_cdnum ) ) input_item_SetTrackNum( p_input, psz_cdnum ); if( !EMPTY_STR( psz_comments ) ) input_item_SetDescription( p_input, psz_comments ); input_item_node_AppendItem( p_subitems, p_input ); vlc_gc_decref( p_input ); free( psz_mrl ); } error: /* Fetch another line */ free( psz_line ); psz_line = vlc_stream_ReadLine( p_demux->s ); if( !psz_line ) b_cleanup = true; if( b_cleanup ) { /* Cleanup state */ while( i_options-- ) free( (char*)ppsz_options[i_options] ); FREENULL( ppsz_options ); FREENULL( psz_artist ); FREENULL( psz_title ); FREENULL( psz_author ); FREENULL( psz_copyright ); FREENULL( psz_album ); FREENULL( psz_genre ); FREENULL( psz_year ); FREENULL( psz_cdnum ); FREENULL( psz_comments ); i_options = 0; i_duration = -1; i_start = 0; i_stop = 0; b_cleanup = false; } } input_item_node_PostAndDelete( p_subitems ); vlc_gc_decref(p_current_input); var_Destroy( p_demux, "m3u-extvlcopt" ); return 0; /* Needed for correct operation of go back */ }
void Parser::Parse(char *msg) { ServerMsgType msg_type = None_Msg; /** * 住个字符分析 获得msg中第一条信息的信息类型 * ( MsgTpe Time ((objname) objprop) ) * ^ * | */ switch ( msg[1] ) { case 'i': msg_type = Initialize_Msg; break; /* ( i nit */ case 'c': switch (msg[2]){ case 'h': msg_type = ChangePlayerType_Msg; break; /* ( c h ange */ case 'l': msg_type = Clang_Msg; break; /* ( c l ang */ } break; case 'd': msg_type = Disp_Msg; break; /* (d isp */ case 'e': msg_type = Error_Msg; break; /* ( e rror */ case 'f': msg_type = Fullstate_Msg; break; /* ( f ullstate */ case 'h': msg_type = Hear_Msg; break; /* ( h ear */ case 'o': msg_type = Ok_Msg; break; /* ( o k */ case 'p': switch( msg[8] ) { case 'p': msg_type = PlayerParam_Msg; break; /* (p layer_ p ram */ case 't': msg_type = PlayerType_Msg; break; /* ( p layer_ t ype */ default: msg_type = None_Msg; break; } break; case 's': switch( msg[3]) { case 'o': msg_type = Score_Msg; break; /* ( s c o re */ case 'e': switch( msg[4]){ case ' ': msg_type = Sight_Msg; break; /* ( s e e */ case '_': msg_type = CoachSight_Msg; break; /* ( s e e _global */ default: msg_type = None_Msg; break; } break; case 'n': msg_type = Sense_Msg; break; /* ( s e n se_body */ case 'r': msg_type = ServerParam_Msg; break; /* ( s e r ver_param */ default: msg_type = None_Msg; break; } break; default: msg_type = None_Msg; break; } /** * 根据信息类型调用对应专用的的解释函数 * ( MsgTpe Time ((objname) objprop) ) * ^ ^ * | | * msg timeend * 共同之处有 * 先分析Time */ char *time_end = 0; switch (msg_type){ case Sight_Msg: ParseTime(msg, &time_end, false); ParseSight(time_end); mpObserver->SetNewSight(); break; case CoachSight_Msg: ParseTime(msg, &time_end, true); ParseSight_Coach(time_end); mpObserver->SetNewSight(); break; case Sense_Msg: ParseTime(msg, &time_end, true); ParseSense(time_end); mpObserver->SetNewSense(); break; case Hear_Msg: if(!ParseForTrainer(msg)){ ParseTime(msg, &time_end, true); ParseSound(time_end); }break; case PlayerParam_Msg: ParsePlayerParam(msg); break; case ServerParam_Msg: ParseServerParam(msg); break; case Disp_Msg: /*TODO: process disp message */ break; case Fullstate_Msg: /*TODO: disable null processing */ break; case ChangePlayerType_Msg: ParseChangePlayerType(msg); break; case Clang_Msg: /*TODO: process clang message*/ break; case PlayerType_Msg: ParsePlayerType(msg); break; case Score_Msg: /*TODO: process score message*/ break; case Ok_Msg: ParseOkMsg(msg); break; case Initialize_Msg: ParseInitializeMsg(msg); break; case Error_Msg: std::cout << __LINE__ << " Cycle: " << mpObserver->CurrentTime() << "; msg : " << msg << std::endl; break; case None_Msg: PRINT_ERROR(mpObserver->CurrentTime() << msg); break; } }
bool ObjIeeeAscii::Comment(const char *buffer, eParseType ParseType) { if (!file) ThrowSyntax(buffer, ParseType); int pos = 2; int cnum = ObjUtil::FromDecimal(buffer, &pos,3); if (buffer[pos++] != ',') ThrowSyntax(buffer, ParseType); ObjString contents = ParseString(buffer, &pos); const char *data = contents.c_str(); CheckTerm(buffer + pos); switch (cnum) { case eAbsolute: absolute = true; // absolute file break; case eMakePass: if (ParseType == eMake) return true; break; case eLinkPass: if (ParseType == eLink) return true; break; case eBrowsePass: if (ParseType == eBrowse) return true; break; case eConfig: /* not supported */ break; case eDefinition: { int pos = 0; ObjString name = ParseString(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); ObjInt value = ObjUtil::FromDecimal(data, &pos); ObjDefinitionSymbol *sym = factory->MakeDefinitionSymbol(name); sym->SetValue(value); file->Add(sym); break; } case eExport: { bool byOrdinal; if (data[0] == 'O') byOrdinal = true; else if (data[0] == 'N') byOrdinal = false; else ThrowSyntax(buffer, ParseType); if (data[1] != ',') ThrowSyntax(buffer, ParseType); int pos = 2; ObjString name = ParseString(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); ObjString externalName; int ordinal = 0xffffffff; if (byOrdinal) ordinal = ObjUtil::FromDecimal(data, &pos); else externalName = ParseString(data, &pos); ObjString moduleName; if (data[pos] == ',') { pos++; moduleName = ParseString(data, &pos); } if (!GetCaseSensitiveFlag()) { for (int i=0; i < name.size(); i++) name[i] = toupper(name[i]); } ObjExportSymbol *sym = factory->MakeExportSymbol(name); sym->SetByOrdinal(byOrdinal); sym->SetOrdinal(ordinal); sym->SetExternalName(externalName); sym->SetDllName(moduleName); file->Add(sym); break; } case eImport: { bool byOrdinal; if (data[0] == 'O') byOrdinal = true; else if (data[0] == 'N') byOrdinal = false; else ThrowSyntax(buffer, ParseType); if (data[1] != ',') ThrowSyntax(buffer, ParseType); int pos = 2; ObjString name = ParseString(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); ObjString externalName; int ordinal = 0xffffffff; ObjString dllName; if (byOrdinal) ordinal = ObjUtil::FromDecimal(data, &pos); else externalName = ParseString(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); dllName = ParseString(data, &pos); if (!GetCaseSensitiveFlag()) { for (int i=0; i < name.size(); i++) name[i] = toupper(name[i]); } ObjImportSymbol *sym = factory->MakeImportSymbol(name); sym->SetByOrdinal(byOrdinal); sym->SetOrdinal(ordinal); sym->SetExternalName(externalName); sym->SetDllName(dllName); file->Add(sym); break; } case eSourceFile: { int pos = 0; int index = ObjUtil::FromDecimal(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); ObjString name = ParseString(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); std::tm time; ParseTime(data, time, &pos); ObjSourceFile *sf = factory->MakeSourceFile(name, index); sf->SetFileTime(time); PutFile(index, sf); break; } case eBrowseInfo: { ObjBrowseInfo::eType type; ObjBrowseInfo::eQual qual; int pos = 0; type = (ObjBrowseInfo::eType)ObjUtil::FromHex(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); qual = (ObjBrowseInfo::eQual)ObjUtil::FromHex(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); int filenum = ObjUtil::FromDecimal(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); int lineno = ObjUtil::FromDecimal(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); int charpos = ObjUtil::FromDecimal(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); ObjString extra = ParseString(data, &pos); ObjSourceFile *sf = files[filenum]; if (!sf) ThrowSyntax(buffer, ParseType); ObjLineNo *line = factory->MakeLineNo(sf, lineno); ObjBrowseInfo *bi = factory->MakeBrowseInfo(type, qual, line, charpos, extra); file->Add(bi); break; } case eLineNo: { int pos = 0; int index = ObjUtil::FromDecimal(data, &pos); if (data[pos++] != ',') ThrowSyntax(buffer, ParseType); int line = ObjUtil::FromDecimal(data, &pos); ObjSourceFile *file = files[index]; if (!file) ThrowSyntax(buffer, ParseType); ObjLineNo *lineNo= factory->MakeLineNo(file, line); ObjDebugTag *tag = factory->MakeDebugTag(lineNo); currentTags->push_back(tag); break; } case eVar: { int pos = 0; int ch = data[pos++]; int index = ObjUtil::FromHex(data, &pos); ObjSymbol *sym = FindSymbol(ch, index); if (!sym) ThrowSyntax(buffer, ParseType); ObjDebugTag *tag = factory->MakeDebugTag(sym); currentTags->push_back(tag); break; } case eBlockStart: { ObjDebugTag *tag = factory->MakeDebugTag(true); currentTags->push_back(tag); break; } case eBlockEnd: { ObjDebugTag *tag = factory->MakeDebugTag(false); currentTags->push_back(tag); break; } case eFunctionStart: case eFunctionEnd: int pos = 0; int ch = data[pos++]; int index = ObjUtil::FromHex(data, &pos); ObjSymbol *sym = FindSymbol(ch, index); if (!sym) ThrowSyntax(buffer, ParseType); ObjDebugTag *tag = factory->MakeDebugTag(sym, cnum == eFunctionStart); currentTags->push_back(tag); break; } return false; }
int OmConvertRunWav(omconvert_settings_t *settings, calc_t *calc) { int retVal = EXIT_OK; int i; FILE *fp; WavInfo wavInfo = { 0 }; char infoArtist[WAV_META_LENGTH] = { 0 }; char infoName[WAV_META_LENGTH] = { 0 }; char infoComment[WAV_META_LENGTH] = { 0 }; char infoDate[WAV_META_LENGTH] = { 0 }; double scale[10] = { 8.0 / 32768.0, 8.0 / 32768.0, 8.0 / 32768.0 }; // Check config. if (settings->outFilename != NULL) { fprintf(stderr, "ERROR: Cannot output to WAV when input is WAV.\n"); return EXIT_CONFIG; } if (settings->infoFilename != NULL) { fprintf(stderr, "ERROR: Cannot output to info file when input is WAV.\n"); return EXIT_CONFIG; } fp = fopen(settings->filename, "rb"); if (fp == NULL) { fprintf(stderr, "ERROR: Cannot open WAV file.\n"); return EXIT_NOINPUT; } wavInfo.infoArtist = infoArtist; wavInfo.infoName = infoName; wavInfo.infoComment = infoComment; wavInfo.infoDate = infoDate; if (!WavRead(&wavInfo, fp)) { fprintf(stderr, "ERROR: Problem reading WAV file format.\n"); fclose(fp); return EXIT_DATAERR; } if (wavInfo.bytesPerChannel != 2) { fprintf(stderr, "ERROR: WAV file format not supported (%d bytes/channel, expected 2).\n", wavInfo.bytesPerChannel); fclose(fp); return EXIT_DATAERR; } if (wavInfo.chans < 3 || wavInfo.chans > 16) { fprintf(stderr, "ERROR: WAV file format not supported (%d channels, expected at least 3 and no more than 16).\n", wavInfo.chans); fclose(fp); return EXIT_DATAERR; } if (wavInfo.freq < 1 || wavInfo.freq > 48000) { fprintf(stderr, "ERROR: WAV file format not supported (%d frequency).\n", wavInfo.freq); fclose(fp); return EXIT_DATAERR; } // Extract metadata char *line; #define MAX_FIELDS 32 //char *artistLines[MAX_FIELDS]; int numArtistLines = 0; //for (line = strtok(wavInfo.infoArtist, "\n"); line != NULL; line = strtok(NULL, "\n")) { if (numArtistLines < MAX_FIELDS) { artistLines[numArtistLines++] = line; } } //char *nameLines[MAX_FIELDS]; int numNameLines = 0; //for (line = strtok(wavInfo.infoName, "\n"); line != NULL; line = strtok(NULL, "\n")) { if (numNameLines < MAX_FIELDS) { nameLines[numNameLines++] = line; } } char *commentLines[MAX_FIELDS]; int numCommentLines = 0; for (line = strtok(wavInfo.infoComment, "\n"); line != NULL; line = strtok(NULL, "\n")) { if (numCommentLines < MAX_FIELDS) { commentLines[numCommentLines++] = line; } } // Parse headers bool parsedTime = false; bool parsedScale[10] = { 0 }; double startTime = 0; for (i = 0; i < numCommentLines; i++) { if (strncmp(commentLines[i], "Time:", 5) == 0) { startTime = ParseTime(commentLines[i] + 5); fprintf(stderr, "Time: %s\n", TimeString(startTime)); if (startTime > 0) { parsedTime = true; } } else if (strncmp(commentLines[i], "Scale-", 6) == 0 && (commentLines[i][6] >= '1' && commentLines[i][6] <= '9') && commentLines[i][7] == ':') { int chan = commentLines[i][6] - '1'; double val = atof(commentLines[i] + 8); scale[chan] = val / 32768.0; fprintf(stderr, "Scale-%d: %f (scale[%d] = %f)\n", chan + 1, val, chan, scale[chan]); if (scale[chan] > 0) { parsedScale[chan] = true; } } } // Check we parsed the headers we need if (!parsedTime) { fprintf(stderr, "WARNING: Didn't successfully parse a 'Time' header (using zero).\n"); } for (i = 0; i < 3; i++) { if (!parsedScale[i]) { fprintf(stderr, "WARNING: Didn't successfully parse a 'Scale-%d' header (using defaults).\n", i + 1); } } int bufferSamples = wavInfo.freq * 60 * 60; // 1 hour buffer short *buffer = malloc(sizeof(short) * wavInfo.chans * bufferSamples); if (buffer == NULL) { fprintf(stderr, "ERROR: Problem allocating buffer for WAV file (%d samples).\n", bufferSamples); fclose(fp); return EXIT_SOFTWARE; } // Init. CSV/SVM/WTV/PAEE int outputOk = CalcInit(calc, wavInfo.freq, startTime); if (!outputOk) { fprintf(stderr, "ERROR: No outputs.\n"); retVal = EXIT_CONFIG; } else { fprintf(stderr, "Working...\n"); unsigned long samplesOffset = 0; unsigned long samplesRemaining = wavInfo.numSamples; while (!feof(fp)) { long offset = wavInfo.offset + ((sizeof(short) * wavInfo.chans) * samplesOffset); unsigned long samplesToRead = bufferSamples; if (samplesToRead > samplesRemaining) { samplesToRead = samplesRemaining; } if (samplesToRead <= 0) { break; } fseek(fp, offset, SEEK_SET); unsigned long samplesRead = fread(buffer, sizeof(short) * wavInfo.chans, samplesToRead, fp); if (samplesRead <= 0) { break; } samplesOffset += samplesRead; samplesRemaining -= samplesRead; double values[3]; for (i = 0; i < (int)samplesRead; i++) { const short *v = buffer + i * wavInfo.chans; // Auxilliary channel is last channel bool valid = true; if (wavInfo.chans > 3) { uint16_t aux = v[wavInfo.chans - 1]; if (aux & WAV_AUX_UNAVAILABLE) { valid = false; } } // Scaling from metadata values[0] = v[0] * scale[0]; values[1] = v[1] * scale[1]; values[2] = v[2] * scale[2]; if (!CalcAddValue(calc, values, 0.0, valid)) { fprintf(stderr, "ERROR: Problem writing calculations.\n"); retVal = EXIT_IOERR; break; } } } } free(buffer); fclose(fp); CalcClose(calc); return retVal; }
static void ProcessEntry( int *pi_n_entry, xml_reader_t *p_xml_reader, input_item_node_t *p_subitems, input_item_t *p_current_input, char *psz_prefix ) { const char *psz_node = NULL; const char *psz_txt = NULL; int i_type; char *psz_title = NULL; char *psz_artist = NULL; char *psz_copyright = NULL; char *psz_moreinfo = NULL; char *psz_description = NULL; char *psz_name = NULL; char *psz_mrl = NULL; char *psz_href = NULL; input_item_t *p_entry = NULL; int i_options; mtime_t i_start = 0; mtime_t i_duration = 0; char *ppsz_options[2]; do { i_type = xml_ReaderNextNode( p_xml_reader, &psz_node ); if( i_type == XML_READER_STARTELEM ) { /* Metadata Node */ if( !strncasecmp( psz_node, "TITLE", 5 ) ) ReadElement( p_xml_reader, &psz_title ); else if( !strncasecmp( psz_node, "AUTHOR", 6 ) ) ReadElement( p_xml_reader, &psz_artist ); else if( !strncasecmp( psz_node, "COPYRIGHT", 9 ) ) ReadElement( p_xml_reader, &psz_copyright ); else if( !strncasecmp( psz_node,"MOREINFO", 8 ) ) { do { psz_txt = xml_ReaderNextAttr( p_xml_reader, &psz_node ); } while(psz_txt && strncasecmp( psz_txt, "HREF", 4 ) ); if( !psz_txt ) ReadElement( p_xml_reader, &psz_moreinfo ); else psz_moreinfo = strdup( psz_node ); resolve_xml_special_chars( psz_moreinfo ); } else if( !strncasecmp( psz_node, "ABSTRACT", 8 ) ) ReadElement( p_xml_reader, &psz_description ); else if( !strncasecmp( psz_node, "DURATION", 8 ) ) i_duration = ParseTime( p_xml_reader ); else if( !strncasecmp( psz_node, "STARTTIME", 9 ) ) i_start = ParseTime( p_xml_reader ); else /* Reference Node */ /* All ref node will be converted into an entry */ if( !strncasecmp( psz_node, "REF", 3 ) ) { *pi_n_entry = *pi_n_entry + 1; if( !psz_title ) psz_title = input_item_GetTitle( p_current_input ); if( !psz_artist ) psz_artist = input_item_GetArtist( p_current_input ); if( !psz_copyright ) psz_copyright = input_item_GetCopyright( p_current_input ); if( !psz_description ) psz_description = input_item_GetDescription( p_current_input ); do { psz_txt = xml_ReaderNextAttr( p_xml_reader, &psz_node ); } while( strncasecmp( psz_txt, "HREF", 4) ); psz_href = strdup( psz_node ); if( asprintf( &psz_name, "%d. %s", *pi_n_entry, psz_title ) == -1) psz_name = strdup( psz_title ); resolve_xml_special_chars( psz_href ); psz_mrl = ProcessMRL( psz_href, psz_prefix ); /* Add Time information */ i_options = 0; if( i_start ) { if( asprintf( ppsz_options, ":start-time=%d" ,(int) i_start/1000000 ) != -1) i_options++; } if( i_duration) { if( asprintf( ppsz_options + i_options, ":stop-time=%d", (int) (i_start+i_duration)/1000000 ) != -1) i_options++; } /* Create the input item */ p_entry = input_item_NewExt( psz_mrl, psz_name, i_options, (const char* const*) ppsz_options, VLC_INPUT_OPTION_TRUSTED, i_duration ); input_item_CopyOptions( p_current_input, p_entry ); /* Add the metadata */ if( psz_name ) input_item_SetTitle( p_entry, psz_name ); if( psz_artist ) input_item_SetArtist( p_entry, psz_artist ); if( psz_copyright ) input_item_SetCopyright( p_entry, psz_copyright ); if( psz_moreinfo ) input_item_SetURL( p_entry, psz_moreinfo ); if( psz_description ) input_item_SetDescription( p_entry, psz_description ); if( i_duration > 0) input_item_SetDuration( p_entry, i_duration ); input_item_node_AppendItem( p_subitems, p_entry ); while( i_options ) free( ppsz_options[--i_options] ); free( psz_name ); free( psz_mrl ); } } } while( i_type != XML_READER_ENDELEM || strncasecmp( psz_node, "ENTRY", 5 ) ); free( psz_href ); free( psz_title ); free( psz_artist ); free( psz_copyright ); free( psz_moreinfo ); free( psz_description ); }
int main(void){ char* lab_greeting = "Smart \"Mirror\"!"; DisableInterrupts(); PLL_Init(Bus80MHz); Output_Init(); // UART0 only used for debugging ST7735_Output_Init(); PortF_Init(); PortE_Init(); printf("\n\r-----------\n\rSystem starting...\n\r"); ESP8266_Init(115200); // connect to access point, set up as client ESP8266_GetVersionNumber(); while(1){ if(last_mode != mode){ refresh =1; last_mode = mode; memset(ResponseJson, 0, SERVER_RESPONSE_SIZE * sizeof(ResponseJson[0])); } if(mode==0&&refresh){ refresh = 0; ST7735_FillScreen(0); ST7735_DrawString(0,0, lab_greeting, ST7735_WHITE); ST7735_DrawString(0,1, "MODE: WEATHER", ST7735_GREEN); ESP8266_GetStatus(); if(ESP8266_MakeTCPConnection("kylepolansky.dyndns.org")){ // open socket in server LED_GreenOn(); ESP8266_SendTCP(Fetch_Kyle); } ESP8266_CloseTCPConnection(); ParseWeather(ResponseJson); printf("START RESPONSE\n"); printf(ResponseJson); printf("STOP RESPONSE\n"); } else if(mode==1&&refresh){ refresh = 0; ST7735_FillScreen(0); ST7735_DrawString(0,0, lab_greeting, ST7735_WHITE); ST7735_DrawString(0,1, "MODE: TIME", ST7735_GREEN); ESP8266_GetStatus(); if(ESP8266_MakeTCPConnection("kylepolansky.dyndns.org")){ // open socket in server LED_GreenOn(); ESP8266_SendTCP(Fetch_Kyle); } ESP8266_CloseTCPConnection(); ParseTime(ResponseJson); printf("START RESPONSE\n"); printf(ResponseJson); printf("STOP RESPONSE\n"); } else if(mode==2&&refresh){ refresh = 0; ST7735_FillScreen(0); ST7735_DrawString(0,0, lab_greeting, ST7735_WHITE); ST7735_DrawString(0,1, "MODE: REMINDERS", ST7735_GREEN); ESP8266_GetStatus(); if(ESP8266_MakeTCPConnection("kylepolansky.dyndns.org")){ // open socket in server LED_GreenOn(); ESP8266_SendTCP(Fetch_Kyle); } ESP8266_CloseTCPConnection(); ParseReminders(ResponseJson); printf("START RESPONSE\n"); printf(ResponseJson); printf("STOP RESPONSE\n"); } else if(mode==3&&refresh){ refresh = 0; ST7735_FillScreen(0); ST7735_DrawString(0,0, lab_greeting, ST7735_WHITE); ST7735_DrawString(0,1, "MODE: NEWS", ST7735_GREEN); ESP8266_GetStatus(); if(ESP8266_MakeTCPConnection("kylepolansky.dyndns.org")){ // open socket in server LED_GreenOn(); ESP8266_SendTCP(Fetch_Kyle); } ESP8266_CloseTCPConnection(); ParseHeadline(ResponseJson); printf("START RESPONSE\n"); printf(ResponseJson); printf("STOP RESPONSE\n"); } else if(mode==4&&refresh){ refresh = 0; ST7735_FillScreen(0); ST7735_DrawString(0,0, lab_greeting, ST7735_WHITE); ST7735_DrawString(0,1, "MODE: STOCK", ST7735_GREEN); ESP8266_GetStatus(); if(ESP8266_MakeTCPConnection("kylepolansky.dyndns.org")){ // open socket in server LED_GreenOn(); ESP8266_SendTCP(Fetch_Kyle); } ESP8266_CloseTCPConnection(); ParseStock(ResponseJson); printf("START RESPONSE\n"); printf(ResponseJson); printf("STOP RESPONSE\n"); } } }
bool TrackReader::endElement(const QString& namespaceURI, const QString& localName, const QString& qName) { Q_UNUSED(qName) // we always work with the old path const QString ePath = d->currentElementPath; const QString eText = d->currentText.trimmed(); const QString eName = myQName(namespaceURI, localName); d->currentElements.removeLast(); d->currentText.clear(); rebuildElementPath(); if (ePath == QString::fromLatin1("gpx:gpx/gpx:trk/gpx:trkseg/gpx:trkpt")) { if (d->currentDataPoint.dateTime.isValid() && d->currentDataPoint.coordinates.hasCoordinates()) { d->fileData->track.points << d->currentDataPoint; } d->currentDataPoint = TrackManager::TrackPoint(); } else if (ePath == QString::fromLatin1("gpx:gpx/gpx:trk/gpx:trkseg/gpx:trkpt/gpx:time")) { d->currentDataPoint.dateTime = ParseTime(eText.trimmed()); } else if (ePath == QString::fromLatin1("gpx:gpx/gpx:trk/gpx:trkseg/gpx:trkpt/gpx:sat")) { bool okay = false; int nSatellites = eText.toInt(&okay); if (okay && (nSatellites >= 0)) d->currentDataPoint.nSatellites = nSatellites; } else if (ePath == QString::fromLatin1("gpx:gpx/gpx:trk/gpx:trkseg/gpx:trkpt/gpx:hdop")) { bool okay = false; qreal hDop = eText.toDouble(&okay); if (okay) d->currentDataPoint.hDop = hDop; } else if (ePath == QString::fromLatin1("gpx:gpx/gpx:trk/gpx:trkseg/gpx:trkpt/gpx:pdop")) { bool okay = false; qreal pDop = eText.toDouble(&okay); if (okay) d->currentDataPoint.pDop = pDop; } else if (ePath == QString::fromLatin1("gpx:gpx/gpx:trk/gpx:trkseg/gpx:trkpt/gpx:fix")) { int fixType = -1; if (eText == QString::fromLatin1("2d")) { fixType = 2; } else if (eText == QString::fromLatin1("3d")) { fixType = 3; } if (fixType>=0) { d->currentDataPoint.fixType = fixType; } } else if (ePath == QString::fromLatin1("gpx:gpx/gpx:trk/gpx:trkseg/gpx:trkpt/gpx:ele")) { bool haveAltitude = false; const qreal alt = eText.toDouble(&haveAltitude); if (haveAltitude) { d->currentDataPoint.coordinates.setAlt(alt); } } else if (ePath == QString::fromLatin1("gpx:gpx/gpx:trk/gpx:trkseg/gpx:trkpt/gpx:speed")) { bool haveSpeed = false; const qreal speed = eText.toDouble(&haveSpeed); if (haveSpeed) { d->currentDataPoint.speed = speed; } } return true; }
// Time 字符串中不能有空格 HRESULT KppUserLog::WriteSingleLog( /* [in] */const std::wstring& wstLogString ) { std::wstring strLog(L""); HRESULT hrRet = E_FAIL; SYSTEMTIME sysTime = {0}; std::wstring strTmep(L"\n"); if(!m_bWrite) { return E_FAIL; } if (!m_bInitFlag) { return E_FAIL; } _LockWork(); FILE* pfile = NULL; if (::PathFileExists(m_strPathName.c_str())) { pfile = ::_wfopen(m_strPathName.c_str(), L"at,ccs=UTF-8"); } else { pfile = ::_wfopen(m_strPathName.c_str(), L"wt,ccs=UTF-8"); } if (!pfile) { hrRet = E_FAIL; goto _Exit; } GetLocalTime( &sysTime ); ParseTime(strLog, &sysTime); strLog += wstLogString; strLog += strTmep; size_t fwsize = ::fwrite((BYTE *)strLog.c_str(), sizeof(BYTE), ::wcslen(strLog.c_str())*2, pfile); hrRet = S_OK; _Exit: if (pfile) { ::fclose(pfile); pfile = NULL; } _UnlockWork(); return hrRet; }
static bool AddItem(const CXmlItem &item, CObjectVector<CFile> &files, int parent) { if (!item.IsTag) return true; if (item.Name == "file") { CFile file; file.Parent = parent; parent = files.Size(); file.Name = item.GetSubStringForTag("name"); AString type = item.GetSubStringForTag("type"); if (type == "directory") file.IsDir = true; else if (type == "file") file.IsDir = false; else return false; int dataIndex = item.FindSubTag("data"); if (dataIndex >= 0 && !file.IsDir) { file.HasData = true; const CXmlItem &dataItem = item.SubItems[dataIndex]; if (!ParseUInt64(dataItem, "size", file.Size)) return false; if (!ParseUInt64(dataItem, "length", file.PackSize)) return false; if (!ParseUInt64(dataItem, "offset", file.Offset)) return false; file.Sha1IsDefined = ParseSha1(dataItem, "extracted-checksum", file.Sha1); // file.packSha1IsDefined = ParseSha1(dataItem, "archived-checksum", file.packSha1); int encodingIndex = dataItem.FindSubTag("encoding"); if (encodingIndex >= 0) { const CXmlItem &encodingItem = dataItem.SubItems[encodingIndex]; if (encodingItem.IsTag) { AString s = encodingItem.GetPropertyValue("style"); if (s.Length() >= 0) { AString appl = "application/"; if (s.Left(appl.Length()) == appl) { s = s.Mid(appl.Length()); AString xx = "x-"; if (s.Left(xx.Length()) == xx) { s = s.Mid(xx.Length()); if (s == "gzip") s = METHOD_NAME_ZLIB; } } file.Method = s; } } } } file.CTime = ParseTime(item, "ctime"); file.MTime = ParseTime(item, "mtime"); file.ATime = ParseTime(item, "atime"); files.Add(file); } for (int i = 0; i < item.SubItems.Size(); i++) if (!AddItem(item.SubItems[i], files, parent)) return false; return true; }
static bool ParseRecordInfo(char *record_info, RecordedFlightInfo &flight) { // According to testing with firmware 5.03: // 18CG6NG1.IGC|2011-08-12|12:23:48|02:03:25|TOBIAS BIENIEK|TH|Club // According to documentation: // 2000-11-08|20:05:21|01:21:09|J.Doe|XYZ|15M // Where the pilot name may take up to 100 bytes, while class, glider- // and competition ID can take up to 32 bytes. // Search for first separator char *p = strchr(record_info, '|'); if (p == NULL) return false; // Replace separator by \0 *p = '\0'; // Move pointer to first character after the replaced separator // and check for valid character p++; if (*p == '\0') return false; // Check if first field is NOT the date (length > 10) if (strlen(record_info) > 10) { record_info = p; // Search for second separator p = strchr(record_info, '|'); if (p == NULL) return false; // Replace separator by \0 *p = '\0'; // Move pointer to first character after the replaced separator // and check for valid character p++; if (*p == '\0') return false; } // Now record_info should point to the date field, // the date field should be null-terminated and p should // point to the start time field and the rest of the null- // terminated string if (!ParseDate(record_info, flight.date)) return false; record_info = p; // Search for next separator p = strchr(record_info, '|'); if (p == NULL) return false; // Replace separator by \0 *p = '\0'; // Move pointer to first character after the replaced separator // and check for valid character p++; if (*p == '\0') return false; // Now record_info should point to the start time field, // the start time field should be null-terminated and p should // point to the duration field and the rest of the null- // terminated string if (!ParseTime(record_info, flight.start_time)) return false; record_info = p; // Search for next separator p = strchr(record_info, '|'); if (p == NULL) return false; // Replace separator by \0 *p = '\0'; // Move pointer to first character after the replaced separator // and check for valid character p++; if (*p == '\0') return false; // Now record_info should point to the duration field, // the duration field should be null-terminated and p should // point to the pilot field and the rest of the null- // terminated string BrokenTime duration; if (!ParseTime(record_info, duration)) return false; flight.end_time = flight.start_time + duration; return true; }
INT cmd_time (LPTSTR param) { LPTSTR *arg; INT argc; INT i; INT nTimeString = -1; if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_TIME_HELP1); return 0; } nErrorLevel = 0; /* build parameter array */ arg = split (param, &argc, FALSE, FALSE); /* check for options */ for (i = 0; i < argc; i++) { if (_tcsicmp (arg[i], _T("/t")) == 0) { /* Display current time in short format */ SYSTEMTIME st; TCHAR szTime[20]; GetLocalTime(&st); FormatTime(szTime, &st); ConOutPuts(szTime); freep(arg); return 0; } if ((*arg[i] != _T('/')) && (nTimeString == -1)) nTimeString = i; } if (nTimeString == -1) { ConOutResPrintf(STRING_LOCALE_HELP1); ConOutPrintf(_T(": %s\n"), GetTimeString()); } while (1) { if (nTimeString == -1) { TCHAR s[40]; ConOutResPuts(STRING_TIME_HELP2); ConInString (s, 40); TRACE ("\'%s\'\n", debugstr_aw(s)); while (*s && s[_tcslen (s) - 1] < _T(' ')) s[_tcslen(s) - 1] = _T('\0'); if (ParseTime (s)) { freep (arg); return 0; } } else { if (ParseTime (arg[nTimeString])) { freep (arg); return 0; } /* force input the next time around. */ nTimeString = -1; } ConErrResPuts(STRING_TIME_ERROR1); nErrorLevel = 1; } freep (arg); return 0; }
int Opt_Parse( int argc, /* Number of arguments in argv. */ char **argv, /* Array of arguments */ Option optionArray[], /* Array of option descriptions */ int numOptions, /* Size of optionArray */ int flags) /* Or'ed combination of various flag bits: * see option.h for definitions. */ { register Option *optionPtr; /* pointer to the current option in the * array of option specifications */ register char *curOpt; /* Current flag argument */ register char **curArg; /* Current argument */ register int argIndex; /* Index into argv to which next unused * argument should be copied */ int stop=0; /* Set non-zero to stop processing * arguments when an OPT_REST flag is * encountered */ int length; /* Number of characters in current * option. */ argIndex = 1; argc -= 1; curArg = &argv[1]; while (argc && !stop) { if (**curArg == '-') { curOpt = &curArg[0][1]; curArg += 1; argc -= 1; /* * Check for the special options "?" and "help". If found, * print documentation and exit. */ if ((strcmp(curOpt, "?") == 0) || (strcmp(curOpt, "help") == 0)) { Opt_PrintUsage (argv[0], optionArray, numOptions); exit(0); } /* * Loop over all the options specified in a single argument * (must be 1 unless OPT_ALLOW_CLUSTERING was specified). */ while (1) { /* * Loop over the array of options searching for one with the * matching key string. If found, it is left pointed to by * optionPtr. */ for (optionPtr = &optionArray[numOptions - 1]; optionPtr >= optionArray; optionPtr -= 1) { if (optionPtr->key == NULL) { continue; } if (*optionPtr->key == *curOpt) { if (flags & OPT_ALLOW_CLUSTERING) { length = strlen(optionPtr->key); if (strncmp(optionPtr->key, curOpt, length) == 0) { break; } } else { if (strcmp(optionPtr->key, curOpt) == 0) { break; } } } } if (optionPtr < optionArray) { /* * No match. Print error message and skip option. */ fprintf(stderr, "Unknown option \"-%s\";", curOpt); fprintf(stderr, " type \"%s -help\" for information\n", argv[0]); break; } /* * Take the appropriate action based on the option type */ if (optionPtr->type >= 0) { *((int *) optionPtr->address) = optionPtr->type; } else { switch (optionPtr->type) { case OPT_REST: stop = 1; *((int *) optionPtr->address) = argIndex; break; case OPT_STRING: if (argc == 0) { OptNoArg(argv[0], optionPtr->key); } else { *((char **)optionPtr->address) = *curArg; curArg++; argc--; } break; case OPT_INT: case OPT_UINT: if (argc == 0) { OptNoArg(argv[0], optionPtr->key); } else { char *endPtr; int value = strtol(*curArg, &endPtr, 0); if (endPtr == *curArg) { fprintf(stderr, "Warning: option \"-%s\" got a non-numeric argument \"%s\". Using default: %d\n", optionPtr->key, *curArg, *((int *) optionPtr->address)); } else if (optionPtr->type == OPT_UINT && value < 0) { fprintf(stderr, "Warning: option \"-%s\" got a negative argument \"%s\". Using default: %u.\n", optionPtr->key, *curArg, *((unsigned *) optionPtr->address)); } else { *((int *) optionPtr->address) = value; } curArg++; argc--; } break; case OPT_TIME: if (argc == 0) { OptNoArg(argv[0], optionPtr->key); } else { ParseTime(argv[0], *curArg, (time_t *)optionPtr->address); curArg++; argc--; } break; case OPT_FLOAT: if (argc == 0) { OptNoArg(argv[0], optionPtr->key); } else { char *endPtr; double value = strtod(*curArg, &endPtr); if (endPtr == *curArg) { fprintf(stderr, "Warning: option \"-%s\" got non-floating-point argument \"%s\". Using default: %lg.\n", optionPtr->key, *curArg, *((double *) optionPtr->address)); } else { *((double *) optionPtr->address) = value; } curArg++; argc--; } break; case OPT_GENFUNC: { int (*handlerProc)(); handlerProc = (int (*)())optionPtr->address; argc = (* handlerProc) (optionPtr->key, argc, curArg); break; } case OPT_FUNC: { int (*handlerProc)(); handlerProc = (int (*)())optionPtr->address; if ((* handlerProc) (optionPtr->key, *curArg)) { curArg += 1; argc -= 1; } break; } case OPT_DOC: Opt_PrintUsage (argv[0], optionArray, numOptions); exit(0); /*NOTREACHED*/ } } /* * Advance to next option */ if (flags & OPT_ALLOW_CLUSTERING) { curOpt += length; if (*curOpt == 0) { break; } } else { break; } } } else { /* * *curArg is an argument for which we have no use, so copy it * down. */ argv[argIndex] = *curArg; argIndex += 1; curArg += 1; argc -= 1; /* * If this wasn't an option, and we're supposed to stop parsing * the first time we see something other than "-", quit. */ if (flags & OPT_OPTIONS_FIRST) { stop = 1; } } } /* * If we broke out of the loop because of an OPT_REST argument, we want * to copy the rest of the arguments down, so we do. */ while (argc) { argv[argIndex] = *curArg; argIndex += 1; curArg += 1; argc -= 1; } argv[argIndex] = (char *)NULL; return argIndex; }
inline bool ParseTime(const std::string& str, time_t& time) { return ParseTime(str.c_str(), time); }
// Time 字符串中不能有空格 HRESULT KppUserLog::WriteSingleLog( /* [in] */const std::wstring& wstLogString ) { std::wstring strLog; HRESULT hrRet = E_FAIL; SYSTEMTIME sysTime = {0}; CStringW strTmep; if (!m_bInitFlag) { return E_FAIL; } _LockWork(); FILE* pfile = NULL; if (::PathFileExists(m_strPathName.c_str())) { pfile = ::_wfopen(m_strPathName.c_str(), L"at,ccs=UNICODE"); } else { pfile = ::_wfopen(m_strPathName.c_str(), L"wt,ccs=UNICODE"); } if (!pfile) { hrRet = S_OK; goto _Exit; } GetLocalTime( &sysTime ); ParseTime(strLog, &sysTime); strTmep = wstLogString.c_str(); strTmep.Replace('\r', ' '); strTmep.Replace('\n', ' '); strLog += strTmep; strLog += '\n'; ::fwrite(strLog.c_str(), sizeof(WCHAR), ::wcslen(strLog.c_str()), pfile); hrRet = S_OK; _Exit: if (pfile) { ::fclose(pfile); pfile = NULL; } _UnlockWork(); return hrRet; }
void CPlayerSubresyncBar::OnEndlabeleditList(NMHDR* pNMHDR, LRESULT* pResult) { LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR; LV_ITEM* pItem = &pDispInfo->item; *pResult = FALSE; if (!m_list.m_fInPlaceDirty) { return; } bool fNeedsUpdate = false; if (pItem->iItem >= 0 && pItem->pszText && (m_mode == VOBSUB || m_mode == TEXTSUB)) { switch (pItem->iSubItem) { case COL_START: { int t; if (ParseTime(pItem->pszText, t)) { fNeedsUpdate = ModStart(pItem->iItem, t); *pResult = TRUE; } } break; case COL_END: if (m_mode == TEXTSUB) { int t; if (ParseTime(pItem->pszText, t)) { fNeedsUpdate = ModEnd(pItem->iItem, t); *pResult = TRUE; } } break; case COL_TEXT: if (m_mode == TEXTSUB) { CString str = m_sts.GetStrW(pItem->iItem, true); if (str != pItem->pszText) { fNeedsUpdate = true; m_sts.SetStr(pItem->iItem, CString(pItem->pszText), true); m_list.SetItemText(pItem->iItem, pItem->iSubItem, m_sts.GetStrW(pItem->iItem, true)); } } break; case COL_STYLE: if (m_mode == TEXTSUB) { CString str(pItem->pszText); str.Trim(); if (!str.IsEmpty() && m_sts[pItem->iItem].style != str) { fNeedsUpdate = true; if (!m_sts.m_styles.Lookup(str)) { m_sts.AddStyle(str, DNew STSStyle()); } m_sts[pItem->iItem].style = str; m_list.SetItemText(pItem->iItem, pItem->iSubItem, pItem->pszText); } } break; case COL_LAYER: if (m_mode == TEXTSUB) { int l; if (_stscanf_s(pItem->pszText, _T("%d"), &l) == 1) { fNeedsUpdate = true; m_sts[pItem->iItem].layer = l; CString str; str.Format(_T("%d"), l); m_list.SetItemText(pItem->iItem, pItem->iSubItem, str); } } break; case COL_ACTOR: if (m_mode == TEXTSUB) { CString str(pItem->pszText); str.Trim(); if (!str.IsEmpty()) { fNeedsUpdate = true; m_sts[pItem->iItem].actor = str; m_list.SetItemText(pItem->iItem, pItem->iSubItem, str); } } break; case COL_EFFECT: if (m_mode == TEXTSUB) { CString str(pItem->pszText); str.Trim(); if (!str.IsEmpty()) { fNeedsUpdate = true; m_sts[pItem->iItem].effect = str; m_list.SetItemText(pItem->iItem, pItem->iSubItem, str); } } break; } } if (fNeedsUpdate) { UpdatePreview(); } }