static int cl_c(statedes *st, bindes *bd, int c, char **v) {int i, rv; char *cpr, *cdv, **sdv, **scp; bd->iparam = MAKE_N(int, 2); rv = 1; cpr = ""; cdv = ""; for (i = 1; i < c; i++) {if (strcmp(v[i], "-c") == 0) cpr = v[++i]; else if (strcmp(v[i], "-dv") == 0) cdv = v[++i]; else if (strcmp(v[i], "-h") == 0) {printf(" C specifications: -c <c-proto> -dv <c-der>\n"); printf(" c file containing C prototypes\n"); printf(" dv file containing C enum,struct,union defs\n"); printf("\n"); cpr = ""; break;};}; if (IS_NULL(cpr) == FALSE) {sdv = file_text(FALSE, cdv); scp = file_text(FALSE, cpr); st->cdv = sdv; st->cpr = scp; bd->iparam[0] = lst_length(sdv); bd->iparam[1] = lst_length(scp); rv = 0;} else printf("No prototypes found for '%s'\n", st->pck); return(rv);}
static void loadconfig(config_t *cfg) { char *cfg_str; bool res; cfg_str = file_text("config.txt"); if (!cfg_str) printf("failed to load config file, using defaults\n"); res = cfg_init(cfg, cfg_str); free(cfg_str); if (!res) { printf("invalid config file, using defaults\n"); cfg_init(cfg, NULL); } printf("cfg.name %s\n", cfg->name); printf("cfg.dlrate %u\n", cfg->dlrate); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString file_path = "/home/eveil/src/dev/qt-json/Load-JSON-deep/test.json"; QFile file_obj(file_path); if(!file_obj.open(QIODevice::ReadOnly)){ qDebug()<< "Failed to open file: " << file_path; exit(1); } QTextStream file_text(&file_obj); QString json_string; json_string = file_text.readAll(); file_obj.close(); QByteArray json_bytes = json_string.toLocal8Bit(); auto json_doc = QJsonDocument::fromJson(json_bytes); if(json_doc.isNull()){ qDebug()<< "Failed to creat json doc from: " <<endl<<json_bytes; exit(2); } qDebug() << json_doc; if(!json_doc.isObject()){ qDebug() << "json doc is not object."; exit(3); } QJsonObject root_obj=json_doc.object(); QVariantMap root_map=root_obj.toVariantMap(); QVariantMap stats=root_map["stats"].toMap(); QVariantList inv=root_map["inventory"].toList(); if(stats.isEmpty()){ qDebug() << "The stats object is empty."; exit(4); } if(inv.isEmpty()){ qDebug() << "The inventory array is empty"; } // iterate a json object's members: QStringList key_list = stats.keys(); for(int i=0; i < key_list.count(); ++i){ QString key=key_list.at(i); int stat_val = stats[key.toLocal8Bit()].toInt(); qDebug() << key << ": " << stat_val; } qDebug() << "Inventory:"; for(int i=0; i < inv.count(); ++i){ qDebug() << inv.at(i).toString(); } return a.exec(); }
void digest_input(string filename) { // Print basic information and advance read cursor past author line. // (Author line must always exist and must be the first line.) cout << "Processing started..." << endl << endl; cout << "Input: " << filename << endl << endl; string filename_input = "Texts/" + filename; ifstream file_text(filename_input); print_data_size(file_text); string author_name; getline(file_text, author_name); string filename_author = "Authors/" + author_name + ".csv"; string filename_summary = create_file_and_name("Digests/", filename, "-SUM.txt"); string filename_words = create_file_and_name("Digests/", filename, "-WORD.csv"); string filename_sentences = create_file_and_name("Digests/", filename, "-SENT.csv"); cout << "Author: " << author_name << endl << endl; cout << "Output: " << filename + "-SUM.txt" << endl << " " << filename + "-WORD.csv" << endl << " " << filename + "-SENT.csv" << endl << endl; Memory RAM; string raw_input; cout << "Parsing text: |"; const int bar_width = 50; for (int i = 0; i<bar_width; ++i) { cout << " "; } cout << "| 0.00%"; for (int i = 0; getline(file_text, raw_input); ++i) { add_data_from_line(RAM, raw_input); // TODO: Make constants settable via command-line options (i.e. 10000, 3000) if (RAM.word_list.size() > 10000) { cout << endl << endl << "Flushing buffer..." << endl << endl; combine_list_file( RAM.word_list, filename_words, RAM.word_list.begin() + 3000, RAM.word_list.end() ); cout << "Parsing text: |"; for (int i = 0; i<bar_width; ++i) { cout << " "; } cout << "| 0.00%"; } // Progress bar stuff: if (i % 120 == 0) { cout << "\b\b\b\b\b\b\b\b"; // "| ##.##%" for (int i = 0; i < bar_width; ++i) { cout << "\b"; } ifstream file_sizer(filename_input); file_sizer.seekg(0, ios::end); float size = static_cast<float>(file_sizer.tellg()); file_sizer.close(); float current = static_cast<float>(file_text.tellg()); float percentage = current / size * 100; int chars_filled = static_cast<int>(floor(percentage/100.0*bar_width)); for (int i = 0; i < bar_width; ++i) { if (i < chars_filled) { cout << "#"; } else { cout << " "; } } std::streamsize precision_init = cout.precision(); int correct_precision = get_precision(5, percentage); cout.precision(correct_precision); std::streamsize width_init = cout.width(); cout << "| " << std::setw(5) << percentage << "%"; cout.precision(precision_init); cout << std::setw(width_init); } } cout << "\b\b\b\b\b\b\b\b"; // "| ##.##%" for (int i = 0; i < bar_width; ++i) { cout << "\b"; } for (int i = 0; i < bar_width; ++i) { cout << "#"; } cout << "| -DONE-" << endl << endl; // Final write: cout << "Writing frequency files..." << endl << endl; std::sort(RAM.word_list.begin(), RAM.word_list.end(), word_compare()); combine_list_file(RAM.word_list, filename_words); get_list_from_file(RAM.word_list, filename_words); ofstream file_sentences(filename_sentences); file_sentences << "WORDS" << endl; for (unsigned int i = 0; i < RAM.sentence_len.size(); ++i) { file_sentences << RAM.sentence_len[i] << endl; } file_sentences.close(); cout << "Writing summary file..." << endl << endl; write_summary(filename_summary, &RAM, author_name); cout << endl << "Done!" << endl; }