/*cdRead routine to read in command lines when cloudy used as subroutine */ #include #include "cddefines.h" #include "input.h" #include "optimr.h" #include "vary.h" #include "trace.h" #include "lgmatch.h" #include "caps.h" #include "cddrive.h" int cdRead(char *chInputLine) /* the string containing the commands */ /* returns the number of lines available in command stack * this is limit to how many more commands can be read */ { char *chEOL , /* will be used to seach for end of line symbols */ chCARD[81]; # ifdef DEBUG_FUN fputs( "<+>cdRead()\n", debug_fp ); # endif /* this is set FALSE when code loaded, set TRUE when cdInit called, * this is check that cdInit was called first */ if( !lgcdInitCalled ) { printf(" cdInit was not called first - this must be the first call.\n"); puts( "[Stop in cdRead]" ); exit(1); } /* totally ignore any card starting with a #, *, space, //, or % */ if( (chInputLine[0]=='#') || (chInputLine[0]=='*') || (chInputLine[0]=='%') || (chInputLine[0]=='\n')|| (chInputLine[0]==' ') || (strncmp(chInputLine,"//", 2 )==0 ) ) { /* return value is number of lines that can still be stuffed in */ return(NKRD - input.nSave); } /*************************************************************************** * validate a location to store this line image, then store the version * * that has been truncated from special end of line characters * * stored image will have <=80 valid characters * ***************************************************************************/ /* this will now point to the next free slot in the line image save array * this is where we will stuff this line image */ ++input.nSave; if( input.nSave >= NKRD ) { /* too many input commands were entered - bail */ fprintf( ioQQQ, " Too many line images entered to cdRead. The limit is%5d\n", NKRD ); fprintf( ioQQQ, " The limit to the number of allowed input lines is%4d. This limit was exceeded. Sorry.\n", NKRD ); fprintf( ioQQQ, " This limit is set by the variable NKRD which appears in parameter statements throughout the code.\n" ); fprintf( ioQQQ, " Increase it everywhere it appears.\n" ); puts( "[Stop in cdRead]" ); exit(1); } /* now kill any part of line image after special end of line character, * this stops info user wants ignored from entering after here */ if( (chEOL = strchr(chInputLine , '\n' ) ) !=NULL ) { *chEOL = '\0'; } if( (chEOL = strchr(chInputLine , '%' ) ) !=NULL ) { *chEOL = '\0'; } if( (chEOL = strchr(chInputLine , ';' ) ) !=NULL ) { *chEOL = '\0'; } if( (chEOL = strstr(chInputLine , "//" ) ) !=NULL ) { *chEOL = '\0'; } /* check that there are less than 80 characters to the null character * first find the end of string mark */ chEOL = strchr(chInputLine , '\0' ); /* do something if no end of string, or if string longer than 80 characters */ if( (chEOL==NULL) || (chEOL - chInputLine)>80 ) { /* remember, in C [80] is the 81th character */ chInputLine[80] = '\0' ; /* this will generate several comments later on, so we know we had too long a line */ lgCardSavTooLong = TRUE; } /* copy string over the chCARD, then convert this to caps to chk vary*/ strcpy( chCARD, chInputLine ); caps(chCARD);/* convert to caps */ /* save string in master array for later use in readr */ strcpy( input.chCardSav[input.nSave], chInputLine ); /* check whether this is a trace command, turn on printout if so */ if( strncmp(chCARD,"TRACE",5) == 0 ) { trace.lgTraceInput = TRUE; } /* print input lines if trace specified */ if( trace.lgTraceInput ) { fprintf( ioQQQ,"cdRead=%s=\n",input.chCardSav[input.nSave] ); } /* now check whether VARY is specified */ if( lgMatch("VARY",chCARD) ) { /* a vary flag was on the line image */ vary.lgVaryOn = TRUE; } /* now check whether line is "no vary" command */ if( strncmp(chCARD,"NO VARY",7) == 0 ) { vary.lgNoVary = TRUE; } if( strncmp(chCARD,"OPTI",4) == 0 ) { /* optimize command read in */ optimr.lgOptimr = TRUE; } # ifdef DEBUG_FUN fputs( " <->cdRead()\n", debug_fp ); # endif return( NKRD - input.nSave ); }