static int echo_finish () { ping_finish (); if (ping->ping_num_recv && PING_TIMING (data_length)) { struct ping_stat *ping_stat = (struct ping_stat *) ping->ping_closure; double total = ping->ping_num_recv + ping->ping_num_rept; double avg = ping_stat->tsum / total; double vari = ping_stat->tsumsq / total - avg * avg; printf ("round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f ms\n", ping_stat->tmin, avg, ping_stat->tmax, nsqrt (vari, 0.0005)); } return (ping->ping_num_recv == 0); }
/* -------------------------------------------------------------------------- */ LRESULT FAR PASCAL RuleAppWndProc (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { static int inMode = ID_CLICK; static LONG x1 = 0, x2 = 0, y1 = 0, y2 = 0; static HCTX hTab = NULL; static FIX32 scale[2]; PAINTSTRUCT psPaint; HDC hDC; switch (wMsg) { case WM_CREATE: TabletScaling(scale); break; case WM_LBUTTONDOWN: if ((hTab = TabletInit(hWnd, scale)) != NULL) { PACKET pkt; inMode = ID_PRESS; InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); while (inMode != ID_CLICK) { /* poll */ if (!WTPacketsGet(hTab, 1, &pkt)) continue; /* handle it */ if (inMode == ID_PRESS && pkt.pkButtons) { x1 = pkt.pkX; y1 = pkt.pkY; inMode = ID_RELEASE; InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); } if (inMode == ID_RELEASE && pkt.pkButtons == 0) { x2 = pkt.pkX; y2 = pkt.pkY; inMode = ID_CLICK; InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); } } WTClose(hTab); } break; case WM_PAINT: hDC = BeginPaint(hWnd, &psPaint); ShowWindow(GetDlgItem(hWnd, ID_CLICK), inMode == ID_CLICK); ShowWindow(GetDlgItem(hWnd, ID_PRESS), inMode == ID_PRESS); ShowWindow(GetDlgItem(hWnd, ID_RELEASE), inMode == ID_RELEASE); if (inMode == ID_CLICK) { LONG delta[3]; /* horz/vert/diag */ int i; delta[0] = labs(x2 - x1); delta[1] = labs(y2 - y1); delta[2] = nsqrt(delta[0] * delta[0] + delta[1] * delta[1]); for (i = 0; i < 3; i++) { /* direction */ char buf[20]; /* print result in cm */ wsprintf(buf, "%d.%3.3d", (UINT)delta[i]/1000, (UINT)delta[i]%1000); SetWindowText(GetDlgItem(hWnd, ID_HC + i), buf); /* convert to inches */ delta[i] = INT(delta[i] * Cm2Inch); /* print result in inches */ wsprintf(buf, "%d.%3.3d", (UINT)delta[i]/1000, (UINT)delta[i]%1000); SetWindowText(GetDlgItem(hWnd, ID_HI + i), buf); } } EndPaint(hWnd, &psPaint); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, wMsg, wParam, lParam); } return (LRESULT)0; }