process_queue load_file(std::ifstream &file) { //le format des données de chaque ligne est: //<temps d’arrivée>, <priorité>, <temps d’exécution>, <nombre d’imprimantes>, //<nombre de scanneurs>, <nombre de modems>, <nombre de CD> std::string cur_line; process_queue proc_list; char delimiter = ','; while (getline(file, cur_line)) { //cout << "///" << endl; std::string p_info; cur_line.erase(std::remove(cur_line.begin(), cur_line.end(), ' '), cur_line.end()); auto proc_infos = extract_infos(cur_line, delimiter); process proc; proc.arrival = stoi(proc_infos[0]); proc.m_priority = parse_priority(proc_infos[1]); proc.exec_time = stoi(proc_infos[2]); proc.resources[resource::printer] = std::stoi(proc_infos[3]); proc.resources[resource::scanner] = std::stoi(proc_infos[4]); proc.resources[resource::modem] = std::stoi(proc_infos[5]); proc.resources[resource::cd] = std::stoi(proc_infos[6]); proc.m_id = 0; proc_list.push_back(proc); } return proc_list; }
/*}}}*/ int process_list(char **x)/*{{{*/ { struct list_options options; int options_done = 0; int any_paths = 0; char index_buffer[256]; char *y; enum Priority prio = PRI_NORMAL, prio_to_use, node_prio; int prio_set = 0; time_t now = time(NULL); unsigned char *hits; int node_index, n_nodes; options.monochrome = 0; options.show_all = 0; options.show_postponed = 0; options.verbose = 0; options.set_depth = 0; if ( (getenv("TDL_LIST_MONOCHROME") != NULL) || (isatty(STDOUT_FILENO) == 0) ) { options.monochrome = 1; } /* Initialisation to support searching */ node_index = 0; allocate_indices(&top, &node_index); n_nodes = node_index; hits = n_nodes ? new_array(unsigned char, n_nodes) : NULL; /* all nodes match until proven otherwise */ memset(hits, 1, n_nodes); while ((y = *x) != 0) { /* An argument starting '1' or '+1' or '+-1' (or '-1' after '--') is * treated as the path of the top node to show */ if (isdigit(y[0]) || (y[0] == '.') || (options_done && (y[0] == '-') && isdigit(y[1])) || ((y[0] == '+') && (isdigit(y[1]) || ((y[1] == '-' && isdigit(y[2])))))) { struct node *n = lookup_node(y, 0, NULL); int summarise_kids; if (!n) return -1; any_paths = 1; index_buffer[0] = '\0'; strcat(index_buffer, y); summarise_kids = (options.set_depth && (options.depth==0)); if (hits[n->iscratch]) { print_details(n, 0, summarise_kids, &options, index_buffer, now); } if (!options.set_depth || (options.depth > 0)) { node_prio = n->priority; /* If the priority has been set on the cmd line, always use that. * Otherwise, use the priority from the specified node, _except_ when * that is higher than normal, in which case use normal. */ prio_to_use = (prio_set) ? prio : ((node_prio > prio) ? prio : node_prio); list_chain(&n->kids, INDENT_TAB, 0, &options, index_buffer, prio_to_use, now, hits); } } else if ((y[0] == '-') && (y[1] == '-')) { options_done = 1; } else if (y[0] == '-') { while (*++y) { switch (*y) { case 'v': options.verbose = 1; break; case 'a': options.show_all = 1; break; case 'm': options.monochrome = 1; break; case 'p': options.show_postponed = 1; break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': options.set_depth = 1; options.depth = (*y) - '1'; break; default: fprintf(stderr, "Unrecognized option : -%c\n", *y); break; } } } else if (y[0] == '/') { /* search expression */ merge_search_condition(hits, n_nodes, y+1); } else { int error; prio = parse_priority(y, &error); if (error < 0) return error; prio_set = 1; } x++; } colours_init(&options); if (!any_paths) { struct node *narrow_top = get_narrow_top(); if (narrow_top) { index_buffer[0] = 0; if (hits[narrow_top->iscratch]) { int summarise_kids = (options.set_depth && (options.depth==0)); print_details(narrow_top, 0, summarise_kids, &options, index_buffer, now); } if (!options.set_depth || (options.depth > 0)) { list_chain(&narrow_top->kids, 0, 1, &options, index_buffer, prio, now, hits); } } else { index_buffer[0] = 0; list_chain(&top, 0, 0, &options, index_buffer, prio, now, hits); } } if (hits) free(hits); return 0; }
void decl_attributes::parse(parser & p) { buffer<char const *> attr_tokens; get_attribute_tokens(attr_tokens); while (true) { auto pos = p.pos(); if (auto it = parse_priority(p)) { m_prio = *it; bool has_prio_attr = false; for (auto const & entry : m_entries) { if (get_attribute_kind(entry.m_attr.c_str()) == attribute_kind::Prioritized) { has_prio_attr = true; break; } } if (!has_prio_attr) { throw parser_error("invalid '[priority]' attribute, declaration has not been marked with a prioritized attribute", pos); } } else if (p.curr_is_token(get_parsing_only_tk())) { if (!m_is_abbrev) throw parser_error("invalid '[parsing_only]' attribute, only abbreviations can be " "marked as '[parsing_only]'", pos); m_parsing_only = true; p.next(); } else { bool found = false; for (char const * tk : attr_tokens) { if (p.curr_is_token(tk)) { p.next(); char const * attr = get_attribute_from_token(tk); for (auto const & entry : m_entries) { if (are_incompatible(entry.m_attr.c_str(), attr)) { throw parser_error(sstream() << "invalid attribute [" << attr << "], declaration was already marked with [" << entry.m_attr << "]", pos); } } switch (get_attribute_kind(attr)) { case attribute_kind::Default: case attribute_kind::Prioritized: m_entries = cons(entry(attr), m_entries); break; case attribute_kind::Parametric: { unsigned v = p.parse_small_nat(); if (v == 0) throw parser_error("invalid attribute parameter, value must be positive", pos); p.check_token_next(get_rbracket_tk(), "invalid attribute, ']' expected"); m_entries = cons(entry(attr, v-1), m_entries); break; } case attribute_kind::OptParametric: if (!p.curr_is_token(get_rbracket_tk())) { unsigned v = p.parse_small_nat(); if (v == 0) throw parser_error("invalid attribute parameter, value must be positive", pos); p.check_token_next(get_rbracket_tk(), "invalid attribute, ']' expected"); m_entries = cons(entry(attr, v-1), m_entries); } else { p.check_token_next(get_rbracket_tk(), "invalid attribute, ']' expected"); m_entries = cons(entry(attr), m_entries); } break; case attribute_kind::MultiParametric: { buffer<unsigned> vs; while (true) { unsigned v = p.parse_small_nat(); if (v == 0) throw parser_error("invalid attribute parameter, value must be positive", pos); vs.push_back(v-1); if (p.curr_is_token(get_rbracket_tk())) break; } p.next(); m_entries = cons(entry(attr, to_list(vs)), m_entries); break; } } found = true; break; } } if (!found) break; } } }