00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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