ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mengine/src/read.c
Revision: 110
Committed: Thu Mar 12 01:43:50 2009 UTC (12 years, 1 month ago) by gilbertke
File size: 2518 byte(s)
Log Message:
further cleanup and localization of atom data
Line File contents
1 #define EXTERN extern
2
3 #include "pcwin.h"
4
5 #include <errno.h>
6
7 void * malloc_filename ( char * , char * ) ;
8 int FetchRecord(FILE *, char *);
9 FILE * fopen_path ( char * , char * , char * ) ;
10 int is_bond(int, int);
11 void message_alert(char *, char *);
12 void clean_string(char *);
13 // ========================================
14 void clean_string(char *astring)
15 {
16 int iz,i;
17 iz = strlen(astring);
18 for (i=0; i < iz; i++)
19 {
20 if (isprint(astring[i]) == 0)
21 astring[i] = ' ';
22 }
23 for (i = iz -1; i >= 0; i--)
24 {
25 if (astring[i] != ' ')
26 {
27 astring[i+1] = '\0';
28 break;
29 }
30 }
31 }
32 /*======================================================================*/
33 void * malloc_filename ( char *path , char *name )
34 {
35 int ix, iz;
36 char *filename;
37
38 ix = 0;
39 if (path != NULL)
40 ix = strlen(path);
41 iz = strlen(name);
42 filename = malloc (ix + 1 + iz + 1) ;
43 if ( ix == 0 )
44 {
45 strcpy (filename,name);
46 }
47 else
48 {
49 sprintf (filename,"%s\\%s",path,name) ;
50 }
51 return ( (void *) filename ) ;
52 }
53 /*======================================================================*/
54 FILE * fopen_path ( char *path , char *name , char *mode )
55 {
56 char *filename = malloc_filename(path,name) ;
57 FILE *rval = fopen (filename,mode) ;
58 if ( rval == NULL )
59 {
60 fprintf(pcmlogfile,"open of --%s-- failed\n",filename) ;
61 fprintf(pcmlogfile,"Error %d %s\n",errno,strerror(errno));
62 fclose(pcmlogfile);
63 exit(0);
64 }
65 free (filename) ;
66 return ( rval ) ;
67 }
68
69 /* ============================================= */
70 int FetchRecord(FILE *fp, char *buffer)
71 {
72 int ch;
73 char *ptr;
74
75 ptr = buffer;
76 do
77 {
78 ch = getc(fp);
79 if (ch >= ' ')
80 *ptr++ = ch;
81 else if (ch == '\n')
82 {
83 *ptr = 0;
84 return TRUE;
85 } else if (ch == '\r')
86 {
87 ch = getc(fp);
88 if (ch != '\n')
89 ungetc(ch,fp);
90 *ptr = 0;
91 return TRUE;
92 } else if (ch == EOF)
93 {
94 *ptr = 0;
95 return (ptr != buffer);
96 } else
97 *ptr++ = ch;
98 } while (ptr < buffer+255);
99
100 do
101 {
102 ch = getc(fp);
103 } while (ch !='\n' && ch != '\r' && ch != EOF);
104 if (ch == '\r')
105 {
106 ch = getc(fp);
107 if (ch != '\n')
108 ungetc(ch,fp);
109 }
110 *ptr = 0;
111 return TRUE;
112 }
113
114
115
116