int find_next_pragma(char * orig_buffer, items * input, int start, int end) { int found, counter, index; item Item; if ((start < 0) || (start >= input->number_of_items) || (end < 0) || (end >= input->number_of_items) || (start > end)) return -1; found = 0; counter = 0; for (index = start; index <= end; index++) { Item = input->data[index]; if (DEBUG_PRAGMAS) printf("Scanning %s at %i\n", types_enum2str(Item.type), get_line_number(orig_buffer, Item.begin)); switch (Item.type) { case PRAGMA_IF: counter++; break; case PRAGMA_ELSE: if (counter == 0) return index; break; case PRAGMA_ENDIF: if (counter == 0) return index; counter--; break; default: printf("Invalid pragma type\n"); /* other types must be filtered out before */ exit(-1); break; } } printf("Cound not find closing pragma starting from %i and ending at %i\n", get_line_number(orig_buffer, input->data[start].begin), get_line_number(orig_buffer, input->data[end].end)); exit(-1); }
/** * Subroutine that simulates one cache event at a time. * @param rw The type of access, READ or WRITE * @param address The address that is being accessed * @param stats The struct that you are supposed to store the stats in */ void cache_access (char rw, uint64_t address, struct cache_stats_t *stats) { int hit; uint64_t tag, line_number, offset, i; cache_line *current_line; cache_block *current_block; cache_block *hit_block; stats -> accesses++; my_cache->timer++; tag = get_tag(address); line_number = get_line_number(address); offset = get_offset(address); current_line = &(my_cache->lines[line_number]); hit = 0; for (i = 0; i < my_cache -> num_blocks_set;i++) { current_block = &(current_line->blocks[i]); if (current_block->valid && current_block->tag == tag) { hit = 1; hit_block = current_block; hit_block->time_stamp = my_cache ->timer; } } if (rw == READ){ stats->reads++; } else if (rw == WRITE) { stats->writes++; } if (hit && rw == WRITE){ hit_block -> dirty = 1; } else if (!hit) { handle_miss(current_line, tag, rw, stats);//get a victim from current line and replace it with the memory from the address. } }
/* read argument string of a single assignment */ char* get_arg( FILE *file, char *name, int type ) { char token[MAX_TOKEN_LENGTH]; char *arg = 0; /* search entry_name */ if ( !find_token( file, name, type, WARNING ) ) return 0; /* token was found so read it */ read_token( file, token ); /* next token must be an equation */ read_token( file, token ); if ( token[0] != '=' ) { fprintf( stderr, "get_arg: line %i: '=' expected after token '%s' but found '%s' instead\n", get_line_number( file ), name, token ); return 0; } /* get argument */ read_token( file, token ); if ( token[0] == 0 ) fprintf( stderr, "get_arg: line %i: warning: argument for '%s' is empty\n", get_line_number( file ), name ); arg = strdup( token ); #ifdef FILE_DEBUG printf( "get_arg: %s = %s\n", name, arg ); #endif return arg; }
int get_line_number(boost::exception_ptr const& e) { try { boost::rethrow_exception(e); } catch (boost::exception const& be) { return get_line_number(be); } }
//插入命令,n为用户输入的行号,从1开始 //extra:输入命令时接着的信息,代表待插入的文本 void com_ins(char *text[], int n, char *extra) { if (n < 0 || n > get_line_number(text) + 1) { printf(1, "invalid line number\n"); return; } char input[MAX_LINE_LENGTH] = {}; if (*extra == '\0') { printf(1, "please input content:\n"); gets(input, MAX_LINE_LENGTH); input[strlen(input)-1] = '\0'; } else strcpy(input, extra); int i = MAX_LINE_NUMBER - 1; for (; i > n; i--) { if (text[i-1] == NULL) continue; else if (text[i] == NULL && text[i-1] != NULL) { text[i] = malloc(MAX_LINE_LENGTH); memset(text[i], 0, MAX_LINE_LENGTH); strcpy(text[i], text[i-1]); } else if (text[i] != NULL && text[i-1] != NULL) { memset(text[i], 0, MAX_LINE_LENGTH); strcpy(text[i], text[i-1]); } } if (text[n] == NULL) { text[n] = malloc(MAX_LINE_LENGTH); if (text[n-1][0] == '\0') { memset(text[n], 0, MAX_LINE_LENGTH); strcpy(text[n-1], input); changed = 1; if (auto_show == 1) show_text(text); return; } } memset(text[n], 0, MAX_LINE_LENGTH); strcpy(text[n], input); changed = 1; if (auto_show == 1) show_text(text); }
//修改命令,n为用户输入的行号,从1开始 //extra:输入命令时接着的信息,代表待修改成的文本 void com_mod(char *text[], int n, char *extra) { if (n <= 0 || n > get_line_number(text) + 1) { printf(1, "invalid line number\n"); return; } char input[MAX_LINE_LENGTH] = {}; if (*extra == '\0') { printf(1, "please input content:\n"); gets(input, MAX_LINE_LENGTH); input[strlen(input)-1] = '\0'; } else strcpy(input, extra); memset(text[n-1], 0, MAX_LINE_LENGTH); strcpy(text[n-1], input); changed = 1; if (auto_show == 1) show_text(text); }
//删除命令,n为用户输入的行号,从1开始 void com_del(char *text[], int n) { if (n <= 0 || n > get_line_number(text) + 1) { printf(1, "invalid line number\n"); return; } memset(text[n-1], 0, MAX_LINE_LENGTH); int i = n - 1; for (; text[i+1] != NULL; i++) { strcpy(text[i], text[i+1]); memset(text[i+1], 0, MAX_LINE_LENGTH); } if (i != 0) { free(text[i]); text[i] = 0; } changed = 1; if (auto_show == 1) show_text(text); }
element * parse_AND_pragmas(char * orig_buffer, items * input, int begin, int end, int * _index) { item Item; element * Pragmas, * p; int index, old_index; Pragmas = NULL; Pragmas = create_pragmas(-1, -1, -1, -1, -1, AND, 10); /* if (begin < 0) begin = 0; if (end < 0) end = input->number_of_items - 1; */ index = begin; if (DEBUG_PRAGMAS) printf("Entering 'parse_AND_pragmas' with [%i, %i]\n", begin, end); if (begin > end) { if (DEBUG_PRAGMAS) printf("Exiting 'parse_AND_pragmas'\n"); *_index = -1; return Pragmas; } old_index = index; while (index <= end) { old_index = index; Item = input->data[index]; switch (Item.type) { case PRAGMA_IF: if (DEBUG_PRAGMAS) printf("#if detected in 'parse_AND_pragmas' at %i\n", get_line_number(orig_buffer, Item.begin)); old_index = index; p = parse_OR_pragmas(orig_buffer, input, old_index, end, &index); p->pid = old_index; add_pragma(Pragmas, p); index++; if (DEBUG_PRAGMAS) printf("#if clause starting at %i was added successfully, next pragma number is %i\n", get_line_number(orig_buffer, Item.begin), index); break; case PRAGMA_ELSE: case PRAGMA_ENDIF: printf("#else or #endif appear without #if at %i\n", get_line_number(orig_buffer, Item.begin)); exit(-1); break; case PRAGMA_OTHER: case STRING: case LITERAL: case COMMENT: case OTHER: case ESCSEQ: printf("Internal error in pragmas handling: more pragma types are present than should be\n"); exit(-1); } } if (DEBUG_PRAGMAS) printf("Exiting 'parse_AND_pragmas'\n"); *_index = index; return Pragmas; }
element * parse_OR_pragmas(char * orig_buffer, items * input, int begin, int end, int * _index) { item oldItem, Item; element * Pragmas, * p; int oldindex, index, x; int done; if (DEBUG_PRAGMAS) printf("Entering 'parse_OR_pragmas' with [%i, %i]\n", begin, end); Pragmas = NULL; Pragmas = create_pragmas(-1, -1, -1, -1, -1, OR, 10); /* if (begin < 0) begin = 0; if (end < 0) end = input->number_of_items - 1; */ index = begin; assert(begin >= 0); assert(begin <= end); done = 0; while (1) { oldindex = index; if (done) index = find_next_pragma(orig_buffer, input, index + 1, end); oldItem = input->data[oldindex]; if (index == -1) { printf("Cannot find matching #else or #endif for #if pragma at %i\n", get_line_number(orig_buffer, oldItem.begin)); exit(-1); } Item = input->data[index]; if (DEBUG_PRAGMAS) printf("Parsing pragmas in 'parse_OR_pragmas' at %i\n", get_line_number(orig_buffer, Item.begin)); if (! done) { if (oldItem.type != PRAGMA_IF) { printf("%s%s%s", "Internal error in parsing pragmas: ", "call to 'parse_OR_pragmas' ", "was made without #if present\n"); exit(-1); } /* p = parse_AND_pragmas(orig_buffer, input, oldindex + 1, index - 1, &x); p->pid = index; add_pragma(Pragmas, p); */ done = 1; } else { switch(Item.type) { case PRAGMA_IF: printf("%s%s%s%i\n", "Internal error in parsing pragmas: ", "program used #if from the lower level ", "to be as in the upper level at ", get_line_number(orig_buffer, Item.begin)); exit(-1); case PRAGMA_ELSE: p = parse_AND_pragmas(orig_buffer, input, oldindex + 1, index - 1, &x); p->pid = oldindex; add_pragma(Pragmas, p); break; case PRAGMA_ENDIF: if (DEBUG_PRAGMAS) printf("Exiting 'parse_OR_pragmas'\n"); p = parse_AND_pragmas(orig_buffer, input, oldindex + 1, index - 1, &x); p->pid = oldindex; add_pragma(Pragmas, p); /* p = create_pragmas(index, -1, -1, -1, -1, AND, 10); add_pragma(Pragmas, p); */ *_index = index; return Pragmas; case PRAGMA_OTHER: case STRING: case LITERAL: case COMMENT: case OTHER: case ESCSEQ: printf("Internal error in pragmas handling\n"); exit(-1); } } } /* should never be reached */ printf("Reached unreachable code\n"); exit(-1); }
bool CL_XMLTokenizer_Generic::next_exclamation_mark_node(CL_XMLToken *out_token) { CL_String::char_type *data_ptr = data.data(); if (pos+2 >= size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); if (data.compare(pos, 2, "--") == 0) // comment block { CL_String::size_type start_pos = pos+2; CL_String::size_type end_pos = data.find("-->", start_pos); if (end_pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); pos = end_pos+3; CL_StringRef text, text_orig(data_ptr + start_pos, end_pos-start_pos, false); unescape(text, text_orig); if (eat_whitespace) text = trim_whitespace(text); out_token->type = CL_XMLToken::COMMENT_TOKEN; out_token->variant = CL_XMLToken::SINGLE; out_token->value = text; return true; } if (pos+7 >= size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); if (data.compare(pos, 7, "DOCTYPE") == 0) { // Strip whitespace: pos = data.find_first_not_of(" \r\n\t", pos+7); if (pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); // Find doctype name: CL_String::size_type name_start = pos; CL_String::size_type name_end = data.find_first_of(" \r\n\t?/>", name_start); if (name_end == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); pos = name_end; // Strip whitespace: pos = data.find_first_not_of(" \r\n\t", pos); if (pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); CL_String::size_type public_start = data.npos; CL_String::size_type public_end = data.npos; CL_String::size_type system_start = data.npos; CL_String::size_type system_end = data.npos; CL_String::size_type subset_start = data.npos; CL_String::size_type subset_end = data.npos; // Look for possible external id: if (data_ptr[pos] != '[' && data_ptr[pos] != '>') { if (pos+6 >= size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); if (data.compare(pos, 6, "SYSTEM") == 0) { pos+=6; if (pos == size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); // Strip whitespace: pos = data.find_first_not_of(" \r\n\t", pos); if (pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); // Read system literal: CL_String::char_type literal_char = data_ptr[pos]; if (literal_char != '\'' && literal_char != '"') CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); system_start = pos+1; system_end = data.find(literal_char, system_start); if (system_end == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); pos = system_end + 1; if (pos >= size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); } else if (data.compare(pos, 6, "PUBLIC") == 0) { pos+=6; if (pos == size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); // Strip whitespace: pos = data.find_first_not_of(" \r\n\t", pos); if (pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); // Read public literal: CL_String::char_type literal_char = data_ptr[pos]; if (literal_char != '\'' && literal_char != '"') CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); public_start = pos+1; public_end = data.find(literal_char, public_start); if (public_end == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); pos = public_end + 1; if (pos >= size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); // Strip whitespace: pos = data.find_first_not_of(" \r\n\t", pos); if (pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); // Read system literal: literal_char = data_ptr[pos]; if (literal_char != '\'' && literal_char != '"') CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); system_start = pos+1; system_end = data.find(literal_char, system_start); if (system_end == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); pos = system_end + 1; if (pos >= size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); } else CL_XMLTokenizer_Generic::throw_exception(cl_format("Error in XML stream, line %1 (unknown external identifier type in DOCTYPE)", get_line_number())); // Strip whitespace: pos = data.find_first_not_of(" \r\n\t", pos); if (pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); } // Look for possible internal subset: if (data_ptr[pos] == '[') { subset_start = pos + 1; // Search for the end of the internal subset: // (to avoid parsing it, we search backwards) CL_String::size_type end_pos = data.find('>', pos+1); if (end_pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); subset_end = data.rfind(']', end_pos); if (subset_end == data.npos) CL_XMLTokenizer_Generic::throw_exception(cl_format("Error in XML stream, line %1 (expected end of internal subset in DOCTYPE)", get_line_number())); pos = end_pos; } // Expect DOCTYPE tag to end now: if (data_ptr[pos] != '>') CL_XMLTokenizer_Generic::throw_exception(cl_format("Error in XML stream, line %1 (expected end of DOCTYPE)", get_line_number())); pos++; out_token->type = CL_XMLToken::DOCUMENT_TYPE_TOKEN; return true; } else if (data.compare(pos, 7, "[CDATA[") == 0) { CL_String::size_type start_pos = pos+7; CL_String::size_type end_pos = data.find("]]>", start_pos); if (end_pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); pos = end_pos+3; CL_StringRef value = string_allocator.alloc( data_ptr + start_pos, end_pos-start_pos); out_token->type = CL_XMLToken::CDATA_SECTION_TOKEN; out_token->variant = CL_XMLToken::SINGLE; out_token->value = value; return true; } else { CL_XMLTokenizer_Generic::throw_exception(cl_format("Error in XML stream at position %1", static_cast<int>(pos))); return false; } }
bool CL_XMLTokenizer_Generic::next_tag_node(CL_XMLToken *out_token) { CL_String::char_type *data_ptr = data.data(); if (pos == size || data_ptr[pos] != '<') return false; pos++; if (pos == size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); // Try to early predict what sort of node it might be: bool closing = (data_ptr[pos] == '/'); bool questionMark = (data_ptr[pos] == '?'); bool exclamationMark = (data_ptr[pos] == '!'); if (closing || questionMark || exclamationMark) { pos++; if (pos == size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); } if (exclamationMark) // check for cdata section, comments or doctype { if (next_exclamation_mark_node(out_token)) return true; } // Extract the tag name: CL_String::size_type start_pos = pos; CL_String::size_type end_pos = data.find_first_of(" \r\n\t?/>", start_pos); if (end_pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); pos = end_pos; out_token->type = questionMark ? CL_XMLToken::PROCESSING_INSTRUCTION_TOKEN : CL_XMLToken::ELEMENT_TOKEN; out_token->variant = closing ? CL_XMLToken::END : CL_XMLToken::BEGIN; out_token->name = string_allocator.alloc(data_ptr + start_pos, end_pos - start_pos); if (out_token->type == CL_XMLToken::PROCESSING_INSTRUCTION_TOKEN) { // Strip whitespace: pos = data.find_first_not_of(" \r\n\t", pos); if (pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); end_pos = data.find_first_of("?", pos); if (end_pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); out_token->value = string_allocator.alloc(data_ptr + pos, end_pos - pos); pos = end_pos; } else // out_token->type == CL_XMLToken::ELEMENT_TOKEN { // Check for possible attributes: while (true) { // Strip whitespace: pos = data.find_first_not_of(" \r\n\t", pos); if (pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); // End of tag, stop searching for more attributes: if (data_ptr[pos] == '/' || data_ptr[pos] == '?' || data_ptr[pos] == '>') break; // Extract attribute name: CL_String::size_type start_pos = pos; CL_String::size_type end_pos = data.find_first_of(" \r\n\t=", start_pos); if (end_pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); pos = end_pos; CL_StringRef attributeName = string_allocator.alloc(data_ptr + start_pos, end_pos-start_pos); // Find seperator: pos = data.find_first_not_of(" \r\n\t", pos); if (pos == data.npos || pos == size-1) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); if (data_ptr[pos++] != '=') CL_XMLTokenizer_Generic::throw_exception(cl_format("XML error(s), parser confused at line %1 (tag=%2, attributeName=%3)", get_line_number(), out_token->name, attributeName)); // Strip whitespace: pos = data.find_first_not_of(" \r\n\t", pos); if (pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); // Extract attribute value: CL_String::char_type const * first_of = " \r\n\t"; if (data_ptr[pos] == '"') { first_of = "\""; pos++; if (pos == size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); } else if (data_ptr[pos] == '\'') { first_of = "'"; pos++; if (pos == size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); } start_pos = pos; end_pos = data.find_first_of(first_of, start_pos); if (end_pos == data.npos) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); CL_StringRef attributeValue, attributeValueOrig(data_ptr + start_pos, end_pos-start_pos, false); unescape(attributeValue, attributeValueOrig); pos = end_pos + 1; if (pos == size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); // Finally apply attribute to token: out_token->attributes.push_back(CL_XMLToken::Attribute(attributeName, attributeValue)); } } // Check if its singular: if (data_ptr[pos] == '/' || data_ptr[pos] == '?') { out_token->variant = CL_XMLToken::SINGLE; pos++; if (pos == size) CL_XMLTokenizer_Generic::throw_exception("Premature end of XML data!"); } // Data stream should be ending now. if (data_ptr[pos] != '>') CL_XMLTokenizer_Generic::throw_exception(cl_format("Error in XML stream, line %1 (expected end of tag)", get_line_number())); pos++; return true; }
int main(int argc, char *argv[]) { setProgramStatus(EDITOR); if (argc == 1) { printf(1, "please input the command as [editor file_name]\n"); setProgramStatus(SHELL); exit(); } //存放文件内容 char *text[MAX_LINE_NUMBER] = {}; text[0] = malloc(MAX_LINE_LENGTH); memset(text[0], 0, MAX_LINE_LENGTH); //存储当前最大的行号,从0开始。即若line_number == x,则从text[0]到text[x]可用 int line_number = 0; //尝试打开文件 int fd = open(argv[1], O_RDONLY); //如果文件存在,则打开并读取里面的内容 if (fd != -1) { char buf[BUF_SIZE] = {}; int len = 0; while ((len = read(fd, buf, BUF_SIZE)) > 0) { int i = 0; int next = 0; int is_full = 0; while (i < len) { //拷贝"\n"之前的内容 for (i = next; i < len && buf[i] != '\n'; i++) ; strcat_n(text[line_number], buf+next, i-next); //必要时新建一行 if (i < len && buf[i] == '\n') { if (line_number >= MAX_LINE_NUMBER - 1) is_full = 1; else { line_number++; text[line_number] = malloc(MAX_LINE_LENGTH); memset(text[line_number], 0, MAX_LINE_LENGTH); } } if (is_full == 1 || i >= len - 1) break; else next = i + 1; } if (is_full == 1) break; } close(fd); } //输出文件内容 show_text(text); //输出帮助 com_help(text); //处理命令 char input[MAX_LINE_LENGTH] = {}; while (1) { printf(1, "\nplease input command:\n"); memset(input, 0, MAX_LINE_LENGTH); gets(input, MAX_LINE_LENGTH); int len = strlen(input); input[len-1] = '\0'; len --; //寻找命令中第一个空格 int pos = MAX_LINE_LENGTH - 1; int j = 0; for (; j < 8; j++) { if (input[j] == ' ') { pos = j + 1; break; } } //ins if (input[0] == 'i' && input[1] == 'n' && input[2] == 's') { if (input[3] == '-') com_ins(text, atoi(&input[4]), &input[pos]); else com_ins(text, line_number+1, &input[pos]); //插入操作需要更新行号 line_number = get_line_number(text); } //mod else if (input[0] == 'm' && input[1] == 'o' && input[2] == 'd') { if (input[3] == '-') com_mod(text, atoi(&input[4]), &input[pos]); else com_mod(text, line_number + 1, &input[pos]); } //del else if (input[0] == 'd' && input[1] == 'e' && input[2] == 'l') { if (input[3] == '-') com_del(text, atoi(&input[4])); else com_del(text, line_number + 1); //删除操作需要更新行号 line_number = get_line_number(text); } else if (strcmp(input, "show") == 0) { auto_show = 1; printf(1, "enable show current contents after text changed.\n"); } else if (strcmp(input, "hide") == 0) { auto_show = 0; printf(1, "disable show current contents after text changed.\n"); } else if (strcmp(input, "help") == 0) com_help(text); else if (strcmp(input, "save") == 0 || strcmp(input, "CTRL+S\n") == 0) com_save(text, argv[1]); else if (strcmp(input, "exit") == 0) com_exit(text, argv[1]); else { printf(1, "invalid command.\n"); com_help(text); } } setProgramStatus(SHELL); exit(); }
int main(void) { char bootlist[MAX_DEVICES][MAX_LENGTH]; int i; char key; u8 max_lines = 0; u8 bootlist_def_ln = 0; u8 bootlist_map_ln = 0; char *ipxe_str; char *scon_str; #ifdef CONFIG_USB /* this needs to be done in order to use the USB keyboard */ usb_initialize(); noecho(); /* don't echo keystrokes */ #endif printf("\n*********************************************************************"); printf("\n*** Sortbootorder payload ver 1.1 Sage Electronic Engineering *"); printf("\n*********************************************************************\n"); // Find out where the bootorder file is in rom char *tmp = cbfs_get_file_content( CBFS_DEFAULT_MEDIA, BOOTORDER_FILE, CBFS_TYPE_RAW, NULL ); flash_address = (int)tmp; if ((u32)tmp & 0xfff) printf("Warning: The bootorder file is not 4k aligned!\n"); // Get required files from CBFS fetch_file_from_cbfs( BOOTORDER_FILE, bootlist, &max_lines ); fetch_file_from_cbfs( BOOTORDER_DEF, bootlist_def, &bootlist_def_ln ); fetch_file_from_cbfs( BOOTORDER_MAP, bootlist_map, &bootlist_map_ln ); // Init ipxe and serial status ipxe_str = cbfs_find_string("pxen", BOOTORDER_FILE); ipxe_str += strlen("pxen"); ipxe_toggle = ipxe_str ? strtoul(ipxe_str, NULL, 10) : 1; scon_str = cbfs_find_string("scon", BOOTORDER_FILE); scon_str += strlen("scon"); serial_toggle = scon_str ? strtoul(scon_str, NULL, 10) : 1; show_boot_device_list( bootlist, max_lines, bootlist_def_ln ); int_ids( bootlist, max_lines, bootlist_def_ln ); // Start main loop for user input while (1) { printf("\n> "); key = getchar(); printf("%c\n\n\n", key); switch(key) { case 'R': for (i = 0; i < max_lines && i < bootlist_def_ln; i++ ) copy_list_line(&(bootlist_def[i][0]), &(bootlist[i][0])); int_ids( bootlist, max_lines, bootlist_def_ln ); break; case 'T': serial_toggle ^= 0x1; break; case 'N': ipxe_toggle ^= 0x1; break; case 'U': usb_toggle ^= 0x1; break; case 'E': update_tag_value(bootlist, max_lines, "scon", serial_toggle + '0'); update_tag_value(bootlist, max_lines, "pxen", ipxe_toggle + '0'); save_flash( bootlist, max_lines ); // fall through to exit ... case 'X': printf("\nExiting ..."); outb(0x06, 0x0cf9); /* reset */ break; default: if (key >= 'a' && key <= 'm' ) { move_boot_list( bootlist, get_line_number(max_lines,key), max_lines ); } break; } show_boot_device_list( bootlist, max_lines, bootlist_def_ln ); } return 0; /* should never get here! */ }
int get_line_number(hpx::exception const& e) { return get_line_number(dynamic_cast<boost::exception const&>(e)); }