bool FileReadRS::render(stk::StkFrames &frames, MuTick base_tick, MuTick start_tick, MuTick end_tick) { // check for format mismatch if (!verify_format(frames)) return false; // check for end of file if (start_tick >= file_read_.fileSize()) return false; if ((start_tick == base_tick) && (end_tick == base_tick + frames.frames())) { // render directly into frames file_read_.read(frames, base_tick); return true; } else if (start_tick < end_tick) { temp_buffer_.resize(end_tick - start_tick, frames.channels()); file_read_.read(temp_buffer_, start_tick); // TODO: memcpy! MuTick offset = start_tick - base_tick; for (int i=0; i<temp_buffer_.frames(); i++) { for (int j=0; j<frames.channels(); j++) { frames(i+offset, j) = temp_buffer_(i, j); } } return true; } else { return false; // nothing to render } }
void FileReadRS::render(stk::StkFrames &frames, MuTick base_tick, MuTick start_tick, MuTick end_tick) { // check for format mismatch if (!verify_format(frames)) return; // check for end of file if (start_tick >= file_read_.fileSize()) return; // fast and loose: this simply fills as much of the buffer as // possible on each call without honoring start_tick or end_tick. file_read_.read(frames, base_tick); }
/* * Reads config parameters from configfile * uses default values if errstr occurs */ static int readconfigfile(const char *filename, struct configparams *config) { FILE *fp; char buff[IOBUF_SIZE]; char *var; char *value; char *pos; int line, len, bufpos; char *locale; /* set default values */ sstrncpy(config->mail_cmd, MAIL_CMD, CNF_BUFFER); sstrncpy(config->from, FROM, CNF_BUFFER); sstrncpy(config->subject, SUBJECT, CNF_BUFFER); sstrncpy(config->cc_to, CC_TO, CNF_BUFFER); sstrncpy(config->support, SUPPORT, CNF_BUFFER); sstrncpy(config->phone, PHONE, CNF_BUFFER); (config->charset)[0] = '\0'; setlocale(LC_ALL, NULL); locale = setlocale(LC_MESSAGES, NULL); if (locale && strcasecmp(locale, "posix") && strcasecmp(locale, "c")) { locale = nl_langinfo(CODESET); sstrncpy(config->charset, locale, CNF_BUFFER); } maildev[0] = 0; config->user_signature = config->user_message = config->group_signature = config->group_message = NULL; config->use_ldap_mail = 0; config->cc_before = -1; #ifdef USE_LDAP_MAIL_LOOKUP config->ldap_port = config->ldap_is_setup = 0; config->ldap_host[0] = 0; config->ldap_uri[0] = 0; #endif if (!(fp = fopen(filename, "r"))) { errstr(_("Cannot open %s: %s\n"), filename, strerror(errno)); return -1; } line = 0; bufpos = 0; while (fgets(buff + bufpos, sizeof(buff) - bufpos, fp)) { /* start reading lines */ line++; if (!bufpos) { /* check for comments or empty lines */ if (buff[0] == '#' || buff[0] == ';') continue; /* Is line empty? */ for (pos = buff; isspace(*pos); pos++); if (!*pos) /* Nothing else was on the line */ continue; } len = bufpos + strlen(buff+bufpos); if (buff[len-1] != '\n') errstr(_("Line %d too long. Truncating.\n"), line); else { len--; if (buff[len-1] == '\\') { /* Should join with next line? */ bufpos = len-1; continue; } } buff[len] = 0; bufpos = 0; /* check for a '=' char */ if ((pos = strchr(buff, '='))) { *pos = 0; /* split buff in two parts: var and value */ var = buff; value = pos + 1; stripstring(&var); stripstring(&value); /* check if var matches anything */ if (!strcmp(var, "MAIL_CMD")) sstrncpy(config->mail_cmd, value, CNF_BUFFER); else if (!strcmp(var, "FROM")) sstrncpy(config->from, value, CNF_BUFFER); else if (!strcmp(var, "SUBJECT")) sstrncpy(config->subject, value, CNF_BUFFER); else if (!strcmp(var, "CC_TO")) sstrncpy(config->cc_to, value, CNF_BUFFER); else if (!strcmp(var, "SUPPORT")) sstrncpy(config->support, value, CNF_BUFFER); else if (!strcmp(var, "PHONE")) sstrncpy(config->phone, value, CNF_BUFFER); else if (!strcmp(var, "CHARSET")) sstrncpy(config->charset, value, CNF_BUFFER); else if (!strcmp(var, "MAILDEV")) /* set the global */ sstrncpy(maildev, value, CNF_BUFFER); else if (!strcmp(var, "MESSAGE")) { config->user_message = sstrdup(value); create_eoln(config->user_message); verify_format(config->user_message, "MESSAGE"); } else if (!strcmp(var, "SIGNATURE")) { config->user_signature = sstrdup(value); create_eoln(config->user_signature); verify_format(config->user_signature, "SIGNATURE"); } else if (!strcmp(var, "GROUP_MESSAGE")) { config->group_message = sstrdup(value); create_eoln(config->group_message); verify_format(config->group_message, "GROUP_MESSAGE"); } else if (!strcmp(var, "GROUP_SIGNATURE")) { config->group_signature = sstrdup(value); create_eoln(config->group_signature); verify_format(config->group_signature, "GROUP_SIGNATURE"); } else if (!strcmp(var, "LDAP_MAIL")) { if(strcasecmp(value, "true") == 0) config->use_ldap_mail = 1; else config->use_ldap_mail = 0; } else if (!strcmp(var, "CC_BEFORE")) { int num; char unit[10]; if (sscanf(value, "%d%s", &num, unit) != 2) goto cc_parse_err; if (str2timeunits(num, unit, &config->cc_before) < 0) { cc_parse_err: die(1, _("Cannot parse time at CC_BEFORE variable (line %d).\n"), line); } } #ifdef USE_LDAP_MAIL_LOOKUP else if (!strcmp(var, "LDAP_HOST")) sstrncpy(config->ldap_host, value, CNF_BUFFER); else if (!strcmp(var, "LDAP_PORT")) config->ldap_port = (int)strtol(value, NULL, 10); else if (!strcmp(var, "LDAP_URI")) sstrncpy(config->ldap_uri, value, CNF_BUFFER); else if(!strcmp(var, "LDAP_BINDDN")) sstrncpy(config->ldap_binddn, value, CNF_BUFFER); else if(!strcmp(var, "LDAP_BINDPW")) sstrncpy(config->ldap_bindpw, value, CNF_BUFFER); else if(!strcmp(var, "LDAP_BASEDN")) sstrncpy(config->ldap_basedn, value, CNF_BUFFER); else if(!strcmp(var, "LDAP_SEARCH_ATTRIBUTE")) sstrncpy(config->ldap_search_attr, value, CNF_BUFFER); else if(!strcmp(var, "LDAP_MAIL_ATTRIBUTE")) sstrncpy(config->ldap_mail_attr, value, CNF_BUFFER); else if(!strcmp(var, "LDAP_DEFAULT_MAIL_DOMAIN")) sstrncpy(config->default_domain, value, CNF_BUFFER); #endif else /* not matched at all */ errstr(_("Error in config file (line %d), ignoring\n"), line); } else /* no '=' char in this line */ errstr(_("Possible error in config file (line %d), ignoring\n"), line); } if (bufpos) errstr(_("Unterminated last line, ignoring\n")); #ifdef USE_LDAP_MAIL_LOOKUP if (config->use_ldap_mail) { if (!config->ldap_uri[0]) { snprintf(config->ldap_uri, CNF_BUFFER, "ldap://%s:%d", config->ldap_host, config->ldap_port); errstr(_("LDAP library version >= 2.3 detected. Please use LDAP_URI instead of hostname and port.\nGenerated URI %s\n"), config->ldap_uri); } } #endif fclose(fp); return 0; }
int main (int argc, char **argv) { int quit = 0; #if defined(__GLIBC__) setup_signal_handlers (); #endif /* command line/config options */ verify_global_config (argc, argv); parse_conf_file (&argc, &argv); parse_cmd_line (argc, argv); /* initialize storage */ init_storage (); /* setup to use the current locale */ set_locale (); #ifdef HAVE_LIBGEOIP init_geoip (); #endif /* init logger */ logger = init_log (); /* init parsing spinner */ parsing_spinner = new_gspinner (); parsing_spinner->process = &logger->process; /* outputting to stdout */ if (conf.output_html) { ui_spinner_create (parsing_spinner); goto out; } /* init curses */ set_input_opts (); if (conf.no_color || has_colors () == FALSE) { conf.color_scheme = NO_COLOR; conf.no_color = 1; } else { start_color (); } init_colors (); init_windows (&header_win, &main_win); set_curses_spinner (parsing_spinner); /* configuration dialog */ if (isatty (STDIN_FILENO) && (conf.log_format == NULL || conf.load_conf_dlg)) { refresh (); quit = verify_format (logger, parsing_spinner); } /* straight parsing */ else { ui_spinner_create (parsing_spinner); } out: /* main processing event */ time (&start_proc); if (conf.load_from_disk) set_general_stats (); else if (!quit && parse_log (&logger, NULL, -1)) FATAL ("Error while processing file"); logger->offset = logger->process; /* no valid entries to process from the log */ if ((logger->process == 0) || (logger->process == logger->invalid)) FATAL ("Nothing valid to process."); /* init reverse lookup thread */ gdns_init (); parse_initial_sort (); allocate_holder (); end_spinner (); time (&end_proc); /* stdout */ if (conf.output_html) { /* CSV */ if (conf.output_format && strcmp ("csv", conf.output_format) == 0) output_csv (logger, holder); /* JSON */ else if (conf.output_format && strcmp ("json", conf.output_format) == 0) output_json (logger, holder); /* HTML */ else output_html (logger, holder); } /* curses */ else { allocate_data (); if (!conf.skip_term_resolver) gdns_thread_create (); render_screens (); get_keys (); attroff (COLOR_PAIR (COL_WHITE)); /* restore tty modes and reset * terminal into non-visual mode */ endwin (); } /* clean */ house_keeping (); return EXIT_SUCCESS; }