~ubuntu-branches/ubuntu/maverick/ploticus/maverick

« back to all changes in this revision

Viewing changes to src/custom.c

  • Committer: Bazaar Package Importer
  • Author(s): James W. Penny
  • Date: 2002-04-10 23:02:04 UTC
  • Revision ID: james.westby@ubuntu.com-20020410230204-64em4ns2f57c5u3l
Tags: 2.0.3-1
* The "That Tears it, Now You Have to Update Docs Package" Release.
* New upstream release (well, not so new :-( )   closes: Bug#137578
* Correct missing libpng2-dev in build-depends.  closes: Bug#142205
* Use correct syntax to:
* close URL type.                                closes: Bug#137577
* fix Architecture                               closes: Bug#141657
* close ITP                                      closes: Bug#132878

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "pl.h"
 
2
 
 
3
 
 
4
/* ----------------------------- */
 
5
/* CUSTOMFORVECT - defines vector objects that app can #for across */
 
6
customforvect( result, obj, n )
 
7
char *result;
 
8
char *obj;
 
9
int n;
 
10
{
 
11
return( 1 );
 
12
}
 
13
 
 
14
 
 
15
/* ----------------------------- */
 
16
/* CUSTOMTEXTVECT - defines text objects that app can #for across */
 
17
customtextvect( result, obj, pos )
 
18
char *result;
 
19
char *obj;
 
20
int *pos;
 
21
{
 
22
return( 1 );
 
23
}
 
24
 
 
25
 
 
26
/* ----------------------------- */
 
27
/* CUSTOM_FUNCTION - returns 0 on success, 1 if named function not found */
 
28
 
 
29
/* NOTE: in order to add a custom function it is now necessary to check the
 
30
   hash value of the function name to be sure that it does not collide with
 
31
   existing names.  See functions.c, fprintf statement around line 108.  */
 
32
 
 
33
custom_function( name, arg, nargs, result, typ )
 
34
char *name;
 
35
char *arg[];
 
36
int nargs;
 
37
char *result;
 
38
int *typ;
 
39
{
 
40
double Econv(), Elimit();
 
41
char buf[100];
 
42
char axis;
 
43
 
 
44
*typ = 0;
 
45
strcpy( result, "0" );
 
46
 
 
47
/* ------------------- */
 
48
/* hash:615 $inrange(value,axis) or $inrange(value,axis,min,max)
 
49
   return 1 if value in range for the axis, 0 if not.
 
50
   min and max are optional args */
 
51
if( strcmp( name, "inrange" )==0 ) {
 
52
        double fval, flow, fhi;
 
53
        axis = tolower( arg[1][0] );
 
54
        fval = Econv( axis, arg[0] );
 
55
        if( nargs > 2 ) flow = Econv( axis, arg[2] );
 
56
        else flow = Elimit( axis, 'l', 's' );
 
57
        if( nargs > 3 ) fhi = Econv( axis, arg[3] );
 
58
        else fhi = Elimit( axis, 'h', 's' );
 
59
        if( fval >= flow && fval <= fhi ) sprintf( result, "1" );
 
60
        else sprintf( result, "0" );    
 
61
        return( 0 );
 
62
        }
 
63
/* ------------------- */
 
64
/* hash:564 $icolor( i ) - return one of 20 color entries, chosen for contrast */
 
65
else if( strcmp( name, "icolor" )==0 ) {
 
66
        int i;
 
67
        char *c;
 
68
        i = atoi( arg[0] );
 
69
        if( i < 1 ) i = 1;
 
70
        i--;
 
71
        Eicolor( i, result );
 
72
        *typ = 1;
 
73
        return( 0 );
 
74
        }
 
75
/* ------------------- */
 
76
/* hash:849 $dataitem(row,field) - return the contents of row,field of current data set.
 
77
   Row is a number (first = 1).  Field is a datafield (name or number 1..n) */
 
78
else if( strcmp( name, "dataitem" )==0 ) {
 
79
        int row, fld;
 
80
        row = atoi( arg[0] ) -1;
 
81
        fld = fref( arg[1] ) -1;
 
82
        sprintf( result, "%s ", da( row, fld ) );
 
83
        *typ = 1;
 
84
        return( 0 );
 
85
        }
 
86
 
 
87
/* ------------------- */
 
88
/* hash:987 $nextstub(maxlen) - return next pltab row stub, "" if no more */
 
89
else if( strcmp( name, "nextstub" )==0 ) {
 
90
        int maxlen, i, slen;
 
91
        maxlen = atoi( arg[0] );
 
92
        if( maxlen == 0 ) maxlen = 80;
 
93
 
 
94
        /* see which axis is using categories or pltab scaling.. */
 
95
        Egetunits( 'y', buf );
 
96
        strcpy( result, "" );
 
97
        if( strcmp( buf, "categories" )==0 ) nextcat( 'y', result, maxlen );
 
98
        else    {
 
99
                Egetunits( 'x', buf );
 
100
                if( strcmp( buf, "categories" )==0 ) nextcat( 'x', result, maxlen );
 
101
                else Eerr( 2709, "$nextstub only valid with pltab or categories", "" );
 
102
                }
 
103
        /* convert spaces to underscores */
 
104
        for( i = 0, slen = strlen( result ); i < slen; i++ ) if( result[i] == ' ' ) result[i] = '_';
 
105
        *typ = 1;
 
106
        return( 0 );
 
107
        }
 
108
 
 
109
 
 
110
/* -------------------- */
 
111
/* hash:206 $max(f1,f2..fn) */
 
112
else if( strcmp( name, "max" )==0 ) {
 
113
        int i, prec;
 
114
        double max;
 
115
        max = -999999999999999.0;
 
116
        for( i = 0; i < nargs; i++ ) {
 
117
                if( !GL_goodnum( arg[i], &prec ) ) continue; /* added scg 11/15/00 */
 
118
                if( atof( arg[i] ) > max ) max = atof( arg[i] );
 
119
                }
 
120
        sprintf( result, "%g", max );
 
121
        return( 0 );
 
122
        }
 
123
 
 
124
/* ------------ */
 
125
/* hash:3396 $data_to_absolute(axis,val) - given a data coordinate, return the absolute location.
 
126
   Example: #set AVAL = $data_to_absolute(Y,@DVAL)
 
127
 */
 
128
else if( strcmp( name, "data_to_absolute" )==0 ) {
 
129
        double f, Econv(), Ea();
 
130
        f = Econv( tolower(arg[0][0]), arg[1] );
 
131
        sprintf( result, "%g", Ea( tolower(arg[0][0]), f ) );
 
132
        return( 0 );
 
133
        }
 
134
 
 
135
 
 
136
/* ------------------- */
 
137
/* hash:376 sleep( n ) - delay for N seconds */
 
138
else if( strcmp( name, "sleep" )==0 ) {
 
139
        int n;
 
140
        Eflush();
 
141
        n = atoi( arg[0] );
 
142
        sleep( n );
 
143
        return( 0 );
 
144
        }
 
145
 
 
146
/* ------------------- */
 
147
/* hash:793 getclick( label ) - produce a button; when user clicks on it, return */
 
148
else if( strcmp( name, "getclick" )==0 ) {
 
149
        if( Edev == 'x' ) do_x_button( "More.." );
 
150
        return( 0 );
 
151
        }
 
152
 
 
153
 
 
154
 
 
155
/* ------------------- */
 
156
/* hash:956 $fieldname(n) - return the field name assigned to field n.  First is 1 */
 
157
else if( strcmp( name, "fieldname" )==0 ) {
 
158
        getfname( atoi( arg[0] ), result );
 
159
        *typ = 1;
 
160
        return( 0 );
 
161
        }
 
162
 
 
163
 
 
164
/* ------------- */
 
165
/* hash:615 $exists(val) - return 1 if val has length > 0 */
 
166
else if( strcmp( name, "exists" )==0 ) {
 
167
        if( arg[0][0] != '\0' ) strcpy( result, "1" );
 
168
        else strcpy( result, "0" );
 
169
        return( 0 );
 
170
        }
 
171
 
 
172
/* ------------- */
 
173
/* hash:1303 $notexists(val) - return 1 if val has length > 0 */
 
174
else if( strcmp( name, "notexists" )==0 ) {
 
175
        if( arg[0][0] != '\0' ) strcpy( result, "0" );
 
176
        else strcpy( result, "1" );
 
177
        return( 0 );
 
178
        }
 
179
 
 
180
 
 
181
        
 
182
return( 1 ); 
 
183
}