void test_notes_notes__creating_a_note_on_a_target_can_overwrite_existing_note(void) { git_oid note_oid, target_oid; git_note *note, *namespace_note; cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello old world\n"); cl_git_pass(git_note_create(¬e_oid, _repo, NULL, _sig, _sig, &target_oid, "hello new world\n", 1)); cl_git_pass(git_note_read(¬e, _repo, NULL, &target_oid)); assert_note_equal(note, "hello new world\n", ¬e_oid); create_note(¬e_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello old world\n"); cl_git_pass(git_note_create(¬e_oid, _repo, "refs/notes/some/namespace", _sig, _sig, &target_oid, "hello new ref world\n", 1)); cl_git_pass(git_note_read(&namespace_note, _repo, "refs/notes/some/namespace", &target_oid)); assert_note_equal(namespace_note, "hello new ref world\n", ¬e_oid); git_note_free(note); git_note_free(namespace_note); }
void test_notes_notes__can_create_a_note(void) { git_oid note_oid; static struct note_create_payload can_create_a_note[] = { { "1c9b1bc36730582a42d56eeee0dc58673d7ae869", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", 0 }, { NULL, NULL, 0 } }; create_note(¬e_oid, "refs/notes/i-can-see-dead-notes", can_create_a_note[0].object_oid, "I decorate 4a20\n"); cl_git_pass(git_note_foreach(_repo, "refs/notes/i-can-see-dead-notes", note_list_create_cb, &can_create_a_note)); assert_notes_seen(can_create_a_note, 1); }
void select_menu(){ // menu int menu; char command[1024]; printf("- Select Menu -\n"); printf("1. create note\n"); printf("2. write note\n"); printf("3. read note\n"); printf("4. delete note\n"); printf("5. exit\n"); scanf("%d", &menu); clear_newlines(); switch(menu){ case 1: create_note(); break; case 2: write_note(); break; case 3: read_note(); break; case 4: delete_note(); break;6 case 5: printf("bye\n"); return; case 0x31337: printf("welcome to hacker's secret menu\n"); printf("i'm sure 1byte overflow will be enough for you to pwn this\n"); fgets(command, 1025, stdin); break; default: printf("invalid menu\n"); break; } select_menu(); }
void test_notes_notes__can_insert_a_note_with_a_custom_namespace(void) { git_oid note_oid, target_oid; git_note *note; cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); create_note(¬e_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world on a custom namespace\n"); cl_git_pass(git_note_read(¬e, _repo, "refs/notes/some/namespace", &target_oid)); assert_note_equal(note, "hello world on a custom namespace\n", ¬e_oid); git_note_free(note); }
/* Test that we can read a note */ void test_notes_notes__can_read_a_note(void) { git_oid note_oid, target_oid; git_note *note; create_note(¬e_oid, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 4a20\n"); cl_git_pass(git_oid_fromstr(&target_oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); cl_git_pass(git_note_read(¬e, _repo, "refs/notes/i-can-see-dead-notes", &target_oid)); cl_assert_equal_s(git_note_message(note), "I decorate 4a20\n"); git_note_free(note); }
void test_notes_notes__inserting_a_note_without_passing_a_namespace_uses_the_default_namespace(void) { git_oid note_oid, target_oid; git_note *note, *default_namespace_note; const char *default_ref; cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); cl_git_pass(git_note_default_ref(&default_ref, _repo)); create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n"); cl_git_pass(git_note_read(¬e, _repo, NULL, &target_oid)); cl_git_pass(git_note_read(&default_namespace_note, _repo, default_ref, &target_oid)); assert_note_equal(note, "hello world\n", ¬e_oid); assert_note_equal(default_namespace_note, "hello world\n", ¬e_oid); git_note_free(note); git_note_free(default_namespace_note); }
void send_letter(player *p,char *str) { note *mail; char *subject,*scan,*first; int length; if (posted_count(p)>=p->max_mail) { tell_player(p,"Sorry, you have reached your mail limit.\n"); return; } subject=next_space(str); if (!*subject) { tell_player(p,"Format: post <character(s)> <subject>\n"); return; } *subject++=0; mail=create_note(); first=first_char(p); scan=strstr(first,"post"); if (scan && (scan!=first_char(p)) && (*(scan-1)=='a')) mail->flags |= ANONYMOUS; strcpy(mail->name,p->name); strncpy(mail->header,subject,MAX_TITLE-2); tell_player(p,"Enter main text of the letter...\n"); *stack=0; start_edit(p,MAX_ARTICLE_SIZE,end_mail,quit_mail,stack); if (p->edit_info) { p->edit_info->misc=(void *)mail; length=strlen(str)+1; mail->text.where=(char *)MALLOC(length); memcpy(mail->text.where,str,length); } else FREE(mail); }
void post_news(player *p,char *str) { note *article; char *scan,*first; if (!*str) { tell_player(p,"Format: post <header>\n"); return; } article=create_note(); strncpy(article->header,str,MAX_TITLE-2); article->flags |= NEWS_ARTICLE; first=first_char(p); scan=strstr(first,"post"); if (scan && (scan!=first_char(p)) && (*(scan-1)=='a')) article->flags |= ANONYMOUS; strcpy(article->name,p->name); tell_player(p,"Now enter the main body text for the article.\n"); *stack=0; start_edit(p,MAX_ARTICLE_SIZE,end_post,quit_post,stack); if (p->edit_info) p->edit_info->misc=(void *)article; else FREE(article); }
int main(int argc, char *argv[]) { int ret = 1, i; dldev_t dev; note_t db; u8 *data; u16 len; /* for data security */ /* umask(S_IRWXG | S_IRWXO); */ while((i = getopt(argc, argv, "hd:u:e:")) != -1){ switch(i){ case 'd': dev_file = optarg; break; case 'u': unused_recs = atoi(optarg); if(unused_recs < 0) unused_recs = 0; break; case 'e': extra_msg_len = atoi(optarg); if(extra_msg_len < 0) extra_msg_len = 0; break; case 'h': default: usage(); break; } } argc -= optind; argv += optind; set_note_unused_recs(unused_recs); set_note_extra_len(extra_msg_len); #ifdef USB_USBHID dev.usb.file = dev_file; #endif if(open_dev(&dev)){ ERROR("open_dev"); goto exit; } if(start_session(&dev)){ ERROR("read_app_info"); goto exit; } /******************************************************************************/ #ifdef DEBUG for(i = 0; i < NUM_APPS; i++){ if(!dev.app[i].acd.app_idx) continue; printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i, dev.app[i].acd.app_idx, dev.app[i].acd.code_loc, dev.app[i].acd.db_loc, dev.app[i].acd.code_invalid, dev.app[i].acd.db_modified, dev.app[i].acd.db_invalid, dev.app[i].acd.passwd_req, dev.app[i].acd.mode_name, dev.app[i].acb.app_type, dev.app[i].acb.app_inst, dev.app[i].acb.asd_addr, dev.app[i].acb.add_addr, dev.app[i].acb.state_mgr_addr, dev.app[i].acb.refresh_addr, dev.app[i].acb.banner_addr, dev.app[i].acb.code_addr, dev.app[i].banner ); } #endif /******************************************************************************/ if(read_note_mem(&dev, &db)){ ERROR("read_note_mem"); goto end; } create_note(&db, &data, &len); if(load_add(&dev, find_app(&dev, "NOTE"), data)){ ERROR("load_add"); goto end; } free(data); print_note(&db, stdout); free_note(&db); /******************************************************************************/ end: if(end_session(&dev)){ ERROR("end_session"); goto exit; } ret = 0; exit: close_dev(&dev); exit(ret); }
void reply_article(player *p,char *str) { note *mail,*old; char *indent,*body,*oldstack,*scan,*first; int length; oldstack=stack; if (!*str) { tell_player(p,"Format: reply <no>\n"); return; } if (posted_count(p)>=p->max_mail) { tell_player(p,"Sorry, you have reached your mail limit.\n"); return; } if (!p->saved) { tell_player(p,"Eeek, no saved bits.\n"); return; } old=find_news_article(atoi(str)); if (!old) { sprintf(stack,"Can't find letter '%s'\n",str); stack=end_string(stack); tell_player(p,oldstack); stack=oldstack; return; } mail=create_note(); first=first_char(p); scan=strstr(first,"reply"); if (scan && (scan!=first_char(p)) && (*(scan-1)=='a')) mail->flags |= ANONYMOUS; if (old->flags&ANONYMOUS) mail->flags |= SUPRESS_NAME; strcpy(mail->name,p->name); if (strstr(old->header,"Re: ")==old->header) strcpy(mail->header,old->header); else { sprintf(stack,"Re: %s",old->header); strncpy(mail->header,stack,MAX_TITLE-2); } indent=stack; get_string(stack,old->text.where); stack=end_string(stack); body=stack; sprintf(stack,"In your article '%s' you wrote ...\n",old->header); stack=strchr(stack,0); while(*indent) { *stack++='>'; *stack++=' '; while(*indent && *indent!='\n') *stack++=*indent++; *stack++='\n'; indent++; } *stack++='\n'; *stack++=0; tell_player(p,"Please trim letter as much as possible...\n"); start_edit(p,MAX_ARTICLE_SIZE,end_mail,quit_mail,body); if (p->edit_info) { p->edit_info->misc=(void *)mail; length=strlen(old->name)+1; mail->text.where=(char *)MALLOC(length); memcpy(mail->text.where,old->name,length); } else FREE(mail); stack=oldstack; }
static int append_edit(int argc, const char **argv, const char *prefix) { const char *object_ref; struct notes_tree *t; unsigned char object[20], new_note[20]; const unsigned char *note; char logmsg[100]; const char * const *usage; struct msg_arg msg = { 0, 0, STRBUF_INIT }; struct option options[] = { { OPTION_CALLBACK, 'm', "message", &msg, "MSG", "note contents as a string", PARSE_OPT_NONEG, parse_msg_arg}, { OPTION_CALLBACK, 'F', "file", &msg, "FILE", "note contents in a file", PARSE_OPT_NONEG, parse_file_arg}, { OPTION_CALLBACK, 'c', "reedit-message", &msg, "OBJECT", "reuse and edit specified note object", PARSE_OPT_NONEG, parse_reedit_arg}, { OPTION_CALLBACK, 'C', "reuse-message", &msg, "OBJECT", "reuse specified note object", PARSE_OPT_NONEG, parse_reuse_arg}, OPT_END() }; int edit = !strcmp(argv[0], "edit"); usage = edit ? git_notes_edit_usage : git_notes_append_usage; argc = parse_options(argc, argv, prefix, options, usage, PARSE_OPT_KEEP_ARGV0); if (2 < argc) { error("too many parameters"); usage_with_options(usage, options); } if (msg.given && edit) fprintf(stderr, "The -m/-F/-c/-C options have been deprecated " "for the 'edit' subcommand.\n" "Please use 'git notes add -f -m/-F/-c/-C' instead.\n"); object_ref = 1 < argc ? argv[1] : "HEAD"; if (get_sha1(object_ref, object)) die("Failed to resolve '%s' as a valid ref.", object_ref); t = init_notes_check(argv[0]); note = get_note(t, object); create_note(object, &msg, !edit, note, new_note); if (is_null_sha1(new_note)) remove_note(t, object); else add_note(t, object, new_note, combine_notes_overwrite); snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'", is_null_sha1(new_note) ? "removed" : "added", argv[0]); commit_notes(t, logmsg); free_notes(t); strbuf_release(&(msg.buf)); return 0; }
static int add(int argc, const char **argv, const char *prefix) { int retval = 0, force = 0; const char *object_ref; struct notes_tree *t; unsigned char object[20], new_note[20]; char logmsg[100]; const unsigned char *note; struct msg_arg msg = { 0, 0, STRBUF_INIT }; struct option options[] = { { OPTION_CALLBACK, 'm', "message", &msg, "MSG", "note contents as a string", PARSE_OPT_NONEG, parse_msg_arg}, { OPTION_CALLBACK, 'F', "file", &msg, "FILE", "note contents in a file", PARSE_OPT_NONEG, parse_file_arg}, { OPTION_CALLBACK, 'c', "reedit-message", &msg, "OBJECT", "reuse and edit specified note object", PARSE_OPT_NONEG, parse_reedit_arg}, { OPTION_CALLBACK, 'C', "reuse-message", &msg, "OBJECT", "reuse specified note object", PARSE_OPT_NONEG, parse_reuse_arg}, OPT_BOOLEAN('f', "force", &force, "replace existing notes"), OPT_END() }; argc = parse_options(argc, argv, prefix, options, git_notes_add_usage, 0); if (1 < argc) { error("too many parameters"); usage_with_options(git_notes_add_usage, options); } object_ref = argc ? argv[0] : "HEAD"; if (get_sha1(object_ref, object)) die("Failed to resolve '%s' as a valid ref.", object_ref); t = init_notes_check("add"); note = get_note(t, object); if (note) { if (!force) { retval = error("Cannot add notes. Found existing notes " "for object %s. Use '-f' to overwrite " "existing notes", sha1_to_hex(object)); goto out; } fprintf(stderr, "Overwriting existing notes for object %s\n", sha1_to_hex(object)); } create_note(object, &msg, 0, note, new_note); if (is_null_sha1(new_note)) remove_note(t, object); else add_note(t, object, new_note, combine_notes_overwrite); snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'", is_null_sha1(new_note) ? "removed" : "added", "add"); commit_notes(t, logmsg); out: free_notes(t); strbuf_release(&(msg.buf)); return retval; }
static int add(int argc, const char **argv, const char *prefix) { int retval = 0, force = 0; const char *object_ref; struct notes_tree *t; unsigned char object[20], new_note[20]; char logmsg[100]; const unsigned char *note; struct msg_arg msg = { 0, 0, STRBUF_INIT }; struct option options[] = { { OPTION_CALLBACK, 'm', "message", &msg, N_("message"), N_("note contents as a string"), PARSE_OPT_NONEG, parse_msg_arg}, { OPTION_CALLBACK, 'F', "file", &msg, N_("file"), N_("note contents in a file"), PARSE_OPT_NONEG, parse_file_arg}, { OPTION_CALLBACK, 'c', "reedit-message", &msg, N_("object"), N_("reuse and edit specified note object"), PARSE_OPT_NONEG, parse_reedit_arg}, { OPTION_CALLBACK, 'C', "reuse-message", &msg, N_("object"), N_("reuse specified note object"), PARSE_OPT_NONEG, parse_reuse_arg}, OPT__FORCE(&force, N_("replace existing notes")), OPT_END() }; argc = parse_options(argc, argv, prefix, options, git_notes_add_usage, PARSE_OPT_KEEP_ARGV0); if (2 < argc) { error(_("too many parameters")); usage_with_options(git_notes_add_usage, options); } object_ref = argc > 1 ? argv[1] : "HEAD"; if (get_sha1(object_ref, object)) die(_("Failed to resolve '%s' as a valid ref."), object_ref); t = init_notes_check("add"); note = get_note(t, object); if (note) { if (!force) { if (!msg.given) { /* * Redirect to "edit" subcommand. * * We only end up here if none of -m/-F/-c/-C * or -f are given. The original args are * therefore still in argv[0-1]. */ argv[0] = "edit"; free_notes(t); return append_edit(argc, argv, prefix); } retval = error(_("Cannot add notes. Found existing notes " "for object %s. Use '-f' to overwrite " "existing notes"), sha1_to_hex(object)); goto out; } fprintf(stderr, _("Overwriting existing notes for object %s\n"), sha1_to_hex(object)); } create_note(object, &msg, 0, note, new_note); if (is_null_sha1(new_note)) remove_note(t, object); else if (add_note(t, object, new_note, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'", is_null_sha1(new_note) ? "removed" : "added", "add"); commit_notes(t, logmsg); out: free_notes(t); strbuf_release(&(msg.buf)); return retval; }
int main (void) { short waveform[NUM_SAMPLES]; double frequency = 440.0; int octave = 1; int volume = 30000; int length = NUM_SAMPLES; char c; FILE * f = wavfile_open("music.wav"); while (c!='X') { c = receive_input(); switch (c) { default: printf("%d is not a valid input\n", c); break; case 'a': frequency = 415.30 * octave; create_note(volume, length, frequency, waveform, f); break; case 'A': frequency = 440.00 * octave; create_note(volume, length, frequency, waveform, f); break; case 'b': frequency = 466.16 * octave; create_note(volume, length, frequency, waveform, f); break; case 'B': frequency = 493.88 * octave; create_note(volume, length, frequency, waveform, f); break; case 'C': create_note(volume, length, frequency, waveform, f); frequency = 523.25 * octave; break; case 'd': frequency = 554.37 * octave; create_note(volume, length, frequency, waveform, f); break; case 'D': frequency = 587.33 * octave; create_note(volume, length, frequency, waveform, f); break; case 'e': frequency = 622.25 * octave; create_note(volume, length, frequency, waveform, f); break; case 'E': frequency = 659.26 * octave; create_note(volume, length, frequency, waveform, f); break; case 'F': frequency = 698.46 * octave; create_note(volume, length, frequency, waveform, f); break; case 'g': frequency = 739.99 * octave; create_note(volume, length, frequency, waveform, f); break; case 'G': frequency = 783.99 * octave; create_note(volume, length, frequency, waveform, f); break; case '.': frequency = 0; create_note(volume, length, frequency, waveform, f); break; case '+': octave*=2; break; case '-': octave/=2; break; case '1': length = NUM_SAMPLES; break; case '2': length = NUM_SAMPLES/2; break; case '4': length = NUM_SAMPLES/4; break; case '8': length = NUM_SAMPLES/8; break; case '6': length = NUM_SAMPLES/16; break; case 'X': wavfile_close(f); break; } } return 0; }
/*********************** Main **********************/ int main(int argc, char *argv[]) { setup_home(); int g = 0; int x = 0; int V = 0; int c = 0; int l = 0; int e = 0; int d = 0; int u = 0; int h = 0; int G = 0; int T = 0; int C = 0; int M = 0; int N = 0; char * group; char * label; char * content; int opt ; while((opt= getopt(argc,argv, "V(verbose)g:x(execute)c(create)l(list)e(echo):d(drop):u(edit):h(help)G(group):T(template):C(command)::M(macro)::N(note)::"))!= -1) { switch(opt) { case 'g': g=1; group = optarg; break; case 'V': V = 1; break; case 'x': x = 1; break; case 'c': c = 1; break; case 'l': l = 1; break; case 'e': e = 1; label = argv[optind]; break; case 'd': d = 1; label = argv[optind]; break; case 'u': u = 1; label = argv[optind]; break; case 'h': h = 1; break; case 'G': G = 1; label = argv[optind]; break; case 'T': T = 1; label = argv[optind]; break; case 'C': C = 1; label = argv[optind]; content = argv[optind+1]; break; case 'N': N = 1; label = argv[optind]; content = argv[optind+1]; break; default: puts("test"); break; } } if(g == 1) { if(c == 1) { if(G ==1) { create_group(label); //break; } else if(N == 1) { create_note(group, label, content); //break; } else if(C == 1) { create_command(label,group,content); //break; } else if(T == 1) { create_template_from_current(group,label); //break; } else { puts("Invalid Command"); return -1; } } if(e == 1) { if(N == 1) { echo_note(group,label); } else if( C == 1) { echo_command(label, group); } else if (T == 1) { echo_template(label, group); } } else if(l == 1) { if(N == 1) { list_notes(group); //break; } else if(C == 1) { list_commands(group); //break; } else if(T == 1) { list_templates(group); } else { puts("Invalid Command"); return -1; } } else if(x == 1) { if(C == 1) { execute_command(group,label); //break; } else if(T == 1) { execute_template(group,label); } else { puts("Invalid Command"); return -1; } } } else if(c == 1) { if(G == 1) { create_group(label); //break; } else { puts("Invalid Command"); return -1; } } else if(e == 1) { if(G == 1) { echo_group(label); } } return 0; }
void new_note_from_menu(GtkMenuItem *menuitem, ColorScheme *scheme) { create_note(NULL, scheme); }