Rename utils.c to printf-utils.c, remove unused functions

This commit is contained in:
Pali Rohár committed 2012-08-10 12:03:30 +02:00
1 parent ad68e324c6
commit 3ce8ca13f1
7 files changed
+63 -47

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
include ../config.mk
OBJ=main.o hexdump.o dump.o nolo.o qmode.o
OBJ+=utils.o console.o
OBJ+=printf-utils.o console.o
OBJ+=squeue/squeue.o
OBJ+=image.o fiasco.o device.o usb-device.o cold-flash.o
BIN=0xFFFF
+8 -4
View File
@@ -17,11 +17,15 @@
*/
#if HAVE_USB
#include "main.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include <unistd.h>
#include "nolo.h"
#include "dump.h"
void cmd_exit(char *line)
{
@@ -72,9 +76,9 @@ void cmd_nanddump(char *line)
(char *)&out, (int*)&ignbb, (int *)&ignoob);
if (ignoob == -1) {
eprintf("Invalid arguments.\n");
eprintf("nanddump [dev] [start] [len] [out] [ignore-badblocks] [ignore-oob]\n");
eprintf(" f.ex: nanddump /dev/mtd0 0x0 0x4000 xloader.bin 1 1\n");
fprintf(stderr, "Invalid arguments.\n");
fprintf(stderr, "nanddump [dev] [start] [len] [out] [ignore-badblocks] [ignore-oob]\n");
fprintf(stderr, " f.ex: nanddump /dev/mtd0 0x0 0x4000 xloader.bin 1 1\n");
} else
nanddump(dev, from, length, out, ignbb, ignoob);
}
+2 -1
View File
@@ -23,6 +23,7 @@
#include "dump.h"
#include "hexdump.h"
#include "printf-utils.h"
/*
* Extracts a piece from an mtd device
@@ -389,7 +390,7 @@ int nanddump(char *mtddev, unsigned long start_addr, unsigned long length, char
/* Write out page data */
//if (pretty_print) dump_bytes(readbuf, bs);
write(ofd, readbuf, bs);
progressbar(ofs, end_addr);
printf_progressbar(ofs, end_addr);
// OOB STUFF //
if (omitoob)
+3 -2
View File
@@ -25,6 +25,7 @@
#include "nolo.h"
#include "image.h"
#include "printf-utils.h"
#include "hexdump.h"
@@ -182,7 +183,7 @@ void nolo_flash_image(struct image * image)
// fclose(fd);
return;
}
progressbar(off, size);
printf_progressbar(off, size);
if (bread<0) {
printf("\n");
perror(" -ee- ");
@@ -194,7 +195,7 @@ void nolo_flash_image(struct image * image)
// fclose(fd);
/*/ EOF */
usb_bulk_write(dev, 2, (char *)nolofiller, 0, 1000);
progressbar(1, 1);
printf_progressbar(1, 1);
printf("\n");
// index = 4????
+15 -32
View File
@@ -1,6 +1,7 @@
/*
* 0xFFFF - Open Free Fiasco Firmware Flasher
* Copyright (C) 2007 pancake <pancake@youterm.com>
* Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,31 +17,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
unsigned long get_file_size(const char *file)
{
FILE *fd = fopen(file, "r");
unsigned long len = 0;
if (fd == NULL) {
fprintf(stderr, "Cannot open file '%s'\n", file);
exit(1);
}
fseek(fd, 0, SEEK_END);
len = ftell(fd);
fclose(fd);
return len;
}
#include "printf-utils.h"
void progressbar(unsigned long long part, unsigned long long total)
{
char *columns = getenv("COLUMNS");
int printf_prev = 0;
void printf_progressbar(unsigned long long part, unsigned long long total) {
char *columns = getenv("COLUMNS");
int pc;
int tmp, cols = 80;
int tmp, cols = 80;
/* percentage calculation */
pc = (int)(part*100/total);
@@ -53,24 +41,19 @@ void progressbar(unsigned long long part, unsigned long long total)
squeue_push2(p, "bar", msg, 0);
} else {
#endif
printf("\x1b[K %3d%% [", pc);
PRINTF_BACK();
PRINTF_ADD("\x1b[K %3d%% [", pc);
if (columns)
cols = atoi(columns);
if (cols > 115)
cols = 115;
cols-=15;
for(tmp=cols*pc/100;tmp;tmp--) printf("#");
for(tmp=cols-(cols*pc/100);tmp;tmp--) printf("-");
printf("]\r");
for(tmp=cols*pc/100;tmp;tmp--) PRINTF_ADD("#");
for(tmp=cols-(cols*pc/100);tmp;tmp--) PRINTF_ADD("-");
PRINTF_ADD("]");
fflush(stdout);
#if HAVE_SQUEUE
}
#endif
}
void eprintf(const char *format, ...)
{
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
//fflush(stderr); // XXX CRASH?!? stdin here?!?!?
}
+33
View File
@@ -0,0 +1,33 @@
/*
* 0xFFFF - Open Free Fiasco Firmware Flasher
* Copyright (C) 2007 pancake <pancake@youterm.com>
* Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PRINTF_UTILS_H
#define PRINTF_UTILS_H
extern int printf_prev;
#define PRINTF_BACK() do { if ( printf_prev ) { printf("\r%-*s\r", printf_prev, ""); printf_prev = 0; } } while (0)
#define PRINTF_ADD(...) do { printf_prev += printf(__VA_ARGS__); } while (0)
#define PRINTF_LINE(...) do { PRINTF_BACK(); PRINTF_ADD(__VA_ARGS__); fflush(stdout); } while (0)
#define PRINTF_END() do { if ( printf_prev ) { printf("\n"); printf_prev = 0; } } while (0)
#define PRINTF_ERROR(...) do { PRINTF_END(); ERROR_INFO(__VA_ARGS__); } while (0)
void printf_progressbar(unsigned long long part, unsigned long long total);
#endif
+1 -7
View File
@@ -28,13 +28,7 @@
#include "global.h"
#include "device.h"
#include "usb-device.h"
static int prev = 0;
#define PRINTF_BACK() do { if ( prev ) { printf("\r%-*s\r", prev, ""); prev = 0; } } while (0)
#define PRINTF_ADD(format, ...) do { prev += printf(format, ##__VA_ARGS__); } while (0)
#define PRINTF_LINE(format, ...) do { PRINTF_BACK(); PRINTF_ADD(format, ##__VA_ARGS__); fflush(stdout); } while (0)
#define PRINTF_END() do { if ( prev ) { printf("\n"); prev = 0; } } while (0)
#define PRINTF_ERROR(format, ...) do { PRINTF_END(); ERROR_INFO(format, ##__VA_ARGS__); } while (0)
#include "printf-utils.h"
static struct usb_flash_device usb_devices[] = {
{ 0x0421, 0x0105, 2, 1, -1, FLASH_NOLO, { DEVICE_SU_18, DEVICE_RX_44, DEVICE_RX_48, DEVICE_RX_51, 0 } },