Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
125 user(s) are online (111 user(s) are browsing Forums)

Members: 0
Guests: 125

more...

Support us!

Headlines

 
  Register To Post  

An expanded mkfile executable
Quite a regular
Quite a regular


See User information
mkfile is a nifty little program that creates a blank file of the specified size... I just want to slightly change it...

I should be able to compile it myself...

Any would be coders out there mind changing this code just slightly to cater to weird numbers? I could theorectically create a file of all of the individual components and then join them all but how hard would it be to change the code so it would do this?


mkfile "GBCPC V8 Full.rar" 3466840749 kb

OR

mkfile "GBCPC V8 Full.rar" 3 gb 466 mb 840749 kb


I might contact the uploader if all else fails but didn't think he would mind if we did a bit of brain storming here on Amigans

thanks goes to those that ponder this

#include <dos/dos.h>
#include <proto/dos.h>

#define PROGNAME "mkfile"
#define TEMPLATE "FILE/A,SIZE/N/A,TB/S,GB/S,MB/S,KB/S"

int main () {
    
struct {
        const 
char *filename;
        
int32 *filesize;
        
uint32 terabytes;
        
uint32 gigabytes;
        
uint32 megabytes;
        
uint32 kilobytes;
    } 
args = {0};
    
void *rd_args;
    
int rc 20;
    
BPTR file ZERO;
    
int64 filesize;
    
    
rd_args IDOS->ReadArgs(TEMPLATE, (LONG *)&argsNULL);
    if (!
rd_args) {
        
IDOS->PrintFault(IDOS->IoErr(), PROGNAME);
        return 
rc;
    }
    
    if (*
args.filesize ||
        (
args.terabytes && *args.filesize 0x7fffff)) {
        
IDOS->PrintFault(ERROR_BAD_NUMBERPROGNAME);
        goto 
out;
    }
    
    if (
args.terabytes) {
        
filesize = ((int64)*args.filesize) << 40;
    } else if (
args.gigabytes) {
        
filesize = ((int64)*args.filesize) << 30;
    } else if (
args.megabytes) {
        
filesize = ((int64)*args.filesize) << 20;
    } else if (
args.kilobytes) {
        
filesize = ((int64)*args.filesize) << 10;
    } else {
        
filesize = *args.filesize;
    }
    
    
file IDOS->Open(args.filenameMODE_OLDFILE);
    if (!
file) {
        
file IDOS->Open(args.filenameMODE_NEWFILE);
    }
    if (
file) {
        if (
IDOS->ChangeFileSize(filefilesizeOFFSET_BEGINNING)) {
            
rc 0;
        }
        
IDOS->Close(file);
    }
    if (
rc) {
        
IDOS->PrintFault(IDOS->IoErr(), args.filename);
    }
    
out:
    
IDOS->FreeArgs(rd_args);
    return 
rc;
}

~Yes I am a Kiwi, No, I did not appear as an extra in 'Lord of the Rings'~
1x AmigaOne X5000 2.0GHz 2gM RadeonR9280X AOS4.x
3x AmigaOne X1000 1.8GHz 2gM RadeonHD7970 AOS4.x
Go to top
Re: An expanded mkfile executable
Just can't stay away
Just can't stay away


See User information
@Slayer

Quote:

Slayer wrote:

mkfile "GBCPC V8 Full.rar" 3466840749 kb

OR

mkfile "GBCPC V8 Full.rar" 3 gb 466 mb 840749 kb

Are you sure you got those numbers right? I.e., do you really want (in your second example) 3 GB plus 466 MB plus 821 MB plus 45 KB, i.e. 4 GB, 263 MB and 45 KB? And do you expect the two examples to add up to the same size in bytes? The first one is 3466840749 * 1024 bytes, which is around 3.23 terabytes, while the second one is 4570788864 bytes or around 4.26 gigabytes.

Just checking ...

Best regards,

Niels

Go to top
Re: An expanded mkfile executable
Quite a regular
Quite a regular


See User information
@nbache

lol

perhaps there should be a . in the last 6 digit figure but it doesn't matter they are only examples... thanks for the consideration though

~Yes I am a Kiwi, No, I did not appear as an extra in 'Lord of the Rings'~
1x AmigaOne X5000 2.0GHz 2gM RadeonR9280X AOS4.x
3x AmigaOne X1000 1.8GHz 2gM RadeonHD7970 AOS4.x
Go to top
Re: An expanded mkfile executable
Not too shy to talk
Not too shy to talk


See User information
@Slayer

Quote:
mkfile "GBCPC V8 Full.rar" 3 gb 466 mb 840749 kb


This is not possible. You could theoretically remove the SIZE parameter and turn all /S in to /K/N, but then you could no longer write 3 GB but had to write GB 3 or GB=3.

