Main Page   Compound List   File List   Compound Members   File Members  

param.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 
00004 #include <polylib/polylib.h>
00005 
00006 /****************************************************/
00007 /* Read_ParamNames() :                              */
00008 /* Reads FILE *in for the parameter names           */
00009 /* if in==NULL or not enough parameters on input,   */
00010 /*  use default names                               */
00011 /* returns an n-array of strings                    */
00012 /****************************************************/
00013 char **Read_ParamNames(FILE *in,int m) {
00014         
00015   char **param_name;
00016   int c, i, j, f;
00017   char s[1024],param[32];
00018   
00019   if(!in)
00020     f = 0;
00021   else
00022     do
00023       f = (fgets(s, 1024, in)!=NULL);
00024     while (f && (*s=='#' || *s=='\n'));
00025   
00026   param_name = (char **)malloc(m*sizeof(char *));
00027   i = 0;
00028   if(f) {
00029     c = 0;
00030     for(;i<m;++i) {
00031       j=0;
00032       for(;;++c) {
00033         if(s[c]==' ') {
00034           if(j==0)
00035             continue;
00036           else
00037             break;
00038         }
00039         if(s[c]=='\n' || s[c]==0)
00040           break;
00041         param[j++] = s[c];
00042       }
00043 
00044       /* Not enough parameters on input, end */
00045       if(j==0)
00046         break;
00047       param[j] = 0;
00048       param_name[i] = (char *)malloc( (j+1)*sizeof(char) );
00049       strcpy(param_name[i],param);
00050     }
00051   }
00052   
00053   /* Not enough parameters on input : use default names */
00054   if(!f || i!=m) {
00055     for(;i<m;++i) {
00056       param_name[i] = (char *) malloc(2*sizeof(char));
00057       sprintf(param_name[i], "%c", PCHAR+i+1);
00058     }
00059   }
00060   return(param_name);
00061 } /* Read_ParamNames */
00062 

Generated on Mon Mar 15 10:59:51 2004 for polylib by doxygen1.2.18