Jump to content











Photo
- - - - -

[closed] batch to bring hex to a table /spreadsheet (off topic notes)


  • This topic is locked This topic is locked
18 replies to this topic

#1 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 15070 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 01 August 2011 - 12:48 PM

In an only seemingly OT deviation, please find attached a small spreadsheet that should (hopefully) help when creating FAT12/16 floppy, superfloppy and volumes.

Discussion is actually here:
http://www.msfn.org/...on/page__st__60
but of course any idea/suggestion/correction is also very welcome here. :)

:cheers:
Wonko

Attached Files



#2 betrand

betrand

    Frequent Member

  • Advanced user
  • 467 posts
  •  
    France

Posted 13 September 2011 - 04:17 PM

Hi.
Edit: peeps will want to know what it's for. It is a "batch to bring hex to a table /spreadsheet".
Edit: working code Post19


@echo off

echo.

echo

echo batch to bring hex to a table.

echo.

set /p hex=where did you store your hex?

set /p out=what name for your table?(no ext)

 

echo the following based on http://www.computing.net/answers/programming/batch-text-file-content-to-variable/16264.html

echo the rest by r. (NNplay4)

setlocal enabledelayedexpansion

set SEPARATOR=

set filecontent=

for /f "delims=" %%a in (%hex%) do (

  set currentline=%%a

  set filecontent=!filecontent!%SEPARATOR%!currentline!

)

echo Your hexadecimal string is: %filecontent%

pause

 

set str=!filecontent!%SEPARATOR%!currentline!

echo. >NUL 2>%out%.htm

copy spread1h.txt+%out%.htm

set str=!filecontent!%SEPARATOR%!currentline!

set str=%str:~0,1%

echo.%str%>%out%.htm

copy %out%.htm+spread2h.txt %out%.htm

 

 

 

set str=!filecontent!%SEPARATOR%!currentline!

set str=%str:~1,1%

echo.%str%>>%out%.htm

copy %out%.htm+spread2h.txt %out%.htm

 

 

set str=!filecontent!%SEPARATOR%!currentline!

set str=%str:~3,1%

echo.%str%>>%out%.htm

copy %out%.htm+spread3h.txt %out%.htm

 


You will probably understand how it works. Blimey, the time I spent on it, I really feel it's a smart thingy now. Pfew!
I don't know how many versions I went through. I used to use dsfi. "used to use, because so many versions it's been long )
Then I realized copy command would be ok. I thought about using it at the beginning, but though it would CR.
I went through so may spreadsheets i've lost count.

You need to make yourself four base files.
-Spread1h.txt
-Spread2h.txt
-Spread2hrow.txt
-Spread3h.txt
These are made by hex-editing an html table.
Enter Value1 in A1, Value2 in A2. Edit: forgot: Save file as webpage 1sheet. Open it in an hex-editor. Find Value1, copy all before it (until the >), save as Spread1h.txt. From after Value1, copy </td>..spacespace. Save as Spread2h.txt.
Find Value2. Copy the last </td>..spacespace from after Value1, until Value2. You should have some </tr>, <tr>,td> included. Save as Spread2hrow.txt. Copy from the end of Value2 to the end of the file. Save that last bit as Spread3h.txt.

You can already sample the above code once these 4 files exist. To make the code evolve, paste the batch in a spreadsheet. The set str=%str:~1,1% should be edited. The

set str=%str:~

inside 1 cell, then

1

in the adjacent cell, and

,1%

in the third.
There is a jump (a clever part :)) . As is mentioned in Wonko's Fat-make Spreadsheet, The hexcode copied will have spaces.
We will use 01 34 67 89. (I mean number 0, number1, not second as it is a space, etc) So the value/function is (last value+2) and (last value+1). eg. =e4+1 and e7or8+2)

I will, for better understanding ;p, post a spreadsheet on request. :)
I could just post a zip anyway, :P

Ok, enough, for now.
r.



EDIT WoW Sh*t. I think there is a mistake!!!
I will try to see what can be done. Give me some feedback too if you think of anything.

Though the Dsfi version works. (I might post later if needed)










Edit
The code should be more along the lines of

set str=!filecontent!%SEPARATOR%!currentline!

echo. >NUL 2>%out%.htm

set str=!filecontent!%SEPARATOR%!currentline!

set str=%str:~0,1%

echo.%str%>%out%.htm

copy spread1h.txt+%out%.htm+spread3h.txt %out%.htm

,

But currently I get an empty cell. Probably a CR somewhere. :(
Shame, I thought copy would do the job..
Anyhow, Dsfi version works.
I will post it after.

#3 betrand

betrand

    Frequent Member

  • Advanced user
  • 467 posts
  •  
    France

Posted 13 September 2011 - 05:41 PM

Ok, re me.

Btw Hi, hope Peeps are good.


The Dsfi version of the Hex2table. 'Only' does two lines. An explanatory spreadsheet is in the works.
Needs the (mentionned in prev. post) Spread1h, etc files (4 of them).
They are included, along with Dsfi.exe of the Dsfok package. (http://faq.sanbarrow...=111&artlang=en)
uhuu, how do you upload?


I'll paste the code (I'll find how to upload la'er)

No, I removed it. See edit below.

(cause Dsfi is cool, but a simpler ver. is nice also.




Edit.
This next code, which works, is something to work on.
I knew there was a possibility with copy command. You still need the four files.
I will post the code for them.


@echo off

echo.

echo

echo batch to bring hex to a table.

echo.

set /p hex=where did you store your hex?

set /p htm=what name for your table?(no ext)

 

echo the following based on http://www.computing.net/answers/programming/batch-text-file-content-to-variable/16264.html

echo the rest by r. (NNplay4)

setlocal enabledelayedexpansion

set SEPARATOR=

set filecontent=

for /f "delims=" %%a in (%hex%) do (

  set currentline=%%a

  set filecontent=!filecontent!%SEPARATOR%!currentline!

)

echo Your hexadecimal string is: %filecontent%

pause

 

set str=!filecontent!%SEPARATOR%!currentline!

echo. >NUL 2>%htm%.swp

echo. >NUL 2>%htm%.htm

set str=!filecontent!%SEPARATOR%!currentline!

set str=%str:~0,1%

echo.%str%>%htm%.swp

copy spread1h.txt+%htm%.swp+spread2h.txt %htm%.htm

echo. >NUL 2>%htm%.swp

rem ============================

rem this line is different from above ( no spread1h, no null out)

set str=!filecontent!%SEPARATOR%!currentline!

echo. >NUL 2>%htm%.swp

set str=!filecontent!%SEPARATOR%!currentline!

set str=%str:~1,1%

echo.%str%>%htm%.swp

copy %htm%.htm+%htm%.swp+spread3h.txt %htm%.htm

echo. >NUL 2>%htm%.swp

 




Prev.edit:
Now, I'll go edit the game I needed that for.

Cheers
R. :)


Edit +put that with echoo.com would be fine.

#4 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 15070 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 13 September 2011 - 06:28 PM

I am failing to see the reason why you are posting OT things on this particular topic instead of starting your own.
Or am I missing something?
(I simply cannot get what would be the use of this batch :unsure:) but whatever this batch is intended for it doesn't seem like being connected with CHS, LBA and MBR/bootsectors.

As a general rule instead of re-writing the same snippet over and over, you could use a loop.
Seemingly this snippet:

set str=!filecontent!%SEPARATOR%!currentline!
set str=%str:~0,1%
echo.%str%>temp\swap0D0A
dsfi temp\swap 0 1 temp\swap0D0A
dsfi %htm%.htm e 0 temp\swap
echo. >NUL 2>temp\swap0D0A
echo. >NUL 2>temp\swap
dsfi %htm%.htm e 0 spread2h


Is copied for all values from 0 to 94 (and I cannot understand WHY and WHY last one points to "spread3h" whilst all previous ones pointed to "spread2h", maybe a typo? :dubbio:)

However:

FOR /L %%? IN (0,1,94) DO (

set str=!filecontent!%SEPARATOR%!currentline!


SET str_index=%%?

set str=%str:~!str_index!,1%



echo.%str%>temp\swap0D0A
dsfi temp\swap 0 1 temp\swap0D0A
dsfi %htm%.htm e 0 temp\swap
echo. >NUL 2>temp\swap0D0A
echo. >NUL 2>temp\swap
dsfi %htm%.htm e 0 spread2h
)


You will also need to add as SECOND line (just after the @echo off) this line:
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

NEVER, unless you really want it to, make a batch without a SETLOCAL initial statement.

:cheers:
Wonko

EDIT: I see that you have changed the program while I was posting, now it makes even less sense to me :ph34r:

#5 betrand

betrand

    Frequent Member

  • Advanced user
  • 467 posts
  •  
    France

Posted 13 September 2011 - 07:01 PM

Hello, Wonko :)

As usual, I get carried away. Though there is, "seemingly", a connection to the CHS-LBA translation, as in the spreadsheets for Hex, it is however, OT.
It would be an (good) idea to move the posts I did to another topic :) . Is it feasible?

How I happened here
Ok, I was editing and old videogame, with no way of copying the Hex to a spreadsheet. I remembered an old topic mentioning Hexalter, this one. I saw there was talk of
copying hex code to a spreadsheet.
So there we are.



I see that you have changed the program while I was posting


Yep, I removed the last one, thinking the new one, without Dsfi.exe, was OK.
In fact there is problem, re: the htm table appears OK in a web -browser, but drops a return (0D0A) when copied to Excel.
So, I will revert back to the old code, which uses dsfi.
I will, If I may, post it again.



Seemingly this snippet:
Quote


set str=!filecontent!%SEPARATOR%!currentline!
set str=%str:~0,1%
echo.%str%>temp\swap0D0A
dsfi temp\swap 0 1 temp\swap0D0A
dsfi %htm%.htm e 0 temp\swap
echo. >NUL 2>temp\swap0D0A
echo. >NUL 2>temp\swap
dsfi %htm%.htm e 0 spread2h

Is copied for all values from 0 to 94 (and I cannot understand WHY and WHY last one points to "spread3h" whilst all previous ones pointed to "spread2h", maybe a typo? :dubbio:)




Nope, no error, thanks for looking though. Spread2h is the "close the cell" code, spread3h is the "close the table and htm" code.

You will also need to add as SECOND line (just after the @echo off) this line:
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION


Thought I'd done that, maybe in some others? I'll check it.


As a general rule instead of re-writing the same snippet over and over, you could use a loop.


Heh, true :) . Nice one. I had just copied the whole Excel table without thinking batch :)




:cheers:
r.

#6 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 15070 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 13 September 2011 - 07:10 PM

As usual, I get carried away. Though there is, "seemingly", a connection to the CHS-LBA translation, as in the spreadsheets for Hex, it is however, OT.
It would be an (good) idea to move the posts I did to another topic :) . Is it feasible?

Sure :), contact an Admin/Mod.

BTW, I still cannot understand WHAT is the use of your batch.
If you could post a description of it's usage, and no "bring hex to a table" is NOT a description of whatever the thingy is supposed to do (at least I cannot understand it, as well as your description of the files involved ):

You need to make yourself four base files.
-Spread1h.txt
-Spread2h.txt
-Spread2hrow.txt
-Spread3h.txt
These are made by hex-editing an html table.
Enter Value1 in A1, Value2 in A2. Edit: forgot: Save file as webpage 1sheet. Open it in an hex-editor. Find Value1, copy all before it (until the >), save as Spread1h.txt. From after Value1, copy </td>..spacespace. Save as Spread2h.txt.
Find Value2. Copy the last </td>..spacespace from after Value1, until Value2. You should have some </tr>, <tr>,td> included. Save as Spread2hrow.txt. Copy from the end of Value2 to the end of the file. Save that last bit as Spread3h.txt.


:w00t:

Maybe if you post a .zip with the "final version" of your batch together with the sample files on some place where it can be downloaded form (like mediafire or the like) it would be easier to understand what you are up to.

:cheers:
Wonko

#7 betrand

betrand

    Frequent Member

  • Advanced user
  • 467 posts
  •  
    France

Posted 13 September 2011 - 07:46 PM

Hello dear Admin Wonko, could you change the thingy of topic, please?

Done ;)

Ok, here the thing.

r.

Attached Files



#8 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 15070 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 13 September 2011 - 07:56 PM

Hello dear Admin Wonko, could you change the thingy of topic, please?

No :(, I persoanlly cannot as I am not Admin (nor Mod of this forum - and even if I were it would have been an unapproved nomination)

Done ;)

Ok, here the thing.

r.


Good. :thumbup:

:cheers:
Wonko

#9 betrand

