⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 driver.c

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef LINTstatic char vcid[] = "$Id: driver.c,v 1.1.1.1 1997/09/17 20:38:46 gropp Exp $";#endif#include <ctype.h>#include "tools.h"#include "doc.h"#include "expandingList.h"/*    This is designed to work with comments in C programs.     It uses the standardized documentation to issue dummy routine   definitions to allow the creation of a Fortran to C library.   This version of "header.c" is a modification of the file taken    from "~gropp/tools.n/c2fort" on 10/7/93.  Modifications have been    introduced so that elements of type void * in the files "nlfunc_v.h",    and "nlspmat_v.h", and "nlsles_v.h" are translated as pointers to    structures in the Fortran version (instead of the default, which is   no translation).  Note that pointers to void functions retain the    usual translation.     An additional flag (flag2) is used in the calling sequence of    ProcessArgDefs() to indicate the files which require the modified    translation.   Also, an additional element, void_function, is added    to the structure ARG_LIST to distinguish pointers to void functions    from pointers to void structures.   */extern char GetSubClass();static int NoFortMsgs = 1;/* NoFortWarnings turns off messages about things not being available in   Fortran */static int NoFortWarnings = 1;/* This says to convert char **a to int*a, and cast to (char **)*a */static int MultipleIndirectAreInts    = 1;static int MultipleIndirectsAreNative = 0;/* static int MultipleIndirects *//* Keep the file name to simplify finding files containing problems */static char *CurrentFilename = 0;/* Whether to replace pointers with indices to a mapping of pointers */static int MapPointers = 0;/* If this is set to true, "void *" are translated as pointers to structures *//* NOT YET IMPLEMENTED */static int TranslateVoidStar = 0;/* If true, add a last integer argument to int functions and return its   value in the last parameter */static int useFerr = 0;/* Enable the MPI definitions */static int isMPI = 0;/*D  bfort - program to extract short definitions for a Fortran to C interface  Input:. filenames - Names the files from which lint definitions are to be extracted. -nomsgs   - Do not generate messages for routines that can not be converted              to Fortran.. -nofort   - Generate messages for all routines/macros without a Fortran              counterpart.. -dir name - Directory for output file. -I name   - file that contains common includes. -mapptr   - translate pointers to integer indices. -ferr     - Fortran versions return the value of the routine as the last              argument (an integer).  This is used in MPI and is a not 	      uncommon approach for handling error returns.. -mpi      - Handle MPI datatypes (some things are pointers by definition). -mnative  - Multiple indirects are native datatypes (no coercion)  Note:  We really need a way to specify a general type as a pointer, so that it  will be handled as a pointer.  The -mpi option is a kludge for a a pressing  need.  Eventually should provide a "-ptr name" option and keep in a   search space when looking for known types.  Author:   Bill GroppD*/main( argc, argv )int  argc;char **argv;{char routine[MAX_ROUTINE_NAME];char *infilename;char outfilename[1024];char dirname[1024];char fname[1024], *p;FILE *fd, *fout, *incfd;int  nread;char kind;char incfile[MAX_FILE_SIZE];char incbuffer[1024];char prefix [100];xpandList wrapperFiles;int argnum;ListCreate( wrapperFiles, char *, 5 );while ((argnum = SYArgFindName( argc, argv, "-w" )) > 0) {  ListAddItem( wrapperFiles, char *, argv[argnum+1] );#if DEBUG  fprintf( stderr, "Adding %s as a wrapper file.\n", argv[argnum+1] );#endif  argv[argnum] = argv[argnum+1] = 0;  SYArgSqueeze( &argc, argv );}/* gather all the wrapper definition filenames *//* process all of the files */strcpy( dirname, "." );incfile[0]  = 0;if (SYArgHasName( &argc, argv, 1, "-h" ) || argc<3) {  PrintHelp( argv );}StoreFunctionInit( ListHeadPtr( wrapperFiles, char * ),		   ListSize( wrapperFiles, char * ),		   argv[1], argv[2] ); argc-=3; argv+=3;  /* get ready to start storing function information */  /* argv[1] should be the function list file */  /* argv[2] should be the output file */while (argc--) {    /* Input filename */    infilename = *argv++;    fd = fopen( infilename, "r" );    if (!fd) {      fprintf( stderr, "Could not open file %s\n", infilename );      continue;    } else    /* Remember file name */    CurrentFilename = infilename;    /* Set the output filename */    SYGetRelativePath( infilename, fname, 1024 );    /* Strip the trailer */    p = fname + strlen(fname) - 1;    while (p > fname && *p != '.') p--;    *p = 0;    /* Add an extra h to include files */    if (p[1] == 'h') {	p[0] = 'h';	p[1] = 0;	}    sprintf( outfilename, "%s/%s_prof.c", dirname, fname );    /* Don't open the filename yet (wait until we know that we'll have       some output for it) */    fout = NULL;    while (FoundLeader( fd, routine, &kind )) {	/* We need this test first to avoid creating an empty file, 	   particularly for initf.c */	if (kind == ROUTINE) {	    OutputRoutine( fd, fout, routine, infilename, kind, prefix );	    }	}    fclose( fd );    if (fout) {	fclose( fout );	}    }FunctionOutput();return 0;}/* We also need to make some edits to the types occasionally.  First, note   that double indirections are often bugs */typedef struct {    char *name;    int  has_star, is_char, is_native, type, is_FILE, void_function;    int  implied_star;    } ARG_LIST;typedef struct {    char type[60];    } TYPE_LIST;typedef struct {    char name[60];    int  num_stars;    } RETURN_TYPE;OutputRoutine( fin, fout, name, filename, kind, prefix )FILE *fin, *fout;char *name, *filename, kind, *prefix;{int         is_function;ARG_LIST    args[512];TYPE_LIST   types[60];RETURN_TYPE rt;int         nargs, nstrings;int         ntypes;int         flag2 = 0;/* Skip to trailer */SkipText( fin, name, filename, kind );/* Get the call to the routine, including finding the argument names */SkipWhite( fin );ProcessArgList( fin, fout, filename, &is_function, name, 	        args, &nargs, &rt, 0 );SkipWhite( fin );ProcessArgDefs( fin, fout, args, nargs, types, &ntypes, &nstrings, 0,                 name, flag2 );StoreFunction( name, args, nargs, types, &rt );}/*    This routine skips the text part of a text page. */        SkipText( fin, name, filename, kind )FILE *fin;char *name, *filename;char kind;{int  c;char lineBuffer[MAX_LINE], *lp;	lineBuffer[0] = '+';   /* Sentinal on lineBuffer */while (1) {    lp = lineBuffer + 1;    c  = getc( fin );    if (c == EOF) break;    if (c == ARGUMENT || c == VERBATIM)	SkipLine( fin );    else if (c == '\n')	;    else {	if (isspace(c) && c != '\n')	    SkipWhite( fin );	else 	    *lp++ = c;    	/* Copy to end of line; do NOT include the EOL */    	while ((c = getc( fin )) != EOF && c != '\n')     	    *lp++ = c;    	lp--;    	while (isspace(*lp)) lp--;    	lp[1] = '\0';    /* Add the trailing null */    	if (lineBuffer[1] == kind && strcmp(lineBuffer+2,"*/") == 0)    	    break;        }    }}#if 0/* Convert a string to lower case, in place */LowerCase( s )char *s;{char c;while (*s) {    c = *s;    if (isascii(c) && isupper(c)) *s = tolower(c);    s++;    }}#endif/* Find the next space delimited token; put the text into token.   The number of leading spaces is kept in nsp.   Alpha-numeric tokens are terminated by a non-alphanumeric character   (_ is allowed in alpha-numeric tokens) */int FindNextANToken( fd, token, nsp )FILE *fd;char *token;int  *nsp;{int fc, c, Nsp;Nsp = SkipWhite( fd );fc = c = getc( fd );if (fc == EOF) return fc;*token++ = c;if (isalnum(c) || c == '_') {    while ((c = getc( fd )) != EOF) {	if (c != '\n' && (isalnum(c) || c == '_')) *token++ = c;	else break;	}    ungetc( (char)c, fd );    }*token++ = '\0';*nsp     = Nsp;return fc;}/* Read the arg list and function type */ProcessArgList( fin, fout, filename, is_function, name, args, Nargs, rt, flag )FILE        *fin, *fout;char        *filename, *name;ARG_LIST    args[512];RETURN_TYPE *rt;int         *Nargs;int         *is_function, flag;{int             c;char            token[1024], *p;int             i, nsp, bl, leadingm;static char     rcall[1024];int             nargs, ln, in_args;int             reading_function_type = 0;int             found_name;SkipWhite( fin );nargs       = 0;in_args     = 0;p           = rcall;c           = FindNextANToken( fin, p, &nsp );/*    We check for routines that return (functions) versus ones that don't   by looking for "void".  A special case is functions that return    pointers to void; we check for these by looking at the first character   of the first token after the void.   We also want to defer generating the function type incase we need to 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -