Recent

Author Topic: MSDOS Arguments  (Read 10167 times)

Coldfire

  • New Member
  • *
  • Posts: 13
MSDOS Arguments
« on: June 02, 2017, 10:00:07 am »
Hi, i'm trying to port a very short programfrom linux to MSDOS-8086.

Code: Pascal  [Select][+][-]
  1. program project1;
  2. Uses sysutils;
  3. var
  4.   arginput       :        string;
  5.   argoutput      :        string;
  6.   fileinput      :        file;
  7.   fileoutput     :        text;
  8.   dumpbuf        :        word;
  9.   resultado      :        integer;
  10.  
  11.  
  12. begin
  13.      arginput:=ParamStr(1);
  14.      argoutput:=ParamStr(2);
  15.      assign(fileinput,arginput);
  16.      assign(fileoutput,argoutput);
  17.      reset(fileinput,2);
  18.      rewrite(fileoutput);
  19.      write(fileoutput,'<nombrevariable> dw ');
  20.      blockread(fileinput, dumpbuf, 2, resultado);
  21.      write(fileoutput, '0', format('%x',[dumpbuf]),'h');
  22.      while(eof(fileinput)=false) do
  23.        begin
  24.          blockread(fileinput, dumpbuf, 2, resultado);
  25.          write(fileoutput, ', 0', format('%x',[dumpbuf]),'h');
  26.        end;
  27.      close(fileinput);
  28.      close(fileoutput);
  29.      writeln(resultado);
  30. end.
in linux works somewhat great(dumps a file into little endian words written in a text file), but it behaves strange in MSDOS. Apparently is ignoring arguments. Also it expects a CRLF from keyboard to finish. MSDOS arguments have limitations?
Thanks

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11944
  • FPC developer.
Re: MSDOS Arguments
« Reply #1 on: June 02, 2017, 10:01:35 am »
The eof() is for cooked I/O not blockread.

EOF with blockread is when resultado<> the number of bytes read (mostly 2 in your case)

So the Linux program is wrong, and might only happen to work by chance
« Last Edit: June 02, 2017, 01:00:52 pm by marcov »

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1191
    • Burdjia
Re: MSDOS Arguments
« Reply #2 on: June 02, 2017, 12:54:15 pm »
Also note that Linux will expand filename wildcards (i.e. "file*", "file??" ...). Neither MS-DOS or Windows does it.  I don't know about others.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Coldfire

  • New Member
  • *
  • Posts: 13
Re: MSDOS Arguments
« Reply #3 on: June 02, 2017, 05:14:16 pm »
The eof() is for cooked I/O not blockread.

EOF with blockread is when resultado<> the number of bytes read (mostly 2 in your case)

So the Linux program is wrong, and might only happen to work by chance

good point. Now that is fixed, linux version works ok, but DOS version is still printing the file to stdout instead of specified file, and still waits for a CRLF from keyboard...

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11944
  • FPC developer.
Re: MSDOS Arguments
« Reply #4 on: June 02, 2017, 05:25:49 pm »
Start with using reset(f,1);


Coldfire

  • New Member
  • *
  • Posts: 13
Re: MSDOS Arguments
« Reply #5 on: June 02, 2017, 06:18:39 pm »

using reset(f,2) and hardcoding file name, it works. However
Code: Pascal  [Select][+][-]
  1. write(fileoutput,'<nombrevariable> dw ');

fileoutput is null  :o. i print it manually

Code: Pascal  [Select][+][-]
  1. arginput:=ParamStr(1);
  2.      argoutput:=ParamStr(2);
  3.      writeln(arginput);  

but does not print nothing (well, prints a CRLF from writeln)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11944
  • FPC developer.
Re: MSDOS Arguments
« Reply #6 on: June 02, 2017, 06:39:47 pm »
Call paramstr() for numbers higher than paramcount is illegal.

Bart

  • Hero Member
  • *****
  • Posts: 5469
    • Bart en Mariska's Webstek
Re: MSDOS Arguments
« Reply #7 on: June 02, 2017, 06:46:51 pm »
Call paramstr() for numbers higher than paramcount is illegal.

Huh?

ParamStr(ParamCount+n), where n>0, simply has to return an empty string (see: http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.ParamStr). It's not illegal, it's maybe a little foolish though.

Bart

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11944
  • FPC developer.
Re: MSDOS Arguments
« Reply #8 on: June 02, 2017, 06:49:35 pm »
Call paramstr() for numbers higher than paramcount is illegal.

Huh?

ParamStr(ParamCount+n), where n>0, simply has to return an empty string (see: http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.ParamStr). It's not illegal, it's maybe a little foolish though.

Bart

Params* are overriden in objpas, so the Object Pascal case might be different from the fpc case.

Though that is not why I was wrong, it is just defensive programming from the early days I guess.

Coldfire

  • New Member
  • *
  • Posts: 13
Re: MSDOS Arguments
« Reply #9 on: June 02, 2017, 06:50:49 pm »
writeln(paramcount);
writes 1 when i put in console ">:/project1 a"
but writeln(paramstr(1)); just prints a CRLF

now code goes in this
Code: Pascal  [Select][+][-]
  1. program project1;
  2. Uses sysutils, dos;
  3. var
  4.   arginput       :        string;
  5.   argoutput      :        string;
  6.   fileinput      :        file;
  7.   fileoutput     :        text;
  8.   dumpbuf        :        word;
  9.   resultado      :        integer;
  10.  
  11.  
  12. begin
  13.      writeln(paramcount);
  14.      //arginput:=ParamStr(1);
  15.      //argoutput:=ParamStr(2);
  16.      writeln(paramstr(1));
  17.      assign(fileinput,'input.ans');
  18.      assign(fileoutput,'output.ans');
  19.      reset(fileinput,2);
  20.      reset(fileoutput);
  21.      rewrite(fileoutput);
  22.      write(fileoutput,'<nombrevariable> dw ');
  23.      blockread(fileinput, dumpbuf, 1, resultado);
  24.      write(fileoutput, '0', format('%x',[dumpbuf]),'h');
  25.      while(resultado=1) do
  26.        begin
  27.          blockread(fileinput, dumpbuf, 1, resultado);
  28.          write(fileoutput, ', 0', format('%x',[dumpbuf]),'h');
  29.        end;
  30.      close(fileinput);
  31.      close(fileoutput);
  32.      //writeln(resultado);
  33.  
  34.                                

Coldfire

  • New Member
  • *
  • Posts: 13
Re: MSDOS Arguments
« Reply #10 on: June 02, 2017, 07:04:49 pm »
OK, i fixed it. I changed mode Objfpc to mode Freepascal and now outputs the correct parameters. Now is this a bug or a feature? because, in project options I stated Without ansistrigs, however, in mode objfpc when i search ParamStr declaration I find

Code: Pascal  [Select][+][-]
  1. {$ifdef FPC_HAS_FEATURE_COMMANDARGS}
  2.      { ParamStr should return also an ansistring }
  3.      Function ParamStr(Param : Integer) : Ansistring;
  4. {$endif FPC_HAS_FEATURE_COMMANDARGS}

So error probably comes from this part. I was trying to assign an ansistring to a pascal string an then triying to pass it to a pascal string argument.


Also randomly appears the following error
system.pp(57,47) Error: se esperaba ;, pero se encontro :
in that line system.pp says
mem  : array[0..$7fff-1] of byte absolute $0:$0;
« Last Edit: June 02, 2017, 07:09:13 pm by Coldfire »

 

TinyPortal © 2005-2018