Ejemplo n.º 1
0
void wsh_client_print_header(FILE* file, const char* format, ...) {
	va_list args;
	va_start(args, format);
	if (wsh_client_get_dark_bg())
		color_print("\x1b[94m", file, format, args);
	else
		color_print("\x1b[34m", file, format, args);
	va_end(args);
}
Ejemplo n.º 2
0
void wsh_client_print_error(const char* format, ...) {
	va_list args;
	va_start(args, format);
	if (wsh_client_get_dark_bg())
		color_print("\x1b[91m", stderr, format, args);
	else
		color_print("\x1b[31m", stderr, format, args);
	va_end(args);
}
Ejemplo n.º 3
0
int main(void)
{
	char line[MAXLINE];
	int found = 0;

	while(my_getline(line, MAXLINE) > 0)
		if(strIndex(line, pattern) >= 0)
		{	//printf("%s", line);
			color_print(line, pattern);
			found ++;
		}
	return found;
}
Ejemplo n.º 4
0
void
search_prompt(void)
{
  char str[128];

  WINDOW *win = specific_win(SEARCH_INPUT);
  
  snprintf(str, sizeof(str), "%s█", songlist->key);

  if(songlist->picking_mode)
	color_print(win, 0, "Search: ");
  else
	color_print(win, 5, "Search: ");
  
  if(songlist->length == 0)
	color_print(win, 4, "no entries...");
  else if(songlist->picking_mode)
	color_print(win, 0, str);
  else
	color_print(win, 6, str);

  wprintw(win, "%*s", 40, " ");
}
Ejemplo n.º 5
0
void
songlist_down_state_bar(void)
{
  static const char *bar =
	"_________________________________________________________/";
  WINDOW *win = specific_win(SLIST_DOWN_STATE_BAR);  

  int length = songlist->length,
	height = wchain[SONGLIST].win->_maxy + 1,
	cursor = songlist->cursor;

  wprintw(win, "%*c %s", 5, ' ', bar);
  color_print(win, 8, "TED MADE");

  if(cursor + height / 2 < length)
  	mvwprintw(win, 0, 0, "%*s     %s", 3, " ", "... ...  ");
}
Ejemplo n.º 6
0
void
print_extra_info(void)
{
  WINDOW *win = specific_win(EXTRA_INFO);
  
  if (basic_info->volume >= 0)
	wprintw(win, "Volume:%3i%c ", basic_info->volume, '%');
  else {
	wprintw(win, "Volume: n/a   ");
  }

  mvwprintw(win, 0, 14, "Search: ");
  color_print(win, 6,
			  mpd_tag_name(songlist->tags
						   [songlist->crt_tag_id]));
  wprintw(win, "  ");
}
Ejemplo n.º 7
0
void  displays_describe_name_before_describe_block(const char* desc) {
  color_print(ANSI_COLOR_RESET, desc);
}
Ejemplo n.º 8
0
void displays_refute_null_failed(void *act, const char* file, int line) {
  char text[TEXT_SIZE];
  sprintf(text, "FAILED\nunexpected null\ngot: %p\n%s:%d", act, file, line);
  color_print(ANSI_COLOR_RED, text);
}
Ejemplo n.º 9
0
void displays_expect_null_failed(void *act, const char*file, int line) {
  char text[TEXT_SIZE];
  sprintf(text, "FAILED\nexpected %p to point to NULL\n%s:%d", act, file, line);
  color_print(ANSI_COLOR_RED, text);
}
Ejemplo n.º 10
0
void displays_expect_false_failed(int act, const char*file, int line) {
  char text[TEXT_SIZE];
  sprintf(text, "FAILED\nexpected %d to be false, got true\n%s:%d", act, file, line);
  color_print(ANSI_COLOR_RED, text);
}
Ejemplo n.º 11
0
void displays_string_refute_failed(const char*exp, const char*act, const char*file, int line) {
  char text[TEXT_SIZE];
  sprintf(text, "FAILED\nexpected \"%s\" not to equal \"%s\"\n%s:%d", exp, act, file, line);
  color_print(ANSI_COLOR_RED, text);
}
Ejemplo n.º 12
0
void displays_refute_equal_failed(long actual, long expected, const char*file, int line) {
  char text[TEXT_SIZE];
  sprintf(text, "FAILED\nexpected (%ld) and (%ld) not to be equal\n%s:%d", expected, actual, file, line);
  color_print(ANSI_COLOR_RED, text);
}
Ejemplo n.º 13
0
void displays_expect_equal_failed(long exp, long act, const char*file, int line) {
  char text[TEXT_SIZE];
  sprintf(text, "FAILED\nexpected: %ld\ngot: %ld\n%s:%d", exp, act, file, line);
  color_print(ANSI_COLOR_RED, text);
}
Ejemplo n.º 14
0
/* For a given region, defined by reg_start and reg_end, show
 the refence sequence, the consensus sequence, 
 and the sequence of all the fragments that overlap this
 region at all.
 */
