TUM-Logo

libRASCH

 

Home
 

General

About libRASCH/News
Design
Screen shots
Sample programs (with source code)
License
 

Download

libRASCH
Tools
 

Documentation

User
Developer
 

Resources

Mailing list
Supported Formats
Plugins
Status
Links
 
Contact
About this site
 
Last updated
Tue Mar 27 23:03:52 2007
libRASCH: pl_general.c Source File

pl_general.c

Go to the documentation of this file.
00001 
00009 /*----------------------------------------------------------------------------
00010  *
00011  * Copyright (C) 2002-2004, Raphael Schneider
00012  * See the file COPYING for information on usage and redistribution.
00013  *
00014  * $Header: /home/cvs_repos/librasch/src/shared/pl_general.c,v 1.12 2004/07/06 08:19:50 rasch Exp $
00015  *
00016  *--------------------------------------------------------------------------*/
00017 
00018 #include <stdlib.h>
00019 #include <string.h>
00020 #include <stdio.h>
00021 
00022 #define _LIBRASCH_BUILD
00023 #define _DEFINE_INFO_STRUCTS
00024 #include <pl_general.h>
00025 #include <ra_event_props.h>
00026 
00027 #ifdef WIN32
00028 #include <windows.h>
00029 #endif
00030 
00038 int
00039 comp_func(const void *id, const void *meta_inf)
00040 {
00041         return (*((int *) id) - ((struct meta_info *) meta_inf)->id);
00042 } /* comp_func() */
00043 
00044 
00051 struct meta_info *
00052 get_meta_info(int id)
00053 {
00054         int num_inf = sizeof(_meta) / sizeof(_meta[0]);
00055         return bsearch(&id, _meta, num_inf, sizeof(_meta[0]), &comp_func);
00056 } /* get_meta_minfo() */
00057 
00058 
00067 int
00068 find_ra_info_by_name(value_handle vh, const char *c)
00069 {
00070         int num_inf, i;
00071         struct ra_value *v = (struct ra_value *)vh;
00072 
00073         if (!vh || !c)
00074                 return -1;
00075 
00076         num_inf = sizeof(_meta) / sizeof(_meta[0]);
00077         /* TODO: think about faster way to find infos (perhaps hash-values ?) */
00078         for (i = 0; i < num_inf; i++)
00079         {
00080                 if (strcmp(_meta[i].ascii_id, c) == 0)
00081                         break;
00082         }
00083 
00084         if (i >= num_inf)
00085                 return -1;
00086 
00087         ra_value_reset(vh);
00088 
00089         set_meta_info(vh, _meta[i].name, _meta[i].desc, _meta[i].id);
00090 
00091         v->utype = _meta[i].type;
00092 
00093         return 0;
00094 } /* find_ra_info_by_name() */
00095 
00096 
00105 int
00106 get_ra_info_id_ascii_by_id(long id, char *id_ascii)
00107 {
00108         int num_inf, i;
00109 
00110         if (!id_ascii)
00111                 return -1;
00112 
00113         num_inf = sizeof(_meta) / sizeof(_meta[0]);
00114         for (i = 0; i < num_inf; i++)
00115         {
00116                 if (_meta[i].id == id)
00117                         break;
00118         }
00119 
00120         if (i >= num_inf)
00121                 return -1;
00122 
00123         strcpy(id_ascii, _meta[i].ascii_id);
00124 
00125         return 0;       
00126 } /* get_ra_info_name_by_id() */
00127 
00128 
00140 void
00141 split_filename(const char *file, char sep, char *dir, char *name, char *ext)
00142 {
00143         const char *dir_p, *name_p, *ext_p;
00144         size_t len;
00145 
00146         dir_p = name_p = ext_p = 0;
00147 
00148         strcpy(dir, ".");
00149         name[0] = '\0';
00150         ext[0] = '\0';
00151 
00152         /* look for directory */
00153         name_p = strrchr(file, sep);
00154         if (name_p)
00155         {
00156                 len = name_p - file;
00157                 strncpy(dir, file, len);
00158                 dir[len] = '\0';
00159                 name_p += 1;
00160         }
00161         else
00162                 name_p = file;
00163 
00164         /* look for extension */
00165         ext_p = strrchr(name_p, '.');
00166         if (ext_p)
00167         {
00168                 strcpy(ext, ext_p + 1);
00169                 len = ext_p - name_p;
00170         }
00171         else
00172                 len = strlen(name_p);
00173 
00174         strncpy(name, name_p, len);
00175         name[len] = '\0';
00176 } /* split_filename() */
00177 
00178 
00187 void
00188 set_one_session(struct ra_meas *meas, const char *name, const char *desc)
00189 {
00190         meas->sessions = ra_alloc_mem(sizeof(struct ra_session));
00191         memset(meas->sessions, 0, sizeof(struct ra_session));
00192         meas->num_sessions = 1;
00193 
00194         if (name)
00195                 strncpy(meas->sessions[0].name, name, RA_VALUE_NAME_MAX);
00196         if (desc)
00197                 strncpy(meas->sessions[0].desc, desc, RA_VALUE_DESC_MAX);
00198 
00199         meas->sessions[0].root_rec = ra_alloc_mem(sizeof(struct ra_rec));
00200         memset(meas->sessions[0].root_rec, 0, sizeof(struct ra_rec));
00201         meas->sessions[0].root_rec->meas = meas;
00202         meas->sessions[0].root_rec->handle_id = RA_HANDLE_REC;
00203 } /* set_one_session() */
00204 
00205 
00212 void
00213 free_session_rec(struct ra_rec *rh)
00214 {
00215         if (rh == NULL)
00216                 return;
00217 
00218         if (rh->child != NULL)
00219                 free_session_rec(rh->child);
00220 
00221         if (rh->next != NULL)
00222                 free_session_rec(rh->next);
00223 
00224         ra_free_mem(rh);
00225 } /* free_session_rec */
00226 
00227 
00228 int
00229 fill_predef_class_info(long id, value_handle vh_id, value_handle vh_name, value_handle vh_desc)
00230 {
00231         int n_class = sizeof(ra_event_class) / sizeof(struct event_class_desc);
00232         int i, idx;
00233 
00234         idx = -1;
00235         for (i = 0; i < n_class; i++)
00236         {
00237                 if (ra_event_class[i].id == id)
00238                 {
00239                         idx = i;
00240                         break;
00241                 }
00242         }
00243         if (idx == -1)
00244                 return -1;
00245 
00246         ra_value_set_string(vh_id, ra_event_class[idx].ascii_id);
00247         ra_value_set_string(vh_name, ra_event_class[idx].name);
00248         ra_value_set_string(vh_desc, ra_event_class[idx].desc);
00249 
00250         return 0;
00251 } /* fill_predef_class_info() */
00252 
00253 
00254 int
00255 fill_predef_class_info_ascii(const char *ascii_id, value_handle vh_name, value_handle vh_desc)
00256 {
00257         int n_class = sizeof(ra_event_class) / sizeof(struct event_class_desc);
00258         int i, idx;
00259 
00260         idx = -1;
00261         for (i = 0; i < n_class; i++)
00262         {
00263                 if (strcmp(ascii_id, ra_event_class[i].ascii_id) == 0)
00264                 {
00265                         idx = i;
00266                         break;
00267                 }
00268         }
00269         if (idx == -1)
00270                 return -1;
00271 
00272         ra_value_set_string(vh_name, ra_event_class[idx].name);
00273         ra_value_set_string(vh_desc, ra_event_class[idx].desc);
00274 
00275         return 0;
00276 } /* fill_predef_class_info_ascii() */
00277 
00278 
00279 long
00280 get_class_id(const char *ascii_id)
00281 {
00282         int n = sizeof(ra_event_class) / sizeof(struct event_class_desc);
00283         int i, idx;
00284 
00285         idx = -1;
00286         for (i = 0; i < n; i++)
00287         {
00288                 if (strcmp(ascii_id, ra_event_class[i].ascii_id) == 0)
00289                 {
00290                         idx = i;
00291                         break;
00292                 }
00293         }
00294         if (idx == -1)
00295                 return -1;
00296 
00297         return ra_event_class[idx].id;
00298 } /* get_class_id() */
00299 
00300 
00320 int
00321 fill_predef_prop_info(int prop, value_handle vh_id, value_handle vh_type, value_handle vh_len, value_handle vh_name, value_handle vh_desc,
00322                       value_handle vh_unit, value_handle vh_use_minmax, value_handle vh_min, value_handle vh_max)
00323 {
00324         int n_prop = sizeof(ra_event_prop) / sizeof(struct event_prop_desc);
00325         int i, idx;
00326 
00327         idx = -1;
00328         for (i = 0; i < n_prop; i++)
00329         {
00330                 if (ra_event_prop[i].id == prop)
00331                 {
00332                         idx = i;
00333                         break;
00334                 }
00335         }
00336         if (idx == -1)
00337                 return -1;
00338 
00339         ra_value_set_string(vh_id, ra_event_prop[idx].ascii_id);
00340         ra_value_set_long(vh_type, ra_event_prop[idx].val_type);
00341         ra_value_set_long(vh_len, ra_event_prop[idx].num_values);
00342         ra_value_set_string(vh_name, ra_event_prop[idx].name);
00343         ra_value_set_string(vh_desc, ra_event_prop[idx].desc);
00344         ra_value_set_string(vh_unit, ra_event_prop[idx].unit);
00345         ra_value_set_long(vh_use_minmax, ra_event_prop[idx].use_minmax);
00346         ra_value_set_double(vh_min, ra_event_prop[idx].min_value);
00347         ra_value_set_double(vh_max, ra_event_prop[idx].max_value);
00348 
00349         return 0;
00350 } /* fill_predef_prop_info() */
00351 
00352 
00353 int
00354 fill_predef_prop_info_ascii(const char *ascii_id, value_handle vh_type, value_handle vh_len,
00355                             value_handle vh_name, value_handle vh_desc, value_handle vh_unit,
00356                             value_handle vh_use_minmax, value_handle vh_min, value_handle vh_max)
00357 {
00358         int n_prop = sizeof(ra_event_prop) / sizeof(struct event_prop_desc);
00359         int i, idx;
00360 
00361         idx = -1;
00362         for (i = 0; i < n_prop; i++)
00363         {
00364                 if (strcmp(ascii_id, ra_event_prop[i].ascii_id) == 0)
00365                 {
00366                         idx = i;
00367                         break;
00368                 }
00369         }
00370         if (idx == -1)
00371                 return -1;
00372 
00373         ra_value_set_long(vh_type, ra_event_prop[idx].val_type);
00374         ra_value_set_long(vh_len, ra_event_prop[idx].num_values);
00375         ra_value_set_string(vh_name, ra_event_prop[idx].name);
00376         ra_value_set_string(vh_desc, ra_event_prop[idx].desc);
00377         ra_value_set_string(vh_unit, ra_event_prop[idx].unit);
00378         ra_value_set_long(vh_use_minmax, ra_event_prop[idx].use_minmax);
00379         ra_value_set_double(vh_min, ra_event_prop[idx].min_value);
00380         ra_value_set_double(vh_max, ra_event_prop[idx].max_value);
00381 
00382         return 0;
00383 } /* fill_predef_prop_info_ascii() */
00384 
00385 
00386 long
00387 get_prop_id(const char *ascii_id)
00388 {
00389         int n = sizeof(ra_event_prop) / sizeof(struct event_prop_desc);
00390         int i, idx;
00391 
00392         idx = -1;
00393         for (i = 0; i < n; i++)
00394         {
00395                 if (strcmp(ascii_id, ra_event_prop[i].ascii_id) == 0)
00396                 {
00397                         idx = i;
00398                         break;
00399                 }
00400         }
00401         if (idx == -1)
00402                 return -1;
00403 
00404         return ra_event_prop[idx].id;
00405 } /* get_prop_id() */

Generated on Fri May 27 11:32:38 2005 for libRASCH by  doxygen 1.4.2