betrand

    Frequent Member

  • Advanced user
  • 467 posts
  •  
    France

Posted 13 September 2011 - 08:23 PM

If you tried you'll have noticed a missing mkdir temp.
Updated in last post.

r.

#10 betrand

betrand

    Frequent Member

  • Advanced user
  • 467 posts
  •  
    France

Posted 13 September 2011 - 09:06 PM

Ok,getting there.

If you open the result htm of hex2tabl_copyversion in an hexeditor, you will find 3E 1A. That's the annoying one!!!!! Mischievous F***!
Ok, Replace 3E 1A with 3E, and you're there :) :) :1st: :1st: :1st:
Pfou, (thing is, it was a sample of the code, so if bigger, maybe some other numbers would appear. :dubbio: )

(dunno how the 1A appeared..)

Also delete all occurrences of 0D0A. The file is still readable.
(btw, clean up the spread*h files, removing the font size etc.

So, one could say the last part is 'cleaning the table Hahah not intentional! (was bound to come out though!) :loleverybody:
with an hex editor.


:cheers:

r.

#11 betrand

betrand

    Frequent Member

  • Advanced user
  • 467 posts
  •  
    France

Posted 13 September 2011 - 09:43 PM

Just do a findstring delete..?

#12 betrand

betrand

    Frequent Member

  • Advanced user
  • 467 posts
  •  
    France

Posted 14 September 2011 - 12:40 PM

Ok, posting v2. (v5+ really).

Gives a good long table.
Still working on an automated findstr-delete (for the 0D0A, and 3E), though..

Attached Files



#13 ady

ady

    Frequent Member

  • Advanced user
  • 165 posts

Posted 14 September 2011 - 01:18 PM

@betrand, So, still OT? Even when you already know it?

@Wonko, would you please be so kind to post in this topic an updated make_fat*.* with the spreadsheet? Thank you in advance.

#14 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 15070 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 14 September 2011 - 01:42 PM

Besides being off-topic, don't take it as an offence :) betrand but you have clearly NO idea of what you are doing, and you are doing it anyway WRONG! :ph34r:

This is a board and not your development blog.

You have something nice to share?
Good, but at least TEST it properly before posting it.
It happens to everyone to post something that once checked/tested by another member in different conditions does not work, but this is frankly a bit too much.
Neither of the two batches work.

They are both UNNEEDEDLY complex and use UNNEEDEDLY a zillion files (both "templates" and "temp files").
You started with an unneedingly complex "base" (an Excel 14 Wizard generated HTML? :w00t:)

Here is some code that does presumably what you originally wanted to do, with no temporary file, no templates, no external programs.

@ECHO OFF
SETLOCAL

ECHO batch to bring hex to a table.
ECHO.
SET /p hex=where did you store your hex?
SET /p htm=what name for your table?

CALL :write_head

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /F "tokens=* delims=" %%? IN (%hex%) DO SET hex_contents=%%?
CALL :parse_line
CALL :write_tail
ECHO.
ECHO File %htm% written...
GOTO :EOF

:write_head
(
ECHO ^<^!doctype html PUBLIC "-//IETF//DTD HTML 2.0//EN"^>
ECHO ^<html^>^<head^>
ECHO ^<title^>HexTable from %hex%^</title^>^</head^>
ECHO ^<body^>^<body bgcolor=#CCCCCC text=black^>^<table border=1^>
ECHO ^<tr^>
) > %htm%
GOTO :EOF

:parse_line
SET /A Counter=0
FOR /L %%A IN (0,3,1200) DO (
SET Hex_Code=!hex_contents%:~%%A,2!
SET /A Counter+=1
IF NOT !Hex_Code!.==. (ECHO ^<td align=center^>^<p^>!Hex_Code!^</p^>^</td^>>>%htm%) ELSE GOTO :EOF
IF !Counter!==16 SET /A Counter=0 &ECHO ^</tr^>^<tr^>>>%htm%
)
GOTO :EOF

:write_tail
ECHO ^</tr^>^</body^>^</html^>>>%htm%
GOTO :EOF


@ady
Last version is attached on the thread on MSFN, can't you get it from there? :unsure:

:cheers:
Wonko

#15 ady

ady

    Frequent Member

  • Advanced user
  • 165 posts

Posted 14 September 2011 - 02:17 PM

@ady
Last version is attached on the thread on MSFN, can't you get it from there?
Wonko


Well, AFAI can see, the latest version I saw posted was make_fat_08.7z in a different topic than the original, and I am not a member of MSFN forums. I don't even know if 08 is the latest. Anyway, why leaving version 05 here, if there is a better version? So, I'd like to repeat my request, if it is not so much trouble for you.

Thank you in advance.

#16 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 15070 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 14 September 2011 - 02:24 PM


Well, AFAI can see, the latest version I saw posted was make_fat_08.7z in a different topic than the original, and I am not a member of MSFN forums. I don't even know if 08 is the latest. Anyway, why leaving version 05 here, if there is a better version? So, I'd like to repeat my request, if it is not so much trouble for you.

Thank you in advance.


It wouldn't be normally :)
But since I am using a NOT VALID browser as defined here:
http://reboot.pro/15419/
I cannot anymore upload *anything* to this Forum. :(
And NO, I am not going to use something that is NOT Opera because the demented guys at IPB board or our Admin have created somehow an incompatible setup.

Give me some time and I'll upload latest (yes it should be 08) to mediafire or the like and post a link to it.


EDIT: Here it is:
http://hotfile.com/d..._08_09.zip.html
I added a 09 version besides the 08.
Remember that his is simply and only "work in progress" and a lot of checks/tests were plainly omitted.

:cheers:
Wonko

#17 betrand

betrand

    Frequent Member

  • Advanced user
  • 467 posts
  •  
    France

Posted 14 September 2011 - 02:32 PM

Hi Ady and Wonko,


@betrand, So, still OT? Even when you already know it?

Besides being off-topic


Yeah, I was going to email the mods : :):. (like, just after)

TEST it properly

Yeah, I was OT, but posting the things was to get feedback /help /ideas. : :): .

