Exemplo n.º 1
0
void
ascii_print_aligned_line(FILE *stream, 
                         int highlighting,
                         char *attribute_name,
                         char *line)
{
  if (highlighting) {
    char *red = get_colour_escape('r', 1);
    char *bold = get_typeface_escape('b');
    char *normal = get_typeface_escape('n');
    fprintf(stream, "%s%s-->%s:%s %s\n", 
            red, bold,
            attribute_name,
            normal,
            line);
  }
  else
    fprintf(stream, "-->%s: %s\n", attribute_name, line);
}
Exemplo n.º 2
0
/**
 * Main function for the interactive CQP program.
 *
 * Doesn't do much except call the initialisation function,
 * and then one of the loop-and-parse-input functions.
 *
 * @param argc  Number of commandline arguments.
 * @param argv  Pointer to commandline arguments.
 * @return      Return value to OS.
 */
int
main(int argc, char *argv[])
{

  which_app = cqp;

  if (!initialize_cqp(argc, argv)) {
    fprintf(stderr, "Can't initialize CQP\n");
    exit(1);
  }

  /* Test ANSI colours (if CQP was invoked with -C switch) */
  if (use_colour) {
#ifndef __MINGW__
    char *blue = get_colour_escape('b', 1);
    char *green = get_colour_escape('g', 1);
    char *red = get_colour_escape('r', 1);
    char *pink = get_colour_escape('p', 1);
    char *cyanBack = get_colour_escape('c', 0);
    char *greenBack = get_colour_escape('g', 0);
    char *yellowBack = get_colour_escape('y', 0);
    char *bold = get_typeface_escape('b');
    char *underline = get_typeface_escape('u');
    char *standout = get_typeface_escape('s');
    char *normal = get_typeface_escape('n');
    char sc_colour[256];
    int i, j;

    printf("%s%sWelcome%s to %s%sC%s%sQ%s%sP%s -- ", green, bold, normal, red, bold, pink, bold, blue, bold, normal);
    printf("the %s Colourful %s Query %s Processor %s.\n", yellowBack, greenBack, cyanBack, normal);

    for (i = 3; i <= 4; i++) {
      printf("[");
      for (j = 0; j < 8; j++) {
        sprintf(sc_colour, "\x1B[0;%d%dm", i,j);
        printf("%d%d: %sN%s%sB%s%sU%s%sS%s  ",
               i, j,
               sc_colour,
               sc_colour, bold,
               sc_colour, underline,
               sc_colour, standout,
               normal);
      }
      printf("]\n");
    }
#else
    fprintf(stderr, "We're sorry, CQP's Colourful Mode is not available under Windows.\n");
    fprintf(stderr, "CQP will continue as normal without it...\n");
    use_colour = 0;
#endif
  } /* endif use_colour */

  install_signal_handler();

  if (child_process) {
    printf("CQP version " VERSION "\n");
    fflush(stdout);
  }

  if (batchmode) {
    if (batchfd == NULL)
      fprintf(stderr, "Can't open batch file\n");
    else
      cqp_parse_file(batchfd, 1);
  }
  else {
#ifdef USE_READLINE
    if (use_readline)
      readline_main();
    else
#endif /* USE_READLINE */
      cqp_parse_file(stdin, 0);
  }

  if (macro_debug)
    macro_statistics();

  return (cqp_error_status == 0 ? 0 : 1);
}
Exemplo n.º 3
0
char *
ascii_print_field(FieldType field, int at_end)
{

  sc_before_token[0] = '\0';                /* sets sc_before_token to "" */

  /* if targets are shown, print target number at end of target/keyword fields */
  if (show_targets && at_end && (field==TargetField || field==KeywordField)) {
    char *red = get_colour_escape('r', 1);
    /* if colours are activated & seem to work, print target number in red, otherwise print in parens */
    if (*red != 0) {
      /* must set colour first, then all other current attributes */
      sprintf(sc_before_token + strlen(sc_before_token),
              "%s%s%s%s%s%d",
              sc_all_out,
              red,
              (sc_s_mode) ? sc_s_in : "",
              (sc_u_mode) ? sc_u_in : "",
              (sc_b_mode) ? sc_b_in : "",
              field - TargetField);       /* should yield 0 .. 9  */
    }
    else {
      sprintf(sc_before_token + strlen(sc_before_token),
               "(%d)", field - TargetField /* should yield 0 .. 9 */
        );
    }
  }

  /* set the display attribute flags */
  switch (field) {

  case MatchField:
    if (at_end)
      sc_s_mode = 0;
    else
      sc_s_mode = 1;
    break;
    
  case KeywordField:
    if (at_end)
      sc_u_mode = 0;
    else
      sc_u_mode = 1;
    break;

  case TargetField:
    if (at_end)
      sc_b_mode = 0;
    else
      sc_b_mode = 1;
    break;

  case NoField:
  default:
    break;
  }
  
  /* now compose escape sequence which has to be sent to the terminal (setting _all_ attributes to their current values) */
  sprintf(sc_before_token + strlen(sc_before_token),
          "%s%s%s%s",
          sc_all_out,                /* first switch off all attributes, then set the active ones in order standout, underline, bold */
          (sc_s_mode) ? sc_s_in : "",
          (sc_u_mode) ? sc_u_in : "",
          (sc_b_mode) ? sc_b_in : "");

  return sc_before_token;
}
Exemplo n.º 4
0
void
get_screen_escapes(void)
{
  int status, l;
  char *term;

  sc_s_in = "";
  sc_s_out = "";
  sc_u_in = "";
  sc_u_out = "";
  sc_b_in = "";
  sc_b_out = "";
  sc_bl_in = "";
  sc_bl_out = "";

  if ((term = getenv("TERM")) == NULL)
    return;

  if ((setupterm(term, 1, &status) == ERR) || (status != 1)) {
    return;
  }  

  /* turn off all attributes */
  sc_all_out = tigetstr("sgr0");
  if (sc_all_out == NULL) sc_all_out = "";

  /* Linux terminfo bug? fix: tigetstr("sgr0") returns an extra ^O (\x0f) character appended to the escape sequence
     (this may be some code used internally by the ncurses library).
     Since weRprintf() the escape sequences directly, we have to remove the extra character or 'less -R' will get confused. */
  l = strlen(sc_all_out);
  if ((l > 0) && (sc_all_out[l-1] == '\x0f')) {
    sc_all_out = cl_strdup(sc_all_out);
    sc_all_out[l-1] = 0;        /* just chop of the offending character */
  }


  /* standout mode */
  sc_s_in = tigetstr("smso");
  if (sc_s_in == NULL) sc_s_in = "";
  sc_s_out = tigetstr("rmso");
  if (sc_s_out == NULL) sc_s_out = "";

  /* underline */
  sc_u_in = tigetstr("smul");
  if (sc_u_in == NULL) sc_u_in = sc_s_in;
  sc_u_out = tigetstr("rmul");
  if (sc_u_out == NULL) sc_u_out = sc_s_out;
  
  /* bold */
  sc_b_in = tigetstr("bold");
  if (sc_b_in == NULL) {
    sc_b_in = sc_s_in;
    sc_b_out = sc_s_out;
  }
  else {
    sc_b_out = tigetstr("sgr0"); /* can't turn off bold explicitly */
    if (sc_b_out == NULL) sc_b_out = "";
  }

  /* blink */
  sc_bl_in = tigetstr("blink");
  if (sc_bl_in == NULL) {
    sc_bl_in = sc_s_in;
    sc_bl_out = sc_s_out;
  }
  else {
    sc_bl_out = sc_all_out;      /* can't turn off blinking mode explicitly */
  }

  escapes_initialized++;
  
  /* in highlighted mode, switch off display attributes at end of line (to be on the safe side) */
  ASCIIHighlightedPrintDescriptionRecord.AfterLine = cl_malloc(strlen(sc_all_out) + 2);
  sprintf(ASCIIHighlightedPrintDescriptionRecord.AfterLine,
          "%s\n", sc_all_out);

  /* print cpos in blue, "print structures" in pink if we're in coloured mode */
  if (use_colour) {
    char *blue = get_colour_escape('b', 1);
    char *pink = get_colour_escape('p', 1);
    char *normal = get_typeface_escape('n');
    char *bold = get_typeface_escape('b');

    ASCIIHighlightedPrintDescriptionRecord.CPOSPrintFormat = cl_malloc(strlen(blue) + strlen(normal) + 8);
    sprintf(ASCIIHighlightedPrintDescriptionRecord.CPOSPrintFormat,
            "%s%c9d:%s ", blue, '%', normal);
    ASCIIHighlightedPrintDescriptionRecord.BeforePrintStructures = cl_malloc(strlen(pink) + strlen(bold) + 4);
    sprintf(ASCIIHighlightedPrintDescriptionRecord.BeforePrintStructures,
            "%s%s", pink, bold);
    ASCIIHighlightedPrintDescriptionRecord.AfterPrintStructures = cl_malloc(strlen(normal) + 6);
    sprintf(ASCIIHighlightedPrintDescriptionRecord.AfterPrintStructures,
            ":%s ", normal);
  }
}