Основы программирования в Linux - Мэтью Нейл
На этом ресурсе Вы можете бесплатно читать книгу онлайн Основы программирования в Linux - Мэтью Нейл. Жанр: Программирование . На сайте e-Knigi.com Вы можете онлайн читать полную версию книги без регистрации и sms. Так же Вы можете ознакомится с содержанием, описанием, предисловием о произведении
item_found = search_cdc_entry(tmp_str, &firstcall); if (item_found.catalog[0] != ' ') { any_entry_found = 1; printf("n"); display_cdc(&item_found); if (get_confirm("This entry? ")) { entry_selected = 1; } } else { if (any_entry_found) printf("Sorry, no more matches foundn"); else printf("Sorry, nothing foundn"); break; } } return(item_found);}18. Функция
list_tracksstatic void list_tracks(const cdc_entry *entry_to_use) { int track_no = 1; cdt_entry entry_found; display_cdc(entry_to_use); printf("nTracksn"); do { entry_found = get_cdt_entry(entry_to_use->catalog, track_no); if (entry_found.catalog[0]) { display_cdt(&entry_found); track_no++; } } while(entry_found.catalog[0]); (void)get_confirm("Press return");} /* list_tracks */19. Функция
count_all_entriesstatic void count_all_entries(void) { int cd_entries_found = 0; int track_entries_found = 0; cdc_entry cdc_found; cdt_entry cdt_found; int track_no = 1; int first_time = 1; char *search_string = ""; do { cdc_found = search_cdc_entry(search_string, &first_time); if (cdc_found.catalog[0]) { cd_entries_found++; track_no = 1; do { cdt_found = get_cdt_entry(cdc_found.catalog, track_no); if (cdt_found.catalog[0]) { track_entries_found++; track_no++; } } while (cdt_found.catalog[0]); } } while (cdc_found.catalog[0]); printf("Found %d CDs, with a total of %d tracksn", cd_entries_found, track_entries_found); (void)get_confirm("Press return");}20. Теперь у вас есть утилита
display_cdcstatic void display_cdc(const cdc_entry *cdc_to_show) { printf("Catalog: %sn", cdc_to_show->catalog); printf("ttitle: %sn", cdc_to_show->title); printf("ttype: %sn", cdc_to_show->type); printf("tartist: %sn", cdc_to_show->artist);}и утилита
display_cdtstatic void display_cdt(const cdt_entry *cdt_to_show) { printf("%d: %sn", cdt_to_show->track_no, cdt_to_show->track_txt);}21. Служебная функция
strip_returnstatic void strip_return(char *string_to_strip) { int len; len = strlen(string_to_strip); if (string_to_strip[len - 1] == 'n') string_to_strip[len - 1] = ' ';}22. Функция
command_modegetoptstatic int command_mode(int argc, char *argv[]) { int c; int result = EXIT_SUCCESS; char *prog_name = argv[0]; /* Эти внешние переменные используются функцией getopt */ extern char *optarg; extern optind, opterr, optopt; while ((c = getopt(argc, argv, ":i")) != -1) { switch(c) { case 'i': if (!database_initialize(1)) { result = EXIT_FAILURE; fprintf(stderr, "Failed to initialize databasen"); } break; case ':':