Skip to content

Commit

Permalink
mtd-utils: standardize PROGRAM_NAME
Browse files Browse the repository at this point in the history
Make sure all the utils define PROGRAM_NAME and do so at the start of
the file so that sub-headers may assume it exists.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
  • Loading branch information
vapier authored and Artem Bityutskiy committed Sep 27, 2010
1 parent 6edaa0c commit e960f7e
Show file tree
Hide file tree
Showing 44 changed files with 182 additions and 135 deletions.
2 changes: 2 additions & 0 deletions compr_zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
* under either the RHEPL or the GPL.
*/

#define PROGRAM_NAME "compr_zlib"

#include <stdint.h>
#define crc32 __zlib_crc32
#include <zlib.h>
Expand Down
2 changes: 2 additions & 0 deletions doc_loadbios.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define PROGRAM_NAME "doc_loadbios"

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down
4 changes: 3 additions & 1 deletion docfdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#define PROGRAM_NAME "docfdisk"

#define _XOPEN_SOURCE 500 /* for pread/pwrite */
#include <unistd.h>
#include <stdlib.h>
Expand Down Expand Up @@ -158,7 +160,7 @@ int main(int argc, char **argv)
"Usage: %s <mtddevice> [<size1> [<size2> [<size3> [<size4]]]]\n"
" Sizes are in device units (run with no sizes to show unitsize and current\n"
" partitions). Last size = 0 means go to end of device.\n",
argv[0]);
PROGRAM_NAME);
return 1;
}

Expand Down
4 changes: 3 additions & 1 deletion flash_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* flash_info.c -- print info about a MTD device
*/

#define PROGRAM_NAME "flash_info"

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
Expand All @@ -19,7 +21,7 @@ int main(int argc,char *argv[])

if (1 >= argc)
{
fprintf(stderr,"Usage: flash_info device\n");
fprintf(stderr,"Usage: %s device\n", PROGRAM_NAME);
return 16;
}

Expand Down
4 changes: 3 additions & 1 deletion flash_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*
*/

#define PROGRAM_NAME "flash_lock"

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
Expand All @@ -29,7 +31,7 @@ int main(int argc, char *argv[])
*/
if(argc != 4)
{
fprintf(stderr, "USAGE: %s <mtd device> <ofs in hex> <num of sectors in decimal or -1 for all sectors>\n", argv[0]);
fprintf(stderr, "USAGE: %s <mtd device> <ofs in hex> <num of sectors in decimal or -1 for all sectors>\n", PROGRAM_NAME);
exit(1);
}
else if(strncmp(argv[1], "/dev/mtd", 8) != 0)
Expand Down
4 changes: 3 additions & 1 deletion flash_otp_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* flash_otp_dump.c -- display One-Time-Programm data
*/

#define PROGRAM_NAME "flash_otp_dump"

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
Expand All @@ -17,7 +19,7 @@ int main(int argc,char *argv[])
unsigned char buf[16];

if (argc != 3 || (strcmp(argv[1], "-f") && strcmp(argv[1], "-u"))) {
fprintf(stderr,"Usage: %s [ -f | -u ] <device>\n", argv[0]);
fprintf(stderr,"Usage: %s [ -f | -u ] <device>\n", PROGRAM_NAME);
return EINVAL;
}

Expand Down
4 changes: 3 additions & 1 deletion flash_otp_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* flash_otp_info.c -- print info about One-Time-Programm data
*/

#define PROGRAM_NAME "flash_otp_info"

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
Expand All @@ -16,7 +18,7 @@ int main(int argc,char *argv[])
int fd, val, i, ret;

if (argc != 3 || (strcmp(argv[1], "-f") && strcmp(argv[1], "-u"))) {
fprintf(stderr,"Usage: %s [ -f | -u ] <device>\n", argv[0]);
fprintf(stderr,"Usage: %s [ -f | -u ] <device>\n", PROGRAM_NAME);
return EINVAL;
}

Expand Down
8 changes: 5 additions & 3 deletions flash_otp_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* flash_otp_lock.c -- lock area of One-Time-Program data
*/

#define PROGRAM_NAME "flash_otp_lock"

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
Expand All @@ -18,7 +20,7 @@ int main(int argc,char *argv[])
char *p, buf[8];

