473,659 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

splitting functions into files

Hello world !

This may be a naive question, so I apologize in advance !

I'm wonderting if it is possible to find a program that takes a C source
code file and split it into multiple files, one per each function
included in the source code ?

Many thanks in advance !

Luc Moulinier, Ph.D
IGBMC, Illkirch
France
Nov 14 '05 #1
5 2882
"moumou" <mo****@igbmc .u-strasbg.fr> wrote in message
news:cs******** **@news.u-strasbg.fr...
Hello world !

This may be a naive question, so I apologize in advance !

I'm wonderting if it is possible to find a program that takes a C source
code file and split it into multiple files, one per each function
included in the source code ?


If such a program exists, I suspect it's possible to find it.
I'd start with www.google.com

If I needed but couldn't find one, I try to write one. Of
course if you have control over the source you're going to parse,
this can make things much easier.

But are you sure you want to do this? I think it
would make much more sense to do this by hand, because a
program's design can often indicate that a set of functions
should stay together in the same file. Also, depending upon
the program, doing this could cause it to fail to build.

IOW if you find a source file too large, I recommend breaking
it up logically, not 'mechanically'. Computers are great
at automating menial work, but they can't do your thinking
for you.

-Mike
Nov 14 '05 #2
moumou <mo****@igbmc .u-strasbg.fr> writes:
I'm wonderting if it is possible to find a program that takes a C
source code file and split it into multiple files, one per each
function included in the source code ?


I don't know of one (unless you count text editors, but I presume you
want a program that does this automatically).

It probably wouldn't be too difficult to write a program that does
this naively. The job is simpler if you make some assumptions about
how the code is formatted, particularly about the placement of curly
braces. For full generality, the program would have to incorporate a
C parser.

There are programs (such as ctags) that generate lists of symbols
declared in a source file. You might be able to use something like
that as a basis for what you want.

But if the file contains declarations other than function definitions,
each split file won't be able to see those declarations. You might be
able to automatically generate a header containing any global
declarations (not definitions!), but that gets tricky.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #3
moumou wrote:
I'm wonderting if it is possible to find a program
that takes a C source code file and split it into multiple files,
one per each function included in the source code?


Most [UNIX] programmers use csplit to do this.
Just type

man csplit

or

info csplit

at your UNIX [Linux] shell prompt.
Nov 14 '05 #4
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > writes:
moumou wrote:
I'm wonderting if it is possible to find a program
that takes a C source code file and split it into multiple files,
one per each function included in the source code?


Most [UNIX] programmers use csplit to do this.
Just type

man csplit

or

info csplit

at your UNIX [Linux] shell prompt.


The 'c' in csplit stands for "context", not C. To use it to split a C
source file into functions, you'd probably have to construct regular
expressions matching the beginnings and ends of functions. I don't
believe that's possible.

If you have a convention of marking function boundaries in your code
(say, by a standard comment), csplit might be helpful -- but then
you've done most of the work already.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
moumou <mo****@igbmc .u-strasbg.fr> writes:
I'm wonderting if it is possible to find a program that takes a C
source code file and split it into multiple files, one per each
function included in the source code ?


It probably wouldn't be too difficult to write a program that does
this naively. The job is simpler if you make some assumptions about
how the code is formatted, particularly about the placement of curly
braces. For full generality, the program would have to incorporate a
C parser.

But if the file contains declarations other than function definitions,
each split file won't be able to see those declarations. You might be
able to automatically generate a header containing any global
declarations (not definitions!), but that gets tricky.


The DMS Software Reengineering Toolkit is designed to help
one build custom tools like this. It does have a full C parser
(and just as important, full name and type resolution) so
that one could identify, for each "split" function, the set
of definitions on which it depends. The parser also
builds trees, and can reconstruct the source from
those trees (comments included).
Using that information, one could write a tool
that wrote individual functions to individual files,
and constructed appropriate externs, .h files
and #includes to ensure the program still compiled
and ran.

See http://www.semanticdesigns.com/Produ...MSToolkit.html.
--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2200
by: Jerry | last post by:
My "main" class is getting a bit long...Is it possble to split a class definition into several files and then import the pieces to get the whole definition? Jerry
11
4745
by: MM | last post by:
Hi I have never written any C programs before, but it seems that I need to do so now. Hope some of you out there can spend a few minutes and help me by writing a simple example of something fairly similar to what I need. I really think it is a simple matter if you know C programming, but to me it is not easy at all. An example from some "professional" C programmer will probably give me all I need to complete it into exactly what I need....
13
2627
by: Skybuck Flying | last post by:
Hi, I would like to split main.c which contains all code into the following Step 1. Machine.h Step 2. drand.h and drand.c Step 3. nrand.h and nrand.c Main.c then only contains some test code.
1
2164
by: sadiewms | last post by:
Hello! I have a flat file that I'm trying to get into a relational Access 2003 DB. One of the fields in the flat file has a list of names separated by ";". I'd like to loop through them and create new records for each in a table relational DB. ( name1; name2; name3; name4) I'm getting stuck on splitting the string. Because there may be up to 6 names in the original field I can't use the Left(), Mid() functions. I've also tried...
10
2722
by: klineb | last post by:
Good Day, I have written and utility to convert our DOS COBOL data files to a SQL Server database. Part of the process requires parsing each line into a sql statement and validting the data to keep the integrity of the database. We are parsing roughl 81 files and range in size 1 kb to 65 MB files (Average of 400,000 lines in the larger files). I have written this utility with VB.NET 2003 and when I parse all of the files I run out...
5
3143
by: hecuba007 | last post by:
My apologies if this question has been asked before .. I would like to split large files into smaller chunks for uploading to php for re-assembly on the server. Is there a (relatively) simple way of doing this in javascript? If so, could someone point me to relevant documentation to read or (if really simple!) give me some coding hints? Thanks.
4
4428
by: nikila | last post by:
Hi, I am trying to split large xml files to smaller xml files using c#.net. can you please provide any sample code for this? I have to split the file if the size is more than 10 MB. Also, xml files after splitting should be valid xml. i am new to Csharp? Thanks for your help
2
2870
by: Matt | last post by:
Hi, I'm ridiculously new to Access (about a week!) so please be patient! My database is a record of British Standards. Each has a unique identifier. Some are split into parts. I would like the user to be able to input the data into a single textbox using a form like this: Record1: BS 1490-1 Record2: BS 1490-2
0
1555
by: aj | last post by:
SQL Server 2005 SP2 I read the excellent advice "Optimize tempdb in SQL Server by striping and splitting to multiple files" at http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1276989,00.html My question: All of my database files, primary and log, are on a SAN that is using RAID 10 -- so these files are striped and mirrored across multiple spindles anyway.
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.