Beispiel #1
0
//------------------------------------------------------------------------------
// IMPRIME_LISTA_CSV
//   Imprime a lista no formato CSV
//------------------------------------------------------------------------------
void imprime_lista_csv(Registro *reg, FILE *fp) {
	if (reg == NULL) return;
	
	if (reg->esq != NULL) imprime_lista_csv(reg->esq, fp);
	write_csv(fp, reg->nome, reg->curso, reg->turno, reg->cidade);
	if (reg->dir != NULL) imprime_lista_csv(reg->dir, fp);
}
Beispiel #2
0
int main(int argc, const char * argv[])
{
    if(argc < 3){
        return 0;
    }
    std::string cmd = argv[1];
    std::string db_path = argv[2];
    std::string collection;
    std::string key = "loadrec";
    if(argc >= 4){
        collection = argv[3];
    }
    if(cmd == "csv"){
        write_csv(db_path, key, collection);
    }else if(cmd == "rec"){
        auto t = current_time();
        auto l = load_average();
        std::string value = t + ", " + l;

        kvsqlite::database db(db_path);
        std::deque<std::string> data;
        db.get(key, data, collection);
        data.push_back(value);
        int max_size = 12*24;
        if(data.size() > max_size) data.pop_front();
        db.set(key, data, collection);
    }

    return 0;
}
Beispiel #3
0
int main (int argc, char **argv) {
	FILE *input, *output;
	char buf[BUFLEN+1];

	uint matchid = 0;
	uint i;
	entry_t entrybuf;
	std::vector<entry_t> entries;

	if (argc < 2) {
		printf("Missing filename\n");
		return 1;
	}
	if (argc == 3) {
		sscanf(argv[1], "%u", &matchid);
	}
	
	input = fopen(argv[argc-1], "r");
	if (input == NULL) {
		printf("Cannot open file!\n");
		return 2;
	}
	if(fgets(buf, BUFLEN, input) == NULL) {
		printf("Invalid file\n");
		return 3;
	}

	while(fgets(buf, BUFLEN, input) != NULL) {
		read_line(buf, BUFLEN, &entrybuf);
		entries.push_back(entrybuf);
	}
	printf("Read %u entries\n", entries.size());

	if (matchid != 0) {
		char nbuf[32];
		sprintf(nbuf, "match_%u.csv", matchid);
		output = fopen(nbuf, "w");
		if (output == NULL) {
			printf("Cannot open output file!\n");
			return 5;
		}
		write_csv(entries, output, matchid);
		printf("Match written to %s\n", nbuf);
	}

	return 0;
}