Ejemplo n.º 1
0
int main()
{
	is_evenly_divisible(3,4);
    is_evenly_divisible(4,4);
    is_evenly_divisible(4,0);
    printf("______________________\n");
    print_max(3,2,4);
    print_max(1,60,2);
    print_max(0,0,4);
    median_int(4,5,3);

	return 0; 
}
Ejemplo n.º 2
0
int main(int argc, char **argv) {
  //check for the correct number of input arguments
  if(argc != 4){
    fprintf(stderr, "There should be 3 arguments, nrowA (integer), ncolA (integer), and ncolB (integer) \n");
    fprintf(stderr, "Usage: %s nrowA ncolA ncolB \n", argv[0]);
    return 1;}
  int nrowA = atoi(argv[1]); int ncolA = atoi(argv[2]); 
  int nrowB = ncolA; int ncolB = atoi(argv[3]);
  int nrowC = nrowA; int ncolC = ncolB;
  //initialize matrices
  AST523_MATRIX *A = AST523_matrixNew(nrowA, ncolA);
  AST523_MATRIX *B = AST523_matrixNew(nrowB, ncolB);
  AST523_MATRIX *C = AST523_matrixNew(nrowC, ncolC);
  sin_init(A);
  sin_init(B);
  //perform multiplication
  matrix_multiply(A,B,C);
  //print output
  print_max(C);
  //clear memory
  AST523_matrixDel(A);
  AST523_matrixDel(B);
  AST523_matrixDel(C);
  return 0;
}
Ejemplo n.º 3
0
int main(void) {
    /* int num; */

    /* printf("The integer number: "); */
    /* scanf("%d", &num); */
    print_max(5, 10, 9, 8, 7, 6);

    return 0;
}
Ejemplo n.º 4
0
Archivo: net_pro.c Proyecto: kota395/np
void cmd_print(int nitems)
{//表示の範囲指定
  int i, start = 0, end = profile_data_nitems;
  if (nitems > 0) end = print_min(nitems, profile_data_nitems);
  if (nitems < 0) start = print_max(end - (-nitems), 0);
  for (i = start; i < end; i++) {
    print_profile(&profile_data_store[i],i);
    printf("\n"); 
  }
}
Ejemplo n.º 5
0
/**
   Print the specified item using at the specified amount of space
*/
static void completion_print_item( const wchar_t *prefix, comp_t *c, int width, bool secondary )
{
	int comp_width=0, desc_width=0;
	int written=0;
	
	if( c->pref_width <= width )
	{
		/*
		  The entry fits, we give it as much space as it wants
		*/
		comp_width = c->comp_width;
		desc_width = c->desc_width;
	}
	else
	{
		/*
		  The completion and description won't fit on the
		  allocated space. Give a maximum of 2/3 of the
		  space to the completion, and whatever is left to
		  the description.
		*/
		int desc_all = c->desc_width?c->desc_width+4:0;
		
		comp_width = maxi( mini( c->comp_width,
					 2*(width-4)/3 ),
				   width - desc_all );
		if( c->desc_width )
			desc_width = width-comp_width-4;
		else
			c->desc_width=0;
		
	}
	
    rgb_color_t bg = secondary ? get_color(HIGHLIGHT_PAGER_SECONDARY) : rgb_color_t::normal();
	for( size_t i=0; i<c->comp.size(); i++ )
	{
        const wcstring &comp = c->comp.at(i);
		if( i != 0 )
			written += print_max( L"  ", comp_width - written, 2 );
		set_color( get_color(HIGHLIGHT_PAGER_PREFIX), bg );
		written += print_max( prefix, comp_width - written, comp.empty()?0:1 );
		set_color( get_color(HIGHLIGHT_PAGER_COMPLETION), bg);
		written += print_max( comp.c_str(), comp_width - written, i!=(c->comp.size()-1) );
	}


	if( desc_width )
	{
		while( written < (width-desc_width-2))
		{
			written++;
			writech( L' ');
		}
		set_color( get_color( HIGHLIGHT_PAGER_DESCRIPTION ), bg);
		written += print_max( L"(", 1, 0 );
		written += print_max( c->desc.c_str(), desc_width, 0 );
		written += print_max( L")", 1, 0 );
	}
	else
	{
		while( written < width )
		{
			written++;
			writech( L' ');
		}
	}
	if ( secondary )
		set_color( rgb_color_t::normal(), rgb_color_t::normal() );
}
Ejemplo n.º 6
0
/// Print the specified item using at the specified amount of space.
line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, size_t row,
                                      size_t column, size_t width, bool secondary, bool selected,
                                      page_rendering_t *rendering) const {
    UNUSED(column);
    UNUSED(row);
    UNUSED(rendering);
    size_t comp_width = 0, desc_width = 0;
    size_t written = 0;
    line_t line_data;

    if (c->pref_width <= (size_t)width) {
        // The entry fits, we give it as much space as it wants.
        comp_width = c->comp_width;
        desc_width = c->desc_width;
    } else {
        // The completion and description won't fit on the allocated space. Give a maximum of 2/3 of
        // the space to the completion, and whatever is left to the description.
        int desc_all = c->desc_width ? c->desc_width + 4 : 0;

        comp_width = maxi(mini(c->comp_width, 2 * (width - 4) / 3), width - desc_all);
        if (c->desc_width) desc_width = width - comp_width - 4;
    }

    int bg_color = secondary ? highlight_spec_pager_secondary : highlight_spec_normal;
    if (selected) {
        bg_color = highlight_spec_search_match;
    }

    for (size_t i = 0; i < c->comp.size(); i++) {
        const wcstring &comp = c->comp.at(i);

        if (i != 0)
            written += print_max(PAGER_SPACER_STRING, highlight_spec_normal, comp_width - written,
                                 true /* has_more */, &line_data);

        int packed_color = highlight_spec_pager_prefix | highlight_make_background(bg_color);
        written += print_max(prefix, packed_color, comp_width - written, !comp.empty(), &line_data);

        packed_color = highlight_spec_pager_completion | highlight_make_background(bg_color);
        written +=
            print_max(comp, packed_color, comp_width - written, i + 1 < c->comp.size(), &line_data);
    }

    if (desc_width) {
        int packed_color = highlight_spec_pager_description | highlight_make_background(bg_color);
        while (written < (width - desc_width - 2))  // the 2 here refers to the parenthesis below
        {
            written += print_max(L" ", packed_color, 1, false, &line_data);
        }
        // hack - this just works around the issue
        print_max(L"(", highlight_spec_pager_completion | highlight_make_background(bg_color), 1,
                  false, &line_data);
        print_max(c->desc, packed_color, desc_width, false, &line_data);
        print_max(L")", highlight_spec_pager_completion | highlight_make_background(bg_color), 1,
                  false, &line_data);
    } else {
        while (written < width) {
            written += print_max(L" ", 0, 1, false, &line_data);
        }
    }

    return line_data;
}
Ejemplo n.º 7
0
/// Try to print the list of completions l with the prefix prefix using cols as the number of
/// columns. Return true if the completion list was printed, false if the terminal is to narrow for
/// the specified number of columns. Always succeeds if cols is 1.
bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const comp_info_list_t &lst,
                                   page_rendering_t *rendering, size_t suggested_start_row) const {
    // The calculated preferred width of each column.
    int pref_width[PAGER_MAX_COLS] = {0};
    // The calculated minimum width of each column.
    int min_width[PAGER_MAX_COLS] = {0};
    // If the list can be printed with this width, width will contain the width of each column.
    int *width = pref_width;

    // Set to one if the list should be printed at this width.
    bool print = false;

    // Compute the effective term width and term height, accounting for disclosure.
    size_t term_width = this->available_term_width;
    size_t term_height =
        this->available_term_height - 1 -
        (search_field_shown ? 1 : 0);  // we always subtract 1 to make room for a comment row
    if (!this->fully_disclosed) {
        term_height = mini(term_height, (size_t)PAGER_UNDISCLOSED_MAX_ROWS);
    }

    size_t row_count = divide_round_up(lst.size(), cols);

    // We have more to disclose if we are not fully disclosed and there's more rows than we have in
    // our term height.
    if (!this->fully_disclosed && row_count > term_height) {
        rendering->remaining_to_disclose = row_count - term_height;
    } else {
        rendering->remaining_to_disclose = 0;
    }

    // If we have only one row remaining to disclose, then squelch the comment row. This prevents us
    // from consuming a line to show "...and 1 more row".
    if (!this->fully_disclosed && rendering->remaining_to_disclose == 1) {
        term_height += 1;
        rendering->remaining_to_disclose = 0;
    }

    size_t pref_tot_width = 0;
    size_t min_tot_width = 0;

    // Skip completions on tiny terminals.
    if (term_width < PAGER_MIN_WIDTH) return true;

    // Calculate how wide the list would be.
    for (size_t col = 0; col < cols; col++) {
        for (size_t row = 0; row < row_count; row++) {
            int pref, min;
            const comp_t *c;
            if (lst.size() <= col * row_count + row) continue;

            c = &lst.at(col * row_count + row);
            pref = c->pref_width;
            min = c->min_width;

            if (col != cols - 1) {
                pref += 2;
                min += 2;
            }
            min_width[col] = maxi(min_width[col], min);
            pref_width[col] = maxi(pref_width[col], pref);
        }
        min_tot_width += min_width[col];
        pref_tot_width += pref_width[col];
    }

    // Force fit if one column.
    if (cols == 1) {
        if (pref_tot_width > term_width) {
            pref_width[0] = term_width;
        }
        width = pref_width;
        print = true;
    } else if (pref_tot_width <= term_width) {
        // Terminal is wide enough. Print the list!
        width = pref_width;
        print = true;
    }

    if (print) {
        // Determine the starting and stop row.
        size_t start_row = 0, stop_row = 0;
        if (row_count <= term_height) {
            // Easy, we can show everything.
            start_row = 0;
            stop_row = row_count;
        } else {
            // We can only show part of the full list. Determine which part based on the
            // suggested_start_row.
            assert(row_count > term_height);
            size_t last_starting_row = row_count - term_height;
            start_row = mini(suggested_start_row, last_starting_row);
            stop_row = start_row + term_height;
            assert(start_row >= 0 && start_row <= last_starting_row);
        }

        assert(stop_row >= start_row);
        assert(stop_row <= row_count);
        assert(stop_row - start_row <= term_height);
        completion_print(cols, width, start_row, stop_row, prefix, lst, rendering);

        // Ellipsis helper string. Either empty or containing the ellipsis char.
        const wchar_t ellipsis_string[] = {ellipsis_char == L'\x2026' ? L'\x2026' : L'\0', L'\0'};

        // Add the progress line. It's a "more to disclose" line if necessary, or a row listing if
        // it's scrollable; otherwise ignore it.
        wcstring progress_text;
        if (rendering->remaining_to_disclose == 1) {
            // I don't expect this case to ever happen.
            progress_text = format_string(_(L"%lsand 1 more row"), ellipsis_string);
        } else if (rendering->remaining_to_disclose > 1) {
            progress_text = format_string(_(L"%lsand %lu more rows"), ellipsis_string,
                                          (unsigned long)rendering->remaining_to_disclose);
        } else if (start_row > 0 || stop_row < row_count) {
            // We have a scrollable interface. The +1 here is because we are zero indexed, but want
            // to present things as 1-indexed. We do not add 1 to stop_row or row_count because
            // these are the "past the last value".
            progress_text =
                format_string(_(L"rows %lu to %lu of %lu"), start_row + 1, stop_row, row_count);
        } else if (completion_infos.empty() && !unfiltered_completion_infos.empty()) {
            // Everything is filtered.
            progress_text = _(L"(no matches)");
        }

        if (!progress_text.empty()) {
            line_t &line = rendering->screen_data.add_line();
            print_max(progress_text, highlight_spec_pager_progress |
                                         highlight_make_background(highlight_spec_pager_progress),
                      term_width, true /* has_more */, &line);
        }

        if (search_field_shown) {
            // Add the search field.
            wcstring search_field_text = search_field_line.text;
            // Append spaces to make it at least the required width.
            if (search_field_text.size() < PAGER_SEARCH_FIELD_WIDTH) {
                search_field_text.append(PAGER_SEARCH_FIELD_WIDTH - search_field_text.size(), L' ');
            }
            line_t *search_field = &rendering->screen_data.insert_line_at_index(0);

            // We limit the width to term_width - 1.
            int search_field_written = print_max(SEARCH_FIELD_PROMPT, highlight_spec_normal,
                                                 term_width - 1, false, search_field);
            print_max(search_field_text, highlight_modifier_force_underline,
                      term_width - search_field_written - 1, false, search_field);
        }
    }
    return print;
}
Ejemplo n.º 8
0
bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const comp_info_list_t &lst, page_rendering_t *rendering, size_t suggested_start_row) const
{
    /*
      The calculated preferred width of each column
    */
    int pref_width[PAGER_MAX_COLS] = {0};
    /*
      The calculated minimum width of each column
    */
    int min_width[PAGER_MAX_COLS] = {0};
    /*
      If the list can be printed with this width, width will contain the width of each column
    */
    int *width=pref_width;

    /* Set to one if the list should be printed at this width */
    bool print = false;

    /* Compute the effective term width and term height, accounting for disclosure */
    int term_width = this->available_term_width;
    int term_height = this->available_term_height - 1 - (search_field_shown ? 1 : 0); // we always subtract 1 to make room for a comment row
    if (! this->fully_disclosed)
    {
        term_height = mini(term_height, PAGER_UNDISCLOSED_MAX_ROWS);
    }

    size_t row_count = divide_round_up(lst.size(), cols);

    /* We have more to disclose if we are not fully disclosed and there's more rows than we have in our term height */
    if (! this->fully_disclosed && row_count > term_height)
    {
        rendering->remaining_to_disclose = row_count - term_height;
    }
    else
    {
        rendering->remaining_to_disclose = 0;
    }

    int pref_tot_width=0;
    int min_tot_width = 0;

    /* Skip completions on tiny terminals */
    if (term_width < PAGER_MIN_WIDTH)
        return true;

    /* Calculate how wide the list would be */
    for (long col = 0; col < cols; col++)
    {
        for (long row = 0; row<row_count; row++)
        {
            int pref,min;
            const comp_t *c;
            if (lst.size() <= col*row_count + row)
                continue;

            c = &lst.at(col*row_count + row);
            pref = c->pref_width;
            min = c->min_width;

            if (col != cols-1)
            {
                pref += 2;
                min += 2;
            }
            min_width[col] = maxi(min_width[col],
                                  min);
            pref_width[col] = maxi(pref_width[col],
                                   pref);
        }
        min_tot_width += min_width[col];
        pref_tot_width += pref_width[col];
    }
    /*
      Force fit if one column
    */
    if (cols == 1)
    {
        if (pref_tot_width > term_width)
        {
            pref_width[0] = term_width;
        }
        width = pref_width;
        print = true;
    }
    else if (pref_tot_width <= term_width)
    {
        /* Terminal is wide enough. Print the list! */
        width = pref_width;
        print = true;
    }
    else
    {
        long next_rows = (lst.size()-1)/(cols-1)+1;
        /*    fwprintf( stderr,
          L"cols %d, min_tot %d, term %d, rows=%d, nextrows %d, termrows %d, diff %d\n",
          cols,
          min_tot_width, term_width,
          rows, next_rows, term_height,
          pref_tot_width-term_width );
        */
        if (min_tot_width < term_width &&
                (((row_count < term_height) && (next_rows >= term_height)) ||
                 (pref_tot_width-term_width< 4 && cols < 3)))
        {
            /*
              Terminal almost wide enough, or squeezing makes the
              whole list fit on-screen.

              This part of the code is really important. People hate
              having to scroll through the completion list. In cases
              where there are a huge number of completions, it can't
              be helped, but it is not uncommon for the completions to
              _almost_ fit on one screen. In those cases, it is almost
              always desirable to 'squeeze' the completions into a
              single page.

              If we are using N columns and can get everything to
              fit using squeezing, but everything would also fit
              using N-1 columns, don't try.
            */

            int tot_width = min_tot_width;
            width = min_width;

            while (tot_width < term_width)
            {
                for (long i=0; (i<cols) && (tot_width < term_width); i++)
                {
                    if (width[i] < pref_width[i])
                    {
                        width[i]++;
                        tot_width++;
                    }
                }
            }
            print = true;
        }
    }

    if (print)
    {
        /* Determine the starting and stop row */
        size_t start_row = 0, stop_row = 0;
        if (row_count <= term_height)
        {
            /* Easy, we can show everything */
            start_row = 0;
            stop_row = row_count;
        }
        else
        {
            /* We can only show part of the full list. Determine which part based on the suggested_start_row */
            assert(row_count > term_height);
            size_t last_starting_row = row_count - term_height;
            start_row = mini(suggested_start_row, last_starting_row);
            stop_row = start_row + term_height;
            assert(start_row >= 0 && start_row <= last_starting_row);
        }

        assert(stop_row >= start_row);
        assert(stop_row <= row_count);
        assert(stop_row - start_row <= term_height);
        completion_print(cols, width, start_row, stop_row, prefix, lst, rendering);

        /* Ellipsis helper string. Either empty or containing the ellipsis char */
        const wchar_t ellipsis_string[] = {ellipsis_char == L'\x2026' ? L'\x2026' : L'\0', L'\0'};

        /* Add the progress line. It's a "more to disclose" line if necessary, or a row listing if it's scrollable; otherwise ignore it */
        wcstring progress_text;
        if (rendering->remaining_to_disclose == 1)
        {
            /* I don't expect this case to ever happen */
            progress_text = format_string(L"%lsand 1 more row", ellipsis_string);
        }
        else if (rendering->remaining_to_disclose > 1)
        {
            progress_text = format_string(L"%lsand %lu more rows", ellipsis_string, (unsigned long)rendering->remaining_to_disclose);
        }
        else if (start_row > 0 || stop_row < row_count)
        {
            /* We have a scrollable interface. The +1 here is because we are zero indexed, but want to present things as 1-indexed. We do not add 1 to stop_row or row_count because these are the "past the last value" */
            progress_text = format_string(L"rows %lu to %lu of %lu", start_row + 1, stop_row, row_count);
        }
        else if (completion_infos.empty() && ! unfiltered_completion_infos.empty())
        {
            /* Everything is filtered */
            progress_text = L"(no matches)";
        }

        if (! progress_text.empty())
        {
            line_t &line = rendering->screen_data.add_line();
            print_max(progress_text.c_str(), highlight_spec_pager_progress | highlight_make_background(highlight_spec_pager_progress), term_width, true /* has_more */, &line);
        }

        if (search_field_shown)
        {
            /* Add the search field */
            wcstring search_field_text = search_field_line.text;
            /* Append spaces to make it at least the required width */
            if (search_field_text.size() < PAGER_SEARCH_FIELD_WIDTH)
            {
                search_field_text.append(PAGER_SEARCH_FIELD_WIDTH - search_field_text.size(), L' ');
            }
            line_t *search_field = &rendering->screen_data.insert_line_at_index(0);

            /* We limit the width to term_width - 1 */
            int search_field_written = print_max(SEARCH_FIELD_PROMPT, highlight_spec_normal, term_width - 1, false, search_field);
            search_field_written += print_max(search_field_text, highlight_modifier_force_underline, term_width - search_field_written - 1, false, search_field);
        }

    }
    return print;
}