Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

strlib.h File Reference

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "common.h"

Go to the source code of this file.

Functions

void NAMD_truncate (char *)
int NAMD_read_line (FILE *, char *)
int NAMD_find_word (const char *, const char *)
int NAMD_blank_string (char *)
void NAMD_find_first_word (char *, char *)
int NAMD_read_int (FILE *, const char *)
void NAMD_pad (char *, size_t)
void NAMD_remove_comment (char *)


Function Documentation

int NAMD_blank_string char *   ) 
 

Definition at line 217 of file strlib.C.

Referenced by Molecule::build_extra_bonds(), getAtomData(), getExtraBonds(), Parameters::read_charmm_parameter_file(), Parameters::read_parameter_file(), Molecule::read_psf_file(), and readPsfFile().

00218 {
00219         int i;          // Current position in str
00220         int blank=1;    // Flag 1-> string is blank
00221         int len;        // length of the string str
00222 
00223         len=strlen(str);
00224 
00225         for (i=0; i<len && blank; i++)
00226         {
00227                 blank = isspace(str[i]);
00228         }
00229 
00230         return(blank);
00231 }

void NAMD_find_first_word char *  ,
char * 
 

Definition at line 253 of file strlib.C.

Referenced by Parameters::read_charmm_parameter_file(), and Parameters::read_parameter_file().

00255 {
00256         int i=0;        //  Position within source
00257         int j=0;        //  Position within word
00258 
00259         /*  Skip leading white space                                    */
00260         while ( (source[i] != STRINGNULL) && isspace(source[i]))
00261                 i++;
00262 
00263         /*  Copy the word                                               */
00264         while ( (source[i] != STRINGNULL) && !isspace(source[i]))
00265         {
00266                 word[j]=source[i];
00267                 i++;
00268                 j++;
00269         }
00270 
00271         word[j]=STRINGNULL;
00272 
00273         return;
00274 }

int NAMD_find_word const char *  ,
const char * 
 

Definition at line 175 of file strlib.C.

Referenced by Molecule::read_psf_file(), and readPsfFile().

00177 {
00178         int i=0;                //  Position inside source
00179         int search_length;      //  Length of string search
00180         int source_length;      //  Length of string source
00181         int found=0;            //  Flag 1-> found the value
00182 
00183         search_length=strlen(search);
00184         source_length=strlen(source);
00185 
00186         /*  While we haven't found it and we haven't readched the      */
00187         /*  point where our current position plus the length of the    */
00188         /*  string we are looking for is longer than the string itself,*/
00189         /*  check the next search_length characters for a match        */
00190         while (!found && ((i+search_length)<=(source_length)))
00191         {
00192                 found = (strncasecmp(source+i, search, search_length)==0);
00193 
00194                 i++;
00195         }
00196 
00197         return(found);
00198 }

void NAMD_pad char *  ,
size_t 
 

Definition at line 377 of file strlib.C.

00379 {
00380         char tmp_string[128];
00381         size_t i;
00382 
00383         if (strlen(str) >= length)
00384                 return;
00385 
00386         for (i=0; i<(length-strlen(str)); i++)
00387         {
00388                 tmp_string[i] = ' ';
00389         }
00390 
00391         tmp_string[i] = STRINGNULL;
00392 
00393         strcat(str, tmp_string);
00394 }

int NAMD_read_int FILE *  ,
const char * 
 

Definition at line 297 of file strlib.C.

References NAMD_die().

Referenced by getAcceptorData(), getAngleData(), getBondData(), getCrosstermData(), getDihedralData(), getDonorData(), and getImproperData().

