Exemplo n.º 1
0
/** @brief Write a string to a user-visible output location.

    Write a null-terminated string to the serial port, console, terminal, or
    other display device, such that the text is visible to the user.

    @param pszString    A null-terminated string.
*/
void RedOsOutputString(
    const char *pszString)
{
    if(pszString == NULL)
    {
        REDERROR();
    }
    else
    {
        uint32_t ulIdx = 0U;

        while(pszString[ulIdx] != '\0')
        {
            OUTPUT_CHARACTER(pszString[ulIdx]);

            /*  Serial output often requires a \r to print newlines correctly.
            */
            if(pszString[ulIdx] == '\n')
            {
                OUTPUT_CHARACTER('\r');
            }

            ulIdx++;
        }
    }
}
Exemplo n.º 2
0
void
shipout_text (struct obstack *obs, const char *text, int length, int line)
{
  static bool start_of_output_line = true;
  const char *cursor;

  /* If output goes to an obstack, merely add TEXT to it.  */

  if (obs != NULL)
    {
      obstack_grow (obs, text, length);
      return;
    }

  /* Do nothing if TEXT should be discarded.  */

  if (output_diversion == NULL)
    return;

  /* Output TEXT to a file, or in-memory diversion buffer.  */

  if (!sync_output)
    switch (length)
      {

        /* In-line short texts.  */

      case 8: OUTPUT_CHARACTER (*text); text++;
      case 7: OUTPUT_CHARACTER (*text); text++;
      case 6: OUTPUT_CHARACTER (*text); text++;
      case 5: OUTPUT_CHARACTER (*text); text++;
      case 4: OUTPUT_CHARACTER (*text); text++;
      case 3: OUTPUT_CHARACTER (*text); text++;
      case 2: OUTPUT_CHARACTER (*text); text++;
      case 1: OUTPUT_CHARACTER (*text);
      case 0:
        return;

        /* Optimize longer texts.  */

      default:
        output_text (text, length);
      }
  else
    {
      /* Check for syncline only at the start of a token.  Multiline
         tokens, and tokens that are out of sync but in the middle of
         the line, must wait until the next raw newline triggers a
         syncline.  */
      if (start_of_output_line)
        {
          start_of_output_line = false;
          output_current_line++;
#ifdef DEBUG_OUTPUT
          xfprintf (stderr, "DEBUG: line %d, cur %d, cur out %d\n",
                   line, current_line, output_current_line);
#endif

          /* Output a `#line NUM' synchronization directive if needed.
             If output_current_line was previously given a negative
             value (invalidated), output `#line NUM "FILE"' instead.  */

          if (output_current_line != line)
            {
              OUTPUT_CHARACTER ('#');
              OUTPUT_CHARACTER ('l');
              OUTPUT_CHARACTER ('i');
              OUTPUT_CHARACTER ('n');
              OUTPUT_CHARACTER ('e');
              OUTPUT_CHARACTER (' ');
              for (cursor = ntoa (line, 10); *cursor; cursor++)
                OUTPUT_CHARACTER (*cursor);
              if (output_current_line < 1 && current_file[0] != '\0')
                {
                  OUTPUT_CHARACTER (' ');
                  OUTPUT_CHARACTER ('"');
                  for (cursor = current_file; *cursor; cursor++)
                    OUTPUT_CHARACTER (*cursor);
                  OUTPUT_CHARACTER ('"');
                }
              OUTPUT_CHARACTER ('\n');
              output_current_line = line;
            }
        }

      /* Output the token, and track embedded newlines.  */
      for (; length-- > 0; text++)
        {
          if (start_of_output_line)
            {
              start_of_output_line = false;
              output_current_line++;
#ifdef DEBUG_OUTPUT
              xfprintf (stderr, "DEBUG: line %d, cur %d, cur out %d\n",
                       line, current_line, output_current_line);
#endif
            }
          OUTPUT_CHARACTER (*text);
          if (*text == '\n')
            start_of_output_line = true;
        }
    }
}