Another possibility is to keep the /S and turn size into /N/M. But then you could no longer tell which number belongs to which unit. For example you could write 1 MB 2 KB 3 GB but the program would make 1 GB, 2 MB and 3 KB of it.

Even now you can already use 1 KB MB GB and the program would use 1 GB because it checks for GB first and ignores the other switches if it finds GB.

In addtion your calculation is wrong. 3 GB are 3072 MB and not 3000 MB, so 3 GB + 466 MB is not 3466 MB but 3538 MB.

Bye,
Thomas

Go to top
Re: An expanded mkfile executable
Quite a regular
Quite a regular


See User information
@thomas

ok, thanks for your help.

I know I didn't bother to times everything by 1024 I just copied the figure from the ctorrent client and then quickly tried to break it up for the second example...

So what you are saying is there is no way to alter this code to accept mkfile 3.4 gb for example without producing a totally new program source?

I need a b for bytes perhaps?

mkfile 3466840749 b

for example would create a file that size in bytes as far as AmigaDos is concerned, correct?

perhaps I need to look on Aminet

~Yes I am a Kiwi, No, I did not appear as an extra in 'Lord of the Rings'~
1x AmigaOne X5000 2.0GHz 2gM RadeonR9280X AOS4.x
3x AmigaOne X1000 1.8GHz 2gM RadeonHD7970 AOS4.x
Go to top
Re: An expanded mkfile executable
Just can't stay away
Just can't stay away


See User information
@Slayer

Quote:
Slayer wrote:
@thomas
So what you are saying is there is no way to alter this code to accept mkfile 3.4 gb for example without producing a totally new program source?

Correct. Of course it can be done, but not using ReadArgs(), and then it would hardly be an Amiga program any more, but just another generic *N?X C program. And coding the args parsing would be maybe 90 percent of the program anyway (once you know what size the user wants the file, it is created "with a snap of your fingers"). Which is part of the reason the program can be done so elegantly with ReadArgs().

Quote:
I need a b for bytes perhaps?

mkfile 3466840749 b

for example would create a file that size in bytes as far as AmigaDos is concerned, correct?

That should be possible within the current framework.

Best regards,

Niels

Go to top
Re: An expanded mkfile executable
Just can't stay away
Just can't stay away


See User information
@Slayer

Quote:

So what you are saying is there is no way to alter this code to accept mkfile 3.4 gb for example without producing a totally new program source?


ReadArgs() doesn't support floating point numbers and neither does my program so this will not work.

I could rewrite the template as:
FILE/A,SIZE/A,TB/S,GB/S,MB/S,KB/S

In this case I could use my own code for converting SIZE into a number and also handle larger numbers correctly. ATM it can only handle numbers up to 2^32-1 AFAIK.

Alternately I've thought of using:
FILE/A,SIZE/M

This way you could type f.e.:
mkfile filename.ext 50gb 100kb 128b

or just:
mkfile filename.ext 50g 100k 128

Quote:

I need a b for bytes perhaps?

mkfile 3466840749 b

for example would create a file that size in bytes as far as AmigaDos is concerned, correct?


You don't need a switch for bytes. If no switch is given the size is assumed to be in bytes.

3.4 GB is 3650722201.6 bytes BTW. Just FYI.

Go to top
Re: An expanded mkfile executable
Quite a regular
Quite a regular


See User information
@salass00

Quote:

salass00 wrote:

You don't need a switch for bytes. If no switch is given the size is assumed to be in bytes.


I will test this later but I think this is all I needed to know... how perculiar... thanks!

and thank you for everyone else that had some input... always very much appreciated!

~Yes I am a Kiwi, No, I did not appear as an extra in 'Lord of the Rings'~
1x AmigaOne X5000 2.0GHz 2gM RadeonR9280X AOS4.x
3x AmigaOne X1000 1.8GHz 2gM RadeonHD7970 AOS4.x
Go to top
Re: An expanded mkfile executable
Just can't stay away
Just can't stay away


See User information
@thomas

Quote:

Even now you can already use 1 KB MB GB and the program would use 1 GB because it checks for GB first and ignores the other switches if it finds GB.


I considered adding a check for this kind of case but was too lazy at the time.

Something like this f.e.:

#define KB 0x1
#define MB 0x2
#define GB 0x4
#define TB 0x8

uint8 switches;
if (
args.terabytesswitches |= TB;
if (
args.gigabytesswitches |= GB;
if (
args.megabytesswitches |= MB;
if (
args.kilobytesswitches |= KB;
switch (
switches) {
    case 
TB:
        
filesize = ((int64)*args.filesize) << 40;
        break;
    case 
GB:
        
filesize = ((int64)*args.filesize) << 30;
        break;
    
/* ... */
    
default:
        
IDOS->Printf("%s: illegal combination of switches\n"PROGNAME);
        goto 
out;
}

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project