Skip to content

Commit ec79a39

Browse files
committed
[romimg] implement filename transformation
1 parent c848b03 commit ec79a39

File tree

6 files changed

+40
-17
lines changed

6 files changed

+40
-17
lines changed

samples/Makefile.eeglobal_sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,6 @@ ifeq (_$(IOPRP_CONTENTS)_,__)
9898
$(error Cannot generate IOPRP if 'IOPRP_CONTENTS' variable is empty)
9999
else
100100
$(DIR_GUARD)
101-
romimg -c $@ $<
101+
romimg -C $@ $<
102102
endif
103103

tools/romimg/src/main.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string.h>
88
#include <sys/stat.h>
99
#include <unistd.h>
10+
#include <ctype.h>
1011

1112
#include "romimg.h"
1213

@@ -34,13 +35,15 @@ static void DisplayROMImgDetails(const ROMIMG *ROMImg)
3435

3536
static void DisplaySyntaxHelp(void)
3637
{
37-
printf(REDBOLD"Syntax error"DEFCOL". Syntax:\n"
38-
"ROMIMG -c <ROM image> <files>\n\tCreate ROM image\n"
38+
printf("Syntax:\n"
39+
"ROMIMG -c <ROM image> <files>\n\tCreate ROM image *\n"
3940
"ROMIMG -l <ROM image>\n\tList files in ROM image\n"
40-
"ROMIMG -a <ROM image> <file(s)>\n\tAdd file(s) to ROM image\n"
41+
"ROMIMG -a <ROM image> <file(s)>\n\tAdd file(s) to ROM image *\n"
4142
"ROMIMG -d <ROM image> <file(s)>\n\tDelete file(s) from ROM image\n"
4243
"ROMIMG -x <ROM image>\n\tExtract all files from ROM image\n"
43-
"ROMIMG -x <ROM image> <file>\n\tExtract file from ROM image\n");
44+
"ROMIMG -x <ROM image> <file>\n\tExtract file from ROM image\n"
45+
"\n note*: write the switch in uppercase to perform filename transformation (eg: 'ioman.irx' > 'IOMAN')\n"
46+
);
4447
}
4548

4649
static void DisplayAddDeleteOperationResult(int result, const char *InvolvedFile)
@@ -80,31 +83,30 @@ int main(int argc, char **argv)
8083

8184
if (argc < 2) {
8285
DisplaySyntaxHelp();
83-
DPRINTF("ERROR: LESS THAN TWO ARGS PROVIDED\n");
8486
return EINVAL;
8587
}
8688

