Skip to content

Commit 84f401c

Browse files
committed
Modified how this code is built to become a library, with one more library
dependence, a lean version of which is included with this code. Modified the Makefile to change how the tagets are built. At present, three targets are include: the main demonstration code, the library that is the core of this code, and a library on which the present library depends. Streamlined the pre-processor directives that deal with C++ renaming such that the libraries link together as expected. A lean version of my utilities library was added to make this respository self-sufficient. IN 2019/05/23 "develop"
1 parent 07a9d76 commit 84f401c

8 files changed

Lines changed: 260 additions & 10 deletions

File tree

‎Makefile‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@ CXXOPTS += $(INCLUDE)
1212
CXXOPTS += $(DEBUG)
1313

1414
###### targets ##############################################################
15-
all: lib
16-
$(CXX) $(CXXOPTS) main.cpp intecplot.o -Wl,$(RPATH) -L $(LIB_DIR) -lINutils
17-
18-
lib:
19-
$(CXX) $(CXXOPTS) -c intecplot.cpp
2015

21-
22-
test:
23-
$(CC) $(COPTS) main.c -Wl,$(RPATH) -L $(LIB_DIR) -lINutils
16+
### (the main target makes use of the "libINtecplot.so" library)
17+
all: lib
18+
$(CXX) $(CXXOPTS) -I $(LIB_DIR) main.cpp \
19+
-Wl,$(RPATH) -L $(LIB_DIR) -lINtecplot
20+
21+
### (the software is made into a library: "libINtecplot.so" and makes use of
22+
### the "libINutils.so" library)
23+
lib: utils
24+
$(CXX) $(CXXOPTS) -I $(LIB_DIR) -c intecplot.cpp
25+
$(CXX) -shared -Wl,-rpath=$(LIB_DIR),-soname,libINtecplot.so -o libINtecplot.so \
26+
intecplot.o -lc -L $(LIB_DIR) -lINutils
27+
28+
### (a lean version of the "libINutils.so" library is built here)
29+
utils:
30+
$(CC) $(COPTS) -c utils.c
31+
$(CC) -shared -Wl,-soname,libINutils.so -o libINutils.so \
32+
utils.o -lc
2433

2534
clean:
2635
rm -f *.o a.out *.so

‎Makefile.in‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### path where "INutils" library is found
2-
LIB_DIR = /project/nompelis/parallel_v1.5
3-
LIB_DIR = ../../INutils
2+
### (This has been changed to use a lean version of the library in here.)
3+
LIB_DIR = .
44

55
### compilers and options
66
CC = gcc

‎intecplot.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#ifdef __cplusplus
4242
extern "C" {
43+
#endif
4344

4445

4546
enum inTecFile_Component {
@@ -2894,6 +2895,7 @@ const char* inTec_File::GetVariableName( int nvar_ ) const
28942895
}
28952896

28962897

2898+
#ifdef __cplusplus
28972899
}
28982900
#endif
28992901

‎intecplot.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
#ifdef __cplusplus
4646
extern "C" {
47+
#endif
4748

4849

4950
//
@@ -155,6 +156,7 @@ class inTec_File {
155156

156157

157158

159+
#ifdef __cplusplus
158160
}
159161
#endif
160162

‎main.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ int main()
2222
return(0);
2323
}
2424

25+

