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: estimate_ch_infos.c Source File

estimate_ch_infos.c

Go to the documentation of this file.
00001 
00010 /*----------------------------------------------------------------------------
00011  *
00012  * Copyright (C) 2002-2004, Raphael Schneider
00013  * See the file COPYING for information on usage and redistribution.
00014  *
00015  * $Header: /home/cvs_repos.bak/librasch/src/estimate_ch_infos.c,v 1.5 2004/06/22 13:43:45 rasch Exp $
00016  *
00017  *--------------------------------------------------------------------------*/
00018 
00019 #include <stdlib.h>
00020 #include <string.h>
00021 #include <stdio.h>
00022 
00023 #define _LIBRASCH_BUILD
00024 #include <ra_estimate_ch_infos.h>
00025 #include <ra_priv.h>
00026 
00027 int find_name(const char *name, char *part);
00028 int isletter(char c);
00029 
00030 
00031 
00039 LIBRAAPI int
00040 ra_est_ch_type(const char *name, struct ra_est_ch_infos *inf)
00041 {
00042         int found = 0;
00043         int i;
00044         char *name_utf8;
00045 
00046         if (name[0] == '\0')
00047                 return 0;
00048 
00049         name_utf8 = malloc(strlen(name) * 2);
00050         local_to_utf8(name, name_utf8, strlen(name) * 2);
00051 
00052         for (i = 0; i < _num_infs; i++)
00053         {
00054                 found = find_name(name_utf8, _inf[i].name_contains);
00055                 if (found)
00056                 {
00057                         memcpy(inf, &(_inf[i]), sizeof(_inf[0]));
00058                         break;
00059                 }
00060         }
00061 
00062         return found;
00063 } /* ra_est_ch_type() */
00064 
00065 
00073 int
00074 find_name(const char *name, char *part)
00075 {
00076         int found = 0;
00077         int i;
00078 
00079         char *buf = NULL;
00080 
00081         buf = malloc(strlen(part) + 1);
00082         memset(buf, 0, strlen(part) + 1);
00083 
00084         for (i = 0; i < (int) strlen(name) - 1; i++)
00085         {
00086                 if ((i == 0) || (!isletter(name[i]) && isletter(name[i + 1])))
00087                 {
00088                         if (i == 0)
00089                                 strncpy(buf, &(name[i]), strlen(part));
00090                         else
00091                                 strncpy(buf, &(name[i + 1]), strlen(part));
00092 
00093                         if (RA_STRICMP(buf, part) == 0)
00094                         {
00095                                 found = 1;
00096                                 break;
00097                         }
00098                 }
00099         }
00100 
00101         if (buf)
00102                 free(buf);
00103 
00104         return found;
00105 } /* find_name() */
00106 
00107 
00114 int
00115 isletter(char c)
00116 {
00117         if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')))
00118                 return 1;
00119 
00120         return 0;
00121 } /* isletter() */

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