Пример #1
0
void cw_flush(t_col_writer *writer) {
  for (int i = 0; i < writer->_linecount; i++) {
    flush_line(writer, writer->_lines[i]);
  }

  free_lines(writer);
  free(writer->_colwidths);
  writer->_colwidths = NULL;
}
Пример #2
0
/*
 * Allocate a LINEDATA struct
 */
static LINEDATA *
allocate_line(void)
{
	LINEDATA *p = typecallocn(LINEDATA,1);
	if (p == 0)
		failed("allocate_line");

	if (all_lines == 0)
		all_lines = p;

	if (total_lines++ > MAX_LINES)
		flush_line();

	return p;
}
Пример #3
0
err(char *msg, ...)
{
  va_list args;
  va_start(args, msg);
  flush_line();
  if (msg[0] && msg[1] && msg[2] == ':' && msg[3] == ' ')
    {
      meta_printf("status:%c%c\n", msg[0], msg[1]);
      msg += 4;
    }
  char buf[1024];
  vsnprintf(buf, sizeof(buf), msg, args);
  meta_printf("message:%s\n", buf);
  fputs(buf, stderr);
  fputc('\n', stderr);
  box_exit(1);
}
Пример #4
0
void flush_lines(int nflush)
{
	LINE *l;

	while (--nflush >= 0) {
		l = lines;
		lines = l->l_next;
		if (l->l_line) {
			flush_blanks();
			flush_line(l);
		}
		nblank_lines++;
		if (l->l_line)
			(void)free((void *)l->l_line);
		free_line(l);
	}
	if (lines)
		lines->l_prev = NULL;
}
Пример #5
0
TIMESTAMP group_recorder::postsync(TIMESTAMP t0, TIMESTAMP t1){
	// if we are strict and an error has occured, stop the simulation

	// if eventful interval, read
	if(0 == write_interval){//
		if(0 == read_line()){
			gl_error("group_recorder::sync");
			/* TROUBLESHOOT
				Placeholder.
			 */
			return 0;
		}
	} else if(0 < write_interval){
		// recalculate next_time, since we know commit() will fire
		if(last_write + write_interval <= t1){
			interval_write = true;
			last_write = t1;
			next_write = t1 + write_interval;
		}
		return next_write;
	} else {
		// on-change intervals simply short-circuit
		return TS_NEVER;
	}
	// if every iteration, write
	if(0 == write_interval){
		if(0 == write_line(t1) ){
			gl_error("group_recorder::sync(): error when writing the values to the file");
			/* TROUBLESHOOT
				Placeholder.
			 */
			return 0;
		}
		if(flush_interval < 0){
			if( ((write_count + 1) % (-flush_interval)) == 0 ){
				flush_line();
			}
		}
	}
	
	// the interval recorders have already return'ed out, earlier in the sequence.
	return TS_NEVER;
}
Пример #6
0
int main(void)
{
    char word[MAX_WORD_LEN+2];
    int word_len;

    clear_line();
    for (;;) {
        read_word(word, MAX_WORD_LEN+1);
        word_len = strlen(word);
        if (word_len == 0) {
            flush_line();
            return 0;
        }
        if (word_len + 1 > space_remaining()) {
            write_line();
            clear_line();
        }
        add_word(word);
    }
}
Пример #7
0
int main(void)
{
    char word[MAX_WORD_LEN+2];
    int word_len;

    clear_line();
    for (;;) {
        read_word(word, MAX_WORD_LEN+1);
        word_len = strlen(word);
        //printf("THIS RAN 1 \n");
        if (word_len == 0) {
          //  printf("THIS RAN 2 \n");
            flush_line();
            return 0;
        }
        //printf("THIS RAN 11 \n");
        
        if (word_len > MAX_WORD_LEN){
            //printf("THIS RAN 3 \n");
            
            word[MAX_WORD_LEN] = '*';
        }
        //printf("THIS RAN 13 \n");
        
        if (word_len + 1 > space_remaining()) {
            printf("THIS RAN 4 \n");
            
            write_line();
            printf("THIS RAN 5 \n");
                
            clear_line();
            printf("THIS RAN 7 \n");
            
        }
        //printf("THIS RAN 18 \n");
        
        add_word(word);
        //printf("THIS RAN 8 \n");
        
    }
}
Пример #8
0
die(char *msg, ...)
{
  va_list args;
  va_start(args, msg);
  char buf[1024];
  int n = vsnprintf(buf, sizeof(buf), msg, args);

  if (write_errors_to_fd)
    {
      // We are inside the box, have to use error pipe for error reporting.
      // We hope that the whole error message fits in PIPE_BUF bytes.
      write(write_errors_to_fd, buf, n);
      exit(2);
    }

  // Otherwise, we in the box keeper process, so we report errors normally
  flush_line();
  meta_printf("status:XX\nmessage:%s\n", buf);
  fputs(buf, stderr);
  fputc('\n', stderr);
  box_exit(2);
}
Пример #9
0
int main(int argc, char *argv[])
{
  char word[MAX_WORD_LEN+2];
  int word_len;
  clear_line();
  for(;;) {
	  read_word(word, MAX_WORD_LEN+1);
	  word_len = strlen(word);
	  if (word_len == 0) {
		  flush_line();
		  return 0;
	  }
	  if (word_len > MAX_WORD_LEN) {
		  word[MAX_WORD_LEN] = '*';
	  }
	  if (word_len + 1 > space_remaining()) {
		  write_line();
		  clear_line();
	  }
	  add_word(word);
  }
  return 0;
}
Пример #10
0
int main(void){
	
	char word[MAX_WORD_LEN + 2];
	int word_len;
	
	clear_line();
	
	for(;;){
		word_len = read_word(word, MAX_WORD_LEN + 1);
		if (word_len == 0){
			flush_line();
			return 0;
		}
		/*
			if (word_len > MAX_WORD_LEN)
				word[MAX_WORD_LEN] = '*';
		*/
		if (word_len + 1 > space_remaining()){
			write_line();
			clear_line();
		}
		add_word(word);
	}
}
Пример #11
0
void freetype_wordwrap_flush_output(true_type_wordwrapper* wrapper) {
  if ( (wrapper->current_buffer_index > 0)
      || (wrapper->metadata_index > 0) ) {
    flush_line(wrapper, -1, false, false);
  }
}
Пример #12
0
void freetype_wrap_z_ucs(true_type_wordwrapper *wrapper, z_ucs *input,
    bool end_line_after_end_of_input) {
  z_ucs *hyphenated_word, *input_index = input;
  z_ucs current_char, last_char, buf;
  long wrap_width_position, end_index, hyph_index;
  long buf_index, last_valid_hyph_index, output_metadata_index;
  long last_valid_hyph_position, hyph_position;
  int hyph_font_dash_bitmap_width, hyph_font_dash_advance;
  int metadata_index = 0, advance, bitmap_width;
  true_type_font *hyph_font;
  bool process_line_end = end_line_after_end_of_input;

  // In order to build an algorithm most suitable to both enabled and
  // disabled hyphenation, we'll collect input until we'll find the first
  // space or newline behind the right margin and then initiate a buffer
  // flush, which will then break according to the given situation.

  // Invoking a separate flush method makes sense since it also allows
  // a simple external triggering of the flush.

  // To minimize calculations, we keeping track of the last complete word's
  // rightmost char in last_word_end_index and the "word's last advance
  // position" in last_word_end_advance_position.

  // An "advance position" sums up all the "horiAdvance" distances for all
  // glyphs in the current word.

  // last_word_end_advance_position contains the advance position of
  // the last complete word/char which still fits into the current line.
  // This is updated every time we hit a space (so we can easily find the last
  // valid position to break).


  // We'll start by fetching the last char from the buffer (if possible) for
  // purposes of kerning.
  last_char
    = (wrapper->current_buffer_index > 0)
    ? wrapper->input_buffer[wrapper->current_buffer_index - 1]
    : 0;

  while ( ((input != NULL) && (*input_index != 0))
      || (process_line_end == true) ) {

    if ((input != NULL) && (*input_index != 0)) {
      current_char = *input_index;

      ensure_additional_buffer_capacity(wrapper, 1);
      wrapper->input_buffer[wrapper->current_buffer_index] = current_char;

      TRACE_LOG("buffer-add: %c / %ld / %p / cap:%ld / lweap:%ld \n",
          (char)current_char,
          wrapper->current_buffer_index,
          wrapper->input_buffer + wrapper->current_buffer_index,
          wrapper->current_advance_position,
          wrapper->last_word_end_advance_position);

      wrapper->current_buffer_index++;

      tt_get_glyph_size(wrapper->current_font, current_char,
          &advance, &bitmap_width);
      wrapper->current_width_position
        = wrapper->current_advance_position + bitmap_width;
      //printf("current_width_position: %ld for '%c'\n",
      //    wrapper->current_width_position, current_char);
      wrapper->current_advance_position += advance;

      /*
      printf("check:'%c',font:%p,advpos,ll,lweim,cwwp,bmw: %ld/%d/%ld/%ld/%d\n",
          current_char,
          wrapper->current_font,
          wrapper->current_advance_position,
          wrapper->line_length,
          wrapper->last_word_end_index,
          wrapper->current_width_position,
          bitmap_width);

      printf("bmw, lwp, ll: %d, %ld, %d.\n",
          bitmap_width,
          wrapper->last_width_position,
          wrapper->line_length);
      */
    }
    else {
      current_char = 0;
      bitmap_width = 0;
      advance = 0;
    }

    if ( (
          (bitmap_width == 0)
          && (wrapper->last_width_position >= wrapper->line_length)
         )
        || (wrapper->current_width_position >= wrapper->line_length) ) {

      wrapper->last_width_position
        = wrapper->current_width_position;
      wrapper->last_chars_font
        = wrapper->current_font;

      /*
      printf("linebehind: %ld, %d.\n",
          wrapper->current_width_position, wrapper->line_length);
      */

      TRACE_LOG("Behind past line, match on space|newline, breaking.\n");
      // In case we're past the right margin, we'll take a look how
      // to best break the line.

      if ((current_char == Z_UCS_SPACE) || (current_char == Z_UCS_NEWLINE)
          || (((input == NULL) || (*input_index == 0))
            && (process_line_end == true)) ) {
        // Here we've found a completed word past the lind end. At this
        // point we'll break the line without exception.
        /*
        printf("last_word_end_width_position: %ld, line_length: %d.\n",
            wrapper->last_word_end_width_position, wrapper->line_length);
        */

        if (wrapper->enable_hyphenation == true) {
          end_index = wrapper->current_buffer_index - 2;
          TRACE_LOG("end_index: %d / %c, lwei: %d\n",
              end_index, wrapper->input_buffer[end_index],
              wrapper->last_word_end_index);
          while ( (end_index >= 0)
              && (end_index > wrapper->last_word_end_index)
              && ( (wrapper->input_buffer[end_index] == Z_UCS_COMMA)
                || (wrapper->input_buffer[end_index] == Z_UCS_DOT) ) ) {
            end_index--;
          }
          TRACE_LOG("end end_index: %d / %c, lwei: %d\n",
              end_index, wrapper->input_buffer[end_index],
              wrapper->last_word_end_index);
          if (end_index > wrapper->last_word_end_index) {
            end_index++;
            buf = wrapper->input_buffer[end_index];
            wrapper->input_buffer[end_index] = 0;
            if ((hyphenated_word = hyphenate(wrapper->input_buffer
                    + wrapper->last_word_end_index + 1)) == NULL) {
              TRACE_LOG("Error hyphenating.\n");
            }
            else {
              TRACE_LOG("hyphenated word: \"");
              TRACE_LOG_Z_UCS(hyphenated_word);
              TRACE_LOG("\".\n");

              wrap_width_position
                = wrapper->last_word_end_advance_position
                + wrapper->space_bitmap_width;
              hyph_index = wrapper->last_word_end_index + 1;
              buf_index = 0;
              last_valid_hyph_index = -1;

              // We'll now have to find the correct font for the start
              // of our hyphenated word. For that we'll remember the current
              // font at buffer start and iterate though all the metadata
              // until we're at the hyphenated word's beginning.
              hyph_font = wrapper->font_at_buffer_start;
              tt_get_glyph_size(hyph_font, Z_UCS_MINUS,
                  &hyph_font_dash_bitmap_width, &hyph_font_dash_advance);
              metadata_index = 0;

              while ( (buf_index < z_ucs_len(hyphenated_word))
                  && (wrap_width_position + hyph_font_dash_bitmap_width
                    <= wrapper->line_length) ) {
                /*
                   printf("Checking buf char %ld / %c, hi:%ld\n",
                   buf_index, hyphenated_word[buf_index],
                   hyph_index);
                   */
                TRACE_LOG("Checking buf char %ld / %c, hi:%ld\n",
                    buf_index, hyphenated_word[buf_index],
                    hyph_index);

                while (metadata_index < wrapper->metadata_index) {
                  //printf("metadata: %d of %d.\n",
                  //    metadata_index, wrapper->metadata_index);

                  output_metadata_index =
                    wrapper->metadata[metadata_index].output_index;

                  //printf("output_metadata_index: %ld, hyph_index: %ld\n",
                  //    output_metadata_index, hyph_index);
                  //printf("hyph_font: %p.\n", hyph_font);

                  if (output_metadata_index <= hyph_index) {
                    if (wrapper->metadata[metadata_index].font != NULL) {
                      hyph_font = wrapper->metadata[metadata_index].font;
                      tt_get_glyph_size(hyph_font, Z_UCS_MINUS,
                          &hyph_font_dash_bitmap_width,
                          &hyph_font_dash_advance);
                    }
                    metadata_index++;
                  }
                  else {
                    break;
                  }
                }

                if (hyphenated_word[buf_index] == Z_UCS_SOFT_HYPEN) {
                  last_valid_hyph_index = hyph_index + 1;
                }
                else if (hyphenated_word[buf_index] == Z_UCS_MINUS) {
                  last_valid_hyph_index = hyph_index;
                }

                if (hyphenated_word[buf_index] != Z_UCS_SOFT_HYPEN) {
                  //printf("hyph_font: %p.\n", hyph_font);
                  tt_get_glyph_size(hyph_font,
                      hyphenated_word[buf_index],
                      &advance, &bitmap_width);
                  //wrap_width_position += bitmap_width;
                  wrap_width_position += advance;
                  hyph_index++;
                }

                if ( (hyphenated_word[buf_index] == Z_UCS_SOFT_HYPEN)
                    || (hyphenated_word[buf_index] == Z_UCS_MINUS) ) {
                  last_valid_hyph_position = wrap_width_position;
                }

                buf_index++;

                /*
                   printf("(%ld + %d) = %ld <= %d\n",
                   wrap_width_position, hyph_font_dash_bitmap_width,
                   wrap_width_position + hyph_font_dash_bitmap_width,
                   wrapper->line_length);
                   */
              }

              free(hyphenated_word);

              if (last_valid_hyph_index != -1) {
                /*
                   printf("Found valid hyph pos at %ld / %c.\n",
                   last_valid_hyph_index,
                   wrapper->input_buffer[last_valid_hyph_index]);
                   */
                TRACE_LOG("Found valid hyph pos at %ld / %c.\n",
                    last_valid_hyph_index,
                    wrapper->input_buffer[last_valid_hyph_index]);
                hyph_index = last_valid_hyph_index;
                hyph_position = last_valid_hyph_position;
              }
              else {
                hyph_index = wrapper->last_word_end_index;
                hyph_position = wrapper->last_word_end_advance_position;
                //printf("no valid hyph, hyph_index: %ld.\n", hyph_index);
              }
            }
            wrapper->input_buffer[end_index] = buf;
          } // endif (end_index > wrapper->last_work_end_index)
          else {
            hyph_index = end_index;
            //printf("Hyph at %ld.\n", hyph_index);
          }
        } // endif (wrapper->enable_hyphentation == true)
        else {
          // Check for dashes inside the last word.
          // Example: "first-class car", where the word end we've now
          // found is between "first-class" and "car".
          wrap_width_position = wrapper->current_width_position;
          hyph_index = wrapper->current_buffer_index - 2;
          while ( (hyph_index >= 0)
              && (hyph_index > wrapper->last_word_end_index)) {
            /*
            printf("hyph_index: %ld / '%c'.\n",
                hyph_index, wrapper->input_buffer[hyph_index]);
            */

            if ( (wrapper->input_buffer[hyph_index] == Z_UCS_MINUS)
                && (wrap_width_position <= wrapper->line_length) ) {
              // Found a dash to break on
              break;
            }
            tt_get_glyph_size(wrapper->current_font,
                wrapper->input_buffer[hyph_index],
                &advance, &bitmap_width);
            wrap_width_position -= bitmap_width;
            hyph_index--;
          }
          hyph_position = wrap_width_position;
        }

        //printf("breaking on char %ld / %c.\n",
        //    hyph_index, wrapper->input_buffer[hyph_index]);
        TRACE_LOG("breaking on char %ld / %c.\n",
            hyph_index, wrapper->input_buffer[hyph_index]);

        if (wrapper->input_buffer[hyph_index] == Z_UCS_MINUS) {
          // We're wrappring on a in-word-dash.
          flush_line(wrapper, hyph_index, false, true);
        }
        else if (wrapper->input_buffer[hyph_index] == Z_UCS_SPACE) {
          flush_line(wrapper, hyph_index - 1, false, true);
          // In case we're wrapping between words without hyphenation or
          // in-word-dashes we'll have to get rid of the remaining leading
          // space-char in the input buffer.
          forget_first_char_in_buffer(wrapper);
        }
        else {
          if (wrapper->input_buffer[hyph_index - 2] == Z_UCS_MINUS) {
            flush_line(wrapper, hyph_index - 3, true, true);
            forget_first_char_in_buffer(wrapper);
          }
          else {
            flush_line(wrapper, hyph_index - 2, true, true);
          }
        }

        wrapper->current_advance_position
          -= hyph_position - wrapper->dash_bitmap_width;

        /*
        wrapper->last_width_position
          = wrapper->current_width_position
          - wrapper->last_word_end_advance_position;
          */

        wrapper->current_width_position
          = wrapper->current_advance_position;

        wrapper->last_word_end_advance_position
          = wrapper->current_advance_position;

        wrapper->last_word_end_width_position
          = wrapper->current_width_position;

        wrapper->last_word_end_index = -1;
      }
      else if (wrapper->current_advance_position > wrapper->line_length * 2) {
        // In case we haven't found a word end we'll only force a line
        // break in case we've filled two full lines of text.

        /*
        printf("flush on: %c\n", wrapper->input_buffer[
            wrapper->current_buffer_index - 2]);
        */
        flush_line(wrapper, wrapper->current_buffer_index - 2, false, true);

        wrapper->current_advance_position
          = advance;

        wrapper->current_width_position
          = wrapper->current_advance_position + bitmap_width;

        wrapper->last_word_end_index = -1;
        wrapper->last_word_end_advance_position = 0;
        wrapper->last_word_end_width_position = 0;

        //printf("first buf: %c\n", wrapper->input_buffer[0]);

        /*
        printf("current_buffer_index: %ld\n", wrapper->current_buffer_index);
        printf("current_advance_position: %ld\n",
            wrapper->current_advance_position);
        printf("break at %ld, 1\n", wrapper->last_char_in_line_index);
        old_index = wrapper->current_buffer_index;
        flush_line(wrapper, wrapper->last_char_in_line_index, false, true);
        chars_sent_count = old_index - wrapper->current_buffer_index;

        printf("chars_sent_count: %ld\n", chars_sent_count);
        printf("current_buffer_index: %ld\n", wrapper->current_buffer_index);

        tt_get_glyph_size(wrapper->last_chars_in_line_font,
            wrapper->input_buffer[wrapper->current_buffer_index],
            &advance, &bitmap_width);

        wrapper->current_advance_position
          -= wrapper->last_chars_in_line_advance_position;

        wrapper->last_width_position
          = wrapper->current_advance_position
          + bitmap_width;

        wrapper->last_char_in_line_index
          = 0;

        wrapper->last_word_end_advance_position
          -= wrapper->last_chars_in_line_advance_position;

        wrapper->last_word_end_width_position
          -= wrapper->last_chars_in_line_advance_position;

        wrapper->last_word_end_index
          -= chars_sent_count;

        printf("current_advance_position: %ld\n",
            wrapper->current_advance_position);
        */
      }
      else {
        // Otherwise, we'll do nothing and keep collecting chars until
        // we later find a word and or exceed the double line length.
      }
    }
    else {
      wrapper->last_width_position
        = wrapper->current_width_position;
    }

    if (current_char == Z_UCS_NEWLINE) {
      TRACE_LOG("Flushing on newline at current position.\n");
      // In case everything fits into the current line and the current
      // char is a newline, we can simply flush at the current position.
      flush_line(wrapper, wrapper->current_buffer_index - 1, false, false);

      wrapper->last_word_end_advance_position = 0;
      wrapper->last_word_end_width_position = 0;
      wrapper->current_advance_position = 0;
      wrapper->current_width_position = 0;
      wrapper->last_width_position = 0;
      wrapper->last_word_end_index = -1;
    }

    if ( (current_char == Z_UCS_SPACE) && (last_char != Z_UCS_SPACE) ) {
      TRACE_LOG("lweap-at-space: %ld\n",
          wrapper->last_word_end_advance_position);
      wrapper->last_word_end_advance_position
        = wrapper->current_advance_position;
      wrapper->last_word_end_width_position
        = wrapper->current_width_position;
      wrapper->last_word_end_index
        = wrapper->current_buffer_index - 1;
    }

    if ( (input != NULL) && (*input_index != 0) ) {
      input_index++;
      last_char = current_char;
    }
    else if (process_line_end == true) {
      process_line_end = false;
    }
  }
}
Пример #13
0
double read_val(FILE *infile,  /* file to read value from */
                int * end_flag /* 0 => OK, 1 => EOL, -1 => EOF */
                )
{
  double val;         /* return value */
  char * ptr;         /* ptr to next string to read */
  char * ptr2;        /* ptr to next string to read */
  int    length;      /* length of line to read */
  int    length_left; /* length of line still around */
  int    white_seen;  /* have I detected white space yet? */
  int    done;        /* checking for end of scan */
  int    i;           /* loop counter */
  double strtod();

  *end_flag = 0;

  if (offset == 0 || offset >= break_pnt) {
    if (offset >= break_pnt) { /* Copy rest of line back to beginning. */
      length_left = LINE_LENGTH - save_pnt - 1;
      ptr2        = line;
      ptr         = &line[save_pnt];
      for (i = length_left; i; i--)
        *ptr2++ = *ptr++;
      length    = save_pnt + 1;
    }
    else {
      length      = LINE_LENGTH;
      length_left = 0;
    }

    line[LINE_LENGTH - 1] = ' ';
    line[LINE_LENGTH - 2] = ' ';
    /* Now read next line, or next segment of current one. */
    ptr2 = fgets(&line[length_left], length, infile);

    if (ptr2 == NULL) { /* We've hit end of file. */
      *end_flag = -1;
      return ((double)0.0);
    }

    if (line[LINE_LENGTH - 1] == '\0' && line[LINE_LENGTH - 2] != '\0' &&
        line[LINE_LENGTH - 2] != '\n' && line[LINE_LENGTH - 2] != '\f') {
      /* Line too long.  Find last safe place in line. */
      break_pnt  = LINE_LENGTH - 1;
      save_pnt   = break_pnt;
      white_seen = FALSE;
      done       = FALSE;
      while (!done) {
        --break_pnt;
        if (line[break_pnt] != '\0') {
          if (isspace(line[break_pnt])) {
            if (!white_seen) {
              save_pnt   = break_pnt + 1;
              white_seen = TRUE;
            }
          }
          else if (white_seen) {
            done = TRUE;
          }
        }
      }
    }
    else {
      break_pnt = LINE_LENGTH;
    }

    offset = 0;
  }

  while (offset < LINE_LENGTH && isspace(line[offset]))
    offset++;
  if (offset == LINE_LENGTH || line[offset] == '%' || line[offset] == '#') {
    *end_flag = 1;
    if (break_pnt < LINE_LENGTH) {
      flush_line(infile);
    }
    return ((double)0.0);
  }

  ptr = &(line[offset]);
  val = strtod(ptr, &ptr2);

  if (ptr2 == ptr) { /* End of input line. */
    offset    = 0;
    *end_flag = 1;
    return ((double)0.0);
  }
  else {
    offset = (int)(ptr2 - line) / sizeof(char);
  }

  return (val);
}
Пример #14
0
/* interpret an edit command */
static bool
edit (struct line_filter *left, char const *lname, lin lline, lin llen,
      struct line_filter *right, char const *rname, lin rline, lin rlen,
      FILE *outfile)
{
  for (;;)
    {
      int cmd0, cmd1;
      bool gotcmd = false;

      cmd1 = 0; /* Pacify `gcc -W'.  */

      while (! gotcmd)
	{
	  if (putchar ('%') != '%')
	    perror_fatal (_("write failed"));
	  ck_fflush (stdout);

	  cmd0 = skip_white ();
	  switch (cmd0)
	    {
	    case '1': case '2': case 'l': case 'r':
	    case 's': case 'v': case 'q':
	      if (skip_white () != '\n')
		{
		  give_help ();
		  flush_line ();
		  continue;
		}
	      gotcmd = true;
	      break;

	    case 'e':
	      cmd1 = skip_white ();
	      switch (cmd1)
		{
		case '1': case '2': case 'b': case 'd': case 'l': case 'r':
		  if (skip_white () != '\n')
		    {
		      give_help ();
		      flush_line ();
		      continue;
		    }
		  gotcmd = true;
		  break;
		case '\n':
		  gotcmd = true;
		  break;
		default:
		  give_help ();
		  flush_line ();
		  continue;
		}
	      break;

	    case EOF:
	      if (feof (stdin))
		{
		  gotcmd = true;
		  cmd0 = 'q';
		  break;
		}
	      /* Fall through.  */
	    default:
	      flush_line ();
	      /* Fall through.  */
	    case '\n':
	      give_help ();
	      continue;
	    }
	}

      switch (cmd0)
	{
	case '1': case 'l':
	  lf_copy (left, llen, outfile);
	  lf_skip (right, rlen);
	  return true;
	case '2': case 'r':
	  lf_copy (right, rlen, outfile);
	  lf_skip (left, llen);
	  return true;
	case 's':
	  suppress_common_lines = true;
	  break;
	case 'v':
	  suppress_common_lines = false;
	  break;
	case 'q':
	  return false;
	case 'e':
	  {
	    int fd;

	    if (tmpname)
	      tmp = fopen (tmpname, "w");
	    else
	      {
		if ((fd = temporary_file ()) < 0)
		  perror_fatal ("mkstemp");
		tmp = fdopen (fd, "w");
	      }

	    if (! tmp)
	      perror_fatal (tmpname);

	    switch (cmd1)
	      {
	      case 'd':
		if (llen)
		  {
		    if (llen == 1)
		      fprintf (tmp, "--- %s %ld\n", lname, (long int) lline);
		    else
		      fprintf (tmp, "--- %s %ld,%ld\n", lname,
			       (long int) lline,
			       (long int) (lline + llen - 1));
		  }
		/* Fall through.  */
	      case '1': case 'b': case 'l':
		lf_copy (left, llen, tmp);
		break;

	      default:
		lf_skip (left, llen);
		break;
	      }

	    switch (cmd1)
	      {
	      case 'd':
		if (rlen)
		  {
		    if (rlen == 1)
		      fprintf (tmp, "+++ %s %ld\n", rname, (long int) rline);
		    else
		      fprintf (tmp, "+++ %s %ld,%ld\n", rname,
			       (long int) rline,
			       (long int) (rline + rlen - 1));
		  }
		/* Fall through.  */
	      case '2': case 'b': case 'r':
		lf_copy (right, rlen, tmp);
		break;

	      default:
		lf_skip (right, rlen);
		break;
	      }

	    ck_fclose (tmp);

	    {
	      int wstatus;
	      int werrno = 0;
	      ignore_SIGINT = true;
	      checksigs ();

	      {
#if ! (HAVE_WORKING_FORK || HAVE_WORKING_VFORK)
		char *command =
		  xmalloc (quote_system_arg (0, editor_program)
			   + 1 + strlen (tmpname) + 1);
		sprintf (command + quote_system_arg (command, editor_program),
			 " %s", tmpname);
		wstatus = system (command);
		if (wstatus == -1)
		  werrno = errno;
		free (command);
#else
		pid_t pid;

		pid = vfork ();
		if (pid == 0)
		  {
		    char const *argv[3];
		    int i = 0;

		    argv[i++] = editor_program;
		    argv[i++] = tmpname;
		    argv[i] = 0;

		    execvp (editor_program, (char **) argv);
		    _exit (errno == ENOENT ? 127 : 126);
		  }

		if (pid < 0)
		  perror_fatal ("fork");

		while (waitpid (pid, &wstatus, 0) < 0)
		  if (errno == EINTR)
		    checksigs ();
		  else
		    perror_fatal ("waitpid");
#endif
	      }

	      ignore_SIGINT = false;
	      check_child_status (werrno, wstatus, EXIT_SUCCESS,
				  editor_program);
	    }

	    {
	      char buf[SDIFF_BUFSIZE];
	      size_t size;
	      tmp = ck_fopen (tmpname, "r");
	      while ((size = ck_fread (buf, SDIFF_BUFSIZE, tmp)) != 0)
		{
		  checksigs ();
		  ck_fwrite (buf, size, outfile);
		}
	      ck_fclose (tmp);
	    }
	    return true;
	  }
	default:
	  give_help ();
	  break;
	}
    }
}
Пример #15
0
int group_recorder::commit(TIMESTAMP t1){
	// short-circuit if strict & error
	if((TS_ERROR == tape_status) && strict){
		gl_error("group_recorder::commit(): the object has error'ed and is halting the simulation");
		/* TROUBLESHOOT
			In strict mode, any group_recorder logic errors or input errors will
			halt the simulation.
		 */
		return 0;
	}

	// short-circuit if not open
	if(TS_OPEN != tape_status){
		return 1;
	}

	// if periodic interval, check for write
	if(write_interval > 0){
		if(interval_write){
			if(0 == read_line()){
				gl_error("group_recorder::commit(): error when reading the values");
				return 0;
			}
			if(0 == write_line(t1)){
				gl_error("group_recorder::commit(): error when writing the values to the file");
				return 0;
			}
			last_write = t1;
			interval_write = false;
		}
	}

	// if every change,
	//	* compare to last values
	//	* if different, write
	if(-1 == write_interval){
		if(0 == read_line()){
			if(0 == read_line()){
				gl_error("group_recorder::commit(): error when reading the values");
				return 0;
			}
			if(0 != strcmp(line_buffer, prev_line_buffer) ){
				if(0 == write_line(t1)){
					gl_error("group_recorder::commit(): error when writing the values to the file");
					return 0;
				}
			}
		}

	}

	// if periodic flush, check for flush
	if(flush_interval > 0){
		if(last_flush + flush_interval <= t1){
			last_flush = t1;
		}
	} else if(flush_interval < 0){
		if( ((write_count + 1) % (-flush_interval)) == 0 ){
			flush_line();
		}
	} // if 0, no flush

	// check if write limit
	if(limit > 0 && write_count >= limit){
		// write footer
		write_footer();
		fclose(rec_file);
		rec_file = 0;
		free(line_buffer);
		line_buffer = 0;
		line_size = 0;
		tape_status = TS_DONE;
	}

	// check if strict & error ... a second time in case the periodic behavior failed.
	if((TS_ERROR == tape_status) && strict){
		gl_error("group_recorder::commit(): the object has error'ed and is halting the simulation");
		/* TROUBLESHOOT
			In strict mode, any group_recorder logic errors or input errors will
			halt the simulation.
		 */
		return 0;
	}

	return 1;
}
Пример #16
0
/*
 * Filter an entire file, writing the result to the standard output.
 */
