CalculiX  2.8
A Free Software Three-Dimensional Structural Finite Element Program
 All Classes Files Functions Variables Macros
strsplt.c File Reference
#include <unistd.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <pthread.h>
#include "CalculiX.h"
#include "readfrd.h"
Include dependency graph for strsplt.c:

Go to the source code of this file.

Functions

ITG strsplt (char *rec_str, char breakchar, char ***ptr)
 

Function Documentation

ITG strsplt ( char *  rec_str,
char  breakchar,
char ***  ptr 
)

Definition at line 13 of file strsplt.c.

14 {
15  ITG i,j;
16  ITG nextarg=0, letter=0, skip_breakchar=0;
17  char **dat;
18 
19  if( (dat= (char **)malloc( 1*sizeof(char *))) == NULL )
20  printf(" ERROR: malloc failed\n");
21  if( (dat[0]= (char *)malloc(MAX_LINE_LENGTH *sizeof(char))) == NULL )
22  printf(" ERROR: malloc failed\n");
23 
24  /* scan all args divided by breakchar */
25  nextarg=0;letter=0;
26  for(j=0; j<MAX_LINE_LENGTH; j++) dat[nextarg][j]='\0';
27  for(i=0; i<MAX_LINE_LENGTH; i++)
28  {
29  if(rec_str[i]==(char)EOF) { break; }
30  if(rec_str[i]=='\n') { break; }
31  if(rec_str[i]==0) { break; }
32  if((rec_str[i]==breakchar)&&(!skip_breakchar))
33  {
34  /* check if the former dat has chars */
35  if(strlen(dat[nextarg]))
36  {
37  nextarg++;
38  letter=0;
39  if( (dat= (char **)realloc((char **)dat, (nextarg+1)*sizeof(char *))) == NULL )
40  printf(" ERROR: realloc failed\n");
41  if( (dat[nextarg]= (char *)malloc(MAX_LINE_LENGTH *sizeof(char))) == NULL )
42  printf(" ERROR: malloc failed\n");
43  for(j=0; j<MAX_LINE_LENGTH; j++) dat[nextarg][j]='\0';
44  }
45  }
46  else
47  {
48  if(rec_str[i]=='"') skip_breakchar=!skip_breakchar;
49  else if(skip_breakchar)
50  {
51  dat[nextarg][letter]=rec_str[i];
52  letter++;
53  }
54  else if(rec_str[i]!=' ')
55  {
56  dat[nextarg][letter]=rec_str[i];
57  letter++;
58  }
59  }
60  }
61  *ptr=dat;
62 
63  /* check if the former dat has chars */
64  if(strlen(dat[nextarg])) nextarg++;
65 
66  /* for(i=0; i<nextarg; i++) printf("dat:%s|\n",dat[i]); */
67  return(nextarg);
68 }
#define MAX_LINE_LENGTH
Definition: readfrd.h:10
#define ITG
Definition: CalculiX.h:51
Hosted by OpenAircraft.com, (Michigan UAV, LLC)