Skip to content

Commit

Permalink
gdtool: better command line, stdin lists, cleanup
Browse files Browse the repository at this point in the history
Also, imgread const filenames and such
  • Loading branch information
skmp committed Jun 13, 2014
1 parent 2bd1c4c commit d59197f
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 123 deletions.
2 changes: 1 addition & 1 deletion core/imgread/cdi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "deps/chdpsr/cdipsr.h"

Disc* cdi_parse(wchar* file)
Disc* cdi_parse(const wchar* file)
{
FILE* fsource=fopen(file,"rb");

Expand Down
6 changes: 3 additions & 3 deletions core/imgread/chd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CHDDisc : Disc
hunk_mem=0;
}

bool TryOpen(wchar* file);
bool TryOpen(const wchar* file);

~CHDDisc()
{
Expand Down Expand Up @@ -64,7 +64,7 @@ struct CHDTrack : TrackFile
}
};

bool CHDDisc::TryOpen(wchar* file)
bool CHDDisc::TryOpen(const wchar* file)
{
chd_error err=chd_open(file,CHD_OPEN_READ,0,&chd);

Expand Down Expand Up @@ -153,7 +153,7 @@ bool CHDDisc::TryOpen(wchar* file)
}


Disc* chd_parse(wchar* file)
Disc* chd_parse(const wchar* file)
{
CHDDisc* rv = new CHDDisc();

Expand Down
12 changes: 6 additions & 6 deletions core/imgread/common.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "common.h"

Disc* chd_parse(wchar* file);
Disc* gdi_parse(wchar* file);
Disc* cdi_parse(wchar* file);
Disc* chd_parse(const wchar* file);
Disc* gdi_parse(const wchar* file);
Disc* cdi_parse(const wchar* file);
#if HOST_OS==OS_WINDOWS
Disc* ioctl_parse(wchar* file);
Disc* ioctl_parse(const wchar* file);
#endif

u32 NullDriveDiscType;
Disc* disc;

Disc*(*drivers[])(wchar* path)=
Disc*(*drivers[])(const wchar* path)=
{
chd_parse,
gdi_parse,
Expand Down Expand Up @@ -129,7 +129,7 @@ bool ConvertSector(u8* in_buff , u8* out_buff , int from , int to,int sector)
return true;
}

Disc* OpenDisc(wchar* fn)
Disc* OpenDisc(const wchar* fn)
{
Disc* rv;

Expand Down
2 changes: 1 addition & 1 deletion core/imgread/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ struct Disc

extern Disc* disc;

Disc* OpenDisc(wchar* fn);
Disc* OpenDisc(const wchar* fn);

struct RawTrackFile : TrackFile
{
Expand Down
4 changes: 2 additions & 2 deletions core/imgread/gdi.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "common.h"
#include <ctype.h>

Disc* load_gdi(char* file)
Disc* load_gdi(const char* file)
{
u32 iso_tc;
Disc* disc = new Disc();
Expand Down Expand Up @@ -75,7 +75,7 @@ Disc* load_gdi(char* file)
}


Disc* gdi_parse(char* file)
Disc* gdi_parse(const char* file)
{
size_t len=strlen(file);
if (len>4)
Expand Down
2 changes: 1 addition & 1 deletion core/imgread/ioctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void PhysicalTrack::Read(u32 FAD,u8* dst,SectorFormat* sector_type,u8* subcode,S
}


Disc* ioctl_parse(wchar* file)
Disc* ioctl_parse(const wchar* file)
{

if (strlen(file)==3 && GetDriveType(file)==DRIVE_CDROM)
Expand Down
8 changes: 5 additions & 3 deletions core/rend/gles/gles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ void OSD_DRAW()
glUseProgram(gl.OSD_SHADER.program);

//reset rendering scale

/*
float dc_width=640;
float dc_height=480;
Expand All @@ -1101,7 +1101,7 @@ void OSD_DRAW()
ShaderUniforms.scale_coefs[3]=-1;
glUniform4fv( gl.OSD_SHADER.scale, 1, ShaderUniforms.scale_coefs);

*/

glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
Expand Down Expand Up @@ -1136,14 +1136,16 @@ void OSD_DRAW()

glBindTexture(GL_TEXTURE_2D,osd_font);
glUseProgram(gl.OSD_SHADER.program);

/*
//-1 -> too much to left
ShaderUniforms.scale_coefs[0]=2.0f/(screen_width/dc2s_scale_h);
ShaderUniforms.scale_coefs[1]=-2/dc_height;
ShaderUniforms.scale_coefs[2]=1-2*ds2s_offs_x/(screen_width);
ShaderUniforms.scale_coefs[3]=-1;
glUniform4fv( gl.OSD_SHADER.scale, 1, ShaderUniforms.scale_coefs);

*/

glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
Expand Down
124 changes: 70 additions & 54 deletions gdtool/src/cdromfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ union voldesc {
};

char *iso_astring(char *, int len);
char *cdrom_time(struct cdromtime *, int);
void printdirent(struct directent *, struct fs *);
void printdirents(struct directent *, struct fs *);
double cdrom_time(struct cdromtime *, int);
void printdirent(FILE* w, struct directent *, struct fs *, bool&);
void printdirents(FILE* w, struct directent *, struct fs *);
void printdirentheader(char *p);
int searchdirent(struct directent *, struct directent *, struct directent *,
struct fs *);
Expand Down Expand Up @@ -353,10 +353,11 @@ printdirentheader(char *path) {
}
/* Print all entries in the directory. */
void
printdirents(struct directent *dp, struct fs *fs) {
printdirents(FILE* w, struct directent *dp, struct fs *fs) {
struct directent *ldp;
long filesize = ISO_WD(FDV(dp, size, fs->type)),
lbn = 0, cnt;
bool first = true;
char *buffer = (char *) malloc(fs->lbs);
while (getblkdirent(dp, buffer, lbn, fs)) {
long entlen, namelen;
Expand All @@ -367,7 +368,7 @@ printdirents(struct directent *dp, struct fs *fs) {
namelen = ISO_BY(FDV(ldp, name_len, fs->type));
/* have we a record to match? */
while (cnt > sizeof (union fsdir) && entlen && namelen) {
printdirent(ldp, fs);
printdirent(w, ldp, fs, first);
/* next entry? */
cnt -= entlen;
ldp = (struct directent *) (((char *) ldp) + entlen);
Expand All @@ -380,61 +381,70 @@ printdirents(struct directent *dp, struct fs *fs) {
free(buffer);
}

char __212[32];

/* print CDROM file modes */
void prmodes(int f) {
char* prmodes(int f) {
memset(__212, 0, sizeof(__212));
char* p = __212;

int i;
for(i=0; i < 8; i++) {
if(CD_FLAGBITS[i] == ' ')
continue;
if(f & (1<<i))
putchar(CD_FLAGBITS[i]);
else
putchar('-');
*p++=(CD_FLAGBITS[i]);
/*else
*p++=('-');*/
}
putchar(' ');

return __212;
}
/* Print a directent on output, formatted. */
#define HN(name, val, lst) fprintf(w, "%s\"%s\":%0.f", !lst?", " : "", name, (double)(val))
#define HS(name, val, lst) fprintf(w, "%s\"%s\":\"%s\"", !lst?", " : " ", name, val)

void
printdirent(struct directent *dp, struct fs *fs) {
printdirent(FILE* w, struct directent *dp, struct fs *fs, bool& first) {
unsigned extattlen;
unsigned fbname, name_len, entlen, enttaken;
/* mode flags */
prmodes(ISO_BY(FDV(dp, flags, fs->type)));
/* Note: this feature of HSF is not used because of lack of semantic def. */
#ifdef whybother
extattlen = ISO_BY(FDV(dp, ext_attr_length, fs->type));
if (extattlen)
printf(" E%3d", extattlen);
else
printf(" ");
#endif
/* size */
printf("\t%6d", ISO_WD(FDV(dp, size, fs->type)));
/* time */
printf(" %s",
cdrom_time((struct cdromtime *) FDV(dp, date, fs->type),fs->type));
/* compensate for reserved field used to word align directory entry */
entlen = ISO_BY(FDV(dp, length, fs->type));

entlen = ISO_BY(FDV(dp, length, fs->type));
name_len = ISO_BY(FDV(dp, name_len, fs->type));
enttaken = sizeof(union fsdir) + name_len;
if (enttaken & 1)

if (enttaken & 1)
enttaken++;
fbname = ISO_BY(FDV(dp, name(), fs->type));
entlen -= enttaken;
/* print size of CDROM Extensions field if present */
if (entlen)
printf(" %3d", entlen);
else
printf(" ");
/* finally print name. compensate for unprintable names */
if (name_len == 1 && fbname <= 1) {
printf("\t%s\n", (fbname == 0) ? "." : "..");
} else
printf("\t%s\n",
iso_astring(FDV(dp, name(), fs->type), name_len));
};
/* attempt to print a CDROM file's creation time */
char *

if (name_len == 1 && fbname <= 1)
return;


fprintf(w, "%s\n\t{", first ? "" : ",");
{
first = false;

HS("name", iso_astring(FDV(dp, name(), fs->type), name_len), true);

//modes
HS("modes", prmodes(ISO_BY(FDV(dp, flags, fs->type))), false);

// size
HN("size", ISO_WD(FDV(dp, size, fs->type)), false);

//lba
HN("startFAD", 150 + ISO_WD(FDV(dp, extent, fs->type)), false);

//time
HN("time", cdrom_time((struct cdromtime *) FDV(dp, date, fs->type),fs->type), false);
}
fprintf(w, " }");
}

//cdrom_time to js timestamp
double
cdrom_time(struct cdromtime *crt, int type) {
struct tm tm;
static char buf[32];
Expand All @@ -457,10 +467,8 @@ cdrom_time(struct cdromtime *crt, int type) {
fmt = "%b %e %H:%M:%S %Z %Y";
} else
#endif
fmt = "%b %d %H:%M:%S %Y";
/* step 2. use ANSI C standard function to format time properly */
(void)strftime(buf, sizeof(buf), fmt, &tm);
return (buf);

return 1000.0*mktime(&tm);
}
static char __strbuf[200];
/* turn a blank padded character field into the null terminated strings
Expand Down Expand Up @@ -533,14 +541,18 @@ mainy(int argc, char *argv[])
#endif


void find(directent* rootent, fs* fsd, char* pathname) {
void find(FILE* w, directent* rootent, fs* fsd, char* pathname) {
struct directent openfile;

if (lookup(rootent, &openfile, pathname, fsd)) {
/* if a directory, format and list it */
if (ISO_BY(FDV(&openfile, flags, fsd->type)) & CD_DIRECTORY) {
/*
printdirentheader(pathname);
printdirents(&openfile, fsd);
*/
fprintf(w, "[");
printdirents(w, &openfile, fsd);
fprintf(w, "\n]\n");
}
/* if a file, print it on standard output */
else
Expand All @@ -551,7 +563,7 @@ void find(directent* rootent, fs* fsd, char* pathname) {
}


void parse_cdfs(cdimage* cdio, int offs) {
bool parse_cdfs(FILE* w, cdimage* cdio, const char* name, int offs, bool first) {
//im
fs fsd;
directent rootent;
Expand All @@ -564,10 +576,14 @@ void parse_cdfs(cdimage* cdio, int offs) {

/* is there a filesystem we can understand here? */
if (iscdromfs(&rootent, &fsd, offs) ) {
/* print the contents of the root directory to give user a start */
printf("Root Directory Listing:\n");
printdirentheader("/");
printdirents(&rootent, &fsd);
//printdirentheader("/");
fprintf(w, "%s\"%s\": [", first? "\n":",\n", name);
printdirents(w, &rootent, &fsd);
fprintf(w, "\n]");

return true;
}
else
return false;

}
2 changes: 1 addition & 1 deletion gdtool/src/cdromfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ struct cdimage {
};


void parse_cdfs(cdimage* cdio, int offs);
bool parse_cdfs(FILE* w, cdimage* cdio, const char* prefix, int offs, bool first);
Loading

0 comments on commit d59197f

Please sign in to comment.