Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90866 > unrolled thread

Convert c file to csv file(unix format) in python

Started byumasrinath88@gmail.com
First post2015-05-19 09:30 -0700
Last post2015-05-19 19:36 +0000
Articles 8 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Convert c file to csv file(unix format) in python umasrinath88@gmail.com - 2015-05-19 09:30 -0700
    Re: Convert c file to csv file(unix format) in python Mihamina Rakotomandimby <mihamina.rakotomandimby@rktmb.org> - 2015-05-19 19:48 +0300
      Re: Convert c file to csv file(unix format) in python umasrinath88@gmail.com - 2015-05-19 10:14 -0700
    Re: Convert c file to csv file(unix format) in python Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-19 18:20 +0000
      Re: Convert c file to csv file(unix format) in python umasrinath88@gmail.com - 2015-05-19 12:26 -0700
        Re: Convert c file to csv file(unix format) in python Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-20 01:57 +0000
          Re: Convert c file to csv file(unix format) in python Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-22 19:48 +0000
    Re: Convert c file to csv file(unix format) in python Grant Edwards <invalid@invalid.invalid> - 2015-05-19 19:36 +0000

#90866 — Convert c file to csv file(unix format) in python

Fromumasrinath88@gmail.com
Date2015-05-19 09:30 -0700
SubjectConvert c file to csv file(unix format) in python
Message-ID<c9733ddb-7f97-4fcf-9dad-a4481d1d3e5d@googlegroups.com>
Hi All,

I have a python script file which converts .hex file  to c file.

Can anyone help me in converting .c file to csv file (unix format).


Regards,
Uma

[toc] | [next] | [standalone]


#90868

FromMihamina Rakotomandimby <mihamina.rakotomandimby@rktmb.org>
Date2015-05-19 19:48 +0300
Message-ID<mailman.144.1432053932.17265.python-list@python.org>
In reply to#90866
On 05/19/2015 07:30 PM, umasrinath88@gmail.com wrote:
> Can anyone help me in converting .c file to csv file (unix format).
>
>
Would you give a sample?

[toc] | [prev] | [next] | [standalone]


#90874

Fromumasrinath88@gmail.com
Date2015-05-19 10:14 -0700
Message-ID<307ed4c5-b140-4f11-844f-db5fcc592dd7@googlegroups.com>
In reply to#90868
On Tuesday, May 19, 2015 at 10:15:43 PM UTC+5:30, Mihamina Rakotomandimby wrote:
> On 05/19/2015 07:30 PM, umasrinath88@gmail.com wrote:
> > Can anyone help me in converting .c file to csv file (unix format).
> >
> >
> Would you give a sample?

Hi Mihamina,

I have sent you the complete work folder.

thyncHextoC.py is python script used to convert .hex to .c structure file

Open command prompt window and type below command.


>python thyncHextoC.py <mention hex file to be converted>

example:  python thyncHextoC.py 18052015_1640_STM_5_08_DVT.hex

stm32Image.c file is created.

this .c file has to be converted to csv file.

I was following manual steps as below:(But want to automate now)

3)Open stm32Image.c file in notepad++
Delete  first 23 lines of data in the file(including this line "const flashImage_t    flashImageData[] ={")

The .C file must contain only hex bytes now.

4)Select all the hex bytes and go to edit option->Blank operation-> Remove leading and trailing spaces

next go again edit option->Line operations-> Remove empty lines containing blank characters

Remove the comma(,) from last hex byte till end of the file.
This can be achieved using Alt+Shift+end and scroll down until the last hex byte.

Note:Donot modify last line 0,0,0 }; of the file. Let it  remain as it is.

5)Once all the above steps are done, Save the file and in command prompt execute below command for converting .c to .csv file

>ren stm32Image.c <file name.csv>

example:ren stm32Image.c 28022015_1140_EVT.csv

[toc] | [prev] | [next] | [standalone]


#90888

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-05-19 18:20 +0000
Message-ID<mjfusi$6mq$2@dont-email.me>
In reply to#90866
On Tue, 19 May 2015 09:30:15 -0700, umasrinath88 wrote:

> I have a python script file which converts .hex file  to c file.

Hex is generally an ascii file containing hexadecimal values.

