Main Page | Class List | File List | Class Members | File Members

param.c

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

Generated on Mon Sep 12 14:48:29 2005 for polylib by doxygen 1.3.5