Main Page   Class Hierarchy   Compound List   File List   Compound Members  

cmd_line_t.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 "cmd_line_t.hpp"
00022 #include "Utils.hpp"
00023 #include "string_t.hpp"
00024 #include "iostream_t.hpp"
00025 
00026 
00027 cmd_line_pt create_cmd_line (int P_nb_args) {
00028   cmd_line_pt L_result ;
00029   int L_i ;
00030 
00031   ALLOC_VAR(L_result,
00032             cmd_line_pt,
00033             sizeof(cmd_line_t));
00034   L_result->m_nb_args = P_nb_args ;
00035   ALLOC_TABLE(L_result->m_args,
00036             char**,
00037             sizeof(char*),
00038             P_nb_args);
00039   for (L_i=0; L_i < P_nb_args ; L_i++) {
00040     L_result->m_args[L_i] = NULL ;
00041   }
00042   return(L_result);
00043 }
00044 
00045 
00046 void copy_cmd_line (cmd_line_pt P_dest, int P_argc, char**P_argv) {
00047   int L_i;
00048 
00049   P_dest->m_nb_args = P_argc ;
00050   for(L_i = 0 ; L_i < P_argc ; L_i ++) {
00051     if (P_dest->m_args[L_i]) {
00052       FREE_TABLE(P_dest->m_args[L_i]);
00053     }
00054     ALLOC_TABLE(P_dest->m_args[L_i],
00055                 char*,
00056                 sizeof(char),
00057                 strlen(P_argv[L_i])+1);
00058     
00059     memcpy(P_dest->m_args[L_i],
00060            P_argv[L_i],
00061            strlen(P_argv[L_i]));
00062     P_dest->m_args[L_i][strlen(P_argv[L_i])] = 0 ;
00063   }
00064 }
00065 
00066 
00067 void  destroy_cmd(cmd_line_pt P_cmd_line) {
00068 
00069   int L_i;
00070 
00071   for(L_i = 0 ; L_i < P_cmd_line->m_nb_args ; L_i ++) {
00072     FREE_TABLE(P_cmd_line->m_args[L_i]);
00073   }
00074 }
00075 
00076 

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