/* Read a melody line from the input file. Uses the getchr and nd_getchr * routines from input.c. Assumes it is called just after the opening "{" * has been read, and returns just after having read the closing "}". */ MelodyLine *readML(void) { MelodyLine *ml = mmalloc (sizeof(MelodyLine)); /* Initialise the structure. */ ml->stems_force = 0; ml->head = ml->tail = NULL; ml->beam = NULL; ml->slur = NULL; ml->lyrics = NULL; /* Begin to read. */ while (1) { switch (nd_gc()) { case '[': case ']': case '/': case '\\': case '<': case '"': case '(': case ')': case 'Z': /* It's a stream control. */ read_stream_control (ml); continue; case '}': /* End of melody line */ gc(); break; default: /* It's a note */ read_note (ml); continue; } break; } return ml; }
/* * Load boards file. */ void load_boards( void ) { FILE *board_fp = NULL; BOARD_DATA *board = NULL; char boardfile[256]; sprintf( boardfile, "%s%s", BOARD_DIR, BOARD_FILE ); if( ( board_fp = fopen( boardfile, "r" ) ) == NULL ) return; while( ( board = read_board( boardfile, board_fp ) ) != NULL ) { char notefile[256]; FILE *note_fp = NULL; LINK( board, first_board, last_board, next, prev ); sprintf( notefile, "%s%s", BOARD_DIR, board->note_file ); if( ( note_fp = fopen( notefile, "r" ) ) != NULL ) { NOTE_DATA *pnote = NULL; while( ( pnote = read_note( notefile, note_fp ) ) != NULL ) { LINK( pnote, board->first_note, board->last_note, next, prev ); board->num_posts++; } } } }
void play_file(FILE * infp, FILE * outfp) { struct note note; int linenum = 0, n; const size_t bufsiz = 1024; char buf[bufsiz]; char *s, *p; while (fgets(buf, bufsiz, infp) != NULL) { ++linenum; s = skip_space(buf); if (*s == '\0') { if (dflag) printf("BLANK LINE\n"); continue; } if (*s == '#') { if (dflag) printf("COMMENT\n"); continue; } if (starts_with(buf, "octave")) { if ((p = strchr(s, ' ')) == NULL && (p = strchr(s, '\t')) == NULL) { syntax_error(linenum, "'octave' directive with no operand"); exit(1); } else { octave = atoi(p); if (!IS_VALID_OCTAVE(octave)) { syntax_error(linenum, "octave must be between %i and %i", MIN_OCTAVE, MAX_OCTAVE); exit(1); } if (dflag) printf("OCTAVE: %i\n", octave); } continue; } if (starts_with(buf, "baseoctave")) { if ((p = strchr(s, ' ')) == NULL && (p = strchr(s, '\t')) == NULL) { syntax_error(linenum, "'baseoctave' directive with no operand"); exit(1); } else { baseoctave = atoi(p); if (dflag) printf("BASEOCTAVE: %i\n", baseoctave); } continue; } note = read_note(s, linenum); if (outfp) fwrite(¬e, sizeof(struct note), 1, outfp); else play_note(note); } }
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(); }