if (argc != 5 || strcmp(argv[1], "-u")) {
fprintf(stderr, "Usage: %s -u <device> <offset> <size>\n", argv[0]);
fprintf(stderr, "Usage: %s -u <device> <offset> <size>\n", PROGRAM_NAME);
fprintf(stderr, "offset and size must match on OTP region boundaries\n");
fprintf(stderr, "CAUTION! ONCE LOCKED, OTP REGIONS CAN'T BE UNLOCKED!\n");
return EINVAL;
Expand All @@ -39,13 +41,13 @@ int main(int argc,char *argv[])

offset = strtoul(argv[3], &p, 0);
if (argv[3][0] == 0 || *p != 0) {
fprintf(stderr, "%s: bad offset value\n", argv[0]);
fprintf(stderr, "%s: bad offset value\n", PROGRAM_NAME);
return ERANGE;
}

size = strtoul(argv[4], &p, 0);
if (argv[4][0] == 0 || *p != 0) {
fprintf(stderr, "%s: bad size value\n", argv[0]);
fprintf(stderr, "%s: bad size value\n", PROGRAM_NAME);
return ERANGE;
}

Expand Down
6 changes: 4 additions & 2 deletions flash_otp_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* flash_otp_write.c -- write One-Time-Program data
*/

#define PROGRAM_NAME "flash_otp_write"

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
Expand All @@ -21,7 +23,7 @@ int main(int argc,char *argv[])
char *p, buf[2048];

if (argc != 4 || strcmp(argv[1], "-u")) {
fprintf(stderr, "Usage: %s -u <device> <offset>\n", argv[0]);
fprintf(stderr, "Usage: %s -u <device> <offset>\n", PROGRAM_NAME);
fprintf(stderr, "the raw data to write should be provided on stdin\n");
fprintf(stderr, "CAUTION! ONCE SET TO 0, OTP DATA BITS CAN'T BE ERASED!\n");
return EINVAL;
Expand All @@ -47,7 +49,7 @@ int main(int argc,char *argv[])

offset = strtoul(argv[3], &p, 0);
if (argv[3][0] == 0 || *p != 0) {
fprintf(stderr, "%s: bad offset value\n", argv[0]);
fprintf(stderr, "%s: bad offset value\n", PROGRAM_NAME);
return ERANGE;
}

Expand Down
4 changes: 3 additions & 1 deletion flash_unlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*
*/

#define PROGRAM_NAME "flash_unlock"

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
Expand All @@ -28,7 +30,7 @@ int main(int argc, char *argv[])
*/
if(argc < 2)
{
fprintf(stderr, "USAGE: %s <mtd device> <offset in hex> <block count in decimal number>\n", argv[0]);
fprintf(stderr, "USAGE: %s <mtd device> <offset in hex> <block count in decimal number>\n", PROGRAM_NAME);
exit(1);
}
else if(strncmp(argv[1], "/dev/mtd", 8) != 0)
Expand Down
20 changes: 10 additions & 10 deletions flashcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#define PROGRAM_NAME "flashcp"

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
Expand Down Expand Up @@ -84,23 +86,23 @@ static void log_printf (int level,const char *fmt, ...)
fflush (fp);
}

static void showusage (const char *progname,bool error)
static void showusage(bool error)
{
int level = error ? LOG_ERROR : LOG_NORMAL;

log_printf (level,
"\n"
"Flash Copy - Written by Abraham van der Merwe <abraham@2d3d.co.za>\n"
"\n"
"usage: %s [ -v | --verbose ] <filename> <device>\n"
" %s -h | --help\n"
"usage: %1$s [ -v | --verbose ] <filename> <device>\n"
" %1$s -h | --help\n"
"\n"
" -h | --help Show this help message\n"
" -v | --verbose Show progress reports\n"
" <filename> File which you want to copy to flash\n"
" <device> Flash device to write to (e.g. /dev/mtd0, /dev/mtd1, etc.)\n"
"\n",
progname,progname);
PROGRAM_NAME);

exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
}
Expand Down Expand Up @@ -165,7 +167,7 @@ static void cleanup (void)

int main (int argc,char *argv[])
{
const char *progname,*filename = NULL,*device = NULL;
const char *filename = NULL,*device = NULL;
int i,flags = FLAG_NONE;
ssize_t result;
size_t size,written;
Expand All @@ -174,8 +176,6 @@ int main (int argc,char *argv[])
struct stat filestat;
unsigned char src[BUFSIZE],dest[BUFSIZE];

(progname = strrchr (argv[0],'/')) ? progname++ : (progname = argv[0]);

/*********************
* parse cmd-line
*****************/
Expand Down Expand Up @@ -206,7 +206,7 @@ int main (int argc,char *argv[])
break;
default:
DEBUG("Unknown parameter: %s\n",argv[option_index]);
showusage (progname,true);
showusage(true);
}
}
if (optind+2 == argc) {
Expand All @@ -219,8 +219,8 @@ int main (int argc,char *argv[])
DEBUG("Got device: %s\n",device);
}