87-
if (argc >= 4 && strcmp(argv[1], "-c") == 0) {
89+
if (argc >= 4 && strcasecmp(argv[1], "-c") == 0) {
8890
if ((result = CreateBlankROMImg(argv[2], &ROMImg)) == 0) {
8991
for (FilesAffected = 0, i = 0; i < argc - 3; i++) {
9092
printf("Adding file '%s'", argv[3 + i]);
91-
if ((result = AddFile(&ROMImg, argv[3 + i])) == 0)
93+
if ((result = AddFile(&ROMImg, argv[3 + i], isupper(argv[1][1]))) == 0)
9294
FilesAffected++;
9395
printf(result == 0 ? GRNBOLD" done!"DEFCOL"\n" : REDBOLD" failed!"DEFCOL"\n");
9496
}
9597

9698
if (FilesAffected > 0) {
97-
printf("Writing image...");
99+
printf("Writing image... ");
98100
printf("%s", (result = WriteROMImg(argv[2], &ROMImg)) == 0 ? GRNBOLD"done!"DEFCOL"\n" : REDBOLD"failed!"DEFCOL"\n");
99101
}
100102
UnloadROMImg(&ROMImg);
101103
} else
102104
ERROR("(Internal fault) Can't create blank image file: %d (%s). Please report.\n", result, strerror(result));
103-
} else if (argc >= 4 && strcmp(argv[1], "-a") == 0) {
105+
} else if (argc >= 4 && strcasecmp(argv[1], "-a") == 0) {
104106
if ((result = LoadROMImg(&ROMImg, argv[2])) == 0) {
105107
for (i = 0, FilesAffected = 0; i < argc - 3; i++) {
106108
printf("Adding file '%s'", argv[3 + i]);
107-
if ((result = AddFile(&ROMImg, argv[3 + i])) == 0)
109+
if ((result = AddFile(&ROMImg, argv[3 + i], isupper(argv[1][1]))) == 0)
108110
FilesAffected++;
109111
DisplayAddDeleteOperationResult(result, argv[3 + i]);
110112
}

tools/romimg/src/platform.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <errno.h>
66
#include <stdlib.h>
7+
#include <ctype.h>
78
#include "dprintf.h"
89
#if defined(_WIN32) || defined(WIN32)
910
#include <windows.h>
@@ -114,3 +115,12 @@ int GetCurrentWorkingDirectory(char *buffer, unsigned int BufferSize)
114115
return EIO;
115116
#endif
116117
}
118+
119+
void upperbuff(char *temp)
120+
{
121+
char *s = temp;
122+
while (*s) {
123+
*s = toupper((unsigned char) *s);
124+
s++;
125+
}
126+
}

tools/romimg/src/platform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ int GetLocalhostName(char *buffer, unsigned int BufferSize);
66
unsigned int GetSystemDate(void);
77
unsigned int GetFileCreationDate(const char *path);
88
int GetCurrentWorkingDirectory(char *buffer, unsigned int BufferSize);
9+
void upperbuff(char *temp);
910

1011
#if defined(_WIN32) || defined(WIN32)
1112
#define PATHSEP '\\'

tools/romimg/src/romimg.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "romimg.h"
1414
#include "SonyRX.h"
1515

16-
#define BUFCHK(X) (X[0] == '\0') ? "" : X
1716
#define IMAGE_COMMENT_BASESIZE 31
1817

1918
struct ROMImgStat
@@ -160,7 +159,7 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg)
160159
GetCurrentWorkingDirectory(cwd, sizeof(cwd));
161160
/* Comment format: YYYYMMDD-XXXYYY,conffile,<filename>,<user>@<localhost>/<image path> */
162161
CommentLength = IMAGE_COMMENT_BASESIZE + strlen(filename) + sizeof(LocalhostName) + sizeof(UserName) + MAX_PATH;
163-
ROMImg->comment = (char *)calloc(0, CommentLength+1);
162+
ROMImg->comment = (char *)malloc( CommentLength+1);
164163
if (!ROMImg->comment) return ENOMEM;
165164
snprintf(ROMImg->comment, CommentLength, "%08x,conffile,%s,%s@%s/%s", ROMImg->date, filename, BUFCHK(UserName), BUFCHK(LocalhostName), cwd);
166165

@@ -453,15 +452,26 @@ static int AddExtInfoStat(struct FileEntry *file, unsigned char type, void *data
453452
return result;
454453
}
455454

456-
int AddFile(ROMIMG *ROMImg, const char *path)
455+
int AddFile(ROMIMG *ROMImg, const char *path, int upperconv)
457456
{
457+
char tbuf[10] = "\0"; // we dont need a large buf, this is for filling in the filename on ROMFS
458458
FILE *InputFile;
459459
int result;
460460
unsigned int FileDateStamp;
461461
unsigned short FileVersion;
462462
if ((InputFile = fopen(path, "rb")) != NULL) {
463463
const char* fname = strrchr(path, PATHSEP);
464464
if (fname == NULL) fname = path; else fname++;
465+
if (upperconv) {
466+
strncpy(tbuf, fname, sizeof(tbuf));
467+
tbuf[sizeof(tbuf) - 1] = '\0';
468+
if (tbuf[0] != '\0') {
469+
upperbuff(tbuf);
470+
fname = tbuf;
471+
char* T = strrchr(fname, '.');
472+
if (T != NULL) *T = '\0'; //null terminate extension
473+
}
474+
}
465475
int size;
466476
fseek(InputFile, 0, SEEK_END);
467477
size = ftell(InputFile);
@@ -477,7 +487,7 @@ int AddFile(ROMIMG *ROMImg, const char *path)
477487
file = &ROMImg->files[ROMImg->NumFiles - 1];
478488
memset(&ROMImg->files[ROMImg->NumFiles - 1], 0, sizeof(struct FileEntry));
479489

480-
strncpy(file->RomDir.name, fname, sizeof(file->RomDir.name) - 1);
490+
strncpy(file->RomDir.name, fname, sizeof(file->RomDir.name));
481491
file->RomDir.name[sizeof(file->RomDir.name) - 1] = '\0';
482492
file->RomDir.ExtInfoEntrySize = 0;
483493

tools/romimg/src/romimg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg);
6868
int WriteROMImg(const char *file, const ROMIMG *ROMImg);
6969
int LoadROMImg(ROMIMG *ROMImg, const char *path);
7070
void UnloadROMImg(ROMIMG *ROMImg);
71-
int AddFile(ROMIMG *ROMImg, const char *path);
71+
int AddFile(ROMIMG *ROMImg, const char *path, int upperconv);
7272
int DeleteFile(ROMIMG *ROMImg, const char *filename);
7373
int ExtractFile(const ROMIMG *ROMImg, const char *filename, const char *FileToExtract);
7474
int IsFileExists(const ROMIMG *ROMImg, const char *filename);
7575

76-
#endif /* __ROMING_H__ */
76+
#endif /* __ROMING_H__ */

0 commit comments

Comments
 (0)