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