Пример #1
0
/*
 * The caller makes sure there is no funny color before calling.
 * format_decorations_extended makes sure the same after return.
 */
void format_decorations_extended(struct strbuf *sb,
			const struct commit *commit,
			int use_color,
			const char *prefix,
			const char *separator,
			const char *suffix)
{
	const struct name_decoration *decoration;
	const struct name_decoration *current_and_HEAD;
	const char *color_commit =
		diff_get_color(use_color, DIFF_COMMIT);
	const char *color_reset =
		decorate_get_color(use_color, DECORATION_NONE);

	decoration = get_name_decoration(&commit->object);
	if (!decoration)
		return;

	current_and_HEAD = current_pointed_by_HEAD(decoration);
	while (decoration) {
		/*
		 * When both current and HEAD are there, only
		 * show HEAD->current where HEAD would have
		 * appeared, skipping the entry for current.
		 */
		if (decoration != current_and_HEAD) {
			strbuf_addstr(sb, color_commit);
			strbuf_addstr(sb, prefix);
			strbuf_addstr(sb, color_reset);
			strbuf_addstr(sb, decorate_get_color(use_color, decoration->type));
			if (decoration->type == DECORATION_REF_TAG)
				strbuf_addstr(sb, "tag: ");

			show_name(sb, decoration);

			if (current_and_HEAD &&
			    decoration->type == DECORATION_REF_HEAD) {
				strbuf_addstr(sb, color_reset);
				strbuf_addstr(sb, color_commit);
				strbuf_addstr(sb, " -> ");
				strbuf_addstr(sb, color_reset);
				strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type));
				show_name(sb, current_and_HEAD);
			}
			strbuf_addstr(sb, color_reset);

			prefix = separator;
		}
		decoration = decoration->next;
	}
	strbuf_addstr(sb, color_commit);
	strbuf_addstr(sb, suffix);
	strbuf_addstr(sb, color_reset);
}
Пример #2
0
int main(void) {
    int i;
    ptr = &my_array[0];     /* point our pointer to the first
                                      element of the array */
    printf("\n\n");
    for (i = 0; i < 6; i++) {
      printf("my_array[%d] = %d   ",i,my_array[i]);   /*<-- A */
      printf("ptr + %d = %d\n",i, *(ptr++));        /*<-- B */
    }

    // lets point our ptr2 to our person object
    ptr2 = &pers;

    // strcpy to assign string to struct attribute
    strcpy(pers.lname, "nsukami");
    strcpy(pers.fname, "patrick");
    pers.age = 42;

    // to access our struct directly
    printf("person: %s\n", pers.lname);

    // to access our struct using a ptr
    printf("person: %s\n", ptr2->fname);

    // pass the ptr2 to a function
    show_name(ptr2);

    return 0;
}
Пример #3
0
void Command::show_uint8(const Command *s, Stream & stream)
{
  uint8_t *ptr = (uint8_t *)s->value;
  if (ptr) {
    show_name(s, stream);
    stream.println(*ptr);
  }
}
void Command::show_uint32(const Command *s, Stream * stream)
{
  uint32_t *ptr = (uint32_t *)s->value;
  if (ptr) {
    show_name(s, stream);
    stream->println(*ptr);
  }
}
Пример #5
0
static void draw_settings_menu() {
    uint8_t x;

    for(x=0; x < NUM_LIVECTRL_CMDS; x++) {
        show_name(x);
        show_parameter(x);
    }
}
Пример #6
0
int main()
{
	struct tag * st_ptr;
	st_ptr = &my_struct;
	strcpy(my_struct.lname,"Jonny");
	strcpy(my_struct.fname,"David");
	printf("%s %s",my_struct.fname,my_struct.lname);
	my_struct.age = 23;
	show_name(st_ptr);
}
Пример #7
0
void Command::show_string(const Command *s, Stream & stream)
{
  char *ptr = (char *)s->value;
  show_name(s, stream);
  if (ptr) {
    stream.println(ptr);
  } else {
    stream.println();
  }
}
Пример #8
0
/* 程式 5.2 from PTRTUT10.HTM   6/13/97 */
#include <stdio.h>
#include <string.h>
struct tag{                     /* 結構型別 */
    char lname[20];             /* 姓 */
    char fname[20];             /* 名 */
    int age;                    /* 年齡 */
    float rate;                 /* 例如: 每小時 100 元 */
};
struct tag my_struct;           /* 結構定義 */
void show_name(struct tag *p);  /* 函式原型 */
int main(void)
{
    struct tag *st_ptr;         /* 指向結構的指標變數 */
    st_ptr = &my_struct;        /* 將指標指向 my_struct */
    strcpy(my_struct.lname,"Jensen");
    strcpy(my_struct.fname,"Ted");
    printf("\n%s ",my_struct.fname);
    printf("%s\n",my_struct.lname);
    my_struct.age = 63;
    show_name(st_ptr);          /* 輸入該指標 */
    return 0;
}
Пример #9
0
int main(void)
{
    tag_T *st_ptr;         /* a pointer to a structure */
    st_ptr = &my_struct;        /* point the pointer to my_struct */
    strcpy(st_ptr->lname,"Jensen");
    strcpy(st_ptr->fname,"Ted");
    printf("\n%s ",st_ptr->lname);
    printf("%s\n",st_ptr->fname);
    st_ptr->age = 63;
    show_name(st_ptr);          /* pass the pointer */
    return 0;
}
int main()
{
	struct tag *st_ptr;
	st_ptr = &my_struct;
	strcpy(my_struct.lname,"Jenson");
	strcpy(my_struct.fname,"Ted");
	printf("%s\n",my_struct.fname);
	printf("%s\n",my_struct.lname);
	my_struct.age = 63;
	printf("Calling function\n"); /* pass the pointer */
	show_name(st_ptr);
	return 0;
}
Пример #11
0
int main() {
  struct tag *st_ptr;
  st_ptr = &my_struct;

  strcpy(my_struct.lname, "Jones");
  strcpy(my_struct.fname, "Indiana");

  puts(my_struct.fname);
  puts(my_struct.lname);

  my_struct.age = 63;
  show_name(st_ptr);

  return 0;
}
Пример #12
0
void setup(){
	//Show name plate
	for(uint8_t i = 0; i < 5; i++){
		show_name(GRN_1); _delay_ms(100);
		show_name(GRN_2); _delay_ms(100);
		show_name(GRN_3); _delay_ms(100);
		show_name(RED_1 | GRN_3); _delay_ms(100);
		show_name(RED_2 | GRN_3); _delay_ms(100);
		show_name(RED_3 | GRN_3); _delay_ms(100);
		show_name(RED_3 | GRN_2); _delay_ms(100);
		show_name(RED_3 | GRN_1); _delay_ms(100);
		show_name(RED_3); _delay_ms(100);
		show_name(RED_2); _delay_ms(100);
		show_name(RED_1); _delay_ms(100);
		show_name(RED_2); _delay_ms(100);
		show_name(RED_3); _delay_ms(100);
		show_name(RED_3 | GRN_1); _delay_ms(100);
		show_name(RED_3 | GRN_2); _delay_ms(100);
		show_name(RED_3 | GRN_3); _delay_ms(100);
		show_name(RED_2 | GRN_3); _delay_ms(100);
		show_name(RED_1 | GRN_3); _delay_ms(100);
		show_name(GRN_3); _delay_ms(100);
		show_name(GRN_2); _delay_ms(100);
	}
	
	//Clear board
	clear_scratch();
	flush();
	matrix_write_buffer();
	_delay_ms(100);

	//Random start positions
	for (uint8_t x = 0; x < MATRIX_WIDTH; x++){
		for (uint8_t y = 0; y < MATRIX_HEIGHT; y++){
			if ((random() & 0x3) == 0x3){		//25% chance
				set_scratch(x, y, GRN_1);
			}
		}
	}
	
	for (uint8_t i = 0; i < RECENT_HASH_COUNT; i++){
		recent_hashes[i] = i;
	}
	
	flush();
	matrix_write_buffer();
}
Пример #13
0
Файл: grep.c Проект: sanj/git
static int grep_buffer_1(struct grep_opt *opt, const char *name,
			 char *buf, unsigned long size, int collect_hits)
{
	char *bol = buf;
	unsigned long left = size;
	unsigned lno = 1;
	unsigned last_hit = 0;
	int binary_match_only = 0;
	unsigned count = 0;
	int try_lookahead = 0;
	enum grep_context ctx = GREP_CONTEXT_HEAD;
	xdemitconf_t xecfg;

	opt->last_shown = 0;

	if (!opt->output)
		opt->output = std_output;

	if (buffer_is_binary(buf, size)) {
		switch (opt->binary) {
		case GREP_BINARY_DEFAULT:
			binary_match_only = 1;
			break;
		case GREP_BINARY_NOMATCH:
			return 0; /* Assume unmatch */
			break;
		default:
			break;
		}
	}

	memset(&xecfg, 0, sizeof(xecfg));
	if (opt->funcname && !opt->unmatch_name_only && !opt->status_only &&
	    !opt->name_only && !binary_match_only && !collect_hits) {
		struct userdiff_driver *drv = userdiff_find_by_path(name);
		if (drv && drv->funcname.pattern) {
			const struct userdiff_funcname *pe = &drv->funcname;
			xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
			opt->priv = &xecfg;
		}
	}
	try_lookahead = should_lookahead(opt);

	while (left) {
		char *eol, ch;
		int hit;

		/*
		 * look_ahead() skips quicly to the line that possibly
		 * has the next hit; don't call it if we need to do
		 * something more than just skipping the current line
		 * in response to an unmatch for the current line.  E.g.
		 * inside a post-context window, we will show the current
		 * line as a context around the previous hit when it
		 * doesn't hit.
		 */
		if (try_lookahead
		    && !(last_hit
			 && lno <= last_hit + opt->post_context)
		    && look_ahead(opt, &left, &lno, &bol))
			break;
		eol = end_of_line(bol, &left);
		ch = *eol;
		*eol = 0;

		if ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))
			ctx = GREP_CONTEXT_BODY;

		hit = match_line(opt, bol, eol, ctx, collect_hits);
		*eol = ch;

		if (collect_hits)
			goto next_line;

		/* "grep -v -e foo -e bla" should list lines
		 * that do not have either, so inversion should
		 * be done outside.
		 */
		if (opt->invert)
			hit = !hit;
		if (opt->unmatch_name_only) {
			if (hit)
				return 0;
			goto next_line;
		}
		if (hit) {
			count++;
			if (opt->status_only)
				return 1;
			if (binary_match_only) {
				opt->output(opt, "Binary file ", 12);
				output_color(opt, name, strlen(name),
					     opt->color_filename);
				opt->output(opt, " matches\n", 9);
				return 1;
			}
			if (opt->name_only) {
				show_name(opt, name);
				return 1;
			}
			/* Hit at this line.  If we haven't shown the
			 * pre-context lines, we would need to show them.
			 * When asked to do "count", this still show
			 * the context which is nonsense, but the user
			 * deserves to get that ;-).
			 */
			if (opt->pre_context)
				show_pre_context(opt, name, buf, bol, lno);
			else if (opt->funcname)
				show_funcname_line(opt, name, buf, bol, lno);
			if (!opt->count)
				show_line(opt, bol, eol, name, lno, ':');
			last_hit = lno;
		}
		else if (last_hit &&
			 lno <= last_hit + opt->post_context) {
			/* If the last hit is within the post context,
			 * we need to show this line.
			 */
			show_line(opt, bol, eol, name, lno, '-');
		}

	next_line:
		bol = eol + 1;
		if (!left)
			break;
		left--;
		lno++;
	}

	if (collect_hits)
		return 0;

	if (opt->status_only)
		return 0;
	if (opt->unmatch_name_only) {
		/* We did not see any hit, so we want to show this */
		show_name(opt, name);
		return 1;
	}

	xdiff_clear_find_func(&xecfg);
	opt->priv = NULL;

	/* NEEDSWORK:
	 * The real "grep -c foo *.c" gives many "bar.c:0" lines,
	 * which feels mostly useless but sometimes useful.  Maybe
	 * make it another option?  For now suppress them.
	 */
	if (opt->count && count) {
		char buf[32];
		output_color(opt, name, strlen(name), opt->color_filename);
		output_sep(opt, ':');
		snprintf(buf, sizeof(buf), "%u\n", count);
		opt->output(opt, buf, strlen(buf));
	}
	return !!last_hit;
}
Пример #14
0
int cmd_name_rev(int argc, const char **argv, const char *prefix)
{
	struct object_array revs = OBJECT_ARRAY_INIT;
	int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
	struct name_ref_data data = { 0, 0, NULL };
	struct option opts[] = {
		OPT_BOOL(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")),
		OPT_BOOL(0, "tags", &data.tags_only, N_("only use tags to name the commits")),
		OPT_STRING(0, "refs", &data.ref_filter, N_("pattern"),
				   N_("only use refs matching <pattern>")),
		OPT_GROUP(""),
		OPT_BOOL(0, "all", &all, N_("list all commits reachable from all refs")),
		OPT_BOOL(0, "stdin", &transform_stdin, N_("read from stdin")),
		OPT_BOOL(0, "undefined", &allow_undefined, N_("allow to print `undefined` names (default)")),
		OPT_BOOL(0, "always",     &always,
			   N_("show abbreviated commit object as fallback")),
		{
			/* A Hidden OPT_BOOL */
			OPTION_SET_INT, 0, "peel-tag", &peel_tag, NULL,
			N_("dereference tags in the input (internal use)"),
			PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1,
		},
		OPT_END(),
	};

	git_config(git_default_config, NULL);
	argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
	if (all + transform_stdin + !!argc > 1) {
		error("Specify either a list, or --all, not both!");
		usage_with_options(name_rev_usage, opts);
	}
	if (all || transform_stdin)
		cutoff = 0;

	for (; argc; argc--, argv++) {
		unsigned char sha1[20];
		struct object *object;
		struct commit *commit;

		if (get_sha1(*argv, sha1)) {
			fprintf(stderr, "Could not get sha1 for %s. Skipping.\n",
					*argv);
			continue;
		}

		commit = NULL;
		object = parse_object(sha1);
		if (object) {
			struct object *peeled = deref_tag(object, *argv, 0);
			if (peeled && peeled->type == OBJ_COMMIT)
				commit = (struct commit *)peeled;
		}

		if (!object) {
			fprintf(stderr, "Could not get object for %s. Skipping.\n",
					*argv);
			continue;
		}

		if (commit) {
			if (cutoff > commit->date)
				cutoff = commit->date;
		}

		if (peel_tag) {
			if (!commit) {
				fprintf(stderr, "Could not get commit for %s. Skipping.\n",
					*argv);
				continue;
			}
			object = (struct object *)commit;
		}
		add_object_array(object, *argv, &revs);
	}

	if (cutoff)
		cutoff = cutoff - CUTOFF_DATE_SLOP;
	for_each_ref(name_ref, &data);

	if (transform_stdin) {
		char buffer[2048];

		while (!feof(stdin)) {
			char *p = fgets(buffer, sizeof(buffer), stdin);
			if (!p)
				break;
			name_rev_line(p, &data);
		}
	} else if (all) {
		int i, max;

		max = get_max_object_index();
		for (i = 0; i < max; i++) {
			struct object *obj = get_indexed_object(i);
			if (!obj || obj->type != OBJ_COMMIT)
				continue;
			show_name(obj, NULL,
				  always, allow_undefined, data.name_only);
		}
	} else {
		int i;
		for (i = 0; i < revs.nr; i++)
			show_name(revs.objects[i].item, revs.objects[i].name,
				  always, allow_undefined, data.name_only);
	}

	return 0;
}
Пример #15
0
Файл: grep.c Проект: 2quala/git
static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int collect_hits)
{
	char *bol;
	unsigned long left;
	unsigned lno = 1;
	unsigned last_hit = 0;
	int binary_match_only = 0;
	unsigned count = 0;
	int try_lookahead = 0;
	int show_function = 0;
	struct userdiff_driver *textconv = NULL;
	enum grep_context ctx = GREP_CONTEXT_HEAD;
	xdemitconf_t xecfg;

	if (!opt->output)
		opt->output = std_output;

	if (opt->pre_context || opt->post_context || opt->file_break ||
	    opt->funcbody) {
		/* Show hunk marks, except for the first file. */
		if (opt->last_shown)
			opt->show_hunk_mark = 1;
		/*
		 * If we're using threads then we can't easily identify
		 * the first file.  Always put hunk marks in that case
		 * and skip the very first one later in work_done().
		 */
		if (opt->output != std_output)
			opt->show_hunk_mark = 1;
	}
	opt->last_shown = 0;

	if (opt->allow_textconv) {
		grep_source_load_driver(gs);
		/*
		 * We might set up the shared textconv cache data here, which
		 * is not thread-safe.
		 */
		grep_attr_lock();
		textconv = userdiff_get_textconv(gs->driver);
		grep_attr_unlock();
	}

	/*
	 * We know the result of a textconv is text, so we only have to care
	 * about binary handling if we are not using it.
	 */
	if (!textconv) {
		switch (opt->binary) {
		case GREP_BINARY_DEFAULT:
			if (grep_source_is_binary(gs))
				binary_match_only = 1;
			break;
		case GREP_BINARY_NOMATCH:
			if (grep_source_is_binary(gs))
				return 0; /* Assume unmatch */
			break;
		case GREP_BINARY_TEXT:
			break;
		default:
			die("bug: unknown binary handling mode");
		}
	}

	memset(&xecfg, 0, sizeof(xecfg));
	opt->priv = &xecfg;

	try_lookahead = should_lookahead(opt);

	if (fill_textconv_grep(textconv, gs) < 0)
		return 0;

	bol = gs->buf;
	left = gs->size;
	while (left) {
		char *eol, ch;
		int hit;

		/*
		 * look_ahead() skips quickly to the line that possibly
		 * has the next hit; don't call it if we need to do
		 * something more than just skipping the current line
		 * in response to an unmatch for the current line.  E.g.
		 * inside a post-context window, we will show the current
		 * line as a context around the previous hit when it
		 * doesn't hit.
		 */
		if (try_lookahead
		    && !(last_hit
			 && (show_function ||
			     lno <= last_hit + opt->post_context))
		    && look_ahead(opt, &left, &lno, &bol))
			break;
		eol = end_of_line(bol, &left);
		ch = *eol;
		*eol = 0;

		if ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))
			ctx = GREP_CONTEXT_BODY;

		hit = match_line(opt, bol, eol, ctx, collect_hits);
		*eol = ch;

		if (collect_hits)
			goto next_line;

		/* "grep -v -e foo -e bla" should list lines
		 * that do not have either, so inversion should
		 * be done outside.
		 */
		if (opt->invert)
			hit = !hit;
		if (opt->unmatch_name_only) {
			if (hit)
				return 0;
			goto next_line;
		}
		if (hit) {
			count++;
			if (opt->status_only)
				return 1;
			if (opt->name_only) {
				show_name(opt, gs->name);
				return 1;
			}
			if (opt->count)
				goto next_line;
			if (binary_match_only) {
				opt->output(opt, "Binary file ", 12);
				output_color(opt, gs->name, strlen(gs->name),
					     opt->color_filename);
				opt->output(opt, " matches\n", 9);
				return 1;
			}
			/* Hit at this line.  If we haven't shown the
			 * pre-context lines, we would need to show them.
			 */
			if (opt->pre_context || opt->funcbody)
				show_pre_context(opt, gs, bol, eol, lno);
			else if (opt->funcname)
				show_funcname_line(opt, gs, bol, lno);
			show_line(opt, bol, eol, gs->name, lno, ':');
			last_hit = lno;
			if (opt->funcbody)
				show_function = 1;
			goto next_line;
		}
		if (show_function && match_funcname(opt, gs, bol, eol))
			show_function = 0;
		if (show_function ||
		    (last_hit && lno <= last_hit + opt->post_context)) {
			/* If the last hit is within the post context,
			 * we need to show this line.
			 */
			show_line(opt, bol, eol, gs->name, lno, '-');
		}

	next_line:
		bol = eol + 1;
		if (!left)
			break;
		left--;
		lno++;
	}

	if (collect_hits)
		return 0;

	if (opt->status_only)
		return 0;
	if (opt->unmatch_name_only) {
		/* We did not see any hit, so we want to show this */
		show_name(opt, gs->name);
		return 1;
	}

	xdiff_clear_find_func(&xecfg);
	opt->priv = NULL;

	/* NEEDSWORK:
	 * The real "grep -c foo *.c" gives many "bar.c:0" lines,
	 * which feels mostly useless but sometimes useful.  Maybe
	 * make it another option?  For now suppress them.
	 */
	if (opt->count && count) {
		char buf[32];
		if (opt->pathname) {
			output_color(opt, gs->name, strlen(gs->name),
				     opt->color_filename);
			output_sep(opt, ':');
		}
		snprintf(buf, sizeof(buf), "%u\n", count);
		opt->output(opt, buf, strlen(buf));
		return 1;
	}
	return !!last_hit;
}
int main(void)
{
  
  //LCD_begin();

  UINT16 i=0,temporary1,temporary2,song_num=0,song_position=0,k,key,key2,key3,key4,sw[17],sw0,sw1,clupsec_num,data_sector;
  
  
  UINT16 back[2]={0},num_lyric,num_music,num_lyrics,time_base,j_base,base,fat_addr,cluster_num;

  UINT32 j;
  unsigned int cl[3000];
  BYTE Buffer[512]={0};
  
  while(SD_card_init())  // wait for the card to be inserted
    usleep(500000);
  LCD_begin();
  
  struct music0 music[30];
  struct lyric0 lyric[30];
  struct lyrics0 lyrics;
  
  char title[2][18]={" Press KEY1 to   ",
                      " select a song   "}; 
  char text[2][16]={"songs",
                    "lyrics"};
  char wait[16]="loading";
  
  file_list(music,lyric,&num_music,&num_lyric,&clupsec_num, &data_sector,&fat_addr); // search and update the database from the SD card
  sw1=IORD(SW_BASE,0);
  back[0]=sw1&0x20000;
  
  while(1)
  { 
    
    IOWR(SEG7_BASE,0,0);
    sw0=IORD(SW_BASE,0);
    sw0=sw0&0x07; 
    sw[0]=sw0&0x01;
    sw[1]=sw0&0x02;   
    sw[2]=sw0&0x04; 
    

    if(!sw0)
    {
      LCD_Init();   
      LCD_Show_Text(title[0]);
      lcd_write_command(LCD_BASE,0xC0);
      LCD_Show_Text(title[1]);
      while(1)
      {
        key=IORD(KEY_BASE,0);      // wait till key2 is pressed
        key2=~key&0x02;
        if(key2)
          break;
      }
      LCD_Init();
      lcd_write_command(LCD_BASE,0x80);
      usleep(100);  
      lcd_write_data(LCD_BASE,(char)(num_music/10+0x30));   // display the number of wav files
      usleep(100);  
      lcd_write_data(LCD_BASE,(char)(num_music%10+0x30));
      usleep(100);
      for(i=0;i<5;i++)
      {
        lcd_write_data(LCD_BASE,text[0][i]);
        usleep(100);
      }
      lcd_write_command(LCD_BASE,0xc0);
      usleep(100);  
      lcd_write_data(LCD_BASE,(char)(num_lyric/10+0x30));  // display the number of lysic files
      usleep(100);  
      lcd_write_data(LCD_BASE,(char)(num_lyric%10+0x30));
      usleep(100);
      for(i=0;i<6;i++)
      {
        lcd_write_data(LCD_BASE,text[1][i]);
         usleep(100);
      }
     usleep(1000000);
     
     while(1)
     {
        show_name(music[song_num].m_name);
        key=IORD(KEY_BASE,0);
        key=~key&0x0e; 
        if(key)
        {   
           key2=key&0x02;
           key3=key&0x04;
           key4=key&0x08;
           if(key2)
             break;
           else if(key3)
           {  
             song_num=(song_num+1)%num_music;           // next song
           }
           else if(key4)
           {
             song_num=(song_num+num_music-1)%num_music;  // previous song
           }
           else
           ;
        }
         time(0,song_num+1,num_music);    
     }
    }
    
    else if(sw[0])       {
      song_num=(song_num+1)%num_music;      // continuous 
      time(0,song_num+1,num_music); 
    }
    else if(sw[1])          {
      song_num+=0;
      time(0,song_num+1,num_music);        // repeat the song
    }
    else if(sw[2])
    {
      song_num=(num_lyrics+temporary1+temporary2+music[song_num].m_name[0])%num_music;  // random play
      time(0,song_num+1,num_music);   
    }    
    LCD_Init();    
    LCD_Show_Text(wait);
    num_lyrics=read_lyrics(music[song_num].m_name,lyric,&lyrics,num_lyric,&clupsec_num, &data_sector); //lyrics
    cl[0]=music[song_num].cluster;
    find_cluster(song_num,fat_addr,cl);
    for(i=0;cl[i]>1;i++);
    cluster_num=i;  
    
    show_name(music[song_num].m_name);   // show the name of the song
    for(song_position=0;song_position<cluster_num;song_position++)
    {  
      base=(cl[song_position]-2)*clupsec_num+data_sector;
      j_base=song_position*clupsec_num-base;
      sw1=IORD(SW_BASE,0);
      sw[4]=sw1&0x10;
      sw[5]=sw1&0x20; 
      sw[6]=sw1&0x40;
      
      back[1]=sw1&0x20000;
      if(back[1]!=back[0])
      {
        back[0]=back[1];
        break;
      } 
      if(sw[4])
      {
         song_position=(song_position+4)%cluster_num;
         time(song_position*clupsec_num,song_num+1,num_music);    // fast forward
         usleep(20000);
         continue;        
      }
      else if(sw[6])
      {
         song_position=(song_position+cluster_num-4)%cluster_num;
         time(song_position*clupsec_num,song_num+1,num_music);   // pause
         usleep(20000);
         continue;
      }    
      else if(sw[5])
      {
         song_position=(song_position+cluster_num-1)%cluster_num;  // reverse
         usleep(20000);
         continue;
      }   
      
      for(j=base;j<base+clupsec_num;j++) //j is the section in the cluster
      {      
        SD_read_lba(Buffer,j,1);    // read function from SD card controller.c
        i=0;
        while(i<512)
        {
          if(!IORD(AUDIO_BASE,0))
          {
            temporary1=((Buffer[i+1]<<8)|Buffer[i]);   // read from SD card
           
            IOWR(AUDIO_BASE,0,temporary1);
            
            i+=2;            
          }
        }

        if(j%32==0)
        {
            unsigned int x=0;
            unsigned int y=0xffff;
            unsigned int z = temporary1;
            do
            {
                x++;
                z=z<<1;
            }while((z & 0x8000)==0);
            y=y>>x;
            IOWR(LEDR_BASE,0,y);
            IOWR(LEDG_BASE,0,z);
        }
/********************************************************************/

        time(j+j_base,song_num+1,num_music); //display time

        for(k=0;k<num_lyrics;k++)            //display lyric
        {       
          time_base=j_base-lyrics.time[k]-2;       
          if(j+j_base==lyrics.time[k])   
          {    
            lcd_write_command(LCD_BASE,0x80);
            break;
          }
          else if(j+j_base==lyrics.time[k]+36)
          {
            lcd_write_command(LCD_BASE,0xc0);
            break;          
          }
          
          else if(j%2==0&&(j+j_base>=lyrics.time[k]+2)&&(j+j_base<=lyrics.time[k]+34))
          {
              lcd_write_data(LCD_BASE,lyrics.text[k][(j+time_base)/2]);
              break;             
          }          
          else if(j%2==0&&(j+j_base>=lyrics.time[k]+38)&&(j+j_base<lyrics.time[k]+70))
          {
              lcd_write_data(LCD_BASE,lyrics.text[k][(j+time_base)/2-2]);
              break;            
          }          
        }             
    }   
   }
  }
Пример #17
0
static int grep_buffer_1(struct grep_opt *opt, const char *name,
			 char *buf, unsigned long size, int collect_hits)
{
	char *bol = buf;
	unsigned long left = size;
	unsigned lno = 1;
	unsigned last_hit = 0;
	int binary_match_only = 0;
	unsigned count = 0;
	enum grep_context ctx = GREP_CONTEXT_HEAD;
	xdemitconf_t xecfg;

	opt->last_shown = 0;

	if (buffer_is_binary(buf, size)) {
		switch (opt->binary) {
		case GREP_BINARY_DEFAULT:
			binary_match_only = 1;
			break;
		case GREP_BINARY_NOMATCH:
			return 0; /* Assume unmatch */
			break;
		default:
			break;
		}
	}

	memset(&xecfg, 0, sizeof(xecfg));
	if (opt->funcname && !opt->unmatch_name_only && !opt->status_only &&
	    !opt->name_only && !binary_match_only && !collect_hits) {
		struct userdiff_driver *drv = userdiff_find_by_path(name);
		if (drv && drv->funcname.pattern) {
			const struct userdiff_funcname *pe = &drv->funcname;
			xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
			opt->priv = &xecfg;
		}
	}

	while (left) {
		char *eol, ch;
		int hit;

		eol = end_of_line(bol, &left);
		ch = *eol;
		*eol = 0;

		if ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))
			ctx = GREP_CONTEXT_BODY;

		hit = match_line(opt, bol, eol, ctx, collect_hits);
		*eol = ch;

		if (collect_hits)
			goto next_line;

		/* "grep -v -e foo -e bla" should list lines
		 * that do not have either, so inversion should
		 * be done outside.
		 */
		if (opt->invert)
			hit = !hit;
		if (opt->unmatch_name_only) {
			if (hit)
				return 0;
			goto next_line;
		}
		if (hit) {
			count++;
			if (opt->status_only)
				return 1;
			if (binary_match_only) {
				printf("Binary file %s matches\n", name);
				return 1;
			}
			if (opt->name_only) {
				show_name(opt, name);
				return 1;
			}
			/* Hit at this line.  If we haven't shown the
			 * pre-context lines, we would need to show them.
			 * When asked to do "count", this still show
			 * the context which is nonsense, but the user
			 * deserves to get that ;-).
			 */
			if (opt->pre_context)
				show_pre_context(opt, name, buf, bol, lno);
			else if (opt->funcname)
				show_funcname_line(opt, name, buf, bol, lno);
			if (!opt->count)
				show_line(opt, bol, eol, name, lno, ':');
			last_hit = lno;
		}
		else if (last_hit &&
			 lno <= last_hit + opt->post_context) {
			/* If the last hit is within the post context,
			 * we need to show this line.
			 */
			show_line(opt, bol, eol, name, lno, '-');
		}

	next_line:
		bol = eol + 1;
		if (!left)
			break;
		left--;
		lno++;
	}

	if (collect_hits)
		return 0;

	if (opt->status_only)
		return 0;
	if (opt->unmatch_name_only) {
		/* We did not see any hit, so we want to show this */
		show_name(opt, name);
		return 1;
	}

	xdiff_clear_find_func(&xecfg);
	opt->priv = NULL;

	/* NEEDSWORK:
	 * The real "grep -c foo *.c" gives many "bar.c:0" lines,
	 * which feels mostly useless but sometimes useful.  Maybe
	 * make it another option?  For now suppress them.
	 */
	if (opt->count && count)
		printf("%s%c%u\n", name,
		       opt->null_following_name ? '\0' : ':', count);
	return !!last_hit;
}
Пример #18
0
int cmd_name_rev(int argc, const char **argv, const char *prefix)
{
	struct object_array revs = { 0, 0, NULL };
	int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0;
	struct name_ref_data data = { 0, 0, NULL };
	struct option opts[] = {
		OPT_BOOLEAN(0, "name-only", &data.name_only, "print only names (no SHA-1)"),
		OPT_BOOLEAN(0, "tags", &data.tags_only, "only use tags to name the commits"),
		OPT_STRING(0, "refs", &data.ref_filter, "pattern",
				   "only use refs matching <pattern>"),
		OPT_GROUP(""),
		OPT_BOOLEAN(0, "all", &all, "list all commits reachable from all refs"),
		OPT_BOOLEAN(0, "stdin", &transform_stdin, "read from stdin"),
		OPT_BOOLEAN(0, "undefined", &allow_undefined, "allow to print `undefined` names"),
		OPT_BOOLEAN(0, "always",     &always,
			   "show abbreviated commit object as fallback"),
		OPT_END(),
	};

	git_config(git_default_config, NULL);
	argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
	if (!!all + !!transform_stdin + !!argc > 1) {
		error("Specify either a list, or --all, not both!");
		usage_with_options(name_rev_usage, opts);
	}
	if (all || transform_stdin)
		cutoff = 0;

	for (; argc; argc--, argv++) {
		unsigned char sha1[20];
		struct object *o;
		struct commit *commit;

		if (get_sha1(*argv, sha1)) {
			fprintf(stderr, "Could not get sha1 for %s. Skipping.\n",
					*argv);
			continue;
		}

		o = deref_tag(parse_object(sha1), *argv, 0);
		if (!o || o->type != OBJ_COMMIT) {
			fprintf(stderr, "Could not get commit for %s. Skipping.\n",
					*argv);
			continue;
		}

		commit = (struct commit *)o;
		if (cutoff > commit->date)
			cutoff = commit->date;
		add_object_array((struct object *)commit, *argv, &revs);
	}

	if (cutoff)
		cutoff = cutoff - CUTOFF_DATE_SLOP;
	for_each_ref(name_ref, &data);

	if (transform_stdin) {
		char buffer[2048];

		while (!feof(stdin)) {
			char *p = fgets(buffer, sizeof(buffer), stdin);
			if (!p)
				break;
			name_rev_line(p, &data);
		}
	} else if (all) {
		int i, max;

		max = get_max_object_index();
		for (i = 0; i < max; i++) {
			struct object *obj = get_indexed_object(i);
			if (!obj)
				continue;
			show_name(obj, NULL,
				  always, allow_undefined, data.name_only);
		}
	} else {
		int i;
		for (i = 0; i < revs.nr; i++)
			show_name(revs.objects[i].item, revs.objects[i].name,
				  always, allow_undefined, data.name_only);
	}

	return 0;
}
Пример #19
0
Файл: grep.c Проект: Inkdit/git
static int grep_buffer_1(struct grep_opt *opt, const char *name,
			 char *buf, unsigned long size, int collect_hits)
{
	char *bol = buf;
	unsigned long left = size;
	unsigned lno = 1;
	struct pre_context_line {
		char *bol;
		char *eol;
	} *prev = NULL, *pcl;
	unsigned last_hit = 0;
	unsigned last_shown = 0;
	int binary_match_only = 0;
	const char *hunk_mark = "";
	unsigned count = 0;
	enum grep_context ctx = GREP_CONTEXT_HEAD;

	if (buffer_is_binary(buf, size)) {
		switch (opt->binary) {
		case GREP_BINARY_DEFAULT:
			binary_match_only = 1;
			break;
		case GREP_BINARY_NOMATCH:
			return 0; /* Assume unmatch */
			break;
		default:
			break;
		}
	}

	if (opt->pre_context)
		prev = xcalloc(opt->pre_context, sizeof(*prev));
	if (opt->pre_context || opt->post_context)
		hunk_mark = "--\n";

	while (left) {
		char *eol, ch;
		int hit;

		eol = end_of_line(bol, &left);
		ch = *eol;
		*eol = 0;

		if ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))
			ctx = GREP_CONTEXT_BODY;

		hit = match_line(opt, bol, eol, ctx, collect_hits);
		*eol = ch;

		if (collect_hits)
			goto next_line;

		/* "grep -v -e foo -e bla" should list lines
		 * that do not have either, so inversion should
		 * be done outside.
		 */
		if (opt->invert)
			hit = !hit;
		if (opt->unmatch_name_only) {
			if (hit)
				return 0;
			goto next_line;
		}
		if (hit) {
			count++;
			if (opt->status_only)
				return 1;
			if (binary_match_only) {
				printf("Binary file %s matches\n", name);
				return 1;
			}
			if (opt->name_only) {
				show_name(opt, name);
				return 1;
			}
			/* Hit at this line.  If we haven't shown the
			 * pre-context lines, we would need to show them.
			 * When asked to do "count", this still show
			 * the context which is nonsense, but the user
			 * deserves to get that ;-).
			 */
			if (opt->pre_context) {
				unsigned from;
				if (opt->pre_context < lno)
					from = lno - opt->pre_context;
				else
					from = 1;
				if (from <= last_shown)
					from = last_shown + 1;
				if (last_shown && from != last_shown + 1)
					printf(hunk_mark);
				while (from < lno) {
					pcl = &prev[lno-from-1];
					show_line(opt, pcl->bol, pcl->eol,
						  name, from, '-');
					from++;
				}
				last_shown = lno-1;
			}
			if (last_shown && lno != last_shown + 1)
				printf(hunk_mark);
			if (!opt->count)
				show_line(opt, bol, eol, name, lno, ':');
			last_shown = last_hit = lno;
		}
		else if (last_hit &&
			 lno <= last_hit + opt->post_context) {
			/* If the last hit is within the post context,
			 * we need to show this line.
			 */
			if (last_shown && lno != last_shown + 1)
				printf(hunk_mark);
			show_line(opt, bol, eol, name, lno, '-');
			last_shown = lno;
		}
		if (opt->pre_context) {
			memmove(prev+1, prev,
				(opt->pre_context-1) * sizeof(*prev));
			prev->bol = bol;
			prev->eol = eol;
		}

	next_line:
		bol = eol + 1;
		if (!left)
			break;
		left--;
		lno++;
	}

	free(prev);
	if (collect_hits)
		return 0;

	if (opt->status_only)
		return 0;
	if (opt->unmatch_name_only) {
		/* We did not see any hit, so we want to show this */
		show_name(opt, name);
		return 1;
	}

	/* NEEDSWORK:
	 * The real "grep -c foo *.c" gives many "bar.c:0" lines,
	 * which feels mostly useless but sometimes useful.  Maybe
	 * make it another option?  For now suppress them.
	 */
	if (opt->count && count)
		printf("%s%c%u\n", name,
		       opt->null_following_name ? '\0' : ':', count);
	return !!last_hit;
}