.c is generally an ascii file formatted in a way that corrsponds to the 
structures of the c programming language.

> Can anyone help me in converting .c file to csv file (unix format).

csv is generally a way of exchanging data between different software 
applications in a generally human readable format.

I'm unsure as to the translations you expect to be made to convert a .c 
file into a csv file. Perhaps you could elaborate on these.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#90889

Fromumasrinath88@gmail.com
Date2015-05-19 12:26 -0700
Message-ID<11c2e290-52db-4bc6-a5fe-5757230a816c@googlegroups.com>
In reply to#90888
On Tuesday, May 19, 2015 at 11:51:20 PM UTC+5:30, Denis McMahon wrote:
> On Tue, 19 May 2015 09:30:15 -0700, umasrinath88 wrote:
> 
> > I have a python script file which converts .hex file  to c file.
> 
> Hex is generally an ascii file containing hexadecimal values.
> 
> .c is generally an ascii file formatted in a way that corrsponds to the 
> structures of the c programming language.
> 
> > Can anyone help me in converting .c file to csv file (unix format).
> 
> csv is generally a way of exchanging data between different software 
> applications in a generally human readable format.
> 
> I'm unsure as to the translations you expect to be made to convert a .c 
> file into a csv file. Perhaps you could elaborate on these.
> 
> -- 
> Denis McMahon, denismfmcmahon@gmail.com

Hi Denis,

I agree to you point.

I have shared c file with you.Iorder to convert to unix format csv, below are the main steps we can follow.

1 Remove the 23 first lines
2.Remove all empty lines
3.Remove spaces at the beginning of each line
4.Replace ,\r\r\n with \n [commaCRCRLF replace with LF]
5.Rename and save this file as csv.

Can you help me in writing a python code for this. Which takes stm32Image.c file as input and generates stm32Image.csv

Regards,
Uma

[toc] | [prev] | [next] | [standalone]


#90913

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-05-20 01:57 +0000
Message-ID<mjgpmv$6mq$4@dont-email.me>
In reply to#90889
On Tue, 19 May 2015 12:26:05 -0700, umasrinath88 wrote:

> I have shared c file with you.Iorder to convert to unix format csv,
> below are the main steps we can follow.

What you're trying to do doesn't match with what you're explaining here.

What you're actually trying to do is extract a constant data declaration 
from a c source code file and output it in a different format.

You haven't explained whether you want the hexadecimal values converted 
to decimal integers or not.

Nor have you stated whether you want the hexadecimal values as quoted 
strings or not.

I believe I have a short program that does what you require based on the 
file you sent me and what I think is the output you're looking for. 
However, before I show you my solution, I'd like to see evidence of your 
own attempt to solve the problem.

Based on the sample you sent, the output csv file is 1657 lines in 
length, and the first and last lines are:

16,0x08000000,0xCC,0x16,0x00,0x20,0x35,0x15,0x00,0x08,0x29,0x15,0x00,0x08,0x2D,0x15,0x00,0x08

12,0x08006780,0x40,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0xFF,0x00,0x00,0x00

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#91066

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-05-22 19:48 +0000
Message-ID<mjo16m$equ$6@dont-email.me>
In reply to#90913
On Wed, 20 May 2015 01:57:51 +0000, Denis McMahon wrote:

> Based on the sample you sent, the output csv file is 1657 lines in
> length, and the first and last lines are:

[snip]

Well he didn't tell me if I was generating the right output, or what was 
wrong with it if it was wrong, so I guess he got a solution elsewhere.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#90890

FromGrant Edwards <invalid@invalid.invalid>
Date2015-05-19 19:36 +0000
Message-ID<mjg3c2$deg$1@reader1.panix.com>
In reply to#90866
On 2015-05-19, umasrinath88@gmail.com <umasrinath88@gmail.com> wrote:

> I have a python script file which converts .hex file  to c file.
>
> Can anyone help me in converting .c file to csv file (unix format).

------------------------------------------------------------------------
#import os,sys
os.rename(sys.argv[1],sys.argv[1].replace('.c','.csv'))
------------------------------------------------------------------------

-- 
Grant Edwards               grant.b.edwards        Yow! I want a WESSON OIL
                                  at               lease!!
                              gmail.com            

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web