/* Inspect the line */ static int parser_inspect(struct parser_obj *po) { int error = EOK; uint32_t action = PARSE_DONE; TRACE_FLOW_ENTRY(); TRACE_INFO_STRING("Buffer:", po->last_read); TRACE_INFO_NUMBER("In comment:", po->inside_comment); if (check_for_comment(po->last_read, po->last_read_len, !(po->parse_flags & INI_PARSE_NO_C_COMMENTS), &(po->inside_comment))) { error = handle_comment(po, &action); if (error) { TRACE_ERROR_NUMBER("Failed to process comment", error); return error; } } else if (isspace(*(po->last_read))) { error = handle_space(po, &action); if (error) { TRACE_ERROR_NUMBER("Failed to process line wrapping", error); return error; } } else if (*(po->last_read) == '[') { error = handle_section(po, &action); if (error) { TRACE_ERROR_NUMBER("Failed to save section", error); return error; } } else { error = handle_kvp(po, &action); if (error) { TRACE_ERROR_NUMBER("Failed to save kvp", error); return error; } } /* Move to the next action */ error = col_enqueue_unsigned_property(po->queue, PARSE_ACTION, action); if (error) { TRACE_ERROR_NUMBER("Failed to schedule an action", error); return error; } TRACE_FLOW_EXIT(); return error; }
void fortran_split_lines(FILE* input, FILE* output, int width) { ERROR_CONDITION(width <= 0, "Invalid width = %d\n", width); int length; char* line; while ((line = read_whole_line(input)) != NULL) { // We must remove trailing spaces before "\n" (if any) // since we cannot continuate to an empty line trim_right_line(line); // Comments that will reach here are those created within the compiler // (e.g. TPL) because scanner always trims them char prefix[33] = { 0 }; char is_construct = check_for_construct(line, prefix, 32); char is_comment = check_for_comment(line); length = strlen(line); // Many times we will fall here by means of length <= width if ((length <= width)) { fputs(line, output); } else if (is_construct) { // Do not complicate ourselves, rely on a double continuation int column = 1; double_continuate_construct(output, prefix, line, width, &column); fprintf(output, "\n"); } else if (is_comment) { fputs(line, output); } else { int column, next_column; char* position; char* next_position; mf03_prepare_string_for_scanning(line); // Initialize stuff column = 1; position = line; // Scan int token = mf03lex(); while (token != EOS) { // Find the token as there can be spaces // next_position has the first character of the token next_position = strstr(position, mf03lval.token_atrib.token_text); if (next_position == NULL) { fatal_error("Serious problem when splitting line. '%s' not found:\n\n %s", mf03lval.token_atrib.token_text, position); } // Next column has the column where the token will start next_column = column + (next_position - position); // Check if we have reached the last column or if spaces plus // token will not fit in this line if (column == width || (next_column + (int)strlen(mf03lval.token_atrib.token_text) >= width)) { DEBUG_CODE() DEBUG_MESSAGE("Cutting at '%s'", mf03lval.token_atrib.token_text); // Nothing fits here already fprintf(output, "&\n"); column = 1; } // Write the blanks char* c; for (c = position; c < next_position; c++) { DEBUG_CODE() DEBUG_MESSAGE("%d - Blank - '%c'", column, *c); fprintf(output, "%c", *c); column++; } if ((column + (int)strlen(mf03lval.token_atrib.token_text)) >= width) { // We are very unlucky, the whole token still does not fit // in this line ! double_continuate(output, mf03lval.token_atrib.token_text, width, &column); } else { // Write the token DEBUG_CODE() DEBUG_MESSAGE("%d - Token '%s'", column, mf03lval.token_atrib.token_text); fprintf(output, "%s", mf03lval.token_atrib.token_text); column += strlen(mf03lval.token_atrib.token_text); } // Update state to be coherent before entering the next iteration // column has been updated before position = next_position + strlen(mf03lval.token_atrib.token_text); token = mf03lex(); } // The EOS fprintf(output, "\n"); } DELETE(line); } }