/* generate JSON unique visitors stats */ static void print_json_visitors (FILE * fp, GHolder * h) { char *data, buf[DATE_LEN]; float percent; int hits, bw, i, process = get_ht_size (ht_unique_visitors); /* make compiler happy */ memset (buf, 0, sizeof (buf)); fprintf (fp, "\t\"%s\": [\n", VISIT_ID); for (i = 0; i < h->idx; i++) { hits = h->items[i].hits; data = h->items[i].data; percent = get_percentage (process, hits); percent = percent < 0 ? 0 : percent; bw = h->items[i].bw; convert_date (buf, data, "%Y%m%d", "%d/%b/%Y", DATE_LEN); fprintf (fp, "\t\t{\n\t\t\t\"hits\": \"%d\",\n", hits); fprintf (fp, "\t\t\t\"percent\": \"%4.2f%%\",\n", percent); fprintf (fp, "\t\t\t\"date\": \"%s\",\n", buf); fprintf (fp, "\t\t\t\"bytes\": \"%d\"\n", bw); fprintf (fp, "\t\t}"); if (i != h->idx - 1) fprintf (fp, ",\n"); else fprintf (fp, "\n"); } fprintf (fp, "\t]"); }
/* generate CSV unique visitors stats */ static void print_csv_visitors (FILE * fp, GHolder * h) { char *data, buf[DATE_LEN]; float percent; int hits, bw, i, process = get_ht_size (ht_unique_visitors); /* make compiler happy */ memset (buf, 0, sizeof (buf)); for (i = 0; i < h->idx; i++) { hits = h->items[i].hits; data = h->items[i].data; percent = get_percentage (process, hits); percent = percent < 0 ? 0 : percent; bw = h->items[i].bw; convert_date (buf, data, "%Y%m%d", "%d/%b/%Y", DATE_LEN); fprintf (fp, "\"%d\",", i); /* idx */ fprintf (fp, ","); /* parent idx */ fprintf (fp, "\"%s\",", VISIT_ID); fprintf (fp, "\"%d\",", hits); fprintf (fp, "\"%4.2f%%\",", percent); fprintf (fp, "\"%s\",", buf); fprintf (fp, "\"%d\"\r\n", bw); } }
int main() { int date, month, year; printf("Enter a date"); // enter the date scanf_s("%d/%d/%d", &date, &month, &year); convert_date(date, month, year); //calling a function }
static int process_date (GLogItem * glog, char *date) { /* make compiler happy */ memset (date, 0, sizeof *date); convert_date (date, glog->date, conf.date_format, "%Y%m%d", DATE_LEN); if (date == NULL) return 1; return 0; }
time_t scan_date() { int fd_date; int n,seclen; int i; time_t t; unsigned char buf[4096]; struct dmx_sct_filter_params sctFilterParams; struct pollfd ufd; t = 0; if((fd_date = open(DVB_DEMUX_DEVICE,O_RDWR|O_NONBLOCK)) < 0){ perror("fd_date DEVICE: "); return 0; } sctFilterParams.pid=0x14; memset(&sctFilterParams.filter.filter,0,DMX_FILTER_SIZE); memset(&sctFilterParams.filter.mask,0,DMX_FILTER_SIZE); sctFilterParams.timeout = 0; sctFilterParams.flags = DMX_IMMEDIATE_START; sctFilterParams.filter.filter[0]=0x70; sctFilterParams.filter.mask[0]=0xff; if (ioctl(fd_date,DMX_SET_FILTER,&sctFilterParams) < 0) { perror("DATE - DMX_SET_FILTER:"); close(fd_date); return 0; } ufd.fd=fd_date; ufd.events=POLLPRI; if (poll(&ufd,1,10000) < 0) { errmsg("TIMEOUT reading from fd_date\n"); close(fd_date); return 0; } if (read(fd_date,buf,3)==3) { seclen=((buf[1] & 0x0f) << 8) | (buf[2] & 0xff); n = read(fd_date,buf+3,seclen); if (n==seclen) { t = convert_date(&(buf[3])); } else { errmsg("Under-read bytes for DATE - wanted %d, got %d\n",seclen,n); return 0; } } else { errmsg("Nothing to read from fd_date - try tuning to a multiplex?\n"); return 0; } close(fd_date); return(t); }
void format_date_visitors (GMetrics * metrics) { char date[DATE_LEN] = ""; /* Ymd */ char *datum = metrics->data; /* make compiler happy */ memset (date, 0, sizeof *date); convert_date (date, datum, "%Y%m%d", "%d/%b/%Y", DATE_LEN); if (date != NULL) { free (datum); metrics->data = xstrdup (date); } }
static void data_visitors (GHolder * h) { char date[DATE_LEN] = ""; /* Ymd */ char *datum = h->items[h->idx].metrics->data; memset (date, 0, sizeof *date); /* verify we have a valid date conversion */ if (convert_date (date, datum, conf.date_format, "%Y%m%d", DATE_LEN) == 0) { free (datum); h->items[h->idx].metrics->data = xstrdup (date); return; } LOG_DEBUG (("invalid date: %s", datum)); free (datum); h->items[h->idx].metrics->data = xstrdup ("---"); }
/* render dashboard data */ static void render_data (GDashModule * data, GDashRender render, int *x) { WINDOW *win = render.win; GModule module = data->module; const GDashStyle *style = module_style; int y = render.y, w = render.w, idx = render.idx, sel = render.sel; char buf[DATE_LEN]; char *value, *padded_data; value = substring (data->data[idx].metrics->data, 0, w - *x); if (module == VISITORS) { /* verify we have a valid date conversion */ if (convert_date (buf, value, "%Y%m%d", "%d/%b/%Y", DATE_LEN) != 0) { LOG_DEBUG (("invalid date: %s", value)); xstrncpy (buf, "---", 4); } } if (sel) { if (data->module == HOSTS && data->data[idx].is_subitem) { padded_data = left_pad_str (value, *x); draw_header (win, padded_data, "%s", y, 0, w, HIGHLIGHT, 0); free (padded_data); } else { draw_header (win, module == VISITORS ? buf : value, "%s", y, *x, w, HIGHLIGHT, 0); } } else { wattron (win, COLOR_PAIR (style[module].color_data)); mvwprintw (win, y, *x, "%s", module == VISITORS ? buf : value); wattroff (win, COLOR_PAIR (style[module].color_data)); } *x += module == VISITORS ? DATE_LEN - 1 : data->data_len; *x += DASH_SPACE; free (value); }
/* render dashboard data */ void render_data (WINDOW * win, GDashModule * module_data, int y, int *x, int idx, int w, int selected) { char buf[DATE_LEN]; char *data; GDashStyle *style = module_style; GModule module = module_data->module; data = substring (module_data->data[idx].data, 0, w - *x); if (module == VISITORS) convert_date (buf, data, "%Y%m%d", "%d/%b/%Y", DATE_LEN); if (selected) { if (conf.color_scheme == MONOCHROME) init_pair (1, COLOR_BLACK, COLOR_WHITE); else init_pair (1, COLOR_BLACK, COLOR_GREEN); wattron (win, COLOR_PAIR (HIGHLIGHT)); if (module_data->module == HOSTS && module_data->data[idx].is_subitem) mvwhline (win, y, 0, ' ', w); else mvwhline (win, y, *x, ' ', w); mvwprintw (win, y, *x, "%s", module == VISITORS ? buf : data); wattroff (win, COLOR_PAIR (HIGHLIGHT)); } else { wattron (win, COLOR_PAIR (style[module].color_hits)); mvwprintw (win, y, *x, "%s", module == VISITORS ? buf : data); wattroff (win, COLOR_PAIR (style[module].color_hits)); } *x += module == VISITORS ? DATE_LEN - 1 : module_data->data_len; *x += DASH_SPACE; free (data); }
int NEAR PASCAL CommandHandler(WORD wParam, LONG lParam) { /* if (HIWORD(lParam) == EN_CHANGE) { if (focus(GetDlgCtrlID(LOWORD(lParam))) && players.player_numb > -1) bNeedSaveP = TRUE; else if (courses.course_numb > -1) bNeedSaveC = TRUE; } */ switch (wParam) { case IDOK: SendMessage(hWnd, WM_COMMAND, IDD_RLIST, MAKELONG(0, LBN_DBLCLK)); return NULL; case IDM_CONTENTS: case IDM_SEARCHON: case IDM_USE: MessageBox(hWnd, "Help to come soon!", szAppName, MB_OK | MB_ICONEXCLAMATION); return NULL; case IDM_ABOUT: /* display about dialog box */ lpfnGenericDlgProc = MakeProcInstance((FARPROC)AboutDlgProc, hInst); DialogBox(hInst, "ABOUT", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_HANDICAP: lpfnGenericDlgProc = MakeProcInstance((FARPROC)HandicapDlgProc, hInst); DialogBox(hInst, "HANDICAP", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_P_SEARCH: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; /* fall through */ case IDM_C_SEARCH: if (!get_course(hWnd, &courses, c_index)) return NULL; wWhich = wParam; lpfnGenericDlgProc = MakeProcInstance((FARPROC)SearchDlgProc, hInst); DialogBox(hInst, "SEARCH", hWnd, lpfnGenericDlgProc); FreeProcInstance(lpfnGenericDlgProc); /* Release memory */ return NULL; case IDM_GRAPH: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; if (!get_course(hWnd, &courses, c_index)) return NULL; if (IDYES == MessageBox(hWnd, "You must have Microsoft Excel\nto use this option. Continue?", szAppName, MB_YESNO | MB_ICONQUESTION)) GraphData(&(players).player[p_index].p_scores, &courses); return NULL; case IDM_NEW_P: /* save current file and clear viewport */ if (bNeedSaveP && IDCANCEL == AskAboutSave(hWnd, szFileTitleP, PLAYER_MARKER)) return FALSE; szFileTitleP[NULL] = '\0'; bNeedSaveP = FALSE; p_index = r_index = r_last = 0; players.player_numb = -1; clear_player(hWnd, hWndRList); DoCaption(hWnd, szFileTitleP, szFileTitleC); return NULL; case IDM_NEW_C: if (bNeedSaveC && IDCANCEL == AskAboutSave(hWnd, szFileTitleC, COURSE_MARKER)) return FALSE; szFileTitleC[NULL] = '\0'; bNeedSaveC = FALSE; c_index = 0; courses.course_numb = -1; clear_course(hWnd); DoCaption(hWnd, szFileTitleP, szFileTitleC); return NULL; case IDM_OPEN_P: /* open an existing file */ of_player.lpstrTitle = "Open Player"; of_player.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; if (!GetOpenFileName(&of_player)) return FALSE; if (ReadFile(hWnd, szFileP, szFileTitleP, szFileTitleC, bNeedSaveP, &players, &courses, PLAYER_MARKER)) { bNeedSaveP = FALSE; p_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); DoCaption(hWnd, szFileTitleP, szFileTitleC); } /* if */ return NULL; case IDM_OPEN_C: /* open an existing file */ of_course.lpstrTitle = "Open Course"; of_course.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; if (!GetOpenFileName(&of_course)) return FALSE; if (ReadFile(hWnd, szFileC, szFileTitleP, szFileTitleC, bNeedSaveC, &players, &courses, COURSE_MARKER)) { bNeedSaveC = FALSE; c_index = 0; show_course(hWnd, &courses, &c_index); DoCaption(hWnd, szFileTitleP, szFileTitleC); } /* if */ return NULL; case IDM_SAVE_P: /* write current file */ if (szFileTitleP[NULL]) { if (!get_player(hWnd, &players, p_index, r_index)) return NULL; if (WriteFile(hWnd, szFileP, &players, &courses, PLAYER_MARKER, p_index, r_index, c_index)) { bNeedSaveP = FALSE; return 1; } /* if */ return NULL; } /* if fall through */ case IDM_SAVEAS_P: /* change file name */ if (!get_player(hWnd, &players, p_index, r_index)) return NULL; of_player.lpstrTitle = "Save Player"; of_player.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if (!GetSaveFileName(&of_player)) return FALSE; if (WriteFile(hWnd, szFileP, &players, &courses, PLAYER_MARKER, p_index, r_index, c_index)) { bNeedSaveP = FALSE; DoCaption(hWnd, szFileTitleP, szFileTitleC); } return NULL; case IDM_SAVE_C: /* write current file */ if (szFileTitleC[NULL]) { if (!get_course(hWnd, &courses, c_index)) return NULL; if (WriteFile(hWnd, szFileC, &players, &courses, COURSE_MARKER, p_index, r_index, c_index)) { bNeedSaveC = FALSE; return 1; } /* if */ return NULL; } /* if fall through */ case IDM_SAVEAS_C: /* change file name */ if (!get_course(hWnd, &courses, c_index)) return NULL; of_course.lpstrTitle = "Save Course"; of_course.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if (!GetSaveFileName(&of_course)) return FALSE; if (WriteFile(hWnd, szFileC, &players, &courses, COURSE_MARKER, p_index, r_index, c_index)) { bNeedSaveC = FALSE; DoCaption(hWnd, szFileTitleP, szFileTitleC); } return NULL; case IDM_PRINT_P: /* Print current file */ if (!get_player(hWnd, &players, p_index, r_index)) return NULL; PrintFile(hInst, hWnd, szFileTitleP[NULL] ? szFileTitleP : szUntitled); return NULL; case IDM_PRINT_C: /* Print current file */ if (!get_course(hWnd, &courses, c_index)) return NULL; PrintFile(hInst, hWnd, szFileTitleC[NULL] ? szFileTitleC : szUntitled); return NULL; case IDM_EXIT: /* Send a close message, and exit the program */ SendMessage(hWnd, WM_CLOSE, NULL, 0L); return NULL; case IDM_UNDO: /* Check for undo status */ SendMessage(GetFocus(), WM_UNDO, 0, 0L); return 0; case IDM_CUT: /* Send cut message */ SendMessage(GetFocus(), WM_CUT, 0, 0L); return 0; case IDM_COPY: /* Send copy message */ SendMessage(GetFocus(), WM_COPY, 0, 0L); return 0; case IDM_PASTE: /* Send paste message */ SendMessage(GetFocus(), WM_PASTE, 0, 0L); return 0; case IDM_CLEAR: /* Send clear message */ SendMessage(GetFocus(), WM_CLEAR, 0, 0L); return 0; case IDM_P_ADD: if (AddPlayer(hWnd, &players, &p_index, &r_index)) bNeedSaveP = TRUE; return NULL; case IDM_R_ADD: if (AddRound(hWnd, &players, &p_index, &r_index, &r_last)) bNeedSaveP = TRUE; return NULL; case IDM_C_ADD: if (AddCourse(hWnd, &courses, &c_index)) bNeedSaveC = TRUE; return NULL; case IDM_P_SORT: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; qsort(players.player, players.player_numb+1, sizeof(players.player[0]), compare_player); bNeedSaveP = TRUE; p_index = r_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); return NULL; case IDM_R_SORT: if (!get_player(hWnd, &players, p_index, r_index)) return NULL; qsort(players.player[p_index].p_scores.history, players.player[p_index].p_scores.round_numb+1, sizeof(players.player[p_index].p_scores.history[0]), compare_round); bNeedSaveP = TRUE; r_index = 0; show_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); return NULL; case IDM_C_SORT: if (!get_course(hWnd, &courses, c_index)) return NULL; qsort(courses.course, courses.course_numb, sizeof(courses.course[0]), compare_course); bNeedSaveC = TRUE; c_index = 0; show_course(hWnd, &courses, &c_index); return NULL; case IDM_P_DELETE: if (players.player_numb > -1) { GetDlgItemText(hWnd, IDD_PLAST, (players).player[p_index].p_last, LAST_NAME_LENGTH+1); GetDlgItemText(hWnd, IDD_PFIRST, (players).player[p_index].p_first, FIRST_NAME_LENGTH+1); lstrcpy(szDelete, "Delete : "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_first); lstrcat(szDelete, " "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_last); if (IDYES == MessageBox(hWnd, szDelete, "Delete Player", MB_YESNO | MB_ICONQUESTION)) { bNeedSaveP = TRUE; delete_player(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); } } /* if */ return NULL; case IDM_R_DELETE: if (players.player[p_index].p_scores.round_numb > -1) { convert_date(&players.player[p_index].p_scores.history[r_index].date, szDate); lstrcpy(szDelete, (LPSTR)"Delete : "); lstrcat(szDelete, (LPSTR)players.player[p_index].p_scores.history[r_index].course_name); lstrcat(szDelete, " "); lstrcat(szDelete, szDate); if (IDYES == MessageBox(hWnd, szDelete, "Delete Round", MB_YESNO | MB_ICONQUESTION)) { delete_round(hWnd, hWndRList, &players, &p_index, &r_index, &r_last); bNeedSaveP = TRUE; } /* if */ } /* if */ return NULL; case IDM_C_DELETE: if (courses.course_numb > -1) { GetDlgItemText(hWnd, IDD_CNAME, (courses).course[c_index].c_name, COURSE_NAME_LENGTH+1); lstrcpy(szc_name, (courses).course[c_index].c_name); lpfnGenericDlgProc = MakeProcInstance((FARPROC)DeleteCourseDlgProc, hInst); DialogBox(hInst, "DELETEC", hWnd, lpfnGenericDlgProc); FreeProcInstance(DeleteCourseDlgProc); /* Release memory */ if (bYesNo == IDYES) { bNeedSaveC = TRUE; delete_course(&courses, &c_index); if (bDeleteRounds && delete_rounds(&players, szc_name)) { bNeedSaveP = TRUE; show_rounds(hWnd, hWndRList, &(players).player[p_index].p_scores, &r_index, &r_last, TRUE); } /* if */ show_course(hWnd, &courses, &c_index); } /* if */ } /* if */ return NULL; case IDD_RLIST: switch(HIWORD(lParam)) { case LBN_DBLCLK: if ((players.player_numb == -1) || (players.player[p_index].p_scores.round_numb == -1)) return NULL; lstrcpy(szNDTitle, "Change Course / Name Date"); convert_date(&players.player[p_index].p_scores.history[r_index].date, szDate); get_date_elements(szDate, szmm, szdd, szyy); lstrcpy(szc_name, (LPSTR)players.player[p_index].p_scores.history[r_index].course_name); lpfnGenericDlgProc = MakeProcInstance((FARPROC)NameDateDlgProc, hInst); DialogBox(hInst, "NAMEDATE", hWnd, lpfnGenericDlgProc); FreeProcInstance(NameDateDlgProc); /* Release memory */ if (bNameDate == IDOK) { bNeedSaveP = TRUE; players.player[p_index].p_scores.history[r_index].date = string_to_date(szmm, szdd, szyy); lstrcpy((LPSTR)players.player[p_index].p_scores.history[r_index].course_name, szc_name); show_rounds(hWnd, hWndRList, &(players).player[p_index].p_scores, &r_index, &r_last, FALSE); } /* if */ return NULL; case LBN_SELCHANGE: if ((int)SendMessage(hWndRList, LB_GETCURSEL, 0, 0L) == r_index) break; if (!get_round(hWnd, &players, p_index, r_index)) { SendMessage(hWndRList, LB_SETCURSEL, r_index, 0L); return NULL; } r_index = (int)SendMessage(hWndRList, LB_GETCURSEL, 0, 0L); if (r_index != LB_ERR && r_index != r_last) { show_round(hWnd, players.player[p_index].p_scores.history[r_index].score); r_last = r_index; } /* if */ return NULL; } /* switch (HIWORD(lParam)) */ return NULL; default: return FALSE; } /* switch (wParam) */ } /* CommandHandler */
int main(int argc, char **argv) { const char *b, *e, *p; const char *output_file = NULL; int f, tot, last, linenum, err, parse_err; struct timer *t = NULL, *t2; struct eb32_node *n; int val, test; int array[5]; int filter_acc_delay = 0, filter_acc_count = 0; int filter_time_resp = 0; int skip_fields = 1; argc--; argv++; while (argc > 0) { if (*argv[0] != '-') break; if (strcmp(argv[0], "-ad") == 0) { if (argc < 2) die("missing option for -ad"); argc--; argv++; filter |= FILT_ACC_DELAY; filter_acc_delay = atol(*argv); } else if (strcmp(argv[0], "-ac") == 0) { if (argc < 2) die("missing option for -ac"); argc--; argv++; filter |= FILT_ACC_COUNT; filter_acc_count = atol(*argv); } else if (strcmp(argv[0], "-rt") == 0) { if (argc < 2) die("missing option for -rt"); argc--; argv++; filter |= FILT_TIME_RESP; filter_time_resp = atol(*argv); } else if (strcmp(argv[0], "-RT") == 0) { if (argc < 2) die("missing option for -RT"); argc--; argv++; filter |= FILT_TIME_RESP | FILT_INVERT_TIME_RESP; filter_time_resp = atol(*argv); } else if (strcmp(argv[0], "-s") == 0) { if (argc < 2) die("missing option for -s"); argc--; argv++; skip_fields = atol(*argv); } else if (strcmp(argv[0], "-e") == 0) filter |= FILT_ERRORS_ONLY; else if (strcmp(argv[0], "-E") == 0) filter |= FILT_ERRORS_ONLY | FILT_INVERT_ERRORS; else if (strcmp(argv[0], "-c") == 0) filter |= FILT_COUNT_ONLY; else if (strcmp(argv[0], "-q") == 0) filter |= FILT_QUIET; else if (strcmp(argv[0], "-v") == 0) filter_invert = !filter_invert; else if (strcmp(argv[0], "-gt") == 0) filter |= FILT_GRAPH_TIMERS; else if (strcmp(argv[0], "-pct") == 0) filter |= FILT_PERCENTILE; else if (strcmp(argv[0], "-o") == 0) { if (output_file) die("Fatal: output file name already specified.\n"); if (argc < 2) die("Fatal: missing output file name.\n"); output_file = argv[1]; } argc--; argv++; } if (!filter) die("No action specified.\n"); if (filter & FILT_ACC_COUNT && !filter_acc_count) filter_acc_count=1; if (filter & FILT_ACC_DELAY && !filter_acc_delay) filter_acc_delay = 1; linenum = 0; tot = 0; parse_err = 0; while ((line = fgets2(stdin)) != NULL) { linenum++; test = 1; if (filter & FILT_TIME_RESP) { int tps; /* only report lines with response times larger than filter_time_resp */ b = field_start(line, TIME_FIELD + skip_fields); if (!*b) { truncated_line(linenum, line); continue; } e = field_stop(b + 1); /* we have field TIME_FIELD in [b]..[e-1] */ p = b; err = 0; for (f = 0; f < 4 && *p; f++) { tps = str2ic(p); if (tps < 0) { tps = -1; err = 1; } SKIP_CHAR(p, '/'); } if (f < 4) { parse_err++; continue; } test &= (tps >= filter_time_resp) ^ !!(filter & FILT_INVERT_TIME_RESP); } if (filter & FILT_ERRORS_ONLY) { /* only report erroneous status codes */ b = field_start(line, STATUS_FIELD + skip_fields); if (!*b) { truncated_line(linenum, line); continue; } if (*b == '-') { test &= !!(filter & FILT_INVERT_ERRORS); } else { val = strl2ui(b, 3); test &= (val >= 500 && val <= 599) ^ !!(filter & FILT_INVERT_ERRORS); } } if (filter & (FILT_ACC_COUNT|FILT_ACC_DELAY)) { b = field_start(line, ACCEPT_FIELD + skip_fields); if (!*b) { truncated_line(linenum, line); continue; } tot++; val = convert_date(b); //printf("date=%s => %d\n", b, val); if (val < 0) { parse_err++; continue; } t2 = insert_value(&timers[0], &t, val); t2->count++; continue; } if (filter & (FILT_GRAPH_TIMERS|FILT_PERCENTILE)) { int f; b = field_start(line, TIME_FIELD + skip_fields); if (!*b) { truncated_line(linenum, line); continue; } e = field_stop(b + 1); /* we have field TIME_FIELD in [b]..[e-1] */ p = b; err = 0; for (f = 0; f < 5 && *p; f++) { array[f] = str2ic(p); if (array[f] < 0) { array[f] = -1; err = 1; } SKIP_CHAR(p, '/'); } if (f < 5) { parse_err++; continue; } /* if we find at least one negative time, we count one error * with a time equal to the total session time. This will * emphasize quantum timing effects associated to known * timeouts. Note that on some buggy machines, it is possible * that the total time is negative, hence the reason to reset * it. */ if (filter & FILT_GRAPH_TIMERS) { if (err) { if (array[4] < 0) array[4] = -1; t2 = insert_timer(&timers[0], &t, array[4]); // total time t2->count++; } else { int v; t2 = insert_timer(&timers[1], &t, array[0]); t2->count++; // req t2 = insert_timer(&timers[2], &t, array[2]); t2->count++; // conn t2 = insert_timer(&timers[3], &t, array[3]); t2->count++; // resp v = array[4] - array[0] - array[1] - array[2] - array[3]; // data time if (v < 0 && !(filter & FILT_QUIET)) fprintf(stderr, "ERR: %s (%d %d %d %d %d => %d)\n", line, array[0], array[1], array[2], array[3], array[4], v); t2 = insert_timer(&timers[4], &t, v); t2->count++; tot++; } } else { /* percentile */ if (err) { if (array[4] < 0) array[4] = -1; t2 = insert_value(&timers[0], &t, array[4]); // total time t2->count++; } else { int v; t2 = insert_value(&timers[1], &t, array[0]); t2->count++; // req t2 = insert_value(&timers[2], &t, array[2]); t2->count++; // conn t2 = insert_value(&timers[3], &t, array[3]); t2->count++; // resp v = array[4] - array[0] - array[1] - array[2] - array[3]; // data time if (v < 0 && !(filter & FILT_QUIET)) fprintf(stderr, "ERR: %s (%d %d %d %d %d => %d)\n", line, array[0], array[1], array[2], array[3], array[4], v); t2 = insert_value(&timers[4], &t, v); t2->count++; tot++; } } continue; } test ^= filter_invert; if (!test) continue; /* all other cases mean we just want to count lines */ tot++; if (!(filter & FILT_COUNT_ONLY)) puts(line); } if (t) free(t); if (filter & FILT_COUNT_ONLY) { printf("%d\n", tot); exit(0); } if (filter & FILT_ERRORS_ONLY) exit(0); if (filter & (FILT_ACC_COUNT|FILT_ACC_DELAY)) { /* sort and count all timers. Output will look like this : * <accept_date> <delta_ms from previous one> <nb entries> */ n = eb32_first(&timers[0]); if (n) last = n->key; while (n) { unsigned int d, h, m, s, ms; t = container_of(n, struct timer, node); h = n->key; d = h - last; last = h; if (d >= filter_acc_delay && t->count >= filter_acc_count) { ms = h % 1000; h = h / 1000; s = h % 60; h = h / 60; m = h % 60; h = h / 60; tot++; printf("%02d:%02d:%02d.%03d %d %d %d\n", h, m, s, ms, last, d, t->count); } n = eb32_next(n); } }
void CanberraCnfDataSet::load_data(std::istream &f) { string file_string; file_string.reserve(128*1024); file_string.assign((istreambuf_iterator<char>(f)), istreambuf_iterator<char>()); const char* beg = file_string.c_str(); const char* end = beg + file_string.size(); int acq_offset = 0, sam_offset = 0, eff_offset = 0, enc_offset = 0, chan_offset = 0; // we have here 48-byte blocks with meta data for (const char* ptr = beg+112; ptr+48 < end; ptr += 48) { // MW - should records 0 in ptr[1] or ptr[2] be really accepted? if ((ptr[1] != 0x20 || ptr[2] != 0x01) && ptr[1] != 0 && ptr[2] != 0) break; uint32_t offset = from_le<uint32_t>(ptr+10); #if 0 printf("%6ld: hex %02x %02x %02x %02x -> %6u", ptr-beg, ptr[0], ptr[1], ptr[2], ptr[3], offset); if (offset > 0 && beg+offset+1 < end) printf(" -> hex %02x %02x", beg[offset], beg[offset+1]); printf("\n"); #endif switch (ptr[0]) { case 0: if (acq_offset == 0) acq_offset = offset; else enc_offset = offset; break; case 1: if (sam_offset == 0) sam_offset = offset; break; case 2: if (eff_offset == 0) eff_offset = offset; break; case 5: // We don't have specs, so it's all based on guessing. // At least for me. Checking a few CNF files I've got, // normally we are here when the record starts with 0x052001, // but the condition above (which I copied like everything // else from JF) is also passing when it starts with, say, // 0x054000 (Miha Cernetic sent us such a file). // No idea if the condition above can be safely changed. // Here is a workaround from JF - checking the value at the // offset. if (chan_offset == 0 && offset+1 < file_string.size() && file_string[offset] == '\x05' && file_string[offset+1] == '\x20') chan_offset = offset; break; default: break; } if (acq_offset != 0 && sam_offset != 0 && eff_offset != 0 && chan_offset != 0) break; } if (enc_offset == 0) enc_offset = acq_offset; auto_ptr<Block> blk(new Block); // sample data - split name into name and description // (this was not in code from JF, it's my guess - MW) const char* sam_ptr = beg + sam_offset; if (sam_ptr+0x30+80 >= end || sam_ptr[0] != 1 || sam_ptr[1] != 0x20) fprintf(stderr, "Warning. Sample data not found.\n"); else { string name = str_trim(string(sam_ptr+0x30, 32)); if (!name.empty() && is_printable(name)) blk->set_name(name); string desc = str_trim(string(sam_ptr+0x30+32, 48)); if (!desc.empty() && is_printable(desc)) blk->meta["description"] = desc; } // go to acquisition data const char* acq_ptr = beg + acq_offset; if (acq_ptr+48+128+10+4 >= end || acq_ptr[0] != 0 || acq_ptr[1] != 0x20) throw FormatError("Acquisition data not found."); uint16_t offset1 = from_le<uint16_t>(acq_ptr+34); uint16_t offset2 = from_le<uint16_t>(acq_ptr+36); const char* pha_ptr = acq_ptr + 48 + 128; if (pha_ptr[0] != 'P' || pha_ptr[1] != 'H' || pha_ptr[2] != 'A') fprintf(stderr, "Warning. PHA keyword not found.\n"); int n_channels = from_le<uint16_t>(pha_ptr+10) * 256; if (n_channels < 256 || n_channels > 16384) throw FormatError("Unexpected number of channels" + S(n_channels)); // dates and times const char* date_ptr = acq_ptr+48+offset2+1; format_assert(this, date_ptr + 3*8 < end); blk->meta["date and time"] = convert_date(date_ptr); // when taken float real_time = convert_time(date_ptr + 8); blk->meta["real time (s)"] = format1<float, 16>("%.2f", real_time); float live_time = convert_time(date_ptr + 16); blk->meta["live time (s)"] = format1<float, 16>("%.2f", live_time); format_assert(this, beg + enc_offset+48+32 + offset1 < end); Column *xcol = read_energy_callibration(beg + enc_offset+48+32 + offset1, blk.get(), n_channels); if (xcol == NULL) xcol = read_energy_callibration(beg + enc_offset+48+32, blk.get(), n_channels); if (xcol == NULL) { fprintf(stderr, "Warning. Energy Calibration not found.\n"); xcol = new StepColumn(1, 1); } // code from JF is also reading detector name, but it's not needed here // detector name was 232 bytes after energy calibration // channel data const char* chan_ptr = beg + chan_offset; if (chan_ptr+512+4*n_channels > end || chan_ptr[0] != 5 || chan_ptr[1] != 0x20) { delete xcol; throw FormatError("Channel data not found."); } VecColumn *ycol = new VecColumn; // the two first channels sometimes contain live and real time for (int i = 0; i < 2; ++i) { uint32_t y = from_le<uint32_t>(chan_ptr+512+4*i); if ((int) y == iround(real_time) || (int) y == iround(live_time)) y = 0; ycol->add_val(y); } for (int i = 2; i < n_channels; ++i) { uint32_t y = from_le<uint32_t>(chan_ptr+512+4*i); ycol->add_val(y); } blk->add_column(xcol); blk->add_column(ycol); add_block(blk.release()); }
int cSysTime::scan_date(time_t *dvb_time, unsigned int to) { int fd_date; int n, seclen; time_t t; unsigned char buf[4096]; struct dmx_sct_filter_params sctFilterParams; struct pollfd ufd; int found = 0; t = 0; if ((fd_date = open("/dev/dvb/adapter0/demux0", O_RDWR | O_NONBLOCK)) < 0) { perror("fd_date DEVICE: "); return -1; } memset(&sctFilterParams, 0, sizeof(sctFilterParams)); sctFilterParams.pid = 0x14; sctFilterParams.timeout = 0; sctFilterParams.flags = DMX_IMMEDIATE_START; sctFilterParams.filter.filter[0] = 0x70; sctFilterParams.filter.mask[0] = 0xff; if (ioctl(fd_date, DMX_SET_FILTER, &sctFilterParams) < 0) { perror("DATE - DMX_SET_FILTER:"); close(fd_date); return -1; } while (to > 0) { int res; memset(&ufd,0,sizeof(ufd)); ufd.fd=fd_date; ufd.events=POLLIN; res = poll(&ufd,1,1000); if (0 == res) { fprintf(stdout, "."); fflush(stdout); to--; continue; } if (1 == res) { found = 1; break; } printf("error polling for data"); close(fd_date); return -1; } fprintf(stdout, "\n"); if (0 == found) { printf("timeout - try tuning to a multiplex?\n"); close(fd_date); return -1; } if ((n = read(fd_date, buf, 4096)) >= 3) { seclen = ((buf[1] & 0x0f) << 8) | (buf[2] & 0xff); if (n == seclen + 3) { t = convert_date(&(buf[3])); } else { printf("Under-read bytes for DATE - wanted %d, got %d\n", seclen, n); return 0; } } else { printf("Nothing to read from fd_date - try tuning to a multiplex?\n"); return 0; } close(fd_date); *dvb_time = t; return 0; }
static void print_html_visitors_report (FILE * fp, GHolder * h) { char *data, *bandwidth, buf[DATE_LEN]; float percent, l; int hits, i, max, process = get_ht_size (ht_unique_visitors); /* make compiler happy */ memset (buf, 0, sizeof (buf)); print_html_h2 (fp, VISIT_HEAD, VISIT_ID); print_p (fp, VISIT_DESC); print_html_begin_table (fp); print_html_begin_thead (fp); fprintf (fp, "<tr>"); fprintf (fp, "<th>Visitors</th>"); fprintf (fp, "<th>%%</th>"); fprintf (fp, "<th>Date</th>"); fprintf (fp, "<th>Bandwidth</th>"); fprintf (fp, "<th style=\"width:100%%;text-align:right;\">"); fprintf (fp, "<span class=\"r\" onclick=\"t(this)\">◀</span>"); fprintf (fp, "</th>"); fprintf (fp, "</tr>"); print_html_end_thead (fp); print_html_begin_tbody (fp); max = 0; for (i = 0; i < h->idx; i++) { if (h->items[i].hits > max) max = h->items[i].hits; } for (i = 0; i < h->idx; i++) { hits = h->items[i].hits; data = h->items[i].data; percent = get_percentage (process, hits); percent = percent < 0 ? 0 : percent; bandwidth = filesize_str (h->items[i].bw); l = get_percentage (max, hits); l = l < 1 ? 1 : l; print_html_begin_tr (fp, i > OUTPUT_N ? 1 : 0); /* hits */ fprintf (fp, "<td>%d</td>", hits); if (hits == max) fprintf (fp, "<td class=\"max\">%4.2f%%</td>", percent); else fprintf (fp, "<td>%4.2f%%</td>", percent); /* date */ convert_date (buf, data, "%Y%m%d", "%d/%b/%Y", DATE_LEN); fprintf (fp, "<td>%s</td>", buf); /* bandwidth */ fprintf (fp, "<td>"); clean_output (fp, bandwidth); fprintf (fp, "</td>"); /* bars */ fprintf (fp, "<td class=\"graph\">"); fprintf (fp, "<div class=\"bar\" style=\"width:%f%%\"></div>", l); fprintf (fp, "</td>\n"); print_html_end_tr (fp); free (bandwidth); } print_html_end_tbody (fp); print_html_end_table (fp); }
bool FitsInput::read_fits_header (void) { std::string fits_header (HEADER_SIZE, 0); // we read whole header at once if (fread (&fits_header[0], 1, HEADER_SIZE, m_fd) != HEADER_SIZE) { if (feof (m_fd)) error ("Hit end of file unexpectedly"); else error ("read error"); return false; // Read failed } for (int i = 0; i < CARDS_PER_HEADER; ++i) { std::string card (CARD_SIZE, 0); // reading card number i memcpy (&card[0], &fits_header[i*CARD_SIZE], CARD_SIZE); std::string keyname, value; fits_pvt::unpack_card (card, keyname, value); // END means that this is end of the FITS header // we can now add to the ImageSpec COMMENT, HISTORY and HIERARCH keys if (keyname == "END") { // removing white spaces that we use to separate lines of comments // from the end ot the string m_comment = m_comment.substr (0, m_comment.size() - m_sep.size ()); m_history = m_history.substr (0, m_history.size() - m_sep.size ()); m_hierarch = m_hierarch.substr (0, m_hierarch.size() - m_sep.size ()); add_to_spec ("Comment", m_comment); add_to_spec ("History", m_history); add_to_spec ("Hierarch", m_hierarch); return true; } if (keyname == "SIMPLE" || keyname == "XTENSION") continue; // setting up some important fields // m_bitpix - format of the data (eg. bpp) // m_naxes - number of axes // width, height and depth of the image if (keyname == "BITPIX") { m_bitpix = atoi (&card[10]); continue; } if (keyname == "NAXIS") { m_naxes = atoi (&card[10]); continue; } if (keyname == "NAXIS1") { m_spec.width = atoi (&card[10]); m_spec.full_width = m_spec.width; continue; } if (keyname == "NAXIS2") { m_spec.height = atoi (&card[10]); m_spec.full_height = m_spec.height; continue; } // ignoring other axis if (keyname.substr (0,5) == "NAXIS") { continue; } if (keyname == "ORIENTAT") { add_to_spec ("Orientation", value); continue; } if (keyname == "DATE") { add_to_spec ("DateTime", convert_date (value)); continue; } if (keyname == "COMMENT") { m_comment += (value + m_sep); continue; } if (keyname == "HISTORY") { m_history += (value + m_sep); continue; } if (keyname == "HIERARCH") { m_hierarch += (value + m_sep); continue; } add_to_spec (pystring::capitalize(keyname), value); } // if we didn't found END keyword in current header, we read next one return read_fits_header (); }
/* process a line from the log and store it accordingly */ static int process_log (GLog * logger, char *line, int test) { GLogItem *glog; char buf[DATE_LEN]; char *qmark = NULL, *req_key = NULL; int not_found = 0; /* 404s */ /* make compiler happy */ memset (buf, 0, sizeof (buf)); if ((line == NULL) || (*line == '\0')) { logger->invalid++; return 0; } /* ignore comments */ if (*line == '#' || *line == '\n') return 0; if (parsing_spinner != NULL && parsing_spinner->state == SPN_RUN) pthread_mutex_lock (&parsing_spinner->mutex); logger->process++; #ifdef TCB_BTREE process_generic_data (ht_general_stats, "total_requests"); #endif if (parsing_spinner != NULL && parsing_spinner->state == SPN_RUN) pthread_mutex_unlock (&parsing_spinner->mutex); glog = init_log_item (logger); if (parse_format (glog, conf.log_format, conf.date_format, line) == 1) { logger->invalid++; #ifdef TCB_BTREE process_generic_data (ht_general_stats, "failed_requests"); #endif goto cleanup; } /* must have the following fields */ if (glog->host == NULL || glog->date == NULL || glog->status == NULL || glog->req == NULL) { logger->invalid++; goto cleanup; } if (test) goto cleanup; convert_date (buf, glog->date, conf.date_format, "%Y%m%d", DATE_LEN); if (buf == NULL) goto cleanup; /* ignore host */ if (conf.ignore_ip_idx && ip_in_range (glog->host)) { logger->exclude_ip++; #ifdef TCB_BTREE process_generic_data (ht_general_stats, "exclude_ip"); #endif goto cleanup; } /* ignore crawlers */ if (conf.ignore_crawlers && is_crawler (glog->agent)) goto cleanup; /* agent will be null in cases where %u is not specified */ if (glog->agent == NULL) glog->agent = alloc_string ("-"); /* process visitors, browsers, and OS */ process_unique_data (glog->host, buf, glog->agent); /* process agents that are part of a host */ if (conf.list_agents) process_host_agents (glog->host, glog->agent); /* is this a 404? */ if (!memcmp (glog->status, "404", 3)) { not_found = 1; } /* treat 444 as 404? */ else if (!memcmp (glog->status, "444", 3) && conf.code444_as_404) { not_found = 1; } /* check if we need to remove the request's query string */ else if (conf.ignore_qstr) { if ((qmark = strchr (glog->req, '?')) != NULL) { if ((qmark - glog->req) > 0) *qmark = '\0'; } } req_key = xstrdup (glog->req); /* include HTTP method/protocol to request */ if (conf.append_method && glog->method) { str_to_upper (glog->method); append_method_to_request (&req_key, glog->method); } if (conf.append_protocol && glog->protocol) { str_to_upper (glog->protocol); append_protocol_to_request (&req_key, glog->protocol); } if ((conf.append_method) || (conf.append_protocol)) req_key = deblank (req_key); /* process 404s */ if (not_found) process_request (ht_not_found_requests, req_key, glog); /* process static files */ else if (verify_static_content (glog->req)) process_request (ht_requests_static, req_key, glog); /* process regular files */ else process_request (ht_requests, req_key, glog); /* process referrers */ process_referrers (glog->ref); /* process status codes */ process_generic_data (ht_status_code, glog->status); /* process hosts */ process_generic_data (ht_hosts, glog->host); /* process bandwidth */ process_request_meta (ht_date_bw, buf, glog->resp_size); process_request_meta (ht_file_bw, req_key, glog->resp_size); process_request_meta (ht_host_bw, glog->host, glog->resp_size); /* process time taken to serve the request, in microseconds */ process_request_meta (ht_file_serve_usecs, req_key, glog->serve_time); process_request_meta (ht_host_serve_usecs, glog->host, glog->serve_time); logger->resp_size += glog->resp_size; #ifdef TCB_BTREE process_request_meta (ht_general_stats, "bandwidth", glog->resp_size); #endif cleanup: free_logger (glog); if (req_key != NULL) free (req_key); return 0; }
BOOL AIXERRPT_SSH_VALUE(char *server, int port, char *uid, char *pwd, char *inifile, int ngid, char* strmid, char *custpath, char *privatekeyfile, char *szReturn) { int ret = 0; char buffer[256] = {0}; char mbuffer[256] = {0}; char mdate[256] = {0}; char datebuff[64] = {0}; char curdate[64] = {0}; char szTmpIniFile[256] = {0}; int isChinese = 0; CString strResult = _T(""); if(DFNParser_GetPrivateProfileString("errorlog", "command", "", buffer, sizeof(buffer), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); return FALSE; } if(DFNParser_GetPrivateProfileString("errorlog", "matchline", "", mbuffer, sizeof(mbuffer), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); return FALSE; } if(DFNParser_GetPrivateProfileString("date", "command", "", mdate, sizeof(mdate), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); return FALSE; } isChinese = DFNParser_GetPrivateProfileInt("date", "isChinese", 0, inifile); if((ret = ssh_command(server,port, uid, pwd, mdate, privatekeyfile, strResult)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); return FALSE; } if(isChinese) { char week[64] = {0}; int years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0; if(sscanf(strResult, "公元%d年%d月%d日 %s %d时%d分%d秒", &years, &months, &days, week, &hours, &minutes, &seconds) != 7) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); return FALSE; } sprintf(curdate, "%2.2d%2.2d%2.2d%2.2d%2.2d", months, days, hours, minutes, years % 100); } else { char week[16] = {0}; char month[16] = {0}; int day = 0; int hours = 0, mins = 0, secs = 0; char div[16] = {0}; int year = 0; if(sscanf(strResult, "%s %s %d %d:%d:%d %s %d", week, month, &day, &hours, &mins, &secs, div, &year) != 8) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); return FALSE; } if(convert_date(month, day, hours, mins, year, curdate)) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); return FALSE; } } sprintf(szTmpIniFile, "logfile.ini"); DFN_GetPrivateProfileString(strmid, "lastdate", "", datebuff, sizeof(datebuff), szTmpIniFile); if(!*datebuff) strncpy(datebuff, curdate, 10); char *ca = NULL; if(ca = strchr(buffer, '<')) { strncpy(ca, datebuff, 10); *(ca + 10) = 0; } strResult = _T(""); if((ret = ssh_command(server, port, uid, pwd, buffer, privatekeyfile, strResult)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); return FALSE; } if(ret == 0 || !strstr(strResult, mbuffer)) { char tmp [256] = {0}; if(GetConfirms(strmid) > 0) DFN_WritePrivateProfileString(strmid, "needconfirm", _ltoa(FALSE, tmp, 10), szTmpIniFile); BOOL bChange = DFN_GetPrivateProfileInt(strmid, "needconfirm", FALSE, szTmpIniFile); if (!bChange) { //sprintf(szReturn, "status=%s$", FuncGetStringFromIDS("<%IDS_AIXErrpt_01%>")); sprintf(szReturn, "status=0$" ); //0: 未改变 1:改变 } else { //sprintf(szReturn, "status=%s$", FuncGetStringFromIDS("<%IDS_AIXErrpt_02%>")); sprintf(szReturn, "status=1$" ); //0: 未改变 1:改变 } } else { //sprintf(szReturn, "status=%s$", FuncGetStringFromIDS("<%IDS_AIXErrpt_02%>")); sprintf(szReturn, "status=1$" ); //0: 未改变 1:改变 FILE *fp = NULL; char szErrptLogFile[256] = {0}; sprintf(szErrptLogFile, "%s\\data\\TmpIniFile\\logfile_%s.log", FuncGetInstallRootPath(), strmid); if(fp = fopen(szErrptLogFile, "a+")) { fprintf(fp, "%s", strResult); fclose(fp); } char tmp [256] = {0}; DFN_WritePrivateProfileString(strmid, "needconfirm", _ltoa(TRUE, tmp, 10), szTmpIniFile); } DFN_WritePrivateProfileString(strmid, "lastdate", curdate, szTmpIniFile); return TRUE; }
void main(int argc, char **argv) { int c; int lib_opt = FALSE; int errflg = 0; extern int optind; extern char *optarg; char *libname,*fname; char *t_name; #ifdef IBM_PC fprintf(stderr, "NYU Ada/Ed Librarian Version 1.11.2\n"); fprintf(stderr, "Copyright (C) 1985-1992 by New York University.\n"); #endif #ifndef IBM_PC while((c = getopt(argc,argv,"l:"))!=EOF) { #else while((c = getopt(argc,argv,"L:l:"))!=EOF) { if (isupper(c)) c = tolower(c); #endif switch(c) { case 'l': /* specify library name */ lib_opt = TRUE; libname = strjoin(optarg,""); break; case '?': errflg++; } } fname = (char *)0; if (optind < argc) fname = argv[optind]; if (!lib_opt && fname == (char *)0) { fname = getenv("ADALIB"); if (fname!= (char *)0) { #ifdef IBM_PC fprintf(stderr, "L"); #else fprintf(stderr, "l"); #endif fprintf(stderr,"ibrary defined by ADALIB: %s\n", fname); } } if ((!lib_opt && fname == (char *)0) || errflg) { fprintf(stderr, "Usage: adalib [-l library]\n"); exit(1); } if (!lib_opt) { libname = emalloc(strlen(fname) + 1); strcpy(libname, fname); } t_name = libset(libname); LIBFILE = ifopen(LIBFILENAME, "", "r", 0); load_library(); exit(0); } static void load_library() /*;load_library*/ { /* * retrieve information from LIBFILE * Called only if lib_option and not newlib. */ int i, j, n, m, unumber, nodes, symbols; int comp_status, unit_count, cur_level; char *comp_date, *status_str, *uname, *aisname, *tmp_str; char *main_string; int is_main, empty_unit_slots, parent; int ignore; unit_count = getnum(LIBFILE, "lib-unit-count"); n = getnum(LIBFILE, "lib-n"); empty_unit_slots = getnum(LIBFILE, "lib-empty-slots"); tmp_str = getstr(LIBFILE, "lib-tmp-str"); for (i = 1; i <= unit_count; i++) { uname = getstr(LIBFILE, "lib-unit-name"); unumber = getnum(LIBFILE, "lib-unit-number"); aisname = getstr(LIBFILE, "lib-ais-name"); comp_date = getstr(LIBFILE, "unit-date"); symbols = getnum(LIBFILE, "lib-symbols"); nodes = getnum(LIBFILE, "lib-nodes"); is_main = getnum(LIBFILE, "lib-is-main"); if (is_main) { if (streq(unit_name_type(uname), "ma")) main_string = "(Interface)"; else main_string = " (Main) "; } else { main_string = ""; } comp_status = getnum(LIBFILE, "lib-status"); status_str = (comp_status) ? "active " : "obsolete"; printf("%8s %11s %-15s %s\n", status_str, main_string, convert_date(comp_date), formatted_name(uname)); } printf("\n"); n = getnum(LIBFILE, "lib-n"); if (n) { printf("stubs \n\n"); for (i = 1; i <= n; i++) { uname = getstr(LIBFILE, "lib-unit-name"); aisname = getstr(LIBFILE, "lib-ais-name"); parent = getnum(LIBFILE, "lib-parent"); cur_level = getnum(LIBFILE, "lib-cur-level"); m = getnum(LIBFILE, "stub-file-size"); for (j = 1; j <= m; j++) ignore = getnum(LIBFILE, "stub-file"); printf("%s\n", formatted_stub(uname)); } printf("\n"); } ifclose(LIBFILE); return; #ifdef TBSL n = getnum(LIBFILE, "precedes-map-size"); printf("precedes map\n"); for (i = 1; i <= n; i += 2) { dom = getnum(LIBFILE, "precedes-map-dom"); m = getnum(LIBFILE, "precedes-map-nelt"); printf(" %4d:", dom); for (j = 1; j <= m; j++) { range = getnum(LIBFILE, "precedes-map-ent"); printf(" %4d", range); } printf("\n"); } n = getnum(LIBFILE, "compilation_table_size"); if (n) { printf("\ncompilation table\n"); for (i = 1; i <= n; i++) { unum = (int) getnum(LIBFILE, "compilation-table-ent"); printf(" %d\n", unum); } printf("\n"); } /* late_instances */ n = getnum(LIBFILE, "late-instances-size"); if (n) { printf("late instances\n"); for (i = 1; i <= n; i++) { str = (char *) getstr(LIBFILE, "late-instances-str"); printf(" %s\n", str); } } /* current code segment */ n = getnum(LIBFILE, "unit-size"); printf("\ncurrent code segments\n"); printf(" unit cs\n"); for (i = 1; i <= n; i++) { cs = getnum(LIBFILE, "current-code-segment"); if (cs) printf(" %d: %d\n", i, cs); } /* local reference maps */ n = getnum(LIBFILE, "unit-size"); get_local_ref_maps(LIBFILE, n); cde_pos = get_cde_slots(LIBFILE, axq); /* could free axq_data_slots, etc., but keep for now */ /* read out LIB_STUB map (always empty for now) */ ifclose(LIBFILE); return; #endif }
bool AIXERRPT_TEL_VALUE(char *server, int port, char *uid, char *pwd, char *pserver, int pport, char *puid, char *ppwd, char *lprom, char *pprom, char *prom, char *inifile, int ngid, char* strmid, char *custpath, char *szReturn) { int ret = 0; int hSocket = 0; bool bResult = TRUE; char buffer[256] = {0}; char mbuffer[256] = {0}; char mdate[256] = {0}; char datebuff[64] = {0}; char curdate[64] = {0}; //char szIniFile[256] = {0}; char szTmpIniFile[256] = {0}; int isChinese = 0; //puts("ok"); /************************************* * For Reason Of Prompt */ int c = 0; char *ca = prom, *cb = NULL; char arprompt[PR_NUM][256]; memset(arprompt, 0, sizeof(arprompt)); LPGDATA pgd=new GDATA; memset(pgd,0,sizeof(GDATA)); while(cb = strchr(ca, 0x20)) { if(ca == cb) { ca ++; continue; } strncpy(arprompt[c++], ca, cb - ca); ca = cb + 1; } strcpy(arprompt[c++], ca); /***********************************/ hSocket = telnet_init(server, port, pserver, pport, puid, ppwd); if(hSocket <= 0) { if(hSocket == -1) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_1%>"));//<%IDS_MQ_1%>"连接失败:域名解析" else if(hSocket == -2) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_2%>"));//<%IDS_MQ_2%>"连接失败:通信初始化" else if(hSocket == -3) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_3%>"));//<%IDS_MQ_3%>"连接失败:连接超时" else if(hSocket == -4) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_4%>"));//<%IDS_MQ_4%>"代理服务器连接失败" else if(hSocket == -5) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_5%>"));//<%IDS_MQ_5%>"代理服务器错误" else sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_6%>"));//<%IDS_MQ_6%>"连接失败:未知错误" bResult = FALSE; goto err; } Tel_Param param; if((ret = telnet_connect(hSocket, uid, pwd, lprom, pprom, arprompt,pgd,¶m)) < 0) { if(ret == -1) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_7%>"));//<%IDS_MQ_7%>"登录失败:读数据超时" else if(ret == -2) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_8%>"));//<%IDS_MQ_8%>"登录失败:读数据错误" else if(ret == -3) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_9%>"));//<%IDS_MQ_9%>"登录失败:查找提示符" else if(ret == -4) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_10%>"));//<%IDS_MQ_10%>"登录失败:查找登录提示符" else if(ret == -5) sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_11%>"));//<%IDS_MQ_11%>"登录失败:查找密码提示符" else sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_MQ_12%>"));//<%IDS_MQ_12%>"登录失败:未知错误" bResult = FALSE; goto err; } if(DFNParser_GetPrivateProfileString("errorlog", "command", "", buffer, sizeof(buffer), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); bResult = FALSE; goto err; } if(DFNParser_GetPrivateProfileString("errorlog", "matchline", "", mbuffer, sizeof(mbuffer), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); bResult = FALSE; goto err; } if(DFNParser_GetPrivateProfileString("date", "command", "", mdate, sizeof(mdate), inifile) <= 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_02%>")); bResult = FALSE; goto err; } isChinese = DFNParser_GetPrivateProfileInt("date", "isChinese", 0, inifile); if((ret = telnet_command(hSocket, mdate,pgd,¶m)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); bResult = FALSE; goto err; } if(isChinese) { char week[64] = {0}; int years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0; if(sscanf(pgd->databuffer, "公元%d年%d月%d日 %s %d时%d分%d秒", &years, &months, &days, week, &hours, &minutes, &seconds) != 7) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); bResult = FALSE; goto err; } sprintf(curdate, "%2.2d%2.2d%2.2d%2.2d%2.2d", months, days, hours, minutes, years % 100); } else { char week[16] = {0}; char month[16] = {0}; int day = 0; int hours = 0, mins = 0, secs = 0; char div[16] = {0}; int year = 0; if(sscanf(pgd->databuffer, "%s %s %d %d:%d:%d %s %d", week, month, &day, &hours, &mins, &secs, div, &year) != 8) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); bResult = FALSE; goto err; } if(convert_date(month, day, hours, mins, year, curdate)) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); bResult = FALSE; goto err; } } sprintf(szTmpIniFile, "logfile.ini"); DFN_GetPrivateProfileString(strmid, "lastdate", "", datebuff, sizeof(datebuff), szTmpIniFile); if(!*datebuff) strncpy(datebuff, curdate, 10); if(ca = strchr(buffer, '<')) { strncpy(ca, datebuff, 10); *(ca + 10) = 0; } memset(pgd->databuffer, 0, BUF_SIZE); pgd->datalen = 0; printf("Error Report Command is :%s\n", buffer); if((ret = telnet_command(hSocket, buffer,pgd)) < 0) { sprintf(szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_LOGFILE_01%>")); bResult = FALSE; goto err; } if(ret == 0 || !strstr(pgd->databuffer, mbuffer)) { char tmp [256] = {0}; //ofstream fout("aixerr.log",ios::app); //int i = GetConfirms(strmid); //fout << itoa(i, tmp, 10) <<"\r\n"; //fout << flush; //fout.close(); if(GetConfirms(strmid) > 0) DFN_WritePrivateProfileString(strmid, "needconfirm", _ltoa(FALSE, tmp, 10), szTmpIniFile); BOOL bChange = DFN_GetPrivateProfileInt(strmid, "needconfirm", FALSE, szTmpIniFile); if (!bChange) { sprintf(szReturn, "status=0$" ); //0: 未改变 1:改变 } else { sprintf(szReturn, "status=1$" ); } } else { sprintf(szReturn, "status=1$" ); FILE *fp = NULL; char szErrptLogFile[256] = {0}; sprintf(szErrptLogFile, "%s\\data\\TmpIniFile\\logfile_%s.log", FuncGetInstallRootPath(), strmid); if(fp = fopen(szErrptLogFile, "a+")) { fprintf(fp, "%s", pgd->databuffer); fclose(fp); } char tmp [256] = {0}; printf("Track record\n"); DFN_WritePrivateProfileString(strmid, "needconfirm", _ltoa(TRUE, tmp, 10), szTmpIniFile); } DFN_WritePrivateProfileString(strmid, "lastdate", curdate, szTmpIniFile); err: shutdown(hSocket, 0x02); closesocket(hSocket); delete pgd; return bResult; }