you have clearly NO idea of what you are doing, and you are doing it anyway WRONG!


I guess I have an idea of what I'm doing, but it took time to evolve. I guess you tried the first posted version,
which I agree was not ready. (I posted afterwards a reviewed file).


Neither of the two batches work.

I guess that's the first posted version.

On the file

UNNEEDEDLY complex and use UNNEEDEDLY a zillion files

I agree the first versions (both), were.


About starting with

Excel 14 Wizard generated HTML

,
I was planning on simplifying afterwards, but at that moment I just wanted the thing to generate a working table.

On you feedback


IF NOT !Hex_Code!.==. (ECHO ^<td align=center^>^<p^>!Hex_Code!^</p^>^</td^>>>%htm%) ELSE GOTO :EOF

Cool, That's what I've just done (after my last post), with an equivalent

if not %str%.==.  goto _end

: :):
You code is good, I was planning to echo the table parts like that at some point.
The only thing I don't understand if you may, is the

:parse_line

SET /A Counter=0

FOR /L %%A IN (0,3,1200) DO (

Could you explain what the 1200 stands for?

Also, something I hadn't done was echoing directly the string to the htm. :)
I was using the (dreaded) temporary file.

Thank you
R.

#18 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 15070 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 14 September 2011 - 02:40 PM

Could you explain what the 1200 stands for?

1200 represents a cardinal number, it is an integer placed right after 1199 and immediately before 1201. :whistling:

In this case it represents an arbitrarily "biggish" number multiple of 3 (the "step").

As is the batch will process up to 1200/3=400 hex numbers.

Using GOTO :EOF is NOT equivalent to a GOTO :label when a CALL is used.:frusty:


:cheers:
Wonko

#19 betrand

betrand

    Frequent Member

  • Advanced user
  • 467 posts
  •  
    France

Posted 14 September 2011 - 03:05 PM

I said "the" 1200. Not 1200. "The" implying this one. The one cited. Otherwise i'd have Wikipediaed it.

1200 represents a cardinal number, it is an integer placed right after 1199 and immediately before 1201.

So, is 1199 an integer also? :clown: :ph34r:


IF NOT !Hex_Code!.==. (ECHO ^<td align=center^>^<p^>!Hex_Code!^</p^>^</td^>>>%htm%) ELSE GOTO :EOF

is the same (idea) as

if not %str%.==.  goto _end

when _end contains echo this and that.




In this case it represents an arbitrarily "biggish" number multiple of 3 (the "step")

Cool.

:cheers:
R.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users