Beispiel #1
0
DllExport long
SfHeader ( SpecFile *sf, long index, char *string, char ***lines, int *error)
{
     char   *headbuf,
            *endheader;

     long nb_found;

     if (sfSetCurrent(sf,index,error) == -1)
          return(-1);

     headbuf   = sf->scanbuffer;
     endheader = sf->scanbuffer + sf->scansize;

     nb_found = sfFindLines(headbuf, endheader,string, lines,error);

     if (nb_found == 0) {
          return SfFileHeader(sf,index,string,lines,error);
     } else {
          return nb_found;
     }
}
Beispiel #2
0
/*********************************************************************
 *   Function:		long SfAllMotors( sf, index, names, error )
 *
 *   Description:	Reads all motor names in #O lines (in file header)
 *
 *   Parameters:
 *		Input :	(1) SpecScan pointer
 *			(2) Scan index
 *		Output:	(3) Names  
 *			(4) Error number 
 *   Returns:
 *			Number of found names
 *			( -1 ) if errors.		
 *   Possible errors:
 *			SF_ERR_SCAN_NOT_FOUND	  
 *			SF_ERR_LINE_NOT_FOUND	
 *			SF_ERR_LINE_EMPTY	
 *			SF_ERR_MEMORY_ALLOC    || => cpyStrArr(),lines2words()
 *			SF_ERR_FILE_READ	|
 *			SF_ERR_HEADER_NOT_FOUND	| => SfFileHeader()
 *
 *   Remark:  The memory allocated should be freed by the application
 *
 *********************************************************************/
DllExport long
SfAllMotors( SpecFile *sf, long index, char ***names, int *error )
{
     char **lines;
     char  *thisline,
           *endline;

     char **motarr;
     char  *onemot;

     static char tmpmot[40];

     char  *ptr;

     long      motct = 0;
     long      no_lines;
     short     i,j;
     
    /*
     * go to scan
     */
     if (sfSetCurrent(sf,index,error) == -1) {
         *names = NULL;
          return(0);
     }

    /*
     * if motor names for this scan have already been read
     */
     if (sf->motor_names != (char **)NULL) {
         motarr = (char **)malloc(sizeof(char *) * sf->no_motor_names);
         for (i=0;i<sf->no_motor_names;i++) {
             motarr[i] = (char *) strdup (sf->motor_names[i]);
         }
        *names = motarr;
         return(sf->no_motor_names);
     }

    /*
     * else
     */
     no_lines =  SfFileHeader(sf, index,"O",&lines,error);
     if (no_lines == -1 || no_lines == 0 ) {
         *names = (char **) NULL;
          return(-1);
     }

     if ( (motarr = (char **)malloc( sizeof(char *))) == (char **)NULL) {
         *error = SF_ERR_MEMORY_ALLOC;
          return(-1);
     } 

     motct = 0;

     for (j=0;j<no_lines;j++) {
         thisline = lines[j] + 4;
         endline  = thisline + strlen(thisline);
         for(ptr=thisline;*ptr == ' ';ptr++);
         for (i=0;ptr < endline -2;ptr++,i++) {
            if (*ptr==' ' && *(ptr+1) == ' ') { 
               tmpmot[i] = '\0';

               motarr = (char **)realloc( motarr, (motct+1) * sizeof(char *));
               onemot = (char *) malloc (i+2);
               strcpy(onemot,tmpmot);
               motarr[motct]  = onemot; 

               motct++; 
               i=-1; 
               for(;*(ptr+1) == ' ' && ptr < endline -1;ptr++);
            } else {
               tmpmot[i] = *ptr;
            }
        }
        if (*ptr != ' ') { tmpmot[i]   = *ptr; i++; }
        ptr++;
        if (*ptr != ' ') { tmpmot[i]   = *ptr; i++; }

        tmpmot[i] = '\0';
        motarr = (char **)realloc( motarr, (motct+1) * sizeof(char *));

        onemot = (char *) malloc (i+2);
        strcpy(onemot,tmpmot);
        motarr[motct]  = onemot; 

        motct++; 

   }

  /*
   * Save in specfile structure
   */
   sf->no_motor_names = motct;
   sf->motor_names = (char **)malloc(sizeof(char *) * motct);
   for (i=0;i<motct;i++) {
        sf->motor_names[i] = (char *)strdup(motarr[i]);
   }

  *names = motarr;
   return( motct );

}