static void
ManFilter(FILE *ifp)
{
	int	c;
	int	level = 0;
	int	ident = CS_NORMAL;
	int	esc_mode = ATR_NORMAL;

	while ((c = fgetc(ifp)) != EOF) {
		switch (c) {
		case '\b':
			backspace();
			break;

		case '\r':
			if (cur_line != 0)
				cur_line->l_this = 0;
			break;

		case '\n':
			next_line();
			cur_line->l_this = 0;
			break;

		case '\t':
			do {
				put_cell(SPACE, level, ident);
			} while (cur_line->l_this & 7);
			break;

		case '\v':
			prev_line();
			break;

		case SHIFT_IN:
			ident = CS_NORMAL;
			break;

		case SHIFT_OUT:
			ident = CS_ALTERNATE;
			break;

		case ESCAPE:
			switch (fgetc(ifp)) {
			case '[':
				esc_mode = ansi_escape(ifp, ident, level);
				break;
			case '\007':
			case '7':
				prev_line();
				break;
			case '\010':
			case '8':
				level = half_up(level);
				break;
			case '\011':
			case '9':
				level = half_down(level);
				break;
			default: /* ignore everything else */
				break;
			}
			break;

		default: /* ignore other nonprinting characters */
			if (isprint(c)) {
				put_cell(c, level, ident);
				if (c != SPACE) {
					if (esc_mode & ATR_BOLD) {
						backspace();
						put_cell(c, level, ident);
					}
					if (esc_mode & ATR_UNDER) {
						backspace();
						put_cell('_', level, ident);
					}
				}
			}
			break;
		}
	}

	while (all_lines != 0)
		flush_line();

	total_lines = 0;
}
Пример #17
0
static void layout_flow(fz_context *ctx, fz_html *box, fz_html *top, float em, float page_h)
{
    fz_html_flow *node, *line, *mark;
    float line_w;
    float indent;
    int align;
    int line_align;

    em = fz_from_css_number(box->style.font_size, em, em);
    indent = box->is_first_flow ? fz_from_css_number(top->style.text_indent, em, top->w) : 0;
    align = top->style.text_align;

    if (box->flow_dir == BIDI_RIGHT_TO_LEFT)
    {
        if (align == TA_LEFT)
            align = TA_RIGHT;
        else if (align == TA_RIGHT)
            align = TA_LEFT;
    }

    box->x = top->x;
    box->y = top->y + top->h;
    box->w = top->w;
    box->h = 0;

    if (!box->flow_head)
        return;

    for (node = box->flow_head; node; node = node->next)
    {
        if (node->type == FLOW_IMAGE)
        {
            float w = 0, h = 0;
            find_accumulated_margins(ctx, box, &w, &h);
            measure_image(ctx, node, top->w - w, page_h - h);
        }
        else
        {
            measure_word(ctx, node, em);
        }
    }

    /* start by skipping whitespace (and newline) at the beginning of tags */
    node = box->flow_head;
    if (node->type == FLOW_BREAK)
        node = node->next;
    while (node && node->type == FLOW_GLUE)
        node = node->next;

    mark = NULL;
    line = node;
    line_w = indent;

    while (node)
    {
        switch (node->type)
        {
        case FLOW_WORD:
            break;
        case FLOW_IMAGE:
            /* TODO: break before/after image */
            mark = node;
            break;
        case FLOW_GLUE:
            mark = node;
            break;
        case FLOW_BREAK:
            line_align = align == TA_JUSTIFY ? TA_LEFT : align;
            flush_line(ctx, box, page_h, top->w, line_align, indent, line, node);
            indent = 0;
            line = node->next;
            line_w = 0;
            mark = NULL;
            break;
        }

        if (mark && line_w + node->w > top->w)
        {
            flush_line(ctx, box, page_h, top->w, align, indent, line, mark);
            indent = 0;
            node = mark;
            while (node && node->type == FLOW_GLUE)
                node = node->next;
            line = node;
            line_w = 0;
            mark = NULL;
        }

        if (node)
        {
            line_w += node->w;
            node = node->next;
        }
    }

    if (line)
    {
        line_align = align == TA_JUSTIFY ? TA_LEFT : align;
        flush_line(ctx, box, page_h, top->w, line_align, indent, line, NULL);
    }
}
Пример #18
0
Token Tokenizer::next() {

  ready = false;

  if (!scanner->current_char()) {
    return m_end;
  }

  while (scanner->current_char()) {
    char c = *scanner->current_char();

    if (c == DOUBLE_QUOTE) {
      position pos = scanner->position();
      scanner->pop();
      ret(Token::String(slurp_until(DOUBLE_QUOTE), pos));
      scanner->pop();
    }
    else if (c == SEMICOLON || (c == DISPATCH && is_next(BANG))) {
      flush_line();
      continue;
    }
    else if (whitespace.find(c) != whitespace.end()) {
      //nothing
    }
    else if (c == BACKSLASH) {
      position pos = scanner->position();
      scanner->pop();
      ret(Token::Char(slurp_until({whitespace, delimiters}), pos));
    }
    else if (c == DISPATCH && is_next(CURLY_OPEN)) {
      ret(Token::SetOpen(scanner->position()));
      scanner->pop();
    }
    else if (c == DISPATCH && is_next(ROUND_OPEN)) {
      ret(Token::FunctionOpen(scanner->position()));
      scanner->pop();
    }
    else if (c == DISPATCH && is_next(DOUBLE_QUOTE)) {
      position pos = scanner->position();
      scanner->pop();
      scanner->pop();
      ret(Token::Regex(slurp_until(DOUBLE_QUOTE), pos));
      scanner->pop();
    }
    else if (c == DISPATCH) {
      position pos = scanner->position();
      scanner->pop();
      ret(Token::Dispatch(slurp_until({whitespace, delimiters}), pos));
    }
    else if (c == ROUND_OPEN) {
      ret(Token::RoundOpen(scanner->position()));
    }
    else if (c == ROUND_CLOSE) {
      ret(Token::RoundClose(scanner->position()));
    }
    else if (c == CURLY_OPEN) {
      ret(Token::CurlyOpen(scanner->position()));
    }
    else if (c == CURLY_CLOSE) {
      ret(Token::CurlyClose(scanner->position()));
    }
    else if (c == SQUARE_OPEN) {
      ret(Token::SquareOpen(scanner->position()));
    }
    else if (c == SQUARE_CLOSE) {
      ret(Token::SquareClose(scanner->position()));
    }
    else {
      position pos = scanner->position();
      ret(Token::Literal(slurp_until({whitespace, delimiters}), pos));
    }

    scanner->pop();

    if (ready) {
      break;
    }

  }

  if (ready) {
    return current;
  }
  else {
    return m_end;
  }
}
Пример #19
0
Файл: xd.c Проект: darius/ung
static void accept (char c) {
  line[n % line_length] = c;
  ++n;
  if (0 == n % line_length)
    flush_line ();
}
Пример #20
0
Файл: xd.c Проект: darius/ung
static void finish (void) {
  if (0 < n % line_length)
    flush_line ();
  must_printf ("\n");
}