示例#1
0
GList *
conting_load_flow_file_relat2(const gchar *filename)
{
	ContingItemData *item_data;

	FILE *fp = fopen(filename, "r");
	gchar buf[256];
	GList *result = NULL;

	if (fp == NULL)
		return NULL;

	skip_lines(fp, 8);

	while (fgets(buf, 256, fp)) {
		if (buf[0] == '-')
			break;
		
		item_data = read_item_data_relat2(buf);
		result = g_list_append(result, item_data);
		puts(buf);
	}

	skip_lines(fp, 9);

	while (fgets(buf, 256, fp)) {
		if (buf[0] == '-')
			break;
		item_data = read_item_data_trans(buf);
		result = g_list_append(result, item_data);
		puts(buf);
	}

	return result;
}
示例#2
0
int main(int argc, char **argv) {
	int ret 	= 0;
	int err 	= 0;
	int stime	= 0;
	FILE *fp = NULL;
	
	if (argc != 3) {
		printf("%s [file_name] [interval]\n", argv[0]);
	} else {
		stime 	= atoi(argv[2]);
		fp	= fopen(argv[1], "r");
		
		if (fp == NULL) {
			printf("Unable to open file %s!  Exiting ungracefully...\n", argv[1]);
		} else {
			struct parsed_data pd;
			struct parsed_time end;
			
			if ((err = skip_lines(fp, 2)) == 0) {
				set_fstart(fp);
				
				err = interval_data(fp, &pd, stime, &end);
				
				if (err == 0 || err == ERR_END_OF_FILE) {
					print_json(&pd, &end);
				}
			}
			
			fclose(fp);
		}
	}
	
	return ret;
}
示例#3
0
// Objekt ueberspringen -------------------------------------------------------
int error_skip_lines (char *pattern, int error_code) 
{
// Fehlermeldung ausgeben

	db_error (error_code, ASCPARSER, yylineno);
	satz_nr = 0;			// Objekt nicht speichern
	skip_lines (pattern);		// Satz suchen

return (error_code);
}
示例#4
0
static void restore_line_number(void)
{
	char line[LINE_BUFFER_SIZE];
	if (skip_lines(rec_pos, line)) {
		if (ferror(word_file))
			pexit("fgets");
		fprintf(stderr, "fgets: Unexpected EOF\n");
		error();
	}
}
static struct Conv_Order_Data* constructor_Conv_Order_Data
	(const struct Integration_Test_Info*const int_test_info, const int error_type,
	 const struct Simulation*const sim)
{
	const int*const p_range  = get_conv_order_range(int_test_info,'p'),
	         *const ml_range = get_conv_order_range(int_test_info,'m');

	const char*const input_name = compute_error_input_name_root(int_test_info,error_type,false,sim);

	const int n_err = compute_n_err(input_name);
	ptrdiff_t extents[]    = { ml_range[1]+1, p_range[1]+1, n_err, };
	const ptrdiff_t base_e = extents[0]*extents[1];

	char**const var_names = malloc((unsigned)n_err * sizeof *var_names); // moved
	for (int i = 0; i < extents[2]; ++i)
		var_names[i] = malloc(STRLEN_MIN * sizeof *var_names); // moved
	struct Multiarray_i* cases_run   = constructor_zero_Multiarray_i('C',2,&extents[0]); // moved
	struct Multiarray_d* h           = constructor_zero_Multiarray_d('C',2,&extents[0]); // moved
	struct Multiarray_i* ex_ord      = constructor_zero_Multiarray_i('C',3,extents);     // moved
	struct Multiarray_d* l2_err      = constructor_zero_Multiarray_d('C',3,extents);     // moved
	struct Multiarray_d* conv_orders = constructor_zero_Multiarray_d('C',3,extents);     // moved

	bool read_var_names = true;
	for (int p = p_range[0]; p <= p_range[1]; ++p) {
	for (int ml = ml_range[0]; ml <= ml_range[1]; ++ml) {
		const char*const input_name_curr = set_file_name_curr(ADAPT_0,p,ml,true,input_name);

		char line[STRLEN_MAX];
		FILE* p_file = fopen_sp_input_file_unchecked('p',input_name_curr,"txt",0); // closed
		if (!p_file)
			continue;

		skip_lines(p_file,1);
		fgets_checked(line,sizeof(line),p_file);
		int data_i[n_err];
		read_skip_i_1(line,1,data_i,n_err);

		if (read_var_names) {
			read_var_names = false;
			skip_lines(p_file,1);
			fgets_checked(line,sizeof(line),p_file);
			read_skip_c_2(line,1,var_names,n_err);
		} else {
			skip_lines(p_file,2);
		}

		fgets_checked(line,sizeof(line),p_file);

		double data_d[n_err+1];
		read_skip_d_1(line,0,data_d,n_err+1);
		fclose(p_file);

		const ptrdiff_t ind_h = compute_index_sub_container(h->order,0,h->extents,(ptrdiff_t[]){ml,p});
		h->data[ind_h] = data_d[0];
		cases_run->data[ind_h] = 1;

		for (int n = 0; n < n_err; ++n) {
			const ptrdiff_t ind_e = n*base_e + p*extents[0] + ml;
			l2_err->data[ind_e] = data_d[n+1];
			ex_ord->data[ind_e] = data_i[n];
		}
	}}

	for (int p = p_range[0]; p <= p_range[1]; ++p) {
	for (int ml = ml_range[0]+1; ml <= ml_range[1]; ++ml) {
	for (int n = 0; n < n_err; ++n) {
		const ptrdiff_t ind_c_h = p*extents[0] + ml-1,
		                ind_f_h = p*extents[0] + ml,
		                ind_c_e = n*base_e + ind_c_h,
		                ind_f_e = n*base_e + ind_f_h;

		double* data_l2 = l2_err->data,
		      * data_h  = h->data;

		if (data_h[ind_f_h] == 0.0 || data_h[ind_c_h] == 0.0)
			continue;

		conv_orders->data[ind_f_e] =
			log10(data_l2[ind_f_e]/data_l2[ind_c_e])/log10(data_h[ind_f_h]/data_h[ind_c_h]);
	}}}

	struct Conv_Order_Data*const cod = malloc(sizeof *cod);      // free
	cod->var_names   = (const char*const*) var_names;            // free (2 levels)
	cod->cases_run   = (struct const_Multiarray_i*) cases_run;   // destructed
	cod->h           = (struct const_Multiarray_d*) h;           // destructed
	cod->ex_ord      = (struct const_Multiarray_i*) ex_ord;      // destructed
	cod->l2_err      = (struct const_Multiarray_d*) l2_err;      // destructed
	cod->conv_orders = (struct const_Multiarray_d*) conv_orders; // destructed

	return cod;
}
示例#6
0
void do_wordlist_crack(struct db_main *db, char *name, int rules)
{
	union {
		char buffer[2][LINE_BUFFER_SIZE + CACHE_BANK_SHIFT];
		ARCH_WORD dummy;
	} aligned;
	char *line = aligned.buffer[0], *last = aligned.buffer[1];
	struct rpp_context ctx;
	char *prerule, *rule, *word;
	char *(*apply)(char *word, char *rule, int split, char *last);
	int dist_rules, dist_switch;
	unsigned long my_words, their_words, my_words_left;

	log_event("Proceeding with wordlist mode");

	if (name) {
		if (!(word_file = fopen(path_expand(name), "r")))
			pexit("fopen: %s", path_expand(name));
		log_event("- Wordlist file: %.100s", path_expand(name));
	} else {
		word_file = stdin;
		log_event("- Reading candidate passwords from stdin");
	}

	length = db->format->params.plaintext_length;

	if (rules) {
		if (rpp_init(rule_ctx = &ctx, SUBSECTION_WORDLIST)) {
			log_event("! No wordlist mode rules found");
			if (john_main_process)
				fprintf(stderr,
				    "No wordlist mode rules found in %s\n",
				    cfg_name);
			error();
		}

		rules_init(length);
		rule_count = rules_count(&ctx, -1);

		log_event("- %d preprocessed word mangling rules", rule_count);

		apply = rules_apply;
	} else {
		rule_ctx = NULL;
		rule_count = 1;

		log_event("- No word mangling rules");

		apply = dummy_rules_apply;
	}

	rule_number = 0;
	line_number = 0;

	status_init(get_progress, 0);

	rec_restore_mode(restore_state);
	rec_init(db, save_state);

	crk_init(db, fix_state, NULL);

	prerule = rule = "";
	if (rules)
		prerule = rpp_next(&ctx);

/* A string that can't be produced by fgetl(). */
	last[0] = '\n';
	last[1] = 0;

	dist_rules = 0;
	dist_switch = rule_count; /* never */
	my_words = ~0UL; /* all */
	their_words = 0;
	if (options.node_count) {
		int rule_rem = rule_count % options.node_count;
		const char *now, *later = "";
		dist_switch = rule_count - rule_rem;
		if (!rule_rem || rule_number < dist_switch) {
			dist_rules = 1;
			now = "rules";
			if (rule_rem)
				later = ", then switch to distributing words";
		} else {
			dist_switch = rule_count; /* never */
			my_words = options.node_max - options.node_min + 1;
			their_words = options.node_count - my_words;
			now = "words";
		}
		log_event("- Will distribute %s across nodes%s", now, later);
	}

	my_words_left = my_words;
	if (their_words) {
		if (line_number) {
/* Restored session.  line_number is right after a word we've actually used. */
			int for_node = line_number % options.node_count + 1;
			if (for_node < options.node_min ||
			    for_node > options.node_max) {
/* We assume that line_number is at the beginning of other nodes' block */
				if (skip_lines(their_words, line) &&
/* Check for error since a mere EOF means next rule (the loop below should see
 * the EOF again, and it will skip to next rule if applicable) */
				    ferror(word_file))
					prerule = NULL;
			} else {
				my_words_left =
				    options.node_max - for_node + 1;
			}
		} else {
/* New session.  Skip lower-numbered nodes' lines. */
			if (skip_lines(options.node_min - 1, line))
				prerule = NULL;
		}
	}

	if (prerule)
	do {
		if (rules) {
			if (dist_rules) {
				int for_node =
				    rule_number % options.node_count + 1;
				if (for_node < options.node_min ||
				    for_node > options.node_max)
					goto next_rule;
			}
			if ((rule = rules_reject(prerule, -1, last, db))) {
				if (strcmp(prerule, rule))
					log_event("- Rule #%d: '%.100s'"
						" accepted as '%.100s'",
						rule_number + 1, prerule, rule);
				else
					log_event("- Rule #%d: '%.100s'"
						" accepted",
						rule_number + 1, prerule);
			} else {
				log_event("- Rule #%d: '%.100s' rejected",
					rule_number + 1, prerule);
				goto next_rule;
			}
		}

		while (fgetl(line, LINE_BUFFER_SIZE, word_file)) {
			line_number++;

			if (line[0] != '#') {
process_word:
				if ((word = apply(line, rule, -1, last))) {
					last = word;

					if (ext_filter(word))
					if (crk_process_key(word)) {
						rules = 0;
						break;
					}
				}
next_word:
				if (--my_words_left)
					continue;
				if (skip_lines(their_words, line))
					break;
				my_words_left = my_words;
				continue;
			}

			if (strncmp(line, "#!comment", 9))
				goto process_word;
			goto next_word;
		}

		if (ferror(word_file))
			break;

		if (rules) {
next_rule:
			if (!(rule = rpp_next(&ctx))) break;
			rule_number++;

			if (rule_number >= dist_switch) {
				log_event("- Switching to distributing words");
				dist_rules = 0;
				dist_switch = rule_count; /* not anymore */
				my_words =
				    options.node_max - options.node_min + 1;
				their_words = options.node_count - my_words;
			}

			line_number = 0;
			if (fseek(word_file, 0, SEEK_SET))
				pexit("fseek");

			if (their_words &&
			    skip_lines(options.node_min - 1, line))
				break;
		}

		my_words_left = my_words;
	} while (rules);

	crk_done();
	rec_done(event_abort || (status.pass && db->salts));

	if (ferror(word_file)) pexit("fgets");

	if (name) {
		if (event_abort)
			progress = get_progress();
		else
			progress = 100;

		if (fclose(word_file)) pexit("fclose");
		word_file = NULL;
	}
}
示例#7
0
文件: vamas.cpp 项目: wojdyr/xylib
// Vamas file is organized as
// file_header block_header block_data [block_header block_data] ...
// There is only a value in every line without a key or label; the meaning is
// determined by its position and values in preceding lines
void VamasDataSet::load_data(std::istream &f, const char*)
{
    int n;
    skip_whitespace(f);
    skip_lines(f, 1);   // magic number: "VAMAS Sur..."
    meta["institution identifier"] = read_line_trim(f);
    meta["institution model identifier"] = read_line_trim(f);
    meta["operator identifier"] = read_line_trim(f);
    meta["experiment identifier"] = read_line_trim(f);

    // skip comment lines, n is number of lines
    n = read_line_int(f);
    skip_lines(f, n);

    exp_mode_ = read_line_trim(f);
    // make sure exp_mode_ has a valid value
    assert_in_array(exp_mode_, exps, "exp_mode");

    scan_mode_ = read_line_trim(f);
    // make sure scan_mode_ has a valid value
    assert_in_array(scan_mode_, scans, "scan_mode");

    // some exp_mode_ specific file-scope meta-info
    if ("MAP" == exp_mode_ || "MAPD" == exp_mode_ ||
        "NORM" == exp_mode_ || "SDP" == exp_mode_) {
        meta["number of spectral regions"] = read_line_trim(f);
    }
    if ("MAP" == exp_mode_ || "MAPD" == exp_mode_) {
        meta["number of analysis positions"] = read_line_trim(f);
        meta["number of discrete x coordinates available in full map"]
                                                            = read_line_trim(f);
        meta["number of discrete y coordinates available in full map"]
                                                            = read_line_trim(f);
    }

    // experimental variables
    exp_var_cnt_ = read_line_int(f);
    for (int i = 1; i <= exp_var_cnt_; ++i) {
        meta["experimental variable label " + S(i)] = read_line_trim(f);
        meta["experimental variable unit " + S(i)] = read_line_trim(f);
    }

    // number of entries in parameter inclusion or exclusion list
    n = read_line_int(f);
    // If the values of any of the block parameters are the same in all of the
    // blocks their values may be sent in the first block and then omitted
    // from all subsequent blocks.
    // n > 0 : the parameters listed are to be included
    // n < 0 : the parameters listed are to be excluded
    // n = 0 : all parameters are to be given in all blocks
    // A complete block contains 40 parts.
    bool all[40], inclusion_list[40];
    for (int i = 0; i < 40; ++i) {
        all[i] = true;
        inclusion_list[i] = (n <= 0);
    }
    for (int i = 0; i < (n >= 0 ? n : -n); ++i) {
        int idx = read_line_int(f) - 1; // "-1" because the input is 1-based
        inclusion_list[idx] = !inclusion_list[idx];
    }

    // # of manually entered items in block
    n = read_line_int(f);
    skip_lines(f, n);

    int exp_fue = read_line_int(f); // # of future upgrade experiment entries
    blk_fue_ = read_line_int(f); // # of future upgrade block entries
    skip_lines(f, exp_fue);

    // handle the blocks
    unsigned blk_cnt = read_line_int(f);
    const Block* first_block = NULL;
    for (unsigned i = 0; i < blk_cnt; ++i) {
        Block *blk = read_block(f, i == 0 ? all : inclusion_list, first_block);
        if (i == 0)
            first_block = blk;
        add_block(blk);
    }
}
示例#8
0
文件: vamas.cpp 项目: wojdyr/xylib
// read one block from file
Block* VamasDataSet::read_block(istream &f, bool includes[],
                                const Block* first_block)
{
    Block *block = new Block;
    double x_start=0., x_step=0.;
    string x_name;

    vector<VecColumn*> ycols;

    block->set_name(read_line_trim(f));
    block->meta["sample identifier"] = read_line_trim(f);

    string date_time;
    string first_dt;
    if (first_block)
        first_dt = first_block->meta.get("date_time");
    // year, month, etc. should be numbers, but don't assume it, just in case
    if (includes[0]) {
        date_time = read_line_trim(f);
        if (date_time.size() < 4)
            date_time.insert(date_time.begin(), 4 - date_time.size(), ' ');
    } else {
        date_time = first_dt.substr(0, 4);
    }

    date_time += includes[1] ? "-" + two_digit(read_line_trim(f))
                             : first_dt.substr(4, 3);;
    date_time += includes[2] ? "-" + two_digit(read_line_trim(f))
                             : first_dt.substr(7, 3);;
    date_time += includes[3] ? " " + two_digit(read_line_trim(f))
                             : first_dt.substr(10, 3);;
    date_time += includes[4] ? ":" + two_digit(read_line_trim(f))
                             : first_dt.substr(13, 3);;
    date_time += includes[5] ? ":" + two_digit(read_line_trim(f))
                             : first_dt.substr(16, 3);;
    if (includes[6]) {
        string timezone = read_line_trim(f);
        if (!timezone.empty()) {
            if (timezone[0] == '-')
                date_time += " -" + two_digit(timezone.substr(1)) + "00";
            else
                date_time += " +" + two_digit(timezone) + "00";
        }
    }
    block->meta["date_time"] = date_time;

    if (includes[7]) {   // skip comments on this block
        int cmt_lines = read_line_int(f);
        skip_lines(f, cmt_lines);
    }

    string tech;
    if (includes[8]) {
        tech = read_line_trim(f);
        block->meta["tech"] = tech;
        assert_in_array(tech, techs, "tech");
    }

    if (includes[9]) {
        if ("MAP" == exp_mode_ || "MAPDP" == exp_mode_) {
            block->meta["x coordinate"] = read_line_trim(f);
            block->meta["y coordinate"] = read_line_trim(f);
        }
    }

    if (includes[10]) {
        for (int i = 0; i < exp_var_cnt_; ++i) {
            block->meta["experimental variable value " + S(i)] = read_line_trim(f);
        }
    }

    if (includes[11])
        block->meta["analysis source label"] = read_line_trim(f);

    if (includes[12]) {
        if ("MAPDP" == exp_mode_ || "MAPSVDP" == exp_mode_
                || "SDP" == exp_mode_ || "SDPSV" == exp_mode_
                || "SNMS energy spec" == tech || "FABMS" == tech
                || "FABMS energy spec" == tech || "ISS" == tech
                || "SIMS" == tech || "SIMS energy spec" == tech
                || "SNMS" == tech) {
            block->meta["sputtering ion oratom atomic number"]
                                                          = read_line_trim(f);
            block->meta["number of atoms in sputtering ion or atom particle"]
                                                          = read_line_trim(f);
            block->meta["sputtering ion or atom charge sign and number"]
                                                          = read_line_trim(f);
        }
    }

    if (includes[13])
        // a.k.a "analysis source characteristic energy"
        block->meta["source energy"] = read_line_trim(f);
    if (includes[14])
        block->meta["analysis source strength"] = read_line_trim(f);

    if (includes[15]) {
        block->meta["analysis source beam width x"] = read_line_trim(f);
        block->meta["analysis source beam width y"] = read_line_trim(f);
    }

    if (includes[16]) {
        if ("MAP" == exp_mode_ || "MAPDP" == exp_mode_ || "MAPSV" == exp_mode_
                || "MAPSVDP" == exp_mode_ || "SEM" == exp_mode_) {
            block->meta["field of view x"] = read_line_trim(f);
            block->meta["field of view y"] = read_line_trim(f);
        }
    }

    if (includes[17]) {
        if ("SEM" == exp_mode_ || "MAPSV" == exp_mode_
                || "MAPSVDP" == exp_mode_) {
            throw FormatError("unsupported MAPPING mode");
        }
    }

    if (includes[18])
        block->meta["analysis source polar angle of incidence"] = read_line_trim(f);
    if (includes[19])
        block->meta["analysis source azimuth"] = read_line_trim(f);
    if (includes[20])
        block->meta["analyser mode"] = read_line_trim(f);
    if (includes[21])
        block->meta["analyser pass energy or retard ratio or mass resolution"]
                                                            = read_line_trim(f);
    if (includes[22]) {
        if ("AES diff" == tech) {
            block->meta["differential width"] = read_line_trim(f);
        }
    }

    if (includes[23])
        block->meta["magnification of analyser transfer lens"] = read_line_trim(f);
    if (includes[24])
        block->meta["analyser work function or acceptance energy of atom or ion"] = read_line_trim(f);
    if (includes[25])
        block->meta["target bias"] = read_line_trim(f);

    if (includes[26]) {
        block->meta["analysis width x"] = read_line_trim(f);
        block->meta["analysis width y"] = read_line_trim(f);
    }

    if (includes[27]) {
        block->meta["analyser axis take off polar angle"] = read_line_trim(f);
        block->meta["analyser axis take off azimuth"] = read_line_trim(f);
    }

    if (includes[28])
        block->meta["species label"] = read_line_trim(f);

    if (includes[29]) {
        block->meta["transition or charge state label"] = read_line_trim(f);
        block->meta["charge of detected particle"] = read_line_trim(f);
    }

    if (includes[30]) {
        if ("REGULAR" == scan_mode_) {
            x_name = read_line_trim(f);
            block->meta["abscissa label"] = x_name;
            block->meta["abscissa units"] = read_line_trim(f);
            x_start = my_strtod(read_line(f));
            x_step = my_strtod(read_line(f));
        }
        else
            throw FormatError("Only REGULAR scans are supported now");
    }
    else
        throw FormatError("how to find abscissa properties in this file?");

    int cor_var; // number of corresponding variables
    if (includes[31]) {
        cor_var = read_line_int(f);
        if (cor_var < 1)
            throw FormatError("wrong number of corresponding variables");
        // columns initialization
        for (int i = 0; i != cor_var; ++i) {
            string corresponding_variable_label = read_line_trim(f);
            skip_lines(f, 1);    // ignoring corresponding variable unit
            ycols.push_back(new VecColumn);
            ycols[i]->set_name(corresponding_variable_label);
        }
    } else {
        assert(first_block != NULL);
        cor_var = first_block->get_column_count() - 1; // don't count xcol
        for (int i = 0; i != cor_var; ++i) {
            ycols.push_back(new VecColumn);
            ycols[i]->set_name(first_block->get_column(i).get_name());
        }
    }

    if (includes[32])
        block->meta["signal mode"] = read_line_trim(f);
    if (includes[33])
        block->meta["signal collection time"] = read_line_trim(f);
    if (includes[34])
        block->meta["# of scans to compile this blk"] = read_line_trim(f);
    if (includes[35])
        block->meta["signal time correction"] = read_line_trim(f);

    if (includes[36]) {
        if (("AES diff" == tech || "AES dir" == tech || "EDX" == tech ||
             "ELS" == tech || "UPS" == tech || "XPS" == tech || "XRF" == tech)
            && ("MAPDP" == exp_mode_ || "MAPSVDP" == exp_mode_
                || "SDP" == exp_mode_ || "SDPSV" == exp_mode_)) {
            skip_lines(f, 7);
        }
    }

    if (includes[37]) {
        block->meta["sample normal polar angle of tilt"] = read_line_trim(f);
        block->meta["sample normal polar tilt azimuth"] = read_line_trim(f);
    }

    if (includes[38])
        block->meta["sample rotate angle"] = read_line_trim(f);

    if (includes[39]) {
        int n = read_line_int(f);   // # of additional numeric parameters
        for (int i = 0; i < n; ++i) {
            // 3 items in every loop: param_label, param_unit, param_value
            string param_label = read_line_trim(f);
            string param_unit = read_line_trim(f);
            block->meta[param_label] = read_line_trim(f) + param_unit;
        }
    }

    skip_lines(f, blk_fue_); // skip future upgrade block entries

    int cur_blk_steps = read_line_int(f);
    skip_lines(f, 2 * cor_var);   // min & max ordinate

    StepColumn *xcol = new StepColumn(x_start, x_step);
    xcol->set_name(x_name);
    block->add_column(xcol);

    int col = 0;
    assert(ycols.size() == (size_t) cor_var);
    for (int i = 0; i < cur_blk_steps; ++i) {
        double y = my_strtod(read_line_trim(f));
        ycols[col]->add_val(y);
        col = (col + 1) % cor_var;
    }
    for (int i = 0; i < cor_var; ++i)
        block->add_column(ycols[i]);
    return block;
}