File: fd_names.c

package info (click to toggle)
libforms 1.0.93sp1-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 11,548 kB
  • sloc: ansic: 97,227; sh: 9,236; makefile: 858
file content (166 lines) | stat: -rw-r--r-- 3,946 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * This file is part of XForms.
 *
 *  XForms is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation; either version 2.1, or
 *  (at your option) any later version.
 *
 *  XForms is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with XForms.  If not, see <http://www.gnu.org/licenses/>.
 */


/**
 * \file fd_names.c
 *
 *  This file is part of XForms package
 *  Copyright (c) 1996-2002  T.C. Zhao and Mark Overmars
 *  All rights reserved.
 *
 * This file is part of the Form Designer.
 *
 * It contains the routines that keep track of the names and
 * callback routines associated to the different objects.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>
#include <stdio.h>
#include "fd_main.h"

/****
  THE DATA STRUCTURE
****/

typedef struct
{
    FL_OBJECT * obj;                        /* The object */
    char        name[ MAX_VAR_LEN ];        /* Its name (if any) */
    char        cbname[ MAX_VAR_LEN ];      /* Callback Routine */
    char        argname[ MAX_VAR_LEN ];     /* The argument */
} OBJ;

#define MAXOBJ  1024

static OBJ objects[ MAXOBJ ];   /* The stored objects */
static int objnumb = 0;     /* Their number */


/***************************************
 * Returns the number of the object in the list
 ***************************************/

static int
get_object_numb( const FL_OBJECT * obj )
{
    int i;

    for ( i = 0; i < objnumb; i++ )
        if ( objects[ i ].obj == obj )
            return i;
    return -1;
}


/***************************************
 * Checks whether the names are correct C-names and don't occur already.
 ***************************************/

static void
check_names( int on )
{
    /* Fill in argument if missing */

    if ( *objects[ on ].cbname && ! *objects[ on ].argname)
        strcpy( objects[ on ].argname, "0" );

    /* HAS TO BE EXTENDED */
}


/****
  ACTUAL ROUTINES
****/


/***************************************
 * returns the names of an object
 ***************************************/

void
get_object_name( const FL_OBJECT * obj,
                 char            * name,
                 char            * cbname,
                 char            * argname)
{
    int on = get_object_numb( obj );

    *name = '\0';
    *cbname = '\0';
    *argname = '\0';
    if ( on == -1 )
        return;

    strcpy( name, objects[ on ].name );
    strcpy( cbname, objects[ on ].cbname );
    strcpy( argname, objects[ on ].argname );
}


/***************************************
 * returns the names of an object
 ***************************************/

void
set_object_name( FL_OBJECT  * obj,
                 const char * name,
                 const char * cbname,
                 const char * argname )
{
    int on = get_object_numb( obj );

    if ( obj == NULL )
        return;

    if ( on == -1 )
    {
        if (    ( ! name    || ! *name    )
             && ( ! cbname  || ! *cbname  )
             && ( ! argname || ! *argname ) )
            return;

        if ( objnumb >= MAXOBJ )
            return;

        objects[ objnumb ].obj = obj;
        on = objnumb++;
    }

    if ( name )
        fli_sstrcpy( objects[ on ].name, name, sizeof objects[ on ].name );
    if ( cbname )
        fli_sstrcpy( objects[ on ].cbname, cbname,
                     sizeof objects[ on ].cbname );
    if ( argname )
        fli_sstrcpy( objects[ on ].argname, argname,
                     sizeof objects[ on ].argname  );

    check_names( on );
}


/*
 * Local variables:
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */