Exemplo n.º 1
0
/*
 * Check whether tk requires a ')' and if so print it
 */
static void print_close_token(printer_t *p, pp_close_token_t *tk) {
  if (tk_has_close_par(tk)) {
    if (p->area.truncate) {

      if (p->col + 5 <= p->margin) {
        // tuncate mode, no pending tokens and enough space for ') ...'
        assert(!p->full_line && p->pending_tokens.size == 0);
        print_close(p, tk);
      } else if (p->col + 4 == p->margin) {
        // truncate mode, no pending tokens, space for 4 more characters
        assert(!p->full_line && p->pending_tokens.size == 0);
        p->pending_col = p->col;
        p->col ++;
        pvector_push(&p->pending_tokens, tag_close(tk));
      } else if (!p->full_line) {
        // pending tokens, line not full
        assert(p->pending_tokens.size > 0);
        if (p->col < p->margin) {
          // enough space for one more ')'
          p->col ++;
          pvector_push(&p->pending_tokens, tag_close(tk));
        } else  {
          // no space for ')'
          print_pending_truncated(p);
          free_close_token(p, tk);
          p->full_line = true;
        }
      } else {
        // the line is full
        assert(p->pending_tokens.size == 0);
        free_close_token(p, tk);
      }

    } else {
      // not truncation
      print_close(p, tk);
    }
  }
}
Exemplo n.º 2
0
/*
 * Collect all composites in the congruence table into vector v
 */
static void collect_congruence_roots(congruence_table_t *tbl, pvector_t *v) {
  uint32_t i, n;
  composite_t *tmp;

  n = tbl->size;
  for (i=0; i<n; i++) {
    tmp = tbl->data[i];
    if (tmp != NULL_COMPOSITE && tmp != DELETED_COMPOSITE) {
      pvector_push(v, tmp);
    }
  }
  sort_composite_array((composite_t **) v->data, v->size);
}
Exemplo n.º 3
0
/*
 * Print the label and '(' for open block tk
 */
static void print_open_token(printer_t *p, pp_open_token_t *tk) {
  uint32_t new_col;

  if (p->area.truncate) {
    if (p->col + 4 <= p->margin) {
      /*
       * truncate mode, line not full, nothing pending
       */
      assert(!p->full_line && p->pending_tokens.size == 0);

      print_blank(p);
      new_col = p->col + tk->label_size + tk_has_par(tk);
      if (new_col + 4 <= p->margin) {
        // tk fits and there's room for ' ...' after it
        print_label(p, tk);
      } else if (new_col <= p->margin) {
        // we can't tell whether tk fits yet
        // because we may need ellipsis
        p->pending_col = p->col;
        p->col = new_col;
        pvector_push(&p->pending_tokens, tag_open(tk));
      } else {
        // tk does not fit: print it truncated
        print_label_truncated(p, tk);
        p->full_line = true;;
      }

    } else if (!p->full_line) {
      /*
       * truncate mode, line not full, tokens pending
       */
      assert(p->col <= p->margin && p->pending_tokens.size > 0);

      // add tk to the pending tokens if it fits
      new_col = p->col + tk->bsize + tk_has_par(tk) + (! p->no_space);
      if (new_col <= p->margin) {
        p->col = new_col;
        pvector_push(&p->pending_tokens, tag_open(tk));
      } else {
        // the pending tokens don't fit
        // print what we can + ellipsis
        print_pending_truncated(p);
        free_open_token(p, tk);
        p->full_line = true;
      }

    } else {
      /*
       * truncate mode, line full, nothing pending
       */
      assert(p->pending_tokens.size == 0);
      free_open_token(p, tk);
    }

  } else {
    /*
     * don't truncate
     */
    print_blank(p);
    print_label(p, tk);
  }
}