Subversion Repositories wimsdev

Rev

Rev 7842 | Rev 7856 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7842 Rev 7848
Line 7... Line 7...
7
* This source code file, and compiled objects derived from it,                  *
7
* This source code file, and compiled objects derived from it,                  *
8
* can be used and distributed without restriction, including for commercial use *
8
* can be used and distributed without restriction, including for commercial use *
9
* No warrenty whatsoever                                                        *
9
* No warrenty whatsoever                                                        *
10
*********************************************************************************
10
*********************************************************************************
11
*/
11
*/
12
#include <stdio.h>
-
 
13
#include <stdlib.h>
-
 
14
#include <errno.h>
-
 
15
#include <string.h>
-
 
16
#include <unistd.h>
-
 
17
#include <time.h> /* use for random id's */
-
 
18
#include <math.h>
-
 
19
/*
-
 
20
#include <ctype.h>
-
 
21
11/2013
-
 
22
removed: FreeBSD 9.0 / 9.1 C-lib bug...in chroot it will result in: Undefined symbol "_ThreadRuneLocale" implemented own versions of tolower() / toupper()
-
 
23
Clang is fine (FreeBSD 10.0)
-
 
24
*/
-
 
25
 
-
 
26
/*
-
 
27
in case svgdraw is in ~/src/Misc/svgdraw
-
 
28
#include "../svgdraw/include/matheval.h"
12
#include "../../Lib/libwims.h"
29
*/
-
 
30
#include "include/matheval.h"
13
#include "canvasdraw.h"
31
#include <assert.h>
14
#include <assert.h>
32
#include "canvasdraw.h"
15
#include "canvasmacro.c"
33
#include<sys/stat.h>
-
 
34
 
16
 
35
/* needed for gettimeofday */
-
 
36
#include <sys/time.h>
-
 
37
#include "canvasmacro.c"
-
 
38
/******************************************************************************
17
/******************************************************************************
39
**  Internal Functions
18
**  Internal Functions
40
******************************************************************************/
19
******************************************************************************/
41
void    add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */
20
void    add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */
42
void    sync_input(FILE *infile);/* proceed with inputfile */
21
void    sync_input(FILE *infile);/* proceed with inputfile */
Line 1098... Line 1077...
1098
                }
1077
                }
1099
            }
1078
            }
1100
            else
1079
            else
1101
            if(strcmp(draw_type,"arrow") == 0 ){
1080
            if(strcmp(draw_type,"arrow") == 0 ){
1102
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
1081
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
1103
                if(reply_format < 1){reply_format = 11;}
1082
                if(reply_format < 1){reply_format = 11;}
1104
                add_js_arrows(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
1083
                add_js_arrows(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
1105
                if(use_input_xy == 1){
1084
                if(use_input_xy == 1){
1106
                    add_input_arrow(js_include_file,1);
1085
                    add_input_arrow(js_include_file,1);
1107
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1086
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1108
                }
1087
                }
Line 2165... Line 2144...
2165
        @ hatchfill x0,y0,dx,dy,color
2144
        @ hatchfill x0,y0,dx,dy,color
2166
        @ x0,y0 in xrange / yrange
2145
        @ x0,y0 in xrange / yrange
2167
        @ distances dx,dy in pixels
2146
        @ distances dx,dy in pixels
2168
        */
2147
        */
2169
            if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
2148
            if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
2170
            for(i=0;i<5;i++){
2149
            for(i=0;i<5;i++){
2171
                switch(i){
2150
                switch(i){
2172
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2151
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2173
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2152
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2174
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2153
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2175
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2154
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2176
                    case 4: stroke_color = get_color(infile,1);
2155
                    case 4: stroke_color = get_color(infile,1);
2177
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
2156
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
Line 2864... Line 2843...
2864
/*
2843
/*
2865
avoid the use of ctypes.h for tolower() toupper();
2844
avoid the use of ctypes.h for tolower() toupper();
2866
it gives trouble in FreeBSD 9.0 / 9.1 when used in a chroot environment (C library bug) : Undefined symbol "_ThreadRuneLocale"
2845
it gives trouble in FreeBSD 9.0 / 9.1 when used in a chroot environment (C library bug) : Undefined symbol "_ThreadRuneLocale"
2867
Upper case -> Lower case : c = c - 'A'+ 'a';
2846
Upper case -> Lower case : c = c - 'A'+ 'a';
2868
Lower case ->  Upper case  c = c + 'A'  - 'a';
2847
Lower case ->  Upper case  c = c + 'A'  - 'a';
2869
*/
2848
 
2870
int tolower(int c){
2849
int tolower(int c){
2871
 if(c <= 'Z'){
2850
 if(c <= 'Z'){
2872
  if (c >= 'A'){
2851
  if (c >= 'A'){
2873
   return c - 'A' + 'a';
2852
   return c - 'A' + 'a';
2874
  }
2853
  }
2875
 }
2854
 }
2876
 return c;
2855
 return c;
2877
}
2856
}
2878
 
2857
 
2879
int toupper(int c){
2858
int toupper(int c){
2880
 if(c >= 'a' && c <= 'z'){
2859
 if(c >= 'a' && c <= 'z'){
2881
   return c + 'A' - 'a';
2860
   return c + 'A' - 'a';
2882
 }
2861
 }
2883
 return c;
2862
 return c;
2884
}
2863
}
2885
 
2864
*/
2886
char *get_color(FILE *infile , int last){
2865
char *get_color(FILE *infile , int last){
2887
    int c,i = 0,is_hex = 0;
2866
    int c,i = 0,is_hex = 0;
2888
    char temp[MAX_COLOR_STRING], *string;
2867
    char temp[MAX_COLOR_STRING], *string;
2889
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){
2868
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){
2890
        if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
2869
        if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
Line 3001... Line 2980...
3001
    if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
2980
    if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
3002
    if( c == EOF ){done = TRUE ; finished = 1;}
2981
    if( c == EOF ){done = TRUE ; finished = 1;}
3003
    tmp[i]='\0';
2982
    tmp[i]='\0';
3004
    if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
2983
    if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
3005
    if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
2984
    if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
3006
     void *f = evaluator_create(tmp);
2985
     void *f = eval_create(tmp);
3007
     assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
2986
     assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
3008
     y = evaluator_evaluate_x(f, 1);
2987
     y = eval_x(f, 1);
3009
     /* if function is bogus; y = 1 : so no core dumps */
2988
     /* if function is bogus; y = 1 : so no core dumps */
3010
     evaluator_destroy(f);
2989
     eval_destroy(f);
3011
    }
2990
    }
3012
    else
2991
    else
3013
    {
2992
    {
3014
     y = atof(tmp);
2993
     y = atof(tmp);
3015
    }
2994
    }