int main(int argc, char *argv[]) { float curr; float full; for(int i = 0; i < argc; i++) {/* Arguments passed to the program will be parsed here. */ if(strcmp(argv[i], "-n") == 0) {/* Set the newline boolean. */ newline = false; continue; } if(strcmp(argv[i], "-b") == 0) {/* Set the colour boolean. */ colour = false; continue; } } read_float(PATH "charge_now", &curr); read_float(PATH "charge_full", &full); print_percentage( calculate_percentage(curr, full)); return EXIT_SUCCESS; }
int mem_info_update(struct mem_info_set *mem_info_set) { struct other_mem_data *other_data = (struct other_mem_data *)(mem_info_set->priv); FILE* file; unsigned long long mem_total, mem_free, swap_total, swap_free, cached_mem, buffer_mem, shmem, sreclaimable_mem; int count; file = fopen(MEMINFO_FILE, "r"); if (!file) return -1; count = fscanf(file, "MemTotal: %llu kB\n" /* MemTotal */ "MemFree: %llu kB\n" /* MemFree */ "Buffers: %llu kB\n" /* Buffers */ "Cached: %llu kB\n" /* Cached */ "%*[^\n]\n" /* Ignore */ "%*[^\n]\n" /* Ignore */ "%*[^\n]\n" /* Ignore */ "%*[^\n]\n" /* Ignore */ "%*[^\n]\n" /* Ignore */ "%*[^\n]\n" /* Ignore */ "%*[^\n]\n" /* Ignore */ "%*[^\n]\n" /* Ignore */ "%*[^\n]\n" /* Ignore */ "SwapTotal: %llu kB\n" /* SwapTotal */ "SwapFree: %llu kB\n" /* SwapFree */ "%*[^\n]\n" /* Ignore */ "%*[^\n]\n" /* Ignore */ "%*[^\n]\n" /* Ignore */ "%*[^\n]\n" /* Ignore */ "Shmem: %llu kB\n" /* Shmem */ "%*[^\n]\n" /* Ignore */ "SReclaimable: %llu kB\n" /* SReclaimable */ , /* Ignore the rest */ &mem_total, &mem_free, &buffer_mem, &cached_mem, &swap_total, &swap_free, &shmem, &sreclaimable_mem); /* Close file */ fclose(file); if (count != 8) return -1; /* Update latest value */ mem_info_set->mem_info.mem_total = mem_total; mem_info_set->mem_info.mem_free = mem_free + cached_mem + buffer_mem + sreclaimable_mem - shmem; mem_info_set->mem_info.mem_used = mem_total - mem_info_set->mem_info.mem_free; mem_info_set->mem_info.swap_total = swap_total; mem_info_set->mem_info.swap_free = swap_free; mem_info_set->mem_info.swap_used = swap_total - swap_free; other_data->buffer = buffer_mem; other_data->cache = cached_mem; calculate_percentage(mem_info_set); return 0; }