00299 {
00300         int i;                  //  Loop counter
00301         int c;                  //  Character read in from file
00302         char tmp_string[11];    //  Temporary string for integer
00303         int isNeg;
00304     
00305         /*  Skip white space                            */
00306         while ( ((c=fgetc(fd)) == '\n') || isspace(c) )
00307         {
00308         }
00309 
00310         /*  Check to make sure we didn't hit EOF        */
00311         if (c==EOF)
00312         {
00313                 char err_msg[128];
00314 
00315                 sprintf(err_msg, "EOF ENCOUNTERED READING %s FROM PSF FILE", msg);
00316                 NAMD_die(err_msg);
00317         }
00318 
00319         /*  Now read in the integer itself              */
00320         i=0;
00321 
00322         /* Modified to read an integer with '-' or '+' sign --Chao Mei */
00323         isNeg = 0;
00324         if(c=='-'){
00325             c = fgetc(fd);
00326             isNeg = 1;
00327         }
00328         if(c=='+')
00329             c = fgetc(fd);
00330                 
00331 
00332         while (!isspace(c))
00333         {
00334                 /*  Check to make sure we only get #'s  */
00335                 if (!isdigit(c))
00336                 {
00337                         char err_msg[128];
00338 
00339                         sprintf(err_msg, "ALPHA CHARCTER ENCOUNTERED WHILE READING %s FROM PSF FILE", msg);
00340                         NAMD_die(err_msg);
00341                 }
00342 
00343                 tmp_string[i] = c;
00344                 i++;
00345 
00346                 c=fgetc(fd);
00347 
00348                 /*  Check to make sure we didn't hit EOF*/
00349                 if (c==EOF)
00350                 {
00351                         char err_msg[128];
00352 
00353                         sprintf(err_msg, "EOF ENCOUNTERED WHILE READING %s FROM PSF FILE", msg);
00354                         NAMD_die(err_msg);
00355                 }
00356         }
00357 
00358         tmp_string[i]=STRINGNULL;
00359 
00360         /*  Convert the string to an integer and return its value       */
00361         if(isNeg)
00362             return(-atoi(tmp_string));
00363         else
00364            return(atoi(tmp_string));
00365 }

int NAMD_read_line FILE *  fd,
char *  buf
 

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 38 of file strlib.C.

References NAMD_die().

Referenced by Molecule::build_extra_bonds(), getAtomData(), getExtraBonds(), Parameters::read_charmm_parameter_file(), Parameters::read_parameter_file(), Molecule::read_psf_file(), and readPsfFile().

00040 {
00041         int i=0;        //  Current position in buf
00042         int c;          //  Character read in from file
00043 
00044         /*  Loop and read characters until we get either an EOF or a    */
00045         /*  newline                                                     */
00046         while ( ((c=fgetc(fd)) != EOF) && (c != '\n') )
00047         {
00048                 /*  If we encounter a bracketed comment, skip it.  This */
00049                 /*  basically means read EVERYTHING until the next } and*/
00050                 /*  throw it into the big bit bucket                    */
00051                 if (c == '{')
00052                 {
00053                         while ( ((c=fgetc(fd)) != EOF) && (c!='}') )
00054                         {
00055                         }
00056 
00057                         if (c==EOF)
00058                         {
00059                                 char err_msg[512];
00060 
00061                                 sprintf(err_msg, "ABNORMAL EOF FOUND - buffer=*%s*\n", 
00062                                    buf);
00063                                 NAMD_die(err_msg);
00064                         }
00065 
00066                         continue;
00067                 }
00068 
00069                 /*  Also, use this little piece of logic to remove      */
00070                 /*  any leading spaces from the line                    */
00071                 if ((i>0) || !isspace(c))
00072                 {
00073                         buf[i] = c;
00074         
00075                         i++;
00076                 }
00077         }
00078 
00079         /*  NULL terminate the string                                   */
00080         buf[i]=STRINGNULL;
00081 
00082         /*  Check for an EOF in the middle of a line                    */
00083         if ((c==EOF) && (i!=0))
00084         {
00085                 char err_msg[512];
00086 
00087                 sprintf(err_msg, "ABNORMAL EOF FOUND - buffer=*%s*\n", 
00088                    buf);
00089                 NAMD_die(err_msg);
00090         }
00091 
00092         /*  Return the appropriate value                                */
00093         if (c==EOF)
00094                 return(-1);
00095         else
00096                 return(0);
00097 }

void NAMD_remove_comment char *   ) 
 

Definition at line 114 of file strlib.C.

00116 {
00117         int i=0;
00118 
00119         while ( (str[i] != STRINGNULL) && (str[i] != '!') )
00120         {
00121                 i++;
00122         }
00123 
00124         str[i] = STRINGNULL;
00125 }

void NAMD_truncate char *   ) 
 

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 140 of file strlib.C.

00142 {
00143         int i;          //  Current position in str
00144 
00145         i=strlen(str);
00146 
00147         /*  Loop from the back of the string until we find a non-space  */
00148         for (i--; i>=0 && isspace(str[i]); i--)
00149         {
00150         }
00151         
00152         str[i+1]=STRINGNULL;
00153 }


Generated on Sat Oct 11 04:07:44 2008 for NAMD by  doxygen 1.3.9.1