void print_region( MapAlignmentP maln, int reg_start, int reg_end,
		   int out_format, int in_color ) {
  int i, ref_pos, ref_gaps, j, cons_pos, ins_len;
  int num_gaps = 0;
  int ins_seq_len;
  int read_out_pos;
  char* consensus;
  char* aln_ref;
  char* read_reg;
  char* ins_cons;
  char* read_str;
  char* read_id;
  char* ins_seq;
  int* ins_cov;
  BaseCountsP bcs;
  AlnSeqP aln_seq;
  PSSMP psm;
  
  /* Make sure region doesn't go off edge */
  if (reg_start < 1) {
    reg_start = 1;
  }
  if (reg_end > maln->ref->seq_len) {
    reg_end = maln->ref->seq_len;
  }
  
  bcs = (BaseCountsP)save_malloc(sizeof(BaseCounts));
  reset_base_counts(bcs);
  
  /* Find how many gaps are in this region */
  for (i = reg_start-1; i <= reg_end; i++) {
    num_gaps += maln->ref->gaps[i];
  }
  
  /* Make char arrays long enough for the sequence plus
     gaps for the reference, the consensus, and a single 
     read. These will be populated and output by the rest
     of this function.
  */
  consensus = (char*)save_malloc((num_gaps + (reg_end-reg_start+1) + 10)
				 * sizeof(char));
  aln_ref = (char*)save_malloc((num_gaps + (reg_end-reg_start+1) + 10)
			       * sizeof(char));
  read_reg = (char*)save_malloc((num_gaps + (reg_end-reg_start+1) + 10)
				* sizeof(char));
	
  /* Make char and int array for insert consensus and
     insert coverage to be used whenever needed */
  ins_cons = (char*)save_malloc(MAX_INS_LEN * sizeof(char));
  ins_cov = (int* )save_malloc(MAX_INS_LEN * sizeof(int));
  
  cons_pos = 0;
  for (ref_pos = reg_start - 1; ref_pos < reg_end; ref_pos++) {
    ref_gaps = maln->ref->gaps[ref_pos];
    /* Add these gaps to the reference aligned string and the inserted
       sequence to the consensus[] */
    if (ref_gaps > 0) {
      find_ins_cons(maln, ref_pos, ins_cons, ins_cov, out_format);
      for (j = 0; j < ref_gaps; j++) {
	aln_ref[cons_pos] = '-';
	consensus[cons_pos] = ins_cons[j];
	cons_pos++;
      }
    }
    /* Re-zero all the base counts */
    reset_base_counts(bcs);
    
    /* Find all the aligned fragments that include this
       position and make a consensus from it */
    for (j = 0; j < maln->num_aln_seqs; j++) {
      aln_seq = maln->AlnSeqArray[j];
      /* Does this aligned fragment cover this position? */
      if ( (aln_seq->start <= ref_pos) && // checked
	   (aln_seq->end >= ref_pos)) {
	if (aln_seq->revcom) {
	  psm = maln->rpsm;
	} else {
	  psm = maln->fpsm;
	}
	add_base(aln_seq->seq[ref_pos - aln_seq->start], bcs, psm,
		 aln_seq->smp[ref_pos - aln_seq->start]);
      }
    }
    
    consensus[cons_pos] = find_consensus(bcs, maln->cons_code);
    aln_ref[cons_pos] = maln->ref->seq[ref_pos];
    cons_pos++;
  }
  
  consensus[cons_pos] = '\0';
  aln_ref[cons_pos] = '\0';
  
  /* Now print the reference and the consensus */
  if (out_format == 61) {
    fasta_aln_print(aln_ref, maln->ref->id);
    fasta_aln_print(consensus, "Consensus");
  } else {
    if (in_color) {
      printf("%-20.20s ", maln->ref->id);
      color_print(aln_ref);
      printf("%-20.20s ", "Consensus");
      color_print(consensus);
    } else
      printf("%-20.20s %s\n%-20s %s\n", maln->ref->id, aln_ref,
	     "Consensus", consensus);
  }
  
  /* 
     Alloc memories for the string to hold each read (plus .'s outside)
     and alloc memories for the special id which is the regular ID
     plus the code for whether it's truncated, reverse complemented,
     and the number of input sequence
  */
  read_str = (char*)save_malloc(strlen(aln_ref) * sizeof(char) + 1);
  read_id  = (char*)save_malloc((MAX_ID_LEN + 4) * sizeof(char) + 1);
  /* Find every sequence that overlaps this region and print
     the overlapping segment */
  for (j = 0; j < maln->num_aln_seqs; j++) {
    aln_seq = maln->AlnSeqArray[j];
    if (alnseq_ol_reg(aln_seq, (reg_start-1), (reg_end-1)) ) {
      read_out_pos = 0;
      if (aln_seq->trimmed) {
	read_id[0] = 't';
      } else {
	read_id[0] = '_';
      }
      
      if (aln_seq->revcom) {
	read_id[1] = 'r';
      } else {
	read_id[1] = '_';
      }
      sprintf( &read_id[2], "%0.2d", aln_seq->num_inputs );
      read_id[4] = '\0';

      strcat(read_id, aln_seq->id);
      if (out_format == 6) {
	printf("%-20.20s ", read_id);
      }
      for (ref_pos = reg_start - 1; ref_pos < reg_end; ref_pos++) {
	ref_gaps = maln->ref->gaps[ref_pos];
	/* Check to make sure that this fragment has started and
	   not ended by this ref_pos */
	if ( (aln_seq->start <= ref_pos) && // checked
	     (aln_seq->end >= ref_pos)) {
	  if (ref_gaps > 0) {
	    if (aln_seq->ins[ref_pos - aln_seq->start] == NULL) {
	      ins_len = 0;
	    } else {
	      ins_len
		= strlen(aln_seq->ins[ref_pos - aln_seq->start]);
	    }
	    if (aln_seq->start == ref_pos) {
	      // Exactly at the beginning of this frag
	      for (i = 0; i < ref_gaps; i++) {
		read_str[read_out_pos++] = '.';
		//		printf( "." );
	      }
	    } else {
	      // Just a normal, interior gapped position
	      if (ins_len > 0) {
		ins_seq
		  = aln_seq->ins[ref_pos - aln_seq->start];
		ins_seq_len = strlen(ins_seq);
		for (i = 0; i < ins_seq_len; i++) {
		  read_str[read_out_pos++] = ins_seq[i];
		}
		//		printf( "%s", aln_seq->ins[ref_pos - aln_seq->start] );
	      }
	      for (i = 0; i < (ref_gaps - ins_len); i++) {
		read_str[read_out_pos++] = '-';
		//		printf( "-" );
	      }
	    }
	  }
	  read_str[read_out_pos++]
	    = aln_seq->seq[ref_pos - aln_seq->start];
	  //printf( "%c", aln_seq->seq[ref_pos - aln_seq->start] );
	} else {
	  // This fragment doesn't actually cover this base
	  for (i = 0; i < ref_gaps; i++) {
	    // print this . for all ref gaps
	    read_str[read_out_pos++] = '.';
	    // printf( "." );
	  }
	  read_str[read_out_pos++] = '.';
	  //printf( "." );
	}
      }
      read_str[read_out_pos] = '\0';
      if (out_format == 61) {
	fasta_aln_print(read_str, read_id);
      } else {
	
	if (in_color) {
	  color_print(read_str);
	} else
	  printf("%s\n", read_str);
      }
    }
  }
  free(bcs);
  free(consensus);
  free(aln_ref);
  free(read_reg);
  free(ins_cons);
  free(ins_cov);
  free(read_str);
  free(read_id);
}
Ejemplo n.º 15
0
void scrollback_displayline(int window_nr, NEWWIN *win, buffer *pbuf, int buffer_offset, int terminal_offset, int offset_in_line, mybool_t force_to_winwidth, char show_winnr)
{
	char *cur_line = (pbuf -> be)[buffer_offset].Bline;

	wmove(win -> win, terminal_offset, 0);

	if (cur_line)
	{
		proginfo *cur_line_meta = (pbuf -> be)[buffer_offset].pi;
		double ts = (pbuf -> be)[buffer_offset].ts;
		char old_color_settings = 0;

		if (scrollback_no_colors && cur_line_meta != NULL)
		{
			old_color_settings = cur_line_meta -> cdef.colorize;
			cur_line_meta -> cdef.colorize = 0;
		}
		if (IS_MARKERLINE(cur_line_meta))
		{
			color_print(window_nr, win, cur_line_meta, cur_line, NULL, -1, MY_FALSE, 0, 0, ts, show_winnr);
		}
		else /* just a buffered line */
		{
			char *error = NULL;
			regmatch_t *pmatch = NULL;
			int matching_regex = -1;
			char display;
			(void)check_filter(cur_line_meta, cur_line, &pmatch, &error, &matching_regex, 0, &display);
			if (error)
			{
				color_print(window_nr, win, cur_line_meta, error, NULL, -1, MY_FALSE, 0, 0, ts, show_winnr);
				myfree(error);
			}
			if (display)
			{
				if (offset_in_line)
				{
					int line_len = strlen(cur_line);
					int new_size = 0;

					if (offset_in_line < line_len)
						new_size = min(win -> width, line_len - offset_in_line);

					color_print(window_nr, win, cur_line_meta, cur_line, pmatch, matching_regex, force_to_winwidth, offset_in_line, offset_in_line + new_size, ts, show_winnr);
				}
				else
				{
					color_print(window_nr, win, cur_line_meta, cur_line, pmatch, matching_regex, force_to_winwidth, 0, 0, ts, show_winnr);
				}
			}

			myfree(pmatch);
		}
		if (scrollback_no_colors && cur_line_meta != NULL)
		{
			cur_line_meta -> cdef.colorize = old_color_settings;
		}
	}
	else /* an empty line */
	{
		/* do nothing */
	}
}
Ejemplo n.º 16
0
pthread_create(pthread_t* thread,
        const pthread_attr_t* attr,
        void* (*start_routine)(void *),
        void * arg)
{
    void *handle;
    char *error;
    int (*rptc) (pthread_t *, const pthread_attr_t *, void* (*start_routine)(void *), void *);
    int ret;
    static int reallpthrindex = 0;
    static int npinned = 0;
    static int ncalled = 0;
    static int overflow = 0;
    static int overflowed = 0;
    static int silent = 0;
    static int pin_ids[MAX_NUM_THREADS];
    static uint64_t skipMask = 0x0;
    static int ncpus = 0;


    /* On first entry: Get Evironment Variable and initialize pin_ids */
    if (ncalled == 0)
    {
        char *str;
        char *token, *saveptr;
        char *delimiter = ",";
        int i = 0;
        cpu_set_t cpuset;

        str = getenv("LIKWID_SKIP");
        if (str != NULL)
        {
            skipMask = strtoul(str, &str, 16);
        }
        else if ( skipMask == 0x0 )
        {
            dlerror();    /* Clear any existing error */
            dlsym(RTLD_DEFAULT,"__kmpc_begin");

            if (( dlerror()) == NULL)  {
                skipMask = 0x1;
            }
        }


        if (getenv("LIKWID_SILENT") != NULL)
        {
            silent = 1;
        }

        if (!silent)
        {
            color_print("[pthread wrapper] \n");
        }

        str = getenv("LIKWID_PIN");
        if (str != NULL)
        {
            token = str;
            while (token)
            {
                token = strtok_r(str,delimiter,&saveptr);
                str = NULL;
                if (token)
                {
                    ncpus++;
                    pin_ids[i++] = strtoul(token, &token, 10);
                }
            }
            CPU_ZERO(&cpuset);
            CPU_SET(pin_ids[ncpus-1], &cpuset);
            ret = sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
            if (!silent)
            {
                color_print("[pthread wrapper] MAIN -> %d\n",pin_ids[ncpus-1]);
            }
            //ncpus--; /* last ID is the first (the process was pinned to) */
        }
        else
        {
            color_print("[pthread wrapper] ERROR: Environment Variabel LIKWID_PIN not set!\n");
        }

        if (!silent)
        {
            color_print("[pthread wrapper] PIN_MASK: ");

            for (int i=0;i<ncpus-1;i++)
            {
                color_print("%d->%d  ",i,pin_ids[i]);
            }
            color_print("\n[pthread wrapper] SKIP MASK: 0x%llX\n",LLU_CAST skipMask);
        }

        overflow = ncpus-1;
    }

    /* Handle dll related stuff */
    do
    {
        handle = dlopen(sosearchpaths[reallpthrindex], RTLD_LAZY);
        if (handle)
        {
            break;
        }
        if (sosearchpaths[reallpthrindex] != NULL) 
        {
            reallpthrindex++;
        }
    }

    while (sosearchpaths[reallpthrindex] != NULL);

    if (!handle)
    {
        color_print("%s\n", dlerror());
        return -1;
    }

    dlerror();    /* Clear any existing error */
    rptc = dlsym(handle, "pthread_create");

    if ((error = dlerror()) != NULL)
    {
        color_print("%s\n", error);
        return -2;
    }

    ret = (*rptc)(thread, attr, start_routine, arg);

    /* After thread creation pin the thread */
    if (ret == 0)
    {
        cpu_set_t cpuset;

        if ((ncalled<64) && (skipMask&(1ULL<<(ncalled))))
        {
            if (!silent)
            {
                color_print("\tthreadid %lu -> SKIP \n", *thread);
            }
        }
        else
        {
            CPU_ZERO(&cpuset);
            CPU_SET(pin_ids[npinned%ncpus], &cpuset);
            pthread_setaffinity_np(*thread, sizeof(cpu_set_t), &cpuset);
            if ((npinned == overflow) && (!overflowed))
            {
                if (!silent)
                {
                    color_print("Roundrobin placement triggered\n\tthreadid %lu -> core %d - OK", *thread, pin_ids[npinned%ncpus]);
                }
                overflowed = 1;
                npinned = (npinned+1)%ncpus;
            }
            else
            {
                if (!silent)
                {
                    color_print("\tthreadid %lu -> core %d - OK", *thread, pin_ids[npinned%ncpus]);
                }
                npinned++;
                if ((npinned >= ncpus) && (overflowed))
                {
                    npinned = 0;
                }
            }

            if (!silent)
            {
                color_print("\n");
            }
        }
    }

    fflush(stdout);
    ncalled++;
    dlclose(handle);

    return ret;
}
Ejemplo n.º 17
0
void wsh_client_print_success(const char* format, ...) {
	va_list args;
	va_start(args, format);
	color_print("\x1b[39m", stdout, format, args);
	va_end(args);
}
Ejemplo n.º 18
0
void displays_example_name_before_it_block(const char* example) {
  printf("- ");
  color_print(ANSI_COLOR_RESET, example);
}
Ejemplo n.º 19
0
void
print_basic_song_info(void)
{
  WINDOW *win = specific_win(BASIC_INFO);
  
  if (basic_info->crt_name) {

	char buff[80];
	/* int twid = 38; */
	/* if(snprintf(buff, twid, "%s", */
	/* 			  get_song_tag(song, MPD_TAG_TITLE)) >= twid) */
	/* 	strcpy(buff + twid - 4, "..."); // in case of long title */
	/* color_print(win, 1, buff); */

	/* print artist
	   int awid = 28;
	   if(snprintf(buff, awid, "\t%s",
	   get_song_tag(song, MPD_TAG_ARTIST)) >= awid)
	   strcpy(buff + awid - 4, "...");
	   color_print(win, 5, buff);
	*/

	int title_len = win->_maxx < (int)sizeof(buff) ?
	  win->_maxx : (int)sizeof(buff);
	snprintf(buff, title_len, "%s", basic_info->crt_name);
	color_print(win, 1,  buff);
  }

  mvwprintw(win, 1, 0, "[");
  if (basic_info->state == MPD_STATE_PLAY)
	color_print(win, 6, "playing");
  else if(basic_info->state == MPD_STATE_PAUSE)
	color_print(win, 4, "paused");
  else
	color_print(win, 4, "stopped");
  wprintw(win, "]");

  /* mvwprintw(win, 1, 10, "[%i/%u]", */
  /* 		  mpd_status_get_song_pos(status) + 1, */
  /* 		  mpd_status_get_queue_length(status)); */
  
  // status modes [ors] : repeat, random, single
  mvwprintw(win, 1, 10, "["); 
  if (basic_info->random)
	color_print(win, 1, "r");
  else wprintw(win, "-");

  if (basic_info->single)
	color_print(win, 7, "s");
  else wprintw(win, "-");

  if (basic_info->repeat)
	color_print(win, 5, "o");
  else wprintw(win, "-");
  wprintw(win, "]");

  mvwprintw(win, 1, 16, "[%s]", basic_info->format); // music format

  mvwprintw(win, 1, 46, "%02i:%02i",
			basic_info->total_time / 60, basic_info->total_time % 60);

  static int old_bit_rate = 111;
  if(abs(old_bit_rate - basic_info->bit_rate)
	 / (float) (basic_info->bit_rate + 1) > 0.2 && basic_info->bit_rate != 0)
	old_bit_rate = basic_info->bit_rate;
  else
	basic_info->bit_rate = old_bit_rate;
  mvwprintw(win, 1, 59, " %ikb/s", basic_info->bit_rate);
}