‎utils.c‎

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/******************************************************************************
2+
Copyright (c) 2017, Ioannis Nompelis
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without any
6+
modification, are permitted provided that the following conditions are met:
7+
1. Redistribution of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
2. Redistribution in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
3. All advertising materials mentioning features or use of this software
13+
must display the following acknowledgement:
14+
"This product includes software developed by Ioannis Nompelis."
15+
4. Neither the name of Ioannis Nompelis and his partners/affiliates nor the
16+
names of other contributors may be used to endorse or promote products
17+
derived from this software without specific prior written permission.
18+
5. Redistribution or use of source code and binary forms for profit must
19+
have written permission of the copyright holder.
20+
21+
THIS SOFTWARE IS PROVIDED BY IOANNIS NOMPELIS ''AS IS'' AND ANY
22+
EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL IOANNIS NOMPELIS BE LIABLE FOR ANY
25+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
******************************************************************************/
32+
33+
#include <stdio.h>
34+
#include <stdlib.h>
35+
#include <string.h>
36+
37+
//
38+
// Items have been trimmed from this header file from the original.
39+
// This is to allow for distribution of a "trimmed" version of my utilities,
40+
// and in this case only the ones presently relevant to this project.
41+
// IN 2019/05/23
42+
//
43+
44+
#include "utils.h"
45+
#include "utils_proto.h"
46+
47+
48+
/*
49+
* Function to read a line of data from an ASCII file similar to and intended
50+
* to replace fgets(). It takes a pointer to a pointer to char and the size that
51+
* is associated with the memory pointed to by that pointer to which the pointer
52+
* is pointing... The pointer to a null pointer can be passed. The idea is to
53+
* keep augmenting the memory as the text lines encountered in the file get
54+
* larger; the user does not care about providing a large enough buffer. Error
55+
* trapping is done by checking the return value; a negative value means failure
56+
* to re-allocate mamory.
57+
* Ioannis Nompelis <nompelis@nobelware.com> Created: 20170517
58+
* Ioannis Nompelis <nompelis@nobelware.com> Last modified: 20170517
59+
*/
60+
61+
int inUtils_ReadTextline( size_t *isize, char **buf, FILE *fp )
62+
{
63+
const size_t iseg_size = 256; // this is arbitrary but a good guess
64+
const size_t isafe = 1; // this is to allow stupid external queries...
65+
char *tbuf = NULL;
66+
size_t i;
67+
int idone = 0;
68+
69+
70+
// check if we have a valid stream open for reading
71+
if( fp == NULL ) {
72+
printf("Not a valid pointer to stream\n");
73+
return(0);
74+
}
75+
76+
#ifdef _DEBUG_
77+
printf("Buffer incoming at: %p \n", *buf );
78+
#endif
79+
80+
// keep reading until an end-of-line is encountered
81+
// allocate memory as needed
82+
i = 0;
83+
while( idone == 0 ) {
84+
int ic;
85+
char c;
86+
87+
// allocate memory if there is inadequate space
88+
if( i == (*isize) ) {
89+
size_t itmp = (*isize) + iseg_size + isafe;
90+
tbuf = (char *) realloc( *buf, itmp*sizeof(char) );
91+
if( tbuf == NULL ) {
92+
printf("Could not (re)allocate buffer\n");
93+
return(-1);
94+
}
95+
// assign buffer pointer
96+
*buf = tbuf;
97+
// set temporary pointer to new segment of the buffer
98+
tbuf = (char *) &((*buf)[ (*isize) ]);
99+
// clean-up the newly allocated memory
100+
memset( tbuf, '\0', iseg_size+isafe );
101+
// update size of buffer
102+
*isize += iseg_size;
103+
104+
#ifdef _DEBUG_
105+
printf("Buffer allocated (size: %ld) at %p / %p\n",
106+
(unsigned long) (*isize), *buf, tbuf );
107+
#endif
108+
}
109+
110+
// get a single character
111+
ic = fgetc( fp );
112+
113+
// check for end-of-file
114+
if( ic == EOF ) {
115+
#ifdef _DEBUG_
116+
printf("End-of-file encountered\n");
117+
#endif
118+
(*buf)[i] = '\0';
119+
idone = 1;
120+
} else {
121+
// put byte in buffer
122+
c = (char) ic;
123+
(*buf)[i] = c;
124+
++i;
125+
#ifdef _DEBUG2_
126+
printf(" Got \"%c\" (%d) \n", c, (int) c);
127+
#endif
128+
}
129+
130+
// terminate on newline character
131+
if( c == '\n' ) {
132+
idone = 1;
133+
}
134+
}
135+
136+
// return count of bytes read
137+
return( (int) i );
138+
}
139+
140+
141+
/*
142+
* Function to trim leading spaces from a string that is properly terminated
143+
* Ioannis Nompelis <nompelis@nobelware.com> Created: 20170517
144+
* Ioannis Nompelis <nompelis@nobelware.com> Last modified: 20170517
145+
*/
146+
147+
int inUtils_TrimLeadingSpaceTextline( char *buf )
148+
{
149+
size_t i,ie=0,is=0;
150+
151+
152+
if( buf == NULL ) return(1);
153+
154+
while( buf[is] == ' ' ) ++is;
155+
while( buf[ie] != '\0' ) ++ie;
156+
157+
if( is == 0 ) return(0);
158+
159+
for(i=0;i<ie-is;++i) {
160+
buf[i] = buf[i+is];
161+
buf[i+is] = '\0';
162+
}
163+
164+
return(0);
165+
}
166+

‎utils.h‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
#ifndef _UTILS_H_
3+
#define _UTILS_H_
4+
5+
/******************************************************************************
6+
Copyright (c) 2017, Ioannis Nompelis
7+
All rights reserved.
8+
9+
Redistribution and use in source and binary forms, with or without any
10+
modification, are permitted provided that the following conditions are met:
11+
1. Redistribution of source code must retain the above copyright
12+
notice, this list of conditions and the following disclaimer.
13+
2. Redistribution in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the distribution.
16+
3. All advertising materials mentioning features or use of this software
17+
must display the following acknowledgement:
18+
"This product includes software developed by Ioannis Nompelis."
19+
4. Neither the name of Ioannis Nompelis and his partners/affiliates nor the
20+
names of other contributors may be used to endorse or promote products
21+
derived from this software without specific prior written permission.
22+
5. Redistribution or use of source code and binary forms for profit must
23+
have written permission of the copyright holder.
24+
25+
THIS SOFTWARE IS PROVIDED BY IOANNIS NOMPELIS ''AS IS'' AND ANY
26+
EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28+
DISCLAIMED. IN NO EVENT SHALL IOANNIS NOMPELIS BE LIABLE FOR ANY
29+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35+
******************************************************************************/
36+
37+
#ifdef __cplusplus
38+
extern "C" {
39+
#endif
40+
41+
#include <utils_proto.h>
42+
43+
44+
//
45+
// Items have been trimmed from this header file from the original.
46+
// This is to allow for distribution of a "trimmed" version of my utilities,
47+
// and in this case only the ones presently relevant to this project.
48+
// IN 2019/05/23
49+
//
50+
51+
52+
#ifdef __cplusplus
53+
}
54+
#endif
55+
56+
#endif
57+

‎utils_proto.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
3+
//
4+
// Items have been trimmed from this header file from the original.
5+
// This is to allow for distribution of a "trimmed" version of my utilities,
6+
// and in this case only the ones presently relevant to this project.
7+
// IN 2019/05/23
8+
//
9+
10+
int inUtils_ReadTextline( size_t *isize, char **buf, FILE *fp );
11+
12+
int inUtils_TrimLeadingSpaceTextline( char *buf );
13+

0 commit comments

Comments
 (0)