rino 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/ext/extconf.rb +1 -24
- data/ext/libinchi.so +0 -0
- data/ext/src/aux2atom.h +120 -39
- data/ext/src/comdef.h +3 -3
- data/ext/src/dispstru.c +2547 -0
- data/ext/src/dispstru.h +73 -0
- data/ext/src/extr_ct.h +5 -2
- data/ext/src/ichi.h +27 -11
- data/ext/src/ichi_bns.c +1800 -254
- data/ext/src/ichi_bns.h +205 -4
- data/ext/src/ichican2.c +197 -86
- data/ext/src/ichicano.c +8 -13
- data/ext/src/ichicano.h +2 -2
- data/ext/src/ichicans.c +11 -6
- data/ext/src/ichicant.h +2 -2
- data/ext/src/ichicomn.h +2 -2
- data/ext/src/ichicomp.h +19 -4
- data/ext/src/ichidrp.h +9 -5
- data/ext/src/ichierr.h +5 -3
- data/ext/src/ichiisot.c +2 -2
- data/ext/src/ichimain.c +461 -0
- data/ext/src/ichimain.h +23 -15
- data/ext/src/ichimak2.c +6 -6
- data/ext/src/ichimake.c +843 -42
- data/ext/src/ichimake.h +4 -2
- data/ext/src/ichimap1.c +5 -5
- data/ext/src/ichimap2.c +2 -2
- data/ext/src/ichimap4.c +34 -21
- data/ext/src/ichinorm.c +11 -5
- data/ext/src/ichinorm.h +3 -2
- data/ext/src/ichiparm.c +2 -2
- data/ext/src/ichiparm.h +232 -30
- data/ext/src/ichiprt1.c +35 -11
- data/ext/src/ichiprt2.c +78 -7
- data/ext/src/ichiprt3.c +300 -120
- data/ext/src/ichiqueu.c +17 -2
- data/ext/src/ichiread.c +6932 -0
- data/ext/src/ichiring.c +3 -2
- data/ext/src/ichiring.h +2 -2
- data/ext/src/ichirvr1.c +4891 -0
- data/ext/src/ichirvr2.c +6344 -0
- data/ext/src/ichirvr3.c +5499 -0
- data/ext/src/ichirvr4.c +3177 -0
- data/ext/src/ichirvr5.c +1166 -0
- data/ext/src/ichirvr6.c +1287 -0
- data/ext/src/ichirvr7.c +2319 -0
- data/ext/src/ichirvrs.h +882 -0
- data/ext/src/ichisize.h +2 -2
- data/ext/src/ichisort.c +5 -5
- data/ext/src/ichister.c +281 -86
- data/ext/src/ichister.h +9 -3
- data/ext/src/ichitaut.c +208 -9
- data/ext/src/ichitaut.h +13 -11
- data/ext/src/ichitime.h +16 -2
- data/ext/src/inchicmp.h +107 -0
- data/ext/src/inpdef.h +6 -3
- data/ext/src/libinchi_wrap.c +912 -0
- data/ext/src/lreadmol.h +34 -31
- data/ext/src/mode.h +244 -7
- data/ext/src/mol2atom.c +1060 -0
- data/ext/src/mol2atom.h +31 -0
- data/ext/src/readinch.c +239 -0
- data/ext/src/readmol.c +28 -0
- data/ext/src/{e_readmol.h → readmol.h} +7 -9
- data/ext/src/runichi.c +251 -177
- data/ext/src/strutil.c +444 -238
- data/ext/src/strutil.h +150 -11
- data/ext/src/util.c +176 -118
- data/ext/src/util.h +15 -3
- data/lib/rino.rb +71 -3
- data/test/test.rb +33 -4
- metadata +22 -34
- data/ext/ruby_inchi_main.so +0 -0
- data/ext/src/e_0dstereo.c +0 -3014
- data/ext/src/e_0dstereo.h +0 -31
- data/ext/src/e_comdef.h +0 -57
- data/ext/src/e_ctl_data.h +0 -147
- data/ext/src/e_ichi_io.c +0 -498
- data/ext/src/e_ichi_io.h +0 -40
- data/ext/src/e_ichi_parms.c +0 -37
- data/ext/src/e_ichi_parms.h +0 -41
- data/ext/src/e_ichicomp.h +0 -50
- data/ext/src/e_ichierr.h +0 -40
- data/ext/src/e_ichimain.c +0 -593
- data/ext/src/e_ichisize.h +0 -43
- data/ext/src/e_inchi_atom.c +0 -75
- data/ext/src/e_inchi_atom.h +0 -33
- data/ext/src/e_inpdef.h +0 -41
- data/ext/src/e_mode.h +0 -706
- data/ext/src/e_mol2atom.c +0 -649
- data/ext/src/e_readinch.c +0 -58
- data/ext/src/e_readmol.c +0 -54
- data/ext/src/e_readstru.c +0 -251
- data/ext/src/e_readstru.h +0 -33
- data/ext/src/e_util.c +0 -284
- data/ext/src/e_util.h +0 -61
- data/ext/src/ichilnct.c +0 -286
- data/ext/src/inchi_api.h +0 -670
- data/ext/src/inchi_dll.c +0 -1480
- data/ext/src/inchi_dll.h +0 -34
- data/ext/src/inchi_dll_main.c +0 -23
- data/ext/src/inchi_dll_main.h +0 -31
- data/ext/src/ruby_inchi_main.c +0 -558
data/ext/src/e_0dstereo.h
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* International Union of Pure and Applied Chemistry (IUPAC)
|
3
|
-
* International Chemical Identifier (InChI)
|
4
|
-
* Version 1
|
5
|
-
* Software version 1.00
|
6
|
-
* April 13, 2005
|
7
|
-
* Developed at NIST
|
8
|
-
*/
|
9
|
-
|
10
|
-
#ifndef __0DSTEREO_H__
|
11
|
-
#define __0DSTEREO_H__
|
12
|
-
|
13
|
-
|
14
|
-
#ifndef INCHI_ALL_CPP
|
15
|
-
#ifdef __cplusplus
|
16
|
-
extern "C" {
|
17
|
-
#endif
|
18
|
-
#endif
|
19
|
-
|
20
|
-
|
21
|
-
int Clear3D2Dstereo(inchi_Input *pInp);
|
22
|
-
int set_0D_stereo_parities( inchi_Input *pInp, int bPointedEdgeStereo );
|
23
|
-
|
24
|
-
#ifndef INCHI_ALL_CPP
|
25
|
-
#ifdef __cplusplus
|
26
|
-
}
|
27
|
-
#endif
|
28
|
-
#endif
|
29
|
-
|
30
|
-
|
31
|
-
#endif /* __0DSTEREO_H__ */
|
data/ext/src/e_comdef.h
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* International Union of Pure and Applied Chemistry (IUPAC)
|
3
|
-
* International Chemical Identifier (InChI)
|
4
|
-
* Version 1
|
5
|
-
* Software version 1.00
|
6
|
-
* April 13, 2005
|
7
|
-
* Developed at NIST
|
8
|
-
*/
|
9
|
-
|
10
|
-
/* common definitions -- do not change */
|
11
|
-
#ifndef __COMDEF_H__
|
12
|
-
#define __COMDEF_H__
|
13
|
-
|
14
|
-
/* input bond type definition */
|
15
|
-
#define MIN_INPUT_BOND_TYPE INCHI_BOND_TYPE_SINGLE
|
16
|
-
#define MAX_INPUT_BOND_TYPE INCHI_BOND_TYPE_ALTERN
|
17
|
-
|
18
|
-
/* MOlfile */
|
19
|
-
#define INPUT_STEREO_SNGL_UP 1
|
20
|
-
#define INPUT_STEREO_SNGL_EITHER 4
|
21
|
-
#define INPUT_STEREO_SNGL_DOWN 6
|
22
|
-
#define INPUT_STEREO_DBLE_EITHER 3
|
23
|
-
|
24
|
-
/* radical definitions */
|
25
|
-
#define RADICAL_SINGLET 1
|
26
|
-
#define RADICAL_DOUBLET 2
|
27
|
-
#define RADICAL_TRIPLET 3
|
28
|
-
|
29
|
-
|
30
|
-
/* BILLY 8/6/04 */
|
31
|
-
#ifndef INCHI_ALL_CPP
|
32
|
-
#ifdef __cplusplus
|
33
|
-
extern "C" {
|
34
|
-
#endif
|
35
|
-
#endif
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
int e_AddMOLfileError( char *pStrErr, const char *szMsg );
|
40
|
-
|
41
|
-
#define MOLFILE_ERR_FIN(err, new_err, err_fin, msg) \
|
42
|
-
if ( !(err) && (new_err) ) { (err) = (new_err);} e_AddMOLfileError(pStrErr, (msg)); goto err_fin
|
43
|
-
#define MOLFILE_ERR_SET(err, new_err, msg) \
|
44
|
-
if ( !(err) && (new_err) ) { (err) = (new_err);} e_AddMOLfileError(pStrErr, (msg))
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
/* BILLY 8/6/04 */
|
50
|
-
#ifndef INCHI_ALL_CPP
|
51
|
-
#ifdef __cplusplus
|
52
|
-
}
|
53
|
-
#endif
|
54
|
-
#endif
|
55
|
-
|
56
|
-
#endif /* __COMDEF_H__ */
|
57
|
-
|
data/ext/src/e_ctl_data.h
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* International Union of Pure and Applied Chemistry (IUPAC)
|
3
|
-
* International Chemical Identifier (InChI)
|
4
|
-
* Version 1
|
5
|
-
* Software version 1.00
|
6
|
-
* April 13, 2005
|
7
|
-
* Developed at NIST
|
8
|
-
*/
|
9
|
-
|
10
|
-
#ifndef __CTL_DATA_H__
|
11
|
-
#define __CTL_DATA_H__
|
12
|
-
#include "e_ichisize.h"
|
13
|
-
/***********************************************/
|
14
|
-
#define STR_ERR_LEN 256
|
15
|
-
|
16
|
-
typedef struct tagStructData {
|
17
|
-
unsigned long ulStructTime;
|
18
|
-
int nErrorCode;
|
19
|
-
int nErrorType;
|
20
|
-
int nStructReadError;
|
21
|
-
int bChiralFlag;
|
22
|
-
char pStrErrStruct[STR_ERR_LEN];
|
23
|
-
long fPtrStart;
|
24
|
-
long fPtrEnd;
|
25
|
-
/* debugging info */
|
26
|
-
#if( bRELEASE_VERSION == 0 )
|
27
|
-
int bExtract;
|
28
|
-
#endif
|
29
|
-
|
30
|
-
} STRUCT_DATA;
|
31
|
-
/***********************************************/
|
32
|
-
|
33
|
-
#if( ACD_LABS_VERSION == 1 )
|
34
|
-
#define MAX_NUM_PATHS 5
|
35
|
-
#else
|
36
|
-
#define MAX_NUM_PATHS 4
|
37
|
-
#endif
|
38
|
-
|
39
|
-
/* SDF treatment */
|
40
|
-
#define MAX_SDF_VALUE 255 /* max lenght of the SDFile data value */
|
41
|
-
#define MAX_SDF_HEADER 64 /* max length of the SDFile data header */
|
42
|
-
|
43
|
-
/***********************************************/
|
44
|
-
|
45
|
-
typedef struct tagInputParms {
|
46
|
-
char szSdfDataHeader[MAX_SDF_HEADER+1];
|
47
|
-
char *pSdfLabel;
|
48
|
-
char *pSdfValue;
|
49
|
-
long lSdfId;
|
50
|
-
long lMolfileNumber;
|
51
|
-
/*#ifndef INCHI_ANSI_ONLY
|
52
|
-
DRAW_PARMS dp;
|
53
|
-
PER_DRAW_PARMS pdp;
|
54
|
-
TBL_DRAW_PARMS tdp;
|
55
|
-
#endif*/
|
56
|
-
/*
|
57
|
-
-- Files --
|
58
|
-
ip->path[0] => Input
|
59
|
-
ip->path[1] => Output (INChI)
|
60
|
-
ip->path[2] => Log
|
61
|
-
ip->path[3] => Problem structures
|
62
|
-
ip->path[4] => Errors file (ACD(
|
63
|
-
|
64
|
-
*/
|
65
|
-
const char *path[MAX_NUM_PATHS];
|
66
|
-
int num_paths;
|
67
|
-
int first_struct_number;
|
68
|
-
int last_struct_number;
|
69
|
-
INPUT_TYPE nInputType;
|
70
|
-
INCHI_MODE nMode;
|
71
|
-
int bAbcNumbers;
|
72
|
-
/*int bXml;*/
|
73
|
-
int bINChIOutputOptions; /* !(ip->bINChIOutputOptions & INCHI_OUT_PLAIN_TEXT) */
|
74
|
-
int bCtPredecessors;
|
75
|
-
int bXmlStarted;
|
76
|
-
int bDisplayEachComponentINChI;
|
77
|
-
|
78
|
-
long msec_MaxTime; /* was ulMaxTime; max time to run ProsessOneStructure */
|
79
|
-
long msec_LeftTime;
|
80
|
-
|
81
|
-
unsigned long ulDisplTime;
|
82
|
-
int bDisplay;
|
83
|
-
int bMergeAllInputStructures;
|
84
|
-
int bSaveWarningStructsAsProblem;
|
85
|
-
int bSaveAllGoodStructsAsProblem;
|
86
|
-
int bGetSdfileId;
|
87
|
-
int bGetMolfileNumber; /* read molfile number from the name line like "Structure #22" */
|
88
|
-
int bCompareComponents; /* see flags CMP_COMPONENTS, etc. */
|
89
|
-
int bDisplayCompositeResults;
|
90
|
-
int bDoNotAddH;
|
91
|
-
int bNoStructLabels;
|
92
|
-
int bChiralFlag;
|
93
|
-
int bAllowEmptyStructure;
|
94
|
-
INCHI_MODE bTautFlags;
|
95
|
-
INCHI_MODE bTautFlagsDone;
|
96
|
-
} INPUT_PARMS;
|
97
|
-
|
98
|
-
/*************************** INChI mode *******************************/
|
99
|
-
/* ip->nMode */
|
100
|
-
#define REQ_MODE_BASIC 0x000001 /* B */
|
101
|
-
#define REQ_MODE_TAUT 0x000002 /* T */
|
102
|
-
#define REQ_MODE_ISO 0x000004 /* I */
|
103
|
-
#define REQ_MODE_NON_ISO 0x000008 /* NI */
|
104
|
-
#define REQ_MODE_STEREO 0x000010 /* S */
|
105
|
-
#define REQ_MODE_ISO_STEREO 0x000020 /* IS */
|
106
|
-
#define REQ_MODE_NOEQ_STEREO 0x000040 /* SS */
|
107
|
-
#define REQ_MODE_REDNDNT_STEREO 0x000080 /* RS */
|
108
|
-
#define REQ_MODE_NO_ALT_SBONDS 0x000100 /* NASB */
|
109
|
-
/* new 10-10-2003 */
|
110
|
-
#define REQ_MODE_RELATIVE_STEREO 0x000200 /* REL All Relative Stereo */
|
111
|
-
#define REQ_MODE_RACEMIC_STEREO 0x000400 /* RAC All Racemic Stereo */
|
112
|
-
#define REQ_MODE_SC_IGN_ALL_UU 0x000800 /* IAUSC Ignore stereocenters if All Undef/Unknown */
|
113
|
-
#define REQ_MODE_SB_IGN_ALL_UU 0x001000 /* IAUSC Ignore stereobonds if All Undef/Unknown */
|
114
|
-
#define REQ_MODE_CHIR_FLG_STEREO 0x002000 /* SUCF If Chiral flag then Abs otherwise Rel stereo */
|
115
|
-
/* end of 10-10-2003 */
|
116
|
-
#define REQ_MODE_MIN_SB_RING_MASK 0x0F0000 /* RSB */
|
117
|
-
#define REQ_MODE_MIN_SB_RING_SHFT 16
|
118
|
-
|
119
|
-
#define REQ_MODE_DEFAULT (REQ_MODE_BASIC | REQ_MODE_TAUT | REQ_MODE_ISO | REQ_MODE_NON_ISO | REQ_MODE_STEREO)
|
120
|
-
|
121
|
-
/*********** compare components flags **********************************/
|
122
|
-
/* ip->bCompareComponents */
|
123
|
-
#define CMP_COMPONENTS 0x0001 /* perform compare components */
|
124
|
-
#define CMP_COMPONENTS_NONISO 0x0002 /* ignore isotopic */
|
125
|
-
#define CMP_COMPONENTS_NONTAUT 0x0004 /* compare non-tautomeric */
|
126
|
-
|
127
|
-
/****************** chemical identifier member definitions *************/
|
128
|
-
/* ip->bINChIOutputOptions */
|
129
|
-
#define INCHI_OUT_NO_AUX_INFO 0x0001 /* do not output Aux Info */
|
130
|
-
#define INCHI_OUT_SHORT_AUX_INFO 0x0002 /* output short version of Aux Info */
|
131
|
-
#define INCHI_OUT_ONLY_AUX_INFO 0x0004 /* output only Aux Info */
|
132
|
-
#define INCHI_OUT_EMBED_REC 0x0008 /* embed reconnected INChI into disconnected INChI */
|
133
|
-
#define INCHI_OUT_SDFILE_ONLY 0x0010 /* save input data in a Molfile instead of creating INChI */
|
134
|
-
#define INCHI_OUT_XML 0x0020 /* output xml INChI */
|
135
|
-
#define INCHI_OUT_PLAIN_TEXT 0x0040 /* output plain text INChI */
|
136
|
-
#define INCHI_OUT_PLAIN_TEXT_COMMENTS 0x0080 /* output plain text annotation */
|
137
|
-
#define INCHI_OUT_XML_TEXT_COMMENTS 0x0100 /* output xml text annotation */
|
138
|
-
#define INCHI_OUT_WINCHI_WINDOW 0x0200 /* output into wINChI text window */
|
139
|
-
#define INCHI_OUT_TABBED_OUTPUT 0x0400 /* tab-delimited (only for plain text) */
|
140
|
-
|
141
|
-
#define FLAG_INP_AT_CHIRAL 1
|
142
|
-
#define FLAG_INP_AT_NONCHIRAL 2
|
143
|
-
#define FLAG_SET_INP_AT_CHIRAL 4
|
144
|
-
#define FLAG_SET_INP_AT_NONCHIRAL 8
|
145
|
-
|
146
|
-
|
147
|
-
#endif /* __CTL_DATA_H__ */
|
data/ext/src/e_ichi_io.c
DELETED
@@ -1,498 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* International Union of Pure and Applied Chemistry (IUPAC)
|
3
|
-
* International Chemical Identifier (InChI)
|
4
|
-
* Version 1
|
5
|
-
* Software version 1.00
|
6
|
-
* April 13, 2005
|
7
|
-
* Developed at NIST
|
8
|
-
*/
|
9
|
-
|
10
|
-
#include <stdio.h>
|
11
|
-
#include <stdlib.h>
|
12
|
-
#include <string.h>
|
13
|
-
#include <ctype.h>
|
14
|
-
#include <limits.h>
|
15
|
-
#include <errno.h>
|
16
|
-
#include <stdarg.h>
|
17
|
-
|
18
|
-
#include "e_mode.h"
|
19
|
-
#include "ichitime.h"
|
20
|
-
#include "inchi_api.h"
|
21
|
-
#include "e_ctl_data.h"
|
22
|
-
|
23
|
-
#include "e_comdef.h"
|
24
|
-
#include "e_ichicomp.h"
|
25
|
-
#include "e_util.h"
|
26
|
-
#include "e_ichi_io.h"
|
27
|
-
#include "e_ichi_parms.h"
|
28
|
-
|
29
|
-
|
30
|
-
#define LtrimRtrim e_LtrimRtrim
|
31
|
-
|
32
|
-
/**********************************************
|
33
|
-
* output " L=V" or " L missing" or ""
|
34
|
-
* The fprintf format string must contain %s%s%s%s
|
35
|
-
*/
|
36
|
-
char e_gsMissing[] = "is missing";
|
37
|
-
char e_gsEmpty[] = "";
|
38
|
-
char e_gsSpace[] = " ";
|
39
|
-
char e_gsEqual[] = "=";
|
40
|
-
|
41
|
-
|
42
|
-
/********* from inchimain.c *****************************************/
|
43
|
-
int e_inchi_print( FILE* f, const char* lpszFormat, ... )
|
44
|
-
{
|
45
|
-
int ret=0, ret2=0;
|
46
|
-
/* char *p=NULL; */
|
47
|
-
|
48
|
-
va_list argList;
|
49
|
-
|
50
|
-
if ( f ) {
|
51
|
-
my_va_start( argList, lpszFormat );
|
52
|
-
ret = vfprintf( f, lpszFormat, argList );
|
53
|
-
va_end( argList );
|
54
|
-
} else {
|
55
|
-
/* printf( "\r" ); */
|
56
|
-
my_va_start( argList, lpszFormat );
|
57
|
-
//ret2 = vfprintf( stdout, lpszFormat, argList );
|
58
|
-
/* ret2 = vprintf( lpszFormat, argList ); */
|
59
|
-
va_end( argList );
|
60
|
-
}
|
61
|
-
|
62
|
-
#ifdef INCHI_LIB
|
63
|
-
if( FWPRINT )
|
64
|
-
{
|
65
|
-
my_va_start( argList, lpszFormat );
|
66
|
-
FWPRINT( lpszFormat, argList );
|
67
|
-
va_end( argList );
|
68
|
-
}
|
69
|
-
#endif
|
70
|
-
return ret? ret : ret2;
|
71
|
-
}
|
72
|
-
|
73
|
-
/*****************************************************************/
|
74
|
-
int e_my_fprintf( FILE* f, const char* lpszFormat, ... )
|
75
|
-
{
|
76
|
-
int ret=0, ret2=0;
|
77
|
-
va_list argList;
|
78
|
-
|
79
|
-
#ifndef INCHI_LIB
|
80
|
-
if ( f ) {
|
81
|
-
if ( f == stderr && lpszFormat && lpszFormat[0] && '\r' == lpszFormat[strlen(lpszFormat)-1] ) {
|
82
|
-
#define CONSOLE_LINE_LEN 80
|
83
|
-
#ifndef INCHI_ANSI_ONLY
|
84
|
-
char szLine[CONSOLE_LINE_LEN];
|
85
|
-
my_va_start( argList, lpszFormat );
|
86
|
-
ret = _vsnprintf( szLine, CONSOLE_LINE_LEN-1, lpszFormat, argList );
|
87
|
-
va_end( argList );
|
88
|
-
if ( ret < 0 ) {
|
89
|
-
/* output is longer than the console line */
|
90
|
-
strcpy(szLine+CONSOLE_LINE_LEN-4, "...\r");
|
91
|
-
}
|
92
|
-
fputs( szLine, f );
|
93
|
-
#else
|
94
|
-
my_va_start( argList, lpszFormat );
|
95
|
-
ret = vfprintf( f, lpszFormat, argList );
|
96
|
-
va_end( argList );
|
97
|
-
#endif
|
98
|
-
#undef CONSOLE_LINE_LEN
|
99
|
-
} else {
|
100
|
-
my_va_start( argList, lpszFormat );
|
101
|
-
ret = vfprintf( f, lpszFormat, argList );
|
102
|
-
va_end( argList );
|
103
|
-
}
|
104
|
-
}
|
105
|
-
if ( f != stderr ) {
|
106
|
-
my_va_start( argList, lpszFormat );
|
107
|
-
//ret2 = vfprintf( stderr, lpszFormat, argList );
|
108
|
-
va_end( argList );
|
109
|
-
}
|
110
|
-
#else
|
111
|
-
if ( f ) {
|
112
|
-
my_va_start( argList, lpszFormat );
|
113
|
-
ret = vfprintf( f, lpszFormat, argList );
|
114
|
-
va_end( argList );
|
115
|
-
}
|
116
|
-
#endif
|
117
|
-
|
118
|
-
return ret? ret : ret2;
|
119
|
-
}
|
120
|
-
/*******************************************************************/
|
121
|
-
void e_PrintFileName( const char *fmt, FILE *output_file, const char *szFname )
|
122
|
-
{
|
123
|
-
fprintf( output_file, fmt, szFname );
|
124
|
-
}
|
125
|
-
/************** copied from util.c *********************************/
|
126
|
-
char *e_fgetsTab( char *szLine, int len, FILE *f );
|
127
|
-
/*******************************************************************/
|
128
|
-
/* read up to len or tab or LF; if empty read next until finds non-empty line */
|
129
|
-
/* remove leading and trailing white spaces; keep zero termination */
|
130
|
-
/*******************************************************************/
|
131
|
-
char *e_fgetsTab( char *szLine, int len, FILE *f )
|
132
|
-
{
|
133
|
-
int length=0, c;
|
134
|
-
len --;
|
135
|
-
while ( length < len && EOF != (c = fgetc( f )) ) {
|
136
|
-
if ( c == '\t' )
|
137
|
-
c = '\n';
|
138
|
-
szLine[length++] = (char)c;
|
139
|
-
if ( c == '\n' )
|
140
|
-
break;
|
141
|
-
}
|
142
|
-
if ( !length && EOF == c ) {
|
143
|
-
return NULL;
|
144
|
-
}
|
145
|
-
szLine[length] = '\0';
|
146
|
-
return szLine;
|
147
|
-
}
|
148
|
-
/*******************************************************************/
|
149
|
-
/* read up to len or tab or LF; if empty read next until finds non-empty line */
|
150
|
-
/* remove leading and trailing white spaces; keep zero termination */
|
151
|
-
/*******************************************************************/
|
152
|
-
int e_my_fgetsTab( char *szLine, int len, FILE *f, int *bTooLongLine )
|
153
|
-
{
|
154
|
-
int length;
|
155
|
-
char *p;
|
156
|
-
do {
|
157
|
-
p = e_fgetsTab( szLine, len-1, f );
|
158
|
-
if ( !p ) {
|
159
|
-
*bTooLongLine = 0;
|
160
|
-
return -1; /* end of file or cannot read */
|
161
|
-
}
|
162
|
-
szLine[len-1] = '\0';
|
163
|
-
/*
|
164
|
-
*bTooLongLine = !strchr( szLine, '\n' );
|
165
|
-
*/
|
166
|
-
p = strchr( szLine, '\n' );
|
167
|
-
*bTooLongLine = ( !p && ((int)strlen(szLine)) == len-2 );
|
168
|
-
LtrimRtrim( szLine, &length );
|
169
|
-
} while ( !length );
|
170
|
-
return length;
|
171
|
-
}
|
172
|
-
/*******************************************************************/
|
173
|
-
int e_my_fgetsTab1( char *szLine, int len, FILE *f, int *bTooLongLine )
|
174
|
-
{
|
175
|
-
int length;
|
176
|
-
char *p;
|
177
|
-
/*do {*/
|
178
|
-
p = e_fgetsTab( szLine, len-1, f );
|
179
|
-
if ( !p ) {
|
180
|
-
*bTooLongLine = 0;
|
181
|
-
return -1; /* end of file or cannot read */
|
182
|
-
}
|
183
|
-
szLine[len-1] = '\0';
|
184
|
-
/*
|
185
|
-
*bTooLongLine = !strchr( szLine, '\n' );
|
186
|
-
*/
|
187
|
-
p = strchr( szLine, '\n' );
|
188
|
-
*bTooLongLine = ( !p && ((int)strlen(szLine)) == len-2 );
|
189
|
-
LtrimRtrim( szLine, &length );
|
190
|
-
/*} while ( !length );*/
|
191
|
-
return length;
|
192
|
-
}
|
193
|
-
/******************************************************************/
|
194
|
-
/* read not more than line_len bytes from an lf-terminated line */
|
195
|
-
/* if input line is too long quietly ignore the rest of the line */
|
196
|
-
char* fgets_up_to_lf( char* line, int line_len, FILE* inp )
|
197
|
-
{
|
198
|
-
char *p, *q;
|
199
|
-
memset( line, 0, line_len );
|
200
|
-
if ( NULL != (p = fgets( line, line_len, inp ) ) && NULL == strchr(p, '\n' ) ){
|
201
|
-
char temp[64]; /* bypass up to '\n' or up to end of file whichever comes first*/
|
202
|
-
while ( NULL != fgets( temp, sizeof(temp), inp ) && NULL == strchr(temp,'\n') )
|
203
|
-
;
|
204
|
-
}
|
205
|
-
if ( p && (q = strchr(line, '\r')) ) { /* fix CR CR LF line terminator. */
|
206
|
-
q[0] = '\n';
|
207
|
-
q[1] = '\0';
|
208
|
-
}
|
209
|
-
return p;
|
210
|
-
}
|
211
|
-
/********************************************************************/
|
212
|
-
int my_fgetsUpToLfOrTab( char *szLine, int len, FILE *f )
|
213
|
-
{
|
214
|
-
int length;
|
215
|
-
char *p;
|
216
|
-
char szSkip[256];
|
217
|
-
int bTooLongLine = 0;
|
218
|
-
do {
|
219
|
-
p = e_fgetsTab( szLine, len-1, f );
|
220
|
-
if ( !p ) {
|
221
|
-
return -1; /* end of file or cannot read */
|
222
|
-
}
|
223
|
-
szLine[len-1] = '\0';
|
224
|
-
/*
|
225
|
-
bTooLongLine = !strchr( szLine, '\n' );
|
226
|
-
*/
|
227
|
-
bTooLongLine = ( !p && ((int)strlen(szLine)) == len-2 );
|
228
|
-
LtrimRtrim( szLine, &length );
|
229
|
-
} while ( !length );
|
230
|
-
if ( bTooLongLine ) {
|
231
|
-
while ( p = e_fgetsTab( szSkip, sizeof(szSkip)-1, f ) ) {
|
232
|
-
szSkip[sizeof(szSkip)-1] = '\0';
|
233
|
-
if ( strchr( szSkip, '\n' ) )
|
234
|
-
break;
|
235
|
-
}
|
236
|
-
}
|
237
|
-
return length;
|
238
|
-
}
|
239
|
-
|
240
|
-
|
241
|
-
#ifdef INCHI_ANSI_ONLY
|
242
|
-
|
243
|
-
static clock_t InchiClock(void);
|
244
|
-
|
245
|
-
#ifdef INCHI_USETIMES
|
246
|
-
static clock_t InchiClock(void)
|
247
|
-
{
|
248
|
-
struct tms buf;
|
249
|
-
clock_t c = times( &buf );
|
250
|
-
if ( c != (clock_t)-1 ) {
|
251
|
-
return buf.tms_utime;
|
252
|
-
}
|
253
|
-
return 0;
|
254
|
-
}
|
255
|
-
#else
|
256
|
-
static clock_t InchiClock(void)
|
257
|
-
{
|
258
|
-
clock_t c = clock();
|
259
|
-
if ( c != (clock_t)-1 ) {
|
260
|
-
return c;
|
261
|
-
}
|
262
|
-
return 0;
|
263
|
-
}
|
264
|
-
#endif
|
265
|
-
|
266
|
-
#define INCHI_MSEC(X) (long)((1000.0/(double)CLOCKS_PER_SEC)*(X))
|
267
|
-
#define INCHI_CLOCK_T(X) (clock_t)( (double)(X) / 1000.0 * (double)CLOCKS_PER_SEC )
|
268
|
-
const clock_t FullMaxClock = (clock_t)(-1);
|
269
|
-
const clock_t HalfMaxClock = (clock_t)(-1) / 2;
|
270
|
-
clock_t MaxPositiveClock = 0;
|
271
|
-
clock_t MinNegativeClock = 0;
|
272
|
-
clock_t HalfMaxPositiveClock = 0;
|
273
|
-
clock_t HalfMinNegativeClock = 0;
|
274
|
-
|
275
|
-
static void FillMaxMinClock(void); /* keep compiler happy */
|
276
|
-
|
277
|
-
static void FillMaxMinClock(void)
|
278
|
-
{
|
279
|
-
if ( !MaxPositiveClock ) {
|
280
|
-
clock_t valPos, val1 = 1;
|
281
|
-
while ( 0 < ((val1 <<= 1), (val1 |= 1)) ) {
|
282
|
-
valPos = val1;
|
283
|
-
}
|
284
|
-
MaxPositiveClock = valPos;
|
285
|
-
MinNegativeClock = -valPos;
|
286
|
-
HalfMaxPositiveClock = MaxPositiveClock / 2;
|
287
|
-
HalfMinNegativeClock = MinNegativeClock / 2;
|
288
|
-
}
|
289
|
-
}
|
290
|
-
|
291
|
-
|
292
|
-
/******** get current process time ****************************************/
|
293
|
-
void InchiTimeGet( inchiTime *TickEnd )
|
294
|
-
{
|
295
|
-
TickEnd->clockTime = InchiClock();
|
296
|
-
}
|
297
|
-
/******** returns difference TickEnd - TickStart in milliseconds **********/
|
298
|
-
long InchiTimeMsecDiff( inchiTime *TickEnd, inchiTime *TickStart )
|
299
|
-
{
|
300
|
-
if ( FullMaxClock > 0 ) {
|
301
|
-
clock_t delta;
|
302
|
-
if ( !TickEnd || !TickStart )
|
303
|
-
return 0;
|
304
|
-
/* clock_t is unsigned */
|
305
|
-
if ( TickEnd->clockTime > TickStart->clockTime ) {
|
306
|
-
if ( TickEnd->clockTime > HalfMaxClock &&
|
307
|
-
TickEnd->clockTime - TickStart->clockTime > HalfMaxClock ) {
|
308
|
-
/* overflow in TickStart->clockTime, actually TickStart->clockTime was later */
|
309
|
-
delta = (FullMaxClock - TickEnd->clockTime) + TickStart->clockTime;
|
310
|
-
return -INCHI_MSEC(delta);
|
311
|
-
}
|
312
|
-
delta = TickEnd->clockTime - TickStart->clockTime;
|
313
|
-
return INCHI_MSEC(delta);
|
314
|
-
} else
|
315
|
-
if ( TickEnd->clockTime < TickStart->clockTime ) {
|
316
|
-
if ( TickStart->clockTime > HalfMaxClock &&
|
317
|
-
TickStart->clockTime - TickEnd->clockTime > HalfMaxClock ) {
|
318
|
-
/* overflow in TickEnd->clockTime, actually TickEnd->clockTime was later */
|
319
|
-
delta = (FullMaxClock - TickStart->clockTime) + TickEnd->clockTime;
|
320
|
-
return INCHI_MSEC(delta);
|
321
|
-
}
|
322
|
-
delta = TickStart->clockTime - TickEnd->clockTime;
|
323
|
-
return -INCHI_MSEC(delta);
|
324
|
-
}
|
325
|
-
return 0; /* TickEnd->clockTime == TickStart->clockTime */
|
326
|
-
} else {
|
327
|
-
/* may happen under Win32 only where clock_t is SIGNED long */
|
328
|
-
clock_t delta;
|
329
|
-
FillMaxMinClock( );
|
330
|
-
if ( !TickEnd || !TickStart )
|
331
|
-
return 0;
|
332
|
-
if ( TickEnd->clockTime >= 0 && TickStart->clockTime >= 0 ||
|
333
|
-
TickEnd->clockTime <= 0 && TickStart->clockTime <= 0) {
|
334
|
-
delta = TickEnd->clockTime - TickStart->clockTime;
|
335
|
-
} else
|
336
|
-
if ( TickEnd->clockTime >= HalfMaxPositiveClock &&
|
337
|
-
TickStart->clockTime <= HalfMinNegativeClock ) {
|
338
|
-
/* end is earlier than start */
|
339
|
-
delta = (MaxPositiveClock - TickEnd->clockTime) + (TickStart->clockTime - MinNegativeClock);
|
340
|
-
delta = -delta;
|
341
|
-
} else
|
342
|
-
if ( TickEnd->clockTime <= HalfMinNegativeClock &&
|
343
|
-
TickStart->clockTime >= HalfMaxPositiveClock ) {
|
344
|
-
/* start was earlier than end */
|
345
|
-
delta = (MaxPositiveClock - TickStart->clockTime) + (TickEnd->clockTime - MinNegativeClock);
|
346
|
-
} else {
|
347
|
-
/* there was no overflow, clock passed zero */
|
348
|
-
delta = TickEnd->clockTime - TickStart->clockTime;
|
349
|
-
}
|
350
|
-
return INCHI_MSEC(delta);
|
351
|
-
}
|
352
|
-
}
|
353
|
-
/******************* get elapsed time from TickStart ************************/
|
354
|
-
long InchiTimeElapsed( inchiTime *TickStart )
|
355
|
-
{
|
356
|
-
inchiTime TickEnd;
|
357
|
-
if ( !TickStart )
|
358
|
-
return 0;
|
359
|
-
InchiTimeGet( &TickEnd );
|
360
|
-
return InchiTimeMsecDiff( &TickEnd, TickStart );
|
361
|
-
}
|
362
|
-
/******************* add number of milliseconds to time *********************/
|
363
|
-
void InchiTimeAddMsec( inchiTime *TickEnd, unsigned long nNumMsec )
|
364
|
-
{
|
365
|
-
clock_t delta;
|
366
|
-
if ( !TickEnd )
|
367
|
-
return;
|
368
|
-
if ( FullMaxClock > 0 ) {
|
369
|
-
/* clock_t is unsigned */
|
370
|
-
delta = INCHI_CLOCK_T(nNumMsec);
|
371
|
-
TickEnd->clockTime += delta;
|
372
|
-
} else {
|
373
|
-
/* may happen under Win32 only where clock_t is SIGNED long */
|
374
|
-
/* clock_t is unsigned */
|
375
|
-
FillMaxMinClock( );
|
376
|
-
delta = INCHI_CLOCK_T(nNumMsec);
|
377
|
-
TickEnd->clockTime += delta;
|
378
|
-
}
|
379
|
-
}
|
380
|
-
/******************* check whether time has expired *********************/
|
381
|
-
int bInchiTimeIsOver( inchiTime *TickStart )
|
382
|
-
{
|
383
|
-
if ( FullMaxClock > 0 ) {
|
384
|
-
clock_t clockCurrTime;
|
385
|
-
if ( !TickStart )
|
386
|
-
return 0;
|
387
|
-
clockCurrTime = InchiClock();
|
388
|
-
/* clock_t is unsigned */
|
389
|
-
if ( TickStart->clockTime > clockCurrTime ) {
|
390
|
-
if ( TickStart->clockTime > HalfMaxClock &&
|
391
|
-
TickStart->clockTime - clockCurrTime > HalfMaxClock ) {
|
392
|
-
/* overflow in clockCurrTime, actually clockCurrTime was later */
|
393
|
-
return 1;
|
394
|
-
}
|
395
|
-
return 0;
|
396
|
-
} else
|
397
|
-
if ( TickStart->clockTime < clockCurrTime ) {
|
398
|
-
if ( clockCurrTime > HalfMaxClock &&
|
399
|
-
clockCurrTime - TickStart->clockTime > HalfMaxClock ) {
|
400
|
-
/* overflow in TickStart->clockTime, actually TickStart->clockTime was later */
|
401
|
-
return 0;
|
402
|
-
}
|
403
|
-
return 1;
|
404
|
-
}
|
405
|
-
return 0; /* TickStart->clockTime == clockCurrTime */
|
406
|
-
} else {
|
407
|
-
/* may happen under Win32 only where clock_t is SIGNED long */
|
408
|
-
clock_t clockCurrTime;
|
409
|
-
FillMaxMinClock( );
|
410
|
-
if ( !TickStart )
|
411
|
-
return 0;
|
412
|
-
clockCurrTime = InchiClock();
|
413
|
-
if ( clockCurrTime >= 0 && TickStart->clockTime >= 0 ||
|
414
|
-
clockCurrTime <= 0 && TickStart->clockTime <= 0) {
|
415
|
-
return (clockCurrTime > TickStart->clockTime);
|
416
|
-
} else
|
417
|
-
if ( clockCurrTime >= HalfMaxPositiveClock &&
|
418
|
-
TickStart->clockTime <= HalfMinNegativeClock ) {
|
419
|
-
/* curr is earlier than start */
|
420
|
-
return 0;
|
421
|
-
} else
|
422
|
-
if ( clockCurrTime <= HalfMinNegativeClock &&
|
423
|
-
TickStart->clockTime >= HalfMaxPositiveClock ) {
|
424
|
-
/* start was earlier than curr */
|
425
|
-
return 1;
|
426
|
-
} else {
|
427
|
-
/* there was no overflow, clock passed zero */
|
428
|
-
return (clockCurrTime > TickStart->clockTime);
|
429
|
-
}
|
430
|
-
}
|
431
|
-
}
|
432
|
-
|
433
|
-
#else
|
434
|
-
|
435
|
-
/******** get current process time ****************************************/
|
436
|
-
void InchiTimeGet( inchiTime *TickEnd )
|
437
|
-
{
|
438
|
-
if ( TickEnd ) {
|
439
|
-
struct _timeb timeb;
|
440
|
-
_ftime( &timeb );
|
441
|
-
TickEnd->clockTime = (unsigned long)timeb.time;
|
442
|
-
TickEnd->millitime = (long)timeb.millitm;
|
443
|
-
}
|
444
|
-
}
|
445
|
-
/******** returns difference TickEnd - TickStart in milliseconds **********/
|
446
|
-
long InchiTimeMsecDiff( inchiTime *TickEnd, inchiTime *TickStart )
|
447
|
-
{
|
448
|
-
long delta;
|
449
|
-
if ( !TickEnd || !TickStart ) {
|
450
|
-
return 0;
|
451
|
-
}
|
452
|
-
if ( TickEnd->clockTime >= TickStart->clockTime ) {
|
453
|
-
delta = (long)(TickEnd->clockTime - TickStart->clockTime);
|
454
|
-
delta *= 1000;
|
455
|
-
delta += TickEnd->millitime - TickStart->millitime;
|
456
|
-
} else {
|
457
|
-
delta = -(long)(TickStart->clockTime - TickEnd->clockTime);
|
458
|
-
delta *= 1000;
|
459
|
-
delta += TickEnd->millitime - TickStart->millitime;
|
460
|
-
}
|
461
|
-
return delta;
|
462
|
-
}
|
463
|
-
/******************* get elapsed time from TickStart ************************/
|
464
|
-
long InchiTimeElapsed( inchiTime *TickStart )
|
465
|
-
{
|
466
|
-
inchiTime TickEnd;
|
467
|
-
if ( !TickStart )
|
468
|
-
return 0;
|
469
|
-
InchiTimeGet( &TickEnd );
|
470
|
-
return InchiTimeMsecDiff( &TickEnd, TickStart );
|
471
|
-
}
|
472
|
-
/******************* add number of milliseconds to time *********************/
|
473
|
-
void InchiTimeAddMsec( inchiTime *TickEnd, unsigned long nNumMsec )
|
474
|
-
{
|
475
|
-
long delta;
|
476
|
-
if ( !TickEnd )
|
477
|
-
return;
|
478
|
-
TickEnd->clockTime += nNumMsec / 1000;
|
479
|
-
delta = nNumMsec % 1000 + TickEnd->millitime;
|
480
|
-
TickEnd->clockTime += delta / 1000;
|
481
|
-
TickEnd->millitime = delta % 1000;
|
482
|
-
}
|
483
|
-
/******************* check whether time has expired *********************/
|
484
|
-
int bInchiTimeIsOver( inchiTime *TickEnd )
|
485
|
-
{
|
486
|
-
struct _timeb timeb;
|
487
|
-
if ( !TickEnd )
|
488
|
-
return 0;
|
489
|
-
_ftime( &timeb );
|
490
|
-
if ( TickEnd->clockTime > (unsigned long)timeb.time )
|
491
|
-
return 0;
|
492
|
-
if ( TickEnd->clockTime < (unsigned long)timeb.time ||
|
493
|
-
TickEnd->millitime < (long)timeb.millitm ) {
|
494
|
-
return 1;
|
495
|
-
}
|
496
|
-
return 0;
|
497
|
-
}
|
498
|
-
#endif
|