if (flags & FLAG_HELP || progname == NULL || device == NULL)
showusage (progname,flags != FLAG_HELP);
if (flags & FLAG_HELP || device == NULL)
showusage(flags != FLAG_HELP);

atexit (cleanup);

Expand Down
8 changes: 5 additions & 3 deletions ftl_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
======================================================================*/

#define PROGRAM_NAME "ftl_check"

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -178,9 +180,9 @@ static void check_partition(int fd)
} /* format_partition */

/* Show usage information */
void showusage(char *pname)
void showusage(void)
{
fprintf(stderr, "usage: %s device\n", pname);
fprintf(stderr, "usage: %s device\n", PROGRAM_NAME);
}

/*====================================================================*/
Expand All @@ -200,7 +202,7 @@ int main(int argc, char *argv[])
}
}
if (errflg || (optind != argc-1)) {
showusage(argv[0]);
showusage();
exit(errflg > 0 ? 0 : EXIT_FAILURE);
}

Expand Down
4 changes: 3 additions & 1 deletion ftl_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
======================================================================*/

#define PROGRAM_NAME "ftl_format"

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -308,7 +310,7 @@ int main(int argc, char *argv[])
}
if (errflg || (optind != argc-1)) {
fprintf(stderr, "usage: %s [-q] [-i] [-s spare-blocks]"
" [-r reserve-percent] [-b bootsize] device\n", argv[0]);
" [-r reserve-percent] [-b bootsize] device\n", PROGRAM_NAME);
exit(EXIT_FAILURE);
}

Expand Down
20 changes: 11 additions & 9 deletions jffs2dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* Bug/ToDo:
*/

#define PROGRAM_NAME "jffs2dump"
#define VERSION "$Revision: 1.10 $"

#include <errno.h>
#include <stdint.h>
#include <stdio.h>
Expand All @@ -34,9 +37,6 @@
#include <crc32.h>
#include "summary.h"

#define PROGRAM "jffs2dump"
#define VERSION "$Revision: 1.10 $"

#define PAD(x) (((x)+3)&~3)

/* For outputting a byte-swapped version of the input image. */
Expand All @@ -52,7 +52,7 @@ char *data; // image data

void display_help (void)
{
printf("Usage: " PROGRAM " [OPTION]... INPUTFILE\n"
printf("Usage: %s [OPTION]... INPUTFILE\n"
"Dump the contents of a binary JFFS2 image.\n\n"
" --help display this help and exit\n"
" --version display version information and exit\n"
Expand All @@ -63,22 +63,24 @@ void display_help (void)
" -r, --recalccrc recalc name and data crc on endian conversion\n"
" -d, --datsize=LEN size of data chunks, when oob data in binary image (NAND only)\n"
" -o, --oobsize=LEN size of oob data chunk in binary image (NAND only)\n"
" -v, --verbose verbose output\n");
" -v, --verbose verbose output\n",
PROGRAM_NAME);
exit(0);
}

void display_version (void)
{
printf(PROGRAM " " VERSION "\n"
printf("%1$s " VERSION "\n"
"\n"
"Copyright (C) 2003 Thomas Gleixner \n"
"\n"
PROGRAM " comes with NO WARRANTY\n"
"%1$s comes with NO WARRANTY\n"
"to the extent permitted by law.\n"
"\n"
"You may redistribute copies of " PROGRAM "\n"
"You may redistribute copies of %1$s\n"
"under the terms of the GNU General Public Licence.\n"
"See the file `COPYING' for more information.\n");
"See the file `COPYING' for more information.\n",
PROGRAM_NAME);
exit(0);
}

Expand Down
8 changes: 5 additions & 3 deletions jffs2reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
- Doesn't check CRC checksums.
*/

#define PROGRAM_NAME "jffs2reader"

#include <errno.h>
#include <stdint.h>
Expand Down Expand Up @@ -817,8 +818,8 @@ void lsdir(char *o, size_t size, char *path, int recurse)

if (ino == 0 ||
(dd == NULL && ino == 0) || (dd != NULL && dd->type != DT_DIR)) {
fprintf(stderr, "jffs2reader: %s: No such file or directory\n",
path);
fprintf(stderr, "%s: %s: No such file or directory\n",
PROGRAM_NAME, path);
exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -888,7 +889,8 @@ int main(int argc, char **argv)
break;
default:
fprintf(stderr,
"Usage: jffs2reader <image> [-d|-f] < path > \n");
"Usage: %s <image> [-d|-f] < path >\n",
PROGRAM_NAME);
exit(EXIT_FAILURE);
}
}
Expand Down
Loading

0 comments on commit e960f7e

Please sign in to comment.