Skip to content
Snippets Groups Projects
Commit 0d6c2723 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

new string manipulation functions

parent 889a7698
No related branches found
No related tags found
No related merge requests found
%{
// $Id: Gmsh.l,v 1.30 2001-05-16 15:11:45 geuzaine Exp $
// $Id: Gmsh.l,v 1.31 2001-07-24 11:33:47 geuzaine Exp $
#include <stdio.h>
#include <stdlib.h>
......@@ -178,6 +178,9 @@ Spline return tSpline;
Surface return tSurface;
Symmetry return tSymmetry;
Sprintf return tSprintf ;
Strcat return tStrcat ;
Strdup return tStrdup ;
Strprefix return tStrprefix ;
Transfinite return tTransfinite;
Translate return tTranslate;
......
This diff is collapsed.
......@@ -37,137 +37,140 @@ typedef union {
#define tHypot 284
#define tPrintf 285
#define tSprintf 286
#define tDraw 287
#define tPoint 288
#define tCircle 289
#define tEllipsis 290
#define tLine 291
#define tSurface 292
#define tSpline 293
#define tVolume 294
#define tCharacteristic 295
#define tLength 296
#define tParametric 297
#define tElliptic 298
#define tPlane 299
#define tRuled 300
#define tTransfinite 301
#define tComplex 302
#define tPhysical 303
#define tUsing 304
#define tBump 305
#define tProgression 306
#define tRotate 307
#define tTranslate 308
#define tSymmetry 309
#define tDilate 310
#define tExtrude 311
#define tDuplicata 312
#define tLoop 313
#define tRecombine 314
#define tDelete 315
#define tCoherence 316
#define tIntersect 317
#define tAttractor 318
#define tLayers 319
#define tScalarTetrahedron 320
#define tVectorTetrahedron 321
#define tTensorTetrahedron 322
#define tScalarTriangle 323
#define tVectorTriangle 324
#define tTensorTriangle 325
#define tScalarLine 326
#define tVectorLine 327
#define tTensorLine 328
#define tScalarPoint 329
#define tVectorPoint 330
#define tTensorPoint 331
#define tBSpline 332
#define tNurbs 333
#define tOrder 334
#define tWith 335
#define tBounds 336
#define tKnots 337
#define tColor 338
#define tColorTable 339
#define tFor 340
#define tIn 341
#define tEndFor 342
#define tIf 343
#define tEndIf 344
#define tExit 345
#define tReturn 346
#define tCall 347
#define tFunction 348
#define tMesh 349
#define tB_SPLINE_SURFACE_WITH_KNOTS 350
#define tB_SPLINE_CURVE_WITH_KNOTS 351
#define tCARTESIAN_POINT 352
#define tTRUE 353
#define tFALSE 354
#define tUNSPECIFIED 355
#define tU 356
#define tV 357
#define tEDGE_CURVE 358
#define tVERTEX_POINT 359
#define tORIENTED_EDGE 360
#define tPLANE 361
#define tFACE_OUTER_BOUND 362
#define tEDGE_LOOP 363
#define tADVANCED_FACE 364
#define tVECTOR 365
#define tDIRECTION 366
#define tAXIS2_PLACEMENT_3D 367
#define tISO 368
#define tENDISO 369
#define tENDSEC 370
#define tDATA 371
#define tHEADER 372
#define tFILE_DESCRIPTION 373
#define tFILE_SCHEMA 374
#define tFILE_NAME 375
#define tMANIFOLD_SOLID_BREP 376
#define tCLOSED_SHELL 377
#define tADVANCED_BREP_SHAPE_REPRESENTATION 378
#define tFACE_BOUND 379
#define tCYLINDRICAL_SURFACE 380
#define tCONICAL_SURFACE 381
#define tCIRCLE 382
#define tTRIMMED_CURVE 383
#define tGEOMETRIC_SET 384
#define tCOMPOSITE_CURVE_SEGMENT 385
#define tCONTINUOUS 386
#define tCOMPOSITE_CURVE 387
#define tTOROIDAL_SURFACE 388
#define tPRODUCT_DEFINITION 389
#define tPRODUCT_DEFINITION_SHAPE 390
#define tSHAPE_DEFINITION_REPRESENTATION 391
#define tELLIPSE 392
#define tTrimmed 393
#define tSolid 394
#define tEndSolid 395
#define tVertex 396
#define tFacet 397
#define tNormal 398
#define tOuter 399
#define tLoopSTL 400
#define tEndLoop 401
#define tEndFacet 402
#define tAFFECTPLUS 403
#define tAFFECTMINUS 404
#define tAFFECTTIMES 405
#define tAFFECTDIVIDE 406
#define tOR 407
#define tAND 408
#define tEQUAL 409
#define tNOTEQUAL 410
#define tAPPROXEQUAL 411
#define tLESSOREQUAL 412
#define tGREATEROREQUAL 413
#define tCROSSPRODUCT 414
#define tPLUSPLUS 415
#define tMINUSMINUS 416
#define UNARYPREC 417
#define tStrcat 287
#define tStrdup 288
#define tStrprefix 289
#define tDraw 290
#define tPoint 291
#define tCircle 292
#define tEllipsis 293
#define tLine 294
#define tSurface 295
#define tSpline 296
#define tVolume 297
#define tCharacteristic 298
#define tLength 299
#define tParametric 300
#define tElliptic 301
#define tPlane 302
#define tRuled 303
#define tTransfinite 304
#define tComplex 305
#define tPhysical 306
#define tUsing 307
#define tBump 308
#define tProgression 309
#define tRotate 310
#define tTranslate 311
#define tSymmetry 312
#define tDilate 313
#define tExtrude 314
#define tDuplicata 315
#define tLoop 316
#define tRecombine 317
#define tDelete 318
#define tCoherence 319
#define tIntersect 320
#define tAttractor 321
#define tLayers 322
#define tScalarTetrahedron 323
#define tVectorTetrahedron 324
#define tTensorTetrahedron 325
#define tScalarTriangle 326
#define tVectorTriangle 327
#define tTensorTriangle 328
#define tScalarLine 329
#define tVectorLine 330
#define tTensorLine 331
#define tScalarPoint 332
#define tVectorPoint 333
#define tTensorPoint 334
#define tBSpline 335
#define tNurbs 336
#define tOrder 337
#define tWith 338
#define tBounds 339
#define tKnots 340
#define tColor 341
#define tColorTable 342
#define tFor 343
#define tIn 344
#define tEndFor 345
#define tIf 346
#define tEndIf 347
#define tExit 348
#define tReturn 349
#define tCall 350
#define tFunction 351
#define tMesh 352
#define tB_SPLINE_SURFACE_WITH_KNOTS 353
#define tB_SPLINE_CURVE_WITH_KNOTS 354
#define tCARTESIAN_POINT 355
#define tTRUE 356
#define tFALSE 357
#define tUNSPECIFIED 358
#define tU 359
#define tV 360
#define tEDGE_CURVE 361
#define tVERTEX_POINT 362
#define tORIENTED_EDGE 363
#define tPLANE 364
#define tFACE_OUTER_BOUND 365
#define tEDGE_LOOP 366
#define tADVANCED_FACE 367
#define tVECTOR 368
#define tDIRECTION 369
#define tAXIS2_PLACEMENT_3D 370
#define tISO 371
#define tENDISO 372
#define tENDSEC 373
#define tDATA 374
#define tHEADER 375
#define tFILE_DESCRIPTION 376
#define tFILE_SCHEMA 377
#define tFILE_NAME 378
#define tMANIFOLD_SOLID_BREP 379
#define tCLOSED_SHELL 380
#define tADVANCED_BREP_SHAPE_REPRESENTATION 381
#define tFACE_BOUND 382
#define tCYLINDRICAL_SURFACE 383
#define tCONICAL_SURFACE 384
#define tCIRCLE 385
#define tTRIMMED_CURVE 386
#define tGEOMETRIC_SET 387
#define tCOMPOSITE_CURVE_SEGMENT 388
#define tCONTINUOUS 389
#define tCOMPOSITE_CURVE 390
#define tTOROIDAL_SURFACE 391
#define tPRODUCT_DEFINITION 392
#define tPRODUCT_DEFINITION_SHAPE 393
#define tSHAPE_DEFINITION_REPRESENTATION 394
#define tELLIPSE 395
#define tTrimmed 396
#define tSolid 397
#define tEndSolid 398
#define tVertex 399
#define tFacet 400
#define tNormal 401
#define tOuter 402
#define tLoopSTL 403
#define tEndLoop 404
#define tEndFacet 405
#define tAFFECTPLUS 406
#define tAFFECTMINUS 407
#define tAFFECTTIMES 408
#define tAFFECTDIVIDE 409
#define tOR 410
#define tAND 411
#define tEQUAL 412
#define tNOTEQUAL 413
#define tAPPROXEQUAL 414
#define tLESSOREQUAL 415
#define tGREATEROREQUAL 416
#define tCROSSPRODUCT 417
#define tPLUSPLUS 418
#define tMINUSMINUS 419
#define UNARYPREC 420
extern YYSTYPE yylval;
%{
// $Id: Gmsh.y,v 1.79 2001-07-08 15:45:48 geuzaine Exp $
// $Id: Gmsh.y,v 1.80 2001-07-24 11:33:48 geuzaine Exp $
//
// Generaliser sprintf avec des chaines de caracteres
......@@ -84,7 +84,7 @@ void skip_until (char *skip, char *until);
%token tEND tAFFECT tDOTS tPi
%token tExp tLog tLog10 tSqrt tSin tAsin tCos tAcos tTan tRand
%token tAtan tAtan2 tSinh tCosh tTanh tFabs tFloor tCeil
%token tFmod tModulo tHypot tPrintf tSprintf tDraw
%token tFmod tModulo tHypot tPrintf tSprintf tStrcat tStrdup tStrprefix tDraw
%token tPoint tCircle tEllipsis tLine tSurface tSpline tVolume
%token tCharacteristic tLength tParametric tElliptic
%token tPlane tRuled tTransfinite tComplex tPhysical
......@@ -119,8 +119,7 @@ void skip_until (char *skip, char *until);
%type <i> BoolExpr NumericAffectation NumericIncrement
%type <u> ColorExpr
%type <c> StringExpr
%type <l> FExpr_Range
%type <l> ListOfDouble ListOfDoubleItem RecursiveListOfDouble
%type <l> FExpr_Multi ListOfDouble RecursiveListOfDouble
%type <l> ListOfListOfDouble RecursiveListOfListOfDouble
%type <l> ListOfColor RecursiveListOfColor
%type <l> ListOfShapes Duplicata Transform MultipleShape
......@@ -907,7 +906,7 @@ Affectation :
/* -------- Option Strings -------- */
| tSTRING '.' tSTRING tAFFECT tBIGSTR tEND
| tSTRING '.' tSTRING tAFFECT StringExpr tEND
{
if(!(pStrCat = Get_StringOptionCategory($1)))
vyyerror("Unknown string option class '%s'", $1);
......@@ -919,7 +918,7 @@ Affectation :
}
}
| tSTRING '[' FExpr ']' '.' tSTRING tAFFECT tBIGSTR tEND
| tSTRING '[' FExpr ']' '.' tSTRING tAFFECT StringExpr tEND
{
if(!(pStrCat = Get_StringOptionCategory($1)))
vyyerror("Unknown string option class '%s'", $1);
......@@ -2125,26 +2124,6 @@ FExpr_Single :
}
;
FExpr_Range :
FExpr tDOTS FExpr
{
$$ = List_Create(2,1,sizeof(double)) ;
for(d=$1 ; ($1<$3)?(d<=$3):(d>=$3) ; ($1<$3)?(d+=1.):(d-=1.))
List_Add($$, &d) ;
}
| FExpr tDOTS FExpr tDOTS FExpr
{
$$ = List_Create(2,1,sizeof(double)) ;
if(!$5 || ($1<$3 && $5<0) || ($1>$3 && $5>0)){
vyyerror("Wrong increment in '%g:%g:%g'", $1, $3, $5) ;
List_Add($$, &($1)) ;
}
else
for(d=$1 ; ($5>0)?(d<=$3):(d>=$3) ; d+=$5)
List_Add($$, &d) ;
}
;
VExpr :
VExpr_Single
{
......@@ -2232,7 +2211,12 @@ RecursiveListOfListOfDouble :
ListOfDouble :
ListOfDoubleItem
FExpr
{
$$ = List_Create(2,1,sizeof(double)) ;
List_Add($$, &($1)) ;
}
| FExpr_Multi
{
$$ = $1 ;
}
......@@ -2250,15 +2234,23 @@ ListOfDouble :
}
;
ListOfDoubleItem :
FExpr
FExpr_Multi :
FExpr tDOTS FExpr
{
$$ = List_Create(2,1,sizeof(double)) ;
List_Add($$, &($1)) ;
for(d=$1 ; ($1<$3)?(d<=$3):(d>=$3) ; ($1<$3)?(d+=1.):(d-=1.))
List_Add($$, &d) ;
}
| FExpr_Range
| FExpr tDOTS FExpr tDOTS FExpr
{
$$ = $1;
$$ = List_Create(2,1,sizeof(double)) ;
if(!$5 || ($1<$3 && $5<0) || ($1>$3 && $5>0)){
vyyerror("Wrong increment in '%g:%g:%g'", $1, $3, $5) ;
List_Add($$, &($1)) ;
}
else
for(d=$1 ; ($5>0)?(d<=$3):(d>=$3) ; d+=$5)
List_Add($$, &d) ;
}
| tSTRING '[' ']'
{
......@@ -2335,7 +2327,12 @@ ListOfDoubleItem :
;
RecursiveListOfDouble :
ListOfDoubleItem
FExpr
{
$$ = List_Create(2,1,sizeof(double)) ;
List_Add($$, &($1)) ;
}
| FExpr_Multi
{
$$ = $1 ;
}
......@@ -2343,72 +2340,13 @@ RecursiveListOfDouble :
{
List_Add($$, &($3)) ;
}
| RecursiveListOfDouble ',' FExpr_Range
| RecursiveListOfDouble ',' FExpr_Multi
{
for(i=0 ; i<List_Nbr($3) ; i++){
List_Read($3, i, &d) ;
List_Add($$, &d) ;
}
}
| RecursiveListOfDouble ',' tSTRING '[' ']'
{
TheSymbol.Name = $3 ;
if (!(pSymbol = (Symbol*)List_PQuery(Symbol_L, &TheSymbol, CompareSymbols))) {
vyyerror("Unknown variable '%s'", $3) ;
}
else{
for(i = 0 ; i < List_Nbr(pSymbol->val) ; i++)
List_Add($$, (double*)List_Pointer_Fast(pSymbol->val, i)) ;
}
}
| RecursiveListOfDouble ',' '-' tSTRING '[' ']'
{
TheSymbol.Name = $4 ;
if (!(pSymbol = (Symbol*)List_PQuery(Symbol_L, &TheSymbol, CompareSymbols))) {
vyyerror("Unknown variable '%s'", $4) ;
}
else{
for(i = 0 ; i < List_Nbr(pSymbol->val) ; i++){
d = - *(double*)List_Pointer_Fast(pSymbol->val, i);
List_Add($$, &d) ;
}
}
}
| RecursiveListOfDouble ',' tSTRING '[' '{' RecursiveListOfDouble '}' ']'
{
TheSymbol.Name = $3 ;
if (!(pSymbol = (Symbol*)List_PQuery(Symbol_L, &TheSymbol, CompareSymbols))) {
vyyerror("Unknown variable '%s'", $3) ;
}
else{
for(i = 0 ; i < List_Nbr($6) ; i++){
j = (int)(*(double*)List_Pointer_Fast($6, i));
if((pd = (double*)List_Pointer_Test(pSymbol->val, j)))
List_Add($$, pd) ;
else
vyyerror("Uninitialized variable '%s[%d]'", $3, j) ;
}
}
List_Delete($6);
}
| RecursiveListOfDouble ',' '-' tSTRING '[' '{' RecursiveListOfDouble '}' ']'
{
TheSymbol.Name = $4 ;
if (!(pSymbol = (Symbol*)List_PQuery(Symbol_L, &TheSymbol, CompareSymbols))) {
vyyerror("Unknown variable '%s'", $4) ;
}
else{
for(i = 0 ; i < List_Nbr($7) ; i++){
j = (int)(*(double*)List_Pointer_Fast($7, i));
if((pd = (double*)List_Pointer_Test(pSymbol->val, j))){
d = - *pd ;
List_Add($$, &d) ;
}
else
vyyerror("Uninitialized variable '%s[%d]'", $4, j) ;
}
}
List_Delete($7);
List_Delete($3);
}
;
......@@ -2422,11 +2360,13 @@ ColorExpr :
{
$$ = PACK_COLOR((int)$2, (int)$4, (int)$6, 255);
}
/* shift/reduce conflict
| '{' tSTRING ',' FExpr '}'
{
$$ = Get_ColorForString(ColorString, (int)$4, $2, &flag);
if(flag) vyyerror("Unknown color '%s'", $2);
}
*/
| tSTRING
{
$$ = Get_ColorForString(ColorString, -1, $1, &flag);
......@@ -2485,11 +2425,32 @@ StringExpr :
{
$$ = $1;
}
| tSprintf '(' tBIGSTR ')'
| tStrcat '(' StringExpr ',' StringExpr ')'
{
$$ = (char *)Malloc((strlen($3)+strlen($5)+1)*sizeof(char)) ;
strcpy($$, $3) ;
strcat($$, $5) ;
Free($3);
Free($5);
}
| tStrprefix '(' StringExpr ')'
{
$$ = (char *)Malloc((strlen($3)+1)*sizeof(char)) ;
for(i=strlen($3)-1; i>=0; i--){
if($3[i] == '.'){
strncpy($$,$3,i);
$$[i]='\0';
break;
}
}
if(i<=0) strcpy($$,$3);
Free($3);
}
| tSprintf '(' StringExpr ')'
{
$$ = $3;
}
| tSprintf '(' tBIGSTR ',' RecursiveListOfDouble ')'
| tSprintf '(' StringExpr ',' RecursiveListOfDouble ')'
{
for(i = 0 ; i<List_Nbr($5) ; i++){
if(!i){
......@@ -2509,9 +2470,42 @@ StringExpr :
break ;
}
}
$$ = (char*)Malloc(strlen(tmpstring)+1);
$$ = (char*)Malloc((strlen(tmpstring)+1)*sizeof(char));
strcpy($$, tmpstring);
List_Delete($5);
Free($3);
}
| tStrdup '(' StringExpr ')'
{
$$ = $3;
}
| tStrdup '(' tSTRING '.' tSTRING ')'
{
if(!(pStrCat = Get_StringOptionCategory($3)))
vyyerror("Unknown string option class '%s'", $3);
else{
if(!(pStrOpt = (char *(*) (int, int, char *))Get_StringOption($5, pStrCat)))
vyyerror("Unknown string option '%s.%s'", $3, $5);
else{
str = pStrOpt(0,GMSH_GET,NULL) ;
$$ = (char*)Malloc((strlen(str)+1)*sizeof(char));
strcpy($$, str);
}
}
}
| tStrdup '(' tSTRING '[' FExpr ']' '.' tSTRING ')'
{
if(!(pStrCat = Get_StringOptionCategory($3)))
vyyerror("Unknown string option class '%s'", $3);
else{
if(!(pStrOpt = (char *(*) (int, int, char *))Get_StringOption($8, pStrCat)))
vyyerror("Unknown string option '%s[%d].%s'", $3, (int)$5, $8);
else{
str = pStrOpt((int)$5,GMSH_GET,NULL) ;
$$ = (char*)Malloc((strlen(str)+1)*sizeof(char));
strcpy($$, str);
}
}
}
;
......
This diff is collapsed.
$Id: VERSIONS,v 1.28 2001-07-18 07:36:36 geuzaine Exp $
$Id: VERSIONS,v 1.29 2001-07-24 11:33:48 geuzaine Exp $
New in 1.21: Fixed more memory leaks; added -opt command line option
to parse definitions directly from the command line; fixed missing
screen refreshes during contour/surface selection;
screen refreshes during contour/surface selection; Added string
manipulation functions (Strdup, Strcat, Strprefix);
New in 1.20: Fixed various bugs (memory leaks, functions in included
files, solver command selection, ColorTable option, duplicate nodes in
......
Include "../tutorial/view1.pos" ;
View[0].Name = "gloups.prout" ;
General.Trackball = 0 ;
For num In {1:2}
General.RotationX += 10 ;
Print Strcat( Strprefix(Strdup(View[0].Name)) , Sprintf("-%g.jpg", num) ) ;
Draw ;
EndFor
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment