News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

filecopy

Started by felipe, February 25, 2019, 04:59:43 AM

Previous topic - Next topic

felipe

a very simple program to copy a file from the command line (cmd.exe). syntax usage: filecopy filenametocopy filenameofcopy. The syntax for this little program is strict, so if you add more than one space between the program name and the first argument, or between the first argument and the second argument, the program will not do the copy of the file succesfully. yeah, it's not a too friendly program, but anyway, who really need it... :P

.asm and .exe attached in .zip.  :icon14:

aw27

What happens if the file names have spaces?  :(

felipe

it doesn't work?  :idea:

aw27

Quote from: felipe on March 01, 2019, 03:52:43 AM
it doesn't work?  :idea:
It is your turn to answer my question, not ask me to test your software. :idea:

felipe

Quote from: AW on March 01, 2019, 04:06:56 AM
It is your turn to answer my question, not ask me to test your software. :idea:

Really? and what license you paid for?  :P

The code it's not that hard, i don't think it requires any explanation to your question... :idea:

aw27

Quote from: felipe on March 01, 2019, 04:27:05 AM
Quote from: AW on March 01, 2019, 04:06:56 AM
It is your turn to answer my question, not ask me to test your software. :idea:
Really? and what license you paid for?  :P
It appears that you are making a favor to everybody by dropping careless pieces of crap.  :idea:
I am dropping out, have fun.

felipe

Quote from: AW on March 01, 2019, 04:31:57 AM
It appears that you are making a favor to everybody by dropping careless pieces of crap.  :idea:

It's more and academic issue (not a commercial issue as you seem to think... ::)). The program states as how it is, very simple, with an strict syntax. Just a simple exercise. :idea:

Quote from: AW on March 01, 2019, 04:31:57 AM
I am dropping out, have fun.

Sure, no problem. This simple academic exercise it's too much of a piece of crap to such a smart professional programmer like you. So keep having fun!  ;)

felipe

 I have been considering the request of a "demanding client"  :P of this software called "filecopy" (a.k.a "careless piece of crap"  :shock:). So in this version that i upload to the forum with the .asm file and the .exe file in the attached .zip file  :icon14:, allows for file names with spaces.  :idea:

jj2007

Are you sure this is a good way to design a loop?

search_arg_1:
          cmp     byte ptr[esi],20h                   ; Look up the first space.
          je      ready_to_arg_1

          inc     esi                                 ; Skip the program name to search for first argument.
          jmp     search_arg_1


Btw lodsb and stosb are fantastic instructions for such tasks. They are a bit slow as other members will not hesitate to remark, so don't use them if your filenames are much longer than a Million characters 8)

felipe

Quote from: jj2007 on March 01, 2019, 10:03:40 AM
Are you sure this is a good way to design a loop?

I like it and it works. If you have any other suggestion, please post it, don't be shy... :idea:

jj2007

Point is, if there is no space, this loop will run very far and eventually crash. In fact, if you launch the program without arguments, it will throw an exception, or, depending on the mood of the OS, it will show nothing, or it will say "ERROR: The operation was NOT performed succesfully"

A well behaved program should never throw an exception into the user's face. It should show an error message explaining, for example, that the program expects two arguments.

hutch--

Come on folks, be reasonable, the original post was a SIMPLE file copy, not an atom cracking wickedly crafted AVX4 world record holder. Anyone old enough to remember the DOS era would know how to use the old style simple file names which had no spaces. The parser to differentiate between a wide variety of inputs is more complicated than the file copy itself.

It is important for people making the effort to write assembler to try out all sorts of things and play with the code design to make it more efficient. I have never seen an algorithm that cannot be tweaked somewhere so it not like there will ever be an "ultimate" version.

felipe

Hutch is right jj, i have never talked about this program like it was an error-free program. I have make some error checkings, but that's all. It can be crashed if there are no arguments, i suppose (i think didn't check that out, as far as i can recall... :idea:). But of course a serious program, aimed to some expected end users must be error-free, at least to some extend... :idea:

aw27

Quote from: hutch-- on March 01, 2019, 11:22:13 AM
The parser to differentiate between a wide variety of inputs is more complicated than the file copy itself.
The OP is expected to be aware of the limitations and not ask users to check if something works or not when they can do it themselves or should have done it themselves beforehand.
I am not going to ask what happens if I use Russian filenames because he may answer that he is not a Russian.
I am not going to ask the reason filecopy origfile.txt "2"file.txt" produces a file named 2 when it should have produced a file named 2file.txt

Note:
All this parsing activity, even if were not crappy, is a waste of time.
For some reason Microsoft invented the function CommandLineToArgvW more than 20 years ago but never invented a function CommandLineToArgvA.

jj2007

Quote from: AW on March 01, 2019, 05:00:55 PMI am not going to ask the reason filecopy origfile.txt "2"file.txt" produces a file named 2 when it should have produced a file named 2file.txt

Where is it documented that a malformed "2"file.txt" should produce a well-formed 2file.txt? Otherwise, strangely enough, I agree with José :bgrin: