Main Page   Class Hierarchy   Compound List   File List   Compound Members  

TextUtils.cpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 
00020 
00021 #include "TextUtils.hpp"
00022 #include "Utils.hpp"
00023 #include "string_t.hpp"
00024 #include <regex.h>
00025 
00026 char* find_text_value (char *P_buf, char *P_field) {
00027 
00028   char *L_value = NULL ;
00029 
00030   regex_t    L_reg_expr ;
00031   int        L_status ;
00032   char       L_buffer[100];
00033   regmatch_t L_pmatch[3] ;
00034   size_t     L_size = 0 ;
00035 
00036   string_t   L_string = "" ;
00037   
00038   L_string  = "([[:blank:]]*" ;
00039   L_string += P_field ;
00040   L_string += "[[:blank:]]*=[[:blank:]]*)([^[:blank:];]+)";
00041 
00042   L_status = regcomp (&L_reg_expr, 
00043                       L_string.c_str(),
00044                       REG_EXTENDED) ;
00045 
00046   if (L_status != 0) {
00047     regerror(L_status, &L_reg_expr, L_buffer, 100);
00048     regfree (&L_reg_expr) ;
00049 
00050   } else {
00051   
00052     L_status = regexec (&L_reg_expr, P_buf, 3, L_pmatch, 0) ;
00053     regfree (&L_reg_expr) ;
00054 
00055     if (L_status == 0) {
00056       
00057       L_size = L_pmatch[2].rm_eo - L_pmatch[2].rm_so ;
00058       
00059       ALLOC_TABLE(L_value, char*, sizeof(char), L_size+1);
00060       memcpy(L_value, &(P_buf[L_pmatch[2].rm_so]), L_size);
00061       L_value[L_size]='\0' ;
00062       
00063     } 
00064   }
00065 
00066 
00067   return (L_value);
00068 }

Generated on Wed Mar 7 14:44:59 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002