📄 log.c
字号:
the logfile.*/static int CreateCmd( clientData, interp, argc, argv )ClientData clientData;Tcl_Interp *interp;int argc;char **argv;{ logFile *log; logFormat format; char *pct_done; int i; FILE *fp;/* Tcl syntax: logfile <cmd> <filename> <format> [opts]*/ if (argc < 4) { Tcl_AppendResult( interp, "wrong # of args: logfile <cmd> <filename> ", "<format> [opts]", (char*)0 ); return TCL_ERROR; } fp = fopen( argv[2], "r" ); if (!fp) { Tcl_AppendResult( interp, "could not open ", argv[2], (char*)0 ); return TCL_ERROR; } fclose( fp ); format = FormatStr2Enum( argv[3] ); if (format == unknown_format) { Tcl_AppendResult( interp, "unrecognized format: ", argv[3], (char*)0 ); return TCL_ERROR; } /* look for a -pctdone option */ pct_done = 0; for (i=4; i<argc && !pct_done; i++) { if (!strcmp( argv[i], "-pctdone" )) { pct_done = argv[i+1]; } } log = Log_Open( interp, argv[1], argv[2], format, pct_done ); if (!log) return TCL_ERROR; else return TCL_OK;}static int Cmd( clientData, interp, argc, argv )ClientData clientData;Tcl_Interp *interp;int argc;char **argv;{ logFile *log; int idx, tag, parent, firstChild, overlapLevel; int len, type, proc1, proc2, size; double time1, time2; char *name, *color, *bitmap, tmpStr[50]; log = (logFile*)clientData; if (argc < 2) { Tcl_AppendResult( interp, "wrong # of args: ", argv[0], " <cmd> ...", (char*)0 ); return TCL_ERROR; } len = strlen(argv[1]); if (len<2) goto unrecognized_cmd; switch (argv[1][0]) { /* first letter of the command is 'c' */ case 'c': if (strcmp( argv[1], "close" ) == 0) return Log_Close( log ); if (strcmp( argv[1], "creator" ) == 0) { if (log->creator) { Tcl_AppendElement( interp, log->creator ); } else Tcl_AppendElement( interp, "" ); return TCL_OK; } goto unrecognized_cmd; /* first letter of the command is 'e' */ case 'e': if (strcmp( argv[1], "endtime" )) goto unrecognized_cmd; return ReturnDouble( interp, Log_EndTime( log ) ); /* first letter of the command is 'n' */ case 'n': switch (argv[1][1]) { case 'p': if (strcmp( argv[1], "np" )) goto unrecognized_cmd; return ReturnInt( interp, Log_Np( log ) ); case 'e': if (len<7) goto unrecognized_cmd; if (argv[1][6] == 's') { if (strcmp( argv[1], "nevents" )) goto unrecognized_cmd; return ReturnInt( interp, Log_Nevents( log ) ); } else { if (strcmp( argv[1], "neventdefs" )) goto unrecognized_cmd; return ReturnInt( interp, Log_NeventDefs( log ) ); } case 's': if (len<7) goto unrecognized_cmd; switch (argv[1][6]) { case 'd': if (strcmp( argv[1], "nstatedefs" )) goto unrecognized_cmd; return ReturnInt( interp, Log_NstateDefs( log ) ); case 's': if (strcmp( argv[1], "nstates" )) goto unrecognized_cmd; return ReturnInt( interp, Log_Nstates( log ) ); case 't': if (strcmp( argv[1], "nstatetypeinst" )) goto unrecognized_cmd; if (ConvertArgs( interp, "<logfile> nstatetypeinst <idx>", "2 d", argc, argv, &idx ) != TCL_OK) { return TCL_ERROR; } return ReturnInt( interp, Log_NstateTypeInst( log, idx ) ); default: goto unrecognized_cmd; } /* switch (argv[1][6]) */ case 'm': if (len<5) goto unrecognized_cmd; if (argv[1][6] == 's') { if (strcmp( argv[1], "nmsgs" )) goto unrecognized_cmd; return ReturnInt( interp, Log_Nmsgs( log ) ); } else { if (strcmp( argv[1], "nmsgdefs" )) goto unrecognized_cmd; return ReturnInt( interp, Log_NmsgDefs( log ) ); } default: goto unrecognized_cmd; } /* switch (argv[1][1]) { */ /* first letter of the command is 'g' */ case 'g': if (len<4) goto unrecognized_cmd; switch (argv[1][3]) { case 'e': if (len<8) goto unrecognized_cmd; if (argv[1][8] == '\0') { if (strcmp( argv[1], "getevent" )) goto unrecognized_cmd; if (ConvertArgs( interp, "<logfile> getevent <idx>", "2 d", argc, argv, &idx ) != TCL_OK) { return TCL_ERROR; } Log_GetEvent( log, idx, &type, &proc1, &time1 ); sprintf( tmpStr, "%d", type ); Tcl_AppendElement( interp, tmpStr ); sprintf( tmpStr, "%d", proc1 ); Tcl_AppendElement( interp, tmpStr ); Tcl_PrintDouble( interp, time1, tmpStr ); Tcl_AppendElement( interp, tmpStr ); return TCL_OK; } else { if (strcmp( argv[1], "geteventdef" )) goto unrecognized_cmd; if (ConvertArgs( interp, "<logfile> geteventdef <idx>", "2 i", argc, argv, &idx ) != TCL_OK) { return TCL_ERROR; } Log_GetEventDef( log, idx, &name ); Tcl_AppendResult( interp, name, (char*)0 ); return TCL_OK; } case 's': if (len<8) goto unrecognized_cmd; if (argv[1][8] == '\0') { if (strcmp( argv[1], "getstate" )) goto unrecognized_cmd; if (ConvertArgs( interp, "<logfile> getstate <idx>", "2 d", argc, argv, &idx ) != TCL_OK) { return TCL_ERROR; } Log_GetState( log, idx, &type, &proc1, &time1, &time2, &parent, &firstChild, &overlapLevel ); sprintf( tmpStr, "%d", type ); Tcl_AppendElement( interp, tmpStr ); sprintf( tmpStr, "%d", proc1 ); Tcl_AppendElement( interp, tmpStr ); Tcl_PrintDouble( interp, time1, tmpStr ); Tcl_AppendElement( interp, tmpStr ); Tcl_PrintDouble( interp, time2, tmpStr ); Tcl_AppendElement( interp, tmpStr ); sprintf( tmpStr, "%d", parent ); Tcl_AppendElement( interp, tmpStr ); sprintf( tmpStr, "%d", firstChild ); Tcl_AppendElement( interp, tmpStr ); sprintf( tmpStr, "%d", overlapLevel ); Tcl_AppendElement( interp, tmpStr ); return TCL_OK; } else { if (strcmp( argv[1], "getstatedef" )) goto unrecognized_cmd; if (ConvertArgs( interp, "<logfile> getstatedef <idx>", "2 d", argc, argv, &idx ) != TCL_OK) { return TCL_ERROR; } /* If the state is not active, don't do anythin */ if (!Log_GetStateDef( log, idx, &name, &color, &bitmap )) { Tcl_AppendElement( interp, name ); Tcl_AppendElement( interp, color ); Tcl_AppendElement( interp, bitmap ); } return TCL_OK; } case 'm': if (len<6) goto unrecognized_cmd; if (argv[1][6] == '\0') { if (strcmp( argv[1], "getmsg" )) goto unrecognized_cmd; if (ConvertArgs( interp, "<logfile> getmsg <idx>", "2 i", argc, argv, &idx ) != TCL_OK) { return TCL_ERROR; } Log_GetMsg( log, idx, &type, &proc1, &proc2, &time1, &time2, &size ); sprintf( tmpStr, "%d", type ); Tcl_AppendElement( interp, tmpStr ); sprintf( tmpStr, "%d", proc1 ); Tcl_AppendElement( interp, tmpStr ); sprintf( tmpStr, "%d", proc2 ); Tcl_AppendElement( interp, tmpStr ); Tcl_PrintDouble( interp, time1, tmpStr ); Tcl_AppendElement( interp, tmpStr ); Tcl_PrintDouble( interp, time2, tmpStr ); Tcl_AppendElement( interp, tmpStr ); sprintf( tmpStr, "%d", size ); Tcl_AppendElement( interp, tmpStr ); return TCL_OK; } else { if (strcmp( argv[1], "getmsgdef" )) goto unrecognized_cmd; if (ConvertArgs( interp, "<logfile> getmsgdef <idx>", "2 i", argc, argv, &idx ) != TCL_OK) { return TCL_ERROR; } Log_GetMsgDef( log, idx, &name, &tag, &color ); Tcl_AppendElement( interp, name ); sprintf( tmpStr, "%d", tag ); Tcl_AppendElement( interp, tmpStr ); } Tcl_AppendElement( interp, color ); return TCL_OK; case 'p': if (strcmp( argv[1], "getprocessdef" ) == 0) { if (ConvertArgs( interp, "<logfile> getprocessdef <idx>", "2 d", argc, argv, &idx ) != TCL_OK) { return TCL_ERROR; } Log_GetProcessDef( log, idx, &name ); Tcl_AppendResult( interp, name, (char *) NULL ); /* not a list elt */ return TCL_OK; } else goto unrecognized_cmd; default: goto unrecognized_cmd; } /* switch argv[1][3] */ /* first letter of the command is 's' */ case 's': if (argv[1][1] == 't') { if (strcmp( argv[1], "starttime" )) goto unrecognized_cmd; return ReturnDouble( interp, Log_StartTime( log ) ); } else { if (len<4) goto unrecognized_cmd; switch (argv[1][3]) { case 'e': if (strcmp( argv[1], "seteventdef" )) goto unrecognized_cmd; if (ConvertArgs( interp, "<logfile> seteventdef <idx> <name>", "2 is", argc, argv, &idx, &name ) != TCL_OK) { return TCL_ERROR; } Log_SetEventDef( log, idx, name ); return TCL_OK; case 's': if (strcmp( argv[1], "setstatedef" )) goto unrecognized_cmd; if (ConvertArgs( interp, "<logfile> setstatedef <idx> <name> <color> <bitmap>", "2 isss", argc, argv, &idx, &name, &color, &bitmap ) != TCL_OK) { return TCL_ERROR; } Log_SetStateDef( log, idx, name, color, bitmap ); return TCL_OK; case 'm': if (strcmp( argv[1], "setmsgdef" )) goto unrecognized_cmd; if (ConvertArgs( interp, "<logfile> setmsgdef <idx> <name> <tag> <color>", "2 isds", argc, argv, &idx, &name, &tag, &color ) != TCL_OK) { return TCL_ERROR; } Log_SetMsgDef( log, idx, name, tag, color ); return TCL_OK; case 'p': if (strcmp( argv[1], "setprocessdef" )) goto unrecognized_cmd; if (ConvertArgs( interp, "<logfile> setprocessdef <idx> <name>", "2 is", argc, argv, &idx, &name ) != TCL_OK) { return TCL_ERROR; } Log_SetProcessDef( log, idx, name ); return TCL_OK; default: goto unrecognized_cmd; } } default: goto unrecognized_cmd; } unrecognized_cmd: Tcl_AppendResult( interp, argv[1], "--unrecognized logfile command. ", "Must be one ", "of: close, np, starttime, endtime, ", "neventdefs, geteventdef, seteventdef, ", "nevents, getevent, ", "nstatedefs, getstatedef, setstatedef, ", "getprocessdef, setprocessdef, ", "nstates, nstatetypeinst, getstate, ", "nmsgdefs, getmsgdef, setmsgdef, ", "nmsgs, getmsg.", (char*)0 ); return TCL_ERROR;}logFile *LogCmd2Ptr( interp, cmd )Tcl_Interp *interp;char *cmd;{ Tcl_CmdInfo cmdInfo; Tcl_GetCommandInfo( interp, cmd, &cmdInfo ); return (logFile*)cmdInfo.clientData;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -